Skip to content

Commit

Permalink
avantis
Browse files Browse the repository at this point in the history
  • Loading branch information
skords committed Mar 5, 2024
1 parent 88cea39 commit 057326d
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
58 changes: 58 additions & 0 deletions dexs/avantis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Chain } from "@defillama/sdk/build/general";
import { CHAIN } from "../../helpers/chains";
import { SimpleAdapter } from "../../adapters/types";
import fetchURL from "../../utils/fetchURL";
import { getTimestampAtStartOfDayUTC } from "../../utils/date";
import { FetchResultVolume } from "../../adapters/types";

interface IData {
success: boolean;
cumulativeVolume: number;
history: {
date: string;
volume: number;
buyVolume: number;
sellVolume: number;
cumulativeVolume: number;
}[];
}

const API_URL = "https://api.avantisfi.com/v1";

const fetchData = (_: Chain) => {
return async (timestamp: number): Promise<FetchResultVolume> => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp);

// Convert timestamp to Date object and format to YYYY-MM-DD in UTC
const date = new Date(todaysTimestamp * 1000);
const dateStr = date.toISOString().split("T")[0];

// Find difference in days between today and the timestamp
const today = new Date();
const diffTime = Math.abs(today.getTime() - date.getTime());
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

const url = `${API_URL}/history/analytics/daily-volumes/${diffDays}`;
const value: IData = await fetchURL(url);
if (!value.success) throw new Error("Failed to fetch data");

const dailyVolume = value.history.find((d) => d.date === dateStr)?.volume;
const totalVolume = value.history[value.history.length - 1]?.cumulativeVolume;
return {
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
totalVolume: totalVolume ? `${totalVolume}` : undefined,
timestamp: todaysTimestamp,
};
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BASE]: {
fetch: fetchData(CHAIN.BASE),
start: 1706313600,
},
},
};

export default adapter;
59 changes: 59 additions & 0 deletions fees/avantis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Chain } from "@defillama/sdk/build/general";
import { CHAIN } from "../../helpers/chains";
import { SimpleAdapter } from "../../adapters/types";
import fetchURL from "../../utils/fetchURL";
import { getTimestampAtStartOfDayUTC } from "../../utils/date";
import { FetchResultFees } from "../../adapters/types";

interface IData {
success: boolean;
cumulativeFee: number;
history: {
date: string;
totalFees: number;
cumulativeFee: number;
totalClosingFee: number;
totalOpeningFee: number;
totalRolloverFee: number;
}[];
}

const API_URL = "https://api.avantisfi.com/v1";

const fetchData = (_: Chain) => {
return async (timestamp: number): Promise<FetchResultFees> => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp);

// Convert timestamp to Date object and format to YYYY-MM-DD in UTC
const date = new Date(todaysTimestamp * 1000);
const dateStr = date.toISOString().split("T")[0];

// Find difference in days between today and the timestamp
const today = new Date();
const diffTime = Math.abs(today.getTime() - date.getTime());
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

const url = `${API_URL}/history/analytics/total-fees/${diffDays}`;
const value: IData = await fetchURL(url);
if (!value.success) throw new Error("Failed to fetch data");

const dailyFee = value.history.find((d) => d.date === dateStr)?.totalFees;
const totalFees = value.history[value.history.length - 1]?.cumulativeFee;
return {
dailyUserFees: dailyFee ? `${dailyFee}` : undefined,
totalUserFees: totalFees ? `${totalFees}` : undefined,
timestamp: todaysTimestamp,
};
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BASE]: {
fetch: fetchData(CHAIN.BASE),
start: 1706313600,
},
},
};

export default adapter;

0 comments on commit 057326d

Please sign in to comment.