Skip to content

Commit 7198e28

Browse files
authored
Merge pull request #1392 from kleros/dev
Release of v2-testnet-3.0.2
2 parents 4963c6a + be7d75c commit 7198e28

File tree

15 files changed

+116
-41
lines changed

15 files changed

+116
-41
lines changed

.github/workflows/deploy-subgraph.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ name: Deploy the Subgraph
33
on:
44
workflow_dispatch:
55
inputs:
6-
network:
7-
description: The network to deploy the subgraph to
6+
graph_environment:
7+
description: The Graph environment to deploy to
88
required: true
9-
default: 'arbitrum-sepolia'
9+
default: 'graph-studio-devnet'
1010
type: choice
1111
options:
12-
- arbitrum-sepolia-devnet
13-
- arbitrum-sepolia
14-
- arbitrum
12+
- graph-studio-devnet
13+
- graph-studio-testnet
14+
- graph-studio-mainnet
1515
subgraph:
1616
description: The name of the subgraph to deploy
1717
required: true
@@ -32,13 +32,17 @@ permissions:
3232
jobs:
3333
buildAndDeploy:
3434
runs-on: ubuntu-latest
35-
environment: kleros-org-subgraph
35+
environment: ${{ inputs.graph_environment }}
3636
steps:
3737
- name: Harden Runner
3838
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
3939
with:
4040
egress-policy: audit
4141

42+
- name: Validate Network environment variable
43+
if: ${{!startsWith(vars.NETWORK, 'arbitrum')}}
44+
run: echo ${{vars.NETWORK}} && exit 1
45+
4246
- name: Checkout code
4347
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
4448

@@ -66,7 +70,7 @@ jobs:
6670
if: ${{ inputs.update }}
6771
run: |
6872
export PATH=$PWD/../bin:$PATH
69-
yarn update:${{ inputs.subgraph }}:${{ inputs.network }}
73+
yarn update:${{ inputs.subgraph }}:${{ vars.NETWORK }}
7074
working-directory: subgraph
7175

7276
- name: Build the subgraph
@@ -75,10 +79,10 @@ jobs:
7579
yarn build:${{ inputs.subgraph }}
7680
working-directory: subgraph
7781

78-
- name: Authenticate with TheGraph
79-
run: yarn graph auth "${{ secrets.SUBGRAPH_AUTH_TOKEN }}" --product hosted-service
82+
- name: Authenticate with TheGraph Studio
83+
run: yarn graph auth "${{ secrets.SUBGRAPH_AUTH_TOKEN }}" --studio
8084
working-directory: subgraph
8185

8286
- name: Deploy the subgraph
83-
run: yarn deploy:${{ inputs.subgraph }}:${{ inputs.network }}
87+
run: yarn deploy:${{ inputs.subgraph }}:${{ vars.NETWORK }}
8488
working-directory: subgraph

contracts/deploy/utils/deployERC20AndFaucet.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ export const deployERC20AndFaucet = async (
99
ticker: string,
1010
faucetFundingAmount: BigNumber = hre.ethers.utils.parseUnits("100000")
1111
): Promise<Contract> => {
12-
let erc20 = await hre.ethers.getContractOrNull(ticker);
13-
if (erc20) {
14-
return erc20;
15-
}
16-
erc20 = await getContractOrDeploy(hre, ticker, {
12+
const erc20 = await getContractOrDeploy(hre, ticker, {
1713
from: deployer,
1814
contract: "TestERC20",
1915
args: [ticker, ticker],
@@ -27,7 +23,8 @@ export const deployERC20AndFaucet = async (
2723
});
2824
const faucetBalance = await erc20.balanceOf(faucet.address);
2925
const deployerBalance = await erc20.balanceOf(deployer);
30-
if (deployerBalance.gte(faucetFundingAmount) && faucetBalance.isZero()) {
26+
if (deployerBalance.gte(faucetFundingAmount) && faucetBalance.lt(faucetFundingAmount.div(5))) {
27+
// Fund the faucet if deployer has enough tokens and if the faucet has less than 20% of the faucetFundingAmount
3128
console.log(`funding ${ticker}Faucet with ${faucetFundingAmount}`);
3229
await erc20.transfer(faucet.address, faucetFundingAmount);
3330
}

contracts/scripts/keeperBot.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DisputeKitClassic, KlerosCore, PNK, RandomizerRNG, SortitionModule } from "../typechain-types";
1+
import { DisputeKitClassic, KlerosCore, PNK, RandomizerRNG, BlockHashRNG, SortitionModule } from "../typechain-types";
22
import request from "graphql-request";
33
import env from "./utils/env";
44
import loggerFactory from "./utils/logger";
@@ -36,9 +36,10 @@ const getContracts = async () => {
3636
const core = (await ethers.getContract("KlerosCore")) as KlerosCore;
3737
const sortition = (await ethers.getContract("SortitionModule")) as SortitionModule;
3838
const randomizerRng = (await ethers.getContract("RandomizerRNG")) as RandomizerRNG;
39+
const blockHashRNG = (await ethers.getContract("BlockHashRNG")) as BlockHashRNG;
3940
const disputeKitClassic = (await ethers.getContract("DisputeKitClassic")) as DisputeKitClassic;
4041
const pnk = (await ethers.getContract("PNK")) as PNK;
41-
return { core, sortition, randomizerRng, disputeKitClassic, pnk };
42+
return { core, sortition, randomizerRng, blockHashRNG, disputeKitClassic, pnk };
4243
};
4344

4445
type Contribution = {
@@ -150,15 +151,32 @@ const handleError = (e: any) => {
150151
};
151152

152153
const isRngReady = async () => {
153-
const { randomizerRng, sortition } = await getContracts();
154-
const requesterID = await randomizerRng.requesterToID(sortition.address);
155-
const n = await randomizerRng.randomNumbers(requesterID);
156-
if (Number(n) === 0) {
157-
logger.info("RandomizerRNG is NOT ready yet");
158-
return false;
154+
const { randomizerRng, blockHashRNG, sortition } = await getContracts();
155+
const currentRng = await sortition.rng();
156+
if (currentRng === randomizerRng.address) {
157+
const requesterID = await randomizerRng.requesterToID(sortition.address);
158+
const n = await randomizerRng.randomNumbers(requesterID);
159+
if (Number(n) === 0) {
160+
logger.info("RandomizerRNG is NOT ready yet");
161+
return false;
162+
} else {
163+
logger.info(`RandomizerRNG is ready: ${n.toString()}`);
164+
return true;
165+
}
166+
} else if (currentRng === blockHashRNG.address) {
167+
const requestBlock = await sortition.randomNumberRequestBlock();
168+
const lookahead = await sortition.rngLookahead();
169+
const n = await blockHashRNG.callStatic.receiveRandomness(requestBlock.add(lookahead));
170+
if (Number(n) === 0) {
171+
logger.info("BlockHashRNG is NOT ready yet");
172+
return false;
173+
} else {
174+
logger.info(`BlockHashRNG is ready: ${n.toString()}`);
175+
return true;
176+
}
159177
} else {
160-
logger.info(`RandomizerRNG is ready: ${n.toString()}`);
161-
return true;
178+
logger.error("Unknown RNG at ", currentRng);
179+
return false;
162180
}
163181
};
164182

scripts/act-subgraph.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
act workflow_dispatch -j buildAndDeploy --input network=arbitrum-sepolia,update=true
3+
act workflow_dispatch -j buildAndDeploy --input graph_environment=graph-studio-devnet,update=true --env network=arbitrum-sepolia-devnet

subgraph/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ $ yarn run graph auth --studio
4040
#### Deployment
4141

4242
```bash
43+
# bump the package version number
44+
yarn version patch
45+
46+
# deploy the new version
4347
yarn deploy:arbitrum-sepolia-devnet
48+
49+
# commit the new version number
50+
git commit -m "chore: subgraph deployment"
4451
```
4552

4653
### Using the Kleros organization account

subgraph/core/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ type Round @entity {
181181
penalties: BigInt!
182182
drawnJurors: [Draw!]! @derivedFrom(field: "round")
183183
dispute: Dispute!
184+
court: Court!
184185
feeToken: FeeToken
185186
}
186187

subgraph/core/src/KlerosCore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function handleDisputeCreation(event: DisputeCreation): void {
7878
court.save();
7979
createDisputeFromEvent(event);
8080
const roundInfo = contract.getRoundInfo(disputeID, ZERO);
81-
createRoundFromRoundInfo(disputeID, ZERO, roundInfo);
81+
createRoundFromRoundInfo(KlerosCore.bind(event.address), disputeID, ZERO, roundInfo);
8282
const arbitrable = event.params._arbitrable.toHexString();
8383
updateArbitrableCases(arbitrable, ONE);
8484
updateCases(ONE, event.block.timestamp);
@@ -163,7 +163,7 @@ export function handleAppealDecision(event: AppealDecision): void {
163163
dispute.currentRound = roundID;
164164
dispute.save();
165165
const roundInfo = contract.getRoundInfo(disputeID, newRoundIndex);
166-
createRoundFromRoundInfo(disputeID, newRoundIndex, roundInfo);
166+
createRoundFromRoundInfo(KlerosCore.bind(event.address), disputeID, newRoundIndex, roundInfo);
167167
}
168168

169169
export function handleCourtJump(event: CourtJump): void {

subgraph/core/src/entities/Round.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { BigInt } from "@graphprotocol/graph-ts";
2-
import { KlerosCore__getRoundInfoResultValue0Struct } from "../../generated/KlerosCore/KlerosCore";
2+
import { KlerosCore, KlerosCore__getRoundInfoResultValue0Struct } from "../../generated/KlerosCore/KlerosCore";
33
import { Round } from "../../generated/schema";
44

55
export function createRoundFromRoundInfo(
6+
contract: KlerosCore,
67
disputeID: BigInt,
78
roundIndex: BigInt,
89
roundInfo: KlerosCore__getRoundInfoResultValue0Struct
@@ -19,5 +20,7 @@ export function createRoundFromRoundInfo(
1920
round.repartitions = roundInfo.repartitions;
2021
round.penalties = roundInfo.pnkPenalties;
2122
round.dispute = disputeID.toString();
23+
const courtID = contract.disputes(disputeID).value0.toString();
24+
round.court = courtID;
2225
round.save();
2326
}

subgraph/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "@kleros/kleros-v2-subgraph",
3+
"version": "0.3.1",
34
"license": "MIT",
45
"scripts": {
56
"update:core:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia core/subgraph.yaml",
@@ -10,9 +11,9 @@
1011
"build:core": "graph build --output-dir core/build/ core/subgraph.yaml",
1112
"test:core": "cd core && graph test",
1213
"clean:core": "graph clean --codegen-dir core/generated/ --build-dir core/build/ && rm core/subgraph.yaml.bak.*",
13-
"deploy:core:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-core-devnet -l v0.0.2 core/subgraph.yaml",
14-
"deploy:core:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-core-testnet -l v0.0.2 core/subgraph.yaml",
15-
"deploy:core:arbitrum": "graph deploy --product subgraph-studio kleros-v2-core -l v0.0.2 core/subgraph.yaml",
14+
"deploy:core:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-core-devnet -l v$npm_package_version core/subgraph.yaml",
15+
"deploy:core:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-core-testnet -l v$npm_package_version core/subgraph.yaml",
16+
"deploy:core:arbitrum": "graph deploy --product subgraph-studio kleros-v2-core -l v$npm_package_version core/subgraph.yaml",
1617
"": "------------------------------------------------------------------------------------------",
1718
"update:drt:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia dispute-template-registry/subgraph.yaml",
1819
"update:drt:arbitrum-sepolia": "./scripts/update.sh arbitrumSepolia arbitrum-sepolia dispute-template-registry/subgraph.yaml",
@@ -22,8 +23,8 @@
2223
"build:drt": "graph build --output-dir dispute-template-registry/generated/ dispute-template-registry/subgraph.yaml",
2324
"test:drt": "cd dispute-template-registry && graph test ",
2425
"clean:drt": "graph clean --codegen-dir dispute-template-registry/generated/ --build-dir dispute-template-registry/build/ && rm dispute-template-registry/subgraph.yaml.bak.*",
25-
"deploy:drt:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-devnet -l v0.0.2 dispute-template-registry/subgraph.yaml",
26-
"deploy:drt:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-testnet -l v0.0.2 dispute-template-registry/subgraph.yaml",
26+
"deploy:drt:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-devnet -l v$npm_package_version dispute-template-registry/subgraph.yaml",
27+
"deploy:drt:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-testnet -l v$npm_package_version dispute-template-registry/subgraph.yaml",
2728
" ": "-----------------------------------------------------------------------------------------",
2829
"update:arbitrum-sepolia-devnet": "./scripts/all.sh update arbitrum-sepolia-devnet",
2930
"update:arbitrum-sepolia": "./scripts/all.sh update arbitrum-sepolia",
Lines changed: 17 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)