From 074a69dd4008560201aaab68188d25a9098d4e4e Mon Sep 17 00:00:00 2001 From: Mujahid Khan <106528609+mujahidkay@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:34:26 +0500 Subject: [PATCH] feat: add IST adapter (#12765) Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> --- projects/agoric/index.js | 58 +++++++++++++++++++++++++++++++++++++ projects/helper/chains.json | 1 + 2 files changed, 59 insertions(+) create mode 100644 projects/agoric/index.js diff --git a/projects/agoric/index.js b/projects/agoric/index.js new file mode 100644 index 000000000000..dad9523b7564 --- /dev/null +++ b/projects/agoric/index.js @@ -0,0 +1,58 @@ +const { post } = require('../helper/http') + +const query = ` +query { + vaultManagerMetrics { + nodes { + liquidatingCollateralBrand + totalCollateral + } + } + oraclePrices { + nodes { + typeInAmount + typeOutAmount + typeInName + } + } + boardAuxes { + nodes { + allegedName + decimalPlaces + } + } +} +` + +const coingeckoMapping = { + 'stATOM': 'stride-staked-atom', + 'stkATOM': 'stkatom', + 'ATOM': 'cosmos', + 'stOSMO': 'stride-staked-osmo', + 'stTIA': 'stride-staked-tia', +} +const decimals = {} + +const tvl = async (api) => { + const { data: { vaultManagerMetrics, boardAuxes } } = await post('https://api.subquery.network/sq/agoric-labs/agoric-mainnet-v2', { query }) + + boardAuxes.nodes.forEach(board => { + decimals[board.allegedName] = 10 ** board.decimalPlaces + }) + + vaultManagerMetrics.nodes.forEach(vault => { + const key = vault.liquidatingCollateralBrand + if (!coingeckoMapping[key]) { + throw new Error(`Unknown coin ${key} (coingecko mapping is missing)`) + } + const decimal = decimals[key] ?? 1e6 + const balance = vault.totalCollateral / decimal + api.addCGToken(coingeckoMapping[key], balance) + }) +} + +module.exports = { + agoric: { + tvl, + }, +} diff --git a/projects/helper/chains.json b/projects/helper/chains.json index 09c5a4091ff7..c353ff3087c9 100644 --- a/projects/helper/chains.json +++ b/projects/helper/chains.json @@ -3,6 +3,7 @@ "ace", "aelf", "aeternity", + "agoric", "ailayer", "airdao", "alephium",