|
1 | 1 | const axios = require('axios');
|
2 | 2 | const sdk = require('@defillama/sdk');
|
3 |
| - |
4 | 3 | const utils = require('../utils');
|
5 | 4 |
|
6 | 5 | const chains = {
|
@@ -60,65 +59,70 @@ const chains = {
|
60 | 59 | };
|
61 | 60 |
|
62 | 61 | const getApy = async () => {
|
63 |
| - const pools = await Promise.all( |
| 62 | + const results = await Promise.all( |
64 | 63 | Object.keys(chains).map(async (chain) => {
|
65 |
| - const y = chains[chain]; |
66 |
| - |
67 |
| - const data = (await axios.get(`https://backend-${chain}.gains.trade/apr`)) |
68 |
| - .data; |
69 |
| - |
70 |
| - const priceKeys = [y.gns, ...y.vaults.map((i) => i.underlying)].map( |
71 |
| - (i) => `${chain}:${i}` |
72 |
| - ); |
73 |
| - |
74 |
| - const prices = ( |
75 |
| - await axios.get(`https://coins.llama.fi/prices/current/${priceKeys}`) |
76 |
| - ).data.coins; |
77 |
| - |
78 |
| - // gns staking pool |
79 |
| - const balance = |
80 |
| - ( |
81 |
| - await sdk.api.abi.call({ |
82 |
| - target: y.gns, |
83 |
| - abi: 'erc20:balanceOf', |
84 |
| - params: [y.staking], |
85 |
| - chain, |
86 |
| - }) |
87 |
| - ).output / 1e18; |
| 64 | + try { |
| 65 | + const y = chains[chain]; |
| 66 | + const data = ( |
| 67 | + await axios.get(`https://backend-${chain}.gains.trade/apr`) |
| 68 | + ).data; |
| 69 | + const priceKeys = [y.gns, ...y.vaults.map((i) => i.underlying)].map( |
| 70 | + (i) => `${chain}:${i}` |
| 71 | + ); |
| 72 | + const prices = ( |
| 73 | + await axios.get(`https://coins.llama.fi/prices/current/${priceKeys}`) |
| 74 | + ).data.coins; |
88 | 75 |
|
89 |
| - const gnsStaking = { |
90 |
| - chain, |
91 |
| - project: 'gains-network', |
92 |
| - pool: y.staking, |
93 |
| - symbol: 'GNS', |
94 |
| - tvlUsd: balance * prices[`${chain}:${y.gns}`].price, |
95 |
| - apyBase: utils.aprToApy(data.sssApr), |
96 |
| - underlyingTokens: [y.gns], |
97 |
| - }; |
| 76 | + const balance = |
| 77 | + ( |
| 78 | + await sdk.api.abi.call({ |
| 79 | + target: y.gns, |
| 80 | + abi: 'erc20:balanceOf', |
| 81 | + params: [y.staking], |
| 82 | + chain, |
| 83 | + }) |
| 84 | + ).output / 1e18; |
98 | 85 |
|
99 |
| - // vaults |
100 |
| - const vaults = data.collateralRewards.map((i) => { |
101 |
| - const addresses = y.vaults.find((v) => v.symbol === i.symbol); |
102 |
| - const priceData = prices[`${chain}:${addresses.underlying}`]; |
103 |
| - const tvlUsd = |
104 |
| - Number(i.vaultTvl / 10 ** priceData.decimals) * priceData.price; |
105 |
| - |
106 |
| - return { |
| 86 | + const gnsStaking = { |
107 | 87 | chain,
|
108 | 88 | project: 'gains-network',
|
109 |
| - pool: addresses.pool, |
110 |
| - symbol: i.symbol, |
111 |
| - tvlUsd, |
112 |
| - apyBase: utils.aprToApy(i.vaultApr), |
113 |
| - underlyingTokens: [addresses.underlying], |
| 89 | + pool: y.staking, |
| 90 | + symbol: 'GNS', |
| 91 | + tvlUsd: balance * prices[`${chain}:${y.gns}`].price, |
| 92 | + apyBase: utils.aprToApy(data.sssApr), |
| 93 | + underlyingTokens: [y.gns], |
114 | 94 | };
|
115 |
| - }); |
116 | 95 |
|
117 |
| - return [gnsStaking, ...vaults]; |
| 96 | + const vaults = data.collateralRewards.flatMap((i) => { |
| 97 | + const addresses = y.vaults.find((v) => v.symbol === i.symbol); |
| 98 | + if (!addresses) return []; |
| 99 | + |
| 100 | + const priceData = prices[`${chain}:${addresses.underlying}`]; |
| 101 | + const tvlUsd = |
| 102 | + Number(i.vaultTvl / 10 ** priceData.decimals) * priceData.price; |
| 103 | + |
| 104 | + return [ |
| 105 | + { |
| 106 | + chain, |
| 107 | + project: 'gains-network', |
| 108 | + pool: addresses.pool, |
| 109 | + symbol: i.symbol, |
| 110 | + tvlUsd, |
| 111 | + apyBase: utils.aprToApy(i.vaultApr), |
| 112 | + underlyingTokens: [addresses.underlying], |
| 113 | + }, |
| 114 | + ]; |
| 115 | + }); |
| 116 | + |
| 117 | + return [gnsStaking, ...vaults]; |
| 118 | + } catch (error) { |
| 119 | + console.error(`Error fetching APY data for ${chain}:`, error); |
| 120 | + return []; |
| 121 | + } |
118 | 122 | })
|
119 | 123 | );
|
120 | 124 |
|
121 |
| - return pools.flat(); |
| 125 | + return results.flat(); |
122 | 126 | };
|
123 | 127 |
|
124 | 128 | module.exports = {
|
|
0 commit comments