@uniswap/universal-router-sdk 2.0.0 → 2.0.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 +1 -0
- package/dist/universal-router-sdk.cjs.development.js +35 -40
- package/dist/universal-router-sdk.cjs.development.js.map +1 -1
- package/dist/universal-router-sdk.cjs.production.min.js +1 -1
- package/dist/universal-router-sdk.cjs.production.min.js.map +1 -1
- package/dist/universal-router-sdk.esm.js +1 -1
- package/dist/universal-router-sdk.esm.js.map +1 -1
- package/package.json +1 -1
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';
|
|
@@ -106,12 +106,6 @@ var NFTTrade = function NFTTrade(market, orders) {
|
|
|
106
106
|
})(exports.TokenType || (exports.TokenType = {}));
|
|
107
107
|
|
|
108
108
|
var _ABI_DEFINITION;
|
|
109
|
-
/**
|
|
110
|
-
* CommandTypes
|
|
111
|
-
* @description Flags that modify a command's execution
|
|
112
|
-
* @enum {number}
|
|
113
|
-
*/
|
|
114
|
-
var CommandType;
|
|
115
109
|
(function (CommandType) {
|
|
116
110
|
CommandType[CommandType["V3_SWAP_EXACT_IN"] = 0] = "V3_SWAP_EXACT_IN";
|
|
117
111
|
CommandType[CommandType["V3_SWAP_EXACT_OUT"] = 1] = "V3_SWAP_EXACT_OUT";
|
|
@@ -148,14 +142,14 @@ var CommandType;
|
|
|
148
142
|
CommandType[CommandType["APPROVE_ERC20"] = 34] = "APPROVE_ERC20";
|
|
149
143
|
CommandType[CommandType["WRAP_STETH"] = 35] = "WRAP_STETH";
|
|
150
144
|
CommandType[CommandType["UNWRAP_STETH"] = 36] = "UNWRAP_STETH";
|
|
151
|
-
})(CommandType || (CommandType = {}));
|
|
145
|
+
})(exports.CommandType || (exports.CommandType = {}));
|
|
152
146
|
var ALLOW_REVERT_FLAG = 0x80;
|
|
153
|
-
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]);
|
|
147
|
+
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]);
|
|
154
148
|
var PERMIT_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)';
|
|
155
149
|
var PERMIT_BATCH_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)';
|
|
156
150
|
var PERMIT2_TRANSFER_FROM_STRUCT = '(address from,address to,uint160 amount,address token)';
|
|
157
151
|
var PERMIT2_TRANSFER_FROM_BATCH_STRUCT = PERMIT2_TRANSFER_FROM_STRUCT + '[]';
|
|
158
|
-
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.WRAP_STETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.UNWRAP_STETH] = ['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);
|
|
152
|
+
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.WRAP_STETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.UNWRAP_STETH] = ['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);
|
|
159
153
|
var RoutePlanner = /*#__PURE__*/function () {
|
|
160
154
|
function RoutePlanner() {
|
|
161
155
|
this.commands = '0x';
|
|
@@ -163,7 +157,7 @@ var RoutePlanner = /*#__PURE__*/function () {
|
|
|
163
157
|
}
|
|
164
158
|
var _proto = RoutePlanner.prototype;
|
|
165
159
|
_proto.addSubPlan = function addSubPlan(subplan) {
|
|
166
|
-
this.addCommand(CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
|
|
160
|
+
this.addCommand(exports.CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
|
|
167
161
|
};
|
|
168
162
|
_proto.addCommand = function addCommand(type, parameters, allowRevert) {
|
|
169
163
|
if (allowRevert === void 0) {
|
|
@@ -330,7 +324,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
330
324
|
// If the input currency is the native currency, we need to wrap it with the router as the recipient
|
|
331
325
|
if (this.trade.inputAmount.currency.isNative) {
|
|
332
326
|
// TODO: optimize if only one v2 pool we can directly send this to the pool
|
|
333
|
-
planner.addCommand(CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
|
|
327
|
+
planner.addCommand(exports.CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
|
|
334
328
|
// since WETH is now owned by the router, the router pays for inputs
|
|
335
329
|
payerIsUser = false;
|
|
336
330
|
}
|
|
@@ -367,7 +361,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
367
361
|
// In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
|
|
368
362
|
if (!!this.options.fee) {
|
|
369
363
|
var feeBips = encodeFeeBips(this.options.fee.fee);
|
|
370
|
-
planner.addCommand(CommandType.PAY_PORTION, [this.trade.outputAmount.currency.wrapped.address, this.options.fee.recipient, feeBips]);
|
|
364
|
+
planner.addCommand(exports.CommandType.PAY_PORTION, [this.trade.outputAmount.currency.wrapped.address, this.options.fee.recipient, feeBips]);
|
|
371
365
|
// If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
|
|
372
366
|
// Otherwise we continue as expected with the trade's normal expected output
|
|
373
367
|
if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
|
|
@@ -379,7 +373,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
379
373
|
if (!!this.options.flatFee) {
|
|
380
374
|
var feeAmount = this.options.flatFee.amount;
|
|
381
375
|
if (minimumAmountOut.lt(feeAmount)) throw new Error('Flat fee amount greater than minimumAmountOut');
|
|
382
|
-
planner.addCommand(CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
|
|
376
|
+
planner.addCommand(exports.CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
|
|
383
377
|
// If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
|
|
384
378
|
// Otherwise we continue as expected with the trade's normal expected output
|
|
385
379
|
if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
|
|
@@ -389,15 +383,15 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
389
383
|
// The remaining tokens that need to be sent to the user after the fee is taken will be caught
|
|
390
384
|
// by this if-else clause.
|
|
391
385
|
if (outputIsNative) {
|
|
392
|
-
planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
|
|
386
|
+
planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
|
|
393
387
|
} else {
|
|
394
|
-
planner.addCommand(CommandType.SWEEP, [this.trade.outputAmount.currency.wrapped.address, this.options.recipient, minimumAmountOut]);
|
|
388
|
+
planner.addCommand(exports.CommandType.SWEEP, [this.trade.outputAmount.currency.wrapped.address, this.options.recipient, minimumAmountOut]);
|
|
395
389
|
}
|
|
396
390
|
}
|
|
397
391
|
if (inputIsNative && (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade))) {
|
|
398
392
|
// for exactOutput swaps that take native currency as input
|
|
399
393
|
// we need to send back the change to the user
|
|
400
|
-
planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
|
|
394
|
+
planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
|
|
401
395
|
}
|
|
402
396
|
};
|
|
403
397
|
return UniswapTrade;
|
|
@@ -409,13 +403,13 @@ function addV2Swap(planner, _ref, tradeType, options, payerIsUser, routerMustCus
|
|
|
409
403
|
outputAmount = _ref.outputAmount;
|
|
410
404
|
var trade = new v2Sdk.Trade(route, tradeType == sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
|
|
411
405
|
if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
|
|
412
|
-
planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [
|
|
406
|
+
planner.addCommand(exports.CommandType.V2_SWAP_EXACT_IN, [
|
|
413
407
|
// if native, we have to unwrap so keep in the router for now
|
|
414
408
|
routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), route.path.map(function (pool) {
|
|
415
409
|
return pool.address;
|
|
416
410
|
}), payerIsUser]);
|
|
417
411
|
} else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
|
|
418
|
-
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) {
|
|
412
|
+
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) {
|
|
419
413
|
return pool.address;
|
|
420
414
|
}), payerIsUser]);
|
|
421
415
|
}
|
|
@@ -433,9 +427,9 @@ function addV3Swap(planner, _ref2, tradeType, options, payerIsUser, routerMustCu
|
|
|
433
427
|
});
|
|
434
428
|
var path = v3Sdk.encodeRouteToPath(route, trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT);
|
|
435
429
|
if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
|
|
436
|
-
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]);
|
|
430
|
+
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]);
|
|
437
431
|
} else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
|
|
438
|
-
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]);
|
|
432
|
+
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]);
|
|
439
433
|
}
|
|
440
434
|
}
|
|
441
435
|
// encode a mixed route swap, i.e. including both v2 and v3 pools
|
|
@@ -485,12 +479,12 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
|
|
|
485
479
|
};
|
|
486
480
|
if (mixedRouteIsAllV3(newRoute)) {
|
|
487
481
|
var path = routerSdk.encodeMixedRouteToPath(newRoute);
|
|
488
|
-
planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [
|
|
482
|
+
planner.addCommand(exports.CommandType.V3_SWAP_EXACT_IN, [
|
|
489
483
|
// if not last section: send tokens directly to the first v2 pair of the next section
|
|
490
484
|
// note: because of the partitioning function we can be sure that the next section is v2
|
|
491
485
|
isLastSectionInRoute(i) ? tradeRecipient : sections[i + 1][0].liquidityToken.address, i == 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, path, payerIsUser && i === 0]);
|
|
492
486
|
} else {
|
|
493
|
-
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) {
|
|
487
|
+
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) {
|
|
494
488
|
return pool.address;
|
|
495
489
|
}), payerIsUser && i === 0]);
|
|
496
490
|
}
|
|
@@ -514,7 +508,7 @@ function encodePermit(planner, permit2) {
|
|
|
514
508
|
// sanitizes signature to cover edge cases of malformed EIP-2098 sigs and v used as recovery id
|
|
515
509
|
signature = ethers.ethers.utils.joinSignature(ethers.ethers.utils.splitSignature(permit2.signature));
|
|
516
510
|
}
|
|
517
|
-
planner.addCommand(CommandType.PERMIT2_PERMIT, [permit2, signature]);
|
|
511
|
+
planner.addCommand(exports.CommandType.PERMIT2_PERMIT, [permit2, signature]);
|
|
518
512
|
}
|
|
519
513
|
// Handles the encoding of commands needed to gather input tokens for a trade
|
|
520
514
|
// Approval: The router approving another address to take tokens.
|
|
@@ -528,14 +522,14 @@ function encodeInputTokenOptions(planner, options) {
|
|
|
528
522
|
if (!!options.permit2TransferFrom && !!options.permit2Permit) !(options.permit2TransferFrom.token === options.permit2Permit.details.token) ? invariant(false, "inconsistent token") : void 0;
|
|
529
523
|
// if an options.approval is required, add it
|
|
530
524
|
if (!!options.approval) {
|
|
531
|
-
planner.addCommand(CommandType.APPROVE_ERC20, [options.approval.token, mapApprovalProtocol(options.approval.protocol)]);
|
|
525
|
+
planner.addCommand(exports.CommandType.APPROVE_ERC20, [options.approval.token, mapApprovalProtocol(options.approval.protocol)]);
|
|
532
526
|
}
|
|
533
527
|
// if this order has a options.permit2Permit, encode it
|
|
534
528
|
if (!!options.permit2Permit) {
|
|
535
529
|
encodePermit(planner, options.permit2Permit);
|
|
536
530
|
}
|
|
537
531
|
if (!!options.permit2TransferFrom) {
|
|
538
|
-
planner.addCommand(CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
|
|
532
|
+
planner.addCommand(exports.CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
|
|
539
533
|
}
|
|
540
534
|
}
|
|
541
535
|
function mapApprovalProtocol(protocolAddress) {
|
|
@@ -647,7 +641,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
647
641
|
// or NFT trades with potential slippage (i.e. sudo).
|
|
648
642
|
// Note: NFTXV2 sends excess ETH to the caller (router), not the specified recipient
|
|
649
643
|
nftInputTokens.forEach(function (inputToken) {
|
|
650
|
-
planner.addCommand(CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
|
|
644
|
+
planner.addCommand(exports.CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
|
|
651
645
|
});
|
|
652
646
|
return SwapRouter.encodePlan(planner, transactionValue, config);
|
|
653
647
|
}
|
|
@@ -671,7 +665,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
671
665
|
});
|
|
672
666
|
totalPrice = totalPrice.add(trade.getTotalPrice());
|
|
673
667
|
}
|
|
674
|
-
planner.addCommand(CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
|
|
668
|
+
planner.addCommand(exports.CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
|
|
675
669
|
return SwapRouter.encodePlan(planner, totalPrice, config);
|
|
676
670
|
}
|
|
677
671
|
/**
|
|
@@ -730,7 +724,7 @@ var CryptopunkTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
730
724
|
_proto.encode = function encode(planner, config) {
|
|
731
725
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
732
726
|
var item = _step.value;
|
|
733
|
-
planner.addCommand(CommandType.CRYPTOPUNKS, [item.tokenId, item.recipient, item.value], config.allowRevert);
|
|
727
|
+
planner.addCommand(exports.CommandType.CRYPTOPUNKS, [item.tokenId, item.recipient, item.value], config.allowRevert);
|
|
734
728
|
}
|
|
735
729
|
};
|
|
736
730
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -2389,7 +2383,7 @@ var FoundationTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
2389
2383
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
2390
2384
|
var item = _step.value;
|
|
2391
2385
|
var calldata = FoundationTrade.INTERFACE.encodeFunctionData('buyV2', [item.tokenAddress, item.tokenId, item.price, item.referrer]);
|
|
2392
|
-
planner.addCommand(CommandType.FOUNDATION, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
2386
|
+
planner.addCommand(exports.CommandType.FOUNDATION, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
2393
2387
|
}
|
|
2394
2388
|
};
|
|
2395
2389
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -4435,7 +4429,7 @@ var LooksRareV2Trade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
4435
4429
|
} else {
|
|
4436
4430
|
calldata = LooksRareV2Trade.INTERFACE.encodeFunctionData('executeMultipleTakerBids', [takerBids, makerOrders, makerSignatures, merkleTrees, ZERO_ADDRESS, false]);
|
|
4437
4431
|
}
|
|
4438
|
-
planner.addCommand(CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
|
|
4432
|
+
planner.addCommand(exports.CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
|
|
4439
4433
|
};
|
|
4440
4434
|
_proto.getBuyItems = function getBuyItems() {
|
|
4441
4435
|
var buyItems = [];
|
|
@@ -4763,7 +4757,7 @@ var NFT20Trade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
4763
4757
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
4764
4758
|
var order = _step.value;
|
|
4765
4759
|
var calldata = NFT20Trade.INTERFACE.encodeFunctionData('ethForNft', [order.tokenAddress, order.tokenIds, order.tokenAmounts, order.recipient, order.fee, order.isV3]);
|
|
4766
|
-
planner.addCommand(CommandType.NFT20, [order.value, calldata], config.allowRevert);
|
|
4760
|
+
planner.addCommand(exports.CommandType.NFT20, [order.value, calldata], config.allowRevert);
|
|
4767
4761
|
}
|
|
4768
4762
|
};
|
|
4769
4763
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -5424,7 +5418,7 @@ var NFTXTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
5424
5418
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
5425
5419
|
var order = _step.value;
|
|
5426
5420
|
var calldata = NFTXTrade.INTERFACE.encodeFunctionData('buyAndRedeem', [order.vaultId, order.tokenIds.length, order.tokenIds, order.swapCalldata, order.recipient]);
|
|
5427
|
-
planner.addCommand(CommandType.NFTX, [order.value, calldata], config.allowRevert);
|
|
5421
|
+
planner.addCommand(exports.CommandType.NFTX, [order.value, calldata], config.allowRevert);
|
|
5428
5422
|
}
|
|
5429
5423
|
};
|
|
5430
5424
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -8191,10 +8185,10 @@ var SeaportTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
8191
8185
|
switch (protocolAddress.toLowerCase()) {
|
|
8192
8186
|
case '0x00000000000000adc04c56bf30ac9d3c0aaf14dc':
|
|
8193
8187
|
// Seaport v1.5
|
|
8194
|
-
return CommandType.SEAPORT_V1_5;
|
|
8188
|
+
return exports.CommandType.SEAPORT_V1_5;
|
|
8195
8189
|
case '0x00000000000001ad428e4906ae43d8f9852d0dd6':
|
|
8196
8190
|
// Seaport v1.4
|
|
8197
|
-
return CommandType.SEAPORT_V1_4;
|
|
8191
|
+
return exports.CommandType.SEAPORT_V1_4;
|
|
8198
8192
|
default:
|
|
8199
8193
|
throw new Error('unsupported Seaport address');
|
|
8200
8194
|
}
|
|
@@ -9385,7 +9379,7 @@ var SudoswapTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
9385
9379
|
var value = order.swaps.reduce(function (prevVal, swap) {
|
|
9386
9380
|
return prevVal.add(swap.maxCost);
|
|
9387
9381
|
}, ethers.BigNumber.from(0));
|
|
9388
|
-
planner.addCommand(CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
|
|
9382
|
+
planner.addCommand(exports.CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
|
|
9389
9383
|
}
|
|
9390
9384
|
};
|
|
9391
9385
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -10538,9 +10532,9 @@ var X2Y2Trade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
10538
10532
|
var functionSelector = X2Y2Trade.INTERFACE.getSighash(X2Y2Trade.INTERFACE.getFunction('run'));
|
|
10539
10533
|
var calldata = functionSelector + item.signedInput.slice(2);
|
|
10540
10534
|
if (item.tokenType == exports.TokenType.ERC721) {
|
|
10541
|
-
planner.addCommand(CommandType.X2Y2_721, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
10535
|
+
planner.addCommand(exports.CommandType.X2Y2_721, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
10542
10536
|
} else if (item.tokenType == exports.TokenType.ERC1155) {
|
|
10543
|
-
planner.addCommand(CommandType.X2Y2_1155, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId, item.tokenAmount], config.allowRevert);
|
|
10537
|
+
planner.addCommand(exports.CommandType.X2Y2_1155, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId, item.tokenAmount], config.allowRevert);
|
|
10544
10538
|
}
|
|
10545
10539
|
}
|
|
10546
10540
|
};
|
|
@@ -10588,7 +10582,7 @@ var UnwrapWETH = /*#__PURE__*/function () {
|
|
|
10588
10582
|
amount: this.amount.toString()
|
|
10589
10583
|
}
|
|
10590
10584
|
});
|
|
10591
|
-
planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
|
|
10585
|
+
planner.addCommand(exports.CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
|
|
10592
10586
|
};
|
|
10593
10587
|
return UnwrapWETH;
|
|
10594
10588
|
}();
|
|
@@ -10614,7 +10608,7 @@ var WrapSTETH = /*#__PURE__*/function () {
|
|
|
10614
10608
|
amount: this.amount.toString()
|
|
10615
10609
|
}
|
|
10616
10610
|
});
|
|
10617
|
-
planner.addCommand(CommandType.WRAP_STETH, [ROUTER_AS_RECIPIENT, this.wrapAmount]);
|
|
10611
|
+
planner.addCommand(exports.CommandType.WRAP_STETH, [ROUTER_AS_RECIPIENT, this.wrapAmount]);
|
|
10618
10612
|
};
|
|
10619
10613
|
return WrapSTETH;
|
|
10620
10614
|
}();
|
|
@@ -10628,7 +10622,7 @@ var UnwrapSTETH = /*#__PURE__*/function () {
|
|
|
10628
10622
|
}
|
|
10629
10623
|
var _proto = UnwrapSTETH.prototype;
|
|
10630
10624
|
_proto.encode = function encode(planner, _) {
|
|
10631
|
-
planner.addCommand(CommandType.UNWRAP_STETH, [this.recipient, this.amountMinimum]);
|
|
10625
|
+
planner.addCommand(exports.CommandType.UNWRAP_STETH, [this.recipient, this.amountMinimum]);
|
|
10632
10626
|
};
|
|
10633
10627
|
return UnwrapSTETH;
|
|
10634
10628
|
}();
|
|
@@ -10641,6 +10635,7 @@ exports.NFTTrade = NFTTrade;
|
|
|
10641
10635
|
exports.NFTXTrade = NFTXTrade;
|
|
10642
10636
|
exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
|
|
10643
10637
|
exports.ROUTER_AS_RECIPIENT = ROUTER_AS_RECIPIENT;
|
|
10638
|
+
exports.RoutePlanner = RoutePlanner;
|
|
10644
10639
|
exports.SeaportTrade = SeaportTrade;
|
|
10645
10640
|
exports.SudoswapTrade = SudoswapTrade;
|
|
10646
10641
|
exports.SwapRouter = SwapRouter;
|