Closed slundqui closed 5 months ago
Attention: Patch coverage is 87.60234%
with 106 lines
in your changes are missing coverage. Please review.
Project coverage is 83.54%. Comparing base (
9950db3
) to head (dc79d09
).:exclamation: Current head dc79d09 differs from pull request most recent head fbf0dda
Please upload reports for the commit fbf0dda to get more accurate results.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
There are several related chainsync issues that may or may not be resolved by this PR; please close them if they are
Update chainsync to work with testnet https://github.com/delvtech/agent0/issues/1411
Use hyperdrivepy rust functions in chainsync https://github.com/delvtech/agent0/issues/1166
chainsync: update to use hyperdrivepy's get spot price https://github.com/delvtech/agent0/issues/927
update chainsync to have a pool column, use one db across pools https://github.com/delvtech/agent0/issues/1455
Extend chainsync to work with remote connections in interactive hyperdrive https://github.com/delvtech/agent0/issues/1456
This PR is the second in a collection of refactors to allow agent0 to support multiple pools.
This PR focuses on updates to the database and related systems. In particular, this makes the following major changes to the database.
Database schema updates
hyperdrive_address
field.HyperdriveAddrToName
maps the hyperdrive address to a logical name. The name defaults to<vault_share_token_symbol>_<position_duration_in_days>_day
.WalletDelta
andHyperdriveTransactions
tables have been removed in favor of the new events table added in https://github.com/delvtech/agent0/pull/1464.PositionSnapshot
table calculates the absolute positions from the deltas stored in theTradeEvent
tables. This table also stores any additional information useful for analysis, such as realized and unrealized values of positions, and the pnl.CurrentWallet
,Ticker
, andWalletPNL
tables have been removed in favor of a newPositionSnapshot
table.PoolAnalysis
table has been removed in favor of putting the fields in thePoolInfo
table.UsernameToUser
table has been removed, no need to map multiple wallets to a single user.Analysis from remote chains
The database container is now managed by the
Chain
object as opposed toLocalChain
. Likewise, database sessions is now managed by theChain
object as opposed toLocalHyperdrive
. These changes allow the remote chain object to have access to the database for gathering events, positions, and pnl from hyperdrive pools.The simulated environment uses the full set of tables in the database, whereas the remote chain environment uses a subset of these tables. Both workflows uses the same underlying schema, but the remote workflow updates these tables lazily, i.e., only query and insert events and snapshots into the db when the user calls the functions that need them. Additionally, the remote workflow only updates the tables with any agents initialized by agent0. In contrast, the simulated environment updates these tables with all agents that have interacted with the simulated pool, and the database is updated on every trade to these pools.
Interactive analysis interface
The interactive interface for getting information from the db has been reworked. Note that some pool analysis functions are only available in
LocalHyperdrive
method, due to lazy event querying on remote chains.Wallet objects and Positions
agent.get_wallet()
has replacedagent.get_positions()
(which replacedagent.wallet
in https://github.com/delvtech/agent0/pull/1464). This function returns aHyperdriveWallet
object that contains the relevant positions (i.e., base, longs, shorts, lp, withdrawal shares) for a specific pool. A future PR will allow this function to take a pool as an argument, or require setting the agent's active pool. This function queries the database for current positions.agent.get_positions()
now returns a dataframe consisting of all open positions across all pools held by the agent, with additional pnl, unrealized, and realized value columns. An optional argumentshow_closed_positions
, if set to True, will also return all closed positions and the position's realized value.hyperdrive.get_positions()
returns a dataframe consisting of all positions across thehyperdrive
pool. This function is only available inLocalHyperdrive
.agent.get_trade_events()
returns a dataframe of events emitted from the agent across all pools that the agent interacted with. An optional argumentall_token_deltas
, if set to True, will repeat anyRemoveLiquidity
events with a non-zero withdrawal shares, where the additional row tracks the withdrawal share token delta.hyperdrive.get_trade_events()
returns a dataframe of events emitted from the pool across all agents. This function is only available inLocalHyperdrive
.Historical positions
We also expose a couple of helper functions for getting positions over time. These are exclusive to
LocalHyperdrive
, due to the underlying table (i.e.,PositionSnapshot
) only being guaranteed to keep historical data for the simulated environment.hyperdrive.get_historical_positions()
returns a dataframe with the history of positions over time. This function is only available inLocalHyperdrive
.hyperdrive.get_historical_pnl()
returns a dataframe of historical positions, aggregated across all positions to find the total pnl. This function is only available inLocalHyperdrive
.Streamlit dashboard
run_dashboard
command is now a function of theLocalChain
.