Skip to content

Commit d1ca196

Browse files
committed
2 parents 8df01fa + 1b637f2 commit d1ca196

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/adaptors/yieldnest/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const { request, gql } = require('graphql-request');
2+
3+
const yieldnestGatewayUrl = 'https://gateway.yieldnest.finance/api/v1/graphql';
4+
const yieldnestRestakePoolBaseUrl = 'https://app.yieldnest.finance/restake/';
5+
const chainIdToName = {
6+
1: 'Ethereum',
7+
56: 'Binance',
8+
};
9+
const yieldnestSummaryQuery = gql`
10+
{
11+
getLRTsData(networkType: mainnet) {
12+
tokens {
13+
token
14+
blockchains {
15+
chainId
16+
apr {
17+
apr7d
18+
restaking7dApr
19+
}
20+
contract_details {
21+
tokenAddress
22+
}
23+
tvl {
24+
value_usd
25+
}
26+
}
27+
}
28+
}
29+
}`
30+
31+
const yieldnestUnderlyingAssetsQuery = gql`
32+
query lrt($chainId: Int!, $token: TOKENS!) {
33+
getAPRLRT(chainId: $chainId, token: $token) {
34+
underlyingAssets {
35+
address
36+
}
37+
}
38+
}`
39+
40+
const getUnderlyingAssets = async (chainId, token) => {
41+
try {
42+
const data = await request(yieldnestGatewayUrl, yieldnestUnderlyingAssetsQuery, { chainId, token });
43+
44+
return data.getAPRLRT.underlyingAssets.map((asset) => asset.address);
45+
} catch (error) {
46+
return [];
47+
}
48+
}
49+
50+
const apy = async () => {
51+
const data = await request(yieldnestGatewayUrl, yieldnestSummaryQuery);
52+
const tokens = data.getLRTsData.tokens;
53+
54+
const pools = await Promise.all(tokens.map(async (token) => {
55+
const blockchainData = token.blockchains[0];
56+
if (!blockchainData) return;
57+
const chain = chainIdToName[blockchainData.chainId];
58+
if (!chain) return;
59+
const address = blockchainData.contract_details.tokenAddress;
60+
const symbol = token.token;
61+
const decimals = 18;
62+
const apy = blockchainData.apr.apr7d + blockchainData.apr.restaking7dApr;
63+
const tvl = blockchainData.tvl.value_usd;
64+
const underlyingAssets = await getUnderlyingAssets(blockchainData.chainId, token.token);
65+
return {
66+
pool: `${address}-${chain}`.toLowerCase(),
67+
chain: chain,
68+
project: 'yieldnest',
69+
symbol: symbol,
70+
tvlUsd: tvl,
71+
apy: apy,
72+
underlyingTokens: underlyingAssets,
73+
url: `${yieldnestRestakePoolBaseUrl}${symbol}`,
74+
};
75+
}));
76+
77+
return pools;
78+
};
79+
80+
module.exports = { timetravel: false, apy };

0 commit comments

Comments
 (0)