-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathslingshot.py
More file actions
46 lines (41 loc) · 1.6 KB
/
slingshot.py
File metadata and controls
46 lines (41 loc) · 1.6 KB
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
import requests
from termcolor import cprint
from network import Networks
def trade(network, tf: str, tt: str, amount: int, wallet_address: str):
url = 'https://slingshot.finance/api/v3/trade/'
json = {
'from': tf,
'fromAmount': str(amount),
'gasOptimized': False,
'limit': "99",
'recipient': wallet_address,
'threeHop': True,
'to': tt,
'_unsafe': False,
}
headers = {}
match (network):
case Networks.POLYGON:
headers['liquidityzone'] = 'matic'
case Networks.ARBITRUM:
json['forcedDexes'] = 'univ3_arbitrum'
headers['liquidityzone'] = 'arbitrum'
case Networks.OPTIMISM:
json['forcedDexes'] = 'univ3_optimism'
headers['liquidityzone'] = 'optimism'
return requests.post(url=url, json=json, headers=headers).json()
def encodeSushi(tf: str, tt: str, amount: int) -> str:
tf_formated = tf[2:]
tt_formated = tt[2:]
return (
'0xef5dab3a'
+ amount.to_bytes(32, 'big').hex()
+ '0000000000000000000000000000000000000000000000000000000000000080'
+ '00000000000000000000000000000000000000000000000000000000000000e0'
+ '0000000000000000000000000000000000000000000000000000000000000001'
+ '0000000000000000000000000000000000000000000000000000000000000002'
+ '0'*(64-len(tf_formated))+tf_formated
+ '0'*(64-len(tt_formated))+tt_formated
+ '0000000000000000000000000000000000000000000000000000000000000001'
+ '00000000000000000000000000000000000000000000000000000000000001f4'
)