Skip to content

Commit 8d87c32

Browse files
holdstationthainq01treeoflife2
authored
feat: add worldchain on holdstation defuture (DefiLlama#3790)
* feat: add worldchain on holdstation defuture * fix: return empty if using historical on worldchain * fix: delete zksync era adapter * fix: fix version * refactor --------- Co-authored-by: thainq <thainguyen12.work@gmail.com> Co-authored-by: treeoflife2 <sol.analyzoor@gmail.com>
1 parent ccc508d commit 8d87c32

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

fees/holdstation-defutures.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import { FetchOptions, FetchResult, SimpleAdapter } from "../adapters/types";
33
import { CHAIN } from "../helpers/chains";
44
import { getUniqStartOfTodayTimestamp } from "../helpers/getUniSubgraphVolume";
55

6-
const historicalVolumeEndpoint = (from: string, to: string) =>
7-
`https://api-trading.holdstation.com/api/fees/summary?fromDate=${from}&toDate=${to}`;
8-
const dailyVolumeEndpoint = (from: string, to: string) =>
9-
`https://api-trading.holdstation.com/api/trading-history/volume-by-day?fromDate=${from}&toDate=${to}`;
10-
116
const historicalVolumeBerachainEndpoint = (from: string, to: string) =>
127
`https://api-trading-bera.holdstation.com/api/fees/summary/internal?fromDate=${from}&toDate=${to}`;
138
const dailyVolumeBerachainEndpoint = (from: string, to: string) =>
149
`https://api-trading-bera.holdstation.com/api/trading-history/volume-by-day?fromDate=${from}&toDate=${to}`;
1510

11+
const dailyVolumeWorldchainEndpoint = (from: string, to: string) =>
12+
`https://worldfuture.holdstation.com/api/trading-history/volume-by-day?fromDate=${from}&toDate=${to}`;
13+
1614
interface IFees {
1715
totalFee: string;
1816
govFee: string;
@@ -27,50 +25,68 @@ interface DailyVolume {
2725

2826
type URLBuilder = (from: string, to: string) => string;
2927

30-
const endpointMap: { [chain: string]: { historical: URLBuilder, daily: URLBuilder } } = {
31-
[CHAIN.ERA]: {
32-
historical: historicalVolumeEndpoint,
33-
daily: dailyVolumeEndpoint,
34-
},
28+
const endpointMap: {
29+
[chain: string]: { historical?: URLBuilder; daily: URLBuilder };
30+
} = {
3531
[CHAIN.BERACHAIN]: {
3632
historical: historicalVolumeBerachainEndpoint,
3733
daily: dailyVolumeBerachainEndpoint,
38-
}
34+
},
35+
[CHAIN.WC]: {
36+
daily: dailyVolumeWorldchainEndpoint,
37+
},
3938
};
4039

41-
const fetch = async (timestamp: number, _t: any, options: FetchOptions): Promise<FetchResult> => {
42-
40+
const fetch = async (_a: any, _b: any, options: FetchOptions) => {
4341
const { historical, daily } = endpointMap[options.chain];
4442

45-
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
46-
const fromTimestamp = new Date(dayTimestamp * 1000).toISOString().split("T")[0];
47-
const toTimestamp = new Date((dayTimestamp + 60 * 60 * 24) * 1000).toISOString().split("T")[0];
48-
const data: IFees = (await fetchURL(historical(fromTimestamp, toTimestamp))).result;
49-
const dailyVolume: DailyVolume[] = (await fetchURL(daily(fromTimestamp, fromTimestamp)));
43+
const dayTimestamp = getUniqStartOfTodayTimestamp(
44+
new Date(options.startTimestamp * 1000)
45+
);
46+
const fromTimestamp = new Date(dayTimestamp * 1000)
47+
.toISOString()
48+
.split("T")[0];
49+
const toTimestamp = new Date((dayTimestamp + 60 * 60 * 24) * 1000)
50+
.toISOString()
51+
.split("T")[0];
52+
53+
let data: IFees;
54+
if (historical) {
55+
data = (await fetchURL(historical(fromTimestamp, toTimestamp))).result;
56+
} else {
57+
data = {
58+
totalFee: "",
59+
govFee: "",
60+
vaultFee: "",
61+
};
62+
}
63+
const dailyVolume: DailyVolume[] = await fetchURL(
64+
daily(fromTimestamp, fromTimestamp)
65+
);
5066

5167
const dailyFees = data.totalFee;
5268
const dailyRevenue = data.govFee;
5369
const dailySupplySideRevenue = data.vaultFee;
5470

5571
return {
72+
dailyVolume: dailyVolume.length > 0 ? dailyVolume[0].volume : "0",
5673
dailyFees,
5774
dailyRevenue,
58-
dailyVolume: dailyVolume.length > 0 ? dailyVolume[0].volume : "0",
59-
dailySupplySideRevenue: dailySupplySideRevenue,
60-
timestamp: dayTimestamp,
75+
dailySupplySideRevenue,
6176
};
62-
}
77+
};
6378

6479
const adapter: SimpleAdapter = {
6580
version: 1,
6681
adapter: {
67-
// [CHAIN.ERA]: {
68-
// fetch,
69-
// start: '2023-05-09',
70-
// },
7182
[CHAIN.BERACHAIN]: {
7283
fetch,
73-
start: '2025-02-07',
84+
start: "2025-02-07",
85+
},
86+
[CHAIN.WC]: {
87+
fetch,
88+
runAtCurrTime: true,
89+
start: "2024-06-04",
7490
},
7591
},
7692
};

0 commit comments

Comments
 (0)