-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.js
58 lines (55 loc) · 1.34 KB
/
example.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
'use strict';
const graphResultsPager = require('.');
const hexToAscii = str => {
const hex = str.toString();
let out = '';
for (let n = 2; n < hex.length; n += 2) {
const nextPair = hex.substr(n, 2);
if (nextPair !== '00') {
out += String.fromCharCode(parseInt(nextPair, 16));
}
}
return out;
};
graphResultsPager({
api: 'https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-exchanges',
max: 10,
timeout: 5e3,
query: {
entity: 'synthExchanges',
selection: {
orderBy: 'timestamp',
orderDirection: 'desc',
where: {
timestamp_gt: Math.floor(Date.now() / 1e3) - 3600 * 24, // one day ago
},
},
properties: [
'id',
'timestamp',
'from',
'fromAmountInUSD',
'fromCurrencyKey',
'toCurrencyKey',
'toAmountInUSD',
'feesInUSD',
],
},
})
.then(results =>
results.map(
({ id, timestamp, from, fromAmountInUSD, fromCurrencyKey, toAmountInUSD, toCurrencyKey, feesInUSD }) => ({
timestamp: Number(timestamp * 1000),
date: new Date(timestamp * 1000),
hash: id.split('-')[0],
fromAddress: from,
fromCurrencyKey: hexToAscii(fromCurrencyKey),
fromAmountInUSD: fromAmountInUSD / 1e18,
toAmountInUSD: toAmountInUSD / 1e18,
toCurrencyKey: hexToAscii(toCurrencyKey),
feesInUSD: feesInUSD / 1e18,
}),
),
)
.then(console.log)
.catch(err => console.error(err));