-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR is the first of a series of PRs to support multi-pool trading in agent0. In this PR, we move away from exposing the `agent.wallet` object (as we're deprecating doing bookkeeping on the wallet itself in python) in favor of using the `agent.get_positions()` function. This function (1) does a query of the chain to gather events and adds them to a `TradeEvent` db table, and (2) queries from the `TradeEvent` table to get the current positions a wallet has. The `TradeEvent` table handles all events on any hyperdrive tokens (i.e., long/short/lp). There's a bit of overlap with the `WalletDelta` table, with the main exception that the `TradeEvent` table is lazy - the table only gets updated when `agent.get_positions()` gets called, and only with the events from `agent`. In addition, the table handles both trade events (e.g., `OpenLong`) and single transfer trades (e.g., wallet to wallet transfers of tokens). We likely can deprecate the `WalletDelta` table with a special call to gather all trade events from a Hyperdrive pool, which fills the `TradeEvent` table with every wallet that has made a trade on the pool. There are a couple of places that can be optimized. Currently, we query the chain for events for every `get_positions` call (from the latest entry in the db to latest block). Some bookkeeping is needed to e.g., don't get events from the logs if a user calls `get_positions` on the same block. As a temporary fix, we also remove `agent.wallet` from remote chains, and `get_positions` gathers all events from the remote chain each time it's called. This will get fixed once the database is exposed in the underlying chain object, with the remote wallet also using the `TradeEvent` table to gather wallet positions. Final note: the failing test here is fixed in #1462. ## Changes - Removing interactive wallet in favor of using `get_positions()`. - Added `TradeEvent` table to database, with supporting ingestion (`trade_events_to_db`) and query (`get_positions_from_db` and `get_trade_events`) interface functions. - Changed all interactive `agent.wallet` calls to `agent.get_positions()` - Renamed `contract_address` to `hyperdrive_address` in `PoolConfig` db table.
- Loading branch information
Showing
23 changed files
with
880 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.