|
1 | 1 | import { CHAIN } from "../../helpers/chains";
|
2 |
| -import { FetchV2 } from "../../adapters/types"; |
3 |
| -import { queryDune } from "../../helpers/dune"; |
4 |
| - |
5 |
| -const chains: Record<string, { duneChain: string; start: string }> = { |
6 |
| - [CHAIN.ETHEREUM]: { duneChain: "ethereum", start: "2023-06-22" }, |
7 |
| - [CHAIN.OPTIMISM]: { duneChain: "optimism", start: "2023-09-19" }, |
8 |
| - [CHAIN.BSC]: { duneChain: "binance", start: "2023-09-20" }, |
9 |
| - [CHAIN.POLYGON]: { duneChain: "polygon", start: "2023-09-05" }, |
10 |
| - [CHAIN.BASE]: { duneChain: "base", start: "2023-12-24" }, |
11 |
| - [CHAIN.ARBITRUM]: { duneChain: "arbitrum", start: "2023-09-11" }, |
12 |
| -}; |
13 |
| - |
14 |
| -const queryId = "4687193"; |
15 |
| - |
16 |
| -const fetchVolume = (chain: string): FetchV2 => async ({ startTimestamp, endTimestamp }) => { |
17 |
| - const chainConfig = chains[chain]; |
18 |
| - if (!chainConfig) throw new Error(`Chain configuration not found for: ${chain}`); |
19 |
| - |
20 |
| - const data = await queryDune(queryId, { |
21 |
| - timestamp_from: startTimestamp, |
22 |
| - timestamp_to: endTimestamp, |
23 |
| - chain: chainConfig.duneChain, |
24 |
| - }); |
25 |
| - |
26 |
| - const chainData = data[0]; |
27 |
| - if (!chainData) throw new Error(`Dune query failed: ${JSON.stringify(data)}`); |
28 |
| - |
29 |
| - return { |
30 |
| - dailyVolume: chainData.volume_timerange, |
31 |
| - totalVolume: chainData.total_volume, |
32 |
| - timestamp: endTimestamp, |
| 2 | +import { httpGet } from "../../utils/fetchURL"; |
| 3 | +import { Adapter, Fetch, FetchResultVolume } from "../../adapters/types"; |
| 4 | +import { getEnv } from "../../helpers/env"; |
| 5 | + |
| 6 | +function fetch(chainId: number): Fetch { |
| 7 | + return async (endTimestamp: number, _, options): Promise<FetchResultVolume> => { |
| 8 | + const totalVolume = options.createBalances(); |
| 9 | + const dailyVolume = options.createBalances(); |
| 10 | + const res = await httpGet( |
| 11 | + `https://api.enso.finance/api/v1/volume/${chainId}?timestamp=${endTimestamp}`, |
| 12 | + { |
| 13 | + headers: { |
| 14 | + Authorization: `Bearer ${getEnv("ENSO_API_KEY")}`, |
| 15 | + }, |
| 16 | + }, |
| 17 | + ); |
| 18 | + |
| 19 | + totalVolume.addUSDValue(res.totalVolume); |
| 20 | + dailyVolume.addUSDValue(res.dailyVolume); |
| 21 | + |
| 22 | + return { |
| 23 | + totalVolume, |
| 24 | + dailyVolume, |
| 25 | + timestamp: endTimestamp, |
| 26 | + }; |
33 | 27 | };
|
34 |
| -}; |
35 |
| - |
36 |
| -const adapter: any = { |
37 |
| - version: 2, |
38 |
| - isExpensiveAdapter: true, |
39 |
| - adapter: Object.fromEntries( |
40 |
| - Object.entries(chains).map(([chain, { start }]) => [ |
41 |
| - chain, |
42 |
| - { fetch: fetchVolume(chain), start }, |
43 |
| - ]) |
44 |
| - ), |
| 28 | +} |
| 29 | + |
| 30 | +const adapter: Adapter = { |
| 31 | + adapter: { |
| 32 | + [CHAIN.ETHEREUM]: { |
| 33 | + fetch: fetch(1), |
| 34 | + start: "2023-06-22", |
| 35 | + }, |
| 36 | + [CHAIN.OPTIMISM]: { |
| 37 | + fetch: fetch(10), |
| 38 | + start: "2023-09-19", |
| 39 | + }, |
| 40 | + [CHAIN.BSC]: { |
| 41 | + fetch: fetch(56), |
| 42 | + start: "2023-09-20", |
| 43 | + }, |
| 44 | + [CHAIN.POLYGON]: { |
| 45 | + fetch: fetch(137), |
| 46 | + start: "2023-09-05", |
| 47 | + }, |
| 48 | + [CHAIN.BASE]: { |
| 49 | + fetch: fetch(8453), |
| 50 | + start: "2023-12-24", |
| 51 | + }, |
| 52 | + [CHAIN.ARBITRUM]: { |
| 53 | + fetch: fetch(42161), |
| 54 | + start: "2023-09-11", |
| 55 | + }, |
| 56 | + [CHAIN.LINEA]: { |
| 57 | + fetch: fetch(59144), |
| 58 | + start: "2023-12-15", |
| 59 | + }, |
| 60 | + }, |
45 | 61 | };
|
46 | 62 |
|
47 | 63 | export default adapter;
|
0 commit comments