Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix volume swapline #577

Merged
merged 1 commit into from
Jun 28, 2023
Merged
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
49 changes: 35 additions & 14 deletions dexs/swapline/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import fetchURL from "../../utils/fetchURL"
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const endpoints = {
[CHAIN.FANTOM]: "https://api.thegraph.com/subgraphs/name/0xhans1/metropolis-v2",
const historicalVolumeEndpoint = "https://api.swapline.com/api/v1/protocol-chartdata?aggregate=true"

interface IVolumeall {
volumeUSD: number;
date: number;
}

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

const dailyVolume = historicalVolume
.find(dayItem => dayItem.date === dayTimestamp)?.volumeUSD

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


const adapter: SimpleAdapter = {
adapter: {
[CHAIN.FANTOM]: {
fetch,
start: async () => 1680048000,
},
},
};

const adapter = univ2Adapter(endpoints, {
factoriesName: "lbfactories",
dayData: "traderJoeDayData",
dailyVolume: "volumeUSD",
totalVolume: "volumeUSD",
dailyVolumeTimestampField: "date"
});

// setting start time to day metropolis adapter was disabled + started tracking swapline
// after swapline acquisition of metropolis
adapter.adapter.fantom.start = async () => 1680048000;
export default adapter;
Loading