Skip to content

Commit

Permalink
Added support for Fees and Revenue share
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-fusion committed Jul 25, 2023
1 parent 88b3929 commit 6f4c317
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions dexs/fusionx-v3/index.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,42 @@
import { FetchResultVolume, SimpleAdapter } from "../../adapters/types";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { request } from "graphql-request";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { Chain } from "@defillama/sdk/build/general";
import { DEFAULT_TOTAL_VOLUME_FIELD, getGraphDimensions } from "../../helpers/getUniSubgraph";

interface IGraph {
dailyTradeVolumeUSD: string;
dayID: string;
const v3Endpoints = {
[CHAIN.MANTLE]: "https://graph.fusionx.finance/subgraphs/name/fusionx/exchange-v3"
}

interface IData {
volumeUSD: IGraph;
}

type TEndpoint = {
[s: string | Chain]: string;
};

const endpoints: TEndpoint = {
[CHAIN.MANTLE]:"https://graph.fusionx.finance/subgraphs/name/fusionx/exchange-v3",
};
const VOLUME_USD = "volumeUSD";

const fetchVolume = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultVolume> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(
new Date(timestamp * 1000)
);
const fromTimestamp = dayTimestamp - 60 * 60 * 24
const toTimestamp = dayTimestamp
const query = `
{
poolDayDatas(where:{date_gte: ${fromTimestamp} date_lte: ${toTimestamp}}) {
volumeUSD
date
}
}`;
const response: IData[] = (await request(endpoints[chain], query)).poolDayDatas;
const dailyVolume = response.filter((e: IData) => Number(e.volumeUSD) < 100_000_000)
.reduce((a: number, b: IData) => a + Number(b.volumeUSD), 0)
return {
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
};
};
};
const v3Graphs = getGraphDimensions({
graphUrls: v3Endpoints,
totalVolume: {
factory: "factories",
field: DEFAULT_TOTAL_VOLUME_FIELD,
},
dailyVolume: {
factory: "fusionXDayData",
field: VOLUME_USD,
},
dailyFees: {
factory: "fusionXDayData",
field: "feesUSD",
},
feesPercent: {
type: "fees",
ProtocolRevenue: 16.7,
HoldersRevenue: 16.7,
Fees: 100,
UserFees: 100, // User fees are 100% of collected fees
SupplySideRevenue: 66.6, // 66% of fees are going to LPs
Revenue: 33.4 // Revenue is 33% of collected fees
}
});

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.MANTLE]: {
fetch: fetchVolume(CHAIN.MANTLE),
fetch: v3Graphs(CHAIN.MANTLE),
start: async () => 1689206400,
},
},
Expand Down

0 comments on commit 6f4c317

Please sign in to comment.