@@ -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}
0 commit comments