Skip to content

Commit

Permalink
sort by address in generating the merkle root
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Sep 16, 2020
1 parent 9b1b8f8 commit 25dc5eb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/parse-balance-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ export function parseBalanceMap(balances: OldFormat | NewFormat[]): MerkleDistri
return memo
}, {})

const sortedAddresses = Object.keys(dataByAddress).sort()

// construct a tree
const tree = new BalanceTree(
Object.keys(dataByAddress).map((address) => ({ account: address, amount: dataByAddress[address].amount }))
sortedAddresses.map((address) => ({ account: address, amount: dataByAddress[address].amount }))
)

// generate claims
const claims = Object.keys(dataByAddress).reduce<{
const claims = sortedAddresses.reduce<{
[address: string]: { amount: string; index: number; proof: string[]; flags?: { [flag: string]: boolean } }
}>((memo, address, index) => {
const { amount, flags } = dataByAddress[address]
Expand All @@ -77,7 +79,7 @@ export function parseBalanceMap(balances: OldFormat | NewFormat[]): MerkleDistri
return memo
}, {})

const tokenTotal: BigNumber = Object.keys(dataByAddress).reduce<BigNumber>(
const tokenTotal: BigNumber = sortedAddresses.reduce<BigNumber>(
(memo, key) => memo.add(dataByAddress[key].amount),
BigNumber.from(0)
)
Expand Down

0 comments on commit 25dc5eb

Please sign in to comment.