forked from balancer/bal-mining-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prices.js
66 lines (54 loc) · 1.9 KB
/
prices.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
const {
ensureDirectoryExists,
pricesAvailable,
readPrices,
writePrices,
} = require('./lib/fileService');
const cliProgress = require('cli-progress');
const Web3 = require('web3');
const { REP_TOKEN, REP_TOKEN_V2 } = require('./lib/tokens');
const { argv } = require('yargs');
const ENDPOINT = process.env.ENDPOINT_URL;
//const ENDPOINT = "ws://localhost:8546"
const web3 = new Web3(new Web3.providers.WebsocketProvider(ENDPOINT));
if (!argv.startBlock || !argv.endBlock || !argv.week) {
console.log(
'Usage: node index.js --week 1 --startBlock 10131642 --endBlock 10156690'
);
process.exit();
}
const END_BLOCK = argv.endBlock; // Closest block to reference time at end of week
const START_BLOCK = argv.startBlock; // Closest block to reference time at beginning of week
const WEEK = argv.week; // Week for mining distributions. Ex: 1
(async function () {
const multibar = new cliProgress.MultiBar(
{
clearOnComplete: false,
format:
'[{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | {task}',
},
cliProgress.Presets.shades_classic
);
ensureDirectoryExists(WEEK);
let startBlockTimestamp = (await web3.eth.getBlock(START_BLOCK)).timestamp;
let endBlockTimestamp = (await web3.eth.getBlock(END_BLOCK)).timestamp;
let prices = {};
console.log(pricesAvailable(WEEK));
if (pricesAvailable(WEEK)) {
prices = readPrices(WEEK);
} else {
const whitelist = await utils.fetchWhitelist();
let priceProgress = multibar.create(whitelist.length, 0, {
task: 'Fetching Prices',
});
prices = await utils.fetchTokenPrices(
whitelist,
startBlockTimestamp,
endBlockTimestamp,
priceProgress
);
prices[REP_TOKEN] = prices[REP_TOKEN_V2];
writePrices(WEEK, prices);
}
return;
})();