agent0.chainsync.db.hyperdrive ============================== .. py:module:: agent0.chainsync.db.hyperdrive .. autoapi-nested-parse:: Hyperdrive database utilities. .. !! processed by numpydoc !! Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/agent0/chainsync/db/hyperdrive/chain_to_db/index /autoapi/agent0/chainsync/db/hyperdrive/convert_data/index /autoapi/agent0/chainsync/db/hyperdrive/event_getters/index /autoapi/agent0/chainsync/db/hyperdrive/import_export_data/index /autoapi/agent0/chainsync/db/hyperdrive/import_export_data_test/index /autoapi/agent0/chainsync/db/hyperdrive/interface/index /autoapi/agent0/chainsync/db/hyperdrive/interface_test/index /autoapi/agent0/chainsync/db/hyperdrive/schema/index /autoapi/agent0/chainsync/db/hyperdrive/schema_test/index Classes ------- .. autoapisummary:: agent0.chainsync.db.hyperdrive.DBCheckpointInfo agent0.chainsync.db.hyperdrive.DBHyperdriveAddrToName agent0.chainsync.db.hyperdrive.DBPoolConfig agent0.chainsync.db.hyperdrive.DBPoolInfo agent0.chainsync.db.hyperdrive.DBPositionSnapshot Functions --------- .. autoapisummary:: agent0.chainsync.db.hyperdrive.checkpoint_events_to_db agent0.chainsync.db.hyperdrive.init_data_chain_to_db agent0.chainsync.db.hyperdrive.pool_info_to_db agent0.chainsync.db.hyperdrive.trade_events_to_db agent0.chainsync.db.hyperdrive.convert_pool_config agent0.chainsync.db.hyperdrive.convert_pool_info agent0.chainsync.db.hyperdrive.export_db_to_file agent0.chainsync.db.hyperdrive.import_to_db agent0.chainsync.db.hyperdrive.import_to_pandas agent0.chainsync.db.hyperdrive.add_checkpoint_info agent0.chainsync.db.hyperdrive.add_hyperdrive_addr_to_name agent0.chainsync.db.hyperdrive.add_pool_config agent0.chainsync.db.hyperdrive.add_pool_infos agent0.chainsync.db.hyperdrive.add_trade_events agent0.chainsync.db.hyperdrive.get_all_traders agent0.chainsync.db.hyperdrive.get_checkpoint_info agent0.chainsync.db.hyperdrive.get_current_positions agent0.chainsync.db.hyperdrive.get_hyperdrive_addr_to_name agent0.chainsync.db.hyperdrive.get_latest_block_number_from_checkpoint_info_table agent0.chainsync.db.hyperdrive.get_latest_block_number_from_pool_info_table agent0.chainsync.db.hyperdrive.get_latest_block_number_from_positions_snapshot_table agent0.chainsync.db.hyperdrive.get_latest_block_number_from_table agent0.chainsync.db.hyperdrive.get_latest_block_number_from_trade_event agent0.chainsync.db.hyperdrive.get_pool_config agent0.chainsync.db.hyperdrive.get_pool_info agent0.chainsync.db.hyperdrive.get_position_snapshot agent0.chainsync.db.hyperdrive.get_positions_over_time agent0.chainsync.db.hyperdrive.get_realized_value_over_time agent0.chainsync.db.hyperdrive.get_total_pnl_over_time agent0.chainsync.db.hyperdrive.get_trade_events Package Contents ---------------- .. py:function:: 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. :param interfaces: A collection of Hyperdrive interface objects, each connected to a pool. :type interfaces: list[HyperdriveReadInterface] :param db_session: The database session. :type db_session: Session .. !! processed by numpydoc !! .. py:function:: 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. :param interfaces: A collection of Hyperdrive interface objects, each connected to a pool. :type interfaces: list[HyperdriveReadInterface] :param session: The database session :type session: Session .. !! processed by numpydoc !! .. py:function:: 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. :param interfaces: A collection of Hyperdrive interface objects, each connected to a pool. :type interfaces: list[HyperdriveReadInterface] :param block_number: The block number to query the chain on. :type block_number: int :param session: The database session. :type session: Session .. !! processed by numpydoc !! .. py:function:: 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. :param interfaces: A collection of Hyperdrive interface objects, each connected to a pool. :type interfaces: list[HyperdriveReadInterface] :param wallet_addr: The wallet address to query. If None, will not filter events by wallet addr. :type wallet_addr: str | None :param db_session: The database session. :type db_session: Session .. !! processed by numpydoc !! .. py:function:: 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 :param pool_config_dict: A dicitonary containing the required pool_config keys. :type pool_config_dict: dict[str, Any] :returns: The db object for pool config :rtype: PoolConfig .. !! processed by numpydoc !! .. py:function:: 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 :param pool_info_dict: The dictionary returned from hyperdrive_instance.get_hyperdrive_pool_info :type pool_info_dict: dict[str, Any] :returns: The db object for pool info :rtype: PoolInfo .. !! processed by numpydoc !! .. py:function:: 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 :param out_dir: The directory to write the parquet files to. It's assumed this directory already exists. :type out_dir: Path :param db_session: The initialized session object. If none, will read credentials from `.env` :type db_session: Session | None, optional .. !! processed by numpydoc !! .. py:function:: 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 :param db_session: The sqlalchemy session object :type db_session: Session :param in_dir: The directory to read the parquet files from that matches the out_dir passed into export_db_to_file :type in_dir: Path :param drop: Whether to drop the existing data in the db before importing :type drop: bool, optional .. !! processed by numpydoc !! .. py:function:: import_to_pandas(in_dir: pathlib.Path) -> dict[str, pandas.DataFrame] Helper function to load data from parquet :param in_dir: The directory to read the parquet files from that matches the out_dir passed into export_db_to_file :type in_dir: Path :returns: A dictionary of pandas dataframes keyed by the original table name in the db :rtype: dict[str, pd.DataFrame] .. !! processed by numpydoc !! .. py:function:: 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. :param checkpoint_info: A CheckpointInfo object to insert into postgres. :type checkpoint_info: CheckpointInfo :param session: The initialized session object. :type session: Session .. !! processed by numpydoc !! .. py:function:: 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. :param name: The logical name to attach to the wallet address. :type name: str :param hyperdrive_address: A hyperdrive address to map to the name. :type hyperdrive_address: str :param session: The initialized session object. :type session: Session :param force_update: If true and an existing mapping is found, will overwrite. :type force_update: bool .. !! processed by numpydoc !! .. py:function:: 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. :param pool_config: A PoolConfig object to insert into postgres. :type pool_config: PoolConfig :param session: The initialized session object. :type session: Session .. !! processed by numpydoc !! .. py:function:: 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. :param pool_infos: A list of PoolInfo objects to insert into postgres. :type pool_infos: list[PoolInfo] :param session: The initialized session object. :type session: Session .. !! processed by numpydoc !! .. py:function:: 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. :param transfer_events: A list of HyperdriveTransferEvent objects to insert into postgres. :type transfer_events: list[HyperdriveTransferEvent] :param session: The initialized session object. :type session: Session .. !! processed by numpydoc !! .. py:function:: get_all_traders(session: sqlalchemy.orm.Session, hyperdrive_address: str | None = None) -> pandas.Series Get the list of all traders from the TradeEvent table. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive pool address to filter the query on. Defaults to returning all traders. :type hyperdrive_address: str | None, optional :returns: A list of addresses that have made a trade. :rtype: pd.Series .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive pool address to filter the query on. Defaults to returning all checkpoint infos. :type hyperdrive_address: str | None, optional :param checkpoint_time: The checkpoint time to filter the query on. Defaults to returning all checkpoint infos. :type checkpoint_time: int | None, optional :param coerce_float: If True, will return floats in dataframe. Otherwise, will return fixed point Decimal. Defaults to False :type coerce_float: bool, optional :returns: A DataFrame that consists of the queried checkpoint info. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized db session object. :type session: Session :param wallet_addr: The wallet address to filter the results on. :type wallet_addr: str :param hyperdrive_address: The hyperdrive address to filter the results on. Returns all if None. :type hyperdrive_address: str | None, optional :param query_block: The block to get positions for. query_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type query_block: int | None, optional :param show_closed_positions: 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. :type show_closed_positions: bool, optional :param coerce_float: If True, will coerce all numeric columns to float. :type coerce_float: bool :returns: A DataFrame that consists of the queried pool info data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object :type session: Session :param hyperdrive_address: The hyperdrive address to filter the results on. Return all if None :type hyperdrive_address: str | None, optional :returns: A DataFrame that consists of the queried pool config data :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive pool address to filter the query on. :type hyperdrive_address: str | None :returns: The latest block number in the poolinfo table. :rtype: int .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive address to filter the results on. Can be None to return latest block number regardless of pool. :type hyperdrive_address: str | None :returns: The latest block number in the poolinfo table. :rtype: int .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param wallet_addr: The wallet address to filter the results on. Can be None to return latest block number regardless of wallet. :type wallet_addr: str | None :param hyperdrive_address: The hyperdrive address to filter the results on. Can be None to return latest block number regardless of pool. :type hyperdrive_address: str | None :returns: The latest block number in the hyperdrive_events table. :rtype: int .. !! processed by numpydoc !! .. py:function:: 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. :param table_obj: The sqlalchemy class that contains the block_number column :type table_obj: Type[Base] :param session: The initialized session object :type session: Session :returns: The latest block number from the specified table :rtype: int .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive address to filter the results on. Can be None to return latest block number regardless of pool. :type hyperdrive_address: str | None :param wallet_address: The wallet address to filter the results on. Can be None to return latest block number regardless of wallet. :type wallet_address: str | None :returns: The latest block number in the hyperdrive_events table. :rtype: int .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The contract_address to filter the results on. Return all if None. Defaults to returning all. :type hyperdrive_address: str | None, optional :param coerce_float: If True, will coerce all numeric columns to float. Defaults to False. :type coerce_float: bool, optional :returns: A DataFrame that consists of the queried pool config data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive address to filter the query on. Return all if None. :type hyperdrive_address: str | None, optional :param start_block: The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type start_block: int | None, optional :param end_block: The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type end_block: int | None, optional :param coerce_float: If true, will return floats in dataframe. Otherwise, will return fixed point Decimal. :type coerce_float: bool, optional :returns: A DataFrame that consists of the queried pool info data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param hyperdrive_address: The hyperdrive pool address(es) to filter the query on. Defaults to returning all position snapshots. :type hyperdrive_address: str | list[str] | None, optional :param latest_entry: If true, will return the latest entry for every pool. Defaults to False. :type latest_entry: bool, optional :param start_block: 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. :type start_block: int | None, optional :param end_block: 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. :type end_block: int | None, optional :param wallet_address: The wallet addresses to filter the query on. Returns all if None. :type wallet_address: list[str] | None, optional :param coerce_float: If True, will return floats in dataframe. Otherwise, will return fixed point Decimal. Defaults to False. :type coerce_float: bool, optional :returns: A DataFrame that consists of the queried pool info data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param start_block: The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type start_block: int | None, optional :param end_block: The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type end_block: int | None, optional :param wallet_address: The wallet addresses to filter the query on. Returns all if None. :type wallet_address: list[str] | None, optional :param coerce_float: If true, will return floats in dataframe. Otherwise, will return fixed point Decimal. :type coerce_float: bool :returns: A DataFrame that consists of the queried pool info data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param start_block: The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type start_block: int | None, optional :param end_block: The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type end_block: int | None, optional :param wallet_address: The wallet addresses to filter the query on. Returns all if None. :type wallet_address: list[str] | None, optional :param coerce_float: If true, will return floats in dataframe. Otherwise, will return fixed point Decimal. :type coerce_float: bool :returns: A DataFrame that consists of the queried pool info data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized session object. :type session: Session :param start_block: The starting block to filter the query on. start_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type start_block: int | None, optional :param end_block: The ending block to filter the query on. end_block integers matches python slicing notation, e.g., list[:3], list[:-3]. :type end_block: int | None, optional :param wallet_address: The wallet addresses to filter the query on. Returns all if None. :type wallet_address: list[str] | None, optional :param coerce_float: If true, will return floats in dataframe. Otherwise, will return fixed point Decimal. :type coerce_float: bool :returns: A DataFrame that consists of the queried pool info data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:function:: 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. :param session: The initialized db session object. :type session: Session :param wallet_address: The wallet address(es) to filter the results on. Return all if None. :type wallet_address: str | list[str] | None, optional :param hyperdrive_address: The hyperdrive address(es) to filter the results on. Returns all if None. :type hyperdrive_address: str | list[str] | None, optional :param all_token_deltas: 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. :type all_token_deltas: bool, optional :param sort_ascending: If True, will sort events in ascending block order. Otherwise, will sort in descending order. Defaults to True. :type sort_ascending: bool, optional :param query_limit: The number of rows to return. Defaults to return all rows. :type query_limit: int | None, optional :param coerce_float: If True, will return floats in dataframe. Otherwise, will return fixed point Decimal. Defaults to False. :type coerce_float: bool, optional :returns: A DataFrame that consists of the queried trade events data. :rtype: DataFrame .. !! processed by numpydoc !! .. py:class:: DBCheckpointInfo Bases: :py:obj:`agent0.chainsync.db.base.DBBase` Table/dataclass schema for checkpoint information. .. !! processed by numpydoc !! .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] The unique identifier for the entry to the table. .. !! processed by numpydoc !! .. py:attribute:: hyperdrive_address :type: sqlalchemy.orm.Mapped[str] The hyperdrive address for the entry. .. !! processed by numpydoc !! .. py:attribute:: block_number :type: sqlalchemy.orm.Mapped[int] The block number on which the event was emitted. .. !! processed by numpydoc !! .. py:attribute:: checkpoint_time :type: sqlalchemy.orm.Mapped[int] The seconds epoch time index for this checkpoint. .. !! processed by numpydoc !! .. py:attribute:: checkpoint_vault_share_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The share price that was checkpointed in this checkpoint. .. !! processed by numpydoc !! .. py:attribute:: vault_share_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The vault share price at the time of checkpoint creation. .. !! processed by numpydoc !! .. py:attribute:: matured_shorts :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The amount of shorts that matured within this checkpoint. .. !! processed by numpydoc !! .. py:attribute:: matured_longs :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The amount of longs that matured within this checkpoint. .. !! processed by numpydoc !! .. py:attribute:: lp_share_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The lp share price at the checkpoint. .. !! processed by numpydoc !! .. py:class:: DBHyperdriveAddrToName Bases: :py:obj:`agent0.chainsync.db.base.DBBase` Maps a hyperdrive address to a logical name. .. !! processed by numpydoc !! .. py:attribute:: hyperdrive_address :type: sqlalchemy.orm.Mapped[str] The hyperdrive address .. !! processed by numpydoc !! .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] The logical name of the hyperdrive address. .. !! processed by numpydoc !! .. py:class:: DBPoolConfig Bases: :py:obj:`agent0.chainsync.db.base.DBBase` Table/dataclass schema for pool config. .. !! processed by numpydoc !! .. py:attribute:: hyperdrive_address :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: base_token :type: sqlalchemy.orm.Mapped[Union[str, None]] .. py:attribute:: vault_shares_token :type: sqlalchemy.orm.Mapped[Union[str, None]] .. py:attribute:: linker_factory :type: sqlalchemy.orm.Mapped[Union[str, None]] .. py:attribute:: initial_vault_share_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: minimum_share_reserves :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: minimum_transaction_amount :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: circuit_breaker_delta :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: position_duration :type: sqlalchemy.orm.Mapped[Union[int, None]] .. py:attribute:: checkpoint_duration :type: sqlalchemy.orm.Mapped[Union[int, None]] .. py:attribute:: time_stretch :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: governance :type: sqlalchemy.orm.Mapped[Union[str, None]] .. py:attribute:: fee_collector :type: sqlalchemy.orm.Mapped[Union[str, None]] .. py:attribute:: sweep_collector :type: sqlalchemy.orm.Mapped[Union[str, None]] .. py:attribute:: curve_fee :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: flat_fee :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: governance_lp_fee :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: governance_zombie_fee :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: inv_time_stretch :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:class:: DBPoolInfo Bases: :py:obj:`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. .. !! processed by numpydoc !! .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: hyperdrive_address :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: block_number :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: timestamp :type: sqlalchemy.orm.Mapped[datetime.datetime] .. py:attribute:: epoch_timestamp :type: sqlalchemy.orm.Mapped[Union[int, None]] .. py:attribute:: share_reserves :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: share_adjustment :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: zombie_base_proceeds :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: zombie_share_reserves :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: bond_reserves :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: lp_total_supply :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: vault_share_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: longs_outstanding :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: long_average_maturity_time :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: shorts_outstanding :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: short_average_maturity_time :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: withdrawal_shares_ready_to_withdraw :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: withdrawal_shares_proceeds :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: lp_share_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: long_exposure :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: total_supply_withdrawal_shares :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: gov_fees_accrued :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: hyperdrive_base_balance :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: hyperdrive_eth_balance :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: variable_rate :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: vault_shares :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: spot_price :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:attribute:: fixed_rate :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] .. py:class:: DBPositionSnapshot Bases: :py:obj:`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. .. !! processed by numpydoc !! .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] The unique identifier for the entry to the table. .. !! processed by numpydoc !! .. py:attribute:: hyperdrive_address :type: sqlalchemy.orm.Mapped[str] The hyperdrive address for the entry. .. !! processed by numpydoc !! .. py:attribute:: block_number :type: sqlalchemy.orm.Mapped[int] The block number for the entry. .. !! processed by numpydoc !! .. py:attribute:: wallet_address :type: sqlalchemy.orm.Mapped[Union[str, None]] The wallet address for the entry. .. !! processed by numpydoc !! .. py:attribute:: token_type :type: sqlalchemy.orm.Mapped[Union[str, None]] The underlying token type for the entry. Can be one of the following: `LONG`, `SHORT, `LP`, or `WITHDRAWAL_SHARE`. .. !! processed by numpydoc !! .. py:attribute:: maturity_time :type: sqlalchemy.orm.Mapped[Union[int, None]] The maturity time of the token for LONG and SHORT tokens. .. !! processed by numpydoc !! .. py:attribute:: token_id :type: sqlalchemy.orm.Mapped[Union[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`. .. !! processed by numpydoc !! .. py:attribute:: token_balance :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The absolute balance of the position. .. !! processed by numpydoc !! .. py:attribute:: unrealized_value :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The unrealized value of the tokens in units of base, calculated if the position is closed at this block. .. !! processed by numpydoc !! .. py:attribute:: realized_value :type: sqlalchemy.orm.Mapped[Union[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. .. !! processed by numpydoc !! .. py:attribute:: pnl :type: sqlalchemy.orm.Mapped[Union[decimal.Decimal, None]] The pnl of the position in units of base. `unrealized_value` + `realized_value` = `pnl`. .. !! processed by numpydoc !! .. py:attribute:: last_balance_update_block :type: sqlalchemy.orm.Mapped[Union[int, None]] The last block number that this position's balance was updated. .. !! processed by numpydoc !!