agent0.core.hyperdrive.interactive.local_hyperdrive_agent

The hyperdrive agent object that encapsulates an agent.

Classes

LocalHyperdriveAgent

Interactive Local Hyperdrive Agent.

Module Contents

class agent0.core.hyperdrive.interactive.local_hyperdrive_agent.LocalHyperdriveAgent(base: fixedpointmath.FixedPoint, eth: fixedpointmath.FixedPoint, name: str | None, chain: agent0.core.hyperdrive.interactive.local_chain.LocalChain, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None, policy: Type[agent0.core.hyperdrive.policies.HyperdriveBasePolicy] | None, policy_config: agent0.core.hyperdrive.policies.HyperdriveBasePolicy.Config | None, private_key: str | None, public_address: str | None)

Bases: agent0.core.hyperdrive.interactive.hyperdrive_agent.HyperdriveAgent

Interactive Local Hyperdrive Agent.

chain
add_funds(base: fixedpointmath.FixedPoint | None = None, eth: fixedpointmath.FixedPoint | None = None, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, signer_account: eth_account.signers.local.LocalAccount | None = None, whale_accounts: dict[eth_typing.ChecksumAddress, eth_typing.ChecksumAddress] | None = None) None

Adds additional funds to the agent.

Note

This method calls set_anvil_account_balance for eth and

mint or account impersonation + transfers from whale accounts under the hood. These functions are likely to fail on any non-test network, but we add them to the interactive agent for convenience.

Parameters:
  • base (FixedPoint | None, optional) – The amount of base to fund the agent with. Defaults to 0.

  • eth (FixedPoint | None, optional) – The amount of ETH to fund the agent with. Defaults to 0.

  • pool (LocalHyperdrive | None, optional) – The pool to mint base for.

  • signer_account (LocalAccount | None, optional) – The signer account to use to call mint. Defaults to the agent itself.

  • whale_accounts (dict[ChecksumAddress, ChecksumAddress] | None, optional) – A mapping between token -> whale addresses to use to fund the fuzz agent. If the token is not in the mapping, will attempt to call mint on the token contract. Defaults to an empty mapping.

set_active(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, policy: Type[agent0.core.hyperdrive.policies.HyperdriveBasePolicy] | None = None, policy_config: agent0.core.hyperdrive.policies.HyperdriveBasePolicy.Config | None = None) None

Sets the active pool or policy for the agent and calls max approval for the pool.

Setting an active pool for an agent allows trades to default to this pool. Setting an active policy for an agent uses this policy with execute_policy_action.

Parameters:
  • pool (LocalHyperdrive) – The pool to set as the active pool.

  • policy (Type[HyperdriveBasePolicy] | None) – The policy to set as the active policy.

  • policy_config (HyperdriveBasePolicy.Config | None) – The configuration for the attached policy.

property account: eth_account.signers.local.LocalAccount

Returns the LocalAccount associated with the agent.

set_max_approval(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) None

Sets the max approval to the hyperdrive contract.

Warning

This sets the max approval to the underlying hyperdrive contract for

this wallet. Do this at your own risk.

Parameters:

pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

open_long(base: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.OpenLongEventFP

Opens a long for this agent.

Parameters:
  • base (FixedPoint) – The amount of longs to open in units of base.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the open long call.

Return type:

OpenLong

close_long(maturity_time: int, bonds: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.CloseLongEventFP

Closes a long for this agent.

Parameters:
  • maturity_time (int) – The maturity time of the bonds to close. This is the identifier of the long tokens.

  • bonds (FixedPoint) – The amount of longs to close in units of bonds.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the close long call.

Return type:

CloseLong

open_short(bonds: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.OpenShortEventFP

Opens a short for this agent.

Parameters:
  • bonds (FixedPoint) – The amount of shorts to open in units of bonds.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the open short call.

Return type:

OpenShort

close_short(maturity_time: int, bonds: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.CloseShortEventFP

Closes a short for this agent.

Parameters:
  • maturity_time (int) – The maturity time of the bonds to close. This is the identifier of the short tokens.

  • bonds (FixedPoint) – The amount of shorts to close in units of bonds.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the close short call.

Return type:

CloseShort

add_liquidity(base: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.AddLiquidityEventFP

Adds liquidity for this agent.

Parameters:
  • base (FixedPoint) – The amount of liquidity to add in units of base.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the add liquidity call.

Return type:

AddLiquidity

remove_liquidity(shares: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.RemoveLiquidityEventFP

Removes liquidity for this agent.

Parameters:
  • shares (FixedPoint) – The amount of liquidity to remove in units of shares.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the remove liquidity call.

Return type:

RemoveLiquidity

redeem_withdrawal_shares(shares: fixedpointmath.FixedPoint, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) hyperdrivetypes.RedeemWithdrawalSharesEventFP

Redeems withdrawal shares for this agent.

Parameters:
  • shares (FixedPoint) – The amount of withdrawal shares to redeem in units of shares.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The emitted event of the redeem withdrawal shares call.

Return type:

RedeemWithdrawalShares

get_policy_action(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]]

Gets the underlying policy actions.

Parameters:

pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

The actions of the underlying policy.

Return type:

list[Trade[HyperdriveMarketAction]]

get_liquidate_action(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, randomize: bool = False) list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]]

Gets the liquidate actions for this agent.

Parameters:
  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

  • randomize (bool, optional) – Whether to randomize the order of the liquidate actions.

Returns:

The liquidate actions of the underlying policy.

Return type:

list[Trade[HyperdriveMarketAction]]

execute_action(actions: list[agent0.core.base.Trade[agent0.core.hyperdrive.HyperdriveMarketAction]], pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) list[hyperdrivetypes.BaseEvent]

Executes the specified actions.

Parameters:
  • actions (list[Trade[HyperdriveMarketAction]]) – The actions to execute. This is the return value of get_policy_action or get_liquidate_action.

  • pool (LocalHyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.

Returns:

Events of the executed actions.

Return type:

list[BaseHyperdriveEvent]

get_positions(pool_filter: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | list[agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive] | None = None, show_closed_positions: bool = False, calc_pnl: bool = False, coerce_float: bool = False, registry_address: str | None = None) pandas.DataFrame

Returns all of the agent’s positions across all hyperdrive pools.

Parameters:
  • pool_filter (LocalHyperdrive | list[LocalHyperdrive], optional) – The hyperdrive pool(s) to query. Defaults to None, which will query all pools.

  • show_closed_positions (bool, optional) – Whether to show positions closed positions (i.e., positions with zero balance). Defaults to False. When False, will only return currently open positions. Useful for gathering currently open positions. When True, will also return any closed positions. Useful for calculating overall pnl of all positions.

  • calc_pnl (bool, optional) – If the chain config’s calc_pnl flag is False, passing in calc_pnl=True to this function allows for a one-off pnl calculation for the current positions. Ignored if the chain’s calc_pnl flag is set to True, as every position snapshot will return pnl information.

  • coerce_float (bool, optional) – Whether to coerce underlying Decimal values to float when as_df is True. Defaults to False.

  • registry_address (str, optional) – Must be None when calling from local hyperdrive agent.

Returns:

The agent’s positions across all hyperdrive pools.

Return type:

pd.DataFrame

get_trade_events(pool_filter: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | list[agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive] | None = None, all_token_deltas: bool = False, coerce_float: bool = False) pandas.DataFrame

Returns the agent’s current wallet.

Parameters:
  • pool_filter (LocalHyperdrive | list[LocalHyperdrive] | None, optional) – The hyperdrive pool(s) to get trade events from. If None, will retrieve all events from all pools.

  • all_token_deltas (bool, optional) – When removing liquidity that results in withdrawal shares, the events table returns two entries for this transaction to keep track of token deltas (one for lp tokens and one for withdrawal shares). If this flag is true, will return all entries in the table, which is useful for calculating token positions. If false, will drop the duplicate withdrawal share entry (useful for returning a ticker).

  • coerce_float (bool, optional) – If True, will coerce underlying Decimals to floats.

Returns:

The agent’s current wallet.

Return type:

HyperdriveWallet