BlockchainTransaction#
tradeexecutor.state.blockhain_transaction.BlockchainTransaction Python class in Trading Strategy framework.
- class BlockchainTransaction[source]#
Bases:
object
A stateful blockchain transaction.
The state tracks a transaction over its life cycle
Transactions are part of a larger logical operation (a trade)
Transactions can be resolved either to success or failed
Transaction information is easily exported to the frontend
Transaction has (rough) four phases
Preparation
Signing
Broadcast
Confirmation
- __init__(type=BlockchainTransactionType.hot_wallet, chain_id=None, from_address=None, contract_address=None, function_selector=None, transaction_args=None, wrapped_function_selector=None, wrapped_args=None, tx_hash=None, nonce=None, details=None, signed_bytes=None, broadcasted_at=None, included_at=None, block_number=None, block_hash=None, status=None, realised_gas_units_consumed=None, realised_gas_price=None, revert_reason=None, stack_trace=None, asset_deltas=<factory>, args=None, other=<factory>)#
- Parameters:
type (BlockchainTransactionType) –
asset_deltas (List[JSONAssetDelta]) –
other (dict) –
- Return type:
None
Methods
__init__
([type, chain_id, from_address, ...])from_dict
(kvs, *[, infer_missing])from_json
(s, *[, parse_float, parse_int, ...])Get the Solidity function input args this transaction was calling.
Get the gas limit of the transaction.
How much wei per gas unit we planned to spend on this transactions.
Get the bytes we can pass to web_ethSendRawTransction
Return the transaction object as it would be in web3.py.
Transaction reverted.
Transaction is success if it's succeed flag has been set.
schema
(*[, infer_missing, only, exclude, ...])set_broadcast_information
(nonce, tx_hash, ...)Update the information we are going to use to broadcast the transaction.
set_confirmation_information
(ts, ...[, ...])Update the information we are going to use to broadcast the transaction.
set_target_information
(chain_id, ...)Update the information on which transaction we are going to perform.
to_dict
([encode_json])to_json
(*[, skipkeys, ensure_ascii, ...])Attributes
What kidn of internal type of this transaction is
Chain id from https://github.com/ethereum-lists/chains
TODO: Part of signed bytes.
Contract we called.
Function name we called
Arguments we passed to the smart contract entry function.
Function name the vault calls.
Arguments that execute the actual trade.
Blockchain bookkeeping
Blockchain bookkeeping
Raw Ethereum transaction dict.
Raw bytes of the signed transaction
When this transaction was broadcasted
Block timestamp when this tranasction was included in a block
Block number when this transaction was included in a block
Block has of the transaction where the executor saw the inclusion
status from the tx receipt.
Gas consumed by the tx
Gas price for the tx in gwei
The transaction revert reason if we manage to extract it
Solidity stack trace of reverted transactions.
List of assets this transaction touches
Legacy compatibility field.
Any other metadata associated with this transaction.
- type: BlockchainTransactionType#
What kidn of internal type of this transaction is
- chain_id: Optional[int]#
Chain id from https://github.com/ethereum-lists/chains
- function_selector: Optional[str]#
Function name we called
This is Solidity function entry point from the transaction data payload
Human-readable function name for debugging purposes.
- transaction_args: Optional[Tuple[Any]]#
Arguments we passed to the smart contract entry function.
This is not JSON serialisable because individual arguments may contain values that are token amounts and thus outside the maximum int of JavaScript.
- wrapped_function_selector: Optional[str]#
Function name the vault calls.
This is Solidity function entry point from the transaction data payload
Human-readable function name for debugging purposes.
- wrapped_args: Optional[Tuple[Any]]#
Arguments that execute the actual trade.
In the case of Enzyme’s vaults, we need to store the underlying smart contract function call, so that we can analyse the slippage later on, because we need the swap function input args for the slippage analysis.
- details: Optional[Dict]#
Raw Ethereum transaction dict. Output from web3 buildTransaction()
Example:
{‘value’: 0, ‘maxFeePerGas’: 1844540158, ‘maxPriorityFeePerGas’: 1000000000, ‘chainId’: 61, ‘from’: ‘0x6B49598B34B9c7FbF7C57306d0b0578676D55ffA’, ‘gas’: 100000, ‘to’: ‘0xF2E246BB76DF876Cef8b38ae84130F4F55De395b’, ‘data’: ‘0x095ea7b30000000000000000000000006d411e0a54382ed43f02410ce1c7a7c122afa6e1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff’, ‘nonce’: 0}
- stack_trace: Optional[str]#
Solidity stack trace of reverted transactions.
Used in the unit testing environment with Anvil.
See
eth_defi.trace
.
- asset_deltas: List[JSONAssetDelta]#
List of assets this transaction touches
Set in
tradeexecutor.tx.TransactionBuilder
- args: Optional[Tuple[Any]]#
Legacy compatibility field.
“Somewhat” human-readable encoded Solidity args to be displayed in the frontend. Arguments cannot be decoded for programmatic use.
Use
transaction_args
andget_actual_function_input_args()
instead.
- other: dict#
Any other metadata associated with this transaction.
Currently used for vault_slippage_tolerance.
- get_transaction()[source]#
Return the transaction object as it would be in web3.py.
Needed for
analyse_trade_by_receipt()
. This will reconstructTypedTransaction
instance from the raw signed transaction bytes. The object will have a dict containing “data” field which we can then use for the trade analysis.- Return type:
- set_target_information(chain_id, contract_address, function_selector, args, details)[source]#
Update the information on which transaction we are going to perform.
- set_broadcast_information(nonce, tx_hash, signed_bytes)[source]#
Update the information we are going to use to broadcast the transaction.
- set_confirmation_information(ts, block_number, block_hash, realised_gas_units_consumed, realised_gas_price, status, revert_reason=None, stack_trace=None)[source]#
Update the information we are going to use to broadcast the transaction.
- get_planned_gas_price()[source]#
How much wei per gas unit we planned to spend on this transactions.
Gets maxFeePerGas for EVM transction.
- Returns:
0 if unknown
- Return type:
- get_gas_limit()[source]#
Get the gas limit of the transaction.
Gets gas for EVM transction.
- Returns:
0 if unknown
- Return type:
- get_actual_function_input_args()[source]#
Get the Solidity function input args this transaction was calling.
For any wrapped vault transaction this returns the real function that was called, instead of the proxy function.
Otherwise return the args in the transaction payload.
- Return type:
- get_prepared_raw_transaction()[source]#
Get the bytes we can pass to web_ethSendRawTransction
- Return type:
- __init__(type=BlockchainTransactionType.hot_wallet, chain_id=None, from_address=None, contract_address=None, function_selector=None, transaction_args=None, wrapped_function_selector=None, wrapped_args=None, tx_hash=None, nonce=None, details=None, signed_bytes=None, broadcasted_at=None, included_at=None, block_number=None, block_hash=None, status=None, realised_gas_units_consumed=None, realised_gas_price=None, revert_reason=None, stack_trace=None, asset_deltas=<factory>, args=None, other=<factory>)#
- Parameters:
type (BlockchainTransactionType) –
asset_deltas (List[JSONAssetDelta]) –
other (dict) –
- Return type:
None