Skip to content

Commit

Permalink
Merge pull request #739 from ekmanss/master
Browse files Browse the repository at this point in the history
add project:EDE(BASE) fees
  • Loading branch information
dtmkeng authored Aug 14, 2023
2 parents d706bc4 + fbb836c commit 6989483
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions fees/edebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Chain } from "@defillama/sdk/build/general";
import { gql, request } from "graphql-request";
import type { ChainEndpoints } from "../adapters/types";
import { Adapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getTimestampAtStartOfDayUTC } from "../utils/date";

const endpoints = {
[CHAIN.BASE ]: "https://api.studio.thegraph.com/query/51000/base_stats/version/latest",
};

const graphs = (graphUrls: ChainEndpoints) => {
return (chain: Chain) => {
return async (timestamp: number) => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp);

const graphQuery = gql`{
feeStat(id: "${todaysTimestamp}",period: "daily") {
mint
burn
marginAndLiquidation
swap
}
}`;

const graphRes = await request(graphUrls[chain], graphQuery);

const dailyFee = (
parseInt(graphRes.feeStat?.mint || 0) +
parseInt(graphRes.feeStat?.burn || 0) +
parseInt(graphRes.feeStat?.marginAndLiquidation || 0) +
parseInt(graphRes.feeStat?.swap || 0)
) / 1e30
const dailyUserFees = (
parseInt(graphRes.feeStat?.marginAndLiquidation || 0) +
parseInt(graphRes.feeStat?.swap || 0)
) / 1e30;

return {
timestamp,
dailyFees: dailyFee.toString(),
dailyUserFees: dailyUserFees.toString(),
dailyRevenue: (dailyFee * 0.3).toString()
};
};
};
};

const adapter: Adapter = {
adapter: {
[CHAIN.BASE]: {
fetch: graphs(endpoints)(CHAIN.BASE),
start: async () => 2437814 ,
meta: {
methodology: {
Fees: "All mint, burn, margin and liquidation and swap fees are collected",
UserFees: "Users pay swap fees and margin and liquidation fees",
Revenue: "Revenue is calculated as 30% of the total fee.",
}
}
},
},
};

export default adapter;

0 comments on commit 6989483

Please sign in to comment.