-
Notifications
You must be signed in to change notification settings - Fork 863
/
thena-v3.ts
61 lines (53 loc) · 1.66 KB
/
thena-v3.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
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, FetchResultFees } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../helpers/getUniSubgraphVolume";
import { getTimestampAtStartOfDayUTC } from "../utils/date";
interface IPoolData {
id: number;
feesUSD: string;
}
type IURL = {
[l: string | Chain]: string;
}
const endpoints: IURL = {
[CHAIN.BSC]: sdk.graph.modifyEndpoint('Hnjf3ipVMCkQze3jmHp8tpSMgPmtPnXBR38iM4ix1cLt')
}
const fetch = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultFees> => {
const todayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dateId = Math.floor(getTimestampAtStartOfDayUTC(todayTimestamp) / 86400)
const graphQuery = gql
`
{
fusionDayData(id: ${dateId}) {
id
feesUSD
}
}
`;
const graphRes: IPoolData = (await request(endpoints[chain], graphQuery)).fusionDayData;
const dailyFeeUSD = graphRes;
const dailyFee = dailyFeeUSD?.feesUSD ? new BigNumber(dailyFeeUSD.feesUSD) : undefined
if (dailyFee === undefined) return { timestamp }
return {
timestamp,
dailyFees: dailyFee.toString(),
dailyUserFees: dailyFee.toString(),
dailyRevenue: dailyFee.toString(),
dailyHoldersRevenue: dailyFee.toString(),
};
};
}
const adapter: Adapter = {
adapter: {
[CHAIN.BSC]: {
fetch: fetch(CHAIN.BSC),
start: 1681516800,
},
},
};
export default adapter;