Closed slundqui closed 2 months ago
Attention: Patch coverage is 94.20849%
with 15 lines
in your changes are missing coverage. Please review.
Project coverage is 82.03%. Comparing base (
14475b2
) to head (ab09336
).:exclamation: Current head ab09336 differs from pull request most recent head 4ef854c. Consider uploading reports for the commit 4ef854c to get more accurate results
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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 theagent.get_positions()
function. This function (1) does a query of the chain to gather events and adds them to aTradeEvent
db table, and (2) queries from theTradeEvent
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 theWalletDelta
table, with the main exception that theTradeEvent
table is lazy - the table only gets updated whenagent.get_positions()
gets called, and only with the events fromagent
. 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 theWalletDelta
table with a special call to gather all trade events from a Hyperdrive pool, which fills theTradeEvent
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 callsget_positions
on the same block.As a temporary fix, we also remove
agent.wallet
from remote chains, andget_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 theTradeEvent
table to gather wallet positions.Final note: the failing test here is fixed in https://github.com/delvtech/agent0/pull/1462.
Changes
get_positions()
.TradeEvent
table to database, with supporting ingestion (trade_events_to_db
) and query (get_positions_from_db
andget_trade_events
) interface functions.agent.wallet
calls toagent.get_positions()
contract_address
tohyperdrive_address
inPoolConfig
db table.