This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathverify_airdrop.js
More file actions
74 lines (61 loc) · 2.8 KB
/
verify_airdrop.js
File metadata and controls
74 lines (61 loc) · 2.8 KB
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
var fs = require('fs');
var csv = require('fast-csv');
var BigNumber = require('bignumber.js');
const polyDistributionArtifacts = require('../build/contracts/PolyDistribution.json');
const polyTokenArtifacts = require('../build/contracts/PolyToken.json');
const contract = require('truffle-contract');
let PolyDistribution = contract(polyDistributionArtifacts);
let PolyToken = contract(polyTokenArtifacts);
const Web3 = require('web3');
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
PolyDistribution.setProvider(web3.currentProvider);
//dirty hack for [email protected] support for localhost testrpc, see https://github.com/trufflesuite/truffle-contract/issues/56#issuecomment-331084530
if (typeof PolyDistribution.currentProvider.sendAsync !== "function") {
PolyDistribution.currentProvider.sendAsync = function() {
return PolyDistribution.currentProvider.send.apply(
PolyDistribution.currentProvider, arguments
);
};
}
PolyToken.setProvider(web3.currentProvider);
//dirty hack for [email protected] support for localhost testrpc, see https://github.com/trufflesuite/truffle-contract/issues/56#issuecomment-331084530
if (typeof PolyToken.currentProvider.sendAsync !== "function") {
PolyToken.currentProvider.sendAsync = function() {
return PolyToken.currentProvider.send.apply(
PolyToken.currentProvider, arguments
);
};
}
let polyDistributionAddress = process.argv.slice(2)[0];
async function listAllocations() {
let accounts = await web3.eth.getAccounts();
let polyDistribution = await PolyDistribution.at(polyDistributionAddress);
let polytokenAddress = await polyDistribution.POLY({from:accounts[0]});
let polyToken = await PolyToken.at(polytokenAddress);
//console.log(polyToken);
let count = 0;
let bal = await polyToken.balanceOf(polyDistribution.address);
var events = await polyToken.Transfer({from: polyDistribution.address},{fromBlock: 0, toBlock: 'latest'});
events.get(function(error, log) {
event_data = log;
console.log("Retrieving logs to inform total amount of tokens distributed so far. This may take a while...")
//console.log(log);
for (var i=0; i<event_data.length;i++){
let tokens = event_data[i].args.value.times(10 ** -18).toString(10);
let addressB = event_data[i].args.to;
//console.log(`Distributed ${tokens} POLY to address ${addressB}`);
count++;
}
console.log(`Successfully airdropped ${count*250} POLY to ${count} addresses`);
});
}
if(polyDistributionAddress){
listAllocations();
}else{
console.log("Please run the script by providing the address of the PolyDistribution contract");
}