agent0.ethpy.hyperdrive.interface.read_write_interface
High-level interface for writing to Hyperdrive smart contracts.
Classes
Read-write end-point API for interfacing with a deployed Hyperdrive pool. |
Module Contents
- class agent0.ethpy.hyperdrive.interface.read_write_interface.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