Skip to content

Commit

Permalink
update aqua network DefiLlama#11386
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Aug 23, 2024
1 parent 76ef653 commit 031673c
Showing 1 changed file with 26 additions and 39 deletions.
65 changes: 26 additions & 39 deletions projects/aqua-network/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
const utils = require("../helper/utils");
const { getApiTvl } = require("../helper/historicalApi");

const { get } = require('../helper/http')
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;
let _data

async function getData() {
if (!_data)
_data = get(AQUA_STATS_URL)
const data = await _data
const res = {}
data.forEach((item) => {
res[item.date] = item.tvl / 1e8
})
return res
}

async function current() {
var aquaHistoricalData = (
await utils.fetchURL(AQUA_STATS_URL)
).data;

const currentItem = findClosestDate(aquaHistoricalData);

return parseFloat(currentItem.tvl) / 10e7;
function formatUnixTimestamp(unixTimestamp) {
const date = new Date(unixTimestamp * 1000); // Convert Unix timestamp to milliseconds
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}

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,
}));
});
async function tvl(api) {
const key = formatUnixTimestamp(api.timestamp)
const allData = await getData()
const usdValue = allData[key]
if (!usdValue)
throw new Error('No data found for current date');
api.addCGToken('tether', usdValue)
}

module.exports = {
start: 1719792000,
misrepresentedTokens: true,
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/".',
Expand Down

0 comments on commit 031673c

Please sign in to comment.