feat(universal-router-sdk): wire up per-hop slippage encoding#532
Conversation
🤖 Claude PR Metadata GenerationStatus: ❌ Error
|
44ce913 to
0e9bf8f
Compare
7c7b54e to
371627e
Compare
0e9bf8f to
dc54071
Compare
|
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.
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') |
There was a problem hiding this comment.
some temp v4-sdk URVersion mocking before the v4-sdk version is bumped up
371627e to
c17b0fe
Compare
dc54071 to
d90a9da
Compare
c17b0fe to
eabaa9a
Compare
d90a9da to
e982e7c
Compare
| ``` | ||
|
|
||
| ## Per-Hop Slippage Protection (V4 Routes) | ||
| ## Per-Hop Slippage Protection |
There was a problem hiding this comment.
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.
e982e7c to
6f78d04
Compare
| return i === sections.length - 1 | ||
| } | ||
|
|
||
| const useV2_1_1 = options.urVersion === URVersion.V2_1_1 |
There was a problem hiding this comment.
should this be >= URV2.1.1? what if a new UR contract is released

Description
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
maxHopSlippageparameter has been moved fromSwapOptionsto individual swaps, enabling granular slippage protection per route.Changes
sdks/universal-router-sdk/src/entities/actions/uniswap.tsmaxHopSlippagefromSwapOptionsinterfacemaxHopSlippage?: bigint[]to theSwapinterface to carry per-hop slippage from trade.swapsaddV2Swap: branches onurVersionto encode with/withoutmaxHopSlippagefor V2_SWAP_EXACT_IN and V2_SWAP_EXACT_OUT commandsaddV3Swap: branches onurVersionto encode with/withoutmaxHopSlippagefor V3_SWAP_EXACT_IN and V3_SWAP_EXACT_OUT commandsaddV4Swap: readsmaxHopSlippagefrom the swap object instead of optionsaddMixedSwap: trackshopOffsetto slice the flatmaxHopSlippagearray per protocol sectionmaxHopSlippagelength matchesroute.pools.lengthsdks/universal-router-sdk/README.mdmaxHopSlippageis specified on each route withinRouterTradesdks/universal-router-sdk/test/unit/perHopSlippage.test.ts(new)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:
maxHopSlippagehas been removed fromSwapOptions. Consumers must now specifymaxHopSlippageon individual routes within theRouterTradeconstructor.Migration: