-
Notifications
You must be signed in to change notification settings - Fork 0
/
getEvent.js
125 lines (90 loc) · 4.45 KB
/
getEvent.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
const { ethers } = require('ethers');
const fs = require("fs")
require('dotenv').config();
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_KEY)
//change stakingABI.json
const { abi: contractABI } = require("./ZIPS.json");
const contractAddress = "0xb0640E8B5F24beDC63c33d371923D68fDe020303";
let temporaryTimestamp;
let tokensToCheck = [3981,4110,4083,5867,8067,2033,1083,4725,7967,4814,3970,6516,3695,8213,8248,1083,4083,278,3981,4083,4110,4110,2004,3836,3955,8792,647,5689,1440,8780,1881,7641,3327,445,1078,1102,4705,6950,672,1941,8550,3410,4051,8481,3181,6950,5244,1406,4116,1240,5434,4640,6265,5739,5497,7754,8403,4785,5243,7339,7289,2363,1654,2771,4369,571,6950,7270,2916,8260,5963,3970,4814,7147,5363,1912,2493,4640,6643,6684,3714,4102,4763,1882,2939,1874,8182,7548,3892,6460,153,307,6620,6578,5847,5828,6438,166,3602,8855,5618,4186,5634,6913,3250,3642,6528,7013,5460,1550,6068,1434,6919,6551,194,1188,6855,4532,5868,4116,2753,847,7976,5293,4389,4389,3557,3753,5323,1148,1148,6855,2673,6015,845,85,88,90,110,442,444,689,743,798,801,1022,1316,1371,1407,1417,1462,1590,1690,1898,1948,1998,2016,2261,2524,2680,2758,2786,3131,3141,3280,3302,3344,3480,3707,3917,4179,4387,4388,4534,4993,5079,5499,5573,5787,6675,6756,7039,7666,8130,8506,8643,6535,6536,213,5029,7143,317];
let uniqueTokensToCheck = [...new Set(tokensToCheck)];
console.log('Unique Tokens to Check:', uniqueTokensToCheck.length)
let tokenIDs = [];
let walletAddresses = [];
let timestamps = [];
let failedTokens = [];
let counter = 0;
const writeFile = (filePath, data) => {
fs.writeFile("./output/"+ filePath, data, (err) => {
if(err) {
throw err;
}
console.log("Data has been written to " + filePath + " successfully.");
});
}
const getEventSignature = (eventName, abi) => {
const eventAbi = abi.find((entry) => entry.name === eventName);
const types = eventAbi.inputs.map((input) => input.type);
return `${eventName}(${types.join(',')})`;
}
async function checkOwnerAndTimestamp(startingBlock,endBlock,tokenID) {
const eventSignature = getEventSignature('Transfer', contractABI)
const filter = {
address: contractAddress,
topics: [
ethers.utils.id(eventSignature),
,
,
ethers.utils.hexZeroPad(tokenID, 32)
],
fromBlock: startingBlock,
toBlock: endBlock,
};
console.log('Getting logs of tokenID:' , tokenID)
const result = await provider.getLogs(filter)
const contractInterface = new ethers.utils.Interface(contractABI);
let ownerOfToken;
let latestTransferBlock;
result.forEach((log, idx) => {
const decodedLog = contractInterface.decodeEventLog('Transfer', log.data, log.topics);
//if its not sent to staking contract, change new owner
if(decodedLog.to != "0xa1A9b59FFe51B69A8Ba305C4813267c69626297d"){
ownerOfToken = decodedLog.to;
latestTransferBlock = log.blockNumber;
}
});
temporaryTimestamp = (await provider.getBlock(latestTransferBlock)).timestamp;
tokenIDs.push(tokenID);
walletAddresses.push(ownerOfToken);
timestamps.push(temporaryTimestamp);
counter++;
console.log('----------------')
console.log('Counter:' , counter)
console.log('Owner of token:' , ownerOfToken)
console.log('Latest transfer timestamp:' , temporaryTimestamp)
console.log('----------------')
}
async function main(){
let groupCount = 1;
for(let i = 0; i < uniqueTokensToCheck.length; i++){
try {
await checkOwnerAndTimestamp(16925030,18183912,uniqueTokensToCheck[i]);
} catch (error) {
console.log('Getting token data failed. Adding ' + uniqueTokensToCheck[i] + ' to failed array')
console.log('----------------')
failedTokens.push(uniqueTokensToCheck[i]);
}
if(walletAddresses.length >= 100 || uniqueTokensToCheck.length - i -1 == 0 ){
writeFile("tokenIDs_" + groupCount + ".txt",tokenIDs.toString());
writeFile("walletAddresses_" + groupCount + ".txt",walletAddresses.toString());
writeFile("timestamps_" + groupCount + ".txt",timestamps.toString());
writeFile("failedTokens_" + groupCount + ".txt",failedTokens.toString());
tokenIDs = [];
failedTokens = [];
walletAddresses = [];
timestamps = [];
groupCount ++;
}
}
}
main();