44from loguru import logger
55from web3 import Web3
66from config import BASILISK_CONTRACTS , BASILISK_ABI
7+ from utils .gas_checker import check_gas
8+ from utils .helpers import retry
79from utils .sleeping import sleep
810from .account import Account
911
@@ -24,6 +26,8 @@ def get_deposit_amount(self):
2426 amount = self .contract .functions .balanceOfUnderlying (self .address ).call ()
2527 return amount
2628
29+ @retry
30+ @check_gas
2731 def deposit (
2832 self ,
2933 min_amount : float ,
@@ -46,82 +50,76 @@ def deposit(
4650 max_percent
4751 )
4852
49- try :
50- logger .info (f"[{ self .account_id } ][{ self .address } ] Make deposit on Basilisk | { amount } ETH" )
53+ logger .info (f"[{ self .account_id } ][{ self .address } ] Make deposit on Basilisk | { amount } ETH" )
5154
52- self .tx .update ({"value" : amount_wei })
55+ self .tx .update ({"value" : amount_wei })
5356
54- transaction = self .contract .functions .mint ().build_transaction (self .tx )
57+ transaction = self .contract .functions .mint ().build_transaction (self .tx )
5558
56- signed_txn = self .sign (transaction )
59+ signed_txn = self .sign (transaction )
5760
58- txn_hash = self .send_raw_transaction (signed_txn )
61+ txn_hash = self .send_raw_transaction (signed_txn )
5962
60- self .wait_until_tx_finished (txn_hash .hex ())
63+ self .wait_until_tx_finished (txn_hash .hex ())
6164
62- if make_withdraw :
63- sleep (sleep_from , sleep_to )
65+ if make_withdraw :
66+ sleep (sleep_from , sleep_to )
6467
65- self .withdraw ()
66- except Exception as e :
67- logger .error (f"[{ self .account_id } ][{ self .address } ] Error | { e } " )
68+ self .withdraw ()
6869
70+ @retry
71+ @check_gas
6972 def withdraw (self ):
7073 amount = self .get_deposit_amount ()
7174
7275 if amount > 0 :
73- try :
74- logger .info (
75- f"[{ self .account_id } ][{ self .address } ] Make withdraw from Basilisk | " +
76- f"{ Web3 .from_wei (amount , 'ether' )} ETH"
77- )
76+ logger .info (
77+ f"[{ self .account_id } ][{ self .address } ] Make withdraw from Basilisk | " +
78+ f"{ Web3 .from_wei (amount , 'ether' )} ETH"
79+ )
7880
79- self .tx .update ({"value" : 0 , "nonce" : self .w3 .eth .get_transaction_count (self .address )})
81+ self .tx .update ({"value" : 0 , "nonce" : self .w3 .eth .get_transaction_count (self .address )})
8082
81- transaction = self .contract .functions .redeemUnderlying (amount ).build_transaction (self .tx )
83+ transaction = self .contract .functions .redeemUnderlying (amount ).build_transaction (self .tx )
8284
83- signed_txn = self .sign (transaction )
85+ signed_txn = self .sign (transaction )
8486
85- txn_hash = self .send_raw_transaction (signed_txn )
87+ txn_hash = self .send_raw_transaction (signed_txn )
8688
87- self .wait_until_tx_finished (txn_hash .hex ())
88- except Exception as e :
89- logger .error (f"[{ self .account_id } ][{ self .address } ] Error | { e } " )
89+ self .wait_until_tx_finished (txn_hash .hex ())
9090 else :
9191 logger .error (f"[{ self .account_id } ][{ self .address } ] Deposit not found" )
9292
93+ @retry
94+ @check_gas
9395 def enable_collateral (self ):
9496 logger .info (f"[{ self .account_id } ][{ self .address } ] Enable collateral on Basilisk" )
9597
9698 contract = self .get_contract (BASILISK_CONTRACTS ["collateral" ], BASILISK_ABI )
9799
98- try :
99- transaction = contract .functions .enterMarkets (
100- [Web3 .to_checksum_address (BASILISK_CONTRACTS ["landing" ])]
101- ).build_transaction (self .tx )
100+ transaction = contract .functions .enterMarkets (
101+ [Web3 .to_checksum_address (BASILISK_CONTRACTS ["landing" ])]
102+ ).build_transaction (self .tx )
102103
103- signed_txn = self .sign (transaction )
104+ signed_txn = self .sign (transaction )
104105
105- txn_hash = self .send_raw_transaction (signed_txn )
106+ txn_hash = self .send_raw_transaction (signed_txn )
106107
107- self .wait_until_tx_finished (txn_hash .hex ())
108- except Exception as e :
109- logger .error (f"[{ self .account_id } ][{ self .address } ] Error | { e } " )
108+ self .wait_until_tx_finished (txn_hash .hex ())
110109
110+ @retry
111+ @check_gas
111112 def disable_collateral (self ):
112113 logger .info (f"[{ self .account_id } ][{ self .address } ] Disable collateral on Basilisk" )
113114
114115 contract = self .get_contract (BASILISK_CONTRACTS ["collateral" ], BASILISK_ABI )
115116
116- try :
117- transaction = contract .functions .exitMarket (
118- Web3 .to_checksum_address (BASILISK_CONTRACTS ["landing" ])
119- ).build_transaction (self .tx )
117+ transaction = contract .functions .exitMarket (
118+ Web3 .to_checksum_address (BASILISK_CONTRACTS ["landing" ])
119+ ).build_transaction (self .tx )
120120
121- signed_txn = self .sign (transaction )
121+ signed_txn = self .sign (transaction )
122122
123- txn_hash = self .send_raw_transaction (signed_txn )
123+ txn_hash = self .send_raw_transaction (signed_txn )
124124
125- self .wait_until_tx_finished (txn_hash .hex ())
126- except Exception as e :
127- logger .error (f"[{ self .account_id } ][{ self .address } ] Error | { e } " )
125+ self .wait_until_tx_finished (txn_hash .hex ())
0 commit comments