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 patheul-stakes.js
88 lines (61 loc) · 2.4 KB
/
eul-stakes.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
/*
Script to withdraw EUL from the EulStakes contract without requiring a UI.
Install NPM dependencies and then run the following command:
RPC_URL="<RPC URL HERE>" node stake-crawler.js withdraw <YOUR ADDRESS HERE>
*/
const ethers = require('ethers');
let stakeContract = '0xc697BB6625D9f7AdcF0fbf0cbd4DcF50D8716cd3';
let iface = new ethers.utils.Interface([
'event Stake(address indexed who, address indexed underlying, address sender, uint newAmount)',
]);
const provider = new ethers.providers.JsonRpcBatchProvider(process.env.RPC_URL);
async function getLogs() {
let filter = {
address: stakeContract,
fromBlock: 0,
};
let logs = await provider.getLogs(filter);
let lookup = {};
for (let log of logs) {
log = iface.parseLog(log);
if (log.name !== 'Stake') console.warn('unknown event: ', log.name);
let who = log.args.who.toLowerCase();
let underlying = log.args.underlying.toLowerCase();
lookup[who] = lookup[who] || {};
lookup[who][underlying] = lookup[who][underlying] || {};
lookup[who][underlying] = log.args.newAmount;
}
return lookup;
};
async function main() {
let mode = process.argv[2];
let lookup = await getLogs();
if (mode === 'dump') {
for (let who of Object.keys(lookup)) {
for (let underlying of Object.keys(lookup[who])) {
let amount = lookup[who][underlying];
if (amount.eq(0)) continue;
console.log(`${who},${underlying},${amount.toString()}`);
}
}
} else if (mode === 'withdraw') {
let who = process.argv[3].toLowerCase();
let u = lookup[who];
let output = [];
for (let underlying of Object.keys(lookup[who])) {
let amount = lookup[who][underlying];
if (amount.eq(0)) continue;
output.push([underlying, amount.mul(-1).toString()]);
}
console.log(`Go to: https://etherscan.io/address/0xc697BB6625D9f7AdcF0fbf0cbd4DcF50D8716cd3#writeContract`);
console.log();
console.log(`Connect your web3 wallet with address ${who}`);
console.log();
console.log(`Enter the following as the "ops" parameter to the stake() function and press the Write button:`);
console.log();
console.log(JSON.stringify(output));
} else {
throw Error("unknown mode");
}
}
main();