Skip to content

feat: Universal Router v2.1.1#470

Open
gretzke wants to merge 13 commits intomainfrom
ur-2.1.1
Open

feat: Universal Router v2.1.1#470
gretzke wants to merge 13 commits intomainfrom
ur-2.1.1

Conversation

@gretzke
Copy link
Contributor

@gretzke gretzke commented Feb 21, 2026

Summary

  • PAY_PORTION_FULL_PRECISION (0x07): New payment command with 1e18 precision (vs 10,000 bips), enabling exact fractional payments like 1/3
  • Per-hop slippage for V2/V3: Adds uint256[] maxHopSlippage parameter to all 4 V2/V3 swap commands (V3_SWAP_EXACT_IN, V3_SWAP_EXACT_OUT, V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT), matching V4's convention where price = amountOut * 1e36 / amountIn
  • v4-periphery submodule bump: Updates submodule to include maxHopSlippage in V4 single-swap structs

Test Plan

  • 101 Foundry tests pass (including 13 new V3 mock pool tests for per-hop slippage)
  • 12 Hardhat integration tests pass (including new tests for PAY_PORTION_FULL_PRECISION)
  • V3 exact-output multi-hop slippage enforcement verified (hop 0 bug fixed)
  • V4 single-swap planner ABI updated for maxHopSlippage field
  • Path length guards prevent underflow on malformed inputs

✨ Claude-Generated Content

Summary

Universal Router v2.1.1 introduces high-precision payment commands and per-hop slippage protection for V2/V3 swaps.

Changes

New Commands

  • PAY_PORTION_FULL_PRECISION (0x07): Payment command with 1e18 precision (vs 10,000 bips), enabling exact fractional payments like 1/3

Per-hop Slippage Protection

  • Add uint256[] maxHopSlippage parameter to all V2/V3 swap commands:
    • V3_SWAP_EXACT_IN, V3_SWAP_EXACT_OUT
    • V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT
  • Price convention: amountOut * 1e36 / amountIn
  • Path length guards prevent underflow on malformed inputs

New Errors

  • V2TooLittleReceivedPerHop, V2InvalidHopSlippageLength in V2SwapRouter
  • V3TooLittleReceivedPerHop, V3TooMuchRequestedPerHop, V3InvalidHopSlippageLength in V3SwapRouter
  • InvalidPortion in Payments module

Library Updates

  • Add toUint256Array helper in BytesLib for decoding hop slippage arrays
  • Add SLIPPAGE_PRECISION constant (1e36) in Constants
  • Add INCREASE_LIQUIDITY_FROM_DELTAS action check in V3ToV4Migrator

Build Configuration

  • Set bytecode_hash = "none" in foundry.toml

Dependencies

  • Update v4-periphery submodule to include maxHopSlippage in V4 single-swap structs

Test Plan

  • 101 Foundry tests pass (including 13 new V3 mock pool tests for per-hop slippage)
  • 12 Hardhat integration tests pass (including 4 new tests for PAY_PORTION_FULL_PRECISION)
  • V3 exact-output multi-hop slippage enforcement verified (hop 0 bug fixed)
  • V4 single-swap planner ABI updated for maxHopSlippage field

@gretzke gretzke requested a review from a team as a code owner February 21, 2026 18:34
@github-actions
Copy link

github-actions bot commented Feb 21, 2026

🤖 Claude Code Review

🔄 Review in progress... Claude is analyzing this pull request. If a review can be seen below, it will be replaced by the results of this one.

⏱️ Reviews typically complete within 5-15 minutes depending on PR size.

Summary

This PR adds two major features to the Universal Router:

  1. Per-hop slippage checks for V2 and V3 swaps - Allows callers to specify minimum price thresholds for each individual hop in multi-hop swaps, providing more granular slippage protection beyond the existing overall amountOutMinimum/amountInMaximum checks.

  2. PAY_PORTION_FULL_PRECISION command - A new payment command that uses 1e18 precision instead of bips (10_000), enabling more precise portion calculations (e.g., exact 1/3 splits impossible with bips).

Analysis

Per-hop Slippage Implementation

The implementation correctly handles the complex ordering of exact-output swaps where trading hops execute in reverse order:

  • V3 exact-input: Slippage checked in the main loop after each swap
  • V3 exact-output: Slippage checked in the callback, with hopIndex starting at maxHopSlippage.length - 1 and decrementing
  • V2: Slippage checked inline during _v2Swap loop for both exact-in and exact-out

The SLIPPAGE_PRECISION of 1e36 provides sufficient precision for price comparisons.

Breaking Change Considerations

The ABI for V2 and V3 swap commands has changed - all calls now require a 6th parameter (maxHopSlippage array). Passing an empty array disables the feature, maintaining backward compatibility at the contract level. However, off-chain integrations will need updates.

Test Coverage

The foundry tests (UniswapV3.t.sol) are well-designed:

  • Tests both single-hop and multi-hop scenarios
  • Tests both exact-input and exact-output
  • testV3ExactOutputMultiHopSlippageFailHop0 specifically catches bugs in hop index ordering
  • Invalid length validation tests

Code Quality

The implementation is clean:

  • Validation upfront with V2InvalidHopSlippageLength / V3InvalidHopSlippageLength errors
  • Graceful no-op when maxHopSlippage.length == 0
  • Consistent precision constant usage

Verdict

The implementation is correct and well-tested. The features are additive with sensible defaults (empty array = disabled). No bugs, security issues, or data corruption risks identified.


💡 Want a fresh review? Add a comment containing @request-claude-review to trigger a new review at any time.

github-actions[bot]
github-actions bot previously approved these changes Feb 21, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

@github-actions github-actions bot dismissed their stale review February 21, 2026 19:02

Superseded by new review after PR update

github-actions[bot]
github-actions bot previously approved these changes Feb 21, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

Remove the TRANSFER_FROM command and associated tests. This reverts
commit e902459 and also removes integration tests added in 7206c96
that depended on it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot dismissed their stale review February 25, 2026 14:56

Superseded by new review after PR update

github-actions[bot]
github-actions bot previously approved these changes Feb 25, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

@github-actions github-actions bot dismissed their stale review February 25, 2026 15:12

Superseded by new review after PR update

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

@github-actions
Copy link

🤖 Claude Code Review

Status: ⚠️ Partial (script error)
Job: View workflow run


The review was completed but there was an error posting inline comments.

Raw Review Output
No review output available

Please check the workflow logs for details.

@github-actions
Copy link

🤖 Claude Code Review

Status: ❌ Error
Job: View workflow run


⚠️ Review Failed

The automated code review encountered an error and could not complete.

Next Steps:

  1. Check the workflow logs for details
  2. Verify the GitHub Actions configuration
  3. Ensure the Anthropic API key is valid
  4. Check for any permission issues

If the problem persists, please contact your repository administrator.


You can manually re-trigger the review by pushing a new commit or re-running the workflow.

@github-actions
Copy link

🤖 Claude Code Review

Status: ⚠️ Partial (script error)
Job: View workflow run


The review was completed but there was an error posting inline comments.

Raw Review Output
No review output available

Please check the workflow logs for details.

@github-actions
Copy link

🤖 Claude Code Review

Status: ❌ Error
Job: View workflow run


⚠️ Review Failed

The automated code review encountered an error and could not complete.

Next Steps:

  1. Check the workflow logs for details
  2. Verify the GitHub Actions configuration
  3. Ensure the Anthropic API key is valid
  4. Check for any permission issues

If the problem persists, please contact your repository administrator.


You can manually re-trigger the review by pushing a new commit or re-running the workflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

🤖 Claude Code Review

Status: ⚠️ Partial (script error)
Job: View workflow run


The review was completed but there was an error posting inline comments.

Raw Review Output
No review output available

Please check the workflow logs for details.

@github-actions
Copy link

🤖 Claude Code Review

Status: ❌ Error
Job: View workflow run


⚠️ Review Failed

The automated code review encountered an error and could not complete.

Next Steps:

  1. Check the workflow logs for details
  2. Verify the GitHub Actions configuration
  3. Ensure the Anthropic API key is valid
  4. Check for any permission issues

If the problem persists, please contact your repository administrator.


You can manually re-trigger the review by pushing a new commit or re-running the workflow.

@github-actions
Copy link

🤖 Claude Code Review

Status: ⚠️ Partial (script error)
Job: View workflow run


The review was completed but there was an error posting inline comments.

Raw Review Output
No review output available

Please check the workflow logs for details.

@github-actions
Copy link

🤖 Claude Code Review

Status: ❌ Error
Job: View workflow run


⚠️ Review Failed

The automated code review encountered an error and could not complete.

Next Steps:

  1. Check the workflow logs for details
  2. Verify the GitHub Actions configuration
  3. Ensure the Anthropic API key is valid
  4. Check for any permission issues

If the problem persists, please contact your repository administrator.


You can manually re-trigger the review by pushing a new commit or re-running the workflow.

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.

2 participants