Skip to content

Commit 24ca0d2

Browse files
committed
feat(subgraph): add-appeal-fee-dispersed-indicator-and-fix-fee-reward-calc
1 parent 32672d2 commit 24ca0d2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

subgraph/core/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ type ClassicRound implements DisputeKitRound @entity {
266266
paidFees: [BigInt!]!
267267
contributions: [ClassicContribution!]! @derivedFrom(field: "localRound")
268268
feeRewards: BigInt!
269+
totalFeeDispersed: BigInt!
270+
appealFeesDispersed: Boolean!
269271
fundedChoices: [BigInt!]!
270272
justifications: [ClassicJustification!] @derivedFrom(field: "localRound")
271273
}

subgraph/core/src/DisputeKitClassic.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
107107
if (localRound.fundedChoices.length > 1) {
108108
const disputeKitClassic = DisputeKitClassic.bind(event.address);
109109
const klerosCore = KlerosCore.bind(disputeKitClassic.core());
110-
const appealCost = klerosCore.appealCost(BigInt.fromString(coreDisputeID));
110+
111+
// cannot use core.appealCost as that will give the cost for the newly created round
112+
const numberOfRounds = klerosCore.getNumberOfRounds(BigInt.fromString(coreDisputeID));
113+
const roundInfo = klerosCore.getRoundInfo(BigInt.fromString(coreDisputeID), numberOfRounds.minus(ONE));
114+
const appealCost = roundInfo.totalFeesForJurors;
115+
111116
localRound.feeRewards = localRound.feeRewards.minus(appealCost);
112117

113118
const localDispute = ClassicDispute.load(`${DISPUTEKIT_ID}-${coreDisputeID}`);
@@ -127,5 +132,21 @@ export function handleWithdrawal(event: Withdrawal): void {
127132
if (!contribution) return;
128133
contribution.rewardWithdrawn = true;
129134
contribution.rewardAmount = event.params._amount;
135+
136+
// check if all appeal fees have been withdrawn
137+
const coreDisputeID = event.params._coreDisputeID.toString();
138+
const coreRoundIndex = event.params._coreRoundID.toString();
139+
const roundID = `${DISPUTEKIT_ID}-${coreDisputeID}-${coreRoundIndex}`;
140+
141+
const localRound = ClassicRound.load(roundID);
142+
if (!localRound) return;
143+
144+
localRound.totalFeeDispersed = localRound.totalFeeDispersed.plus(event.params._amount);
145+
146+
if (localRound.totalFeeDispersed.equals(localRound.feeRewards)) {
147+
localRound.appealFeesDispersed = true;
148+
}
149+
130150
contribution.save();
151+
localRound.save();
131152
}

subgraph/core/src/entities/ClassicRound.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export function createClassicRound(disputeID: string, numberOfChoices: BigInt, r
1616
classicRound.totalCommited = ZERO;
1717
classicRound.paidFees = new Array<BigInt>(choicesLength.toI32()).fill(ZERO);
1818
classicRound.feeRewards = ZERO;
19+
classicRound.appealFeesDispersed = false;
20+
classicRound.totalFeeDispersed = ZERO;
1921
classicRound.fundedChoices = [];
2022
classicRound.save();
2123
}

0 commit comments

Comments
 (0)