Skip to content

Commit

Permalink
Registry: Fix totalizators (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo authored Mar 24, 2020
1 parent a5c52de commit d55abf9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/DisputeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/JurorsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit d55abf9

Please sign in to comment.