fix: seed position_ledger from create tx in dhook Create handler#71
Open
RhizoNymph wants to merge 2 commits into
Open
fix: seed position_ledger from create tx in dhook Create handler#71RhizoNymph wants to merge 2 commits into
RhizoNymph wants to merge 2 commits into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The newer
DopplerHookInitializer(0xBDF938...) doesn't re-emitModifyLiquidityat the initializer level for seeding, and the seedingPoolManager.ModifyLiquiditylogs fire at a lowerlog_indexthan the matchingCreateevent in the same tx — so by the time thePoolManager:ModifyLiquidityhandler runs, the pool isn't in the dhook cache yet and the upsert short-circuits. Net result: affected pools have an emptyposition_ledger, and every downstreamSwapcomputesreserves = computeReservesFromPositions([], tick) = {0, 0}.This patch closes the leak going forward by replaying the create tx's receipt in the
DopplerHookInitializer:Createhandler:seedPositionLedgerFromCreateTx({ poolAddress, context, txHash })that pullsgetTransactionReceipt, filters PoolManager +ModifyLiquiditytopic +topic1 == poolId, decodes(int24, int24, int256, bytes32), and feeds each delta to the existingupsertPositionLedger.insertPoolIfNotExistsDHook+ cache registration, then compute reserves from the now-populated ledger viagetPositionsForPoolinstead offetchPositions.One RPC call per Create event; no block-range walking; naturally scoped to the create tx so future ModifyLiquidity events still go through the standard PoolManager handler (which now succeeds because the cache has the pool).
Follow-up
Pools created before this lands still have empty ledgers and need
scripts/backfill-position-ledger.mjs --schema prod ... --applyto repair. Verified by hand against0xf12523285529af9b21d9e9687c02c58cf5559ba3on Base — its create tx (0x9758db0b..., block 46821559) contains exactly the two seedingPoolManager.ModifyLiquiditylogs this handler would now decode and persist ([119600, 229600] → 1.028e24and[-887200, 119600] → 2.530e24).