@uniswap/universal-router-sdk 1.5.7 → 1.6.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.
@@ -3,8 +3,14 @@ import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap
3
3
  import { Permit2Permit } from '../../utils/inputTokens';
4
4
  import { Currency, TradeType } from '@uniswap/sdk-core';
5
5
  import { Command, RouterTradeType, TradeConfig } from '../Command';
6
+ import { BigNumberish } from 'ethers';
7
+ export declare type FlatFeeOptions = {
8
+ amount: BigNumberish;
9
+ recipient: string;
10
+ };
6
11
  export declare type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
7
12
  inputTokenPermit?: Permit2Permit;
13
+ flatFee?: FlatFeeOptions;
8
14
  };
9
15
  export declare class UniswapTrade implements Command {
10
16
  trade: RouterTrade<Currency, Currency, TradeType>;
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: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
197
+ router: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
204
198
  weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
205
- creationBlock: 42294741
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: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
205
+ router: '0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8',
212
206
  weth: '0x4200000000000000000000000000000000000006',
213
- creationBlock: 96333990
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: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
213
+ router: '0x5E325eDA8064b456f4781070C0738d849c824258',
220
214
  weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
221
- creationBlock: 87206402
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: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
221
+ router: '0x643770e279d5d0733f21d6dc03a8efbabf3255b4',
228
222
  weth: WETH_NOT_SUPPORTED_ON_CHAIN,
229
- creationBlock: 19106929
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: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
229
+ router: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
236
230
  weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
237
- creationBlock: 27915533
231
+ creationBlock: 35160263
238
232
  }, _CHAIN_CONFIGS[43114] = {
239
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
233
+ router: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
240
234
  weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
241
- creationBlock: 31583684
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: '0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC',
241
+ router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
248
242
  weth: '0x4200000000000000000000000000000000000006',
249
- creationBlock: 1452376
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);
@@ -282,6 +276,7 @@ var UniswapTrade = /*#__PURE__*/function () {
282
276
  this.trade = trade;
283
277
  this.options = options;
284
278
  this.tradeType = exports.RouterTradeType.UniswapTrade;
279
+ if (!!options.fee && !!options.flatFee) throw new Error('Only one fee option permitted');
285
280
  }
286
281
  var _proto = UniswapTrade.prototype;
287
282
  _proto.encode = function encode(planner, _config) {
@@ -290,7 +285,7 @@ var UniswapTrade = /*#__PURE__*/function () {
290
285
  // If the input currency is the native currency, we need to wrap it with the router as the recipient
291
286
  if (this.trade.inputAmount.currency.isNative) {
292
287
  // TODO: optimize if only one v2 pool we can directly send this to the pool
293
- 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()]);
294
289
  // since WETH is now owned by the router, the router pays for inputs
295
290
  payerIsUser = false;
296
291
  }
@@ -303,7 +298,7 @@ var UniswapTrade = /*#__PURE__*/function () {
303
298
  var performAggregatedSlippageCheck = this.trade.tradeType === sdkCore.TradeType.EXACT_INPUT && this.trade.routes.length > 2;
304
299
  var outputIsNative = this.trade.outputAmount.currency.isNative;
305
300
  var inputIsNative = this.trade.inputAmount.currency.isNative;
306
- var routerMustCustody = performAggregatedSlippageCheck || outputIsNative || !!this.options.fee;
301
+ var routerMustCustody = performAggregatedSlippageCheck || outputIsNative || hasFeeOption(this.options);
307
302
  for (var _iterator = _createForOfIteratorHelperLoose(this.trade.swaps), _step; !(_step = _iterator()).done;) {
308
303
  var swap = _step.value;
309
304
  switch (swap.route.protocol) {
@@ -327,25 +322,37 @@ var UniswapTrade = /*#__PURE__*/function () {
327
322
  // In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
328
323
  if (!!this.options.fee) {
329
324
  var feeBips = encodeFeeBips(this.options.fee.fee);
330
- 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]);
331
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
332
327
  // Otherwise we continue as expected with the trade's normal expected output
333
328
  if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
334
329
  minimumAmountOut = minimumAmountOut.sub(minimumAmountOut.mul(feeBips).div(10000));
335
330
  }
336
331
  }
332
+ // If there is a flat fee, that absolute amount is sent to the fee recipient
333
+ // In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
334
+ if (!!this.options.flatFee) {
335
+ var feeAmount = this.options.flatFee.amount;
336
+ if (minimumAmountOut.lt(feeAmount)) throw new Error('Flat fee amount greater than minimumAmountOut');
337
+ planner.addCommand(exports.CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
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
339
+ // Otherwise we continue as expected with the trade's normal expected output
340
+ if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
341
+ minimumAmountOut = minimumAmountOut.sub(feeAmount);
342
+ }
343
+ }
337
344
  // The remaining tokens that need to be sent to the user after the fee is taken will be caught
338
345
  // by this if-else clause.
339
346
  if (outputIsNative) {
340
- planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
347
+ planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
341
348
  } else {
342
- 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]);
343
350
  }
344
351
  }
345
352
  if (inputIsNative && (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade))) {
346
353
  // for exactOutput swaps that take native currency as input
347
354
  // we need to send back the change to the user
348
- planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
355
+ planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
349
356
  }
350
357
  };
351
358
  return UniswapTrade;
@@ -357,13 +364,13 @@ function addV2Swap(planner, _ref, tradeType, options, payerIsUser, routerMustCus
357
364
  outputAmount = _ref.outputAmount;
358
365
  var trade = new v2Sdk.Trade(route, tradeType == sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
359
366
  if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
360
- planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [
367
+ planner.addCommand(exports.CommandType.V2_SWAP_EXACT_IN, [
361
368
  // if native, we have to unwrap so keep in the router for now
362
369
  routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), route.path.map(function (pool) {
363
370
  return pool.address;
364
371
  }), payerIsUser]);
365
372
  } else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
366
- 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) {
367
374
  return pool.address;
368
375
  }), payerIsUser]);
369
376
  }
@@ -381,9 +388,9 @@ function addV3Swap(planner, _ref2, tradeType, options, payerIsUser, routerMustCu
381
388
  });
382
389
  var path = v3Sdk.encodeRouteToPath(route, trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT);
383
390
  if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
384
- 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]);
385
392
  } else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
386
- 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]);
387
394
  }
388
395
  }
389
396
  // encode a mixed route swap, i.e. including both v2 and v3 pools
@@ -433,12 +440,12 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
433
440
  };
434
441
  if (mixedRouteIsAllV3(newRoute)) {
435
442
  var path = routerSdk.encodeMixedRouteToPath(newRoute);
436
- planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [
443
+ planner.addCommand(exports.CommandType.V3_SWAP_EXACT_IN, [
437
444
  // if not last section: send tokens directly to the first v2 pair of the next section
438
445
  // note: because of the partitioning function we can be sure that the next section is v2
439
446
  isLastSectionInRoute(i) ? tradeRecipient : sections[i + 1][0].liquidityToken.address, i == 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, path, payerIsUser && i === 0]);
440
447
  } else {
441
- 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) {
442
449
  return pool.address;
443
450
  }), payerIsUser && i === 0]);
444
451
  }
@@ -448,6 +455,9 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
448
455
  function riskOfPartialFill(trade) {
449
456
  return trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
450
457
  }
458
+ function hasFeeOption(swapOptions) {
459
+ return !!swapOptions.fee || !!swapOptions.flatFee;
460
+ }
451
461
 
452
462
  var SIGNATURE_LENGTH = 65;
453
463
  var EIP_2098_SIGNATURE_LENGTH = 64;
@@ -459,7 +469,7 @@ function encodePermit(planner, permit2) {
459
469
  // sanitizes signature to cover edge cases of malformed EIP-2098 sigs and v used as recovery id
460
470
  signature = ethers.ethers.utils.joinSignature(ethers.ethers.utils.splitSignature(permit2.signature));
461
471
  }
462
- planner.addCommand(CommandType.PERMIT2_PERMIT, [permit2, signature]);
472
+ planner.addCommand(exports.CommandType.PERMIT2_PERMIT, [permit2, signature]);
463
473
  }
464
474
  // Handles the encoding of commands needed to gather input tokens for a trade
465
475
  // Approval: The router approving another address to take tokens.
@@ -473,14 +483,14 @@ function encodeInputTokenOptions(planner, options) {
473
483
  if (!!options.permit2TransferFrom && !!options.permit2Permit) !(options.permit2TransferFrom.token === options.permit2Permit.details.token) ? invariant(false, "inconsistent token") : void 0;
474
484
  // if an options.approval is required, add it
475
485
  if (!!options.approval) {
476
- 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)]);
477
487
  }
478
488
  // if this order has a options.permit2Permit, encode it
479
489
  if (!!options.permit2Permit) {
480
490
  encodePermit(planner, options.permit2Permit);
481
491
  }
482
492
  if (!!options.permit2TransferFrom) {
483
- 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]);
484
494
  }
485
495
  }
486
496
  function mapApprovalProtocol(protocolAddress) {
@@ -585,7 +595,7 @@ var SwapRouter = /*#__PURE__*/function () {
585
595
  // or NFT trades with potential slippage (i.e. sudo).
586
596
  // Note: NFTXV2 sends excess ETH to the caller (router), not the specified recipient
587
597
  nftInputTokens.forEach(function (inputToken) {
588
- planner.addCommand(CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
598
+ planner.addCommand(exports.CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
589
599
  });
590
600
  return SwapRouter.encodePlan(planner, transactionValue, config);
591
601
  }
@@ -609,7 +619,7 @@ var SwapRouter = /*#__PURE__*/function () {
609
619
  });
610
620
  totalPrice = totalPrice.add(trade.getTotalPrice());
611
621
  }
612
- planner.addCommand(CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
622
+ planner.addCommand(exports.CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
613
623
  return SwapRouter.encodePlan(planner, totalPrice, config);
614
624
  }
615
625
  /**
@@ -668,7 +678,7 @@ var CryptopunkTrade = /*#__PURE__*/function (_NFTTrade) {
668
678
  _proto.encode = function encode(planner, config) {
669
679
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
670
680
  var item = _step.value;
671
- 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);
672
682
  }
673
683
  };
674
684
  _proto.getBuyItems = function getBuyItems() {
@@ -2327,7 +2337,7 @@ var FoundationTrade = /*#__PURE__*/function (_NFTTrade) {
2327
2337
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
2328
2338
  var item = _step.value;
2329
2339
  var calldata = FoundationTrade.INTERFACE.encodeFunctionData('buyV2', [item.tokenAddress, item.tokenId, item.price, item.referrer]);
2330
- 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);
2331
2341
  }
2332
2342
  };
2333
2343
  _proto.getBuyItems = function getBuyItems() {
@@ -4373,7 +4383,7 @@ var LooksRareV2Trade = /*#__PURE__*/function (_NFTTrade) {
4373
4383
  } else {
4374
4384
  calldata = LooksRareV2Trade.INTERFACE.encodeFunctionData('executeMultipleTakerBids', [takerBids, makerOrders, makerSignatures, merkleTrees, ZERO_ADDRESS, false]);
4375
4385
  }
4376
- planner.addCommand(CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
4386
+ planner.addCommand(exports.CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
4377
4387
  };
4378
4388
  _proto.getBuyItems = function getBuyItems() {
4379
4389
  var buyItems = [];
@@ -4701,7 +4711,7 @@ var NFT20Trade = /*#__PURE__*/function (_NFTTrade) {
4701
4711
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
4702
4712
  var order = _step.value;
4703
4713
  var calldata = NFT20Trade.INTERFACE.encodeFunctionData('ethForNft', [order.tokenAddress, order.tokenIds, order.tokenAmounts, order.recipient, order.fee, order.isV3]);
4704
- planner.addCommand(CommandType.NFT20, [order.value, calldata], config.allowRevert);
4714
+ planner.addCommand(exports.CommandType.NFT20, [order.value, calldata], config.allowRevert);
4705
4715
  }
4706
4716
  };
4707
4717
  _proto.getBuyItems = function getBuyItems() {
@@ -5362,7 +5372,7 @@ var NFTXTrade = /*#__PURE__*/function (_NFTTrade) {
5362
5372
  for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
5363
5373
  var order = _step.value;
5364
5374
  var calldata = NFTXTrade.INTERFACE.encodeFunctionData('buyAndRedeem', [order.vaultId, order.tokenIds.length, order.tokenIds, order.swapCalldata, order.recipient]);
5365
- planner.addCommand(CommandType.NFTX, [order.value, calldata], config.allowRevert);
5375
+ planner.addCommand(exports.CommandType.NFTX, [order.value, calldata], config.allowRevert);
5366
5376
  }
5367
5377
  };
5368
5378
  _proto.getBuyItems = function getBuyItems() {
@@ -8129,10 +8139,10 @@ var SeaportTrade = /*#__PURE__*/function (_NFTTrade) {
8129
8139
  switch (protocolAddress.toLowerCase()) {
8130
8140
  case '0x00000000000000adc04c56bf30ac9d3c0aaf14dc':
8131
8141
  // Seaport v1.5
8132
- return CommandType.SEAPORT_V1_5;
8142
+ return exports.CommandType.SEAPORT_V1_5;
8133
8143
  case '0x00000000000001ad428e4906ae43d8f9852d0dd6':
8134
8144
  // Seaport v1.4
8135
- return CommandType.SEAPORT_V1_4;
8145
+ return exports.CommandType.SEAPORT_V1_4;
8136
8146
  default:
8137
8147
  throw new Error('unsupported Seaport address');
8138
8148
  }
@@ -9323,7 +9333,7 @@ var SudoswapTrade = /*#__PURE__*/function (_NFTTrade) {
9323
9333
  var value = order.swaps.reduce(function (prevVal, swap) {
9324
9334
  return prevVal.add(swap.maxCost);
9325
9335
  }, ethers.BigNumber.from(0));
9326
- planner.addCommand(CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
9336
+ planner.addCommand(exports.CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
9327
9337
  }
9328
9338
  };
9329
9339
  _proto.getBuyItems = function getBuyItems() {
@@ -10476,9 +10486,9 @@ var X2Y2Trade = /*#__PURE__*/function (_NFTTrade) {
10476
10486
  var functionSelector = X2Y2Trade.INTERFACE.getSighash(X2Y2Trade.INTERFACE.getFunction('run'));
10477
10487
  var calldata = functionSelector + item.signedInput.slice(2);
10478
10488
  if (item.tokenType == exports.TokenType.ERC721) {
10479
- 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);
10480
10490
  } else if (item.tokenType == exports.TokenType.ERC1155) {
10481
- 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);
10482
10492
  }
10483
10493
  }
10484
10494
  };
@@ -10526,7 +10536,7 @@ var UnwrapWETH = /*#__PURE__*/function () {
10526
10536
  amount: this.amount.toString()
10527
10537
  }
10528
10538
  });
10529
- planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
10539
+ planner.addCommand(exports.CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
10530
10540
  };
10531
10541
  return UnwrapWETH;
10532
10542
  }();
@@ -10539,6 +10549,7 @@ exports.NFTTrade = NFTTrade;
10539
10549
  exports.NFTXTrade = NFTXTrade;
10540
10550
  exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
10541
10551
  exports.ROUTER_AS_RECIPIENT = ROUTER_AS_RECIPIENT;
10552
+ exports.RoutePlanner = RoutePlanner;
10542
10553
  exports.SeaportTrade = SeaportTrade;
10543
10554
  exports.SudoswapTrade = SudoswapTrade;
10544
10555
  exports.SwapRouter = SwapRouter;