agent0.core.hyperdrive.agent
Account and wallet with Hyperdrive specific parts
Submodules
Classes
The descriptor of an action in a market. |
|
Market action specification. |
|
Stateful variable for storing what is in the agent's wallet. |
|
An open long position. |
|
An open short position. |
|
A data object that stores all information of an executed trade. |
Functions
|
Return a trade object for adding liquidity. |
|
Return a trade object for closing a long. |
|
Return a trade object for closing a short. |
|
Return a trade object for opening a long. |
|
Return a trade object for opening a short. |
Return a trade object for redeeming withdraw shares. |
|
Return a trade object for removing liquidity. |
Package Contents
- class agent0.core.hyperdrive.agent.HyperdriveActionType
Bases:
enum.EnumThe descriptor of an action in a market.
- INITIALIZE_MARKET = 'initialize_market'
- OPEN_LONG = 'open_long'
- CLOSE_LONG = 'close_long'
- OPEN_SHORT = 'open_short'
- CLOSE_SHORT = 'close_short'
- ADD_LIQUIDITY = 'add_liquidity'
- REMOVE_LIQUIDITY = 'remove_liquidity'
- REDEEM_WITHDRAW_SHARE = 'redeem_withdraw_share'
- class agent0.core.hyperdrive.agent.HyperdriveMarketAction
Bases:
agent0.core.base.BaseMarketAction[HyperdriveActionType]Market action specification.
- action_type: HyperdriveActionType
- trade_amount: fixedpointmath.FixedPoint
- maturity_time: int | None = None
- slippage_tolerance: fixedpointmath.FixedPoint | None = None
- gas_limit: int | None = None
- base_fee_multiple: float | None = None
- priority_fee_multiple: float | None = None
- min_apr: fixedpointmath.FixedPoint
- max_apr: fixedpointmath.FixedPoint
- agent0.core.hyperdrive.agent.add_liquidity_trade(trade_amount: fixedpointmath.FixedPoint, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None, gas_limit: int | None = None, min_apr: fixedpointmath.FixedPoint | None = None, max_apr: fixedpointmath.FixedPoint | None = None) agent0.core.base.Trade[HyperdriveMarketAction]
Return a trade object for adding liquidity.
- Parameters:
trade_amount (FixedPoint) – The amount of liquidity you wish to add to the pool.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
min_apr (FixedPoint, optional) – Minimum allowable APR after liquidity is added. If this is not met, the trade will not execute. Defaults to the minimum solidity FixedPoint (1e-18)
max_apr (FixedPoint, optional) – Maximum allowable APR after liquidity is added. If this is not met, the trade will not execute. Defaults to the maximum solidity FixedPoint (2**256-1)
- Returns:
The trade object for adding liquidity to a Hyperdrive pool.
- Return type:
- agent0.core.hyperdrive.agent.close_long_trade(trade_amount: fixedpointmath.FixedPoint, maturity_time: int, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None, gas_limit: int | None = None) agent0.core.base.Trade[HyperdriveMarketAction]
Return a trade object for closing a long.
- Parameters:
trade_amount (FixedPoint) – The amount of bonds you wish to close.
maturity_time (int) – The token maturity time in seconds.
slippage_tolerance (FixedPoint, optional) – Amount of slippage allowed from the trade. If given, then the trade will not execute unless the slippage is below this value. If not given, then execute the trade regardless of the slippage.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
- Returns:
The trade object for closing a long in a Hyperdrive pool.
- Return type:
- agent0.core.hyperdrive.agent.close_short_trade(trade_amount: fixedpointmath.FixedPoint, maturity_time: int, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None, gas_limit: int | None = None) agent0.core.base.Trade[HyperdriveMarketAction]
Return a trade object for closing a short.
- Parameters:
trade_amount (FixedPoint) – The amount of bonds you wish to close.
maturity_time (int) – The token maturity time in seconds.
slippage_tolerance (FixedPoint, optional) – Amount of slippage allowed from the trade. If given, then the trade will not execute unless the slippage is below this value. If not given, then execute the trade regardless of the slippage.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
- Returns:
The trade object for closing a short in a Hyperdrive pool.
- Return type:
- agent0.core.hyperdrive.agent.open_long_trade(trade_amount: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None, gas_limit: int | None = None) agent0.core.base.Trade[HyperdriveMarketAction]
Return a trade object for opening a long.
- Parameters:
trade_amount (FixedPoint) – The amount of base you wish to use to open a long.
slippage_tolerance (FixedPoint, optional) – Amount of slippage allowed from the trade. If given, then the trade will not execute unless the slippage is below this value. If not given, then execute the trade regardless of the slippage.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
- Returns:
The trade object for opening a long in a Hyperdrive pool.
- Return type:
- agent0.core.hyperdrive.agent.open_short_trade(trade_amount: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None, gas_limit: int | None = None) agent0.core.base.Trade[HyperdriveMarketAction]
Return a trade object for opening a short.
- Parameters:
trade_amount (FixedPoint) – The amount of bonds you wish to short.
slippage_tolerance (FixedPoint, optional) – Amount of slippage allowed from the trade. If given, then the trade will not execute unless the slippage is below this value. If not given, then execute the trade regardless of the slippage.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
- Returns:
The trade object for opening a short in a Hyperdrive pool.
- Return type:
Return a trade object for redeeming withdraw shares.
- Parameters:
trade_amount (FixedPoint) – The amount of withdraw shares you wish to redeem from the pool.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
- Returns:
The trade object for redeeming withdraw shares from a Hyperdrive pool.
- Return type:
- agent0.core.hyperdrive.agent.remove_liquidity_trade(trade_amount: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, base_fee_multiple: float | None = None, priority_fee_multiple: float | None = None, gas_limit: int | None = None) agent0.core.base.Trade[HyperdriveMarketAction]
Return a trade object for removing liquidity.
- Parameters:
trade_amount (FixedPoint) – The amount of liquidity you wish to remove from the pool.
slippage_tolerance (FixedPoint, optional) – Amount of slippage allowed from the trade. If given, then the trade will not execute unless the slippage is below this value. If not given, then execute the trade regardless of the slippage.
base_fee_multiple (float | None, optional) – The base fee multiple for the transaction.
priority_fee_multiple (float | None, optional) – The priority fee multiple for the transaction.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
- Returns:
Trade[HyperdriveMarketAction] – The trade object for removing liquidity from a Hyperdrive pool.
.. warning:: – Slippage tolerance is not implemented for remove liquidity trades, field will be ignored.
- class agent0.core.hyperdrive.agent.HyperdriveWallet
Bases:
agent0.core.base.EthWalletStateful variable for storing what is in the agent’s wallet.
- lp_tokens: fixedpointmath.FixedPoint
The LP tokens held by the trader.
The amount of unclaimed withdraw shares held by the agent.
- longs: dict[int, Long]
The long positions held by the trader. The dictionary is keyed by the maturity time in seconds.
- shorts: dict[int, Short]
The short positions held by the trader. The dictionary is keyed by the maturity time in seconds.
- copy() HyperdriveWallet
Return a new copy of self.
- Returns:
A deep copy of the wallet.
- Return type:
- class agent0.core.hyperdrive.agent.Long
An open long position.
- balance: fixedpointmath.FixedPoint
The amount of bonds that the position is long.
- maturity_time: int
The maturity time of the long.
- class agent0.core.hyperdrive.agent.Short
An open short position.
- balance: fixedpointmath.FixedPoint
The amount of bonds that the position is short.
- maturity_time: int
The maturity time of the short.
- class agent0.core.hyperdrive.agent.TradeResult
A data object that stores all information of an executed trade.
- trade_successful: bool
The status of the trade.
- account: eth_account.signers.local.LocalAccount | None = None
The agent that was executing the trade.
- wallet: agent0.core.hyperdrive.agent.hyperdrive_wallet.HyperdriveWallet | None = None
The wallet of the agent that was executing the trade.
- policy: agent0.core.hyperdrive.policies.HyperdriveBasePolicy | None = None
The policy that was executing the trade.
- trade_object: agent0.core.base.Trade[agent0.core.hyperdrive.agent.hyperdrive_actions.HyperdriveMarketAction] | None = None
The trade object for the trade.
- hyperdrive_event: pypechain.core.BaseEvent | None = None
The transaction receipt of the trade.
- contract_call: dict[str, Any] | None = None
A dictionary detailing the underlying contract call.
- is_slippage: bool = False
If the trade failed due to slippage.
- is_invalid_balance: bool = False
If the trade failed due to invalid balance.
- is_insufficient_allowance: bool = False
If the trade failed due to insufficient approval.
- is_min_txn_amount: bool = False
If the trade failed due to minimum transaction amount.
- is_long_proceeds_less_than_fees: bool = False
If the trade failed due long proceeds less than fees.
- block_number: int | None = None
The block number of the transaction.
- block_timestamp: int | None = None
The block timestamp of the transaction.
- exception: Exception | None = None
The exception that was thrown.
- orig_exception: Exception | list[Exception] | BaseException | None = None
If exception was wrapped, the original exception that was thrown.
- pool_config: dict[str, Any] | None = None
The pool config information.
- pool_info: dict[str, Any] | None = None
The pool info information.
- checkpoint_info: dict[str, Any] | None = None
The checkpoint info information.
- contract_addresses: dict[str, Any] | None = None
The contract addresses.
- additional_info: dict[str, Any] | None = None
Additional information used for crash reporting.
- raw_transaction: dict[str, Any] | None = None
The raw transaction sent to the chain.
- raw_pool_config: dict[str, Any] | None = None
The raw pool config.
- raw_pool_info: dict[str, Any] | None = None
The raw pool info.
- raw_checkpoint: dict[str, Any] | None = None
The raw checkpoint info.
- anvil_state: str | None = None
The dumped anvil state.