Skip to content

Commit

Permalink
Merge pull request #577 from DefiLlama/swapline-fx
Browse files Browse the repository at this point in the history
fix volume swapline
  • Loading branch information
dtmkeng committed Jun 28, 2023
2 parents cc7037c + 4d85914 commit 47db79e
Showing 1 changed file with 35 additions and 14 deletions.
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;

0 comments on commit 47db79e

Please sign in to comment.