Skip to content

Commit

Permalink
streamflow: return tvl by token
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolley committed Jul 19, 2024
1 parent 8eec7d5 commit 17be21b
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions projects/streamflow/index.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
};
});

0 comments on commit 17be21b

Please sign in to comment.