fix(deploy-uni-hook): anchor price/balance/skew gates to the pool's own price - #1031
Merged
Merged
Conversation
…wn price, not an implicit 1.0 A freeform balance/skew gate that compares the two virtual reserves is really comparing raw price to 1.0: StateLibrary gives amount0/amount1 = 1/price, so the liquidity L cancels exactly. Such a gate is permanently one-directional on any pair that is not a same-decimals pool near parity (a USDC/WETH-shaped pool sits ~8 orders of magnitude off, two 18-dec tokens at price 2.0 are already outside a 10% band): one whole leg of trade reverts forever. - Codify it in the Fleet audit rules (Gates rule 6): snapshot the pool's own sqrtPriceX96 at afterInitialize and gate against that, and add the afterInitialize callback (flag 0x1000) to any price / balance / skew hook. - Require the behavioral test to assert such gates OFF 1:1. The setUp scaffold pool is at 1:1, the single price where the bug hides, and the generator may not edit setUp. Add a _freshPoolAt(sqrtPriceX96) helper so a test can repoint the pool off parity and assert both legs.
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.
What
Freeform balance / skew / "heavier-side" hooks generated by this skill compare the two virtual reserves. That comparison is a raw-price gate in disguise:
StateLibrarygivesamount0 = L*2^96/sqrtPandamount1 = L*sqrtP/2^96, soamount0/amount1 = 1/priceand the liquidityLcancels exactly. The gate therefore tests the pool's raw price against an implicit1.0, which only matches "balanced" for a same-decimals pair near parity.Consequence: on any real pair the pool is permanently one-directional (one whole leg of trade reverts forever). A USDC(6d)/WETH(18d) pool sits ~8 orders of magnitude off; two 18-dec tokens at price 2.0 are already outside a 10% band. And "every trade rebalances toward 50/50" is false anyway (a full-range position is already 50/50 by value at any price).
The skill's own behavioral-test scaffold hides this:
setUp()opens the pool at 1:1 (the one price where such a gate looks correct) and the generator may not editsetUp().Changes
SKILL.md): documents theL-cancels defect and the fix - snapshot the pool's ownsqrtPriceX96atafterInitializeand gate against that, never1.0. Requires theafterInitializecallback (flag0x1000) on any price/balance/skew hook.templates/Hook.t.sol: new_freshPoolAt(uint160 sqrtPriceX96)helper (fixed scaffolding) that repoints the test pool to a second pool on the same hook at an arbitrary price, so the generator can assert both legs away from parity without touchingsetUp().No frontmatter or file-count change, so
catalog/skills.jsonis unaffected (verified against theci-skills-jsonnormalized diff).forge fmt --checkpasses on the template.