Skip to content

feat(universal-router-sdk): wire up per-hop slippage encoding#532

Draft
kristiehuang wants to merge 1 commit into03-02-feat_universal-router-sdk_v2.1.1_version_rename_abi_infrastructurefrom
03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding
Draft

feat(universal-router-sdk): wire up per-hop slippage encoding#532
kristiehuang wants to merge 1 commit into03-02-feat_universal-router-sdk_v2.1.1_version_rename_abi_infrastructurefrom
03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding

Conversation

@kristiehuang
Copy link
Collaborator

@kristiehuang kristiehuang commented Mar 2, 2026

Description

  • Remove maxHopSlippage from SwapOptions
  • Update Swap interface to carry maxHopSlippage (from trade.swaps)
  • addV2Swap / addV3Swap: branch on urVersion to encode with or without maxHopSlippage
  • addV4Swap: read maxHopSlippage from swap instead of options
  • addMixedSwap: slice maxHopSlippage per section with hop offset tracking
  • Tests for all protocol paths (V2, V3, V4, mixed) with and without per-hop slippage

How Has This Been Tested?

[e.g. Manually, E2E tests, unit tests, Storybook]

Are there any breaking changes?

If consumers want to use UR v2.1.1, they must update to this version of the UR-sdk.


✨ Claude-Generated Content

Summary

Wire up per-hop slippage encoding for Universal Router v2.1.1 across all protocol versions (V2, V3, V4, and mixed routes). The maxHopSlippage parameter has been moved from SwapOptions to individual swaps, enabling granular slippage protection per route.

Changes

sdks/universal-router-sdk/src/entities/actions/uniswap.ts

  • Removed maxHopSlippage from SwapOptions interface
  • Added maxHopSlippage?: bigint[] to the Swap interface to carry per-hop slippage from trade.swaps
  • addV2Swap: branches on urVersion to encode with/without maxHopSlippage for V2_SWAP_EXACT_IN and V2_SWAP_EXACT_OUT commands
  • addV3Swap: branches on urVersion to encode with/without maxHopSlippage for V3_SWAP_EXACT_IN and V3_SWAP_EXACT_OUT commands
  • addV4Swap: reads maxHopSlippage from the swap object instead of options
  • addMixedSwap: tracks hopOffset to slice the flat maxHopSlippage array per protocol section
  • Added validation to ensure maxHopSlippage length matches route.pools.length

sdks/universal-router-sdk/README.md

  • Updated per-hop slippage documentation to reflect new API where maxHopSlippage is specified on each route within RouterTrade
  • Added mixed routes example showing how the SDK slices hop slippage by section
  • Updated references from v2.1 to v2.1.1

sdks/universal-router-sdk/test/unit/perHopSlippage.test.ts (new)

  • Tests for V2_SWAP_EXACT_IN/OUT with maxHopSlippage (V2.1.1 ABI)
  • Tests for V3_SWAP_EXACT_IN/OUT with maxHopSlippage (V2.1.1 ABI)
  • Tests for empty maxHopSlippage arrays
  • Backward compatibility tests (V2.0 ABI without maxHopSlippage)
  • Mixed route slippage slicing tests

How Has This Been Tested?

Unit tests covering all protocol paths (V2, V3, V4, mixed) with and without per-hop slippage encoding.

Are there any breaking changes?

Minor breaking change: maxHopSlippage has been removed from SwapOptions. Consumers must now specify maxHopSlippage on individual routes within the RouterTrade constructor.
Migration:

// Before (v2.1)
SwapRouter.swapCallParameters(trade, { maxHopSlippage: [...], urVersion: URVersion.V2_1 })
// After (v2.1.1)
const trade = new RouterTrade({
  v3Routes: [{ routev3, inputAmount, outputAmount, maxHopSlippage: [...] }],
  tradeType,
})
SwapRouter.swapCallParameters(trade, { urVersion: URVersion.V2_1_1 })

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🤖 Claude PR Metadata Generation

Status: ❌ Error
Job: View workflow run


⚠️ Generation Failed

The automated PR title and description generation encountered an error.

Next Steps:

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

You can manually set the PR title and description, or re-trigger by pushing a new commit.

@kristiehuang kristiehuang force-pushed the 03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding branch from 44ce913 to 0e9bf8f Compare March 2, 2026 21:19
@kristiehuang kristiehuang force-pushed the 03-02-feat_universal-router-sdk_v2.1.1_version_rename_abi_infrastructure branch from 7c7b54e to 371627e Compare March 2, 2026 21:24
@kristiehuang kristiehuang force-pushed the 03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding branch from 0e9bf8f to dc54071 Compare March 2, 2026 21:24
Copy link
Collaborator Author

kristiehuang commented Mar 2, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

const { BigNumber, utils } = require('ethers')
const { defaultAbiCoder } = require('ethers/lib/utils')

const v4sdk = require('@uniswap/v4-sdk')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

some temp v4-sdk URVersion mocking before the v4-sdk version is bumped up

@kristiehuang kristiehuang force-pushed the 03-02-feat_universal-router-sdk_v2.1.1_version_rename_abi_infrastructure branch from 371627e to c17b0fe Compare March 2, 2026 23:00
@kristiehuang kristiehuang force-pushed the 03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding branch from dc54071 to d90a9da Compare March 2, 2026 23:00
@kristiehuang kristiehuang force-pushed the 03-02-feat_universal-router-sdk_v2.1.1_version_rename_abi_infrastructure branch from c17b0fe to eabaa9a Compare March 2, 2026 23:15
@kristiehuang kristiehuang force-pushed the 03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding branch from d90a9da to e982e7c Compare March 2, 2026 23:15
```

## Per-Hop Slippage Protection (V4 Routes)
## Per-Hop Slippage Protection
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tbh the previous section on per-hop slippage protection was probably just claude-generated? I don't think this should live here in the README. it should live in the uniswap docs.

@kristiehuang kristiehuang force-pushed the 03-02-feat_univeresal-router-sdk_wire_up_per-hop_slippage_encoding branch from e982e7c to 6f78d04 Compare March 4, 2026 23:09
return i === sections.length - 1
}

const useV2_1_1 = options.urVersion === URVersion.V2_1_1

Choose a reason for hiding this comment

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

should this be >= URV2.1.1? what if a new UR contract is released

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