agent0.core.hyperdrive.interactive.local_hyperdrive

Defines the interactive hyperdrive class that encapsulates a hyperdrive pool.

Classes

LocalHyperdrive

Interactive Hyperdrive class that supports an interactive interface for running tests and experiments.

Module Contents

class agent0.core.hyperdrive.interactive.local_hyperdrive.LocalHyperdrive(chain: agent0.core.hyperdrive.interactive.local_chain.LocalChain, config: Config | None = None, name: str | None = None, deploy: bool = True, hyperdrive_address: eth_typing.ChecksumAddress | str | None = None, backfill_data_start_block: int | None = None, backfill_sample_period: int | None = None)

Bases: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive

Interactive Hyperdrive class that supports an interactive interface for running tests and experiments.

DeployType
class Config

Bases: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive.Config

The configuration for the local hyperdrive pool.

data_pipeline_timeout: int = 60

The timeout for the data pipeline. Defaults to 60 seconds.

initial_liquidity: fixedpointmath.FixedPoint

The amount of money to be provided by the deploy_account for initial pool liquidity.

initial_variable_rate: fixedpointmath.FixedPoint

The starting variable rate for an underlying yield source.

initial_fixed_apr: fixedpointmath.FixedPoint

The fixed rate of the pool on initialization.

initial_time_stretch_apr: fixedpointmath.FixedPoint

The rate to target for the time stretch.

factory_checkpoint_duration_resolution: int = 3600

The resolution for checkpoint durations.

factory_min_checkpoint_duration: int = 3600

The factory’s minimum checkpoint duration.

factory_max_checkpoint_duration: int = 86400

The factory’s maximum checkpoint duration.

factory_min_position_duration: int = 86400

The factory’s minimum position duration.

factory_max_position_duration: int = 315360000

The factory’s maximum position duration.

factory_min_circuit_breaker_delta: fixedpointmath.FixedPoint

The factory’s minimum circuit breaker delta.

factory_max_circuit_breaker_delta: fixedpointmath.FixedPoint

The factory’s maximum circuit breaker delta.

factory_min_fixed_apr: fixedpointmath.FixedPoint

The factory’s minimum fixed APR.

factory_max_fixed_apr: fixedpointmath.FixedPoint

The factory’s maximum fixed APR.

factory_min_time_stretch_apr: fixedpointmath.FixedPoint

The factory’s minimum time stretch rate.

factory_max_time_stretch_apr: fixedpointmath.FixedPoint

The factory’s maximum time stretch rate.

factory_min_curve_fee: fixedpointmath.FixedPoint

The lower bound on the curve fee that governance can set.

factory_min_flat_fee: fixedpointmath.FixedPoint

The lower bound on the flat fee that governance can set.

factory_min_governance_lp_fee: fixedpointmath.FixedPoint

The lower bound on the governance lp fee that governance can set.

factory_min_governance_zombie_fee: fixedpointmath.FixedPoint

The lower bound on the governance zombie fee that governance can set.

factory_max_curve_fee: fixedpointmath.FixedPoint

The upper bound on the curve fee that governance can set.

factory_max_flat_fee: fixedpointmath.FixedPoint

The upper bound on the flat fee that governance can set.

factory_max_governance_lp_fee: fixedpointmath.FixedPoint

The upper bound on the governance lp fee that governance can set.

factory_max_governance_zombie_fee: fixedpointmath.FixedPoint

The upper bound on the governance zombie fee that governance can set.

deploy_type: agent0.ethpy.hyperdrive.HyperdriveDeployType

The type of deployment to use. If not specified, it will default to ERC4626.

minimum_share_reserves: fixedpointmath.FixedPoint | None = None

The minimum share reserves.

minimum_transaction_amount: fixedpointmath.FixedPoint

The minimum amount of tokens that a position can be opened or closed with.

circuit_breaker_delta: fixedpointmath.FixedPoint

The circuit breaker delta defines the maximum delta between the last checkpoint’s weighted spot rate and the current spot rate to allow an LP to add liquidity.

position_duration: int = 604800

The duration of a position prior to maturity (in seconds).

checkpoint_duration: int = 3600

The duration of a checkpoint (in seconds).

curve_fee: fixedpointmath.FixedPoint

The LP fee applied to the curve portion of a trade.

flat_fee: fixedpointmath.FixedPoint

The LP fee applied to the flat portion of a trade in annualized rates.

governance_lp_fee: fixedpointmath.FixedPoint

The portion of the LP fee that goes to governance.

governance_zombie_fee: fixedpointmath.FixedPoint

The portion of the zombie interest that is given to governance as a fee. The portion of the zombie interest that will go to LPs is 1 - governance_zombie_fee.

classmethod get_hyperdrive_pools_from_registry(chain: agent0.core.hyperdrive.interactive.chain.Chain, registry_address: str) Sequence[LocalHyperdrive]

Gather deployed Hyperdrive pool addresses.

Parameters:
  • chain (Chain) – The Chain object connected to a chain.

  • registry_address (str) – The address of the Hyperdrive registry contract.

Returns:

The hyperdrive objects for all registered pools

Return type:

Sequence[LocalHyperdrive]

calc_pnl
chain
data_pipeline_timeout = 60
sync_database(start_block: int | None = None, progress_bar: bool = False, force_backfill: bool = False, backfill_sample_period: int | None = None) None

Explicitly syncs the database with the chain. This function doesn’t need to be explicitly called if manual_database_sync = False.

The database itself will determine how to append new data to ensure non-duplicated data. We call this function with a start block if we want to skip intermediate blocks. Subsequent calls after can again be self._deploy_block_number as long as the call with skipping blocks wrote a row, as the data pipeline checks the latest block entry and starts from there.

TODO these functions are not thread safe, need to fix if we expose async functions

Parameters:
  • start_block (int | None, optional) – The block number to start syncing from. Only used if we want to skip blocks in the database. Defaults to ensuring all blocks are synced.

  • progress_bar (bool, optional) – If True, will show a progress bar.

  • force_backfill (bool, optional) – If True, will force backfilling pool info data. Otherwise will look for chain.config.backfill_pool_info in the chain config.

  • backfill_sample_period (int | None, optional) – The sample period to use when backfilling data. Defaults to every block.

set_variable_rate(variable_rate: fixedpointmath.FixedPoint) None

Sets the underlying variable rate for this pool.

Parameters:

variable_rate (FixedPoint) – The new variable rate for the pool.

get_pool_config(coerce_float: bool = False) pandas.Series

Get the pool config and returns as a pandas series.

Parameters:

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

Returns:

A pandas series that consists of the deployed pool config.

Return type:

pd.Series

get_pool_info(coerce_float: bool = False) pandas.DataFrame

Get the pool info (and additional info) per block and returns as a pandas dataframe.

Parameters:

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

Returns:

A pandas dataframe that consists of the pool info per block.

Return type:

pd.Dataframe

get_checkpoint_info(coerce_float: bool = False) pandas.DataFrame

Get the previous checkpoint infos per block and returns as a pandas dataframe.

Parameters:

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

Returns:

A pandas dataframe that consists of previous checkpoints made on this pool.

Return type:

pd.Dataframe

get_positions(show_closed_positions: bool = False, calc_pnl: bool = False, coerce_float: bool = False) pandas.DataFrame

Gets all current positions of this pool and their corresponding pnl and returns as a pandas dataframe.

This function only exists in local hyperdrive as only sim pool keeps track of all positions of all wallets.

Parameters:
  • 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. Defaults to False.

  • 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) – If True, will coerce underlying Decimals to floats. Defaults to False.

Returns:

A dataframe consisting of currently open positions and their corresponding pnl.

Return type:

pd.Dataframe

get_historical_positions(coerce_float: bool = False) pandas.DataFrame

Gets the history of all positions over time and their corresponding pnl and returns as a pandas dataframe.

Parameters:

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

Returns:

A dataframe consisting of positions over time and their corresponding pnl.

Return type:

pd.Dataframe

get_trade_events(all_token_deltas: bool = False, coerce_float: bool = False) pandas.DataFrame

Gets the ticker history of all trades and the corresponding token deltas for each trade.

Parameters:
  • all_token_deltas (bool) – 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) – If True, will coerce underlying Decimals to floats.

Returns:

A dataframe of trade events.

Return type:

pd.Dataframe

get_historical_pnl(coerce_float: bool = False) pandas.DataFrame

Gets total pnl for each wallet for each block, aggregated across all open positions.

Parameters:

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

Returns:

A dataframe of aggregated wallet pnl per block

Return type:

pd.Dataframe