forked from ccyanxyz/cycle-arb-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_toppair_blockwise_reserves.py
53 lines (49 loc) · 1.68 KB
/
get_toppair_blockwise_reserves.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
import json
pairs = json.load(open('data/pairs.json'))
def get_pair(token0, token1):
for pair in pairs:
if token0 == pair['token0']['id'] and token1 == pair['token1']['id']:
return pair['id']
if token1 == pair['token0']['id'] and token0 == pair['token1']['id']:
return pair['id']
return None
counts = json.load(open('data/path_counts.json'))
top10 = list(counts.keys())[:10]
top10_path_pairs = []
top10_path_pair_addrs = []
for path in top10:
addrs = path.split('-')
token0 = addrs[0]
token1 = addrs[2]
token2 = addrs[4]
pair1 = get_pair(token0, token1)
pair2 = get_pair(token0, token2)
pair3 = get_pair(token1, token2)
top10_path_pair_addrs.append(pair1)
top10_path_pair_addrs.append(pair2)
top10_path_pair_addrs.append(pair3)
stats = {}
for addr in top10_path_pair_addrs:
stats[addr] = {}
with open('data/blockwise_reserves', 'r') as f:
idx = 0
for line in f:
info = json.loads(line)
blockNumber = list(info.keys())[0]
bn = int(blockNumber)
print(bn)
for addr in top10_path_pair_addrs:
if bn == 10000835 or bn == 0:
stats[addr][blockNumber] = {'r0': 0, 'r1': 0}
else:
try:
stats[addr][i] = stats[addr][str(bn-1)]
except:
pass
for addr in info[blockNumber].keys():
r0 = info[blockNumber][addr]['reserve0']
r1 = info[blockNumber][addr]['reserve1']
if addr in top10_path_pair_addrs:
stats[addr][bn] = {'r0': r0, 'r1': r1}
idx += 1
json.dump(stats, open('data/toppair_blockwise_reserves.json', 'w'))