From 17be21b70765c2dfa34e0404c0eac20ac9806dd6 Mon Sep 17 00:00:00 2001 From: Yolley Date: Fri, 19 Jul 2024 09:50:34 +0300 Subject: [PATCH] streamflow: return tvl by token --- projects/streamflow/index.js | 41 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/projects/streamflow/index.js b/projects/streamflow/index.js index 993db79e4731..1c2ffeca4252 100644 --- a/projects/streamflow/index.js +++ b/projects/streamflow/index.js @@ -1,9 +1,7 @@ const { getCache } = require('../helper/http') -const TVL_KEY = "tvl"; -const VESTING_KEY = "tvl_vested"; -const api = - "https://metabase.internal-streamflow.com/_public/api/v1/stats/accumulated"; +const url = + "https://metabase.internal-streamflow.com/_public/api/v1/stats/accumulated/by-token"; const chains = [ "solana", "aptos", @@ -16,39 +14,36 @@ const chainMapping = { bsc: 'bnb' }; -const getValueForKey = (arr, chain, key) => { - for (let i = 0; i < arr.length; i++) { - if (arr[i].chain.toLowerCase() === (chainMapping[chain] || chain) && arr[i][key] !== undefined) { - return arr[i][key]; - } - } - return 0; -} - async function getCachedApiRespnse() { - let apiResponse = (await getCache(api)); + let apiResponse = (await getCache(url)); return apiResponse; } async function tvl(api) { - return { - tether: 0 - } -} -async function vesting(api) { - return { - tether: getValueForKey(await getCachedApiRespnse(), api.chain, VESTING_KEY), + const tokenHoldings = await getCachedApiRespnse(); + const chain = (chainMapping[api.chain] || api.chain).toUpperCase(); + + const mints = []; + const balances = []; + + for (const tokenHolding of tokenHoldings) { + if (tokenHolding.chain === chain) { + mints.push(tokenHolding.mint); + balances.push(tokenHolding.amount_locked); + } } + + api.addTokens(mints, balances); } module.exports = { methodology: 'Token breakdown: https://metabase.internal-streamflow.com/public/dashboard/fe3731c1-fbe4-4fb6-8960-515af1d6e72d', timetravel: false, - misrepresentedTokens: true, + misrepresentedTokens: false, } chains.forEach((chain) => { module.exports[chain] = { - tvl, vesting + tvl }; });