This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrender-merkle-dist.js
128 lines (91 loc) · 3.02 KB
/
render-merkle-dist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const fs = require('fs');
const ethers = require('ethers');
const utils = require('./utils');
let mode = process.argv[2];
if (mode === 'dump') {
let file = process.argv[3];
let outputFile = process.argv[4];
let distribution = utils.loadMerkleDistFile(file);
let output = render(distribution);
fs.writeFileSync(outputFile, output);
} else if (mode === 'diff') {
let file1 = process.argv[3];
let file2 = process.argv[4];
let outputFile = process.argv[5];
let distribution1 = utils.loadMerkleDistFile(file1);
let distribution2 = utils.loadMerkleDistFile(file2);
let distributionDiff = diff(distribution1, distribution2);
let output = render(distributionDiff);
fs.writeFileSync(outputFile, output);
} else {
throw Error(`unknown mode: ${mode}`);
}
function render(distribution) {
let addrs = [];
for (let v of distribution.values) {
if (v[1] !== utils.EulTokenAddr) continue;
addrs.push(v);
}
addrs.sort((a,b) => {
let v1 = ethers.BigNumber.from(a[2]);
let v2 = ethers.BigNumber.from(b[2]);
if (v1.eq(v2)) return 0;
else if (v1.lt(v2)) return 1;
else return -1;
});
let total;
if (distribution.mode === 'diff') {
total = ethers.BigNumber.from(distribution.info2.totals[utils.EulTokenAddr]).sub(distribution.info1.totals[utils.EulTokenAddr]).toString();
} else {
total = distribution.info.totals[utils.EulTokenAddr];
}
let output = `## Merkle Drop Summary\n`;
if (distribution.mode === 'diff') {
output += `
* Block range: ${distribution.info1.lastBlock} - ${distribution.info2.lastBlock}
* Total: \`${ethers.utils.formatEther(total)} EUL\`
* Accounts: ${addrs.length}
`;
} else {
output += `
* Block: ${distribution.info.lastBlock}
* Root: \`${distribution.info.root}\`
* Total: \`${ethers.utils.formatEther(total)} EUL\`
* Accounts: ${addrs.length}
`;
}
output += `
| Address | Amount | Percent | Links |
| ----------- | --------- | ---- | ---- |
`;
for (let a of addrs) {
let percent = ethers.BigNumber.from(a[2]).mul(1e6).div(total).toNumber() / 1e6 * 100;
let links = `[etherscan](https://etherscan.io/address/${a[0]}) [spy](https://app.euler.finance/account/0?spy=${a[0]})`;
output += `| \`${a[0]}\` | \`${ethers.utils.formatEther(a[2])} EUL\` | \`${percent.toFixed(3)}%\` | ${links} |\n`;
}
return output;
}
function diff(d1, d2) {
let o = {};
o.mode = 'diff';
o.info1 = d1.info;
o.info2 = d2.info;
o.values = [];
let prevValues = {};
for (let v of d1.values) {
if (v[1] !== utils.EulTokenAddr) continue;
prevValues[v[0]] = v[2];
}
for (let v of d2.values) {
let prev = prevValues[v[0]];
if (!prev) prev = '0';
let delta = ethers.BigNumber.from(v[2]).sub(prev).toString();
if (delta === '0') continue;
o.values.push([
v[0],
utils.EulTokenAddr,
delta,
]);
}
return o;
}