Skip to content

Commit 49395e7

Browse files
committed
update
– add 1inch dex – add OpenOcean dex – add GAS_MULTIPLIER settings
1 parent 8b2a378 commit 49395e7

File tree

8 files changed

+301
-29
lines changed

8 files changed

+301
-29
lines changed

config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@
154154
"router": "0x30E63157bD0bA74C814B786F6eA2ed9549507b46",
155155
"use_ref": True # If you use True, you support me 1% of the transaction amount
156156
}
157+
OPENOCEAN_CONTRACT = {
158+
"router": "0x36A1aCbbCAfca2468b85011DDD16E7Cb4d673230",
159+
"use_ref": True # If you use True, you support me 1% of the transaction amount
160+
}
161+
162+
INCH_CONTRACT = "0x6e2b76966cbd9cf4cc2fa0d76d24d5241e0abc2f"
157163

158164
BUNGEE_CONTRACT = "0x7ee459d7fde8b4a3c22b9c8c7aa52abaddd9ffd5"
159165

main.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,36 @@ def get_module():
3232
Choice("14) Make swap on Odos", swap_odos),
3333
Choice("15) Make swap on ZkSwap", swap_zkswap),
3434
Choice("16) Make swap on XYSwap", swap_xyswap),
35-
Choice("17) Make bungee refuel", bungee_refuel),
36-
Choice("18) Stargate bridge MAV", stargate_bridge),
37-
Choice("19) Deposit Eralend", deposit_eralend),
38-
Choice("20) Withdraw Eralend", withdraw_erlaned),
39-
Choice("21) Enable collateral on Eralend", enable_collateral_eralend),
40-
Choice("22) Disable collateral on Eralend", disable_collateral_eralend),
41-
Choice("23) Deposit Basilisk", deposit_basilisk),
42-
Choice("24) Withdraw Basilisk", withdraw_basilisk),
43-
Choice("25) Enable collateral on Basilisk", enable_collateral_basilisk),
44-
Choice("26) Disable collateral on Basilisk", disable_collateral_basilisk),
45-
Choice("27) Deposit ReactorFusion", deposit_reactorfusion),
46-
Choice("28) Withdraw ReactorFusion", withdraw_reactorfusion),
47-
Choice("29) Enable collateral on ReactorFusion", enable_collateral_reactorfusion),
48-
Choice("30) Disable collateral on ReactorFusion", disable_collateral_reactorfusion),
49-
Choice("31) Create NFT collection on Omnisea", create_omnisea),
50-
Choice("32) Mint and bridge NFT L2Telegraph", bridge_nft),
51-
Choice("33) Mint Tavaera ID + NFT", mint_tavaera),
52-
Choice("34) Mint NFT", mint_nft),
53-
Choice("35) Mint ZKS Domain", mint_zks_domain),
54-
Choice("36) Mint Era Domain", mint_era_domain),
55-
Choice("37) Send message L2Telegraph", send_message),
56-
Choice("38) Dmail sending mail", send_mail),
57-
Choice("39) MultiSwap", swap_multiswap),
58-
Choice("40) Use custom routes", custom_routes),
59-
Choice("41) MultiApprove", multi_approve),
60-
Choice("42) Deploy contract and mint token", deploy_contract_zksync),
61-
Choice("43) Check transaction count", "tx_checker"),
62-
Choice("44) Exit", "exit"),
35+
Choice("17) Make swap on OpenOcean", swap_openocean),
36+
Choice("18) Make swap on 1inch", swap_inch),
37+
Choice("19) Make bungee refuel", bungee_refuel),
38+
Choice("20) Stargate bridge MAV", stargate_bridge),
39+
Choice("21) Deposit Eralend", deposit_eralend),
40+
Choice("22) Withdraw Eralend", withdraw_erlaned),
41+
Choice("23) Enable collateral on Eralend", enable_collateral_eralend),
42+
Choice("24) Disable collateral on Eralend", disable_collateral_eralend),
43+
Choice("25) Deposit Basilisk", deposit_basilisk),
44+
Choice("26) Withdraw Basilisk", withdraw_basilisk),
45+
Choice("27) Enable collateral on Basilisk", enable_collateral_basilisk),
46+
Choice("28) Disable collateral on Basilisk", disable_collateral_basilisk),
47+
Choice("29) Deposit ReactorFusion", deposit_reactorfusion),
48+
Choice("30) Withdraw ReactorFusion", withdraw_reactorfusion),
49+
Choice("31) Enable collateral on ReactorFusion", enable_collateral_reactorfusion),
50+
Choice("32) Disable collateral on ReactorFusion", disable_collateral_reactorfusion),
51+
Choice("33) Create NFT collection on Omnisea", create_omnisea),
52+
Choice("34) Mint and bridge NFT L2Telegraph", bridge_nft),
53+
Choice("35) Mint Tavaera ID + NFT", mint_tavaera),
54+
Choice("36) Mint NFT", mint_nft),
55+
Choice("37) Mint ZKS Domain", mint_zks_domain),
56+
Choice("38) Mint Era Domain", mint_era_domain),
57+
Choice("39) Send message L2Telegraph", send_message),
58+
Choice("40) Dmail sending mail", send_mail),
59+
Choice("41) MultiSwap", swap_multiswap),
60+
Choice("42) Use custom routes", custom_routes),
61+
Choice("43) MultiApprove", multi_approve),
62+
Choice("44) Deploy contract and mint token", deploy_contract_zksync),
63+
Choice("45) Check transaction count", "tx_checker"),
64+
Choice("46) Exit", "exit"),
6365
],
6466
qmark="⚙️ ",
6567
pointer="✅ "

modules/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from .odos import Odos
1111
from .zkswap import ZKSwap
1212
from .xyswap import XYSwap
13+
from .openocean import OpenOcean
14+
from .inch import Inch
1315
from .multiswap import Multiswap
1416
from .dmail import Dmail
1517
from .bungee import Bungee

modules/account.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from web3.exceptions import TransactionNotFound
99

1010
from config import RPC, ERC20_ABI, ZKSYNC_TOKENS
11+
from settings import GAS_MULTIPLIER
1112
from utils.sleeping import sleep
1213

1314

@@ -140,7 +141,7 @@ def wait_until_tx_finished(self, hash: str, max_wait_time=180):
140141

141142
def sign(self, transaction):
142143
gas = self.w3.eth.estimate_gas(transaction)
143-
gas = int(gas + gas * 0.3)
144+
gas = int(gas * GAS_MULTIPLIER)
144145

145146
transaction.update({"gas": gas})
146147

modules/inch.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from typing import Union
2+
3+
import requests
4+
from loguru import logger
5+
from web3 import Web3
6+
from config import INCH_CONTRACT, ZKSYNC_TOKENS
7+
from settings import INCH_API_KEY
8+
from utils.gas_checker import check_gas
9+
from utils.helpers import retry
10+
from .account import Account
11+
12+
13+
class Inch(Account):
14+
def __init__(self, account_id: int, private_key: str, proxy: Union[None, str]) -> None:
15+
super().__init__(account_id=account_id, private_key=private_key, proxy=proxy, chain="zksync")
16+
17+
self.url = f"https://api.1inch.dev/swap/v5.2/{self.w3.eth.chain_id}"
18+
self.headers = { "Authorization": f"Bearer {INCH_API_KEY}", "accept": "application/json" }
19+
20+
self.proxies = {}
21+
22+
if proxy:
23+
self.proxies.update({"http": f"http://{proxy}", "https": f"http://{proxy}"})
24+
25+
self.tx = {
26+
"from": self.address,
27+
"gasPrice": self.w3.eth.gas_price,
28+
"nonce": self.w3.eth.get_transaction_count(self.address)
29+
}
30+
31+
def build_tx(self, from_token: str, to_token: str, amount: int, slippage: int):
32+
url = f"{self.url}/swap"
33+
params = {
34+
"src": Web3.to_checksum_address(from_token),
35+
"dst": Web3.to_checksum_address(to_token),
36+
"amount": amount,
37+
"from": self.address,
38+
"slippage": slippage,
39+
}
40+
41+
response = requests.get(url, params=params, headers=self.headers, proxies=self.proxies)
42+
transaction = response.json()
43+
44+
return transaction
45+
46+
@retry
47+
@check_gas
48+
def swap(
49+
self,
50+
from_token: str,
51+
to_token: str,
52+
min_amount: float,
53+
max_amount: float,
54+
decimal: int,
55+
slippage: int,
56+
all_amount: bool,
57+
min_percent: int,
58+
max_percent: int
59+
):
60+
amount_wei, amount, balance = self.get_amount(
61+
from_token,
62+
min_amount,
63+
max_amount,
64+
decimal,
65+
all_amount,
66+
min_percent,
67+
max_percent
68+
)
69+
70+
logger.info(
71+
f"[{self.account_id}][{self.address}] Swap on 1inch – {from_token} -> {to_token} | {amount} {from_token}"
72+
)
73+
74+
from_token = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" if from_token == "ETH" else ZKSYNC_TOKENS[from_token]
75+
to_token = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" if to_token == "ETH" else ZKSYNC_TOKENS[to_token]
76+
77+
if from_token != "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
78+
self.approve(amount_wei, from_token, INCH_CONTRACT)
79+
80+
transaction_data = self.build_tx(from_token, to_token, amount_wei, slippage)
81+
82+
transaction_data["tx"].update(
83+
{
84+
"to": Web3.to_checksum_address(transaction_data["tx"]["to"]),
85+
"value": int(transaction_data["tx"]["value"]),
86+
"gasPrice": int(transaction_data["tx"]["gasPrice"]),
87+
"nonce": self.w3.eth.get_transaction_count(self.address)
88+
}
89+
)
90+
91+
signed_txn = self.sign(transaction_data["tx"])
92+
93+
txn_hash = self.send_raw_transaction(signed_txn)
94+
95+
self.wait_until_tx_finished(txn_hash.hex())

modules/openocean.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from typing import Union
2+
3+
import requests
4+
from loguru import logger
5+
from web3 import Web3
6+
from config import OPENOCEAN_CONTRACT, ZKSYNC_TOKENS
7+
from utils.gas_checker import check_gas
8+
from utils.helpers import retry
9+
from .account import Account
10+
11+
12+
class OpenOcean(Account):
13+
def __init__(self, account_id: int, private_key: str, proxy: Union[None, str]) -> None:
14+
super().__init__(account_id=account_id, private_key=private_key, proxy=proxy, chain="zksync")
15+
16+
self.proxies = {}
17+
18+
if proxy:
19+
self.proxies.update({"http": f"http://{proxy}", "https": f"http://{proxy}"})
20+
21+
self.tx = {
22+
"from": self.address,
23+
"gasPrice": self.w3.eth.gas_price,
24+
"nonce": self.w3.eth.get_transaction_count(self.address)
25+
}
26+
27+
def build_transaction(self, from_token: str, to_token: str, amount: int, slippage: float):
28+
url = "https://open-api.openocean.finance/v3/324/swap_quote"
29+
30+
params = {
31+
"inTokenAddress": Web3.to_checksum_address(from_token),
32+
"outTokenAddress": Web3.to_checksum_address(to_token),
33+
"amount": amount,
34+
"gasPrice": Web3.from_wei(self.w3.eth.gas_price, "gwei"),
35+
"slippage": slippage,
36+
"account": self.address,
37+
}
38+
39+
if OPENOCEAN_CONTRACT["use_ref"]:
40+
params.update({
41+
"referrer": Web3.to_checksum_address("0x1c7ff320ae4327784b464eed07714581643b36a7"),
42+
"referrerFee": 1
43+
})
44+
45+
response = requests.get(url=url, params=params, proxies=self.proxies)
46+
47+
return response.json()
48+
49+
@retry
50+
@check_gas
51+
def swap(
52+
self,
53+
from_token: str,
54+
to_token: str,
55+
min_amount: float,
56+
max_amount: float,
57+
decimal: int,
58+
slippage: int,
59+
all_amount: bool,
60+
min_percent: int,
61+
max_percent: int
62+
):
63+
amount_wei, amount, balance = self.get_amount(
64+
from_token,
65+
min_amount,
66+
max_amount,
67+
decimal,
68+
all_amount,
69+
min_percent,
70+
max_percent
71+
)
72+
73+
logger.info(
74+
f"[{self.account_id}][{self.address}] Swap on OpenOcean – {from_token} -> {to_token} | {amount} {from_token}"
75+
)
76+
77+
from_token = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" if from_token == "ETH" else ZKSYNC_TOKENS[from_token]
78+
to_token = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" if to_token == "ETH" else ZKSYNC_TOKENS[to_token]
79+
80+
transaction_data = self.build_transaction(
81+
from_token,
82+
to_token,
83+
amount,
84+
slippage,
85+
)
86+
87+
if from_token != "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
88+
self.approve(amount_wei, from_token, OPENOCEAN_CONTRACT["router"])
89+
90+
self.tx.update(
91+
{
92+
"to": transaction_data["data"]["to"],
93+
"data": transaction_data["data"]["data"],
94+
"value": int(transaction_data["data"]["value"]),
95+
"nonce": self.w3.eth.get_transaction_count(self.address)
96+
}
97+
)
98+
99+
signed_txn = self.sign(self.tx)
100+
101+
txn_hash = self.send_raw_transaction(signed_txn)
102+
103+
self.wait_until_tx_finished(txn_hash.hex())

modules_settings.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,64 @@ def swap_xyswap(account_id, key, proxy):
398398
xyswap.swap(from_token, to_token, min_amount, max_amount, decimal, slippage, all_amount, min_percent, max_percent)
399399

400400

401+
def swap_openocean(account_id, key, proxy):
402+
"""
403+
Make swap on OpenOcean
404+
______________________________________________________
405+
from_token – Choose SOURCE token ETH, WETH, USDC, USDT, BUSD, MAV, OT, WBTC | Select one
406+
to_token – Choose DESTINATION token ETH, WETH, USDC, USDT, BUSD, MAV, OT, WBTC | Select one
407+
408+
Disclaimer - If you use True for use_fee, you support me 1% of the transaction amount
409+
______________________________________________________
410+
all_amount - swap from min_percent to max_percent
411+
"""
412+
413+
from_token = "ETH"
414+
to_token = "WETH"
415+
416+
min_amount = 0.0001
417+
max_amount = 0.0002
418+
decimal = 6
419+
slippage = 1
420+
421+
all_amount = True
422+
423+
min_percent = 1
424+
max_percent = 2
425+
426+
xyswap = OpenOcean(account_id, key, proxy)
427+
xyswap.swap(from_token, to_token, min_amount, max_amount, decimal, slippage, all_amount, min_percent, max_percent)
428+
429+
430+
def swap_inch(account_id, key, proxy):
431+
"""
432+
Make swap on 1inch
433+
______________________________________________________
434+
from_token – Choose SOURCE token ETH, WETH, USDC, USDT, BUSD | Select one
435+
to_token – Choose DESTINATION token ETH, WETH, USDC, USDT, BUSD | Select one
436+
437+
Disclaimer - If you use True for use_fee, you support me 1% of the transaction amount
438+
______________________________________________________
439+
all_amount - swap from min_percent to max_percent
440+
"""
441+
442+
from_token = "ETH"
443+
to_token = "WETH"
444+
445+
min_amount = 0.0001
446+
max_amount = 0.0002
447+
decimal = 6
448+
slippage = 1
449+
450+
all_amount = True
451+
452+
min_percent = 1
453+
max_percent = 2
454+
455+
inch_dex = Inch(account_id, key, proxy)
456+
inch_dex.swap(from_token, to_token, min_amount, max_amount, decimal, slippage, all_amount, min_percent, max_percent)
457+
458+
401459
def bungee_refuel(account_id, key, proxy):
402460
"""
403461
Make refuel on Bungee

settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@
1414
CHECK_GWEI = True # True or False
1515
MAX_GWEI = 25
1616

17+
GAS_MULTIPLIER = 1.3
18+
1719
# RETRY MODE
1820
RETRY_COUNT = 3
21+
22+
# INCH API KEY
23+
INCH_API_KEY = ""

0 commit comments

Comments
 (0)