From e29a0debe1957d68b994d935b3f80703c7557f5f Mon Sep 17 00:00:00 2001 From: Dry cake <174254844+dry-cake@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:13:31 +0200 Subject: [PATCH] Add aqua-network adapter (#11374) * Add aqua-network tvl adapter * fix: api calls * fix texts --- projects/aqua-network/index.js | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 projects/aqua-network/index.js diff --git a/projects/aqua-network/index.js b/projects/aqua-network/index.js new file mode 100644 index 000000000000..e60f8cf783c8 --- /dev/null +++ b/projects/aqua-network/index.js @@ -0,0 +1,52 @@ +const utils = require("../helper/utils"); +const { getApiTvl } = require("../helper/historicalApi"); + +const AQUA_STATS_URL = "https://amm-api.aqua.network/api/external/v1/statistics/totals/?size=all" + +function findClosestDate(items) { + const currentDate = new Date().getTime(); + + let closestItem = null; + let closestDiff = Infinity; + + for (let item of items) { + const itemDate = new Date(item.date).getTime(); + const diff = Math.abs(currentDate - itemDate); + + if (diff < closestDiff) { + closestItem = item; + closestDiff = diff; + } + } + + return closestItem; +} + +async function current() { + var aquaHistoricalData = ( + await utils.fetchURL(AQUA_STATS_URL) + ).data; + + const currentItem = findClosestDate(aquaHistoricalData); + + return parseFloat(currentItem.tvl) / 10e7; +} + +function tvl(time) { + return getApiTvl(time, current, async () => { + var aquaHistoricalData = ( + await utils.fetchURL(AQUA_STATS_URL) + ).data; + + return aquaHistoricalData.map((item) => ({ + date: new Date(item.date), + totalLiquidityUSD: parseFloat(item.tvl) / 10e7, + })); + }); +} + +module.exports = { + methodology: + 'counts the liquidity of the Pools on AMM, data is pulled from the Aquarius API: "https://amm-api.aqua.network/api/external/v1/statistics/totals/".', + stellar: {tvl}, +};