Skip to content

Commit f6732be

Browse files
authored
Merge pull request #982 from kleros/feat(subgraph)/update-subgraph-to-interfaces
Feat(subgraph): update variable names to go with new interfaces
2 parents 5fa615e + f1c03d6 commit f6732be

File tree

6 files changed

+42
-62
lines changed

6 files changed

+42
-62
lines changed

subgraph/src/DisputeKitClassic.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ import {
99
Withdrawal,
1010
} from "../generated/DisputeKitClassic/DisputeKitClassic";
1111
import { KlerosCore } from "../generated/KlerosCore/KlerosCore";
12-
import {
13-
ClassicDispute,
14-
ClassicEvidence,
15-
ClassicRound,
16-
} from "../generated/schema";
12+
import { ClassicDispute, ClassicEvidence, ClassicRound } from "../generated/schema";
1713
import { ensureClassicContributionFromEvent } from "./entities/ClassicContribution";
1814
import { createClassicDisputeFromEvent } from "./entities/ClassicDispute";
1915
import { ensureClassicEvidenceGroup } from "./entities/ClassicEvidenceGroup";
20-
import {
21-
createClassicRound,
22-
updateChoiceFundingFromContributionEvent,
23-
updateCounts,
24-
} from "./entities/ClassicRound";
16+
import { createClassicRound, updateChoiceFundingFromContributionEvent, updateCounts } from "./entities/ClassicRound";
2517
import { createClassicVote } from "./entities/ClassicVote";
2618
import { ONE, ZERO } from "./utils";
2719

@@ -35,14 +27,12 @@ export function handleDisputeCreation(event: DisputeCreation): void {
3527
}
3628

3729
export function handleEvidenceEvent(event: EvidenceEvent): void {
38-
const evidenceGroupID = event.params._evidenceGroupID.toString();
30+
const evidenceGroupID = event.params._externalDisputeID.toString();
3931
const evidenceGroup = ensureClassicEvidenceGroup(evidenceGroupID);
4032
const evidenceIndex = evidenceGroup.nextEvidenceIndex;
4133
evidenceGroup.nextEvidenceIndex = evidenceGroup.nextEvidenceIndex.plus(ONE);
4234
evidenceGroup.save();
43-
const evidence = new ClassicEvidence(
44-
`${evidenceGroupID}-${evidenceIndex.toString()}`
45-
);
35+
const evidence = new ClassicEvidence(`${evidenceGroupID}-${evidenceIndex.toString()}`);
4636
evidence.evidence = event.params._evidence;
4737
evidence.evidenceGroup = evidenceGroupID.toString();
4838
evidence.sender = event.params._party.toHexString();
@@ -54,8 +44,7 @@ export function handleJustificationEvent(event: JustificationEvent): void {
5444
const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
5545
const classicDispute = ClassicDispute.load(classicDisputeID);
5646
if (!classicDispute) return;
57-
const currentLocalRoundID =
58-
classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
47+
const currentLocalRoundID = classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
5948
updateCounts(currentLocalRoundID, event.params._choice);
6049
createClassicVote(currentLocalRoundID, event);
6150
}
@@ -85,9 +74,7 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
8574
const appealCost = klerosCore.appealCost(BigInt.fromString(coreDisputeID));
8675
localRound.feeRewards = localRound.feeRewards.minus(appealCost);
8776

88-
const localDispute = ClassicDispute.load(
89-
`${DISPUTEKIT_ID}-${coreDisputeID}`
90-
);
77+
const localDispute = ClassicDispute.load(`${DISPUTEKIT_ID}-${coreDisputeID}`);
9178
if (!localDispute) return;
9279
const newRoundIndex = localDispute.currentLocalRoundIndex.plus(ONE);
9380
const numberOfChoices = localDispute.numberOfChoices;

subgraph/src/KlerosCore.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ export function handleCourtCreated(event: CourtCreated): void {
3838
}
3939

4040
export function handleCourtModified(event: CourtModified): void {
41-
const contract = KlerosCore.bind(event.address);
42-
const courtContractState = contract.courts(event.params._courtID);
4341
const court = Court.load(event.params._courtID.toString());
4442
if (!court) return;
45-
court.hiddenVotes = courtContractState.value1;
46-
court.minStake = courtContractState.value2;
47-
court.alpha = courtContractState.value3;
48-
court.feeForJuror = courtContractState.value4;
49-
court.jurorsForCourtJump = courtContractState.value5;
50-
court.timesPerPeriod = contract.getTimesPerPeriod(event.params._courtID);
43+
court.hiddenVotes = event.params._hiddenVotes;
44+
court.minStake = event.params._minStake;
45+
court.alpha = event.params._alpha;
46+
court.feeForJuror = event.params._feeForJuror;
47+
court.jurorsForCourtJump = event.params._jurorsForCourtJump;
48+
court.timesPerPeriod = event.params._timesPerPeriod;
5149
court.save();
5250
}
5351

@@ -77,7 +75,7 @@ export function handleDisputeCreation(event: DisputeCreation): void {
7775
court.save();
7876
createDisputeFromEvent(event);
7977
const roundInfo = contract.getRoundInfo(disputeID, ZERO);
80-
createRoundFromRoundInfo(disputeID, ZERO, court.feeForJuror, roundInfo);
78+
createRoundFromRoundInfo(disputeID, ZERO, roundInfo);
8179
const arbitrable = event.params._arbitrable.toHexString();
8280
updateArbitrableCases(arbitrable, ONE);
8381
updateCases(ONE, event.block.timestamp);
@@ -119,7 +117,7 @@ export function handleAppealDecision(event: AppealDecision): void {
119117
dispute.save();
120118
const feeForJuror = getFeeForJuror(dispute.court);
121119
const roundInfo = contract.getRoundInfo(disputeID, newRoundIndex);
122-
createRoundFromRoundInfo(disputeID, newRoundIndex, feeForJuror, roundInfo);
120+
createRoundFromRoundInfo(disputeID, newRoundIndex, roundInfo);
123121
}
124122

125123
export function handleDraw(event: DrawEvent): void {
@@ -154,20 +152,20 @@ export function handleTokenAndETHShift(event: TokenAndETHShiftEvent): void {
154152
createTokenAndEthShiftFromEvent(event);
155153
const jurorAddress = event.params._account.toHexString();
156154
const disputeID = event.params._disputeID.toString();
157-
const tokenAmount = event.params._tokenAmount;
158-
const ethAmount = event.params._ethAmount;
159-
if (tokenAmount.gt(ZERO)) {
160-
updateRedistributedPNK(tokenAmount, event.block.timestamp);
161-
}
162-
updatePaidETH(ethAmount, event.block.timestamp);
155+
const pnkAmount = event.params._pnkAmount;
156+
const feeAmount = event.params._feeAmount;
163157
const dispute = Dispute.load(disputeID);
164158
if (!dispute) return;
165159
const court = Court.load(dispute.court);
166160
if (!court) return;
167161
updateJurorStake(jurorAddress, court.id, KlerosCore.bind(event.address), event.block.timestamp);
168-
resolveUserDispute(jurorAddress, tokenAmount, disputeID);
169-
court.paidETH = court.paidETH.plus(ethAmount);
170-
court.paidPNK = court.paidPNK.plus(tokenAmount);
171-
court.save();
162+
resolveUserDispute(jurorAddress, pnkAmount, disputeID);
163+
court.paidETH = court.paidETH.plus(feeAmount);
164+
if (pnkAmount.gt(ZERO)) {
165+
court.paidPNK = court.paidPNK.plus(pnkAmount);
166+
updateRedistributedPNK(pnkAmount, event.block.timestamp);
167+
}
168+
updatePaidETH(feeAmount, event.block.timestamp);
172169
updatePenalty(event);
170+
court.save();
173171
}

subgraph/src/entities/Penalty.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ export function updatePenalty(event: TokenAndETHShift): void {
1010
const penaltyID = `${roundID}-${jurorAddress}`;
1111
const penalty = Penalty.load(penaltyID);
1212
if (penalty) {
13-
penalty.amount = penalty.amount.plus(event.params._tokenAmount);
13+
penalty.amount = penalty.amount.plus(event.params._pnkAmount);
1414
const totalCoherency = penalty.degreeOfCoherency.times(penalty.numberDraws);
1515
penalty.numberDraws = penalty.numberDraws.plus(ONE);
16-
penalty.degreeOfCoherency = totalCoherency
17-
.plus(penalty.degreeOfCoherency)
18-
.div(penalty.numberDraws);
16+
penalty.degreeOfCoherency = totalCoherency.plus(penalty.degreeOfCoherency).div(penalty.numberDraws);
1917
penalty.save();
2018
} else {
2119
createPenalty(event);
@@ -33,7 +31,7 @@ export function createPenalty(event: TokenAndETHShift): void {
3331
penalty.round = roundID;
3432
penalty.juror = jurorAddress;
3533
penalty.numberDraws = ONE;
36-
penalty.amount = event.params._tokenAmount;
34+
penalty.amount = event.params._pnkAmount;
3735
penalty.degreeOfCoherency = event.params._degreeOfCoherency;
3836
penalty.save();
3937
}

subgraph/src/entities/Round.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { Round } from "../../generated/schema";
55
export function createRoundFromRoundInfo(
66
disputeID: BigInt,
77
roundIndex: BigInt,
8-
feeForJuror: BigInt,
98
roundInfo: KlerosCore__getRoundInfoResult
109
): void {
1110
const roundID = `${disputeID.toString()}-${roundIndex.toString()}`;
1211
const round = new Round(roundID);
13-
round.disputeKit = roundInfo.value5.toString();
14-
round.tokensAtStakePerJuror = roundInfo.value0;
15-
round.totalFeesForJurors = roundInfo.value1;
16-
round.nbVotes = roundInfo.value1.div(feeForJuror);
17-
round.repartitions = roundInfo.value2;
18-
round.penalties = roundInfo.value3;
12+
round.disputeKit = roundInfo.getDisputeKitID.toString();
13+
round.tokensAtStakePerJuror = roundInfo.getPnkAtStakePerJuror();
14+
round.totalFeesForJurors = roundInfo.getTotalFeesForJurors();
15+
round.nbVotes = roundInfo.getNbVotes();
16+
round.repartitions = roundInfo.getRepartitions();
17+
round.penalties = roundInfo.getPnkPenalties();
1918
round.dispute = disputeID.toString();
2019
round.save();
2120
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { TokenAndETHShift as TokenAndETHShiftEvent } from "../../generated/KlerosCore/KlerosCore";
22
import { TokenAndETHShift } from "../../generated/schema";
33

4-
export function createTokenAndEthShiftFromEvent(
5-
event: TokenAndETHShiftEvent
6-
): void {
4+
export function createTokenAndEthShiftFromEvent(event: TokenAndETHShiftEvent): void {
75
const jurorAddress = event.params._account.toHexString();
86
const disputeID = event.params._disputeID.toString();
97
const shiftID = `${jurorAddress}-${disputeID}`;
108
const shift = new TokenAndETHShift(shiftID);
119
shift.juror = jurorAddress;
1210
shift.dispute = disputeID;
13-
shift.tokenAmount = event.params._tokenAmount;
14-
shift.ethAmount = event.params._ethAmount;
11+
shift.tokenAmount = event.params._pnkAmount;
12+
shift.ethAmount = event.params._feeAmount;
1513
shift.save();
1614
}

subgraph/subgraph.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ dataSources:
66
name: KlerosCore
77
network: arbitrum-goerli
88
source:
9-
address: "0xA429667Abb1A6c530BAd1083df4C69FBce86D696"
9+
address: "0x8Af82E2F8890acb4AB84cbaB3c4C4Eb3E965CF24"
1010
abi: KlerosCore
11-
startBlock: 25602125
11+
startBlock: 27808431
1212
mapping:
1313
kind: ethereum/events
1414
apiVersion: 0.0.6
@@ -38,7 +38,7 @@ dataSources:
3838
handler: handleNewPeriod
3939
- event: CourtCreated(indexed uint256,indexed uint96,bool,uint256,uint256,uint256,uint256,uint256[4],uint256[])
4040
handler: handleCourtCreated
41-
- event: CourtModified(indexed uint96,string)
41+
- event: CourtModified(indexed uint96,bool,uint256,uint256,uint256,uint256,uint256[4])
4242
handler: handleCourtModified
4343
- event: DisputeKitCreated(indexed uint256,indexed address,indexed uint256)
4444
handler: handleDisputeKitCreated
@@ -48,7 +48,7 @@ dataSources:
4848
handler: handleStakeSet
4949
- event: StakeDelayed(indexed address,uint256,uint256,uint256)
5050
handler: handleStakeDelayed
51-
- event: TokenAndETHShift(indexed address,indexed uint256,indexed uint256,uint256,int256,int256)
51+
- event: TokenAndETHShift(indexed address,indexed uint256,indexed uint256,uint256,int256,int256,address)
5252
handler: handleTokenAndETHShift
5353
- event: Ruling(indexed address,indexed uint256,uint256)
5454
handler: handleRuling
@@ -77,9 +77,9 @@ dataSources:
7777
name: DisputeKitClassic
7878
network: arbitrum-goerli
7979
source:
80-
address: "0xcBE3aD699919Cf59efDF715e4B41AF30A0E4c92d"
80+
address: "0x0245A93ABd9c5b2d767B2D98cE6d5e612208E474"
8181
abi: DisputeKitClassic
82-
startBlock: 25602098
82+
startBlock: 27808415
8383
mapping:
8484
kind: ethereum/events
8585
apiVersion: 0.0.6

0 commit comments

Comments
 (0)