Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions dexs/aqua-network/index.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dry-cake thanks for the PR but I have reverted it back to use version 1 because, the api returns daily data not for a arbitrary time range (per-requsite for v2 adapters)

Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
import fetchURL from "../../utils/fetchURL"
import { SimpleAdapter } from "../../adapters/types";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const AQUA_VOLUME_ENDPOINT = "https://amm-api.aqua.network/api/external/v1/statistics/totals/?size=all"

interface IVolumeAll {
volume: number;
tvl: number;
date: string;
protocol_fees: number;
lp_fees: number;
external_rewards: number;
timestamp_date_from: number;
timestamp_date_to: number;
}

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeAll[] = (await fetchURL(AQUA_VOLUME_ENDPOINT));
const fetch = async ({ fromTimestamp, toTimestamp }: FetchOptions) => {
const historicalVolume: IVolumeAll[] = (await fetchURL(AQUA_VOLUME_ENDPOINT));

const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.date).getTime() / 1000) === dayTimestamp)?.volume

return {
dailyVolume: dailyVolume ? `${Number(dailyVolume) / 1e7}` : undefined,
};
// Seems like we have here gap about 3.5 hours in to-timestamps, can u maybe explain that diff?
// Finding day period from our api, that matches llama toTimestamp (current time)
const day = historicalVolume
.find(i => toTimestamp >= i.timestamp_date_from && toTimestamp <= i.timestamp_date_to);

if (!day) {
throw new Error('No data for timestamp: ' + fromTimestamp);
}

const ProtocolFees = day.protocol_fees / 1e7
const LPFees = day.lp_fees / 1e7
const ExternalRewards = day.external_rewards / 1e7

return {
dailyVolume: day.volume / 1e7,
dailyFees: ProtocolFees + LPFees + ExternalRewards,
dailyUserFees: ProtocolFees + LPFees,
dailySupplySideRevenue: LPFees,
dailyRevenue: ProtocolFees,
dailyHoldersRevenue: ProtocolFees,
dailyBribesRevenue: ExternalRewards,
dailyProtocolRevenue: 0,
}
};

const methodology = {
dailyFees: "All fees including 100% of the swap fees and external rewards for AQUA holders.",
dailyUserFees: "100% of the swap fees",
dailyRevenue: "50% of the swap fees that are received by the protocol and then distributed between AQUA holders that voted for the markets where these fees have been collected",
dailyProtocolRevenue: "Share of the fees kept by Aquarius. Currently equals 0.",
dailyHoldersRevenue: "50% of the swap fees that are received by the protocol and then distributed between AQUA holders that voted for the markets where these fees have been collected.",
dailySupplySideRevenue: "50% of the swap fees that are shared with the Aquarius liquidity providers",
dailyBribesRevenue: "Amount of external incentives for AQUA holders voting for specific markets on Aquarius.",
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.STELLAR]: {
fetch,
start: '2024-07-01',
},
},
version: 2,
methodology,
adapter: {
[CHAIN.STELLAR]: { fetch, start: '2024-07-01' },
},
};

export default adapter;
Loading