-
Notifications
You must be signed in to change notification settings - Fork 52
/
get_failed_router_stats.py
33 lines (29 loc) · 1.06 KB
/
get_failed_router_stats.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
import json
from web3.auto import w3
# need to identify if its a cycle tx or not
router_abi = json.load(open('abi/UniswapV2Router02.json'))
router = w3.eth.contract(address=w3.toChecksumAddress("0x7a250d5630b4cf539739df2c5dacb4c659f2488d"), abi=router_abi)
def is_cycle(info):
try:
return info['path'][0] == info['path'][-1] and len(info['path']) >= 4
except:
return False
stats = {'failed_count': 0, 'failed_cost': 0}
with open('/data/tx_info/0x7a250d5630b4cf539739df2c5dacb4c659f2488d') as f:
# with open('data/0x7a250d5630b4cf539739df2c5dacb4c659f2488d') as f:
idx = 0
for line in f:
print(idx)
idx += 1
l = json.loads(line)
if l['txreceipt_status'] == 1:
continue
try:
info = router.decode_function_input(l['input'])
except:
continue
if not is_cycle(info[1]):
continue
stats['failed_count'] += 1
stats['failed_cost'] += int(l['gasPrice']) * int(l['gasUsed'])
json.dump(stats, open('data/router_fail_stats.json', 'w'))