|
1 | 1 | const { gql, request } = require('graphql-request'); |
| 2 | +const sdk = require('@defillama/sdk'); |
2 | 3 | const config = require('./config.js'); |
3 | 4 |
|
4 | | -const prevBlockQuery = gql` |
5 | | - query Blocks($timestamp_lte: BigInt = "") { |
6 | | - blocks( |
7 | | - first: 1 |
8 | | - orderBy: timestamp |
9 | | - orderDirection: desc |
10 | | - where: { timestamp_lte: $timestamp_lte } |
11 | | - ) { |
12 | | - number |
13 | | - timestamp |
14 | | - } |
15 | | - } |
16 | | -`; |
17 | | - |
18 | 5 | const volumesQuery = gql` |
19 | 6 | query Volumes($block: Int = 0) { |
20 | 7 | assetsNow: assets { |
@@ -52,58 +39,58 @@ const aprQuery = gql` |
52 | 39 | const oneDay = 86400; |
53 | 40 |
|
54 | 41 | const apy = async () => { |
55 | | - apy_export = []; |
56 | | - for (chain in config) { |
57 | | - const timestampPrior = +(new Date() / 1000).toFixed(0) - oneDay; |
| 42 | + const apy_export = []; |
| 43 | + for (const chain in config) { |
| 44 | + try { |
| 45 | + const timestampPrior = +(new Date() / 1000).toFixed(0) - oneDay; |
58 | 46 |
|
59 | | - const blockPrior = ( |
60 | | - await request(config[chain]['BLOCK_ENDPOINT'], prevBlockQuery, { |
61 | | - timestamp_lte: timestampPrior, |
62 | | - }) |
63 | | - ).blocks[0].number; |
| 47 | + const { chainBlocks } = await sdk.blocks.getBlocks(timestampPrior, [chain]); |
| 48 | + const blockPrior = chainBlocks[chain]; |
64 | 49 |
|
65 | | - const { assetsNow, assets24hAgo } = await request( |
66 | | - config[chain]['APR_ENDPOINT'], |
67 | | - volumesQuery, |
68 | | - { |
69 | | - block: +blockPrior, |
70 | | - } |
71 | | - ); |
| 50 | + const { assetsNow, assets24hAgo } = await request( |
| 51 | + config[chain]['APR_ENDPOINT'], |
| 52 | + volumesQuery, |
| 53 | + { |
| 54 | + block: +blockPrior, |
| 55 | + } |
| 56 | + ); |
72 | 57 |
|
73 | | - const { assets: aprs } = await request( |
74 | | - config[chain]['APR_ENDPOINT'], |
75 | | - aprQuery |
76 | | - ); |
| 58 | + const { assets: aprs } = await request( |
| 59 | + config[chain]['APR_ENDPOINT'], |
| 60 | + aprQuery |
| 61 | + ); |
77 | 62 |
|
78 | | - const assets = aprs.map((pool) => { |
79 | | - const aprData = aprs.find((apr) => apr.id === pool.id) || {}; |
80 | | - const feeNow = assetsNow.find((apr) => apr.id === pool.id) || {}; |
81 | | - const fee24hAgo = assets24hAgo.find((apr) => apr.id === pool.id) || {}; |
| 63 | + aprs.map((pool) => { |
| 64 | + const aprData = aprs.find((apr) => apr.id === pool.id) || {}; |
| 65 | + const feeNow = assetsNow.find((apr) => apr.id === pool.id) || {}; |
| 66 | + const fee24hAgo = assets24hAgo.find((apr) => apr.id === pool.id) || {}; |
82 | 67 |
|
83 | | - // Projected baseApy estimated by feeUSD collected in 24h |
84 | | - let apyBase = |
85 | | - (((Number(feeNow.totalSharedFeeUSD) - |
86 | | - Number(fee24hAgo.totalSharedFeeUSD)) / |
87 | | - 2) * |
88 | | - 365 * |
89 | | - 100) / |
90 | | - Number(pool.liabilityUSD) || 0; |
| 68 | + let apyBase = |
| 69 | + (((Number(feeNow.totalSharedFeeUSD) - |
| 70 | + Number(fee24hAgo.totalSharedFeeUSD)) / |
| 71 | + 2) * |
| 72 | + 365 * |
| 73 | + 100) / |
| 74 | + Number(pool.liabilityUSD) || 0; |
91 | 75 |
|
92 | | - let apyReward = |
93 | | - (Number(aprData.womBaseApr) + Number(aprData.totalBonusTokenApr)) * 100; |
| 76 | + let apyReward = |
| 77 | + (Number(aprData.womBaseApr) + Number(aprData.totalBonusTokenApr)) * 100; |
94 | 78 |
|
95 | | - apy_export.push({ |
96 | | - pool: aprData.id, |
97 | | - project: 'wombat-exchange', |
98 | | - chain: chain, |
99 | | - tvlUsd: Number(pool.liabilityUSD) || 0, |
100 | | - symbol: pool.symbol, |
101 | | - apyReward, |
102 | | - apyBase, |
103 | | - underlyingTokens: [pool.underlyingToken.id], |
104 | | - rewardTokens: [config[chain]['WOM_ADDRESS']], |
| 79 | + apy_export.push({ |
| 80 | + pool: aprData.id, |
| 81 | + project: 'wombat-exchange', |
| 82 | + chain: chain, |
| 83 | + tvlUsd: Number(pool.liabilityUSD) || 0, |
| 84 | + symbol: pool.symbol, |
| 85 | + apyReward, |
| 86 | + apyBase, |
| 87 | + underlyingTokens: [pool.underlyingToken.id], |
| 88 | + rewardTokens: [config[chain]['WOM_ADDRESS']], |
| 89 | + }); |
105 | 90 | }); |
106 | | - }); |
| 91 | + } catch (e) { |
| 92 | + console.log(`wombat-exchange ${chain} failed: ${e.message}`); |
| 93 | + } |
107 | 94 | } |
108 | 95 |
|
109 | 96 | // remove dupes on lptoken |
|
0 commit comments