agent0.core.hyperdrive.interactive.hyperdrive_agent
The hyperdrive agent object that encapsulates an agent.
Classes
Interactive Hyperdrive Agent. |
Module Contents
- class agent0.core.hyperdrive.interactive.hyperdrive_agent.HyperdriveAgent(name: str | None, chain: agent0.core.hyperdrive.interactive.chain.Chain, 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)
Interactive Hyperdrive Agent.
- chain
- address: eth_typing.ChecksumAddress
- nonce_lock
- current_nonce = 0
- property account: eth_account.signers.local.LocalAccount
Returns the LocalAccount associated with the agent.
- property policy_done_trading: bool
Return whether the agent’s policy is done trading.
- 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 (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
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_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.
- 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.
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 (Hyperdrive) – 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.
- 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 (Hyperdrive | 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 (Hyperdrive | 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 (Hyperdrive | 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 (Hyperdrive | 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 (Hyperdrive | 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 (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
The emitted event of the remove liquidity call.
- Return type:
RemoveLiquidity
Redeems withdrawal shares for this agent.
- Parameters:
shares (FixedPoint) – The amount of withdrawal shares to redeem in units of shares.
pool (Hyperdrive | 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 (Hyperdrive | 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 (Hyperdrive | 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 (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Events of the executed actions.
- Return type:
list[BaseHyperdriveEvent]
- execute_policy_action(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) list[hyperdrivetypes.BaseEvent]
Gets the underlying policy action and executes them.
This function simply calls execute_action with the result of get_policy_action.
- Parameters:
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Events of the executed actions.
- Return type:
list[BaseHyperdriveEvent]
- execute_liquidate(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, randomize: bool = False) list[hyperdrivetypes.BaseEvent]
Gets the agent’s liquidate actions and executes them.
This function simply calls execute_action with the result of get_liquidate_action.
- Parameters:
randomize (bool, optional) – Whether to randomize liquidation trades. Defaults to False.
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Events of the executed actions.
- Return type:
list[CloseLong | CloseShort | RemoveLiquidity | RedeemWithdrawalShares]
- get_eth() fixedpointmath.FixedPoint
Returns the ETH balance of the agent.
- Returns:
Returns the ETH balance of the agent.
- Return type:
FixedPoint
- get_wallet(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) agent0.core.hyperdrive.agent.HyperdriveWallet
Returns the wallet object for the agent for the given hyperdrive pool.
- Parameters:
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Returns the HyperdriveWallet object for the given pool.
- Return type:
- get_longs(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) list[agent0.core.hyperdrive.agent.hyperdrive_wallet.Long]
Returns longs for the agent for the given hyperdrive pool.
- Parameters:
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Returns the list of longs for the given pool.
- Return type:
list[Long]
- get_shorts(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) list[agent0.core.hyperdrive.agent.hyperdrive_wallet.Short]
Returns shorts for the agent for the given hyperdrive pool.
- Parameters:
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Returns the list of longs for the given pool.
- Return type:
list[Short]
- get_lp(pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None) fixedpointmath.FixedPoint
Returns lp balance for the agent for the given hyperdrive pool.
- Parameters:
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Returns the list of longs for the given pool.
- Return type:
list[Short]
Returns withdrawal shares balance for the agent for the given hyperdrive pool.
- Parameters:
pool (Hyperdrive | None, optional) – The pool to interact with. Defaults to the active pool.
- Returns:
Returns the list of longs for the given pool.
- Return type:
list[Short]
- 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) pandas.DataFrame
Returns all of the agent’s positions across all hyperdrive pools.
- Parameters:
pool_filter (Hyperdrive | list[Hyperdrive], 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.
- 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 (Hyperdrive | list[Hyperdrive] | None, optional) – The hyperdrive pool(s) to get trade events from.
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: