Skip to content

Commit 317aed6

Browse files
committed
feat: support for shutter disputekit in devnet
1 parent ee2ceb6 commit 317aed6

File tree

8 files changed

+138
-28
lines changed

8 files changed

+138
-28
lines changed

subgraph/core/src/DisputeKitClassic.ts

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import {
99
CommitCast,
1010
} from "../generated/DisputeKitClassic/DisputeKitClassic";
1111
import { KlerosCore } from "../generated/KlerosCore/KlerosCore";
12-
import { ClassicDispute, ClassicJustification, ClassicRound, ClassicVote, Dispute } from "../generated/schema";
12+
import {
13+
ClassicDispute,
14+
ClassicJustification,
15+
ClassicRound,
16+
ClassicVote,
17+
Dispute,
18+
DisputeKit,
19+
Round,
20+
} from "../generated/schema";
1321
import { ensureClassicContributionFromEvent } from "./entities/ClassicContribution";
1422
import { createClassicDisputeFromEvent } from "./entities/ClassicDispute";
1523
import {
@@ -19,23 +27,31 @@ import {
1927
updateCountsAndGetCurrentRuling,
2028
} from "./entities/ClassicRound";
2129
import { ensureClassicVote } from "./entities/ClassicVote";
22-
import { ONE, ZERO } from "./utils";
23-
24-
export const DISPUTEKIT_ID = "1";
30+
import { ONE, ZERO, extractDisputeKitIDFromExtraData } from "./utils";
2531

2632
export function handleDisputeCreation(event: DisputeCreation): void {
2733
const disputeID = event.params._coreDisputeID.toString();
28-
createClassicDisputeFromEvent(event);
34+
const disputeKitID = extractDisputeKitIDFromExtraData(event.params._extraData);
35+
createClassicDisputeFromEvent(event, disputeKitID);
2936
const numberOfChoices = event.params._numberOfChoices;
30-
createClassicRound(disputeID, numberOfChoices, ZERO);
37+
createClassicRound(disputeID, numberOfChoices, ZERO, disputeKitID);
3138
}
3239

3340
export function handleCommitCast(event: CommitCast): void {
34-
const coreDisputeID = event.params._coreDisputeID;
35-
const coreDispute = Dispute.load(coreDisputeID.toString());
36-
const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
41+
const coreDisputeID = event.params._coreDisputeID.toString();
42+
const coreDispute = Dispute.load(coreDisputeID);
43+
if (!coreDispute) return;
44+
45+
const coreCurrentRound = Round.load(coreDispute.currentRound);
46+
if (!coreCurrentRound) return;
47+
48+
const disputeKitID = coreCurrentRound.disputeKit;
49+
50+
const classicDisputeID = `${disputeKitID}-${coreDisputeID}`;
51+
3752
const classicDispute = ClassicDispute.load(classicDisputeID);
38-
if (!classicDispute || !coreDispute) return;
53+
if (!classicDispute) return;
54+
3955
const currentLocalRoundID = classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
4056
const voteIDs = event.params._voteIDs;
4157
for (let i = 0; i < voteIDs.length; i++) {
@@ -55,9 +71,18 @@ export function handleVoteCast(event: VoteCast): void {
5571
const juror = event.params._juror.toHexString();
5672
const coreDisputeID = event.params._coreDisputeID.toString();
5773
const coreDispute = Dispute.load(coreDisputeID);
58-
const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
74+
if (!coreDispute) return;
75+
76+
const coreCurrentRound = Round.load(coreDispute.currentRound);
77+
if (!coreCurrentRound) return;
78+
79+
const disputeKitID = coreCurrentRound.disputeKit;
80+
81+
const classicDisputeID = `${disputeKitID}-${coreDisputeID}`;
82+
5983
const classicDispute = ClassicDispute.load(classicDisputeID);
60-
if (!classicDispute || !coreDispute) return;
84+
if (!classicDispute) return;
85+
6186
const choice = event.params._choice;
6287
const currentLocalRoundID = classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
6388
const voteIDs = event.params._voteIDs;
@@ -70,6 +95,7 @@ export function handleVoteCast(event: VoteCast): void {
7095
justification.transactionHash = event.transaction.hash.toHexString();
7196
justification.timestamp = event.block.timestamp;
7297
justification.save();
98+
7399
const currentRulingInfo = updateCountsAndGetCurrentRuling(
74100
currentLocalRoundID,
75101
choice,
@@ -78,6 +104,7 @@ export function handleVoteCast(event: VoteCast): void {
78104
coreDispute.currentRuling = currentRulingInfo.ruling;
79105
coreDispute.tied = currentRulingInfo.tied;
80106
coreDispute.save();
107+
81108
let classicVote: ClassicVote;
82109
for (let i = 0; i < voteIDs.length; i++) {
83110
classicVote = ensureClassicVote(currentLocalRoundID, juror, voteIDs[i], coreDispute);
@@ -97,7 +124,16 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
97124
const coreDisputeID = event.params._coreDisputeID.toString();
98125
const coreRoundIndex = event.params._coreRoundID.toString();
99126
const choice = event.params._choice;
100-
const roundID = `${DISPUTEKIT_ID}-${coreDisputeID}-${coreRoundIndex}`;
127+
128+
const coreDispute = Dispute.load(coreDisputeID);
129+
if (!coreDispute) return;
130+
131+
const roundId = `${coreDisputeID}-${coreRoundIndex}`;
132+
const coreRound = Round.load(roundId);
133+
if (!coreRound) return;
134+
const disputeKitID = coreRound.disputeKit;
135+
136+
const roundID = `${disputeKitID}-${coreDisputeID}-${coreRoundIndex}`;
101137

102138
const localRound = ClassicRound.load(roundID);
103139
if (!localRound) return;
@@ -123,13 +159,13 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
123159

124160
localRound.feeRewards = localRound.feeRewards.minus(appealCost);
125161

126-
const localDispute = ClassicDispute.load(`${DISPUTEKIT_ID}-${coreDisputeID}`);
162+
const localDispute = ClassicDispute.load(`${disputeKitID}-${coreDisputeID}`);
127163
if (!localDispute) return;
128164
const newRoundIndex = localDispute.currentLocalRoundIndex.plus(ONE);
129165
const numberOfChoices = localDispute.numberOfChoices;
130166
localDispute.currentLocalRoundIndex = newRoundIndex;
131167
localDispute.save();
132-
createClassicRound(coreDisputeID, numberOfChoices, newRoundIndex);
168+
createClassicRound(coreDisputeID, numberOfChoices, newRoundIndex, disputeKitID);
133169
}
134170

135171
localRound.save();
@@ -144,7 +180,16 @@ export function handleWithdrawal(event: Withdrawal): void {
144180
// check if all appeal fees have been withdrawn
145181
const coreDisputeID = event.params._coreDisputeID.toString();
146182
const coreRoundIndex = event.params._coreRoundID.toString();
147-
const roundID = `${DISPUTEKIT_ID}-${coreDisputeID}-${coreRoundIndex}`;
183+
184+
const coreDispute = Dispute.load(coreDisputeID);
185+
if (!coreDispute) return;
186+
187+
const roundId = `${coreDisputeID}-${coreRoundIndex}`;
188+
const coreRound = Round.load(roundId);
189+
if (!coreRound) return;
190+
const disputeKitID = coreRound.disputeKit;
191+
192+
const roundID = `${disputeKitID}-${coreDisputeID}-${coreRoundIndex}`;
148193

149194
const localRound = ClassicRound.load(roundID);
150195
if (!localRound) return;

subgraph/core/src/KlerosCore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function handleNewPeriod(event: NewPeriod): void {
156156
updateTotalLeaderboardJurors(ONE, event.block.timestamp);
157157
}
158158

159-
// Since this is a ClassicVote entity, this will only work for the Classic DisputeKit (which has ID "1").
159+
// Since this is a ClassicVote entity, this will only work for the ClassicDisputeKit and ShutterDisputeKit.
160160
const vote = ClassicVote.load(`${round.disputeKit}-${draw.id}`);
161161

162162
if (!vote) {

subgraph/core/src/entities/ClassicContribution.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
import { ClassicContribution } from "../../generated/schema";
1+
import { ClassicContribution, Dispute, DisputeKit, Round } from "../../generated/schema";
22
import { Contribution as ContributionEvent, Withdrawal } from "../../generated/DisputeKitClassic/DisputeKitClassic";
3-
import { DISPUTEKIT_ID } from "../DisputeKitClassic";
43
import { ensureUser } from "./User";
54

65
export function ensureClassicContributionFromEvent<T>(event: T): ClassicContribution | null {
76
if (!(event instanceof ContributionEvent) && !(event instanceof Withdrawal)) return null;
87
const coreDisputeID = event.params._coreDisputeID.toString();
98
const coreRoundIndex = event.params._coreRoundID.toString();
10-
const roundID = `${DISPUTEKIT_ID}-${coreDisputeID}-${coreRoundIndex}`;
9+
10+
const coreDispute = Dispute.load(coreDisputeID);
11+
if (!coreDispute) return null;
12+
13+
const roundId = `${coreDisputeID}-${coreRoundIndex}`;
14+
const coreRound = Round.load(roundId);
15+
if (!coreRound) return null;
16+
17+
const disputeKitID = coreRound.disputeKit;
18+
19+
const roundID = `${disputeKitID}-${coreDisputeID}-${coreRoundIndex}`;
20+
1121
ensureUser(event.params._contributor.toHexString());
1222
const contributor = event.params._contributor.toHexString();
1323
const choice = event.params._choice;

subgraph/core/src/entities/ClassicDispute.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { Bytes } from "@graphprotocol/graph-ts";
12
import { DisputeCreation } from "../../generated/DisputeKitClassic/DisputeKitClassic";
23
import { ClassicDispute } from "../../generated/schema";
34
import { ZERO } from "../utils";
45

5-
export function createClassicDisputeFromEvent(event: DisputeCreation): void {
6+
export function createClassicDisputeFromEvent(event: DisputeCreation, disputeKitID: string): void {
67
const coreDisputeID = event.params._coreDisputeID.toString();
7-
const classicDispute = new ClassicDispute(`1-${coreDisputeID}`);
8+
const classicDispute = new ClassicDispute(`${disputeKitID}-${coreDisputeID}`);
89
classicDispute.coreDispute = coreDisputeID;
910
classicDispute.currentLocalRoundIndex = ZERO;
1011
classicDispute.numberOfChoices = event.params._numberOfChoices;

subgraph/core/src/entities/ClassicRound.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { BigInt } from "@graphprotocol/graph-ts";
22
import { Contribution } from "../../generated/DisputeKitClassic/DisputeKitClassic";
3-
import { Answer, ClassicRound } from "../../generated/schema";
3+
import { Answer, ClassicRound, Dispute, Round } from "../../generated/schema";
44
import { ZERO } from "../utils";
55

6-
export function createClassicRound(disputeID: string, numberOfChoices: BigInt, roundIndex: BigInt): void {
7-
const localDisputeID = `1-${disputeID}`;
6+
export function createClassicRound(
7+
disputeID: string,
8+
numberOfChoices: BigInt,
9+
roundIndex: BigInt,
10+
disputeKitID: string
11+
): void {
12+
const localDisputeID = `${disputeKitID}-${disputeID}`;
813
const id = `${localDisputeID}-${roundIndex.toString()}`;
914
const classicRound = new ClassicRound(id);
1015
classicRound.localDispute = localDisputeID;
@@ -67,9 +72,16 @@ export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt, delt
6772
}
6873

6974
export function updateChoiceFundingFromContributionEvent(event: Contribution): void {
70-
const disputeKitID = "1";
7175
const coreDisputeID = event.params._coreDisputeID.toString();
7276
const coreRoundIndex = event.params._coreRoundID.toString();
77+
const coreDispute = Dispute.load(coreDisputeID);
78+
if (!coreDispute) return;
79+
80+
const roundId = `${coreDisputeID}-${coreRoundIndex}`;
81+
const coreRound = Round.load(roundId);
82+
if (!coreRound) return;
83+
const disputeKitID = coreRound.disputeKit;
84+
7385
const roundID = `${disputeKitID}-${coreDisputeID}-${coreRoundIndex}`;
7486

7587
const classicRound = ClassicRound.load(roundID);

subgraph/core/src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { BigInt } from "@graphprotocol/graph-ts";
1+
import { BigInt, Bytes } from "@graphprotocol/graph-ts";
22

33
export const ZERO = BigInt.fromI32(0);
44
export const ONE = BigInt.fromI32(1);
5+
6+
export function extractDisputeKitIDFromExtraData(extraData: Bytes): string {
7+
const start = extraData.length - 32;
8+
const littleEndian = extraData.subarray(start, extraData.length).reverse();
9+
return BigInt.fromUnsignedBytes(Bytes.fromUint8Array(littleEndian)).toString();
10+
}

subgraph/core/subgraph.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,42 @@ dataSources:
120120
- event: CommitCast(indexed uint256,indexed address,uint256[],bytes32)
121121
handler: handleCommitCast
122122
file: ./src/DisputeKitClassic.ts
123+
- kind: ethereum
124+
name: DisputeKitShutter
125+
network: arbitrum-sepolia
126+
source:
127+
address: "0x09F3d00B995186D76Af9AA8627D06351d0d9f950"
128+
abi: DisputeKitShutter
129+
startBlock: 148194178
130+
mapping:
131+
kind: ethereum/events
132+
apiVersion: 0.0.7
133+
language: wasm/assemblyscript
134+
entities:
135+
- ClassicDispute
136+
- ClassicRound
137+
- ClassicVote
138+
- ClassicContribution
139+
abis:
140+
- name: DisputeKitShutter
141+
file: ../../contracts/deployments/arbitrumSepoliaDevnet/DisputeKitShutter.json
142+
- name: KlerosCore
143+
# FIX: temporarily point to abi with event addition
144+
file: ./abi-migrations/KlerosCore.json
145+
eventHandlers:
146+
- event: DisputeCreation(indexed uint256,uint256,bytes)
147+
handler: handleDisputeCreation
148+
- event: Contribution(indexed uint256,indexed uint256,uint256,indexed address,uint256)
149+
handler: handleContributionEvent
150+
- event: Withdrawal(indexed uint256,indexed uint256,uint256,indexed address,uint256)
151+
handler: handleWithdrawal
152+
- event: ChoiceFunded(indexed uint256,indexed uint256,indexed uint256)
153+
handler: handleChoiceFunded
154+
- event: VoteCast(indexed uint256,indexed address,uint256[],indexed uint256,string)
155+
handler: handleVoteCast
156+
- event: CommitCast(indexed uint256,indexed address,uint256[],bytes32)
157+
handler: handleCommitCast
158+
file: ./src/DisputeKitClassic.ts
123159
- kind: ethereum
124160
name: EvidenceModule
125161
network: arbitrum-sepolia

subgraph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/kleros-v2-subgraph",
3-
"version": "0.15.2",
3+
"version": "0.16.0",
44
"drtVersion": "0.12.0",
55
"license": "MIT",
66
"scripts": {

0 commit comments

Comments
 (0)