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",