forked from Matteus1904/Arbitrage-Scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.py
92 lines (70 loc) · 2.32 KB
/
requests.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
from const import (
ALL_PAIRS_CALL_HEX,
GET_RESERVES_METHOD_ENCODED,
BALANCEOF_METHOD_ENCODED,
TOKEN0_METHOD_ENCODED,
TOKEN1_METHOD_ENCODED,
)
def generate_json_rpc(method, params, request_id=1):
return {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": request_id,
}
def get_param_all_pairs(factory_address, pair_id):
return {"to": factory_address, "data": hex(ALL_PAIRS_CALL_HEX + pair_id)}
def get_request_all_pairs(factory_address, pair_id, block_identifier, request_id):
return generate_json_rpc(
method="eth_call",
params=[get_param_all_pairs(factory_address, pair_id), hex(block_identifier)],
request_id=request_id,
)
def get_param_balanceof(token_address, balanceof_address):
param = {
"to": token_address,
"data": BALANCEOF_METHOD_ENCODED + balanceof_address[2:],
}
return param
def get_request_balanceof(token_address, wallet_address, block_identifier, request_id):
return generate_json_rpc(
method="eth_call",
params=[
get_param_balanceof(token_address, wallet_address),
hex(block_identifier),
],
request_id=request_id,
)
def get_param_get_reserves(address):
return {"to": address, "data": GET_RESERVES_METHOD_ENCODED}
def get_request_get_reserves(pair_address, block_identifier, request_id):
return generate_json_rpc(
method="eth_call",
params=[
get_param_get_reserves(pair_address),
hex(block_identifier),
],
request_id=request_id,
)
def get_param_token0(pair_address):
return {"to": pair_address, "data": TOKEN0_METHOD_ENCODED}
def get_param_token1(pair_address):
return {"to": pair_address, "data": TOKEN1_METHOD_ENCODED}
def get_request_token0(pair_address, block_identifier, request_id):
return generate_json_rpc(
method="eth_call",
params=[
get_param_token0(pair_address),
hex(block_identifier),
],
request_id=request_id,
)
def get_request_token1(pair_address, block_identifier, request_id):
return generate_json_rpc(
method="eth_call",
params=[
get_param_token1(pair_address),
hex(block_identifier),
],
request_id=request_id,
)