agent0.chainsync.db.hyperdrive

Hyperdrive database utilities.

Submodules

Classes

DBCheckpointInfo

Table/dataclass schema for checkpoint information.

DBHyperdriveAddrToName

Maps a hyperdrive address to a logical name.

DBPoolConfig

Table/dataclass schema for pool config.

DBPoolInfo

Table/dataclass schema for pool info.

DBPositionSnapshot

Table/dataclass schema for snapshots of positions

Functions

checkpoint_events_to_db(→ None)

Function to query checkpoint events from all pools and add them to the db.

init_data_chain_to_db(→ None)

Function to query and insert pool config to dashboard.

pool_info_to_db(→ None)

Function to query and insert data to dashboard.

trade_events_to_db(→ None)

Function to query trade events from all pools and add them to the db.

convert_pool_config(...)

Converts a pool_config_dict from a call in hyperdrive_interface to the postgres data type

convert_pool_info(...)

Converts a pool_info_dict from a call in hyperdrive interface to the postgres data type

export_db_to_file(→ None)

Export all tables from the database and write as parquet files, one per table.

import_to_db(→ None)

Helper function to load data from parquet into the db

import_to_pandas(→ dict[str, pandas.DataFrame])

Helper function to load data from parquet

add_checkpoint_info(→ None)

Add checkpoint info to the checkpointinfo table if it doesn't exist.

add_hyperdrive_addr_to_name(→ None)

Add username mapping to postgres during agent initialization.

add_pool_config(→ None)

Add pool config to the pool config table if not exist.

add_pool_infos(→ None)

Add a pool info to the poolinfo table.

add_trade_events(→ None)

Add transfer events to the transfer events table.

get_all_traders(→ pandas.Series)

Get the list of all traders from the TradeEvent table.

get_checkpoint_info(→ pandas.DataFrame)

Get all info associated with a given checkpoint.

get_current_positions(→ pandas.DataFrame)

Gets all positions for a given wallet address.

get_hyperdrive_addr_to_name(→ pandas.DataFrame)

Get all usermapping and returns as a pandas dataframe.

get_latest_block_number_from_checkpoint_info_table(→ int)

Get the latest block number based on the checkpoint info table in the db.

get_latest_block_number_from_pool_info_table(→ int)

Get the latest block number based on the pool info table in the db.

get_latest_block_number_from_positions_snapshot_table(→ int)

Get the latest block number based on the positions snapshot table in the db.

get_latest_block_number_from_table(→ int)

Get the latest block number based on the specified table in the db.

get_latest_block_number_from_trade_event(→ int)

Get the latest block number based on the hyperdrive events table in the db.

get_pool_config(→ pandas.DataFrame)

Get all pool config and returns a pandas dataframe.

get_pool_info(→ pandas.DataFrame)

Get all pool info and returns a pandas dataframe.

get_position_snapshot(→ pandas.DataFrame)

Get all position snapshot data and returns a pandas dataframe.

get_positions_over_time(→ pandas.DataFrame)

Aggregate over token types over all position types.

get_realized_value_over_time(→ pandas.DataFrame)

Aggregate over realized value over all position types.

get_total_pnl_over_time(→ pandas.DataFrame)

Aggregate pnl over time over all positions a wallet has.

get_trade_events(→ pandas.DataFrame)

Get all trade events and returns a pandas dataframe.

Package Contents

agent0.chainsync.db.hyperdrive.checkpoint_events_to_db(interfaces: list[agent0.ethpy.hyperdrive.HyperdriveReadInterface], db_session: sqlalchemy.orm.Session) None

Function to query checkpoint events from all pools and add them to the db.

Parameters:
  • interfaces (list[HyperdriveReadInterface]) – A collection of Hyperdrive interface objects, each connected to a pool.

  • db_session (Session) – The database session.

agent0.chainsync.db.hyperdrive.init_data_chain_to_db(interfaces: list[agent0.ethpy.hyperdrive.HyperdriveReadInterface], session: sqlalchemy.orm.Session) None

Function to query and insert pool config to dashboard.

Parameters:
  • interfaces (list[HyperdriveReadInterface]) – A collection of Hyperdrive interface objects, each connected to a pool.

  • session (Session) – The database session

agent0.chainsync.db.hyperdrive.pool_info_to_db(interfaces: list[agent0.ethpy.hyperdrive.HyperdriveReadInterface], block_number: int, session: sqlalchemy.orm.Session) None

Function to query and insert data to dashboard.

Parameters:
  • interfaces (list[HyperdriveReadInterface]) – A collection of Hyperdrive interface objects, each connected to a pool.

  • block_number (int) – The block number to query the chain on.

  • session (Session) – The database session.

agent0.chainsync.db.hyperdrive.trade_events_to_db(interfaces: list[agent0.ethpy.hyperdrive.HyperdriveReadInterface], wallet_addr: str | None, db_session: sqlalchemy.orm.Session) None

Function to query trade events from all pools and add them to the db.

Parameters:
  • interfaces (list[HyperdriveReadInterface]) – A collection of Hyperdrive interface objects, each connected to a pool.

  • wallet_addr (str | None) – The wallet address to query. If None, will not filter events by wallet addr.

  • db_session (Session) – The database session.

agent0.chainsync.db.hyperdrive.convert_pool_config(pool_config_dict: dict[str, Any]) agent0.chainsync.db.hyperdrive.schema.DBPoolConfig

Converts a pool_config_dict from a call in hyperdrive_interface to the postgres data type

Parameters:

pool_config_dict (dict[str, Any]) – A dicitonary containing the required pool_config keys.

Returns:

The db object for pool config

Return type:

PoolConfig

agent0.chainsync.db.hyperdrive.convert_pool_info(pool_info_dict: dict[str, Any]) agent0.chainsync.db.hyperdrive.schema.DBPoolInfo

Converts a pool_info_dict from a call in hyperdrive interface to the postgres data type

Parameters:

pool_info_dict (dict[str, Any]) – The dictionary returned from hyperdrive_instance.get_hyperdrive_pool_info

Returns:

The db object for pool info

Return type:

PoolInfo

agent0.chainsync.db.hyperdrive.export_db_to_file(out_dir: pathlib.Path, db_session: sqlalchemy.orm.Session | None = None) None

Export all tables from the database and write as parquet files, one per table. We use parquet since it’s type aware, so all original types (including Decimals) are preserved when read

Parameters:
  • out_dir (Path) – The directory to write the parquet files to. It’s assumed this directory already exists.

  • db_session (Session | None, optional) – The initialized session object. If none, will read credentials from .env

agent0.chainsync.db.hyperdrive.import_to_db(db_session: sqlalchemy.orm.Session, in_dir: pathlib.Path, drop=True) None

Helper function to load data from parquet into the db

Parameters:
  • db_session (Session) – The sqlalchemy session object

  • in_dir (Path) – The directory to read the parquet files from that matches the out_dir passed into export_db_to_file

  • drop (bool, optional) – Whether to drop the existing data in the db before importing

agent0.chainsync.db.hyperdrive.import_to_pandas(in_dir: pathlib.Path) dict[str, pandas.DataFrame]

Helper function to load data from parquet

Parameters:

in_dir (Path) – The directory to read the parquet files from that matches the out_dir passed into export_db_to_file

Returns:

A dictionary of pandas dataframes keyed by the original table name in the db

Return type:

dict[str, pd.DataFrame]

agent0.chainsync.db.hyperdrive.add_checkpoint_info(checkpoint_info: agent0.chainsync.db.hyperdrive.schema.DBCheckpointInfo, session: sqlalchemy.orm.Session) None

Add checkpoint info to the checkpointinfo table if it doesn’t exist.

This function is only used for injecting rows into the db. The actual ingestion happens via checkpoint_events_to_db using dataframes.

Parameters:
  • checkpoint_info (CheckpointInfo) – A CheckpointInfo object to insert into postgres.

  • session (Session) – The initialized session object.

agent0.chainsync.db.hyperdrive.add_hyperdrive_addr_to_name(name: str, hyperdrive_address: str, session: sqlalchemy.orm.Session, force_update: bool = False) None

Add username mapping to postgres during agent initialization.

Parameters:
  • name (str) – The logical name to attach to the wallet address.

  • hyperdrive_address (str) – A hyperdrive address to map to the name.

  • session (Session) – The initialized session object.

  • force_update (bool) – If true and an existing mapping is found, will overwrite.

agent0.chainsync.db.hyperdrive.add_pool_config(pool_config: agent0.chainsync.db.hyperdrive.schema.DBPoolConfig, session: sqlalchemy.orm.Session) None

Add pool config to the pool config table if not exist.

Verify pool config if it does exist.

Parameters:
  • pool_config (PoolConfig) – A PoolConfig object to insert into postgres.

  • session (Session) – The initialized session object.

agent0.chainsync.db.hyperdrive.add_pool_infos(pool_infos: list[agent0.chainsync.db.hyperdrive.schema.DBPoolInfo], session: sqlalchemy.orm.Session) None

Add a pool info to the poolinfo table.

Parameters:
  • pool_infos (list[PoolInfo]) – A list of PoolInfo objects to insert into postgres.

  • session (Session) – The initialized session object.

agent0.chainsync.db.hyperdrive.add_trade_events(transfer_events: list[agent0.chainsync.db.hyperdrive.schema.DBTradeEvent], session: sqlalchemy.orm.Session) None

Add transfer events to the transfer events table.

This function is only used for injecting rows into the db. The actual ingestion happens via trade_events_to_db using dataframes.

Parameters:
  • transfer_events (list[HyperdriveTransferEvent]) – A list of HyperdriveTransferEvent objects to insert into postgres.

  • session (Session) – The initialized session object.

agent0.chainsync.db.hyperdrive.get_all_traders(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None) pandas.Series

Get the list of all traders from the TradeEvent table.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None, optional) – The hyperdrive pool address to filter the query on. Defaults to returning all traders.

Returns:

A list of addresses that have made a trade.

Return type:

pd.Series

agent0.chainsync.db.hyperdrive.get_checkpoint_info(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None, checkpoint_time: int | None = None, coerce_float=False) pandas.DataFrame

Get all info associated with a given checkpoint.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None, optional) – The hyperdrive pool address to filter the query on. Defaults to returning all checkpoint infos.

  • checkpoint_time (int | None, optional) – The checkpoint time to filter the query on. Defaults to returning all checkpoint infos.

  • coerce_float (bool, optional) – If True, will return floats in dataframe. Otherwise, will return fixed point Decimal. Defaults to False

Returns:

A DataFrame that consists of the queried checkpoint info.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_current_positions(session: sqlalchemy.orm.Session, wallet_addr: str | None = None, hyperdrive_address: str | None = None, query_block: int | None = None, show_closed_positions: bool = False, coerce_float=False) pandas.DataFrame

Gets all positions for a given wallet address.

Parameters:
  • session (Session) – The initialized db session object.

  • wallet_addr (str) – The wallet address to filter the results on.

  • hyperdrive_address (str | None, optional) – The hyperdrive address to filter the results on. Returns all if None.

  • query_block (int | None, optional) – The block to get positions for. query_block integers matches python slicing notation, e.g., list[:3], list[:-3].

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

  • coerce_float (bool) – If True, will coerce all numeric columns to float.

Returns:

A DataFrame that consists of the queried pool info data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_hyperdrive_addr_to_name(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None) pandas.DataFrame

Get all usermapping and returns as a pandas dataframe.

Parameters:
  • session (Session) – The initialized session object

  • hyperdrive_address (str | None, optional) – The hyperdrive address to filter the results on. Return all if None

Returns:

A DataFrame that consists of the queried pool config data

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_latest_block_number_from_checkpoint_info_table(session: sqlalchemy.orm.Session, hyperdrive_address: str | None) int

Get the latest block number based on the checkpoint info table in the db.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None) – The hyperdrive pool address to filter the query on.

Returns:

The latest block number in the poolinfo table.

Return type:

int

agent0.chainsync.db.hyperdrive.get_latest_block_number_from_pool_info_table(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None) int

Get the latest block number based on the pool info table in the db.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None) – The hyperdrive address to filter the results on. Can be None to return latest block number regardless of pool.

Returns:

The latest block number in the poolinfo table.

Return type:

int

agent0.chainsync.db.hyperdrive.get_latest_block_number_from_positions_snapshot_table(session: sqlalchemy.orm.Session, wallet_addr: str | None, hyperdrive_address: str | None) int

Get the latest block number based on the positions snapshot table in the db.

Parameters:
  • session (Session) – The initialized session object.

  • wallet_addr (str | None) – The wallet address to filter the results on. Can be None to return latest block number regardless of wallet.

  • hyperdrive_address (str | None) – The hyperdrive address to filter the results on. Can be None to return latest block number regardless of pool.

Returns:

The latest block number in the hyperdrive_events table.

Return type:

int

agent0.chainsync.db.hyperdrive.get_latest_block_number_from_table(table_obj: Type[agent0.chainsync.db.base.schema.DBBase], session: sqlalchemy.orm.Session) int

Get the latest block number based on the specified table in the db.

Parameters:
  • table_obj (Type[Base]) – The sqlalchemy class that contains the block_number column

  • session (Session) – The initialized session object

Returns:

The latest block number from the specified table

Return type:

int

agent0.chainsync.db.hyperdrive.get_latest_block_number_from_trade_event(session: sqlalchemy.orm.Session, hyperdrive_address: str | None, wallet_address: str | None) int

Get the latest block number based on the hyperdrive events table in the db.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None) – The hyperdrive address to filter the results on. Can be None to return latest block number regardless of pool.

  • wallet_address (str | None) – The wallet address to filter the results on. Can be None to return latest block number regardless of wallet.

Returns:

The latest block number in the hyperdrive_events table.

Return type:

int

agent0.chainsync.db.hyperdrive.get_pool_config(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None, coerce_float=False) pandas.DataFrame

Get all pool config and returns a pandas dataframe.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None, optional) – The contract_address to filter the results on. Return all if None. Defaults to returning all.

  • coerce_float (bool, optional) – If True, will coerce all numeric columns to float. Defaults to False.

Returns:

A DataFrame that consists of the queried pool config data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_pool_info(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None, start_block: int | None = None, end_block: int | None = None, coerce_float=False) pandas.DataFrame

Get all pool info and returns a pandas dataframe.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | None, optional) – The hyperdrive address to filter the query on. Return all if None.

  • start_block (int | None, optional) – The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • end_block (int | None, optional) – The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • coerce_float (bool, optional) – If true, will return floats in dataframe. Otherwise, will return fixed point Decimal.

Returns:

A DataFrame that consists of the queried pool info data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_position_snapshot(session: sqlalchemy.orm.Session, hyperdrive_address: str | list[str] | None = None, latest_entry: bool = False, start_block: int | None = None, end_block: int | None = None, wallet_address: list[str] | str | None = None, coerce_float=False) pandas.DataFrame

Get all position snapshot data and returns a pandas dataframe.

Parameters:
  • session (Session) – The initialized session object.

  • hyperdrive_address (str | list[str] | None, optional) – The hyperdrive pool address(es) to filter the query on. Defaults to returning all position snapshots.

  • latest_entry (bool, optional) – If true, will return the latest entry for every pool. Defaults to False.

  • start_block (int | None, optional) – The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3]. Defaults to first entry. Not used if latest_entry is True.

  • end_block (int | None, optional) – The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3]. Defaults to last entry. Not used if latest_entry is True.

  • wallet_address (list[str] | None, optional) – The wallet addresses to filter the query on. Returns all if None.

  • coerce_float (bool, optional) – If True, will return floats in dataframe. Otherwise, will return fixed point Decimal. Defaults to False.

Returns:

A DataFrame that consists of the queried pool info data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_positions_over_time(session: sqlalchemy.orm.Session, start_block: int | None = None, end_block: int | None = None, wallet_address: list[str] | None = None, coerce_float=False) pandas.DataFrame

Aggregate over token types over all position types.

Parameters:
  • session (Session) – The initialized session object.

  • start_block (int | None, optional) – The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • end_block (int | None, optional) – The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • wallet_address (list[str] | None, optional) – The wallet addresses to filter the query on. Returns all if None.

  • coerce_float (bool) – If true, will return floats in dataframe. Otherwise, will return fixed point Decimal.

Returns:

A DataFrame that consists of the queried pool info data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_realized_value_over_time(session: sqlalchemy.orm.Session, start_block: int | None = None, end_block: int | None = None, wallet_address: list[str] | None = None, coerce_float=False) pandas.DataFrame

Aggregate over realized value over all position types.

Parameters:
  • session (Session) – The initialized session object.

  • start_block (int | None, optional) – The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • end_block (int | None, optional) – The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • wallet_address (list[str] | None, optional) – The wallet addresses to filter the query on. Returns all if None.

  • coerce_float (bool) – If true, will return floats in dataframe. Otherwise, will return fixed point Decimal.

Returns:

A DataFrame that consists of the queried pool info data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_total_pnl_over_time(session: sqlalchemy.orm.Session, start_block: int | None = None, end_block: int | None = None, wallet_address: list[str] | None = None, coerce_float=False) pandas.DataFrame

Aggregate pnl over time over all positions a wallet has.

Parameters:
  • session (Session) – The initialized session object.

  • start_block (int | None, optional) – The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • end_block (int | None, optional) – The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3].

  • wallet_address (list[str] | None, optional) – The wallet addresses to filter the query on. Returns all if None.

  • coerce_float (bool) – If true, will return floats in dataframe. Otherwise, will return fixed point Decimal.

Returns:

A DataFrame that consists of the queried pool info data.

Return type:

DataFrame

agent0.chainsync.db.hyperdrive.get_trade_events(session: sqlalchemy.orm.Session, wallet_address: str | list[str] | None = None, hyperdrive_address: str | list[str] | None = None, all_token_deltas: bool = True, sort_ascending: bool = True, query_limit: int | None = None, coerce_float=False) pandas.DataFrame

Get all trade events and returns a pandas dataframe.

Parameters:
  • session (Session) – The initialized db session object.

  • wallet_address (str | list[str] | None, optional) – The wallet address(es) to filter the results on. Return all if None.

  • hyperdrive_address (str | list[str] | None, optional) – The hyperdrive address(es) to filter the results on. Returns all if None.

  • all_token_deltas (bool, optional) – 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). Defaults to True.

  • sort_ascending (bool, optional) – If True, will sort events in ascending block order. Otherwise, will sort in descending order. Defaults to True.

  • query_limit (int | None, optional) – The number of rows to return. Defaults to return all rows.

  • coerce_float (bool, optional) – If True, will return floats in dataframe. Otherwise, will return fixed point Decimal. Defaults to False.

Returns:

A DataFrame that consists of the queried trade events data.

Return type:

DataFrame

class agent0.chainsync.db.hyperdrive.DBCheckpointInfo

Bases: agent0.chainsync.db.base.DBBase

Table/dataclass schema for checkpoint information.

id: sqlalchemy.orm.Mapped[int]

The unique identifier for the entry to the table.

hyperdrive_address: sqlalchemy.orm.Mapped[str]

The hyperdrive address for the entry.

block_number: sqlalchemy.orm.Mapped[int]

The block number on which the event was emitted.

checkpoint_time: sqlalchemy.orm.Mapped[int]

The seconds epoch time index for this checkpoint.

checkpoint_vault_share_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The share price that was checkpointed in this checkpoint.

vault_share_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The vault share price at the time of checkpoint creation.

matured_shorts: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The amount of shorts that matured within this checkpoint.

matured_longs: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The amount of longs that matured within this checkpoint.

lp_share_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The lp share price at the checkpoint.

class agent0.chainsync.db.hyperdrive.DBHyperdriveAddrToName

Bases: agent0.chainsync.db.base.DBBase

Maps a hyperdrive address to a logical name.

hyperdrive_address: sqlalchemy.orm.Mapped[str]

The hyperdrive address

name: sqlalchemy.orm.Mapped[str]

The logical name of the hyperdrive address.

class agent0.chainsync.db.hyperdrive.DBPoolConfig

Bases: agent0.chainsync.db.base.DBBase

Table/dataclass schema for pool config.

hyperdrive_address: sqlalchemy.orm.Mapped[str]
base_token: sqlalchemy.orm.Mapped[str | None]
vault_shares_token: sqlalchemy.orm.Mapped[str | None]
linker_factory: sqlalchemy.orm.Mapped[str | None]
initial_vault_share_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]
minimum_share_reserves: sqlalchemy.orm.Mapped[decimal.Decimal | None]
minimum_transaction_amount: sqlalchemy.orm.Mapped[decimal.Decimal | None]
circuit_breaker_delta: sqlalchemy.orm.Mapped[decimal.Decimal | None]
position_duration: sqlalchemy.orm.Mapped[int | None]
checkpoint_duration: sqlalchemy.orm.Mapped[int | None]
time_stretch: sqlalchemy.orm.Mapped[decimal.Decimal | None]
governance: sqlalchemy.orm.Mapped[str | None]
fee_collector: sqlalchemy.orm.Mapped[str | None]
sweep_collector: sqlalchemy.orm.Mapped[str | None]
curve_fee: sqlalchemy.orm.Mapped[decimal.Decimal | None]
flat_fee: sqlalchemy.orm.Mapped[decimal.Decimal | None]
governance_lp_fee: sqlalchemy.orm.Mapped[decimal.Decimal | None]
governance_zombie_fee: sqlalchemy.orm.Mapped[decimal.Decimal | None]
inv_time_stretch: sqlalchemy.orm.Mapped[decimal.Decimal | None]
class agent0.chainsync.db.hyperdrive.DBPoolInfo

Bases: agent0.chainsync.db.base.DBBase

Table/dataclass schema for pool info.

Mapped class that is a data class on the python side, and an declarative base on the sql side.

id: sqlalchemy.orm.Mapped[int]
hyperdrive_address: sqlalchemy.orm.Mapped[str]
block_number: sqlalchemy.orm.Mapped[int]
timestamp: sqlalchemy.orm.Mapped[datetime.datetime]
epoch_timestamp: sqlalchemy.orm.Mapped[int | None]
share_reserves: sqlalchemy.orm.Mapped[decimal.Decimal | None]
share_adjustment: sqlalchemy.orm.Mapped[decimal.Decimal | None]
zombie_base_proceeds: sqlalchemy.orm.Mapped[decimal.Decimal | None]
zombie_share_reserves: sqlalchemy.orm.Mapped[decimal.Decimal | None]
bond_reserves: sqlalchemy.orm.Mapped[decimal.Decimal | None]
lp_total_supply: sqlalchemy.orm.Mapped[decimal.Decimal | None]
vault_share_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]
longs_outstanding: sqlalchemy.orm.Mapped[decimal.Decimal | None]
long_average_maturity_time: sqlalchemy.orm.Mapped[decimal.Decimal | None]
shorts_outstanding: sqlalchemy.orm.Mapped[decimal.Decimal | None]
short_average_maturity_time: sqlalchemy.orm.Mapped[decimal.Decimal | None]
withdrawal_shares_ready_to_withdraw: sqlalchemy.orm.Mapped[decimal.Decimal | None]
withdrawal_shares_proceeds: sqlalchemy.orm.Mapped[decimal.Decimal | None]
lp_share_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]
long_exposure: sqlalchemy.orm.Mapped[decimal.Decimal | None]
total_supply_withdrawal_shares: sqlalchemy.orm.Mapped[decimal.Decimal | None]
gov_fees_accrued: sqlalchemy.orm.Mapped[decimal.Decimal | None]
hyperdrive_base_balance: sqlalchemy.orm.Mapped[decimal.Decimal | None]
hyperdrive_eth_balance: sqlalchemy.orm.Mapped[decimal.Decimal | None]
variable_rate: sqlalchemy.orm.Mapped[decimal.Decimal | None]
vault_shares: sqlalchemy.orm.Mapped[decimal.Decimal | None]
spot_price: sqlalchemy.orm.Mapped[decimal.Decimal | None]
fixed_rate: sqlalchemy.orm.Mapped[decimal.Decimal | None]
class agent0.chainsync.db.hyperdrive.DBPositionSnapshot

Bases: agent0.chainsync.db.base.DBBase

Table/dataclass schema for snapshots of positions This table takes snapshots of open positions and calculates the value and pnl of positions every snapshot.

Mapped class that is a data class on the python side, and an declarative base on the sql side.

id: sqlalchemy.orm.Mapped[int]

The unique identifier for the entry to the table.

hyperdrive_address: sqlalchemy.orm.Mapped[str]

The hyperdrive address for the entry.

block_number: sqlalchemy.orm.Mapped[int]

The block number for the entry.

wallet_address: sqlalchemy.orm.Mapped[str | None]

The wallet address for the entry.

token_type: sqlalchemy.orm.Mapped[str | None]

The underlying token type for the entry. Can be one of the following: LONG, SHORT, `LP, or WITHDRAWAL_SHARE.

maturity_time: sqlalchemy.orm.Mapped[int | None]

The maturity time of the token for LONG and SHORT tokens.

token_id: sqlalchemy.orm.Mapped[str | None]

The id for the token itself, which consists of the token_type, appended with maturity_time for LONG and SHORT. For example, LONG-1715126400.

token_balance: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The absolute balance of the position.

unrealized_value: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The unrealized value of the tokens in units of base, calculated if the position is closed at this block.

realized_value: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The total change in base for opening/closing this position. NOTE: this doesn’t take into account any transfers of tokens outside of hyperdrive trades.

pnl: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The pnl of the position in units of base. unrealized_value + realized_value = pnl.

last_balance_update_block: sqlalchemy.orm.Mapped[int | None]

The last block number that this position’s balance was updated.