@@ -19,12 +19,12 @@ import { createDisputeKitFromEvent, filterSupportedDisputeKits } from "./entitie
19
19
import { createDisputeFromEvent } from "./entities/Dispute" ;
20
20
import { createRoundFromRoundInfo , updateRoundTimeline } from "./entities/Round" ;
21
21
import { updateCases , updateCasesAppealing , updateCasesRuled , updateCasesVoting } from "./datapoint" ;
22
- import { addUserActiveDispute , ensureUser } from "./entities/User" ;
22
+ import { addUserActiveDispute , computeCoherenceScore , ensureUser } from "./entities/User" ;
23
23
import { updateJurorStake } from "./entities/JurorTokensPerCourt" ;
24
24
import { createDrawFromEvent } from "./entities/Draw" ;
25
25
import { updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift" ;
26
26
import { updateArbitrableCases } from "./entities/Arbitrable" ;
27
- import { Court , Dispute , Round , User } from "../generated/schema" ;
27
+ import { ClassicVote , Court , Dispute , Draw , Round , User } from "../generated/schema" ;
28
28
import { BigInt } from "@graphprotocol/graph-ts" ;
29
29
import { updatePenalty } from "./entities/Penalty" ;
30
30
import { ensureFeeToken } from "./entities/FeeToken" ;
@@ -75,9 +75,12 @@ export function handleDisputeCreation(event: DisputeCreation): void {
75
75
const court = Court . load ( courtID ) ;
76
76
if ( ! court ) return ;
77
77
court . numberDisputes = court . numberDisputes . plus ( ONE ) ;
78
+
79
+ const roundInfo = contract . getRoundInfo ( disputeID , ZERO ) ;
80
+ court . numberVotes = court . numberVotes . plus ( roundInfo . nbVotes ) ;
81
+
78
82
court . save ( ) ;
79
83
createDisputeFromEvent ( event ) ;
80
- const roundInfo = contract . getRoundInfo ( disputeID , ZERO ) ;
81
84
createRoundFromRoundInfo ( KlerosCore . bind ( event . address ) , disputeID , ZERO , roundInfo ) ;
82
85
const arbitrable = event . params . _arbitrable . toHexString ( ) ;
83
86
updateArbitrableCases ( arbitrable , ONE ) ;
@@ -124,6 +127,41 @@ export function handleNewPeriod(event: NewPeriod): void {
124
127
dispute . currentRuling = currentRulingInfo . getRuling ( ) ;
125
128
dispute . overridden = currentRulingInfo . getOverridden ( ) ;
126
129
dispute . tied = currentRulingInfo . getTied ( ) ;
130
+
131
+ const rounds = dispute . rounds . load ( ) ;
132
+ for ( let i = 0 ; i < rounds . length ; i ++ ) {
133
+ const round = Round . load ( rounds [ i ] . id ) ;
134
+ if ( ! round ) continue ;
135
+
136
+ const draws = round . drawnJurors . load ( ) ;
137
+ // Iterate over all draws in the round
138
+ for ( let j = 0 ; j < draws . length ; j ++ ) {
139
+ const draw = Draw . load ( draws [ j ] . id ) ;
140
+ if ( ! draw ) continue ;
141
+
142
+ // Since this is a ClassicVote entity, this will only work for the Classic DisputeKit (which has ID "1").
143
+ const vote = ClassicVote . load ( `${ round . disputeKit } -${ draw . id } ` ) ;
144
+
145
+ if ( ! vote ) continue ;
146
+
147
+ const juror = ensureUser ( draw . juror ) ;
148
+ juror . totalResolvedVotes = juror . totalResolvedVotes . plus ( ONE ) ;
149
+
150
+ if ( vote . choice === null ) continue ;
151
+
152
+ // Check if the vote choice matches the final ruling
153
+ if ( vote . choice ! . equals ( dispute . currentRuling ) ) {
154
+ juror . totalCoherentVotes = juror . totalCoherentVotes . plus ( ONE ) ;
155
+ }
156
+
157
+ // Recalculate coherenceScore
158
+ if ( juror . totalResolvedVotes . gt ( ZERO ) ) {
159
+ juror . coherenceScore = computeCoherenceScore ( juror . totalCoherentVotes , juror . totalResolvedVotes ) ;
160
+ }
161
+
162
+ juror . save ( ) ;
163
+ }
164
+ }
127
165
}
128
166
129
167
dispute . period = newPeriod ;
@@ -164,6 +202,15 @@ export function handleAppealDecision(event: AppealDecision): void {
164
202
dispute . currentRound = roundID ;
165
203
dispute . save ( ) ;
166
204
const roundInfo = contract . getRoundInfo ( disputeID , newRoundIndex ) ;
205
+
206
+ const disputeStorage = contract . disputes ( disputeID ) ;
207
+ const courtID = disputeStorage . value0 . toString ( ) ;
208
+ const court = Court . load ( courtID ) ;
209
+ if ( ! court ) return ;
210
+
211
+ court . numberVotes = court . numberVotes . plus ( roundInfo . nbVotes ) ;
212
+ court . save ( ) ;
213
+
167
214
createRoundFromRoundInfo ( KlerosCore . bind ( event . address ) , disputeID , newRoundIndex , roundInfo ) ;
168
215
}
169
216
0 commit comments