@@ -107,7 +107,12 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
107
107
if ( localRound . fundedChoices . length > 1 ) {
108
108
const disputeKitClassic = DisputeKitClassic . bind ( event . address ) ;
109
109
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
+
111
116
localRound . feeRewards = localRound . feeRewards . minus ( appealCost ) ;
112
117
113
118
const localDispute = ClassicDispute . load ( `${ DISPUTEKIT_ID } -${ coreDisputeID } ` ) ;
@@ -127,5 +132,21 @@ export function handleWithdrawal(event: Withdrawal): void {
127
132
if ( ! contribution ) return ;
128
133
contribution . rewardWithdrawn = true ;
129
134
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
+
130
150
contribution . save ( ) ;
151
+ localRound . save ( ) ;
131
152
}
0 commit comments