-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.js
75 lines (58 loc) · 1.8 KB
/
check.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
import dotenv from "dotenv";
import { readFile } from "fs/promises";
// Lib
import { parse } from "./lib/json.js";
dotenv.config();
const { TOKEN_ADDRESS } = process.env;
const getWithdrawals = async () => {
return parse(await readFile("withdrawals.json"), ["sum", "amount", "index"]);
};
const getTransfers = async () => {
return parse(await readFile("transfers.json"), ["value"]);
};
const { withdrawals } = await getWithdrawals();
const allTransfers = await getTransfers();
// Build transfers from the deposit contract per address
const transfers = {};
for (const transfer of allTransfers) {
if (transfer.from !== TOKEN_ADDRESS) {
continue;
}
if (!transfers[transfer.to]) {
transfers[transfer.to] = [];
}
transfers[transfer.to].push(transfer);
}
// Check if the claims are correct for each address
for (const [address, events] of Object.entries(transfers)) {
console.log(`Processing address ${address}`);
events.unshift({ block: 18093 });
let j = 0;
const details = withdrawals[address.toLowerCase()].details.sort(
(a, b) => a.block - b.block
);
for (let i = 0; i < events.length - 1; i++) {
let sum = 0n;
const range = {
from: events[i].block,
to: events[i + 1].block - 1,
};
for (; j < details.length && details[j].block <= range.to; j++) {
const detail = details[j];
// Ignore all withdrawals before the first claim
if (detail.block < range.from) {
continue;
}
sum += (detail.amount * BigInt(1e9)) / 32n;
}
if (sum === events[i + 1].value) {
console.log(`${range.from} - ${range.to}: success: ${sum}`);
} else {
console.log(
`${range.from} - ${range.to}: wrong value: expected ${
events[i + 1].value
}, got ${sum} (${events[i + 1].value - sum})`
);
}
}
}