Skip to content

Commit

Permalink
Merge pull request DefiLlama#1245 from Scopuly/master
Browse files Browse the repository at this point in the history
Scopuly Vol
  • Loading branch information
dtmkeng authored Feb 28, 2024
2 parents 1b703e9 + f015fd1 commit 9090f4b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions dexs/Scopuly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import fetchURL from "../../utils/fetchURL"
import { Chain } from "@defillama/sdk/build/general";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import customBackfill from "../../helpers/customBackfill";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const historicalVolumeEndpoint = "https://api.scopuly.com/api/liquidity_pools_volume"

interface IVolumeall {
vol: number;
time: number;
}

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint));
const totalVolume = historicalVolume
.filter(volItem => getUniqStartOfTodayTimestamp(new Date(Number(volItem.time))) <= dayTimestamp)
.reduce((acc, { vol }) => acc + Number(vol), 0)

const dailyVolume = historicalVolume
.find(dayItem => getUniqStartOfTodayTimestamp(new Date(Number(dayItem.time))) === dayTimestamp)?.vol

return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
};
};

const getStartTimestamp = async () => {
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint));
return getUniqStartOfTodayTimestamp(new Date(historicalVolume[0].time))
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.STELLAR]: {
fetch,
start: getStartTimestamp,
customBackfill: customBackfill(CHAIN.STELLAR as Chain, (_chian: string) => fetch)
},
},
};

export default adapter;

0 comments on commit 9090f4b

Please sign in to comment.