-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (60 loc) · 2.65 KB
/
index.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
const axios = require("axios");
var fs = require('fs');
async function getStakerInfo() {
try {
let ContractAddress = "0x0afdf238d10f2D617cbD4eceb9CDdf2B64C2CA2c";
let snapshotTimeStamp = "1608310926";
const response = await axios.get(
`https://api.etherscan.io/api?module=account&action=tokentx&address=${ContractAddress}&apikey=WIKDHW4267QM5Z2HCUVKQ2N81B6U4FEZWK`);
const stakingEventsArr = response.data.result;
let historyStakers = [];
let fullDataBeforeSnapshot = [];
stakingEventsArr.forEach(eventData => {
if (parseInt(eventData.timeStamp) <= parseInt(snapshotTimeStamp)) {
fullDataBeforeSnapshot.push(eventData);
if (!historyStakers.includes(eventData.to) && eventData.to != ContractAddress) {
historyStakers.push(eventData.to);
}
if (!historyStakers.includes(eventData.from) && eventData.from != ContractAddress) {
historyStakers.push(eventData.from);
}
}
});
fs.writeFile('fullDataBeforeSnapshot.json', JSON.stringify(fullDataBeforeSnapshot), function (err) {
if (err) return console.log(err);
console.log('fullDataBeforeSnapshot.json created.');
});
fs.writeFile('historyStakers.json', JSON.stringify(historyStakers), function (err) {
if (err) return console.log(err);
console.log('historyStakers.json created.');
});
let stakesInfo = [];
historyStakers.forEach(address => {
let addressStake = { staker: address, amount: 0 };
fullDataBeforeSnapshot.forEach(element => {
if (element.from == address) {
//console.log("Stake");
//console.log(element);
addressStake.amount += parseInt(element.value);
addressStake.lastStakeDate = element.timeStamp;
}
if (element.to == address) {
//console.log("UNStake");
//console.log(element);
addressStake.amount = 0;
addressStake.lastStakeDate = "0";
}
});
if(addressStake.amount != 0)
stakesInfo.push(addressStake);
});
fs.writeFile('YgemStakeSnapshot.json', JSON.stringify(stakesInfo), function (err) {
if (err) return console.log(err);
console.log('YgemStakeSnapshot.json created.');
});
console.log(stakesInfo);
} catch (error) {
console.error(error);
}
}
getStakerInfo();