Skip to content

Commit 031673c

Browse files
committed
update aqua network DefiLlama#11386
1 parent 76ef653 commit 031673c

File tree

1 file changed

+26
-39
lines changed

1 file changed

+26
-39
lines changed

projects/aqua-network/index.js

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
1-
const utils = require("../helper/utils");
2-
const { getApiTvl } = require("../helper/historicalApi");
3-
1+
const { get } = require('../helper/http')
42
const AQUA_STATS_URL = "https://amm-api.aqua.network/api/external/v1/statistics/totals/?size=all"
53

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
2315
}
2416

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}`;
3323
}
3424

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)
4632
}
4733

4834
module.exports = {
35+
start: 1719792000,
4936
misrepresentedTokens: true,
5037
methodology:
5138
'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

Comments
 (0)