agent0.core.hyperdrive.interactive

Interactive hyperdrive

Submodules

Classes

Chain

A class that represents a ethereum node.

Hyperdrive

Interactive Hyperdrive class that supports connecting to an existing hyperdrive deployment.

LocalChain

Launches a local anvil chain in a subprocess, along with a postgres container.

LocalHyperdrive

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

Package Contents

class agent0.core.hyperdrive.interactive.Chain(rpc_uri: str, config: Config | None = None)

A class that represents a ethereum node.

class Config

The configuration for the chain object.

log_filename: str | None = None

Path and name of the log file. Won’t log to file if None. Defaults to None.

log_max_bytes: int | None = None

Maximum size of the log file in bytes. Defaults to hyperlogs.DEFAULT_LOG_MAXBYTES.

log_level_threshold: int | None = None

Threshold for log level in logging. Defaults to hyperlogs.DEFAULT_LOG_LEVEL.

delete_previous_logs: bool = False

Whether to delete previous log file if it exists. Defaults to False.

log_to_stdout: bool = True

Whether to log to standard output. Defaults to True.

log_format_string: str | None = None

Log formatter object. Defaults to None.

keep_previous_handlers: bool = False

Whether to keep previous handlers. Defaults to False.

exception_on_policy_error: bool = True

When executing agent policies, whether to raise an exception if an error is encountered. Defaults to True.

exception_on_policy_slippage: bool = False

When executing agent policies, whether to raise an exception if the slippage is too large. Defaults to False.

preview_before_trade: bool = False

Whether to preview the position before executing a trade. Defaults to False.

crash_log_level: int = 40

The log level to log crashes at. Defaults to error.

crash_report_stdout_summary: bool = True

Whether to print a summary of the crash report to stdout (if True), or print out the full report (if False). Defaults to True.

log_to_rollbar: bool = False

Whether to log crash reports to rollbar. Defaults to False.

rollbar_log_level_threshold: int = 10

Threshold for log level in rollbar. Defaults to debug (i.e., log all to rollbar).

rollbar_log_prefix: str | None = None

Additional prefix for this hyperdrive to log to rollbar.

rollbar_log_filter_func: Callable[[Exception], bool] | None = None

A function that filters exceptions to log to rollbar. The function should return True for exceptions that should be filtered from rollbar logging. Defaults to logging all exceptions.

crash_report_additional_info: dict[str, Any] | None = None

Additional information to include in the crash report.

always_execute_policy_post_action: bool = False

Whether to execute the policy post_action function after non-policy trades. If True, the policy post_action function always be called after any agent trade. If False, the policy post_action function will only be called after execute_policy_action. Defaults to False.

log_anvil_state_dump: bool = False

Whether to log the anvil state dump in crash reports. Defaults to False.

calc_pnl: bool = True

Whether to calculate pnl. Defaults to True.

no_postgres: bool = False

Don’t launch postgres connection at all. Expect things to break if this is set to True.

use_existing_postgres: bool = False

If True, will connect to a remote postgres instance using environmental variables (see env.sample). If False, will manage a local postgres instance. Defaults to False.

db_port: int = 5433

The port to bind for the postgres container. Will fail if this port is being used. Defaults to 5433. Not used if use_existing_postgres is True.

remove_existing_db_container: bool = True

Whether to remove the existing container if it exists on container launch. Defaults to True. Not used if use_existing_postgres is True.

backfill_pool_info: bool = True

Determines if we keep the pool info for every block in the database. Defaults to True.

rng_seed: int | None = None

The seed for the random number generator. Defaults to None.

rng: numpy.random.Generator | None = None

The experiment’s stateful random number generator. Defaults to creating a generator from the provided random seed if not set.

txn_receipt_timeout: float | None = None

The timeout for waiting for a transaction receipt in seconds. Defaults to 120.

gas_limit: int | None = None

The maximum gas to use when executing transactions. This gas limit controls any transactions that are executed on the chain. NOTE: the policies gas_limit overwrites this value if it is set.

txn_signature: bytes | None = None

The signature for transactions. Defaults to 0xa0.

rpc_uri
docker_client = None
postgres_container = None
db_session = None
config = None
cleanup()

General cleanup of resources of interactive hyperdrive.

block_number() eth_typing.BlockNumber

Get the current block number on the chain.

Returns:

The current block number

Return type:

int

block_data(block_identifier: web3.types.BlockIdentifier = 'latest') web3.types.BlockData

Get the current block on the chain.

Parameters:

block_identifier – The identifier of the block to get. Defaults to ‘latest’.

Returns:

The current block number

Return type:

int

block_time() web3.types.Timestamp

Get the current block time on the chain.

Returns:

The current block number

Return type:

int

property is_local_chain: bool

Returns if this object is a local chain.

property name: str

Returns the name of the chain, which is the base hostname of the rpc uri.

property chain_id: int

Returns the chain id of the chain.

init_agent(private_key: str | None = None, public_address: str | None = None, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, policy: Type[agent0.core.hyperdrive.policies.HyperdriveBasePolicy] | None = None, policy_config: agent0.core.hyperdrive.policies.HyperdriveBasePolicy.Config | None = None, name: str | None = None) agent0.core.hyperdrive.interactive.hyperdrive_agent.HyperdriveAgent

Initialize an agent object given a private key.

Note

Due to the underlying bookkeeping, each agent object needs a unique private key.

Parameters:
  • private_key (str, optional) – The private key of the associated account. Must be supplied to allow this agent to do any transactions.

  • public_address (str | None, optional) – The public address of the associated account. This allows this agent to be used for analyzing data. Can’t be used in conjunction with private_key.

  • pool (LocalHyperdrive, optional) – An optional pool to set as the active pool.

  • policy (HyperdrivePolicy, optional) – An optional policy to set as the active policy.

  • policy_config (HyperdrivePolicy, optional) – The configuration for the attached policy.

  • name (str, optional) – The name of the agent. Defaults to the wallet address.

Returns:

The agent object for a user to execute trades with.

Return type:

HyperdriveAgent

dump_db(save_dir: pathlib.Path) None

Export the managed database to file.

Parameters:

save_dir (Path) – The output directory to dump the data to.

load_db(load_dir: pathlib.Path) None

Import the managed database from file.

Parameters:

load_dir (Path) – The directory that contains the exported database.

class agent0.core.hyperdrive.interactive.Hyperdrive(chain: agent0.core.hyperdrive.interactive.chain.Chain, hyperdrive_address: eth_typing.ChecksumAddress, config: Config | None = None, name: str | None = None)

Interactive Hyperdrive class that supports connecting to an existing hyperdrive deployment.

class Config

The configuration for the interactive hyperdrive class.

classmethod get_hyperdrive_addresses_from_registry(chain: agent0.core.hyperdrive.interactive.chain.Chain, registry_address: str) dict[str, eth_typing.ChecksumAddress]

Gather deployed Hyperdrive pool addresses.

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

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

Returns:

A dictionary keyed by the pool’s name, valued by the pool’s address

Return type:

dict[str, ChecksumAddress]

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

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[Hyperdrive]

abstract 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 is not implemented for remote hyperdrive, as gathering this data is expensive. In the future, we can explicitly make this call gather data from the remote chain.

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

  • 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.

  • show_closed_positions (bool) – 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.

Returns:

A dataframe consisting of currently open positions 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

abstract 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.

This function is not implemented for remote hyperdrive, as gathering this data is expensive. In the future, we can explicitly make this call gather data from the remote chain.

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

abstract get_historical_pnl(coerce_float: bool = False) pandas.DataFrame

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

This function is not implemented for remote hyperdrive, as gathering this data is expensive. In the future, we can explicitly make this call gather data from the remote chain.

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

property hyperdrive_address: eth_typing.ChecksumAddress

Returns the hyperdrive addresses for this pool.

Returns:

The hyperdrive addresses for this pool

Return type:

ChecksumAddress

class agent0.core.hyperdrive.interactive.LocalChain(config: Config | None = None, fork_uri: str | None = None, fork_block_number: int | None = None)

Bases: agent0.core.hyperdrive.interactive.chain.Chain

Launches a local anvil chain in a subprocess, along with a postgres container.

class Config

Bases: agent0.core.hyperdrive.interactive.chain.Chain.Config

The configuration for the local chain object.

verbose: bool = False

If True, will print underlying subprocess output to stdout. Defaults to suppressing output.

dashboard_port: int | None = None

The URL port for the deployed dashboard. Defaults to finding an open port.

block_time: int | None = None

If None, mines per transaction. Otherwise mines every block_time seconds.

block_timestamp_interval: int | None = 12

Number of seconds to advance time for every mined block. Uses real time if None.

chain_host: str | None = None

The host to bind for the anvil chain. Defaults to 127.0.0.1.

chain_id: int | None = None

The chain ID for the local anvil chain.

chain_port: int = 10000

The port to bind for the anvil chain. Will fail if this port is being used.

chain_genesis_timestamp: int | None = None

The genesis timestamp (in epoch seconds) for the anvil chain. If None, uses the current time.

transaction_block_keeper: int = 10000

The number of blocks to keep transaction records for. Undocumented in Anvil, we’re being optimistic here.

snapshot_dir: str | None = None

The directory where the snapshot will be stored. Defaults to .interactive_state/snapshot/chain_<chain_port>.

load_rng_on_snapshot: bool = True

If True, loading a snapshot also loads the RNG state of the underlying policy. This results in the same RNG state as when the snapshot was taken. If False, will use the existing RNG state before load. Defaults to False.

manual_database_sync: bool = False

If True, depends on the user to sync the database against the chain by calling pool.sync_database(). NOTE if this is True, the caller must call pool.sync_database() before any references to getting the user’s wallet, including any policy actions that require a wallet. Otherwise, the wallet may be out of date. Use this at your own risk.

crash_log_ticker: bool = False

Whether to log the trade ticker in crash reports. Defaults to False.

config = None
dashboard_subprocess: subprocess.Popen | None = None
cleanup()

Kills the subprocess in this class’ destructor.

get_deployer_account_private_key() str

Get the private key of the deployer account.

Returns:

The private key for the deployer account.

Return type:

str

get_deployer_account() eth_account.signers.local.LocalAccount

Get the public key of the deployer account.

Returns:

The public key for the deployer account.

Return type:

src

get_deployer_address() str

Get the public key of the deployer account.

Returns:

The public key for the deployer account.

Return type:

src

property is_local_chain: bool

Returns if this object is a local chain.

mine_blocks(num_blocks: int = 1) None

Advance time for this chain using the anvil_mine RPC call.

This function mines the specified amount of blocks with the chain config specified time between blocks.

Note

This advances the chain for all pool connected to this chain.

Parameters:

num_blocks (int) – The amount of blocks to advance. Defaults to 1.

advance_time(time_delta: int | datetime.timedelta, create_checkpoints: bool = True) dict[agent0.core.hyperdrive.interactive.local_hyperdrive.LocalHyperdrive, list[hyperdrivetypes.CreateCheckpointEventFP]]

Advance time for this chain using the evm_mine RPC call.

This function looks at the timestamp of the current block, then mines a block explicitly setting the timestamp to the current block timestamp + time_delta.

If create_checkpoints is True, it will also create intermediate checkpoints when advancing time.

Note

This advances the chain for all pool connected to this chain.

Note

This function is a best effort attempt at being exact in advancing time, but the final result may be off by a second.

Parameters:
  • time_delta (int | timedelta) – The amount of time to advance. Can either be a datetime.timedelta object or an integer in seconds.

  • create_checkpoints (bool, optional) – If set to true, will create intermediate checkpoints between advance times. Defaults to True.

Returns:

Returns a dictionary keyed by the interactive hyperdrive object, with a value of a list of emitted CreateCheckpoint events called from advancing time.

Return type:

dict[InteractiveHyperdrive, list[CreateCheckpoint]]

save_state(save_dir: pathlib.Path | None = None, save_prefix: str | None = None) pathlib.Path

Saves the interactive state using the anvil_dumpState RPC call. Saving/loading state can be done across chains.

Parameters:
  • save_dir (Path, optional) – The directory to save the state to. Defaults to {Config.save_state_dir}/{save_prefix}_{current_time}/, where Config.save_state_dir defaults to ./.interactive_state/.

  • save_prefix (str, optional) – If save_dir wasn’t provided, prepends an optional prefix to the time suffix for this state.

Returns:

The path to the saved state.

Return type:

str

abstract load_state(load_dir: pathlib.Path) None

Loads the interactive state from the save_state function. Saving/loading state can be done across chains.

Note

This feature is currently unavailable. There are issues around load_state, namely:

  • Anvil load state doesn’t load the block number and timestamp.

  • Anvil load state only loads the current state, not all previous states.

  • There exists an issue with the underlying yield contract, as there is a last_updated var that gets saved, but anvil doesn’t load the original timestamp, so the yield contract throws an error. (May be able to solve if we’re able to solve issue 1 to correctly load the block number and previous states.)

  • To load the state in another chain, we need this function to load all original objects created from the saved chain, e.g., interactive_hyperdrive and all agents they contain, and return them from this function.

Parameters:

load_dir (Path) – The directory to load the state from.

save_snapshot() None

Saves a snapshot using the evm_snapshot RPC call. The chain can store one snapshot at a time, saving another snapshot overwrites the previous snapshot. Saving/loading snapshot only persist on the same chain, not across chains.

load_snapshot() None

Loads the previous snapshot using the evm_revert RPC call. Can load the snapshot multiple times.

Note

Saving/loading snapshot only persist on the same chain, not across chains.

Note

Loading a snapshot affects any agent’s active pools and policies, and will revert both to the state of the saved snapshot.

init_agent(private_key: str | None = None, public_address: str | None = None, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, policy: Type[agent0.core.hyperdrive.policies.HyperdriveBasePolicy] | None = None, policy_config: agent0.core.hyperdrive.policies.HyperdriveBasePolicy.Config | None = None, name: str | None = None, base: fixedpointmath.FixedPoint | None = None, eth: fixedpointmath.FixedPoint | None = None) agent0.core.hyperdrive.interactive.local_hyperdrive_agent.LocalHyperdriveAgent

Initializes an agent with initial funding and a logical name.

Parameters:
  • private_key (str, optional) – The private key of the associated account. Default is auto-generated.

  • public_address (str | None, optional) – Must be None for local agents.

  • pool (LocalHyperdrive, optional) – An optional pool to set as the active pool.

  • policy (HyperdrivePolicy, optional) – An optional policy to set as the active policy.

  • policy_config (HyperdrivePolicy, optional) – The configuration for the attached policy.

  • name (str, optional) – The name of the agent. Defaults to the wallet address.

  • base (FixedPoint | None, optional) – The amount of base to fund the agent with. Defaults to 0. If a private key is provided then the base amount is added to their previous balance.

  • eth (FixedPoint | None, optional) – The amount of ETH to fund the agent with. Defaults to 0. If a private key is provided then the eth amount is added to their previous balance.

Returns:

The agent object for a user to execute trades with.

Return type:

LocalHyperdriveAgent

get_dashboard_iframe(width: int = 1000, height: int = 800) IPython.display.IFrame

Embeds the streamlit dashboard into a Jupyter notebook as an IFrame.

Note

The interactive hyperdrive script must be in a paused state (before cleanup) for the dashboard to connect with the underlying database, otherwise cleanup and/or the main thread executed will kill the streamlit server. Passing blocking=True will block execution of the main script in this function until a keypress is registered.

Parameters:
  • width (int) – Width, in pixels, of the IFrame. Defaults to 1000.

  • height (int) – Height, in pixels, of the IFrame. Defaults to 800.

Returns:

A dashboard IFrame that can be shown in a Jupyter notebook with the display command.

Return type:

IFrame

run_dashboard(blocking: bool = False) None

Runs the streamlit dashboard in a subprocess connected to interactive hyperdrive.

Note

The interactive hyperdrive script must be in a paused state (before cleanup) for the dashboard to connect with the underlying database, otherwise cleanup and/or the main thread executed will kill the streamlit server. Passing blocking=True will block execution of the main script in this function until a keypress is registered.

Parameters:

blocking (bool) – If True, will block execution of the main script in this function until a keypress is registered. When in blocking mode, the server will be killed upon return of control to caller. If False, will clean up subprocess in cleanup.

class agent0.core.hyperdrive.interactive.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