ReHypothecationHook: add slippage protection to add/remove liquidity (#122)#134
Open
impetus82 wants to merge 1 commit into
Open
ReHypothecationHook: add slippage protection to add/remove liquidity (#122)#134impetus82 wants to merge 1 commit into
impetus82 wants to merge 1 commit into
Conversation
Addresses OpenZeppelin#122. addReHypothecatedLiquidity and removeReHypothecatedLiquidity took only `shares` and computed the actual token amounts from the live pool price / yield-source balances, with no slippage bounds -- exposing users to sandwiching and price/yield movement between transaction signing and execution. Add backwards-compatible slippage-protected overloads: - addReHypothecatedLiquidity(shares, amount0Max, amount1Max) reverts with ExcessiveInput if the required input exceeds the caller's maximums. - removeReHypothecatedLiquidity(shares, amount0Min, amount1Min) reverts with InsufficientOutput if the returned output is below the caller's minimums. The original single-argument functions are preserved and delegate to the new overloads with unbounded limits, so existing integrations are unaffected. Adds tests covering both reverts and within-bounds success; full suite green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for uniswap-hooks-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for uniswap-hooks ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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
Addresses #122.
addReHypothecatedLiquidityandremoveReHypothecatedLiquidityaccepted onlysharesand derived the actual token amounts from the live pool price (whentotalSupply() == 0) or from yield-source balances, with no slippage bounds — exposing users to sandwiching and price/yield movement between transaction signing and execution.Changes
addReHypothecatedLiquidity(shares, amount0Max, amount1Max)— reverts withExcessiveInputif the required input (seepreviewMint) exceeds the caller's maximums.removeReHypothecatedLiquidity(shares, amount0Min, amount1Min)— reverts withInsufficientOutputif the returned output (seepreviewRedeem) is below the caller's minimums.WARNINGin the contract docstring to point at the new overloads.Design note
The change is intentionally backwards-compatible (the 1-arg functions remain, unbounded). If you'd prefer to make the bounds mandatory (dropping the unbounded path) or a different parameter naming/convention, happy to adjust.
Tests
Four new tests in
ReHypothecationHookERC4626.t.sol: revert on excessive input, revert on insufficient output, success within bounds, and backwards-compatibility of the single-argument overload. Full suite green (308/308),forge fmtclean.Closes #122
🤖 Generated with Claude Code