agent0.ethpy.hyperdrive
Interfaces for bots and hyperdrive smart contracts.
Submodules
Attributes
Classes
The asset ID is used to encode the trade type in a transaction receipt |
|
Collection of attributes associated with a locally deployed Hyperdrive factory. |
|
Collection of attributes associated with a locally deployed chain with a Hyperdrive pool. |
|
The deploy type for the hyperdrive pool. |
|
Read-only end-point API for interfacing with a deployed Hyperdrive pool. |
|
Read-write end-point API for interfacing with a deployed Hyperdrive pool. |
Functions
|
Fetch addresses for deployed contracts in the Hyperdrive system. |
|
Generates a name for a given hyperdrive address. The address generated is of the form |
Fetch addresses for deployed contracts in the Hyperdrive system. |
|
|
Decodes a transaction asset ID into its constituent parts of an identifier, data, and a timestamp. |
|
Encodes a prefix and a timestamp into an asset ID. |
|
Deploys the underlying base and vault contracts |
|
Deploys the hyperdrive factory and supporting contracts on the rpc_uri chain. |
|
Initializes a Hyperdrive pool and supporting contracts on an existing chain. |
|
Checks that the version meets the minimum hyperdrive version. |
Get the minimum hyperdrive version from the min-hyperdrive.version file. |
|
Get the checkpoint info for the Hyperdrive contract at a given block. |
|
Get the checkpoint exposure for the Hyperdrive contract at a given block. |
|
Get the hyperdrive config from a deployed hyperdrive contract. |
|
Get the block pool info from the Hyperdrive contract. |
Package Contents
- agent0.ethpy.hyperdrive.get_hyperdrive_addresses_from_registry(hyperdrive_registry_addr: str, web3: web3.Web3) dict[str, eth_typing.ChecksumAddress]
Fetch addresses for deployed contracts in the Hyperdrive system.
- Parameters:
hyperdrive_registry_addr (str) – The address of the Hyperdrive registry contract.
web3 (Web3) – The instantiated Web3 instance that’s connect to a chain to use.
- Returns:
A dictionary keyed by the pool name (e.g., StETHHyperdrive_14day) with a value of the address of the deployed hyperdrive pool.
- Return type:
dict[str, ChecksumAddress]
- agent0.ethpy.hyperdrive.get_hyperdrive_name(hyperdrive_address: eth_typing.ChecksumAddress, web3: web3.Web3) str
Generates a name for a given hyperdrive address. The address generated is of the form <vault_shares_token_symbol>_<position_duration>_day.
- Parameters:
hyperdrive_address (ChecksumAddress) – The address of a hyperdrive pool.
web3 (Web3) – The instantiated Web3 instance that’s connect to a chain to use.
- Returns:
The generated name of the hyperdrive pool.
- Return type:
str
- agent0.ethpy.hyperdrive.get_hyperdrive_registry_from_artifacts(artifacts_uri: str) str
Fetch addresses for deployed contracts in the Hyperdrive system.
- Parameters:
artifacts_uri (str) – The URI for the artifacts endpoint.
- Returns:
A dictionary that mirrors the artifacts json structure.
- Return type:
dict[str, ChecksumAddress]
- agent0.ethpy.hyperdrive.BASE_TOKEN_SYMBOL = 'WETH'
- class agent0.ethpy.hyperdrive.AssetIdPrefix
Bases:
enum.IntEnumThe asset ID is used to encode the trade type in a transaction receipt
- LP = 0
- LONG = 1
- SHORT = 2
- WITHDRAWAL_SHARE = 3
- agent0.ethpy.hyperdrive.decode_asset_id(asset_id: int) tuple[int, int]
Decodes a transaction asset ID into its constituent parts of an identifier, data, and a timestamp.
First calculate the prefix mask by left-shifting 1 by 248 bits and subtracting 1 from the result. This gives us a bit-mask with 248 bits set to 1 and the rest set to 0. Then apply this mask to the input ID using the bitwise-and operator & to extract the lower 248 bits as the timestamp.
- Parameters:
asset_id (int) – Encoded ID from a transaction. It is a concatenation, [identifier: 8 bits][timestamp: 248 bits]
- Returns:
identifier, timestamp
- Return type:
tuple[int, int]
- agent0.ethpy.hyperdrive.encode_asset_id(prefix: int, timestamp: int) int
Encodes a prefix and a timestamp into an asset ID.
Asset IDs are used so that LP, long, and short tokens can all be represented in a single MultiToken instance. The zero asset ID indicates the LP token.
Encode the asset ID by left-shifting the prefix by 248 bits, then bitwise-or-ing the result with the timestamp.
- Parameters:
prefix (int) – A one byte prefix that specifies the asset type.
timestamp (int) – A timestamp associated with the asset.
- Returns:
The asset ID.
- Return type:
int
- class agent0.ethpy.hyperdrive.DeployedHyperdriveFactory
Bases:
NamedTupleCollection of attributes associated with a locally deployed Hyperdrive factory.
- deployer_account: eth_account.signers.local.LocalAccount
- factory_contract: hyperdrivetypes.types.HyperdriveFactoryContract
- deployer_coordinator_contract: hyperdrivetypes.types.ERC4626HyperdriveDeployerCoordinatorContract | hyperdrivetypes.types.StETHHyperdriveDeployerCoordinatorContract
- factory_deploy_config: hyperdrivetypes.types.HyperdriveFactory.FactoryConfig
- class agent0.ethpy.hyperdrive.DeployedHyperdrivePool
Bases:
NamedTupleCollection of attributes associated with a locally deployed chain with a Hyperdrive pool.
- deployer_account: eth_account.signers.local.LocalAccount
- hyperdrive_contract: hyperdrivetypes.types.IHyperdriveContract
- base_token_contract: hyperdrivetypes.types.ERC20MintableContract | web3.contract.contract.Contract
- deploy_block_number: int
- pool_deploy_config: hyperdrivetypes.types.IHyperdrive.PoolDeployConfig
- class agent0.ethpy.hyperdrive.HyperdriveDeployType
Bases:
enum.EnumThe deploy type for the hyperdrive pool.
- ERC4626 = 0
- STETH = 1
- agent0.ethpy.hyperdrive.deploy_base_and_vault(web3: web3.Web3, deploy_type: HyperdriveDeployType, deploy_account: eth_account.signers.local.LocalAccount, initial_variable_rate: fixedpointmath.FixedPoint) DeployedBaseAndVault
Deploys the underlying base and vault contracts
- Parameters:
web3 (Web3) – Web3 provider object.
deploy_type (HyperdriveDeployType) – The deploy type for the hyperdrive pool.
deploy_account (LocalAccount) – The account that’s deploying the contract.
initial_variable_rate (FixedPoint) – The starting variable rate for an underlying vault.
- Returns:
Containing the deployed base and vault contracts.
- Return type:
- agent0.ethpy.hyperdrive.deploy_hyperdrive_factory(web3: web3.Web3, deployer_account: eth_account.signers.local.LocalAccount, deployed_base_and_vault: DeployedBaseAndVault, deploy_type: HyperdriveDeployType, factory_deploy_config: hyperdrivetypes.types.HyperdriveFactory.FactoryConfig) DeployedHyperdriveFactory
Deploys the hyperdrive factory and supporting contracts on the rpc_uri chain.
- Parameters:
web3 (Web3) – Web3 provider object.
deployer_account (LocalAccount) – The account that’s deploying the contract.
deployed_base_and_vault (DeployedBaseAndVault) – The base and vault contracts that were deployed on the local chain.
deploy_type (HyperdriveDeployType) – The deploy type for the hyperdrive pool.
factory_deploy_config (FactoryConfig) – The factory configuration for initializing the hyperdrive factory. The type is generated from the Hyperdrive ABI using Pypechain.
- Returns:
Containing the deployed factory, the deploy coordinator contracts, the updated factory config, and the hyperdrive registry contract.
- Return type:
- agent0.ethpy.hyperdrive.deploy_hyperdrive_from_factory(web3: web3.Web3, deployer_account: eth_account.signers.local.LocalAccount, deployed_base_and_vault: DeployedBaseAndVault, deployed_factory: DeployedHyperdriveFactory, deploy_type: HyperdriveDeployType, initial_liquidity: fixedpointmath.FixedPoint, initial_fixed_apr: fixedpointmath.FixedPoint, initial_time_stretch_apr: fixedpointmath.FixedPoint, pool_deploy_config: hyperdrivetypes.types.IHyperdrive.PoolDeployConfig) DeployedHyperdrivePool
Initializes a Hyperdrive pool and supporting contracts on an existing chain.
- Parameters:
web3 (Web3) – Web3 provider object.
deployer_account (LocalAccount) – The local account deploying Hyperdrive.
deployed_base_and_vault (DeployedBaseAndVault) – The base and vault contracts that were deployed on the local chain.
deployed_factory (DeployedHyperdriveFactory) – The factory and supporting contracts that were deployed on the local chain.
deploy_type (HyperdriveDeployType) – The deploy type for the hyperdrive pool.
initial_liquidity (FixedPoint) – The amount of money to be provided by the deployer_account for initial pool liquidity.
initial_fixed_apr (FixedPoint) – The fixed rate of the pool on initialization.
initial_time_stretch_apr (FixedPoint) – The apr to target for the time stretch calculation.
pool_deploy_config (PoolDeployConfig) – The configuration for initializing hyperdrive pool. The type is generated from the Hyperdrive ABI using Pypechain.
- Returns:
- A named tuple with the following fields:
- deploy_account: LocalAccount
The local account that deploys and initializes hyperdrive.
- hyperdrive_contract: IHyperdriveContract
Web3 contract instance for the hyperdrive contract.
- base_token_contract: Contract
Web3 contract instance for the base token contract.
- vault_shares_token_contract: Contract
Web3 contract instance for the vault shares token contract.
- deploy_block_number: int
The block number hyperdrive was deployed at.
- Return type:
- agent0.ethpy.hyperdrive.check_hyperdrive_version(in_version: str) bool
Checks that the version meets the minimum hyperdrive version.
- Parameters:
in_version (str) – The version string to check.
- Returns:
True if the version meets the minimum hyperdrive version.
- Return type:
bool
- agent0.ethpy.hyperdrive.get_minimum_hyperdrive_version() str
Get the minimum hyperdrive version from the min-hyperdrive.version file.
- Returns:
The minimum hyperdrive version.
- Return type:
str
- class agent0.ethpy.hyperdrive.HyperdriveReadInterface(hyperdrive_address: eth_typing.ChecksumAddress, rpc_uri: str | None = None, web3: web3.Web3 | None = None, txn_receipt_timeout: float | None = None, txn_signature: bytes | None = None)
Read-only end-point API for interfacing with a deployed Hyperdrive pool.
- class HyperdriveKind
Bases:
enum.EnumHyperdrive contract kind.
NOTE the values of these enums match the output of the kind() function from the hyperdrive contract.
- ERC4626 = 'ERC4626Hyperdrive'
- STETH = 'StETHHyperdrive'
- MORPHO = 'MorphoBlueHyperdrive'
- EZETH = 'EzETHHyperdrive'
- RETH = 'RETHHyperdrive'
- STKWELL = 'StkWellHyperdrive'
- EETH = 'EETHHyperdrive'
- hyperdrive_address
- web3 = None
- hyperdrive_contract
- hyperdrive_version
- pool_config
- hyperdrive_name
- morpho_contract = None
- morpho_market_id = None
- base_token_contract: hyperdrivetypes.types.ERC20MintableContract
- txn_receipt_timeout = None
- last_state_block_number = -1
- get_deploy_block_number() eth_typing.BlockNumber | None
Get the block number that the Hyperdrive contract was deployed on.
NOTE: The deploy event may get lost on e.g., anvil, so we ensure we only check once
- Returns:
The block number that the Hyperdrive contract was deployed on. Returns None if it can’t be found.
- Return type:
BlockNumber | None
- property current_pool_state: agent0.ethpy.hyperdrive.state.PoolState
The current state of the pool.
Each time this is accessed we use an RPC to check that the pool state is synced with the current block.
- get_current_block() web3.types.BlockData
Use an RPC to get the current block.
- Returns:
A web3py dataclass containing information about the latest mined block.
- Return type:
BlockData
- get_block(block_identifier: web3.types.BlockIdentifier) web3.types.BlockData
Use an RPC to get the block for the provided identifier.
Delegates to eth_getBlockByNumber if block_identifier is an integer or one of the predefined block parameters ‘latest’, ‘earliest’, ‘pending’, ‘safe’, ‘finalized’. Otherwise delegates to eth_getBlockByHash. Throws BlockNotFound error if the block is not found.
- Parameters:
block_identifier (BlockIdentifier) – Any one of the web3py types: [BlockParams, BlockNumber, Hash32, HexStr, HexBytes, int].
- Returns:
A web3py dataclass containing block information.
- Return type:
BlockData
- get_block_number(block: web3.types.BlockData) eth_typing.BlockNumber
Use an RPC to get the number for the provided block.
- Parameters:
block (BlockData) – A web3py dataclass for storing block information.
- Returns:
The number for the corresponding block.
- Return type:
BlockNumber
- get_block_timestamp(block: web3.types.BlockData) web3.types.Timestamp
Use an RPC to get the time for the provided block.
- Parameters:
block (BlockData) – A web3py dataclass for storing block information.
- Returns:
The integer timestamp, in seconds, for the corresponding block.
- Return type:
Timestamp
- get_hyperdrive_state(block_identifier: web3.types.BlockIdentifier | None = None, block_data: web3.types.BlockData | None = None) agent0.ethpy.hyperdrive.state.PoolState
Use RPCs and contract calls to get the Hyperdrive pool and block state, given a block identifier.
- Parameters:
block_identifier (BlockIdentifier, optional) – The block identifier to get hyperdrive state on.
block_data (BlockData, optional) – The block data to use to get hyperdrive state. This parameter is useful for reusing a previously retrieved block data. Can’t provide both block_identifier and block_data at the same time.
- Returns:
A dataclass containing PoolInfo, PoolConfig, Checkpoint, and Block information that is synced to a given block number.
- Return type:
- get_checkpoint(checkpoint_time: web3.types.Timestamp, block_identifier: web3.types.BlockIdentifier | None = None) hyperdrivetypes.CheckpointFP
Use an RPC to get the checkpoint info for the Hyperdrive contract for a given checkpoint_time index.
- Parameters:
checkpoint_time (Timestamp) – The block timestamp that indexes the checkpoint to get.
block_identifier (BlockIdentifier, optional) – The identifier for a block. If not given, the latest block is used.
- Returns:
The dataclass containing the checkpoint info in fixed point
- Return type:
CheckpointFP
Use an RPC to get the minimum transaction amount in units of shares at the given block.
- Parameters:
block_identifier (BlockIdentifier, optional) – The identifier for a block. If not given, the latest block number is used.
- Returns:
The quantity of withdrawal shares available in the Hyperdrive pool.
- Return type:
FixedPoint
Use an RPC to get the total supply of withdrawal shares in the pool at the given block.
- Parameters:
block_identifier (BlockIdentifier, optional) – The identifier for a block. If not given, the latest block number is used.
- Returns:
The quantity of withdrawal shares available in the Hyperdrive pool.
- Return type:
FixedPoint
Use an RPC to get the balance of shares that the Hyperdrive pool has in the underlying yield source.
- Parameters:
block_identifier (BlockNumber, optional) – The identifier for a block. Defaults to the current block number.
- Returns:
The quantity of vault shares for the yield source at the provided block.
- Return type:
FixedPoint
Get the balance of idle shares that the Hyperdrive pool has.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The quantity of vault shares for the yield source at the provided block.
- Return type:
FixedPoint
- get_variable_rate(block_identifier: web3.types.BlockIdentifier | None = None) fixedpointmath.FixedPoint | None
Use an RPC to get the yield source variable rate.
Note
This function assumes there exists an underlying getRate function in the contract.
This call will return None if the deployed yield contract doesn’t have a getRate function. In this case, use get_standardized_variable_rate instead.
- Parameters:
block_identifier (BlockIdentifier, optional) – The identifier for a block. Defaults to the current block number.
- Returns:
The variable rate for the yield source at the provided block, or None if the yield source doesn’t have a getRate function.
- Return type:
FixedPoint | None
- get_standardized_variable_rate(time_range: int = 604800) fixedpointmath.FixedPoint
Get a standardized variable rate using vault share prices from checkpoints in the last time_range seconds.
Note
This function will throw an error if the pool was deployed within the last time_range seconds.
- Parameters:
time_range (int) – The time range (in seconds) to use to calculate the variable rate to look for checkpoints.
- Returns:
The standardized variable rate.
- Return type:
FixedPoint
- get_eth_base_balances(agent: eth_account.signers.local.LocalAccount) tuple[fixedpointmath.FixedPoint, fixedpointmath.FixedPoint]
Use an RPC to get the agent’s balance on the Base & Hyperdrive contracts.
- Parameters:
agent (LocalAccount) – The account for the agent that is executing and signing the trade transaction.
- Returns:
A tuple containing the [agent_eth_balance, agent_base_balance].
- Return type:
tuple[FixedPoint]
- get_hyperdrive_eth_balance() fixedpointmath.FixedPoint
Get the current Hyperdrive eth balance from an RPC.
- Returns:
The eth on the chain.
- Return type:
FixedPoint
- get_hyperdrive_base_balance(block_identifier: web3.types.BlockIdentifier | None = None) fixedpointmath.FixedPoint
Get the current Hyperdrive balance in the base contract.
- Parameters:
block_identifier (BlockIdentifier, optional) – The identifier for a block. Defaults to the current block number.
- Returns:
The result of base_token_contract.balanceOf(hyperdrive_address).
- Return type:
FixedPoint
- get_gov_fees_accrued(block_identifier: web3.types.BlockIdentifier | None = None) fixedpointmath.FixedPoint
Get the current amount of Uncollected Governance Fees in the Hyperdrive contract.
- Parameters:
block_identifier (BlockIdentifier, optional) – The identifier for a block. Defaults to the current block number.
- Returns:
The result of hyperdrive_contract.functions.getUncollectedGovernanceFees
- Return type:
FixedPoint
- get_long_total_supply(maturity_time: int, block_identifier: web3.types.BlockIdentifier | None = None) fixedpointmath.FixedPoint
Get the total supply of long tokens with the given maturity time.
- Parameters:
maturity_time (int) – The maturity time in seconds.
block_identifier (BlockIdentifier, optional) – The identifier for a block. Defaults to the current block number.
- Returns:
The result of the total supply of long tokens with the given maturity time.
- Return type:
FixedPoint
- get_short_total_supply(maturity_time: int, block_identifier: web3.types.BlockIdentifier | None = None) fixedpointmath.FixedPoint
Get the total supply of short tokens with the given maturity time.
- Parameters:
maturity_time (int) – The maturity time in seconds.
block_identifier (BlockIdentifier, optional) – The identifier for a block. Defaults to the current block number.
- Returns:
The result of the total supply of short tokens with the given maturity time.
- Return type:
FixedPoint
- get_pool_is_paused() bool
Get whether or not the pool is paused from events.
- Returns:
Whether or not the pool is paused.
- Return type:
bool
- calc_position_duration_in_years(pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Return the pool config position duration as a fraction of a year.
This “annualized” time value is used in some calculations, such as the Fixed APR. The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The annualized position duration
- Return type:
FixedPoint
- calc_time_stretch(target_rate: fixedpointmath.FixedPoint, target_position_duration: fixedpointmath.FixedPoint) fixedpointmath.FixedPoint
Return the time stretch parameter given a target fixed rate and position duration.
- Parameters:
target_rate (FixedPoint) – The fixed rate that the Hyperdrive pool will be initialized with.
target_position_duration (FixedPoint) – The position duration that the Hyperdrive pool will be initialized with.
- Returns:
The time stretch constant.
- Return type:
FixedPoint
- calc_checkpoint_timestamp(time: int | web3.types.Timestamp, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) web3.types.Timestamp
Converts a timestamp to the checkpoint timestamp that it corresponds to.
- Parameters:
time (int | Timestamp) – Any timestamp (in seconds) before or at the present.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The checkpoint timestamp.
- Return type:
Timestamp
- calc_checkpoint_id(checkpoint_duration: int | None = None, block_timestamp: web3.types.Timestamp | None = None) web3.types.Timestamp
Calculate the Checkpoint ID for a given timestamp.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
checkpoint_duration (int, optional) – The time, in seconds, between checkpoints. Defaults to the current pool’s checkpoint duration.
block_timestamp (Timestamp, optional) – A timestamp for any block. Use the latest block to get the current checkpoint id, or a specific timestamp of a transaction’s block if getting the checkpoint id for that transaction. Defaults to the current block timestamp.
- Returns:
The checkpoint id, in units of seconds, which represents the time of the last checkpoint.
- Return type:
int
- calc_spot_rate(pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the spot fixed rate for a given pool state.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs. The simulation follows the formula:
\[r = ((1 / p) - 1) / t = (1 - p) / (p * t)\]- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The fixed rate apr for the Hyperdrive pool state.
- Return type:
FixedPoint
- calc_rate_given_fixed_price(price: fixedpointmath.FixedPoint, position_duration: fixedpointmath.FixedPoint) fixedpointmath.FixedPoint
Calculate the rate assuming a given price is constant for some annualized duration.
We calculate the rate for a fixed length of time as:
- ..math::
r = (1 - p) / (p t)
where $p$ is the price and $t$ is the length of time that this price is assumed to be constant, in units of years. For example, if the price is constant for 6 months, then $t=0.5$. In our case, $t = text{position_duration} / (60*60*24*365)$.
- Parameters:
price (FixedPoint) – The spot price of bonds fora given pool.
position_duration (FixedPoint) – The pool bond position duration, over which the price is assumed to be constant.
- Returns:
The fixed rate apr for a given fixed price and position duration.
- Return type:
FixedPoint
- calc_spot_price(pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the spot price for a given Hyperdrive pool.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The spot price for the Hyperdrive pool state.
- Return type:
FixedPoint
- calc_max_spot_price(pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Get the pool’s max spot price.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The pool’s maximum achievable spot price.
- Return type:
FixedPoint
Calculate the adjusted share reserves for a given Hyperdrive pool.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The effective (aka zeta-adjusted) share reserves.
- Return type:
FixedPoint
Calculates the idle share reserves in base of the pool.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The pool’s idle share reserves in base.
- Return type:
FixedPoint
Return the bond reserves for the market share reserves and a given fixed rate.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs. The calculation is based on the formula:
\[\mu * (z - \zeta) * (1 + \text{apr} * t)^{1 / \tau}\]- Parameters:
target_rate (FixedPoint) – The target apr for which to calculate the bond reserves given the pools current share reserves.
target_shares (FixedPoint, optional) – The target share reserves for the pool
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The output bonds.
- Return type:
FixedPoint
- calc_open_long(base_amount: fixedpointmath.FixedPoint, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the long amount that will be opened for a given base amount after fees.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
base_amount (FixedPoint) – The amount to spend, in base.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of bonds purchased.
- Return type:
FixedPoint
- calc_pool_deltas_after_open_long(base_amount: fixedpointmath.FixedPoint, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) tuple[fixedpointmath.FixedPoint, fixedpointmath.FixedPoint]
Calculate the bond deltas to be applied to the pool after opening a long.
- Parameters:
base_amount (FixedPoint) – The amount of base used to open a long.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of (shares, bonds) to remove from the pool reserves.
- Return type:
tuple[FixedPoint, FixedPoint]
- calc_spot_price_after_long(base_amount: fixedpointmath.FixedPoint, bond_amount: fixedpointmath.FixedPoint | None = None, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the spot price for a given Hyperdrive pool after a long is opened for base_amount.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
base_amount (FixedPoint) – The amount of base provided for the long.
bond_amount (FixedPoint | None, optional) – The amount of bonds that would be purchased by the long. The default is to use whatever is returned by calc_open_long(base_amount).
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The spot price for the Hyperdrive pool state.
- Return type:
FixedPoint
- calc_spot_rate_after_long(base_amount: fixedpointmath.FixedPoint, bond_amount: fixedpointmath.FixedPoint | None = None, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the spot rate for a given Hyperdrive pool after a long is opened for base_amount.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
base_amount (FixedPoint) – The amount of base provided for the long.
bond_amount (FixedPoint | None, optional) – The amount of bonds that would be purchased by the long. The default is to use whatever is returned by calc_open_long(base_amount).
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The spot rate for the Hyperdrive pool state.
- Return type:
FixedPoint
- calc_max_long(budget: fixedpointmath.FixedPoint, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the maximum allowable long for the given Hyperdrive pool and agent budget.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
budget (FixedPoint) – How much money the agent is able to spend, in base.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The maximum long, in units of base.
- Return type:
FixedPoint
- calc_close_long(bond_amount: fixedpointmath.FixedPoint, maturity_time: int, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the amount of shares that will be returned after fees for closing a long.
- Parameters:
bond_amount (FixedPoint) – The amount of bonds to sell.
maturity_time (int) – The maturity time of the bond.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of shares returned.
- Return type:
FixedPoint
- calc_market_value_long(bond_amount: fixedpointmath.FixedPoint, maturity_time: int, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the amount of shares that will be returned after fees for closing a long.
- Parameters:
bond_amount (FixedPoint) – The amount of bonds to sell.
maturity_time (int) – The maturity time of the bond.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
An estimate of the amount of shares returned upon closing the long.
- Return type:
FixedPoint
- calc_targeted_long(budget: fixedpointmath.FixedPoint, target_rate: fixedpointmath.FixedPoint, max_iterations: int | None = None, allowable_error: fixedpointmath.FixedPoint | None = None, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the amount of bonds that can be purchased for the given budget.
- Parameters:
budget (FixedPont) – The account budget in base for making a long.
target_rate (FixedPoint) – The target fixed rate.
max_iterations (int | None, optional) – The number of iterations to use for the Newtonian method. Defaults to 7.
allowable_error (FixedPoint | None, optional) – The amount of error supported for reaching the target rate. Defaults to 1e-4.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of shares returned.
- Return type:
FixedPoint
- calc_open_short(bond_amount: fixedpointmath.FixedPoint, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the amount of base the trader will need to deposit for a short of a given size, after fees.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
bond_amount (FixedPoint) – The amount to of bonds to short.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of base required to short the bonds (aka the “max loss”).
- Return type:
FixedPoint
Calculate the amount of shares the pool will add after opening a short.
- Parameters:
bond_amount (FixedPoint) – The amount to of bonds to short.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of shares to add to the pool reserves.
- Return type:
FixedPoint
- calc_spot_price_after_short(bond_amount: fixedpointmath.FixedPoint, base_amount: fixedpointmath.FixedPoint | None = None, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the spot price for a given Hyperdrive pool after a short is opened for base_amount.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
bond_amount (FixedPoint) – The amount that woud be used to open a short.
base_amount (FixedPoint | None, optional) – The amount of base provided for the short. The default is to use whatever is returned by calc_open_short(bond_amount).
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The spot price for the Hyperdrive pool state.
- Return type:
FixedPoint
- calc_max_short(budget: fixedpointmath.FixedPoint, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the maximum allowable short for the given Hyperdrive pool and agent budget.
The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
budget (FixedPoint) – How much money the agent is able to spend, in base.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The maximum short, in units of bonds.
- Return type:
FixedPoint
- calc_close_short(bond_amount: fixedpointmath.FixedPoint, open_vault_share_price: fixedpointmath.FixedPoint, close_vault_share_price: fixedpointmath.FixedPoint, maturity_time: int, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Get the amount of shares the trader will receive from closing a short.
- Parameters:
bond_amount (FixedPoint) – The amount to of bonds provided.
open_vault_share_price (FixedPoint) – The checkpoint share price when the short was opened.
close_vault_share_price (FixedPoint) – The share price when the short was closed. If the short isn’t mature, this is the current share price. If the short is mature, this is the share price of the maturity checkpoint.
maturity_time (int) – The maturity time of the short.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of shares the trader will receive for closing the short.
- Return type:
FixedPoint
- calc_market_value_short(bond_amount: fixedpointmath.FixedPoint, open_vault_share_price: fixedpointmath.FixedPoint, close_vault_share_price: fixedpointmath.FixedPoint, maturity_time: int, pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Estimates the current market value of an open short position.
- Parameters:
bond_amount (FixedPoint) – The amount to of bonds provided.
open_vault_share_price (FixedPoint) – The checkpoint share price when the short was opened.
close_vault_share_price (FixedPoint) – The share price when the short was closed. If the short isn’t mature, this is the current share price. If the short is mature, this is the share price of the maturity checkpoint.
maturity_time (int) – The maturity time of the short.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
An estimate of the amount of shares returned upon closing the short.
- Return type:
FixedPoint
- calc_present_value(pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the present value of LPs capital in the pool.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The present value of all LP capital in the pool.
- Return type:
FixedPoint
- calc_solvency(pool_state: agent0.ethpy.hyperdrive.state.PoolState | None = None) fixedpointmath.FixedPoint
Calculate the pool’s solvency.
- Parameters:
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
solvency = share_reserves - long_exposure / vault_share_price - minimum_share_reserves
- Return type:
FixedPoint
Calculate the amount of bonds a user will receive from the pool by providing a specified amount of shares.
We underestimate the amount of bonds. The amount returned is before fees are applied. The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
amount_in (FixedPoint) – The amount of shares going into the pool.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of bonds out.
- Return type:
FixedPoint
Calculate the amount of shares a user must provide the pool to receive a specified amount of bonds.
We overestimate the amount of shares in. The amount returned is before fees are applied. The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
amount_in (FixedPoint) – The amount of bonds to target.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not given, use the current pool state.
- Returns:
The amount of shares in to reach the target.
- Return type:
FixedPoint
Calculate the amount of shares a user must provide the pool to receive a specified amount of bonds.
We underestimate the amount of shares in. The amount returned is before fees are applied. The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
amount_in (FixedPoint) – The amount of bonds to target.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not provided, use the current pool state.
- Returns:
The amount of shares in to reach the target.
- Return type:
FixedPoint
Calculate the amount of shares a user will receive from the pool by providing a specified amount of bonds.
We underestimate the amount of shares out. The amount returned is before fees are applied. The function does not perform contract calls, but instead relies on the Hyperdrive-rust api to simulate the contract outputs.
- Parameters:
amount_in (FixedPoint) – The amount of bonds in.
pool_state (PoolState | None, optional) – The state of the pool, which includes block details, pool config, and pool info. If not provided, use the current pool state.
- Returns:
The amount of shares out.
- Return type:
FixedPoint
- class agent0.ethpy.hyperdrive.HyperdriveReadWriteInterface(hyperdrive_address: eth_typing.ChecksumAddress, rpc_uri: str | None = None, web3: web3.Web3 | None = None, txn_receipt_timeout: float | None = None, txn_signature: bytes | None = None)
Bases:
agent0.ethpy.hyperdrive.interface.read_interface.HyperdriveReadInterfaceRead-write end-point API for interfacing with a deployed Hyperdrive pool.
- get_read_interface() agent0.ethpy.hyperdrive.interface.read_interface.HyperdriveReadInterface
Return the current instance as an instance of the parent (HyperdriveReadInterface) class.
- Returns:
This instantiated object, but as a ReadInterface.
- Return type:
- create_checkpoint(sender: eth_account.signers.local.LocalAccount, checkpoint_time: int | None = None, preview: bool = False, gas_limit: int | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None) hyperdrivetypes.CreateCheckpointEventFP
Create a Hyperdrive checkpoint.
- Parameters:
sender (LocalAccount) – The sender account that is executing and signing the trade transaction.
checkpoint_time (int, optional) – The checkpoint time to use. Defaults to the corresponding checkpoint for the provided block_number
preview (bool, optional) – Whether to preview the transaction first for error catching.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction.
nonce_func (Callable[[], Nonce] | None) – 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.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
CreateCheckpoint
- set_variable_rate(sender: eth_account.signers.local.LocalAccount, new_rate: fixedpointmath.FixedPoint) None
Set the variable rate for the yield source.
Note
This function assumes there’s an underlying setRate function in the contract.
This call will fail if the deployed yield contract doesn’t have a setRate function.
- Parameters:
sender (LocalAccount) – The sender account that is executing and signing the trade transaction.
new_rate (FixedPoint) – The new variable rate for the yield source.
- async async_open_long(sender: eth_account.signers.local.LocalAccount, trade_amount: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, gas_limit: int | None = None, txn_options_base_fee_multiple: float | None = None, txn_options_priority_fee_multiple: float | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None, preview_before_trade: bool = False) hyperdrivetypes.OpenLongEventFP
Contract call to open a long position.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
trade_amount (FixedPoint) – The size of the position, in base.
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.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
OpenLong
- async async_close_long(sender: eth_account.signers.local.LocalAccount, trade_amount: fixedpointmath.FixedPoint, maturity_time: int, slippage_tolerance: fixedpointmath.FixedPoint | None = None, gas_limit: int | None = None, txn_options_base_fee_multiple: float | None = None, txn_options_priority_fee_multiple: float | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None, preview_before_trade: bool = False) hyperdrivetypes.CloseLongEventFP
Contract call to close a long position.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
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.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
CloseLong
- async async_open_short(sender: eth_account.signers.local.LocalAccount, trade_amount: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, gas_limit: int | None = None, txn_options_base_fee_multiple: float | None = None, txn_options_priority_fee_multiple: float | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None, preview_before_trade: bool = False) hyperdrivetypes.OpenShortEventFP
Contract call to open a short position.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
trade_amount (FixedPoint) – The size of the position, in base.
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.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
OpenShort
- async async_close_short(sender: eth_account.signers.local.LocalAccount, trade_amount: fixedpointmath.FixedPoint, maturity_time: int, slippage_tolerance: fixedpointmath.FixedPoint | None = None, gas_limit: int | None = None, txn_options_base_fee_multiple: float | None = None, txn_options_priority_fee_multiple: float | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None, preview_before_trade: bool = False) hyperdrivetypes.CloseShortEventFP
Contract call to close a short position.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
trade_amount (FixedPoint) – The size of the position, in base.
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.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
CloseShort
- async async_add_liquidity(sender: eth_account.signers.local.LocalAccount, trade_amount: fixedpointmath.FixedPoint, min_apr: fixedpointmath.FixedPoint, max_apr: fixedpointmath.FixedPoint, slippage_tolerance: fixedpointmath.FixedPoint | None = None, gas_limit: int | None = None, txn_options_base_fee_multiple: float | None = None, txn_options_priority_fee_multiple: float | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None, preview_before_trade: bool = False) hyperdrivetypes.AddLiquidityEventFP
Contract call to add liquidity to the Hyperdrive pool.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
trade_amount (FixedPoint) – The size of the position, in base.
min_apr (FixedPoint) – The minimum allowable APR after liquidity is added.
max_apr (FixedPoint) – The maximum allowable APR after liquidity is added.
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.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
AddLiquidity
- async async_remove_liquidity(sender: eth_account.signers.local.LocalAccount, trade_amount: fixedpointmath.FixedPoint, gas_limit: int | None = None, txn_options_base_fee_multiple: float | None = None, txn_options_priority_fee_multiple: float | None = None, nonce_func: Callable[[], web3.types.Nonce] | None = None, preview_before_trade: bool = False) hyperdrivetypes.RemoveLiquidityEventFP
Contract call to remove liquidity from the Hyperdrive pool.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
trade_amount (FixedPoint) – The size of the position, in base.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
RemoveLiquidity
Contract call to redeem withdraw shares from Hyperdrive pool.
This should be done after closing liquidity.
Note
This is not guaranteed to redeem all shares. The pool will try to redeem as many as possible, up to the withdrawPool.readyToRedeem limit, without reverting. This will revert if the min_output is too high or the user is trying to withdraw more shares than they have.
- Parameters:
sender (LocalAccount) – The account that is executing and signing the trade transaction.
trade_amount (FixedPoint) – The size of the position, in base.
gas_limit (int | None, optional) – The maximum amount of gas used by the transaction. Defaults to eth_estimateGas RPC output.
txn_options_base_fee_multiple (float | None, optional) – The multiple applied to the base fee for the transaction. Defaults to 1.
txn_options_priority_fee_multiple (float | None, optional) – The multiple applied to the priority fee for the transaction. Defaults to 1.
nonce_func (Callable[[], Nonce] | None) – 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.
preview_before_trade (bool, optional) – Whether to preview the trade before executing. Defaults to False.
- Returns:
A dataclass containing the output event of the contract call.
- Return type:
RedeemWithdrawalShares
- agent0.ethpy.hyperdrive.get_hyperdrive_checkpoint(hyperdrive_contract: hyperdrivetypes.types.IHyperdriveContract, checkpoint_time: web3.types.Timestamp, block_identifier: web3.types.BlockIdentifier) hyperdrivetypes.fixedpoint_types.CheckpointFP
Get the checkpoint info for the Hyperdrive contract at a given block.
- Parameters:
hyperdrive_contract (IHyperdriveContract) – The contract to query the pool info from.
checkpoint_time (Timestamp) – The block timestamp that indexes the checkpoint to get.
block_identifier (BlockIdentifier) – The block number to query from the chain.
- Returns:
The dataclass containing the checkpoint info in fixed point
- Return type:
CheckpointFP
- agent0.ethpy.hyperdrive.get_hyperdrive_checkpoint_exposure(hyperdrive_contract: hyperdrivetypes.types.IHyperdriveContract, checkpoint_time: web3.types.Timestamp, block_identifier: web3.types.BlockIdentifier) fixedpointmath.FixedPoint
Get the checkpoint exposure for the Hyperdrive contract at a given block.
- Parameters:
hyperdrive_contract (IHyperdriveContract) – The contract to query the pool info from.
checkpoint_time (Timestamp) – The block timestamp that indexes the checkpoint to get. This must be an exact checkpoint time for the deployed pool.
block_identifier (BlockIdentifier) – The block number to query from the chain.
- Returns:
The dataclass containing the checkpoint info in fixed point.
- Return type:
CheckpointFP
- agent0.ethpy.hyperdrive.get_hyperdrive_pool_config(hyperdrive_contract: hyperdrivetypes.types.IHyperdriveContract) hyperdrivetypes.fixedpoint_types.PoolConfigFP
Get the hyperdrive config from a deployed hyperdrive contract.
- Parameters:
hyperdrive_contract (Contract) – The deployed hyperdrive contract instance.
- Returns:
The hyperdrive pool config.
- Return type:
dict[str, Any]
- agent0.ethpy.hyperdrive.get_hyperdrive_pool_info(hyperdrive_contract: hyperdrivetypes.types.IHyperdriveContract, block_identifier: web3.types.BlockIdentifier) hyperdrivetypes.fixedpoint_types.PoolInfoFP
Get the block pool info from the Hyperdrive contract.
- Parameters:
hyperdrive_contract (Contract) – The contract to query the pool info from.
block_identifier (BlockIdentifier) – The block identifier to query from the chain.
- Returns:
A dictionary containing the Hyperdrive pool info returned from the smart contract.
- Return type:
dict[str, Any]