@uniswap/universal-router-sdk 1.5.8 → 1.6.1

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { SwapRouter } from './swapRouter';
2
2
  export * from './entities';
3
+ export { RoutePlanner, CommandType } from './utils/routerCommands';
3
4
  export { UNIVERSAL_ROUTER_ADDRESS, UNIVERSAL_ROUTER_CREATION_BLOCK, PERMIT2_ADDRESS, ROUTER_AS_RECIPIENT, WETH_ADDRESS, } from './utils/constants';
@@ -104,12 +104,6 @@ var NFTTrade = function NFTTrade(market, orders) {
104
104
  })(exports.TokenType || (exports.TokenType = {}));
105
105
 
106
106
  var _ABI_DEFINITION;
107
- /**
108
- * CommandTypes
109
- * @description Flags that modify a command's execution
110
- * @enum {number}
111
- */
112
- var CommandType;
113
107
  (function (CommandType) {
114
108
  CommandType[CommandType["V3_SWAP_EXACT_IN"] = 0] = "V3_SWAP_EXACT_IN";
115
109
  CommandType[CommandType["V3_SWAP_EXACT_OUT"] = 1] = "V3_SWAP_EXACT_OUT";
@@ -144,14 +138,14 @@ var CommandType;
144
138
  CommandType[CommandType["SEAPORT_V1_4"] = 32] = "SEAPORT_V1_4";
145
139
  CommandType[CommandType["EXECUTE_SUB_PLAN"] = 33] = "EXECUTE_SUB_PLAN";
146
140
  CommandType[CommandType["APPROVE_ERC20"] = 34] = "APPROVE_ERC20";
147
- })(CommandType || (CommandType = {}));
141
+ })(exports.CommandType || (exports.CommandType = {}));
148
142
  var ALLOW_REVERT_FLAG = 0x80;
149
- var REVERTIBLE_COMMANDS = /*#__PURE__*/new Set([CommandType.SEAPORT_V1_5, CommandType.SEAPORT_V1_4, CommandType.NFTX, CommandType.LOOKS_RARE_V2, CommandType.X2Y2_721, CommandType.X2Y2_1155, CommandType.FOUNDATION, CommandType.SUDOSWAP, CommandType.NFT20, CommandType.EXECUTE_SUB_PLAN, CommandType.CRYPTOPUNKS, CommandType.ELEMENT_MARKET]);
143
+ var REVERTIBLE_COMMANDS = /*#__PURE__*/new Set([exports.CommandType.SEAPORT_V1_5, exports.CommandType.SEAPORT_V1_4, exports.CommandType.NFTX, exports.CommandType.LOOKS_RARE_V2, exports.CommandType.X2Y2_721, exports.CommandType.X2Y2_1155, exports.CommandType.FOUNDATION, exports.CommandType.SUDOSWAP, exports.CommandType.NFT20, exports.CommandType.EXECUTE_SUB_PLAN, exports.CommandType.CRYPTOPUNKS, exports.CommandType.ELEMENT_MARKET]);
150
144
  var PERMIT_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)';
151
145
  var PERMIT_BATCH_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)';
152
146
  var PERMIT2_TRANSFER_FROM_STRUCT = '(address from,address to,uint160 amount,address token)';
153
147
  var PERMIT2_TRANSFER_FROM_BATCH_STRUCT = PERMIT2_TRANSFER_FROM_STRUCT + '[]';
154
- var ABI_DEFINITION = (_ABI_DEFINITION = {}, _ABI_DEFINITION[CommandType.EXECUTE_SUB_PLAN] = ['bytes', 'bytes[]'], _ABI_DEFINITION[CommandType.PERMIT2_PERMIT] = [PERMIT_STRUCT, 'bytes'], _ABI_DEFINITION[CommandType.PERMIT2_PERMIT_BATCH] = [PERMIT_BATCH_STRUCT, 'bytes'], _ABI_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM] = ['address', 'address', 'uint160'], _ABI_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM_BATCH] = [PERMIT2_TRANSFER_FROM_BATCH_STRUCT], _ABI_DEFINITION[CommandType.V3_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[CommandType.V3_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[CommandType.V2_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[CommandType.V2_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[CommandType.WRAP_ETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.UNWRAP_WETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP_ERC721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP_ERC1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.TRANSFER] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.PAY_PORTION] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.BALANCE_CHECK_ERC20] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.OWNER_CHECK_721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.OWNER_CHECK_1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.APPROVE_ERC20] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.SEAPORT_V1_5] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.SEAPORT_V1_4] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.NFTX] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.LOOKS_RARE_V2] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.X2Y2_721] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.X2Y2_1155] = ['uint256', 'bytes', 'address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.FOUNDATION] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SUDOSWAP] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.NFT20] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.CRYPTOPUNKS] = ['uint256', 'address', 'uint256'], _ABI_DEFINITION[CommandType.ELEMENT_MARKET] = ['uint256', 'bytes'], _ABI_DEFINITION);
148
+ var ABI_DEFINITION = (_ABI_DEFINITION = {}, _ABI_DEFINITION[exports.CommandType.EXECUTE_SUB_PLAN] = ['bytes', 'bytes[]'], _ABI_DEFINITION[exports.CommandType.PERMIT2_PERMIT] = [PERMIT_STRUCT, 'bytes'], _ABI_DEFINITION[exports.CommandType.PERMIT2_PERMIT_BATCH] = [PERMIT_BATCH_STRUCT, 'bytes'], _ABI_DEFINITION[exports.CommandType.PERMIT2_TRANSFER_FROM] = ['address', 'address', 'uint160'], _ABI_DEFINITION[exports.CommandType.PERMIT2_TRANSFER_FROM_BATCH] = [PERMIT2_TRANSFER_FROM_BATCH_STRUCT], _ABI_DEFINITION[exports.CommandType.V3_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[exports.CommandType.V3_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[exports.CommandType.V2_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[exports.CommandType.V2_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[exports.CommandType.WRAP_ETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.UNWRAP_WETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SWEEP] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SWEEP_ERC721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SWEEP_ERC1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[exports.CommandType.TRANSFER] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.PAY_PORTION] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.BALANCE_CHECK_ERC20] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.OWNER_CHECK_721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.OWNER_CHECK_1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[exports.CommandType.APPROVE_ERC20] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SEAPORT_V1_5] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.SEAPORT_V1_4] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.NFTX] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.LOOKS_RARE_V2] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.X2Y2_721] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.X2Y2_1155] = ['uint256', 'bytes', 'address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[exports.CommandType.FOUNDATION] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SUDOSWAP] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.NFT20] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.CRYPTOPUNKS] = ['uint256', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.ELEMENT_MARKET] = ['uint256', 'bytes'], _ABI_DEFINITION);
155
149
  var RoutePlanner = /*#__PURE__*/function () {
156
150
  function RoutePlanner() {
157
151
  this.commands = '0x';
@@ -159,7 +153,7 @@ var RoutePlanner = /*#__PURE__*/function () {
159
153
  }
160
154
  var _proto = RoutePlanner.prototype;
161
155
  _proto.addSubPlan = function addSubPlan(subplan) {
162
- this.addCommand(CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
156
+ this.addCommand(exports.CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
163
157
  };
164
158
  _proto.addCommand = function addCommand(type, parameters, allowRevert) {
165
159
  if (allowRevert === void 0) {
@@ -200,53 +194,53 @@ var CHAIN_CONFIGS = (_CHAIN_CONFIGS = {}, _CHAIN_CONFIGS[1] = {
200
194
  weth: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
201
195
  creationBlock: 3543575
202
196
  }, _CHAIN_CONFIGS[137] = {
203
- router: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
197
+ router: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
204
198
  weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
205
- creationBlock: 46866777
199
+ creationBlock: 52210153
206
200
  }, _CHAIN_CONFIGS[80001] = {
207
201
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
208
202
  weth: '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889',
209
203
  creationBlock: 35176052
210
204
  }, _CHAIN_CONFIGS[10] = {
211
- router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
205
+ router: '0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8',
212
206
  weth: '0x4200000000000000000000000000000000000006',
213
- creationBlock: 108825869
207
+ creationBlock: 114702266
214
208
  }, _CHAIN_CONFIGS[420] = {
215
209
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
216
210
  weth: '0x4200000000000000000000000000000000000006',
217
211
  creationBlock: 8887728
218
212
  }, _CHAIN_CONFIGS[42161] = {
219
- router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
213
+ router: '0x5E325eDA8064b456f4781070C0738d849c824258',
220
214
  weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
221
- creationBlock: 125861718
215
+ creationBlock: 169472836
222
216
  }, _CHAIN_CONFIGS[421613] = {
223
217
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
224
218
  weth: '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
225
219
  creationBlock: 18815277
226
220
  }, _CHAIN_CONFIGS[42220] = {
227
- router: '0x88a3ED7F21A3fCF6adb86b6F878C5B7a02D20e9b',
221
+ router: '0x643770e279d5d0733f21d6dc03a8efbabf3255b4',
228
222
  weth: WETH_NOT_SUPPORTED_ON_CHAIN,
229
- creationBlock: 21116361
223
+ creationBlock: 21407637
230
224
  }, _CHAIN_CONFIGS[44787] = {
231
225
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
232
226
  weth: WETH_NOT_SUPPORTED_ON_CHAIN,
233
227
  creationBlock: 17566658
234
228
  }, _CHAIN_CONFIGS[56] = {
235
- router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
229
+ router: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
236
230
  weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
237
- creationBlock: 31254967
231
+ creationBlock: 35160263
238
232
  }, _CHAIN_CONFIGS[43114] = {
239
- router: '0x82635AF6146972cD6601161c4472ffe97237D292',
233
+ router: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
240
234
  weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
241
- creationBlock: 34491144
235
+ creationBlock: 40237257
242
236
  }, _CHAIN_CONFIGS[84531] = {
243
237
  router: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
244
238
  weth: '0x4200000000000000000000000000000000000006',
245
239
  creationBlock: 6915289
246
240
  }, _CHAIN_CONFIGS[8453] = {
247
- router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
241
+ router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
248
242
  weth: '0x4200000000000000000000000000000000000006',
249
- creationBlock: 3229053
243
+ creationBlock: 9107268
250
244
  }, _CHAIN_CONFIGS);
251
245
  var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(chainId) {
252
246
  if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
@@ -291,7 +285,7 @@ var UniswapTrade = /*#__PURE__*/function () {
291
285
  // If the input currency is the native currency, we need to wrap it with the router as the recipient
292
286
  if (this.trade.inputAmount.currency.isNative) {
293
287
  // TODO: optimize if only one v2 pool we can directly send this to the pool
294
- planner.addCommand(CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
288
+ planner.addCommand(exports.CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
295
289
  // since WETH is now owned by the router, the router pays for inputs
296
290
  payerIsUser = false;
297
291
  }
@@ -328,7 +322,7 @@ var UniswapTrade = /*#__PURE__*/function () {
328
322
  // In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
329
323
  if (!!this.options.fee) {
330
324
  var feeBips = encodeFeeBips(this.options.fee.fee);
331
- planner.addCommand(CommandType.PAY_PORTION, [this.trade.outputAmount.currency.wrapped.address, this.options.fee.recipient, feeBips]);
325
+ planner.addCommand(exports.CommandType.PAY_PORTION, [this.trade.outputAmount.currency.wrapped.address, this.options.fee.recipient, feeBips]);
332
326
  // If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
333
327
  // Otherwise we continue as expected with the trade's normal expected output
334
328
  if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
@@ -340,7 +334,7 @@ var UniswapTrade = /*#__PURE__*/function () {
340
334
  if (!!this.options.flatFee) {
341
335
  var feeAmount = this.options.flatFee.amount;
342
336
  if (minimumAmountOut.lt(feeAmount)) throw new Error('Flat fee amount greater than minimumAmountOut');
343
- planner.addCommand(CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
337
+ planner.addCommand(exports.CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
344
338
  // If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
345
339
  // Otherwise we continue as expected with the trade's normal expected output
346
340
  if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
@@ -350,15 +344,15 @@ var UniswapTrade = /*#__PURE__*/function () {
350
344
  // The remaining tokens that need to be sent to the user after the fee is taken will be caught
351
345
  // by this if-else clause.
352
346
  if (outputIsNative) {
353
- planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
347
+ planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
354
348
  } else {
355
- planner.addCommand(CommandType.SWEEP, [this.trade.outputAmount.currency.wrapped.address, this.options.recipient, minimumAmountOut]);
349
+ planner.addCommand(exports.CommandType.SWEEP, [this.trade.outputAmount.currency.wrapped.address, this.options.recipient, minimumAmountOut]);
356
350
  }
357
351
  }
358
352
  if (inputIsNative && (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade))) {
359
353
  // for exactOutput swaps that take native currency as input
360
354
  // we need to send back the change to the user
361
- planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
355
+ planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
362
356
  }
363
357
  };
364
358
  return UniswapTrade;
@@ -370,13 +364,13 @@ function addV2Swap(planner, _ref, tradeType, options, payerIsUser, routerMustCus
370
364
  outputAmount = _ref.outputAmount;
371
365
  var trade = new v2Sdk.Trade(route, tradeType == sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
372
366
  if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
373
- planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [
367
+ planner.addCommand(exports.CommandType.V2_SWAP_EXACT_IN, [
374
368
  // if native, we have to unwrap so keep in the router for now
375
369
  routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), route.path.map(function (pool) {
376
370
  return pool.address;
377
371
  }), payerIsUser]);
378
372
  } else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
379
- planner.addCommand(CommandType.V2_SWAP_EXACT_OUT, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), route.path.map(function (pool) {
373
+ planner.addCommand(exports.CommandType.V2_SWAP_EXACT_OUT, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), route.path.map(function (pool) {
380
374
  return pool.address;
381
375
  }), payerIsUser]);
382
376
  }
@@ -394,9 +388,9 @@ function addV3Swap(planner, _ref2, tradeType, options, payerIsUser, routerMustCu
394
388
  });
395
389
  var path = v3Sdk.encodeRouteToPath(route, trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT);
396
390
  if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
397
- planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
391
+ planner.addCommand(exports.CommandType.V3_SWAP_EXACT_IN, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
398
392
  } else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
399
- planner.addCommand(CommandType.V3_SWAP_EXACT_OUT, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
393
+ planner.addCommand(exports.CommandType.V3_SWAP_EXACT_OUT, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
400
394
  }
401
395
  }
402
396
  // encode a mixed route swap, i.e. including both v2 and v3 pools
@@ -446,12 +440,12 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
446
440
  };
447
441
  if (mixedRouteIsAllV3(newRoute)) {
448
442
  var path = routerSdk.encodeMixedRouteToPath(newRoute);
449
- planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [
443
+ planner.addCommand(exports.CommandType.V3_SWAP_EXACT_IN, [
450
444
  // if not last section: send tokens directly to the first v2 pair of the next section
451
445
  // note: because of the partitioning function we can be sure that the next section is v2
452
446
  isLastSectionInRoute(i) ? tradeRecipient : sections[i + 1][0].liquidityToken.address, i == 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, path, payerIsUser && i === 0]);
453
447
  } else {
454
- planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [isLastSectionInRoute(i) ? tradeRecipient : ROUTER_AS_RECIPIENT, i === 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (pool) {
448
+ planner.addCommand(exports.CommandType.V2_SWAP_EXACT_IN, [isLastSectionInRoute(i) ? tradeRecipient : ROUTER_AS_RECIPIENT, i === 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (pool) {
455
449
  return pool.address;
456
450
  }), payerIsUser && i === 0]);
457
451
  }
@@ -475,7 +469,7 @@ function encodePermit(planner, permit2) {
475
469
  // sanitizes signature to cover edge cases of malformed EIP-2098 sigs and v used as recovery id
476
470
  signature = ethers.ethers.utils.joinSignature(ethers.ethers.utils.splitSignature(permit2.signature));
477
471
  }
478
- planner.addCommand(CommandType.PERMIT2_PERMIT, [permit2, signature]);
472
+ planner.addCommand(exports.CommandType.PERMIT2_PERMIT, [permit2, signature]);
479
473
  }
480
474
  // Handles the encoding of commands needed to gather input tokens for a trade
481
475
  // Approval: The router approving another address to take tokens.
@@ -489,14 +483,14 @@ function encodeInputTokenOptions(planner, options) {
489
483
  if (!!options.permit2TransferFrom && !!options.permit2Permit) !(options.permit2TransferFrom.token === options.permit2Permit.details.token) ? invariant(false, "inconsistent token") : void 0;
490
484
  // if an options.approval is required, add it
491
485
  if (!!options.approval) {
492
- planner.addCommand(CommandType.APPROVE_ERC20, [options.approval.token, mapApprovalProtocol(options.approval.protocol)]);
486
+ planner.addCommand(exports.CommandType.APPROVE_ERC20, [options.approval.token, mapApprovalProtocol(options.approval.protocol)]);
493
487
  }
494
488
  // if this order has a options.permit2Permit, encode it
495
489
  if (!!options.permit2Permit) {
496
490
  encodePermit(planner, options.permit2Permit);
497
491
  }
498
492
  if (!!options.permit2TransferFrom) {
499
- planner.addCommand(CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
493
+ planner.addCommand(exports.CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
500
494
  }
501
495
  }
502
496
  function mapApprovalProtocol(protocolAddress) {
@@ -601,7 +595,7 @@ var SwapRouter = /*#__PURE__*/function () {
601
595
  // or NFT trades with potential slippage (i.e. sudo).
602
596
  // Note: NFTXV2 sends excess ETH to the caller (router), not the specified recipient
603
597
  nftInputTokens.forEach(function (inputToken) {
604
- planner.addCommand(CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
598
+ planner.addCommand(exports.CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
605
599
  });
606
600
  return SwapRouter.encodePlan(planner, transactionValue, config);
607
601
  }
@@ -625,7 +619,7 @@ var SwapRouter = /*#__PURE__*/function () {
625
619
  });
626
620
  totalPrice = totalPrice.add(trade.getTotalPrice());
627
621
  }
628
- planner.addCommand(CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
622
+ planner.addCommand(exports.CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
629
623
  return SwapRouter.encodePlan(planner, totalPrice, config);
630
624
  }
631
625
  /**
@@ -684,7 +678,7 @@ var CryptopunkTrade = /*#__PURE__*/function (_NFTTrade) {
684
678
  _proto.encode = function encode(planner, config) {
685
679
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
686
680
  var item = _step.value;
687
- planner.addCommand(CommandType.CRYPTOPUNKS, [item.tokenId, item.recipient, item.value], config.allowRevert);
681
+ planner.addCommand(exports.CommandType.CRYPTOPUNKS, [item.tokenId, item.recipient, item.value], config.allowRevert);
688
682
  }
689
683
  };
690
684
  _proto.getBuyItems = function getBuyItems() {
@@ -2343,7 +2337,7 @@ var FoundationTrade = /*#__PURE__*/function (_NFTTrade) {
2343
2337
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
2344
2338
  var item = _step.value;
2345
2339
  var calldata = FoundationTrade.INTERFACE.encodeFunctionData('buyV2', [item.tokenAddress, item.tokenId, item.price, item.referrer]);
2346
- planner.addCommand(CommandType.FOUNDATION, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
2340
+ planner.addCommand(exports.CommandType.FOUNDATION, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
2347
2341
  }
2348
2342
  };
2349
2343
  _proto.getBuyItems = function getBuyItems() {
@@ -4389,7 +4383,7 @@ var LooksRareV2Trade = /*#__PURE__*/function (_NFTTrade) {
4389
4383
  } else {
4390
4384
  calldata = LooksRareV2Trade.INTERFACE.encodeFunctionData('executeMultipleTakerBids', [takerBids, makerOrders, makerSignatures, merkleTrees, ZERO_ADDRESS, false]);
4391
4385
  }
4392
- planner.addCommand(CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
4386
+ planner.addCommand(exports.CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
4393
4387
  };
4394
4388
  _proto.getBuyItems = function getBuyItems() {
4395
4389
  var buyItems = [];
@@ -4717,7 +4711,7 @@ var NFT20Trade = /*#__PURE__*/function (_NFTTrade) {
4717
4711
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
4718
4712
  var order = _step.value;
4719
4713
  var calldata = NFT20Trade.INTERFACE.encodeFunctionData('ethForNft', [order.tokenAddress, order.tokenIds, order.tokenAmounts, order.recipient, order.fee, order.isV3]);
4720
- planner.addCommand(CommandType.NFT20, [order.value, calldata], config.allowRevert);
4714
+ planner.addCommand(exports.CommandType.NFT20, [order.value, calldata], config.allowRevert);
4721
4715
  }
4722
4716
  };
4723
4717
  _proto.getBuyItems = function getBuyItems() {
@@ -5378,7 +5372,7 @@ var NFTXTrade = /*#__PURE__*/function (_NFTTrade) {
5378
5372
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
5379
5373
  var order = _step.value;
5380
5374
  var calldata = NFTXTrade.INTERFACE.encodeFunctionData('buyAndRedeem', [order.vaultId, order.tokenIds.length, order.tokenIds, order.swapCalldata, order.recipient]);
5381
- planner.addCommand(CommandType.NFTX, [order.value, calldata], config.allowRevert);
5375
+ planner.addCommand(exports.CommandType.NFTX, [order.value, calldata], config.allowRevert);
5382
5376
  }
5383
5377
  };
5384
5378
  _proto.getBuyItems = function getBuyItems() {
@@ -8145,10 +8139,10 @@ var SeaportTrade = /*#__PURE__*/function (_NFTTrade) {
8145
8139
  switch (protocolAddress.toLowerCase()) {
8146
8140
  case '0x00000000000000adc04c56bf30ac9d3c0aaf14dc':
8147
8141
  // Seaport v1.5
8148
- return CommandType.SEAPORT_V1_5;
8142
+ return exports.CommandType.SEAPORT_V1_5;
8149
8143
  case '0x00000000000001ad428e4906ae43d8f9852d0dd6':
8150
8144
  // Seaport v1.4
8151
- return CommandType.SEAPORT_V1_4;
8145
+ return exports.CommandType.SEAPORT_V1_4;
8152
8146
  default:
8153
8147
  throw new Error('unsupported Seaport address');
8154
8148
  }
@@ -9339,7 +9333,7 @@ var SudoswapTrade = /*#__PURE__*/function (_NFTTrade) {
9339
9333
  var value = order.swaps.reduce(function (prevVal, swap) {
9340
9334
  return prevVal.add(swap.maxCost);
9341
9335
  }, ethers.BigNumber.from(0));
9342
- planner.addCommand(CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
9336
+ planner.addCommand(exports.CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
9343
9337
  }
9344
9338
  };
9345
9339
  _proto.getBuyItems = function getBuyItems() {
@@ -10492,9 +10486,9 @@ var X2Y2Trade = /*#__PURE__*/function (_NFTTrade) {
10492
10486
  var functionSelector = X2Y2Trade.INTERFACE.getSighash(X2Y2Trade.INTERFACE.getFunction('run'));
10493
10487
  var calldata = functionSelector + item.signedInput.slice(2);
10494
10488
  if (item.tokenType == exports.TokenType.ERC721) {
10495
- planner.addCommand(CommandType.X2Y2_721, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
10489
+ planner.addCommand(exports.CommandType.X2Y2_721, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
10496
10490
  } else if (item.tokenType == exports.TokenType.ERC1155) {
10497
- planner.addCommand(CommandType.X2Y2_1155, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId, item.tokenAmount], config.allowRevert);
10491
+ planner.addCommand(exports.CommandType.X2Y2_1155, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId, item.tokenAmount], config.allowRevert);
10498
10492
  }
10499
10493
  }
10500
10494
  };
@@ -10542,7 +10536,7 @@ var UnwrapWETH = /*#__PURE__*/function () {
10542
10536
  amount: this.amount.toString()
10543
10537
  }
10544
10538
  });
10545
- planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
10539
+ planner.addCommand(exports.CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
10546
10540
  };
10547
10541
  return UnwrapWETH;
10548
10542
  }();
@@ -10555,6 +10549,7 @@ exports.NFTTrade = NFTTrade;
10555
10549
  exports.NFTXTrade = NFTXTrade;
10556
10550
  exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
10557
10551
  exports.ROUTER_AS_RECIPIENT = ROUTER_AS_RECIPIENT;
10552
+ exports.RoutePlanner = RoutePlanner;
10558
10553
  exports.SeaportTrade = SeaportTrade;
10559
10554
  exports.SudoswapTrade = SudoswapTrade;
10560
10555
  exports.SwapRouter = SwapRouter;