From 5091319a460a96783e5fc8f55e8ac79419a89ccf Mon Sep 17 00:00:00 2001 From: abstract829 Date: Fri, 21 Jun 2024 15:59:41 -0400 Subject: [PATCH] Soroswap TVL Adapter --- projects/soroswap/index.js | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 projects/soroswap/index.js diff --git a/projects/soroswap/index.js b/projects/soroswap/index.js new file mode 100644 index 000000000000..14a806760c7c --- /dev/null +++ b/projects/soroswap/index.js @@ -0,0 +1,44 @@ +const utils = require("../helper/utils"); +const { getApiTvl } = require("../helper/historicalApi"); + +const getCurrentTvl = (pools) => { + return pools?.data?.reduce((acc, pool) => { + return acc + (pool.tvl || 0); + }, 0); +}; + +const getTvlDayData = (pools) => { + const tvlChartData = {}; + + pools?.data?.forEach((pool) => { + pool.tvlChartData?.forEach((data) => { + tvlChartData[data.date] = { + tvl: (tvlChartData?.[data?.date]?.tvl || 0) + data.tvl, + date: data.date, + }; + }); + }); + + return Object.keys(tvlChartData).map((key) => ({ + date: tvlChartData[key].date, + totalLiquidityUSD: tvlChartData[key].tvl, + })); +}; + +async function tvl(time) { + const pools = await utils.fetchURL( + "https://info.soroswap.finance/api/pairs?network=MAINNET" + ); + + return getApiTvl( + time, + () => getCurrentTvl(pools), + () => getTvlDayData(pools) + ); +} + +module.exports = { + methodology: + 'TVL counts the liquidity of the Pools on AMM, data is pulled from the Soroswap Info: "https://info.soroswap.finance/".', + stellar: { tvl }, +};