Skip to content
Open
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: 12 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generate merkle proof
From the root directory, run
```shell
$ node scripts/generateMerkleRoot.js -f example.json
```

The script will export the result into `merkle_data_$CYCLE.json`, where `$CYCLE` is the cycle number.

# Example.json
- The tokens can be of different lengths for each user.
- Consistency need not be maintained for each cycle. For instance, the token list can be of a different order.
- The amounts in `cumulativeAmounts` can be either strings, or hexadecimal string equivalents of their numerical values. Refer to the example.
12 changes: 6 additions & 6 deletions scripts/example.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"cycle": 1,
"cycle": 3,
"userRewards": {
"0xF3c6F5F265F503f53EAD8aae90FC257A5aa49AC1": {
"tokens": ["0xdd974d5c2e2928dea5f71b9825b8b646686bd200","0x5228a22e72ccc52d415ecfd199f99d0665e7733b"],
"cumulativeAmounts": [10000, 500]
"tokens": ["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"],
"cumulativeAmounts": ["1234567800"]
},
"0xecabe455bd6cd440bba804c63da360d85cb16b75": {
"tokens": ["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x57ab1ec28d129707052df4df418d58a2d46d5f51"],
"cumulativeAmounts": [5000, 1300]
"cumulativeAmounts": ["0x2710", "0x3800"]
},
"0x529676cc3ffe94fd594d3bc0f4d2b8d89ed69a91": {
"tokens": ["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x57ab1ec28d129707052df4df418d58a2d46d5f51"],
"cumulativeAmounts": [500, 400]
"tokens": ["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],
"cumulativeAmounts": ["1234567800", "0x123"]
}
}
}
6 changes: 4 additions & 2 deletions scripts/generateMerkleRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const argv = require('yargs/yargs')(process.argv.slice(2)).argv;
const parseRewards = require('./merkleDist/parseRewards').parseRewards;

const configPath = argv.f;
const json = JSON.parse(fs.readFileSync(path.join(__dirname, configPath), { encoding: 'utf8' }))
let json = JSON.parse(fs.readFileSync(path.join(__dirname, configPath), { encoding: 'utf8' }));
let cycle = json['cycle'];
if (typeof json !== 'object') throw new Error('Invalid JSON');
console.log(JSON.stringify(parseRewards(json)));
json = JSON.stringify(parseRewards(json), null, 2);
fs.writeFileSync(path.join(__dirname, `merkle_data_${cycle}.json`), json);
4 changes: 2 additions & 2 deletions scripts/merkleDist/parseRewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports.parseRewards = function (rewardInfo) {
const leaves = hashElements(treeElements, cycle);
const tree = new MerkleTree(leaves, keccak256, {sort: true});
const userRewardsWithProof = treeElements.reduce((memo, {account}, index) => {
tokens = mappedTokensAmounts[account].tokens;
cumulativeAmounts = mappedTokensAmounts[account].cumulativeAmounts.map((amt) => amt.toHexString());
let tokens = mappedTokensAmounts[account].tokens;
let cumulativeAmounts = mappedTokensAmounts[account].cumulativeAmounts.map((amt) => amt.toHexString());

memo[account] = {
index,
Expand Down