forked from flashbots/mev-inspect-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
106 lines (96 loc) Β· 2.57 KB
/
helpers.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from typing import List
from mev_inspect.schemas.traces import (
Classification,
ClassifiedTrace,
DecodedCallTrace,
Protocol,
TraceType,
)
def make_transfer_trace(
block_number: int,
transaction_hash: str,
trace_address: List[int],
from_address: str,
to_address: str,
token_address: str,
amount: int,
):
return DecodedCallTrace(
transaction_hash=transaction_hash,
transaction_position=0,
block_number=block_number,
type=TraceType.call,
trace_address=trace_address,
classification=Classification.transfer,
from_address=from_address,
to_address=token_address,
abi_name="ERC20",
function_name="transfer",
function_signature="transfer(address,uint256)",
inputs={
"recipient": to_address,
"amount": amount,
},
block_hash=str(block_number),
action={},
subtraces=0.0,
)
def make_swap_trace(
block_number: int,
transaction_hash: str,
trace_address: List[int],
from_address: str,
contract_address: str,
abi_name: str,
function_signature: str,
protocol: Protocol,
recipient_address: str,
recipient_input_key: str,
):
return DecodedCallTrace(
transaction_hash=transaction_hash,
transaction_position=0,
block_number=block_number,
type=TraceType.call,
trace_address=trace_address,
action={},
subtraces=0,
classification=Classification.swap,
from_address=from_address,
to_address=contract_address,
function_name="swap",
function_signature=function_signature,
inputs={recipient_input_key: recipient_address},
abi_name=abi_name,
protocol=protocol,
block_hash=str(block_number),
)
def make_unknown_trace(
block_number: int,
transaction_hash: str,
trace_address: List[int],
):
return ClassifiedTrace(
block_number=block_number,
transaction_hash=transaction_hash,
transaction_position=0,
trace_address=trace_address,
action={},
subtraces=0,
block_hash=str(block_number),
type=TraceType.call,
classification=Classification.unknown,
)
def make_many_unknown_traces(
block_number: int,
transaction_hash: str,
trace_addresses: List[List[int]],
) -> List[ClassifiedTrace]:
return [
make_unknown_trace(
block_number,
transaction_hash,
trace_address,
)
for trace_address in trace_addresses
]