-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from ekmanss/master
add project:EDE(BASE) fees
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |