From d55abf93b165d8a15ce68f50d6b0114ca712f16b Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Tue, 24 Mar 2020 18:07:07 -0300 Subject: [PATCH] Registry: Fix totalizators (#55) --- src/DisputeManager.ts | 14 ++++++++------ src/JurorsRegistry.ts | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/DisputeManager.ts b/src/DisputeManager.ts index 102d7343..da57f13e 100644 --- a/src/DisputeManager.ts +++ b/src/DisputeManager.ts @@ -105,7 +105,7 @@ export function handlePenaltiesSettled(event: PenaltiesSettled): void { } // create movements for appeal fees if there were no coherent jurors - createAppealFeesForJurorFees(event, dispute as Dispute) + createAppealFeesForJurorFees(event, event.params.disputeId) dispute.save() } @@ -126,7 +126,7 @@ export function handleAppealDepositSettled(event: AppealDepositSettled): void { appeal.settled = true appeal.save() - createAppealFeesForDeposits(event.params.disputeId, event.params.roundId, appeal as Appeal, event) + createAppealFeesForDeposits(event.params.disputeId, event.params.roundId, appealId, event) } export function handleRulingComputed(event: RulingComputed): void { @@ -203,7 +203,8 @@ function updateAppeal(disputeId: BigInt, roundNumber: BigInt, event: EthereumEve appeal.save() } -function createAppealFeesForDeposits(disputeId: BigInt, roundNumber: BigInt, appeal: Appeal, event: EthereumEvent): void { +function createAppealFeesForDeposits(disputeId: BigInt, roundNumber: BigInt, appealId: BigInt, event: EthereumEvent): void { + let appeal = Appeal.load(appealId.toString()) let manager = DisputeManager.bind(event.address) let nextRound = manager.getNextRoundDetails(disputeId, roundNumber) let totalFees = nextRound.value4 @@ -215,9 +216,9 @@ function createAppealFeesForDeposits(disputeId: BigInt, roundNumber: BigInt, app let dispute = Dispute.load(disputeId.toString()) let finalRuling = BigInt.fromI32(dispute.finalRuling) - if (appeal.appealedRuling.equals(finalRuling)) { + if (appeal.appealedRuling == finalRuling) { createFeeMovement(APPEAL_FEES, maker, totalDeposit.minus(totalFees), event) - } else if (appeal.opposedRuling.equals(finalRuling)) { + } else if (appeal.opposedRuling == finalRuling) { createFeeMovement(APPEAL_FEES, taker, totalDeposit.minus(totalFees), event) } else { let feesRefund = totalFees.div(BigInt.fromI32(2)) @@ -227,7 +228,8 @@ function createAppealFeesForDeposits(disputeId: BigInt, roundNumber: BigInt, app } } -function createAppealFeesForJurorFees(event: PenaltiesSettled, dispute: Dispute): void { +function createAppealFeesForJurorFees(event: PenaltiesSettled, disputeId: BigInt): void { + let dispute = Dispute.load(disputeId.toString()) let roundId = buildRoundId(event.params.disputeId, event.params.roundId).toString() let round = AdjudicationRound.load(roundId) if (round.coherentJurors.isZero()) { diff --git a/src/JurorsRegistry.ts b/src/JurorsRegistry.ts index 2aabe21c..bfbd9f04 100644 --- a/src/JurorsRegistry.ts +++ b/src/JurorsRegistry.ts @@ -135,13 +135,13 @@ function createANJMovement(id: string, juror: Address, type: string, amount: Big function increaseTotalStaked(registryAddress: Address, amount: BigInt): void { let jurorsRegistry = JurorsRegistryModule.load(registryAddress.toHex()) - jurorsRegistry.totalActive = jurorsRegistry.totalStaked.plus(amount) + jurorsRegistry.totalStaked = jurorsRegistry.totalStaked.plus(amount) jurorsRegistry.save() } function decreaseTotalStaked(registryAddress: Address, amount: BigInt): void { let jurorsRegistry = JurorsRegistryModule.load(registryAddress.toHex()) - jurorsRegistry.totalActive = jurorsRegistry.totalStaked.minus(amount) + jurorsRegistry.totalStaked = jurorsRegistry.totalStaked.minus(amount) jurorsRegistry.save() }