Skip to content

Commit

Permalink
Merge pull request #1660 from PanoraExchange/master
Browse files Browse the repository at this point in the history
fix: DefiLlama stats for panora
  • Loading branch information
dtmkeng committed Jul 10, 2024
2 parents baea215 + 825aa1d commit b06c37c
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions aggregators/swapgpt/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,61 @@
import fetchURL from "../../utils/fetchURL"
import fetchURL from "../../utils/fetchURL";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";



interface IVolumeall {
grouptimestamp: string;
amount: string;
startDateTime: string;
dailyVolumeUSD: string;
}

const baseUrl = "https://stats.panora.exchange";
const endpoint = "stats/getDefiLamaStats";
const baseUrl = "https://stats-api.panora.exchange";
const endpoint = "getDefiLlamaStats";

const getStartOfDay = (timestamp: number) => {
const now = new Date(timestamp);

const startOfDayUTC = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
);

const startOfDayISO = startOfDayUTC.toISOString();

return startOfDayISO;
};

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(`${baseUrl}/${endpoint}`))?.volumeInUsd
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.grouptimestamp).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { amount }) => acc + Number(amount), 0)
const dayTimestamp = getStartOfDay(timestamp);

const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.grouptimestamp).getTime() / 1000) === dayTimestamp)?.amount
const historicalVolume: IVolumeall[] = (
await fetchURL(`${baseUrl}/${endpoint}`)
)?.dailyVolumeUSD;

const totalVolume = historicalVolume
.filter(
(volItem) =>
new Date(volItem.startDateTime)?.getTime() <=
new Date(dayTimestamp)?.getTime()
)
.reduce((acc, { dailyVolumeUSD }) => acc + Number(dailyVolumeUSD), 0);

const dailyVolume = historicalVolume.find(
(dayItem) =>
new Date(dayItem.startDateTime)?.getTime() ===
new Date(dayTimestamp)?.getTime()
)?.dailyVolumeUSD;

return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
totalVolume: String(totalVolume),
dailyVolume,
timestamp: new Date(dayTimestamp)?.getTime() / 1000,
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.APTOS]: {
fetch: fetch,
start: (new Date('2023-11-28T00:00:00.000Z').getTime() / 1000),
}
fetch,
start: new Date("2023-11-28T00:00:00.000Z").getTime() / 1000,
},
},
};

Expand Down

0 comments on commit b06c37c

Please sign in to comment.