forked from sushiswap/sushi-data
/
index.js
55 lines (48 loc) · 1.4 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
'use strict';
const pageResults = require('graph-results-pager');
const { Promise } = require('bluebird')
const { graphAPIEndpoints } = require('./constants')
const sushi = require('./queries/sushi');
const blocks = require('./queries/blocks');
const charts = require('./queries/charts');
const exchange = require('./queries/exchange');
const exchange_v1 = require('./queries/exchange_v1')
const masterchef = require('./queries/masterchef');
const bar = require('./queries/bar')
const maker = require('./queries/maker')
const timelock = require('./queries/timelock');
const lockup = require('./queries/lockup');
const bentobox = require('./queries/bentobox');
const utils = require('./utils');
module.exports = {
pageResults,
graphAPIEndpoints,
sushi,
blocks,
charts,
exchange,
exchange_v1,
masterchef,
bar,
maker,
timelock,
lockup,
bentobox,
utils,
async timeseries({blocks = undefined, timestamps = undefined, target = undefined} = {}, targetArguments) {
if(!target) { throw new Error("sushi-data: Target function undefined"); }
if(!blocks && !timestamps) { throw new Error("sushi-data: Timeframe undefined"); }
if(blocks) {
return Promise.map(blocks, async (block) => ({
block,
data: await target({block, ...targetArguments})
}));
}
else {
return Promise.map(timestamps, async (timestamp) => ({
timestamp,
data: await target({timestamp, ...targetArguments})
}));
}
},
};