|
1 |
| -const utils = require("../helper/utils"); |
2 |
| -const { getApiTvl } = require("../helper/historicalApi"); |
3 |
| - |
| 1 | +const { get } = require('../helper/http') |
4 | 2 | const AQUA_STATS_URL = "https://amm-api.aqua.network/api/external/v1/statistics/totals/?size=all"
|
5 | 3 |
|
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; |
| 4 | +let _data |
| 5 | + |
| 6 | +async function getData() { |
| 7 | + if (!_data) |
| 8 | + _data = get(AQUA_STATS_URL) |
| 9 | + const data = await _data |
| 10 | + const res = {} |
| 11 | + data.forEach((item) => { |
| 12 | + res[item.date] = item.tvl / 1e8 |
| 13 | + }) |
| 14 | + return res |
23 | 15 | }
|
24 | 16 |
|
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; |
| 17 | +function formatUnixTimestamp(unixTimestamp) { |
| 18 | + const date = new Date(unixTimestamp * 1000); // Convert Unix timestamp to milliseconds |
| 19 | + const year = date.getFullYear(); |
| 20 | + const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based |
| 21 | + const day = String(date.getDate()).padStart(2, '0'); |
| 22 | + return `${year}-${month}-${day}`; |
33 | 23 | }
|
34 | 24 |
|
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 |
| - }); |
| 25 | +async function tvl(api) { |
| 26 | + const key = formatUnixTimestamp(api.timestamp) |
| 27 | + const allData = await getData() |
| 28 | + const usdValue = allData[key] |
| 29 | + if (!usdValue) |
| 30 | + throw new Error('No data found for current date'); |
| 31 | + api.addCGToken('tether', usdValue) |
46 | 32 | }
|
47 | 33 |
|
48 | 34 | module.exports = {
|
| 35 | + start: 1719792000, |
49 | 36 | misrepresentedTokens: true,
|
50 | 37 | methodology:
|
51 | 38 | '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/".',
|
|
0 commit comments