|
| 1 | +const utils = require("../helper/utils"); |
| 2 | +const { getApiTvl } = require("../helper/historicalApi"); |
| 3 | + |
| 4 | +const AQUA_STATS_URL = "https://amm-api.aqua.network/api/external/v1/statistics/totals/?size=all" |
| 5 | + |
| 6 | +function findClosestDate(items) { |
| 7 | + const currentDate = new Date().getTime(); |
| 8 | + |
| 9 | + let closestItem = null; |
| 10 | + let closestDiff = Infinity; |
| 11 | + |
| 12 | + for (let item of items) { |
| 13 | + const itemDate = new Date(item.date).getTime(); |
| 14 | + const diff = Math.abs(currentDate - itemDate); |
| 15 | + |
| 16 | + if (diff < closestDiff) { |
| 17 | + closestItem = item; |
| 18 | + closestDiff = diff; |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + return closestItem; |
| 23 | +} |
| 24 | + |
| 25 | +async function current() { |
| 26 | + var aquaHistoricalData = ( |
| 27 | + await utils.fetchURL(AQUA_STATS_URL) |
| 28 | + ).data; |
| 29 | + |
| 30 | + const currentItem = findClosestDate(aquaHistoricalData); |
| 31 | + |
| 32 | + return parseFloat(currentItem.tvl) / 10e7; |
| 33 | +} |
| 34 | + |
| 35 | +function tvl(time) { |
| 36 | + return getApiTvl(time, current, async () => { |
| 37 | + var aquaHistoricalData = ( |
| 38 | + await utils.fetchURL(AQUA_STATS_URL) |
| 39 | + ).data; |
| 40 | + |
| 41 | + return aquaHistoricalData.map((item) => ({ |
| 42 | + date: new Date(item.date), |
| 43 | + totalLiquidityUSD: parseFloat(item.tvl) / 10e7, |
| 44 | + })); |
| 45 | + }); |
| 46 | +} |
| 47 | + |
| 48 | +module.exports = { |
| 49 | + methodology: |
| 50 | + '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/".', |
| 51 | + stellar: {tvl}, |
| 52 | +}; |
0 commit comments