|
1 |
| -import { SimpleAdapter } from "../../adapters/types"; |
2 |
| -import { CHAIN } from "../../helpers/chains"; |
3 |
| -import { httpGet } from "../../utils/fetchURL"; |
4 |
| - |
5 |
| -const endpoint = "https://eos.hyperion.eosrio.io/v2"; |
6 |
| - |
7 |
| -interface ActionData { |
8 |
| - account_action_seq: number; |
9 |
| - act: { |
10 |
| - name: string; |
11 |
| - data: { |
12 |
| - quantity?: string; |
13 |
| - contract?: string; |
14 |
| - ev?: { |
15 |
| - price: number; |
16 |
| - base_quantity: string; |
17 |
| - quote_quantity: string; |
18 |
| - time: string; |
19 |
| - [key: string]: any; |
20 |
| - }; |
21 |
| - [key: string]: any; |
22 |
| - }; |
23 |
| - }; |
24 |
| - block_time: string; |
25 |
| - [key: string]: any; |
26 |
| -} |
27 |
| - |
28 |
| -interface HyperionResponse { |
29 |
| - actions: ActionData[]; |
30 |
| - total: number; |
31 |
| -} |
32 |
| -async function getContractActions( |
33 |
| - contract: string, |
34 |
| - actionNames: string | string[], |
35 |
| - startDate: string, |
36 |
| - endDate: string |
37 |
| -): Promise<ActionData[]> { |
38 |
| - const allActions: ActionData[] = []; |
39 |
| - let skip = 0; |
40 |
| - const limit = 100; |
41 |
| - let hasMore = true; |
42 |
| - |
43 |
| - const actionNameParam = Array.isArray(actionNames) |
44 |
| - ? actionNames.map((action) => `${contract}:${action}`).join(",") |
45 |
| - : `${contract}:${actionNames}`; |
46 |
| - |
47 |
| - while (hasMore) { |
48 |
| - const url = `${endpoint}/history/get_actions?account=${contract}&limit=${limit}&skip=${skip}&after=${startDate}&before=${endDate}&filter=${actionNameParam}`; |
49 |
| - const response: HyperionResponse = await httpGet(url); |
50 |
| - |
51 |
| - const actions = response.actions || []; |
52 |
| - if (actions.length === 0) break; |
53 |
| - |
54 |
| - allActions.push(...actions); |
55 |
| - |
56 |
| - skip += limit; |
57 |
| - hasMore = actions.length === limit; |
58 |
| - } |
59 |
| - |
60 |
| - return allActions; |
61 |
| -} |
62 |
| - |
63 |
| -function parseQuantity(quantityStr: string): number { |
64 |
| - const [amount] = quantityStr.split(" "); |
65 |
| - return parseFloat(amount); |
66 |
| -} |
67 |
| - |
68 |
| -function formatDate(date: Date): string { |
69 |
| - return date.toISOString(); |
70 |
| -} |
| 1 | +import { CHAIN } from "../../helpers/chains" |
| 2 | +import { httpGet } from "../../utils/fetchURL" |
71 | 3 |
|
72 | 4 | async function fetch() {
|
73 |
| - const now = new Date(); |
74 |
| - const oneDayAgo = new Date(now); |
75 |
| - oneDayAgo.setDate(oneDayAgo.getDate() - 1); |
76 |
| - |
77 |
| - const startDate = formatDate(oneDayAgo); |
78 |
| - const endDate = formatDate(now); |
79 |
| - |
80 |
| - const actions = await getContractActions( |
81 |
| - "event.velox", |
82 |
| - "emitfilled", |
83 |
| - startDate, |
84 |
| - endDate |
85 |
| - ); |
86 |
| - |
87 |
| - let dailyVolume = 0; |
88 |
| - |
89 |
| - actions.forEach((action) => { |
90 |
| - const eventData = action.act.data.ev; |
91 |
| - if (!eventData) return; |
92 |
| - |
93 |
| - const quoteAmount = parseQuantity(eventData.quote_quantity); |
94 |
| - dailyVolume += quoteAmount; |
95 |
| - }); |
96 |
| - |
97 |
| - return { dailyVolume }; |
| 5 | + const endpoint = `https://api.1dex.com/24h-trade-info` |
| 6 | + const { data: { volume_usdt: dailyVolume } } = await httpGet(endpoint) |
| 7 | + return { dailyVolume, } |
98 | 8 | }
|
99 | 9 |
|
100 |
| -const adapter: SimpleAdapter = { |
| 10 | +export default { |
101 | 11 | adapter: {
|
102 | 12 | [CHAIN.EOS]: {
|
103 | 13 | fetch,
|
104 | 14 | start: "2025-04-15",
|
105 | 15 | runAtCurrTime: true,
|
106 | 16 | },
|
107 | 17 | },
|
108 |
| -}; |
109 |
| - |
110 |
| -export default adapter; |
| 18 | +} |
0 commit comments