forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aqua-network adapter (DefiLlama#11374)
* Add aqua-network tvl adapter * fix: api calls * fix texts
- Loading branch information
1 parent
f624aa2
commit e29a0de
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | ||
}; |