@uniswap/universal-router-sdk 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,88 +39,6 @@ forge install
39
39
  yarn test:forge
40
40
  ```
41
41
 
42
- ## Per-Hop Slippage Protection
43
-
44
- Universal Router v2.1.1 adds granular slippage protection for multi-hop swaps across all protocol versions (V2, V3, V4, and mixed routes). In addition to the overall trade-level slippage check, the contract can verify that each individual pool hop doesn't exceed a maximum price limit.
45
-
46
- ### How It Works
47
-
48
- Per-hop slippage bounds live on each swap's route data (via `RouterTrade`). The `maxHopSlippage` array on each route maps 1:1 to the route's pools: `maxHopSlippage[i]` constrains `route.pools[i]`.
49
-
50
- To enable the V2.1.1 ABI encoding (which includes the `maxHopSlippage` parameter), set `urVersion: URVersion.V2_1_1` on your swap options.
51
-
52
- ```typescript
53
- import { SwapRouter } from '@uniswap/universal-router-sdk'
54
- import { Trade as RouterTrade } from '@uniswap/router-sdk'
55
- import { URVersion } from '@uniswap/v4-sdk'
56
- import { Percent, TradeType } from '@uniswap/sdk-core'
57
-
58
- // 1. Build a trade with per-hop slippage on each route
59
- const trade = new RouterTrade({
60
- v3Routes: [
61
- {
62
- routev3: myV3Route, // e.g. USDC → DAI → WETH
63
- inputAmount,
64
- outputAmount,
65
- maxHopSlippage: [
66
- // one entry per pool in the route
67
- BigInt('1010000000000000000'), // Hop 0: USDC→DAI, max price 1.01
68
- BigInt('2500000000000000000000'), // Hop 1: DAI→WETH, max price 2500
69
- ],
70
- },
71
- ],
72
- tradeType: TradeType.EXACT_INPUT,
73
- })
74
-
75
- // 2. Encode with V2.1.1 ABI
76
- const { calldata, value } = SwapRouter.swapCallParameters(trade, {
77
- slippageTolerance: new Percent(50, 10000), // 0.5% overall slippage
78
- recipient: '0x...',
79
- urVersion: URVersion.V2_1_1, // required for per-hop encoding
80
- })
81
- ```
82
-
83
- ### Price Calculation
84
-
85
- Slippage is expressed as a **price** with 18 decimals of precision:
86
-
87
- - `price = amountIn * 1e18 / amountOut`
88
-
89
- If the calculated price for hop `i` exceeds `maxHopSlippage[i]`, the transaction reverts.
90
-
91
- ### Mixed Routes
92
-
93
- For mixed routes that span multiple protocol versions (e.g. V3 pool → V4 pool → V2 pool), the SDK automatically slices the flat `maxHopSlippage` array by section. Each protocol section receives the corresponding slice of hop bounds:
94
-
95
- ```typescript
96
- const trade = new RouterTrade({
97
- mixedRoutes: [
98
- {
99
- mixedRoute: myMixedRoute, // V3 pool, V3 pool, V2 pool
100
- inputAmount,
101
- outputAmount,
102
- maxHopSlippage: [
103
- BigInt('1010000000000000000'), // Hop 0 (V3 section)
104
- BigInt('2500000000000000000000'), // Hop 1 (V3 section)
105
- BigInt('1005000000000000000'), // Hop 2 (V2 section)
106
- ],
107
- },
108
- ],
109
- tradeType: TradeType.EXACT_INPUT,
110
- })
111
- ```
112
-
113
- ### Benefits
114
-
115
- 1. **MEV Protection**: Prevents sandwich attacks on individual pool hops
116
- 2. **Route Quality**: Ensures each segment of a multi-hop route meets price expectations
117
- 3. **Granular Control**: Different slippage tolerances for different pairs (e.g. tighter bounds on stablecoin hops)
118
-
119
- ### Backward Compatibility
120
-
121
- - If `maxHopSlippage` is omitted or is an empty array, only the overall trade-level slippage is checked
122
- - If `urVersion` is not set (defaults to V2.0), commands use the standard ABI without `maxHopSlippage`
123
-
124
42
  ## Signed Routes (Universal Router v2.1)
125
43
 
126
44
  Universal Router v2.1 supports EIP712-signed route execution, enabling gasless transactions and intent-based trading.
@@ -289,9 +289,9 @@ class UniswapTrade {
289
289
  }
290
290
  exports.UniswapTrade = UniswapTrade;
291
291
  // encode a uniswap v2 swap
292
- function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
293
- if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
294
- throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
292
+ function addV2Swap(planner, { route, inputAmount, outputAmount, minHopPriceX36 }, tradeType, options, payerIsUser, routerMustCustody) {
293
+ if ((minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.length) && minHopPriceX36.length !== route.pools.length) {
294
+ throw new Error(`minHopPriceX36 length (${minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
295
295
  }
296
296
  const trade = new v2_sdk_1.Trade(route, tradeType == sdk_core_1.TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
297
297
  const useV2_1_1 = (0, constants_1.isAtLeastV2_1_1)(options.urVersion);
@@ -306,7 +306,7 @@ function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
306
306
  payerIsUser,
307
307
  ];
308
308
  if (useV2_1_1)
309
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
309
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
310
310
  planner.addCommand(routerCommands_1.CommandType.V2_SWAP_EXACT_IN, params, false, options.urVersion);
311
311
  }
312
312
  else if (tradeType == sdk_core_1.TradeType.EXACT_OUTPUT) {
@@ -318,14 +318,14 @@ function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
318
318
  payerIsUser,
319
319
  ];
320
320
  if (useV2_1_1)
321
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
321
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
322
322
  planner.addCommand(routerCommands_1.CommandType.V2_SWAP_EXACT_OUT, params, false, options.urVersion);
323
323
  }
324
324
  }
325
325
  // encode a uniswap v3 swap
326
- function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
327
- if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
328
- throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
326
+ function addV3Swap(planner, { route, inputAmount, outputAmount, minHopPriceX36 }, tradeType, options, payerIsUser, routerMustCustody) {
327
+ if ((minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.length) && minHopPriceX36.length !== route.pools.length) {
328
+ throw new Error(`minHopPriceX36 length (${minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
329
329
  }
330
330
  const trade = v3_sdk_1.Trade.createUncheckedTrade({
331
331
  route: route,
@@ -344,7 +344,7 @@ function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
344
344
  payerIsUser,
345
345
  ];
346
346
  if (useV2_1_1)
347
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
347
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
348
348
  planner.addCommand(routerCommands_1.CommandType.V3_SWAP_EXACT_IN, params, false, options.urVersion);
349
349
  }
350
350
  else if (tradeType == sdk_core_1.TradeType.EXACT_OUTPUT) {
@@ -356,14 +356,14 @@ function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
356
356
  payerIsUser,
357
357
  ];
358
358
  if (useV2_1_1)
359
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
359
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
360
360
  planner.addCommand(routerCommands_1.CommandType.V3_SWAP_EXACT_OUT, params, false, options.urVersion);
361
361
  }
362
362
  }
363
- function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
363
+ function addV4Swap(planner, { inputAmount, outputAmount, route, minHopPriceX36 }, tradeType, options, payerIsUser, routerMustCustody) {
364
364
  var _a, _b;
365
- if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
366
- throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
365
+ if ((minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.length) && minHopPriceX36.length !== route.pools.length) {
366
+ throw new Error(`minHopPriceX36 length (${minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
367
367
  }
368
368
  // create a deep copy of pools since v4Planner encoding tampers with array
369
369
  const pools = route.pools.map((p) => p);
@@ -375,7 +375,7 @@ function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }
375
375
  tradeType,
376
376
  });
377
377
  const slippageToleranceOnSwap = routerMustCustody && tradeType == sdk_core_1.TradeType.EXACT_INPUT ? undefined : options.slippageTolerance;
378
- const perHopSlippage = (_a = maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.map((s) => ethers_1.BigNumber.from(s))) !== null && _a !== void 0 ? _a : [];
378
+ const perHopSlippage = (_a = minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.map((s) => ethers_1.BigNumber.from(s))) !== null && _a !== void 0 ? _a : [];
379
379
  const v4Planner = new v4_sdk_1.V4Planner();
380
380
  v4Planner.addTrade(trade, slippageToleranceOnSwap, perHopSlippage, toURVersion(options.urVersion));
381
381
  v4Planner.addSettle(trade.route.pathInput, payerIsUser);
@@ -402,8 +402,8 @@ function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }
402
402
  function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMustCustody) {
403
403
  var _a, _b, _c, _d;
404
404
  const route = swap.route;
405
- if (((_a = swap.maxHopSlippage) === null || _a === void 0 ? void 0 : _a.length) && swap.maxHopSlippage.length !== route.pools.length) {
406
- throw new Error(`maxHopSlippage length (${swap.maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
405
+ if (((_a = swap.minHopPriceX36) === null || _a === void 0 ? void 0 : _a.length) && swap.minHopPriceX36.length !== route.pools.length) {
406
+ throw new Error(`minHopPriceX36 length (${swap.minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
407
407
  }
408
408
  const inputAmount = swap.inputAmount;
409
409
  const outputAmount = swap.outputAmount;
@@ -447,8 +447,8 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
447
447
  const routePool = section[0];
448
448
  const outputToken = (0, router_sdk_1.getOutputOfPools)(section, inputToken);
449
449
  const subRoute = new router_sdk_1.MixedRoute(new router_sdk_1.MixedRouteSDK([...section], inputToken, outputToken));
450
- // Slice this section's portion of maxHopSlippage from the flat array
451
- const sectionHopSlippage = (_c = swap.maxHopSlippage) === null || _c === void 0 ? void 0 : _c.slice(hopOffset, hopOffset + section.length);
450
+ // Slice this section's portion of minHopPriceX36 from the flat array
451
+ const sectionHopSlippage = (_c = swap.minHopPriceX36) === null || _c === void 0 ? void 0 : _c.slice(hopOffset, hopOffset + section.length);
452
452
  let nextInputToken;
453
453
  let swapRecipient;
454
454
  if (isLastSectionInRoute(i)) {
@@ -470,7 +470,7 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
470
470
  {
471
471
  currencyIn: inputToken.isNative ? constants_1.ETH_ADDRESS : inputToken.address,
472
472
  path: (0, v4_sdk_1.encodeRouteToPath)(v4SubRoute),
473
- maxHopSlippage: v4SectionSlippage,
473
+ minHopPriceX36: v4SectionSlippage,
474
474
  amountIn: 0,
475
475
  amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut,
476
476
  },
@@ -221,7 +221,7 @@ exports.COMMAND_DEFINITION = {
221
221
  ],
222
222
  },
223
223
  };
224
- // V2.1.1 ABI definitions for V2/V3 swap commands (extended with maxHopSlippage)
224
+ // V2.1.1 ABI definitions for V2/V3 swap commands (extended with minHopPriceX36)
225
225
  exports.V2V3_SWAP_COMMANDS_V2_1_1 = {
226
226
  [CommandType.V3_SWAP_EXACT_IN]: {
227
227
  parser: Parser.Abi,
@@ -231,7 +231,7 @@ exports.V2V3_SWAP_COMMANDS_V2_1_1 = {
231
231
  { name: 'amountOutMin', type: 'uint256' },
232
232
  { name: 'path', subparser: Subparser.V3PathExactIn, type: 'bytes' },
233
233
  { name: 'payerIsUser', type: 'bool' },
234
- { name: 'maxHopSlippage', type: 'uint256[]' },
234
+ { name: 'minHopPriceX36', type: 'uint256[]' },
235
235
  ],
236
236
  },
237
237
  [CommandType.V3_SWAP_EXACT_OUT]: {
@@ -242,7 +242,7 @@ exports.V2V3_SWAP_COMMANDS_V2_1_1 = {
242
242
  { name: 'amountInMax', type: 'uint256' },
243
243
  { name: 'path', subparser: Subparser.V3PathExactOut, type: 'bytes' },
244
244
  { name: 'payerIsUser', type: 'bool' },
245
- { name: 'maxHopSlippage', type: 'uint256[]' },
245
+ { name: 'minHopPriceX36', type: 'uint256[]' },
246
246
  ],
247
247
  },
248
248
  [CommandType.V2_SWAP_EXACT_IN]: {
@@ -253,7 +253,7 @@ exports.V2V3_SWAP_COMMANDS_V2_1_1 = {
253
253
  { name: 'amountOutMin', type: 'uint256' },
254
254
  { name: 'path', type: 'address[]' },
255
255
  { name: 'payerIsUser', type: 'bool' },
256
- { name: 'maxHopSlippage', type: 'uint256[]' },
256
+ { name: 'minHopPriceX36', type: 'uint256[]' },
257
257
  ],
258
258
  },
259
259
  [CommandType.V2_SWAP_EXACT_OUT]: {
@@ -264,7 +264,7 @@ exports.V2V3_SWAP_COMMANDS_V2_1_1 = {
264
264
  { name: 'amountInMax', type: 'uint256' },
265
265
  { name: 'path', type: 'address[]' },
266
266
  { name: 'payerIsUser', type: 'bool' },
267
- { name: 'maxHopSlippage', type: 'uint256[]' },
267
+ { name: 'minHopPriceX36', type: 'uint256[]' },
268
268
  ],
269
269
  },
270
270
  };
@@ -285,9 +285,9 @@ export class UniswapTrade {
285
285
  }
286
286
  }
287
287
  // encode a uniswap v2 swap
288
- function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
289
- if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
290
- throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
288
+ function addV2Swap(planner, { route, inputAmount, outputAmount, minHopPriceX36 }, tradeType, options, payerIsUser, routerMustCustody) {
289
+ if ((minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.length) && minHopPriceX36.length !== route.pools.length) {
290
+ throw new Error(`minHopPriceX36 length (${minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
291
291
  }
292
292
  const trade = new V2Trade(route, tradeType == TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
293
293
  const useV2_1_1 = isAtLeastV2_1_1(options.urVersion);
@@ -302,7 +302,7 @@ function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
302
302
  payerIsUser,
303
303
  ];
304
304
  if (useV2_1_1)
305
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
305
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
306
306
  planner.addCommand(CommandType.V2_SWAP_EXACT_IN, params, false, options.urVersion);
307
307
  }
308
308
  else if (tradeType == TradeType.EXACT_OUTPUT) {
@@ -314,14 +314,14 @@ function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
314
314
  payerIsUser,
315
315
  ];
316
316
  if (useV2_1_1)
317
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
317
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
318
318
  planner.addCommand(CommandType.V2_SWAP_EXACT_OUT, params, false, options.urVersion);
319
319
  }
320
320
  }
321
321
  // encode a uniswap v3 swap
322
- function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
323
- if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
324
- throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
322
+ function addV3Swap(planner, { route, inputAmount, outputAmount, minHopPriceX36 }, tradeType, options, payerIsUser, routerMustCustody) {
323
+ if ((minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.length) && minHopPriceX36.length !== route.pools.length) {
324
+ throw new Error(`minHopPriceX36 length (${minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
325
325
  }
326
326
  const trade = V3Trade.createUncheckedTrade({
327
327
  route: route,
@@ -340,7 +340,7 @@ function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
340
340
  payerIsUser,
341
341
  ];
342
342
  if (useV2_1_1)
343
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
343
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
344
344
  planner.addCommand(CommandType.V3_SWAP_EXACT_IN, params, false, options.urVersion);
345
345
  }
346
346
  else if (tradeType == TradeType.EXACT_OUTPUT) {
@@ -352,14 +352,14 @@ function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }
352
352
  payerIsUser,
353
353
  ];
354
354
  if (useV2_1_1)
355
- params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
355
+ params.push(minHopPriceX36 !== null && minHopPriceX36 !== void 0 ? minHopPriceX36 : []);
356
356
  planner.addCommand(CommandType.V3_SWAP_EXACT_OUT, params, false, options.urVersion);
357
357
  }
358
358
  }
359
- function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
359
+ function addV4Swap(planner, { inputAmount, outputAmount, route, minHopPriceX36 }, tradeType, options, payerIsUser, routerMustCustody) {
360
360
  var _a, _b;
361
- if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
362
- throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
361
+ if ((minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.length) && minHopPriceX36.length !== route.pools.length) {
362
+ throw new Error(`minHopPriceX36 length (${minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
363
363
  }
364
364
  // create a deep copy of pools since v4Planner encoding tampers with array
365
365
  const pools = route.pools.map((p) => p);
@@ -371,7 +371,7 @@ function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }
371
371
  tradeType,
372
372
  });
373
373
  const slippageToleranceOnSwap = routerMustCustody && tradeType == TradeType.EXACT_INPUT ? undefined : options.slippageTolerance;
374
- const perHopSlippage = (_a = maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.map((s) => BigNumber.from(s))) !== null && _a !== void 0 ? _a : [];
374
+ const perHopSlippage = (_a = minHopPriceX36 === null || minHopPriceX36 === void 0 ? void 0 : minHopPriceX36.map((s) => BigNumber.from(s))) !== null && _a !== void 0 ? _a : [];
375
375
  const v4Planner = new V4Planner();
376
376
  v4Planner.addTrade(trade, slippageToleranceOnSwap, perHopSlippage, toURVersion(options.urVersion));
377
377
  v4Planner.addSettle(trade.route.pathInput, payerIsUser);
@@ -398,8 +398,8 @@ function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }
398
398
  function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMustCustody) {
399
399
  var _a, _b, _c, _d;
400
400
  const route = swap.route;
401
- if (((_a = swap.maxHopSlippage) === null || _a === void 0 ? void 0 : _a.length) && swap.maxHopSlippage.length !== route.pools.length) {
402
- throw new Error(`maxHopSlippage length (${swap.maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
401
+ if (((_a = swap.minHopPriceX36) === null || _a === void 0 ? void 0 : _a.length) && swap.minHopPriceX36.length !== route.pools.length) {
402
+ throw new Error(`minHopPriceX36 length (${swap.minHopPriceX36.length}) must equal route.pools.length (${route.pools.length})`);
403
403
  }
404
404
  const inputAmount = swap.inputAmount;
405
405
  const outputAmount = swap.outputAmount;
@@ -443,8 +443,8 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
443
443
  const routePool = section[0];
444
444
  const outputToken = getOutputOfPools(section, inputToken);
445
445
  const subRoute = new MixedRoute(new MixedRouteSDK([...section], inputToken, outputToken));
446
- // Slice this section's portion of maxHopSlippage from the flat array
447
- const sectionHopSlippage = (_c = swap.maxHopSlippage) === null || _c === void 0 ? void 0 : _c.slice(hopOffset, hopOffset + section.length);
446
+ // Slice this section's portion of minHopPriceX36 from the flat array
447
+ const sectionHopSlippage = (_c = swap.minHopPriceX36) === null || _c === void 0 ? void 0 : _c.slice(hopOffset, hopOffset + section.length);
448
448
  let nextInputToken;
449
449
  let swapRecipient;
450
450
  if (isLastSectionInRoute(i)) {
@@ -466,7 +466,7 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
466
466
  {
467
467
  currencyIn: inputToken.isNative ? ETH_ADDRESS : inputToken.address,
468
468
  path: encodeV4RouteToPath(v4SubRoute),
469
- maxHopSlippage: v4SectionSlippage,
469
+ minHopPriceX36: v4SectionSlippage,
470
470
  amountIn: 0,
471
471
  amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut,
472
472
  },
@@ -218,7 +218,7 @@ export const COMMAND_DEFINITION = {
218
218
  ],
219
219
  },
220
220
  };
221
- // V2.1.1 ABI definitions for V2/V3 swap commands (extended with maxHopSlippage)
221
+ // V2.1.1 ABI definitions for V2/V3 swap commands (extended with minHopPriceX36)
222
222
  export const V2V3_SWAP_COMMANDS_V2_1_1 = {
223
223
  [CommandType.V3_SWAP_EXACT_IN]: {
224
224
  parser: Parser.Abi,
@@ -228,7 +228,7 @@ export const V2V3_SWAP_COMMANDS_V2_1_1 = {
228
228
  { name: 'amountOutMin', type: 'uint256' },
229
229
  { name: 'path', subparser: Subparser.V3PathExactIn, type: 'bytes' },
230
230
  { name: 'payerIsUser', type: 'bool' },
231
- { name: 'maxHopSlippage', type: 'uint256[]' },
231
+ { name: 'minHopPriceX36', type: 'uint256[]' },
232
232
  ],
233
233
  },
234
234
  [CommandType.V3_SWAP_EXACT_OUT]: {
@@ -239,7 +239,7 @@ export const V2V3_SWAP_COMMANDS_V2_1_1 = {
239
239
  { name: 'amountInMax', type: 'uint256' },
240
240
  { name: 'path', subparser: Subparser.V3PathExactOut, type: 'bytes' },
241
241
  { name: 'payerIsUser', type: 'bool' },
242
- { name: 'maxHopSlippage', type: 'uint256[]' },
242
+ { name: 'minHopPriceX36', type: 'uint256[]' },
243
243
  ],
244
244
  },
245
245
  [CommandType.V2_SWAP_EXACT_IN]: {
@@ -250,7 +250,7 @@ export const V2V3_SWAP_COMMANDS_V2_1_1 = {
250
250
  { name: 'amountOutMin', type: 'uint256' },
251
251
  { name: 'path', type: 'address[]' },
252
252
  { name: 'payerIsUser', type: 'bool' },
253
- { name: 'maxHopSlippage', type: 'uint256[]' },
253
+ { name: 'minHopPriceX36', type: 'uint256[]' },
254
254
  ],
255
255
  },
256
256
  [CommandType.V2_SWAP_EXACT_OUT]: {
@@ -261,7 +261,7 @@ export const V2V3_SWAP_COMMANDS_V2_1_1 = {
261
261
  { name: 'amountInMax', type: 'uint256' },
262
262
  { name: 'path', type: 'address[]' },
263
263
  { name: 'payerIsUser', type: 'bool' },
264
- { name: 'maxHopSlippage', type: 'uint256[]' },
264
+ { name: 'minHopPriceX36', type: 'uint256[]' },
265
265
  ],
266
266
  },
267
267
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniswap/universal-router-sdk",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "sdk for integrating with the Universal Router contracts",
5
5
  "repository": "https://github.com/Uniswap/sdks.git",
6
6
  "keywords": [
@@ -44,14 +44,14 @@
44
44
  "@ethersproject/abstract-signer": "^5.7.0",
45
45
  "@openzeppelin/contracts": "4.7.0",
46
46
  "@uniswap/permit2-sdk": "^1.4.0",
47
- "@uniswap/router-sdk": "^2.9.0",
47
+ "@uniswap/router-sdk": "^2.10.0",
48
48
  "@uniswap/sdk-core": "^7.13.0",
49
49
  "@uniswap/universal-router": "2.1.0",
50
50
  "@uniswap/v2-core": "^1.0.1",
51
51
  "@uniswap/v2-sdk": "^4.20.0",
52
52
  "@uniswap/v3-core": "1.0.0",
53
53
  "@uniswap/v3-sdk": "^3.30.0",
54
- "@uniswap/v4-sdk": "^2.0.0",
54
+ "@uniswap/v4-sdk": "^2.1.0",
55
55
  "bignumber.js": "^9.0.2",
56
56
  "ethers": "^5.7.0",
57
57
  "jsbi": "^3.1.4",