TransactionBuilder#
tradeexecutor.ethereum.tx.TransactionBuilder Python class in Trading Strategy framework.
- class TransactionBuilder[source]#
Bases:
ABC
Base class for different transaction builders.
We can build different transactions depending if we execute them directly from the hot wallet, or through a smart contract:
Hot wallet based, see
HotWalletTransactionBuilder
Vault based, see
tradeexecutor.enzyme.tx.EnzymeTransactionBuilder
Life cycle:
TransactionBuilder is created once at the application startup
See also
tradeeexecutor.ethereum.routing_state.EthereumRoutingState.create_signed_transaction()
.Methods
__init__
(web3)broadcast
(tx)Broadcast the transaction.
Watch multiple transactions executed at parallel.
Get raw transaction data out from the signed tx bytes.
Calculate the suggested gas price based on a policy.
Get the address that holds ERC-20 supply
Get the address that holds native token for gas fees
Get the balance of the native currency (ETH, BNB, MATIC) of the wallet.
Get the target address for ERC-20 token delivery.
init
()Initialise the transaction builder.
Prepare a transaction as a format ready to broadcast.
sign_transaction
(contract, args_bound_func)Createa a signed tranaction and set up tx broadcast parameters.
- fetch_gas_price_suggestion()[source]#
Calculate the suggested gas price based on a policy.
- Return type:
- broadcast(tx)[source]#
Broadcast the transaction.
Push the transaction to the peer-to-peer network / MEV relay to be includedin the
Sets the tx.broadcasted_at timestamp.
- Returns:
Transaction hash, or tx_hash
- Parameters:
tx (BlockchainTransaction) –
- Return type:
HexBytes
- static serialise_to_broadcast_format(tx)[source]#
Prepare a transaction as a format ready to broadcast.
- Parameters:
tx (BlockchainTransaction) –
- Return type:
SignedTransaction
- static decode_signed_bytes(tx)[source]#
Get raw transaction data out from the signed tx bytes.
- Parameters:
tx (BlockchainTransaction) –
- Return type:
- static broadcast_and_wait_transactions_to_complete(web3, txs, confirmation_block_count=0, max_timeout=datetime.timedelta(seconds=300), poll_delay=datetime.timedelta(seconds=1), revert_reasons=False)[source]#
Watch multiple transactions executed at parallel.
Modifies the given transaction objects in-place and updates block inclusion and succeed status.
Note
This method is designed to be used only in unit testing as a shortcut.
- Parameters:
web3 (Web3) –
txs (List[BlockchainTransaction]) –
- abstract sign_transaction(contract, args_bound_func, gas_limit=None, gas_price_suggestion=None, asset_deltas=None)[source]#
Createa a signed tranaction and set up tx broadcast parameters.
- Parameters:
args_bound_func (ContractFunction) – A Solidity function with its arguments bound to the function instance.
Max gas limit per this transaction.
The transaction will fail if the gas limit is exceeded.
If set to None then it is up to the signed to figure it out based on the function hints.
gas_price_suggestion (Optional[GasPriceSuggestion]) –
What gas price will be used.
Support old-style and London style transactions.
asset_deltas (Optional[List[AssetDelta]]) – Expected assets inbound and outbound.
contract (Contract) –
- Returns:
Prepared BlockchainTransaction instance.
This transaction object can be stored in the persistent state.
- Return type:
- abstract get_token_delivery_address()[source]#
Get the target address for ERC-20 token delivery.
Where do Uniswap should send the tokens after a swap.
- Return type:
- abstract get_erc_20_balance_address()[source]#
Get the address that holds ERC-20 supply
- Return type: