-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-pool and events based database refactor #1467
Conversation
0408ca5
to
28136c6
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1467 +/- ##
==========================================
+ Coverage 82.28% 83.54% +1.26%
==========================================
Files 90 87 -3
Lines 6019 5623 -396
==========================================
- Hits 4953 4698 -255
+ Misses 1066 925 -141
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
94dd4a3
to
4e05bb6
Compare
… snapshot schema for values
… removing as base
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heroic effort! Well done :)
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 Adding event queries to db #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 Adding event queries to db #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
.