agent0.chainsync.db.hyperdrive.schema

Database Schemas for the Hyperdrive Contract.

Attributes

FIXED_NUMERIC

Classes

DBHyperdriveAddrToName

Maps a hyperdrive address to a logical name.

DBPoolConfig

Table/dataclass schema for pool config.

DBCheckpointInfo

Table/dataclass schema for checkpoint information.

DBPoolInfo

Table/dataclass schema for pool info.

DBTradeEvent

Table for storing any transfer events emitted by the Hyperdrive contract.

DBPositionSnapshot

Table/dataclass schema for snapshots of positions

Module Contents

agent0.chainsync.db.hyperdrive.schema.FIXED_NUMERIC
class agent0.chainsync.db.hyperdrive.schema.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.schema.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.schema.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.schema.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.schema.DBTradeEvent

Bases: agent0.chainsync.db.base.DBBase

Table for storing any transfer events emitted by the Hyperdrive contract.

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.

transaction_hash: sqlalchemy.orm.Mapped[str]

The transaction hash for the entry.

block_number: sqlalchemy.orm.Mapped[int]

The block number for the entry.

wallet_address: sqlalchemy.orm.Mapped[str]

The wallet address for the entry.

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

The underlying event type for the entry. Can be one of the following: Initialize, AddLiquidity, RemoveLiquidity, RedeemWithdrawalShares, OpenLong, OpenShort, CloseLong, CloseShort, or TransferSingle.

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_delta: sqlalchemy.orm.Mapped[decimal.Decimal | None]

The change in tokens with respect to the wallet address.

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

The change in base tokens for the event with respect to the wallet address.

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

The change in vault share tokens for the event with respect to the wallet address.

as_base: sqlalchemy.orm.Mapped[bool | None]

A flag defining if the trade was made in units of base or vault shares.

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

The vault share price at the time of the emitted event.

extra_data: sqlalchemy.orm.Mapped[bytes | None]
class agent0.chainsync.db.hyperdrive.schema.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.