Skip to content

Commit 1034d43

Browse files
committed
fix: gains-network
1 parent 8bb8e46 commit 1034d43

File tree

1 file changed

+54
-50
lines changed

1 file changed

+54
-50
lines changed

src/adaptors/gains-network/index.js

+54-50
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const axios = require('axios');
22
const sdk = require('@defillama/sdk');
3-
43
const utils = require('../utils');
54

65
const chains = {
@@ -60,65 +59,70 @@ const chains = {
6059
};
6160

6261
const getApy = async () => {
63-
const pools = await Promise.all(
62+
const results = await Promise.all(
6463
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;
8875

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;
9885

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 = {
10787
chain,
10888
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],
11494
};
115-
});
11695

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+
}
118122
})
119123
);
120124

121-
return pools.flat();
125+
return results.flat();
122126
};
123127

124128
module.exports = {

0 commit comments

Comments
 (0)