Skip to content

Commit

Permalink
Soroswap TVL Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
abstract829 committed Jun 21, 2024
1 parent 9efaaae commit 5091319
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions projects/soroswap/index.js
Original file line number Diff line number Diff line change
@@ -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 },
};

0 comments on commit 5091319

Please sign in to comment.