-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtx_get.py
executable file
·62 lines (47 loc) · 1.58 KB
/
tx_get.py
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
#!/usr/bin/env python
#
# This script get transaction hashes from the events.
#
# Warning: for now, always assumes that one event - one tx.
# This is not always true
import os
YEAR = os.getenv("YEAR")
if YEAR is None or len(YEAR) == 0:
YEAR = "2023"
POOL = os.getenv("POOL")
if POOL is None or len(POOL) == 0:
POOL = "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc" # v2 USDC/ETH
POOL = POOL.lower()
DECIMALS = os.getenv("DECIMALS")
if DECIMALS is None or len(DECIMALS) == 0:
DECIMALS = 6 # for USDC
DECIMALS = int(DECIMALS)
VERSION = os.getenv("VERSION")
if VERSION is None or len(VERSION) == 0:
VERSION = 2
print(f"using pool {POOL} on Uniswap v{VERSION}, year {YEAR}, token0 decimals {DECIMALS}")
self_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(self_dir, "data", f"uniswap-v{VERSION}-swaps", YEAR)
def load_csv(filename):
result = []
with open(os.path.join(data_dir, filename)) as f:
f.readline() # skip the header
for line in f.readlines():
fields = line.strip().split(",")
if len(fields) == 0:
continue
pool = fields[2]
if pool != POOL:
continue
result.append(fields[-1])
return result
def main():
with open(f"tx-v{VERSION}-{YEAR}-{POOL}.csv", "w") as outf:
for filename in sorted(os.listdir(data_dir)):
if "-swaps.csv" in filename:
txs = load_csv(filename)
for tx in txs:
outf.write(tx)
outf.write('\n')
if __name__ == "__main__":
main()