Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/contractkit/src/wrappers/Election.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eqAddress } from '@celo/utils/lib/address'
import { eqAddress, normalizeAddress } from '@celo/utils/lib/address'
import { concurrentMap, concurrentValuesMap } from '@celo/utils/lib/async'
import { zip } from '@celo/utils/lib/collections'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -406,7 +406,7 @@ export class ElectionWrapper extends BaseWrapper<Election> {
(e: EventLog, index: number): GroupVoterReward => ({
epochNumber,
group: validatorGroup[index],
groupVoterPayment: e.returnValues.value,
groupVoterPayment: valueToBigNumber(e.returnValues.value),
})
)
}
Expand All @@ -421,7 +421,7 @@ export class ElectionWrapper extends BaseWrapper<Election> {
const voter = await this.getVoter(address, blockNumber)
const activeVoterVotes: Record<string, BigNumber> = {}
for (const vote of voter.votes) {
const group: string = vote.group.toLowerCase()
const group: string = normalizeAddress(vote.group)
activeVoterVotes[group] = vote.active
}
const activeGroupVotes: Record<string, BigNumber> = await concurrentValuesMap(
Expand All @@ -432,13 +432,15 @@ export class ElectionWrapper extends BaseWrapper<Election> {

const groupVoterRewards = await this.getGroupVoterRewards(epochNumber)
const voterRewards = groupVoterRewards.filter(
(e: GroupVoterReward) => e.group.address.toLowerCase() in activeVoterVotes
(e: GroupVoterReward) => normalizeAddress(e.group.address) in activeVoterVotes
)
return voterRewards.map(
(e: GroupVoterReward): VoterReward => ({
address,
addressPayment: e.groupVoterPayment.times(
activeVoterVotes[e.group.address].dividedBy(activeGroupVotes[e.group.address])
activeVoterVotes[normalizeAddress(e.group.address)].dividedBy(
activeGroupVotes[normalizeAddress(e.group.address)]
)
),
group: e.group,
epochNumber: e.epochNumber,
Expand Down
4 changes: 2 additions & 2 deletions packages/contractkit/src/wrappers/Validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ export class ValidatorsWrapper extends BaseWrapper<Validators> {
(e: EventLog, index: number): ValidatorReward => ({
epochNumber,
validator: validator[index],
validatorPayment: e.returnValues.validatorPayment,
validatorPayment: valueToBigNumber(e.returnValues.validatorPayment),
group: validatorGroup[index],
groupPayment: e.returnValues.groupPayment,
groupPayment: valueToBigNumber(e.returnValues.groupPayment),
})
)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {

export type Address = string

export const eqAddress = (a: Address, b: Address) =>
trimLeading0x(a).toLowerCase() === trimLeading0x(b).toLowerCase()
export const eqAddress = (a: Address, b: Address) => normalizeAddress(a) === normalizeAddress(b)

export const normalizeAddress = (a: Address) => trimLeading0x(a).toLowerCase()

export const trimLeading0x = (input: string) => (input.startsWith('0x') ? input.slice(2) : input)

Expand Down