Skip to content

Commit 3d268a7

Browse files
committed
feat(subgraph): add-juror-rewards-and-drawn-indicators
1 parent 1c02948 commit 3d268a7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

subgraph/core/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ type Round @entity {
192192
court: Court!
193193
feeToken: FeeToken
194194
timeline: [BigInt!]!
195+
jurorsDrawn: Boolean!
196+
jurorRewardsDispersed: Boolean!
195197
}
196198

197199
type Draw @entity(immutable: true) {

subgraph/core/src/KlerosCore.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { updateJurorStake } from "./entities/JurorTokensPerCourt";
2424
import { createDrawFromEvent } from "./entities/Draw";
2525
import { updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
2626
import { updateArbitrableCases } from "./entities/Arbitrable";
27-
import { Court, Dispute, User } from "../generated/schema";
27+
import { Court, Dispute, Round, User } from "../generated/schema";
2828
import { BigInt } from "@graphprotocol/graph-ts";
2929
import { updatePenalty } from "./entities/Penalty";
3030
import { ensureFeeToken } from "./entities/FeeToken";
@@ -185,6 +185,17 @@ export function handleDraw(event: DrawEvent): void {
185185
const jurorAddress = event.params._address.toHexString();
186186
updateJurorStake(jurorAddress, dispute.court, sortitionModule, event.block.timestamp);
187187
addUserActiveDispute(jurorAddress, disputeID);
188+
189+
const roundIndex = event.params._roundID;
190+
const roundID = `${disputeID}-${roundIndex.toString()}`;
191+
192+
const currentRound = Round.load(roundID);
193+
if (!currentRound) return;
194+
195+
if (currentRound.nbVotes.toI32() === currentRound.drawnJurors.load().length) {
196+
currentRound.jurorsDrawn = true;
197+
currentRound.save();
198+
}
188199
}
189200

190201
export function handleTokenAndETHShift(event: TokenAndETHShiftEvent): void {
@@ -199,6 +210,21 @@ export function handleTokenAndETHShift(event: TokenAndETHShiftEvent): void {
199210
const klerosCore = KlerosCore.bind(event.address);
200211
const sortitionModule = SortitionModule.bind(klerosCore.sortitionModule());
201212
updateJurorStake(jurorAddress, court.id, sortitionModule, event.block.timestamp);
213+
214+
const roundIndex = event.params._roundID;
215+
const roundID = `${disputeID}-${roundIndex.toString()}`;
216+
217+
const round = Round.load(roundID);
218+
if (!round) return;
219+
220+
const roundInfo = klerosCore.getRoundInfo(event.params._disputeID, roundIndex);
221+
const repartitions = roundInfo.repartitions;
222+
const nbVotes = roundInfo.nbVotes;
223+
224+
if (repartitions >= nbVotes) {
225+
round.jurorRewardsDispersed = true;
226+
round.save();
227+
}
202228
}
203229

204230
export function handleAcceptedFeeToken(event: AcceptedFeeToken): void {

subgraph/core/src/entities/Round.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export function createRoundFromRoundInfo(
2424
const courtID = contract.disputes(disputeID).value0.toString();
2525
round.court = courtID;
2626
round.timeline = new Array<BigInt>(4).fill(new BigInt(0));
27+
round.jurorsDrawn = false;
28+
round.jurorRewardsDispersed = false;
2729
round.save();
2830
}
2931

0 commit comments

Comments
 (0)