File tree Expand file tree Collapse file tree 1 file changed +42
-18
lines changed Expand file tree Collapse file tree 1 file changed +42
-18
lines changed Original file line number Diff line number Diff line change 1
1
2
2
const subgraphEndpoint = 'https://api.goldsky.com/api/public/project_cm97dvfxxyivn01xe2sda93ka/subgraphs/angstrom-mainnet/1.3.3/gn'
3
- const subgraphQuery = {
4
- query : `
5
- {
6
- pools(first: 1000) {
7
- token0 {
8
- id
9
- decimals
10
- }
11
- token1 {
12
- id
13
- decimals
14
- }
15
- totalValueLockedToken0
16
- totalValueLockedToken1
17
- }
18
- }
3
+ const subgraphQuery = ( blockNumber ) => {
4
+ return {
5
+ query : `
6
+ {
7
+ pools(first: 1000, block: {number: ${ blockNumber } }) {
8
+ token0 {
9
+ id
10
+ decimals
11
+ }
12
+ token1 {
13
+ id
14
+ decimals
15
+ }
16
+ totalValueLockedToken0
17
+ totalValueLockedToken1
18
+ }
19
+ }
19
20
20
- `
21
+ `
22
+ }
21
23
} ;
22
24
25
+ async function getGraphBlock ( ) {
26
+ const query = {
27
+ query : `
28
+ {
29
+ _meta {
30
+ block {
31
+ number
32
+ }
33
+ }
34
+ }
35
+ `
36
+ }
37
+ const response = await fetch ( subgraphEndpoint , {
38
+ "body" : JSON . stringify ( query ) ,
39
+ "method" : "POST"
40
+ } )
41
+ const data = await response . json ( )
42
+
43
+ return Number ( data . data . _meta . block . number )
44
+ }
45
+
23
46
module . exports . ethereum = {
24
47
tvl : async ( api ) => {
25
48
const block = await api . getBlock ( api . timestamp )
49
+ const graphBlock = await getGraphBlock ( )
26
50
27
51
const response = await fetch ( subgraphEndpoint , {
28
- "body" : JSON . stringify ( subgraphQuery ) ,
52
+ "body" : JSON . stringify ( subgraphQuery ( block > graphBlock ? graphBlock : block ) ) ,
29
53
"method" : "POST"
30
54
} )
31
55
const data = await response . json ( )
You can’t perform that action at this time.
0 commit comments