forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshadow-exchange.ts
84 lines (72 loc) · 1.96 KB
/
shadow-exchange.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as sdk from "@defillama/sdk";
import { FetchOptions, SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import request from "graphql-request";
type TStartTime = {
[key: string]: number;
};
const startTimeV2: TStartTime = {
[CHAIN.SONIC]: 1735129946,
};
export const v2Endpoints: any = {
[CHAIN.SONIC]:
sdk.graph.modifyEndpoint('HGyx7TCqgbWieay5enLiRjshWve9TjHwiug3m66pmLGR'),
};
interface IPool {
id: string;
volumeUSD: string;
feesUSD: string;
isCL: boolean;
}
export async function fetchPools(options: FetchOptions): Promise<IPool[]> {
const query = `
{
clPoolDayDatas(where:{startOfDay: ${options.startOfDay}}) {
startOfDay
volumeUSD
feesUSD
}
legacyPoolDayDatas(where:{startOfDay: ${options.startOfDay}}) {
startOfDay
volumeUSD
feesUSD
}
}
`;
const rows = await request(v2Endpoints[options.chain], query);
const res: IPool[] = [
...rows.clPoolDayDatas.map((row: any) => ({ ...row, isCL: true })),
...rows.legacyPoolDayDatas.map((row: any) => ({ ...row, isCL: false })),
]
return res
}
const fetch = async (options: FetchOptions) => {
const pools = (await fetchPools(options)).filter((pool) => pool.isCL)
const dailyFees = pools.reduce((acc, pool) => acc + Number(pool.feesUSD), 0);
const dailyVolume = pools.reduce((acc, pool) => acc + Number(pool.volumeUSD), 0);
return {
dailyVolume,
dailyFees,
dailyUserFees: dailyFees,
dailyRevenue: dailyFees,
dailyHoldersRevenue: dailyFees,
};
}
const methodology = {
UserFees: "User pays fees on each swap.",
ProtocolRevenue: "Revenue going to the protocol.",
HoldersRevenue: "User fees are distributed among holders.",
};
const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.SONIC]: {
fetch,
start: startTimeV2[CHAIN.SONIC],
meta: {
methodology: methodology
},
},
},
};
export default adapter;