Skip to content

ReHypothecationHook: add slippage protection to add/remove liquidity (#122)#134

Open
impetus82 wants to merge 1 commit into
OpenZeppelin:masterfrom
impetus82:fix/rehypothecation-slippage-122
Open

ReHypothecationHook: add slippage protection to add/remove liquidity (#122)#134
impetus82 wants to merge 1 commit into
OpenZeppelin:masterfrom
impetus82:fix/rehypothecation-slippage-122

Conversation

@impetus82

Copy link
Copy Markdown

Summary

Addresses #122. addReHypothecatedLiquidity and removeReHypothecatedLiquidity accepted only shares and derived the actual token amounts from the live pool price (when totalSupply() == 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 with ExcessiveInput if the required input (see previewMint) exceeds the caller's maximums.
  • removeReHypothecatedLiquidity(shares, amount0Min, amount1Min) — reverts with InsufficientOutput if the returned output (see previewRedeem) 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 (opt-in protection).
  • Updated the slippage WARNING in 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 fmt clean.

Closes #122

🤖 Generated with Claude Code

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>
@netlify

netlify Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploy Preview for uniswap-hooks-docs ready!

Name Link
🔨 Latest commit 66ebc46
🔍 Latest deploy log https://app.netlify.com/projects/uniswap-hooks-docs/deploys/6a366a4577a2fa000854d401
😎 Deploy Preview https://deploy-preview-134--uniswap-hooks-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploy Preview for uniswap-hooks ready!

Name Link
🔨 Latest commit 66ebc46
🔍 Latest deploy log https://app.netlify.com/projects/uniswap-hooks/deploys/6a366a45c647010008c02af2
😎 Deploy Preview https://deploy-preview-134--uniswap-hooks.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReHypothecationHook: add slippage protection to addReHypothecatedLiquidity and removeReHypothecatedLiquidity

1 participant