agent0.core.hyperdrive.policies.lpandarb ======================================== .. py:module:: agent0.core.hyperdrive.policies.lpandarb .. autoapi-nested-parse:: Agent policy for LP trading that can also arbitrage on the fixed rate. .. !! processed by numpydoc !! Attributes ---------- .. autoapisummary:: agent0.core.hyperdrive.policies.lpandarb.TOLERANCE agent0.core.hyperdrive.policies.lpandarb.MAX_ITER Classes ------- .. autoapisummary:: agent0.core.hyperdrive.policies.lpandarb.LPandArb Functions --------- .. autoapisummary:: agent0.core.hyperdrive.policies.lpandarb.arb_fixed_rate_down agent0.core.hyperdrive.policies.lpandarb.arb_fixed_rate_up agent0.core.hyperdrive.policies.lpandarb.calc_shares_needed_for_bonds agent0.core.hyperdrive.policies.lpandarb.calc_delta_reserves_for_target_rate agent0.core.hyperdrive.policies.lpandarb.calc_reserves_to_hit_target_rate agent0.core.hyperdrive.policies.lpandarb.apply_step_to_reserves agent0.core.hyperdrive.policies.lpandarb.apply_step_to_pool_state Module Contents --------------- .. py:data:: TOLERANCE :value: 1e-18 .. py:data:: MAX_ITER :value: 50 .. py:function:: arb_fixed_rate_down(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, pool_state: agent0.ethpy.hyperdrive.state.PoolState, wallet: agent0.core.hyperdrive.HyperdriveWallet, max_trade_amount_base: fixedpointmath.FixedPoint, min_trade_amount_bonds: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None) -> list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]] Return an action list for arbitraging the fixed rate down to the variable rate. :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadInterface :param pool_state: The hyperdrive pool state. :type pool_state: PoolState :param wallet: The agent's wallet. :type wallet: HyperdriveWallet :param max_trade_amount_base: The maximum amount of base allowed to trade. :type max_trade_amount_base: FixedPoint :param min_trade_amount_bonds: The minimum amount of bonds needed to open a trade. :type min_trade_amount_bonds: FixedPoint :param slippage_tolerance: The slippage tolerance for trades. Defaults to None. :type slippage_tolerance: FixedPoint | None, optional :param base_fee_multiple: The base fee multiple for transactions. Defaults to None. :type base_fee_multiple: float | None, optional :param priority_fee_multiple: The priority fee multiple for transactions. Defaults to None. :type priority_fee_multiple: float | None, optional :returns: A list of actions for arbitration trades. :rtype: list[MarketAction] .. !! processed by numpydoc !! .. py:function:: arb_fixed_rate_up(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, pool_state: agent0.ethpy.hyperdrive.state.PoolState, wallet: agent0.core.hyperdrive.HyperdriveWallet, max_trade_amount_base: fixedpointmath.FixedPoint, min_trade_amount_bonds: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None) -> list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]] Return an action list for arbitraging the fixed rate up to the variable rate. :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadInterface :param pool_state: The hyperdrive pool state. :type pool_state: PoolState :param wallet: The agent's wallet. :type wallet: HyperdriveWallet :param max_trade_amount_base: The maximum amount of base allowed to trade. :type max_trade_amount_base: FixedPoint :param min_trade_amount_bonds: The minimum amount of bonds needed to open a trade. :type min_trade_amount_bonds: FixedPoint :param slippage_tolerance: The slippage tolerance for trades. Defaults to None. :type slippage_tolerance: FixedPoint | None, optional :param base_fee_multiple: The base fee multiple for transactions. Defaults to None. :type base_fee_multiple: float | None, optional :param priority_fee_multiple: The priority fee multiple for transactions. Defaults to None. :type priority_fee_multiple: float | None, optional :returns: A list of actions for arbitration trades. :rtype: list[MarketAction] .. !! processed by numpydoc !! .. py:function:: calc_shares_needed_for_bonds(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, pool_state: agent0.ethpy.hyperdrive.state.PoolState, bonds_needed: fixedpointmath.FixedPoint, min_trade_amount_bonds: fixedpointmath.FixedPoint) -> fixedpointmath.FixedPoint Calculate the shares needed to trade a certain amount of bonds, and the associate governance fee. :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadInterface :param pool_state: The hyperdrive pool state. :type pool_state: PoolState :param bonds_needed: The given amount of bonds that is going to be traded. :type bonds_needed: FixedPoint :param min_trade_amount_bonds: The minimum amount of bonds needed to open a trade. :type min_trade_amount_bonds: FixedPoint :returns: The change in shares in the pool for the given amount of bonds. :rtype: FixedPoint .. !! processed by numpydoc !! .. py:function:: calc_delta_reserves_for_target_rate(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, pool_state: agent0.ethpy.hyperdrive.state.PoolState, target_rate: fixedpointmath.FixedPoint, min_trade_amount_bonds: fixedpointmath.FixedPoint) -> tuple[fixedpointmath.FixedPoint, fixedpointmath.FixedPoint] Calculate the bonds needed to hit the desired reserves ratio, keeping shares constant. delta_bonds tells us the number of bonds to hit the desired reserves ratio, keeping shares constant. However trades modify both bonds and shares in amounts of equal value. We modify bonds by only half of delta_bonds, knowing that an amount of equal value will move shares in the other direction, toward our desired ratio. This guess is very bad when slippage is high, so we check how bad, then scale accordingly. To avoid negative share reserves, we increase the divisor until they are no longer negative. :param interface: Interface for the market on which this agent will be executing trades (MarketActions). :type interface: HyperdriveReadInterface :param pool_state: The current pool state. :type pool_state: PoolState :param target_rate: The target rate the pool will have after the calculated change in bonds and shares. :type target_rate: FixedPoint :param min_trade_amount_bonds: The minimum amount of bonds needed to open a trade. :type min_trade_amount_bonds: FixedPoint :returns: The delta (bonds, shares) needed to hit the desired fixed rate. :rtype: tuple[FixedPoint, FixedPoint] .. !! processed by numpydoc !! .. py:function:: calc_reserves_to_hit_target_rate(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, pool_state: agent0.ethpy.hyperdrive.state.PoolState, target_rate: fixedpointmath.FixedPoint, min_trade_amount_bonds: fixedpointmath.FixedPoint) -> tuple[fixedpointmath.FixedPoint, fixedpointmath.FixedPoint] Calculate the bonds and shares needed to hit the target fixed rate. :param interface: The Hyperdrive API interface object. :type interface: HyperdriveReadInterface :param pool_state: The current pool state. :type pool_state: PoolState :param target_rate: The target rate the pool will have after the calculated change in bonds and shares. :type target_rate: FixedPoint :param min_trade_amount_bonds: The minimum amount of bonds needed to open a trade. :type min_trade_amount_bonds: FixedPoint :returns: total_shares_needed: FixedPoint Total amount of shares needed to be added into the pool to hit the target rate. total_bonds_needed: FixedPoint Total amount of bonds needed to be added into the pool to hit the target rate. :rtype: tuple[FixedPoint, FixedPoint, int] .. !! processed by numpydoc !! .. py:function:: apply_step_to_reserves(share_reserves: fixedpointmath.FixedPoint, delta_shares: fixedpointmath.FixedPoint, bond_reserves: fixedpointmath.FixedPoint, delta_bonds: fixedpointmath.FixedPoint) -> tuple[fixedpointmath.FixedPoint, fixedpointmath.FixedPoint] Apply a single convergence step to pool share and bond reserve levels. :param share_reserves: The current Hyperdrive pool's share reserves. :type share_reserves: FixedPoint :param delta_shares: The amount of shares to add or remove from the reserves, depending on the delta bonds sign. :type delta_shares: FixedPoint :param bond_reserves: The current Hyperdrive pool's bond reserves. :type bond_reserves: FixedPoint :param delta_bonds: The amount of bonds to add or remove from the reserves. :type delta_bonds: FixedPoint :returns: The resulting share reserves and bond reserves after the delta updates are applied. :rtype: tuple[FixedPoint, FixedPoint] .. !! processed by numpydoc !! .. py:function:: apply_step_to_pool_state(pool_state: agent0.ethpy.hyperdrive.state.PoolState, delta_bonds: fixedpointmath.FixedPoint, delta_shares: fixedpointmath.FixedPoint) -> agent0.ethpy.hyperdrive.state.PoolState Save a single convergence step into the pool info. .. todo:: This function updates the pool_state argument _and_ returns it. This is a bad pattern because it obscures that the input argument is modified in-place. We should either always return a new instance (either via deepcopy or constructing from scratch) or always modify the provided variable in-place. :param pool_state: The current pool state. :type pool_state: PoolState :param delta_bonds: The amount of bonds that is going to be traded. :type delta_bonds: FixedPoint :param delta_shares: The amount of shares that is going to be traded. :type delta_shares: FixedPoint :returns: The updated pool state. :rtype: PoolState .. !! processed by numpydoc !! .. py:class:: LPandArb(policy_config: Config) Bases: :py:obj:`agent0.core.hyperdrive.policies.hyperdrive_policy.HyperdriveBasePolicy` LP and Arbitrage in a fixed proportion. .. !! processed by numpydoc !! .. py:method:: description() -> str :classmethod: Describe the policy in a user friendly manner that allows newcomers to decide whether to use it. :returns: The description of the policy, as described above. :rtype: str .. !! processed by numpydoc !! .. py:class:: Config Bases: :py:obj:`agent0.core.hyperdrive.policies.hyperdrive_policy.HyperdriveBasePolicy.Config` Custom config arguments for this policy. .. !! processed by numpydoc !! .. py:attribute:: lp_portion :type: fixedpointmath.FixedPoint The portion of capital assigned to LP. Defaults to 0. .. !! processed by numpydoc !! .. py:attribute:: high_fixed_rate_thresh :type: fixedpointmath.FixedPoint Amount over variable rate to arbitrage. .. !! processed by numpydoc !! .. py:attribute:: low_fixed_rate_thresh :type: fixedpointmath.FixedPoint Amount below variable rate to arbitrage. Defaults to 0. .. !! processed by numpydoc !! .. py:attribute:: auto_fixed_rate_thresh :type: bool :value: False If set, override the high and low rate thresholds to compute profitable amounts based on fees. .. !! processed by numpydoc !! .. py:attribute:: rate_slippage :type: fixedpointmath.FixedPoint .. py:attribute:: done_on_empty :type: bool :value: False Whether to exit the bot if there are no trades. .. !! processed by numpydoc !! .. py:attribute:: min_trade_amount_bonds :type: fixedpointmath.FixedPoint The minimum bond trade amount below which the agent won't submit a trade. .. !! processed by numpydoc !! .. py:property:: arb_portion :type: fixedpointmath.FixedPoint The portion of capital assigned to arbitrage. .. !! processed by numpydoc !! .. py:attribute:: min_trade_amount_bonds .. py:method:: action(interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, wallet: agent0.core.hyperdrive.HyperdriveWallet) -> tuple[list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]], bool] Specify actions. :param interface: Interface for the market on which this agent will be executing trades (MarketActions). :type interface: HyperdriveReadInterface :param wallet: The agent's wallet. :type wallet: HyperdriveWallet :returns: A tuple where the first element is a list of actions, and the second element defines if the agent is done trading. :rtype: tuple[list[MarketAction], bool] .. !! processed by numpydoc !!