forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IndigoProtocol/ Add Yields for Indigo Stability Pools (DefiLlama#1301)
* IndigoProtocol/ Add Yields for Indigo Stability Pools - create appropriate functionality to get APY for each Stability Pool - fetch Prices/APR/AssetAnalytics/ADA price to USD - calculate TVL * IndigoProtocol/ Add Indigo Stability Pools - update response of TVL - update APY rewards * IndigoProtocol/ Add Indigo Stability Pools - update response of TVL - update APY rewards
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const axios = require("axios") | ||
|
||
async function get(endpoint, options) { | ||
try { | ||
return (await axios.get(endpoint, options)).data | ||
} catch (e) { | ||
throw new Error(`Failed to get ${endpoint}`) | ||
} | ||
} | ||
|
||
async function post(endpoint, body, options) { | ||
try { | ||
return (await axios.post(endpoint, body, options)).data | ||
} catch (e) { | ||
throw new Error(`Failed to post ${endpoint}`) | ||
} | ||
} | ||
|
||
module.exports = { | ||
get, | ||
post | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const { get, post } = require('./http-helper') | ||
|
||
// Get Pool Data for each Stability Pool | ||
async function apy() { | ||
const stabilityPools = await fetchStabilityPools(); | ||
const adaPriceUsd = await fetchAdaPriceToUsd(); | ||
|
||
return Promise.all(stabilityPools.map(async (pool) => { | ||
const adaRewardsKey = `sp_${pool.asset}_ada`; | ||
const indyRewardsKey = `sp_${pool.asset}_indy`; | ||
|
||
const [adaApy, indyApy] = await Promise.all([ | ||
fetchApr(adaRewardsKey), | ||
fetchApr(indyRewardsKey) | ||
]); | ||
|
||
const assetAnalytics = await fetchAssetAnalytics(pool.asset); | ||
const tvlUsd = await calculateTvlUsd(assetAnalytics, adaPriceUsd); | ||
|
||
return { | ||
pool: pool.asset, | ||
chain: "Cardano", | ||
project: "indigo", | ||
symbol: pool.asset, | ||
apyReward: (adaApy || 0) + (indyApy || 0), | ||
rewardTokens: ['ADA', 'INDY'], | ||
underlyingTokens: [pool.asset], | ||
tvlUsd: Number(tvlUsd), | ||
}; | ||
})); | ||
} | ||
|
||
// fetch stability pools | ||
async function fetchStabilityPools() { | ||
return await get(`https://analytics.indigoprotocol.io/api/stability-pools`); | ||
} | ||
|
||
// Fetch APR for each Stability Pool | ||
async function fetchApr(key) { | ||
return await post(`https://analytics.indigoprotocol.io/api/apr/?key=${key}`) | ||
.then(res => { | ||
return parseFloat(res.value) || 0; | ||
}) | ||
.catch((error) => { | ||
console.error(`Error fetching APR for ${key}:`, error); | ||
return 0; | ||
}); | ||
} | ||
|
||
// Fetch iAsset analytics for a specific asset | ||
async function fetchAssetAnalytics(assetName) { | ||
try { | ||
const response = await get(`https://analytics.indigoprotocol.io/api/assets/${assetName}/analytics`); | ||
return response[assetName]; | ||
} catch (error) { | ||
console.error(`Error fetching analytics for ${assetName}:`, error); | ||
return null; | ||
} | ||
} | ||
|
||
// Fetch the ADA price in USD | ||
async function fetchAdaPriceToUsd() { | ||
try { | ||
const response = await get('https://analytics.indigoprotocol.io/api/price?from=ADA&to=USD'); | ||
return response.price; | ||
} catch (error) { | ||
console.error('Error fetching ADA price:', error); | ||
return 0; | ||
} | ||
} | ||
|
||
// Calculate TVL in USD | ||
async function calculateTvlUsd(assetAnalytics, adaPriceUsd) { | ||
if (!assetAnalytics) return 0; | ||
|
||
return assetAnalytics.totalValueLocked * adaPriceUsd; | ||
} | ||
|
||
module.exports = { | ||
timetravel: false, | ||
apy: apy, | ||
url: 'https://app.indigoprotocol.io/stability-pools', | ||
}; | ||
|