Skip to content

Commit

Permalink
Merge pull request #304 from bancorprotocol/improve-node-error-handling
Browse files Browse the repository at this point in the history
Improve the handling of the error-message returned from the node
  • Loading branch information
zavelevsky authored Jan 22, 2024
2 parents 54191e4 + 74f2361 commit 8b9fd4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
14 changes: 5 additions & 9 deletions fastlane_bot/helpers/txhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# from fastlane_bot.tools.cpc import ConstantProductCurve
from fastlane_bot.config import Config
from fastlane_bot.data.abi import * # TODO: PRECISE THE IMPORTS or from .. import abi
from fastlane_bot.utils import num_format, log_format, num_format_float
from fastlane_bot.utils import num_format, log_format, num_format_float, int_prefix


@dataclass
Expand Down Expand Up @@ -608,14 +608,12 @@ def build_transaction_with_gas(
if "max fee per gas less than block base fee" in str(e):
try:
message = str(e)
split1 = message.split("maxFeePerGas: ")[1]
split2 = split1.split(" baseFee: ")
split_baseFee = int(int(split2[1].split(" (supplied gas")[0]))
baseFee = int_prefix(message.split("baseFee: ")[1])
transaction = self.construct_contract_function(
routes=routes,
src_amt=src_amt,
src_address=src_address,
gas_price=split_baseFee,
gas_price=baseFee,
max_priority=max_priority,
nonce=nonce,
flashloan_struct=flashloan_struct,
Expand Down Expand Up @@ -959,13 +957,11 @@ def approve_token_for_arb_contract(self, token_address: str, approval_amount: in
if "max fee per gas less than block base fee" in str(e):
try:
message = str(e)
split1 = message.split('maxFeePerGas: ')[1]
split2 = split1.split(' baseFee: ')
split_baseFee = int(int(split2[1].split(" (supplied gas")[0]))
baseFee = int_prefix(message.split("baseFee: ")[1])
approve_tx = token_contract.functions.approve(self.arb_contract.address,
approval_amount).build_transaction(
self.build_tx(
base_gas_price=split_baseFee, max_priority_fee=max_priority, nonce=self.get_nonce()
base_gas_price=baseFee, max_priority_fee=max_priority, nonce=self.get_nonce()
)
)
except Exception as e:
Expand Down
8 changes: 3 additions & 5 deletions fastlane_bot/tools/pool_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
BANCOR_V3_POOL_COLLECTION_ABI,
)
from fastlane_bot.events.managers.manager import Manager
from fastlane_bot.helpers.txhelpers import TxHelpers
from fastlane_bot.helpers.txhelpers import TxHelpers, int_prefix


@dataclass
Expand Down Expand Up @@ -264,14 +264,12 @@ def _build_transaction(self, e: Exception, max_priority: int, tkn: str, nonce: i
"""
message = str(e)
split1 = message.split("maxFeePerGas: ")[1]
split2 = split1.split(" baseFee: ")
split_base_fee = int(split2[1].split(" (supplied gas")[0])
baseFee = int_prefix(message.split("baseFee: ")[1])
return self.bancor_network_contract.functions.withdrawPOL(
self.mgr.web3.to_checksum_address(tkn)
).build_transaction(
self.tx_helpers.build_tx(
base_gas_price=split_base_fee,
base_gas_price=baseFee,
max_priority_fee=max_priority,
nonce=nonce,
)
Expand Down
4 changes: 4 additions & 0 deletions fastlane_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
from fastlane_bot.data.abi import *


def int_prefix(string: str) -> int:
return int(string[:-len(string.lstrip("0123456789"))])


def convert_decimals_to_wei_format(tkn_amt: Decimal, decimals: int) -> int:
"""
param: tkn_amt: the number of tokens to convert
Expand Down

0 comments on commit 8b9fd4e

Please sign in to comment.