Skip to content

Commit

Permalink
Merge branch 'dev' into feat(sdk)/data-mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Jan 23, 2024
2 parents ef42969 + e31f829 commit 935ed57
Show file tree
Hide file tree
Showing 39 changed files with 712 additions and 269 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/deploy-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,16 @@ jobs:
working-directory: subgraph

- name: Deploy the subgraph
run: yarn deploy:${{ inputs.subgraph }}:${{ vars.NETWORK }}
run: |
# working around a graph bug which doesn't exit 1 on error: https://github.com/graphprotocol/graph-tooling/issues/1570
error=$(yarn deploy:${{ inputs.subgraph }}:${{ vars.NETWORK }})
echo "$error"
if [[ $error == *"Error"* ]]
then
echo "exiting..."
exit 1
else
echo "deployed successfully"
exit 0
fi
working-directory: subgraph
15 changes: 14 additions & 1 deletion contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1
REPORT_GAS=true

INFURA_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1

# Testing
REPORT_GAS=true

# There seems to be a bug with hardhat-deploy's implementation of etherscan-verify
# If ETHERSCAN_API_KEY is set, it overrides any hardhat configuration.
ETHERSCAN_API_KEY_FIX=ABC123ABC123ABC123ABC123ABC123ABC1
ARBISCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
GNOSISSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1

# For the bots
LOG_LEVEL=debug
SUBGRAPH_URL=https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest
LOGTAIL_TOKEN_KEEPER_BOT=cqPqBofVC8nmA8EZdZGqqvUV
LOGTAIL_TOKEN_RELAYER_BOT=41h8q5Z4gnz5yDx215eqcQ4r
LOGTAIL_TOKEN_DISPUTOR_BOT=mSryyvYubviaMqKDWfBKAGsi
HEARTBEAT_URL_KEEPER_BOT=https://uptime.betterstack.com/api/v1/heartbeat/jc23S8ZZzpf8KbzwxL1hoBp9
HEARTBEAT_URL_RELAYER_BOT=https://uptime.betterstack.com/api/v1/heartbeat/eT6Trk6CddJV6fFBbqZNzyqC
DISPUTES_TO_SKIP=

# Optionally for debugging
# TENDERLY_USERNAME=your_username
# TENDERLY_PROJECT=your_project
Expand Down
197 changes: 197 additions & 0 deletions contracts/README.md.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# @kleros/kleros-v2-contracts

Smart contracts for Kleros v2

## Deployments

Refresh the list of deployed contracts by running `./scripts/generateDeploymentsMarkdown.sh` or `./scripts/populateReadme.sh`.

$deployments

## Getting Started

### Install the Dependencies

```bash
yarn install
```

### Run Tests

```bash
yarn test
```

### Compile the Contracts

```bash
yarn build
```

### Run Linter on Files

```bash
yarn lint
```

### Fix Linter Issues on Files

```bash
yarn fix
```

### Deploy Instructions

**NOTICE:** the commands below work only if you are inside the `contracts/` directory.

#### 0. Set the Environment Variables

Copy `.env.example` file as `.env` and edit it accordingly.

```bash
cp .env.example .env
```

The following env vars are required:

- `PRIVATE_KEY`: the private key of the deployer account used for the testnets.
- `MAINNET_PRIVATE_KEY`: the private key of the deployer account used for Mainnet.
- `INFURA_API_KEY`: the API key for infura.

The ones below are optional:

- `ETHERSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Etherscan**.
- `ARBISCAN_API_KEY`: to verify the source of the newly deployed contracts on **Arbitrum**.
- `GNOSISSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Gnosis chain**.

#### 1. Update the Constructor Parameters (optional)

If some of the constructor parameters (such as the Meta Evidence) needs to change, you need to update the files in the `deploy/` directory.

#### 2. Deploy to a Local Network

The complete deployment is multi-chain, so a deployment to the local network can only simulate either the Home chain or the Foreign chain.

**Shell 1: the node**

```bash
yarn hardhat node --tags nothing
```

**Shell 2: the deploy script**

```bash
yarn deploy --network localhost --tags <Arbitration|VeaMock|ForeignGatewayOnEthereum|HomeGateway>
```

#### 3. Deploy to Public Testnets

```bash
# ArbitrumSepolia to Chiado
yarn deploy --network arbitrumSepolia --tags Arbitration
yarn deploy --network arbitrumSepolia --tags HomeArbitrable
yarn deploy --network chiado --tags ForeignGatewayOnGnosis
yarn deploy --network chiado --tags KlerosLiquidOnGnosis
yarn deploy --network chiado --tags ForeignArbitrable
yarn deploy --network arbitrumSepolia --tags HomeGatewayToGnosis

# Sepolia
yarn deploy --network sepolia --tags ForeignGatewayOnEthereum
yarn deploy --network sepolia --tags ForeignArbitrable
yarn deploy --network arbitrumSepolia --tags HomeGatewayToEthereum
```

The deployed addresses should be displayed to the screen after the deployment is complete. If you missed them, you can always go to the `deployments/<network>` directory and look for the respective file.

#### 4. Deploy a Devnet on Public Testnets

Same steps as above but append `Devnet` to the `--network` parameter.

#### Running Test Fixtures

**Shell 1: the node**

```bash
yarn hardhat node --tags Arbitration,VeaMock
```

**Shell 2: the test scripts**

```bash
yarn test --network localhost
```

#### 4. Verify the Source Code

This must be done for each network separately.

```bash
# explorer
yarn etherscan-verify --network <arbitrumSepolia|arbitrum|chiado|gnosischain|sepolia|mainnet>
yarn etherscan-verify-proxies

# sourcify
yarn sourcify --network <arbitrumSepolia|arbitrum|chiado|gnosischain|sepolia|mainnet>

```

## Ad-hoc procedures

### Populating the policy registry and courts

The policy registry and courts configuration can be found in `config/policies.*.json` and `config/courts.*.json`.

#### 1/ Export the registry data from V1

```bash
for network in mainnet gnosischain
do
yarn hardhat run scripts/getPoliciesV1.ts --network $network | tee config/policies.v1.$network.json
yarn hardhat run scripts/getCourtsV1.ts --network $network | tee config/courts.v1.$network.json
done
```

#### 2/ Import the data to V2 - Local Network

Shell 1:

```bash
yarn hardhat node --tags Arbitration
```

Shell 2:

```bash
yarn hardhat run scripts/populateCourts.ts --network localhost
yarn hardhat run scripts/populatePolicyRegistry.ts --network localhost
```

#### 3/ Import the data to V2 - Public Testnet

```bash
yarn hardhat run scripts/populateCourts.ts --network arbitrumSepolia
yarn hardhat run scripts/populatePolicyRegistry.ts --network arbitrumSepolia
```

### Generate deployment artifacts for existing contracts

#### Usage

```bash
scripts/generateDeploymentArtifact.sh <network> <address>
```

#### Example: WETH on Gnosis chain

```bash
scripts/generateDeploymentArtifact.sh gnosischain 0xf8d1677c8a0c961938bf2f9adc3f3cfda759a9d9 > deployments/gnosischain/WETH.json
```

### Push the contracts to a Tenderly project

Ensure that your `$TENDERLY_PROJECT` and `$TENDERLY_USERNAME` is set correctly in `.env`.

```bash
yarn tenderly-verify --network sepolia
yarn tenderly-verify --network arbitrumSepolia
```
26 changes: 13 additions & 13 deletions contracts/config/courts.v2.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
"id": 1,
"parent": 0,
"hiddenVotes": false,
"hiddenVotes": true,
"minStake": "150000000000000000000",
"alpha": "5000",
"feeForJuror": "10000000000000",
"jurorsForCourtJump": "511",
"timesPerPeriod": [
28800,
28800,
28800,
28800
43200,
43200,
43200,
43200
]
},
{
Expand All @@ -23,10 +23,10 @@
"feeForJuror": "10000000000000",
"jurorsForCourtJump": "30",
"timesPerPeriod": [
28800,
28800,
28800,
28800
43200,
43200,
43200,
43200
]
},
{
Expand All @@ -38,10 +38,10 @@
"feeForJuror": "10000000000000",
"jurorsForCourtJump": "63",
"timesPerPeriod": [
28800,
28800,
28800,
28800
43200,
43200,
43200,
43200
]
}
]
2 changes: 2 additions & 0 deletions subgraph/core/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type Dispute @entity {
id: ID!
disputeID: BigInt!
court: Court!
createdAt: BigInt
arbitrated: Arbitrable!
period: Period!
ruled: Boolean!
Expand Down Expand Up @@ -183,6 +184,7 @@ type Round @entity {
dispute: Dispute!
court: Court!
feeToken: FeeToken
timeline: [BigInt!]!
}

type Draw @entity(immutable: true) {
Expand Down
3 changes: 2 additions & 1 deletion subgraph/core/src/KlerosCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ZERO, ONE } from "./utils";
import { createCourtFromEvent } from "./entities/Court";
import { createDisputeKitFromEvent, filterSupportedDisputeKits } from "./entities/DisputeKit";
import { createDisputeFromEvent } from "./entities/Dispute";
import { createRoundFromRoundInfo } from "./entities/Round";
import { createRoundFromRoundInfo, updateRoundTimeline } from "./entities/Round";
import { updateCases, updateCasesAppealing, updateCasesRuled, updateCasesVoting } from "./datapoint";
import { addUserActiveDispute, ensureUser } from "./entities/User";
import { updateJurorStake } from "./entities/JurorTokensPerCourt";
Expand Down Expand Up @@ -135,6 +135,7 @@ export function handleNewPeriod(event: NewPeriod): void {
} else {
dispute.periodDeadline = BigInt.fromU64(U64.MAX_VALUE);
}
updateRoundTimeline(disputeID.toString(), newPeriod, event.block.timestamp);
dispute.save();
court.save();
}
Expand Down
10 changes: 5 additions & 5 deletions subgraph/core/src/entities/ClassicRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class CurrentRulingInfo {
tied: boolean;
}

export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt, choiceCount: BigInt): CurrentRulingInfo {
export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt, delta: BigInt): CurrentRulingInfo {
const round = ClassicRound.load(id);
if (!round) return { ruling: ZERO, tied: false };
const choiceNum = choice.toI32();
const delta = choiceCount.minus(round.counts[choiceNum]);
const newChoiceCount = round.counts[choiceNum].plus(delta);
let newCounts: BigInt[] = [];
for (let i = 0; i < round.counts.length; i++) {
if (BigInt.fromI32(i).equals(choice)) {
newCounts.push(choiceCount);
newCounts.push(newChoiceCount);
} else {
newCounts.push(round.counts[i]);
}
Expand All @@ -43,9 +43,9 @@ export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt, choi
if (choice.equals(round.winningChoice)) {
if (round.tied) round.tied = false;
} else {
if (choiceCount.equals(currentWinningCount)) {
if (newChoiceCount.equals(currentWinningCount)) {
if (!round.tied) round.tied = true;
} else if (choiceCount.gt(currentWinningCount)) {
} else if (newChoiceCount.gt(currentWinningCount)) {
round.winningChoice = choice;
round.tied = false;
}
Expand Down
1 change: 1 addition & 0 deletions subgraph/core/src/entities/Dispute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function createDisputeFromEvent(event: DisputeCreation): void {
const courtID = disputeContractState.value0.toString();
dispute.court = courtID;
dispute.disputeID = disputeID;
dispute.createdAt = event.block.timestamp;
dispute.arbitrated = event.params._arbitrable.toHexString();
dispute.period = "evidence";
dispute.ruled = false;
Expand Down
Loading

0 comments on commit 935ed57

Please sign in to comment.