Skip to content

Commit

Permalink
TxHelpers: comments and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sklbancor committed Apr 4, 2024
1 parent 4ce3661 commit 5fa2d17
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions fastlane_bot/helpers/txhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ def validate_and_submit_transaction(
safety_override: bool = False,
log_object: Dict[str, Any] = None,
flashloan_struct: List[Dict[str, int or str]] = None,
) -> Optional[Dict[str, Any]]:
) -> Optional[str]:
"""
Validates and submits a transaction to the arb contract.
Parameters
----------
TODO: Add parameters
Returns
-------
Optional[str]
The transaction hash of the submitted transaction or None
"""

Expand Down Expand Up @@ -473,13 +479,13 @@ def build_tx(
tx_details["value"] = value
return tx_details

def submit_regular_transaction(self, signed_tx) -> str:
def submit_regular_transaction(self, signed_tx) -> Optional[str]:
"""
Submits the transaction to the blockchain.
:param signed_tx: the signed transaction to be submitted to the blockchain
returns: the transaction hash of the submitted transaction
:returns: the transaction hash (str) of the submitted transaction (None if timed out)
"""

self.ConfigObj.logger.info(
Expand All @@ -488,14 +494,14 @@ def submit_regular_transaction(self, signed_tx) -> str:

return self._submit_transaction(self.web3.eth.send_raw_transaction(signed_tx.rawTransaction))

def submit_private_transaction(self, signed_tx, block_number: int) -> str:
def submit_private_transaction(self, signed_tx, block_number: int) -> Optional[str]:
"""
Submits the transaction privately through Alchemy -> Flashbots RPC to mitigate frontrunning.
:param signed_tx: the signed transaction to be submitted to the blockchain
:param block_number: the current block number
returns: The transaction receipt, or None if the transaction failed
:returns: the transaction hash (str) of the submitted transaction (None if timed out)
"""

self.ConfigObj.logger.info(
Expand Down Expand Up @@ -528,11 +534,18 @@ def submit_private_transaction(self, signed_tx, block_number: int) -> str:
)
return None

def _submit_transaction(self, tx_hash) -> str:
# TODO: should be renamed to _wait_for_transaction_receipt
def _submit_transaction(self, tx_hash) -> Optional[str]:
"""
waits for the transaction receipt
:param tx_hash: the transaction hash of the receipt to wait for
:returns: the transaction hash (str) of the submitted transaction or None (TimeExhausted)
"""
try:
tx_receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash)
assert tx_hash == tx_receipt["transactionHash"]
return tx_hash
return tx_hash.hex() # HexBytes -> str [TODO-KEVIN: Please check]
except TimeExhausted as e:
self.ConfigObj.logger.info(
f"[helpers.txhelpers._submit_transaction] Transaction timeout (stuck in mempool); moving on"
Expand Down

0 comments on commit 5fa2d17

Please sign in to comment.