-
Notifications
You must be signed in to change notification settings - Fork 858
/
camelot-v2.ts
59 lines (51 loc) · 1.6 KB
/
camelot-v2.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
import * as sdk from "@defillama/sdk";
import { Chain } from "@defillama/sdk/build/general";
import BigNumber from "bignumber.js";
import request, { gql } from "graphql-request";
import { Adapter, FetchOptions, FetchResultV2 } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
interface IPoolData {
date: number;
dailyFeeUSD: string;
}
type IURL = {
[l: string | Chain]: string;
}
const endpoints: IURL = {
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('8zagLSufxk5cVhzkzai3tyABwJh53zxn9tmUYJcJxijG')
}
const fetch = async (options: FetchOptions): Promise<FetchResultV2> => {
const graphQuery = gql
`
{
pairDayDatas(where:{date_gte:${options.fromTimestamp}, date_lte:${options.endTimestamp}, reserveUSD_gt:1000}, orderBy:dailyFeeUSD, orderDirection:desc) {
id
dailyFeeUSD
reserveUSD
}
}
`;
const graphRes: IPoolData[] = (await request(endpoints[options.chain], graphQuery)).pairDayDatas;
const dailyFeeUSD = graphRes;
const dailyFee = dailyFeeUSD.reduce((acc, pool) => {
return acc.plus(pool.dailyFeeUSD);
}, new BigNumber(0));
return {
dailyFees: dailyFee.toString(),
dailyUserFees: dailyFee.toString(),
dailyRevenue: dailyFee.multipliedBy(0.4).toString(),
dailyProtocolRevenue: dailyFee.multipliedBy(0.05).toString(),
dailyHoldersRevenue: dailyFee.multipliedBy(0.35).toString(),
dailySupplySideRevenue: dailyFee.multipliedBy(0.60).toString(),
};
}
const adapter: Adapter = {
version: 2,
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetch,
start: 1668124800,
},
},
};
export default adapter;