From 3871a9b30d42efdd79e5b25e95057930a7b705d7 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Fri, 10 Nov 2023 04:15:49 -0800 Subject: [PATCH] removing incompatible type reference for upcoming web3.py version change --- fastlane_bot/helpers/submithandler.py | 65 ++++++++++++++------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/fastlane_bot/helpers/submithandler.py b/fastlane_bot/helpers/submithandler.py index b06e233f8..31a36d991 100644 --- a/fastlane_bot/helpers/submithandler.py +++ b/fastlane_bot/helpers/submithandler.py @@ -9,13 +9,12 @@ import json from dataclasses import dataclass, asdict -from typing import List, Any, Dict +from typing import List, Any, Dict, Callable import requests from eth_utils import to_hex from web3._utils.threads import Timeout from web3._utils.transactions import fill_nonce -from web3.contract import ContractFunction from web3.exceptions import TimeExhausted from web3.types import TxParams @@ -111,9 +110,7 @@ def _get_transaction(self, tx_details: TxParams) -> TxParams: """ return fill_nonce(self.ConfigObj.w3, tx_details) - def _get_transaction_receipt( - self, tx_hash: str, timeout: int - ): + def _get_transaction_receipt(self, tx_hash: str, timeout: int): """ Gets the transaction receipt for a given transaction hash. @@ -203,13 +200,13 @@ def _get_gas_price(self) -> int: self.ConfigObj.w3.eth.gas_price * self.ConfigObj.DEFAULT_GAS_PRICE_OFFSET ) - def _get_gas(self, tx_function: ContractFunction, address: str) -> int: + def _get_gas(self, tx_function: Callable, address: str) -> int: """ Gets the gas for the transaction. Parameters ---------- - tx_function: ContractFunction + tx_function: Callable The transaction function. Returns @@ -263,7 +260,11 @@ def _get_tx_details(self): } def submit_transaction_tenderly( - self, route_struct: List[RouteStruct], src_address: str, src_amount: int, flashloan_struct: List[Dict[str, int or str]] = None + self, + route_struct: List[RouteStruct], + src_address: str, + src_amount: int, + flashloan_struct: List[Dict[str, int or str]] = None, ) -> Any: """ Submits a transaction to the network. @@ -301,29 +302,33 @@ def submit_transaction_tenderly( address = self.ConfigObj.w3.toChecksumAddress( self.ConfigObj.BINANCE14_WALLET_ADDRESS ) - return self.arb_contract.functions.flashloanAndArb( - route_struct, src_address, src_amount - ).transact( - { - "gas": self.ConfigObj.DEFAULT_GAS, - "from": address, - "nonce": self._get_nonce(address), - "gasPrice": 0, - } - ) if flashloan_struct is None else self.arb_contract.functions.flashloanAndArbV2( + return ( + self.arb_contract.functions.flashloanAndArb( + route_struct, src_address, src_amount + ).transact( + { + "gas": self.ConfigObj.DEFAULT_GAS, + "from": address, + "nonce": self._get_nonce(address), + "gasPrice": 0, + } + ) + if flashloan_struct is None + else self.arb_contract.functions.flashloanAndArbV2( flashloan_struct, route_struct ).transact( - { - "gas": self.ConfigObj.DEFAULT_GAS, - "from": address, - "nonce": self._get_nonce(address), - "gasPrice": 0, - } + { + "gas": self.ConfigObj.DEFAULT_GAS, + "from": address, + "nonce": self._get_nonce(address), + "gasPrice": 0, + } + ) ) def _get_transaction_details( self, - tx_function: ContractFunction, + tx_function: Callable, tx_params: TxParams, from_address: str, to_address: str, @@ -333,7 +338,7 @@ def _get_transaction_details( Parameters ---------- - tx_function: ContractFunction + tx_function: Callable The transaction function. tx_params: TxParams The transaction parameters. @@ -398,7 +403,7 @@ def _get_nonce(self, address: str) -> int: # build transaction def _build_transaction( self, - tx_function: ContractFunction, + tx_function: Callable, tx_params: TxParams, from_address: str, to_address: str, @@ -408,7 +413,7 @@ def _build_transaction( Parameters ---------- - tx_function: ContractFunction + tx_function: Callable The transaction function. tx_params: TxParams The transaction parameters. @@ -428,7 +433,7 @@ def _build_transaction( # submit transaction def _submit_transaction( self, - tx_function: ContractFunction, + tx_function: Callable, tx_params: TxParams, from_address: str, to_address: str, @@ -439,7 +444,7 @@ def _submit_transaction( Parameters ---------- - tx_function: ContractFunction + tx_function: Callable The transaction function. tx_params: TxParams The transaction parameters.