From 523d3783421919fe0255ef4446f1178b0f7ead41 Mon Sep 17 00:00:00 2001 From: 0xpeluche <0xpeluche@proton.me> Date: Mon, 30 Sep 2024 10:11:43 +0200 Subject: [PATCH] Fix: Quicksilver (filter out undefined) --- projects/quicksilver/index.js | 37 +++++++++-------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/projects/quicksilver/index.js b/projects/quicksilver/index.js index 8e135e4c820b..342ac38365e9 100644 --- a/projects/quicksilver/index.js +++ b/projects/quicksilver/index.js @@ -16,32 +16,15 @@ const coinGeckoIds = { async function tvl() { const balances = {}; + const { zones } = await get(endPoints.quicksilver + "/quicksilver/interchainstaking/v1/zones"); + const { supply } = await get(endPoints.quicksilver + "/cosmos/bank/v1beta1/supply"); - const { zones } = await get( - endPoints.quicksilver + "/quicksilver/interchainstaking/v1/zones" - ); - const { supply } = await get( - endPoints.quicksilver + "/cosmos/bank/v1beta1/supply" - ); - - zones.map((zone) => { - const balance = supply.find((coin) => { - return coin.denom === zone.local_denom; - }); - let amount = balance.amount / 1e6; - if (zone.base_denom === "adydx") - amount = balance.amount / 1e18 - + zones.forEach((zone) => { + const balance = supply.find((coin) => coin.denom === zone.local_denom); + if (!balance) return + const amount = zone.base_denom === "adydx" ? balance.amount / 1e18 : balance.amount / Math.pow(10, 6) const id = coinGeckoIds[zone.base_denom] - if (!id) { - throw new Error("Missing CoinGecko ID for denom " + zone.base_denom); - } - - sdk.util.sumSingleBalance( - balances, - id, - amount * zone.redemption_rate - ); + sdk.util.sumSingleBalance(balances, id, amount * zone.redemption_rate); }); return balances; @@ -50,7 +33,5 @@ async function tvl() { module.exports = { timetravel: false, methodology: "Sum of all the tokens that are liquid staked on Quicksilver", - quicksilver: { - tvl, - }, -}; // node test.js projects/quicksilver/index.js + quicksilver: { tvl }, +};