diff --git a/src/adaptors/stake.link-index/index.js b/src/adaptors/stake.link-index/index.js deleted file mode 100644 index 33a0f91a57..0000000000 --- a/src/adaptors/stake.link-index/index.js +++ /dev/null @@ -1,58 +0,0 @@ -const utils = require('../utils'); - -const API_URL = 'https://stake.link/v1/metrics/staking'; -const CHAIN_NAME = 'Ethereum'; - -const pools = [ - { - symbol: 'ixETH', - address: '0x535321013A1E2D5aF3B1853812a64CA3fc6C1fa1', - priceId: 'ethereum', - query: `SELECT - (total_rewards * (31536000 / EXTRACT(epoch from period))) / (total_deposits - rewards_amount) * 100 as apy, - total_deposits - FROM (SELECT *, (ts - prev_ts) as period - FROM (SELECT *, - (rewards_amount - total_fees) as total_rewards, - lead(ts) over (order by ts DESC) as prev_ts - FROM index_update_rewards as rewards - ORDER BY ts DESC) as reward_rate) as reward_rate limit 1;`, - }, -]; - -const fetchPrice = async (tokenId) => { - const priceKey = `coingecko:${tokenId}`; - const data = await utils.getData( - `https://coins.llama.fi/prices/current/${priceKey}` - ); - return data.coins[priceKey].price; -}; - -const fetchPool = async (pool) => { - const { symbol, address, priceId, query } = pool; - - const price = await fetchPrice(priceId); - - let data = await utils.getData(API_URL, query); - let apy = data[0].apy; - let tvl = data[0].total_deposits * price; - - return { - pool: `${address}-${CHAIN_NAME}`.toLowerCase(), - chain: CHAIN_NAME, - project: 'stake.link-index', - symbol, - tvlUsd: tvl, - apyBase: apy, - }; -}; - -const fetchPools = async () => { - return Promise.all(pools.map((pool) => fetchPool(pool))); -}; - -module.exports = { - timetravel: false, - apy: fetchPools, - url: 'https://stake.link/staking-pools', -}; diff --git a/src/adaptors/stake.link-liquid/index.js b/src/adaptors/stake.link-liquid-staking/index.js similarity index 61% rename from src/adaptors/stake.link-liquid/index.js rename to src/adaptors/stake.link-liquid-staking/index.js index fdea5562e9..ffdae5d901 100644 --- a/src/adaptors/stake.link-liquid/index.js +++ b/src/adaptors/stake.link-liquid-staking/index.js @@ -15,16 +15,18 @@ const getData = async (url, query = null) => { }; const SUBGRAPH_URL = - 'https://api.studio.thegraph.com/query/72555/stakedotlink-ethereum/version/latest'; + 'https://graph-readonly.linkpool.pro/subgraphs/name/stakedotlink-ethereum-production'; const query = ` { totalRewardAmounts { totalRewardSTLINK + totalRewardSTPOL __typename } totalCounts { linkStakingDistributionCount + polStakingDistributionCount __typename } linkStakingDistributions( @@ -42,6 +44,22 @@ const query = ` ts __typename } + polStakingDistributions( + first: 1 + skip: 0 + orderBy: ts + orderDirection: desc + where: {isUpdatedWithBurnAmount: true} + ) { + reward_rate + reward_amount + total_staked + fees + fee_percentage + tx_hash + ts + __typename + } } `; @@ -54,6 +72,11 @@ const pools = [ address: '0xb8b295df2cd735b15BE5Eb419517Aa626fc43cD5', priceId: 'chainlink', }, + { + symbol: 'stPOL', + address: '0x2ff4390dB61F282Ef4E6D4612c776b809a541753', + priceId: 'polygon-ecosystem-token', + }, ]; const fetchPrice = async (tokenId) => { @@ -70,16 +93,32 @@ const fetchPool = async (pool) => { const price = await fetchPrice(priceId); const response = await getData(SUBGRAPH_URL, JSON.stringify({ query })); - if ( - !response || - !response.data || - !response.data.linkStakingDistributions || - !response.data.linkStakingDistributions[0] - ) { + if (!response || !response.data) { throw new Error('Invalid data structure received from subgraph'); } - const distribution = response.data.linkStakingDistributions[0]; + // Determine which distribution data to use based on symbol + let distribution; + if (symbol === 'stLINK') { + if ( + !response.data.linkStakingDistributions || + !response.data.linkStakingDistributions[0] + ) { + throw new Error('Invalid LINK staking distribution data'); + } + distribution = response.data.linkStakingDistributions[0]; + } else if (symbol === 'stPOL') { + if ( + !response.data.polStakingDistributions || + !response.data.polStakingDistributions[0] + ) { + throw new Error('Invalid POL staking distribution data'); + } + distribution = response.data.polStakingDistributions[0]; + } else { + throw new Error(`Unsupported symbol: ${symbol}`); + } + const apy = parseFloat(distribution.reward_rate); const totalStakedInWei = distribution.total_staked; const totalStaked = parseFloat(ethers.utils.formatEther(totalStakedInWei)); @@ -88,7 +127,7 @@ const fetchPool = async (pool) => { return { pool: `${address}-${CHAIN_NAME}`.toLowerCase(), chain: CHAIN_NAME, - project: 'stake.link-liquid', + project: 'stake.link-liquid-staking', symbol, tvlUsd: tvl, apyBase: apy,