Skip to content

Commit

Permalink
Merge pull request #1392 from kleros/dev
Browse files Browse the repository at this point in the history
Release of v2-testnet-3.0.2
  • Loading branch information
jaybuidl authored Jan 5, 2024
2 parents 4963c6a + be7d75c commit 7198e28
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 41 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/deploy-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name: Deploy the Subgraph
on:
workflow_dispatch:
inputs:
network:
description: The network to deploy the subgraph to
graph_environment:
description: The Graph environment to deploy to
required: true
default: 'arbitrum-sepolia'
default: 'graph-studio-devnet'
type: choice
options:
- arbitrum-sepolia-devnet
- arbitrum-sepolia
- arbitrum
- graph-studio-devnet
- graph-studio-testnet
- graph-studio-mainnet
subgraph:
description: The name of the subgraph to deploy
required: true
Expand All @@ -32,13 +32,17 @@ permissions:
jobs:
buildAndDeploy:
runs-on: ubuntu-latest
environment: kleros-org-subgraph
environment: ${{ inputs.graph_environment }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
with:
egress-policy: audit

- name: Validate Network environment variable
if: ${{!startsWith(vars.NETWORK, 'arbitrum')}}
run: echo ${{vars.NETWORK}} && exit 1

- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

Expand Down Expand Up @@ -66,7 +70,7 @@ jobs:
if: ${{ inputs.update }}
run: |
export PATH=$PWD/../bin:$PATH
yarn update:${{ inputs.subgraph }}:${{ inputs.network }}
yarn update:${{ inputs.subgraph }}:${{ vars.NETWORK }}
working-directory: subgraph

- name: Build the subgraph
Expand All @@ -75,10 +79,10 @@ jobs:
yarn build:${{ inputs.subgraph }}
working-directory: subgraph

- name: Authenticate with TheGraph
run: yarn graph auth "${{ secrets.SUBGRAPH_AUTH_TOKEN }}" --product hosted-service
- name: Authenticate with TheGraph Studio
run: yarn graph auth "${{ secrets.SUBGRAPH_AUTH_TOKEN }}" --studio
working-directory: subgraph

- name: Deploy the subgraph
run: yarn deploy:${{ inputs.subgraph }}:${{ inputs.network }}
run: yarn deploy:${{ inputs.subgraph }}:${{ vars.NETWORK }}
working-directory: subgraph
9 changes: 3 additions & 6 deletions contracts/deploy/utils/deployERC20AndFaucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ export const deployERC20AndFaucet = async (
ticker: string,
faucetFundingAmount: BigNumber = hre.ethers.utils.parseUnits("100000")
): Promise<Contract> => {
let erc20 = await hre.ethers.getContractOrNull(ticker);
if (erc20) {
return erc20;
}
erc20 = await getContractOrDeploy(hre, ticker, {
const erc20 = await getContractOrDeploy(hre, ticker, {
from: deployer,
contract: "TestERC20",
args: [ticker, ticker],
Expand All @@ -27,7 +23,8 @@ export const deployERC20AndFaucet = async (
});
const faucetBalance = await erc20.balanceOf(faucet.address);
const deployerBalance = await erc20.balanceOf(deployer);
if (deployerBalance.gte(faucetFundingAmount) && faucetBalance.isZero()) {
if (deployerBalance.gte(faucetFundingAmount) && faucetBalance.lt(faucetFundingAmount.div(5))) {
// Fund the faucet if deployer has enough tokens and if the faucet has less than 20% of the faucetFundingAmount
console.log(`funding ${ticker}Faucet with ${faucetFundingAmount}`);
await erc20.transfer(faucet.address, faucetFundingAmount);
}
Expand Down
38 changes: 28 additions & 10 deletions contracts/scripts/keeperBot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DisputeKitClassic, KlerosCore, PNK, RandomizerRNG, SortitionModule } from "../typechain-types";
import { DisputeKitClassic, KlerosCore, PNK, RandomizerRNG, BlockHashRNG, SortitionModule } from "../typechain-types";
import request from "graphql-request";
import env from "./utils/env";
import loggerFactory from "./utils/logger";
Expand Down Expand Up @@ -36,9 +36,10 @@ const getContracts = async () => {
const core = (await ethers.getContract("KlerosCore")) as KlerosCore;
const sortition = (await ethers.getContract("SortitionModule")) as SortitionModule;
const randomizerRng = (await ethers.getContract("RandomizerRNG")) as RandomizerRNG;
const blockHashRNG = (await ethers.getContract("BlockHashRNG")) as BlockHashRNG;
const disputeKitClassic = (await ethers.getContract("DisputeKitClassic")) as DisputeKitClassic;
const pnk = (await ethers.getContract("PNK")) as PNK;
return { core, sortition, randomizerRng, disputeKitClassic, pnk };
return { core, sortition, randomizerRng, blockHashRNG, disputeKitClassic, pnk };
};

type Contribution = {
Expand Down Expand Up @@ -150,15 +151,32 @@ const handleError = (e: any) => {
};

const isRngReady = async () => {
const { randomizerRng, sortition } = await getContracts();
const requesterID = await randomizerRng.requesterToID(sortition.address);
const n = await randomizerRng.randomNumbers(requesterID);
if (Number(n) === 0) {
logger.info("RandomizerRNG is NOT ready yet");
return false;
const { randomizerRng, blockHashRNG, sortition } = await getContracts();
const currentRng = await sortition.rng();
if (currentRng === randomizerRng.address) {
const requesterID = await randomizerRng.requesterToID(sortition.address);
const n = await randomizerRng.randomNumbers(requesterID);
if (Number(n) === 0) {
logger.info("RandomizerRNG is NOT ready yet");
return false;
} else {
logger.info(`RandomizerRNG is ready: ${n.toString()}`);
return true;
}
} else if (currentRng === blockHashRNG.address) {
const requestBlock = await sortition.randomNumberRequestBlock();
const lookahead = await sortition.rngLookahead();
const n = await blockHashRNG.callStatic.receiveRandomness(requestBlock.add(lookahead));
if (Number(n) === 0) {
logger.info("BlockHashRNG is NOT ready yet");
return false;
} else {
logger.info(`BlockHashRNG is ready: ${n.toString()}`);
return true;
}
} else {
logger.info(`RandomizerRNG is ready: ${n.toString()}`);
return true;
logger.error("Unknown RNG at ", currentRng);
return false;
}
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/act-subgraph.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

act workflow_dispatch -j buildAndDeploy --input network=arbitrum-sepolia,update=true
act workflow_dispatch -j buildAndDeploy --input graph_environment=graph-studio-devnet,update=true --env network=arbitrum-sepolia-devnet
7 changes: 7 additions & 0 deletions subgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ $ yarn run graph auth --studio
#### Deployment

```bash
# bump the package version number
yarn version patch

# deploy the new version
yarn deploy:arbitrum-sepolia-devnet

# commit the new version number
git commit -m "chore: subgraph deployment"
```

### Using the Kleros organization account
Expand Down
1 change: 1 addition & 0 deletions subgraph/core/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type Round @entity {
penalties: BigInt!
drawnJurors: [Draw!]! @derivedFrom(field: "round")
dispute: Dispute!
court: Court!
feeToken: FeeToken
}

Expand Down
4 changes: 2 additions & 2 deletions subgraph/core/src/KlerosCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function handleDisputeCreation(event: DisputeCreation): void {
court.save();
createDisputeFromEvent(event);
const roundInfo = contract.getRoundInfo(disputeID, ZERO);
createRoundFromRoundInfo(disputeID, ZERO, roundInfo);
createRoundFromRoundInfo(KlerosCore.bind(event.address), disputeID, ZERO, roundInfo);
const arbitrable = event.params._arbitrable.toHexString();
updateArbitrableCases(arbitrable, ONE);
updateCases(ONE, event.block.timestamp);
Expand Down Expand Up @@ -163,7 +163,7 @@ export function handleAppealDecision(event: AppealDecision): void {
dispute.currentRound = roundID;
dispute.save();
const roundInfo = contract.getRoundInfo(disputeID, newRoundIndex);
createRoundFromRoundInfo(disputeID, newRoundIndex, roundInfo);
createRoundFromRoundInfo(KlerosCore.bind(event.address), disputeID, newRoundIndex, roundInfo);
}

export function handleCourtJump(event: CourtJump): void {
Expand Down
5 changes: 4 additions & 1 deletion subgraph/core/src/entities/Round.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BigInt } from "@graphprotocol/graph-ts";
import { KlerosCore__getRoundInfoResultValue0Struct } from "../../generated/KlerosCore/KlerosCore";
import { KlerosCore, KlerosCore__getRoundInfoResultValue0Struct } from "../../generated/KlerosCore/KlerosCore";
import { Round } from "../../generated/schema";

export function createRoundFromRoundInfo(
contract: KlerosCore,
disputeID: BigInt,
roundIndex: BigInt,
roundInfo: KlerosCore__getRoundInfoResultValue0Struct
Expand All @@ -19,5 +20,7 @@ export function createRoundFromRoundInfo(
round.repartitions = roundInfo.repartitions;
round.penalties = roundInfo.pnkPenalties;
round.dispute = disputeID.toString();
const courtID = contract.disputes(disputeID).value0.toString();
round.court = courtID;
round.save();
}
11 changes: 6 additions & 5 deletions subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@kleros/kleros-v2-subgraph",
"version": "0.3.1",
"license": "MIT",
"scripts": {
"update:core:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia core/subgraph.yaml",
Expand All @@ -10,9 +11,9 @@
"build:core": "graph build --output-dir core/build/ core/subgraph.yaml",
"test:core": "cd core && graph test",
"clean:core": "graph clean --codegen-dir core/generated/ --build-dir core/build/ && rm core/subgraph.yaml.bak.*",
"deploy:core:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-core-devnet -l v0.0.2 core/subgraph.yaml",
"deploy:core:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-core-testnet -l v0.0.2 core/subgraph.yaml",
"deploy:core:arbitrum": "graph deploy --product subgraph-studio kleros-v2-core -l v0.0.2 core/subgraph.yaml",
"deploy:core:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-core-devnet -l v$npm_package_version core/subgraph.yaml",
"deploy:core:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-core-testnet -l v$npm_package_version core/subgraph.yaml",
"deploy:core:arbitrum": "graph deploy --product subgraph-studio kleros-v2-core -l v$npm_package_version core/subgraph.yaml",
"": "------------------------------------------------------------------------------------------",
"update:drt:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia dispute-template-registry/subgraph.yaml",
"update:drt:arbitrum-sepolia": "./scripts/update.sh arbitrumSepolia arbitrum-sepolia dispute-template-registry/subgraph.yaml",
Expand All @@ -22,8 +23,8 @@
"build:drt": "graph build --output-dir dispute-template-registry/generated/ dispute-template-registry/subgraph.yaml",
"test:drt": "cd dispute-template-registry && graph test ",
"clean:drt": "graph clean --codegen-dir dispute-template-registry/generated/ --build-dir dispute-template-registry/build/ && rm dispute-template-registry/subgraph.yaml.bak.*",
"deploy:drt:arbitrum-sepolia-devnet": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-devnet -l v0.0.2 dispute-template-registry/subgraph.yaml",
"deploy:drt:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-testnet -l v0.0.2 dispute-template-registry/subgraph.yaml",
"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",
"deploy:drt:arbitrum-sepolia": "graph deploy --product subgraph-studio kleros-v2-drt-arbisep-testnet -l v$npm_package_version dispute-template-registry/subgraph.yaml",
" ": "-----------------------------------------------------------------------------------------",
"update:arbitrum-sepolia-devnet": "./scripts/all.sh update arbitrum-sepolia-devnet",
"update:arbitrum-sepolia": "./scripts/all.sh update arbitrum-sepolia",
Expand Down
17 changes: 17 additions & 0 deletions web/src/assets/svgs/icons/paperclip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/components/Verdict/DisputeTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const useItems = (disputeDetails?: DisputeDetailsQuery, arbitrable?: `0x${string
acc.push({
title: `Jury Decision - Round ${index + 1}`,
party: isOngoing ? "Voting is ongoing" : getVoteChoice(parsedRoundChoice, answers),
subtitle: eventDate,
subtitle: `${eventDate} / ${votingHistory?.dispute?.rounds.at(index)?.court.name}`,
rightSided: true,
variant: theme.secondaryPurple,
Icon: icon !== "" ? icon : undefined,
Expand Down
4 changes: 4 additions & 0 deletions web/src/hooks/queries/useVotingHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const votingHistoryQuery = graphql(`
id
rounds {
nbVotes
court {
id
name
}
}
disputeKitDispute {
localRounds {
Expand Down
22 changes: 20 additions & 2 deletions web/src/pages/Cases/CaseDetails/Overview/Policies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IPFS_GATEWAY } from "consts/index";
import PolicyIcon from "svgs/icons/policy.svg";
import { isUndefined } from "utils/index";
import { responsiveSize } from "styles/responsiveSize";
import PaperclipIcon from "svgs/icons/paperclip.svg";

const ShadeArea = styled.div`
display: flex;
Expand Down Expand Up @@ -46,21 +47,38 @@ const StyledPolicyIcon = styled(PolicyIcon)`
fill: ${({ theme }) => theme.primaryBlue};
`;

const StyledPaperclipIcon = styled(PaperclipIcon)`
width: 16px;
fill: ${({ theme }) => theme.primaryBlue};
`;

const LinkContainer = styled.div`
display: flex;
gap: ${responsiveSize(8, 24)};
gap: ${responsiveSize(16, 24)};
flex-wrap: wrap;
`;

type Attachment = {
label?: string;
uri: string;
};
interface IPolicies {
disputePolicyURI?: string;
courtId?: string;
attachment?: Attachment;
}

export const Policies: React.FC<IPolicies> = ({ disputePolicyURI, courtId }) => {
export const Policies: React.FC<IPolicies> = ({ disputePolicyURI, courtId, attachment }) => {
return (
<ShadeArea>
<StyledP>Make sure you read and understand the Policies</StyledP>
<LinkContainer>
{!isUndefined(attachment) && !isUndefined(attachment.uri) ? (
<StyledA href={`${IPFS_GATEWAY}${attachment.uri}`} target="_blank" rel="noreferrer">
<StyledPaperclipIcon />
{attachment.label ?? "Attachment"}
</StyledA>
) : null}
{isUndefined(disputePolicyURI) ? null : (
<StyledA href={`${IPFS_GATEWAY}${disputePolicyURI}`} target="_blank" rel="noreferrer">
<StyledPolicyIcon />
Expand Down
6 changes: 5 additions & 1 deletion web/src/pages/Cases/CaseDetails/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const Overview: React.FC<IOverview> = ({ arbitrable, courtID, currentPeriodIndex
{...{ rewards, category }}
/>
</Container>
<Policies disputePolicyURI={disputeTemplate?.policyURI} courtId={courtID} />
<Policies
disputePolicyURI={disputeTemplate?.policyURI}
courtId={courtID}
attachment={disputeTemplate?.attachment}
/>
</>
);
};
Expand Down
3 changes: 2 additions & 1 deletion web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
? "All jurors voted"
: localRounds.at(currentTab)?.totalVoted.toString() +
` vote${localRounds.at(currentTab)?.totalVoted.toString() === "1" ? "" : "s"} cast out of ` +
rounds.at(currentTab)?.nbVotes}
rounds.at(currentTab)?.nbVotes}{" "}
- {rounds.at(currentTab)?.court.name}
</p>
</StyledBox>
<StyledAccordion
Expand Down

0 comments on commit 7198e28

Please sign in to comment.