Skip to content

Commit

Permalink
Add aqua-network adapter (DefiLlama#11374)
Browse files Browse the repository at this point in the history
* Add aqua-network tvl adapter

* fix: api calls

* fix texts
  • Loading branch information
dry-cake authored and tlatkdgus1 committed Nov 25, 2024
1 parent f624aa2 commit e29a0de
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions projects/aqua-network/index.js
Original file line number Diff line number Diff line change
@@ -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},
};

0 comments on commit e29a0de

Please sign in to comment.