-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.ts
63 lines (55 loc) · 1.62 KB
/
index.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
62
63
import { FetchOptions, FetchResultVolume, SimpleAdapter } from "../../adapters/types"
import { CHAIN } from "../../helpers/chains"
const gurar = '0x2073D8035bB2b0F2e85aAF5a8732C6f397F9ff9b';
const abis: any = {
"forSwaps": "function forSwaps() view returns ((address lp, bool stable, address token0, address token1, address factory)[])"
}
interface IForSwap {
lp: string;
token0: string;
token1: string;
}
interface ILog {
address: string;
data: string;
transactionHash: string;
topics: string[];
}
const event_swap = 'event Swap(address indexed sender,address indexed to,uint256 amount0In,uint256 amount1In,uint256 amount0Out,uint256 amount1Out)'
const fetch = async (timestamp: number, _: any, { api, getLogs, createBalances, }: FetchOptions): Promise<FetchResultVolume> => {
const dailyVolume = createBalances()
const forSwaps: IForSwap[] = (await api.call({
target: gurar,
abi: abis.forSwaps,
chain: CHAIN.BASE,
})).map((e: any) => {
return {
lp: e.lp,
token0: e.token0,
token1: e.token1,
}
})
const targets = forSwaps.map((forSwap: IForSwap) => forSwap.lp)
const logs: ILog[][] = await getLogs({
targets,
eventAbi: event_swap,
flatten: false,
})
logs.forEach((logs: ILog[], idx: number) => {
const { token0, token1 } = forSwaps[idx]
logs.forEach((log: any) => {
dailyVolume.add(token0, log.amount0Out)
dailyVolume.add(token1, log.amount1Out)
})
})
return { dailyVolume, timestamp }
}
const adapters: SimpleAdapter = {
adapter: {
[CHAIN.BASE]: {
fetch: fetch as any,
start: 1693180800,
}
}
}
export default adapters;