-
Notifications
You must be signed in to change notification settings - Fork 503
/
run.js
48 lines (37 loc) · 1.3 KB
/
run.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
/*==================================================
Modules
==================================================*/
const sdk = require('./');
const moment = require('moment');
/*==================================================
Run
==================================================*/
async function Run(runFunction, project, timeUnit = 'day', timeOffset = 0) {
try {
let timestamp;
if(typeof timeUnit == 'number') {
timestamp = timeUnit;
} else {
timestamp = moment().utcOffset(0).startOf(timeUnit).add(timeOffset, timeUnit).unix();
}
let point = await sdk.api.util.lookupBlock(timestamp);
await sdk.api.util.resetEthCallCount();
let output = await project[runFunction](point.timestamp, point.block);
if(runFunction == 'tvl') {
output = (await sdk.api.util.toSymbols(output)).output;
output = (await sdk.api.util.unwrap({balances: output, block: point.block})).output;
}
let ethCallCount = await sdk.api.util.getEthCallCount();
return {
...ethCallCount,
...point,
output
}
} catch(error) {
console.log(error);
}
}
/*==================================================
Exports
==================================================*/
module.exports = Run;