/
edebase.ts
65 lines (57 loc) · 2.17 KB
/
edebase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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: 1691539200,
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;