agent0.core.hyperdrive.interactive.exec ======================================= .. py:module:: agent0.core.hyperdrive.interactive.exec .. autoapi-nested-parse:: Helper functions for executing agent trades. .. !! processed by numpydoc !! Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/agent0/core/hyperdrive/interactive/exec/check_for_new_block/index /autoapi/agent0/core/hyperdrive/interactive/exec/execute_agent_trades/index Functions --------- .. autoapisummary:: agent0.core.hyperdrive.interactive.exec.check_for_new_block agent0.core.hyperdrive.interactive.exec.async_execute_agent_trades agent0.core.hyperdrive.interactive.exec.async_execute_single_trade agent0.core.hyperdrive.interactive.exec.get_liquidation_trades agent0.core.hyperdrive.interactive.exec.get_trades Package Contents ---------------- .. py:function:: check_for_new_block(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, last_block_number: eth_typing.BlockNumber | int) -> tuple[bool, web3.types.BlockData] Returns True if the chain has ticked to a block that is newer than the input block. :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadInterface :param last_block_number: The last block number to check against. :type last_block_number: BlockNumber | int :returns: Tuple with a boolean indicating if the latest block is newer than the last_block input, as well as the latest block data. :rtype: tuple[bool, BlockData] .. !! processed by numpydoc !! .. py:function:: async_execute_agent_trades(trades: list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]], interface: agent0.ethpy.hyperdrive.HyperdriveReadWriteInterface, account: eth_account.signers.local.LocalAccount, wallet_func: Callable[[], agent0.core.hyperdrive.HyperdriveWallet], policy: agent0.core.hyperdrive.policies.HyperdriveBasePolicy | None, preview_before_trade: bool, nonce_func: Callable[[], web3.types.Nonce] | None = None) -> list[agent0.core.hyperdrive.TradeResult] :async: Executes a single agent's trade based on its policy. This function is async as `_match_contract_call_to_trade` waits for a transaction receipt. .. note :: This function is not thread safe, as (1) the agent's policies `action` and `post_action` may not be thread safe, and (2) the agent's wallet update is not thread safe. (3) acquiring the base nonce for this set of trades is not thread safe. :param trades: The list of trades to execute. :type trades: list[Trade[HyperdriveMarketAction]] :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadWriteInterface :param account: The account that is conducting the trade. :type account: LocalAccount :param wallet_func: The function to get the agent's wallet object tied to a pool. We only use this function in crash reporting, so we only call this if a trade fails. NOTE: this function parameter doesn't receive any arguments, so a partial function must be made to pass in arguments, e.g., the pool. :type wallet_func: Callable[[], HyperdriveWallet] :param policy: The policy being executed. :type policy: HyperdriveBasePolicy :param preview_before_trade: Whether or not to preview the trade before it is executed. :type preview_before_trade: bool :param nonce_func: A callable function to use to get a nonce. This function is useful for e.g., passing in a safe nonce getter tied to an agent. Defaults to setting it to the result of `get_transaction_count`. :type nonce_func: Callable[[], Nonce] | None :returns: Returns a list of TradeResult objects, one for each trade made by the agent. TradeResult handles any information about the trade, as well as any trade errors. :rtype: list[TradeResult] .. !! processed by numpydoc !! .. py:function:: async_execute_single_trade(interface: agent0.ethpy.hyperdrive.HyperdriveReadWriteInterface, account: eth_account.signers.local.LocalAccount, wallet_func: Callable[[], agent0.core.hyperdrive.HyperdriveWallet], trade_object: agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction], execute_policy_post_action: bool, preview_before_trade: bool, nonce_func: Callable[[], web3.types.Nonce] | None = None, policy: agent0.core.hyperdrive.policies.HyperdriveBasePolicy | None = None) -> agent0.core.hyperdrive.TradeResult :async: Executes a single trade made by the agent. .. note :: This function is not thread safe, as (1) the agent's wallet update is not thread safe (2) acquiring the nonce for this trade is not thread safe :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadWriteInterface :param account: The LocalAccount that is conducting the trade. :type account: LocalAccount :param wallet_func: The function to get the agent's wallet object tied to a pool. We only use this function in crash reporting, so we only call this if a trade fails. NOTE: this function parameter doesn't receive any arguments, so a partial function must be made to pass in arguments, e.g., the pool. :type wallet_func: Callable[[], HyperdriveWallet] :param trade_object: The trade to execute. :type trade_object: Trade[HyperdriveMarketAction] :param execute_policy_post_action: Whether or not to execute the post_action of the policy after the trade. :type execute_policy_post_action: bool :param preview_before_trade: Whether or not to preview the trade before it is executed. :type preview_before_trade: bool :param nonce_func: A callable function to use to get a nonce. This function is useful for e.g., passing in a safe nonce getter tied to an agent. Defaults to setting it to the result of `get_transaction_count`. :type nonce_func: Callable[[], Nonce] | None :param policy: The policy attached to the agent. This is only used to potentially call `post_action` of the policy. :type policy: HyperdriveBasePolicy | None, optional :returns: The result of the trade. :rtype: TradeResult .. !! processed by numpydoc !! .. py:function:: get_liquidation_trades(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, wallet: agent0.core.hyperdrive.HyperdriveWallet, randomize_trades: bool, rng: numpy.random.Generator) -> list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]] Get liquidation trades. :param interface: The read interface for the market. :type interface: HyperdriveReadInterface :param wallet: The wallet of the account. :type wallet: HyperdriveWallet :param randomize_trades: Whether to randomize trades. :type randomize_trades: bool :param rng: The random number generator for randomizing trades. :type rng: Generator :returns: The list of liquidation trades. :rtype: list[Trade[HyperdriveMarketAction]] .. !! processed by numpydoc !! .. py:function:: get_trades(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, policy: agent0.core.hyperdrive.policies.HyperdriveBasePolicy, wallet: agent0.core.hyperdrive.HyperdriveWallet, default_gas_limit: int | None = None) -> list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]] Get trades from the policy. :param interface: The read interface for the market. :type interface: HyperdriveReadInterface :param policy: The policy attached to the agent. :type policy: HyperdriveBasePolicy :param wallet: The wallet of the account. :type wallet: HyperdriveWallet :param default_gas_limit: The default gas limit to use if not provided by the policy. :type default_gas_limit: int | None :returns: The list of trades from the policy. :rtype: list[Trade[HyperdriveMarketAction]] .. !! processed by numpydoc !!