@kittycorn-labs/universal-router-sdk 1.4.43 → 2.0.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 +312 -0
- package/dist/cjs/src/abis/UniversalRouter.json +740 -0
- package/dist/{entities → cjs/src/entities}/Command.d.ts +12 -12
- package/dist/cjs/src/entities/Command.js +9 -0
- package/dist/cjs/src/entities/Command.js.map +1 -0
- package/dist/cjs/src/entities/actions/across.d.ts +21 -0
- package/dist/cjs/src/entities/actions/across.js +7 -0
- package/dist/cjs/src/entities/actions/across.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/index.d.ts +3 -2
- package/dist/cjs/src/entities/actions/index.js +7 -0
- package/dist/cjs/src/entities/actions/index.js.map +1 -0
- package/dist/cjs/src/entities/actions/uniswap.d.ts +94 -0
- package/dist/cjs/src/entities/actions/uniswap.js +740 -0
- package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/unwrapWETH.d.ts +12 -12
- package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/index.d.ts +2 -2
- package/dist/cjs/src/entities/index.js +6 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/cjs/src/index.d.ts +19 -0
- package/dist/cjs/src/index.js +43 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/kittycorn.d.ts +9 -0
- package/dist/cjs/src/kittycorn.js +26 -0
- package/dist/cjs/src/kittycorn.js.map +1 -0
- package/dist/cjs/src/swapRouter.d.ts +123 -0
- package/dist/cjs/src/swapRouter.js +445 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/cjs/src/types/encodeSwaps.d.ts +197 -0
- package/dist/cjs/src/types/encodeSwaps.js +3 -0
- package/dist/cjs/src/types/encodeSwaps.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/commandParser.d.ts +36 -34
- package/dist/cjs/src/utils/commandParser.js +154 -0
- package/dist/cjs/src/utils/commandParser.js.map +1 -0
- package/dist/cjs/src/utils/computeEncodeSwapsAmounts.d.ts +8 -0
- package/dist/cjs/src/utils/computeEncodeSwapsAmounts.js +46 -0
- package/dist/cjs/src/utils/computeEncodeSwapsAmounts.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/constants.d.ts +46 -30
- package/dist/cjs/src/utils/constants.js +777 -0
- package/dist/cjs/src/utils/constants.js.map +1 -0
- package/dist/cjs/src/utils/directTransfers.d.ts +15 -0
- package/dist/cjs/src/utils/directTransfers.js +381 -0
- package/dist/cjs/src/utils/directTransfers.js.map +1 -0
- package/dist/cjs/src/utils/eip712.d.ts +17 -0
- package/dist/cjs/src/utils/eip712.js +44 -0
- package/dist/cjs/src/utils/eip712.js.map +1 -0
- package/dist/cjs/src/utils/encodeSwapStep.d.ts +4 -0
- package/dist/cjs/src/utils/encodeSwapStep.js +62 -0
- package/dist/cjs/src/utils/encodeSwapStep.js.map +1 -0
- package/dist/cjs/src/utils/encodeV4Action.d.ts +7 -0
- package/dist/cjs/src/utils/encodeV4Action.js +84 -0
- package/dist/cjs/src/utils/encodeV4Action.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/getCurrencyAddress.d.ts +2 -2
- package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/inputTokens.d.ts +23 -23
- package/dist/cjs/src/utils/inputTokens.js +58 -0
- package/dist/cjs/src/utils/inputTokens.js.map +1 -0
- package/dist/cjs/src/utils/normalizeEncodeSwapsSpec.d.ts +6 -0
- package/dist/cjs/src/utils/normalizeEncodeSwapsSpec.js +34 -0
- package/dist/cjs/src/utils/normalizeEncodeSwapsSpec.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/numbers.d.ts +7 -6
- package/dist/cjs/src/utils/numbers.js +27 -0
- package/dist/cjs/src/utils/numbers.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +3 -3
- package/dist/cjs/src/utils/pathCurrency.js +27 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/cjs/src/utils/portionFees.d.ts +14 -0
- package/dist/cjs/src/utils/portionFees.js +40 -0
- package/dist/cjs/src/utils/portionFees.js.map +1 -0
- package/dist/cjs/src/utils/routerBalanceSteps.d.ts +31 -0
- package/dist/cjs/src/utils/routerBalanceSteps.js +293 -0
- package/dist/cjs/src/utils/routerBalanceSteps.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/routerCommands.d.ts +77 -64
- package/dist/cjs/src/utils/routerCommands.js +331 -0
- package/dist/cjs/src/utils/routerCommands.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/routerTradeAdapter.d.ts +73 -73
- package/dist/cjs/src/utils/routerTradeAdapter.js +139 -0
- package/dist/cjs/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/cjs/src/utils/toV4URVersion.d.ts +3 -0
- package/dist/cjs/src/utils/toV4URVersion.js +17 -0
- package/dist/cjs/src/utils/toV4URVersion.js.map +1 -0
- package/dist/cjs/src/utils/validateEncodeSwaps.d.ts +2 -0
- package/dist/cjs/src/utils/validateEncodeSwaps.js +344 -0
- package/dist/cjs/src/utils/validateEncodeSwaps.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/abis/UniversalRouter.json +740 -0
- package/dist/esm/src/entities/Command.d.ts +12 -0
- package/dist/esm/src/entities/Command.js +6 -0
- package/dist/esm/src/entities/Command.js.map +1 -0
- package/dist/esm/src/entities/actions/across.d.ts +21 -0
- package/dist/esm/src/entities/actions/across.js +3 -0
- package/dist/esm/src/entities/actions/across.js.map +1 -0
- package/dist/esm/src/entities/actions/index.d.ts +3 -0
- package/dist/esm/src/entities/actions/index.js +4 -0
- package/dist/esm/src/entities/actions/index.js.map +1 -0
- package/dist/esm/src/entities/actions/uniswap.d.ts +94 -0
- package/dist/esm/src/entities/actions/uniswap.js +735 -0
- package/dist/esm/src/entities/actions/uniswap.js.map +1 -0
- package/dist/esm/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js +28 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +2 -0
- package/dist/esm/src/entities/index.js +3 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/index.d.ts +19 -0
- package/dist/esm/src/index.js +15 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/kittycorn.d.ts +9 -0
- package/dist/esm/src/kittycorn.js +22 -0
- package/dist/esm/src/kittycorn.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +123 -0
- package/dist/esm/src/swapRouter.js +440 -0
- package/dist/esm/src/swapRouter.js.map +1 -0
- package/dist/esm/src/types/encodeSwaps.d.ts +197 -0
- package/dist/esm/src/types/encodeSwaps.js +2 -0
- package/dist/esm/src/types/encodeSwaps.js.map +1 -0
- package/dist/esm/src/utils/commandParser.d.ts +36 -0
- package/dist/esm/src/utils/commandParser.js +146 -0
- package/dist/esm/src/utils/commandParser.js.map +1 -0
- package/dist/esm/src/utils/computeEncodeSwapsAmounts.d.ts +8 -0
- package/dist/esm/src/utils/computeEncodeSwapsAmounts.js +41 -0
- package/dist/esm/src/utils/computeEncodeSwapsAmounts.js.map +1 -0
- package/dist/esm/src/utils/constants.d.ts +46 -0
- package/dist/esm/src/utils/constants.js +768 -0
- package/dist/esm/src/utils/constants.js.map +1 -0
- package/dist/esm/src/utils/directTransfers.d.ts +15 -0
- package/dist/esm/src/utils/directTransfers.js +369 -0
- package/dist/esm/src/utils/directTransfers.js.map +1 -0
- package/dist/esm/src/utils/eip712.d.ts +17 -0
- package/dist/esm/src/utils/eip712.js +39 -0
- package/dist/esm/src/utils/eip712.js.map +1 -0
- package/dist/esm/src/utils/encodeSwapStep.d.ts +4 -0
- package/dist/esm/src/utils/encodeSwapStep.js +58 -0
- package/dist/esm/src/utils/encodeSwapStep.js.map +1 -0
- package/dist/esm/src/utils/encodeV4Action.d.ts +7 -0
- package/dist/esm/src/utils/encodeV4Action.js +80 -0
- package/dist/esm/src/utils/encodeV4Action.js.map +1 -0
- package/dist/esm/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/esm/src/utils/getCurrencyAddress.js +5 -0
- package/dist/esm/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/esm/src/utils/inputTokens.d.ts +23 -0
- package/dist/esm/src/utils/inputTokens.js +51 -0
- package/dist/esm/src/utils/inputTokens.js.map +1 -0
- package/dist/esm/src/utils/normalizeEncodeSwapsSpec.d.ts +6 -0
- package/dist/esm/src/utils/normalizeEncodeSwapsSpec.js +27 -0
- package/dist/esm/src/utils/normalizeEncodeSwapsSpec.js.map +1 -0
- package/dist/esm/src/utils/numbers.d.ts +7 -0
- package/dist/esm/src/utils/numbers.js +19 -0
- package/dist/esm/src/utils/numbers.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.d.ts +3 -0
- package/dist/esm/src/utils/pathCurrency.js +23 -0
- package/dist/esm/src/utils/pathCurrency.js.map +1 -0
- package/dist/esm/src/utils/portionFees.d.ts +14 -0
- package/dist/esm/src/utils/portionFees.js +35 -0
- package/dist/esm/src/utils/portionFees.js.map +1 -0
- package/dist/esm/src/utils/routerBalanceSteps.d.ts +31 -0
- package/dist/esm/src/utils/routerBalanceSteps.js +282 -0
- package/dist/esm/src/utils/routerBalanceSteps.js.map +1 -0
- package/dist/esm/src/utils/routerCommands.d.ts +77 -0
- package/dist/esm/src/utils/routerCommands.js +326 -0
- package/dist/esm/src/utils/routerCommands.js.map +1 -0
- package/dist/esm/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/esm/src/utils/routerTradeAdapter.js +134 -0
- package/dist/esm/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/esm/src/utils/toV4URVersion.d.ts +3 -0
- package/dist/esm/src/utils/toV4URVersion.js +13 -0
- package/dist/esm/src/utils/toV4URVersion.js.map +1 -0
- package/dist/esm/src/utils/validateEncodeSwaps.d.ts +2 -0
- package/dist/esm/src/utils/validateEncodeSwaps.js +339 -0
- package/dist/esm/src/utils/validateEncodeSwaps.js.map +1 -0
- package/dist/types/src/entities/Command.d.ts +13 -0
- package/dist/types/src/entities/Command.d.ts.map +1 -0
- package/dist/types/src/entities/actions/across.d.ts +22 -0
- package/dist/types/src/entities/actions/across.d.ts.map +1 -0
- package/dist/types/src/entities/actions/index.d.ts +4 -0
- package/dist/types/src/entities/actions/index.d.ts.map +1 -0
- package/dist/types/src/entities/actions/uniswap.d.ts +95 -0
- package/dist/types/src/entities/actions/uniswap.d.ts.map +1 -0
- package/dist/types/src/entities/actions/unwrapWETH.d.ts +13 -0
- package/dist/types/src/entities/actions/unwrapWETH.d.ts.map +1 -0
- package/dist/types/src/entities/index.d.ts +3 -0
- package/dist/types/src/entities/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +20 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/kittycorn.d.ts +10 -0
- package/dist/types/src/kittycorn.d.ts.map +1 -0
- package/dist/types/src/swapRouter.d.ts +124 -0
- package/dist/types/src/swapRouter.d.ts.map +1 -0
- package/dist/types/src/types/encodeSwaps.d.ts +198 -0
- package/dist/types/src/types/encodeSwaps.d.ts.map +1 -0
- package/dist/types/src/utils/commandParser.d.ts +37 -0
- package/dist/types/src/utils/commandParser.d.ts.map +1 -0
- package/dist/types/src/utils/computeEncodeSwapsAmounts.d.ts +9 -0
- package/dist/types/src/utils/computeEncodeSwapsAmounts.d.ts.map +1 -0
- package/dist/types/src/utils/constants.d.ts +47 -0
- package/dist/types/src/utils/constants.d.ts.map +1 -0
- package/dist/types/src/utils/directTransfers.d.ts +16 -0
- package/dist/types/src/utils/directTransfers.d.ts.map +1 -0
- package/dist/types/src/utils/eip712.d.ts +18 -0
- package/dist/types/src/utils/eip712.d.ts.map +1 -0
- package/dist/types/src/utils/encodeSwapStep.d.ts +5 -0
- package/dist/types/src/utils/encodeSwapStep.d.ts.map +1 -0
- package/dist/types/src/utils/encodeV4Action.d.ts +8 -0
- package/dist/types/src/utils/encodeV4Action.d.ts.map +1 -0
- package/dist/types/src/utils/getCurrencyAddress.d.ts +3 -0
- package/dist/types/src/utils/getCurrencyAddress.d.ts.map +1 -0
- package/dist/types/src/utils/inputTokens.d.ts +24 -0
- package/dist/types/src/utils/inputTokens.d.ts.map +1 -0
- package/dist/types/src/utils/normalizeEncodeSwapsSpec.d.ts +7 -0
- package/dist/types/src/utils/normalizeEncodeSwapsSpec.d.ts.map +1 -0
- package/dist/types/src/utils/numbers.d.ts +8 -0
- package/dist/types/src/utils/numbers.d.ts.map +1 -0
- package/dist/types/src/utils/pathCurrency.d.ts +4 -0
- package/dist/types/src/utils/pathCurrency.d.ts.map +1 -0
- package/dist/types/src/utils/portionFees.d.ts +15 -0
- package/dist/types/src/utils/portionFees.d.ts.map +1 -0
- package/dist/types/src/utils/routerBalanceSteps.d.ts +32 -0
- package/dist/types/src/utils/routerBalanceSteps.d.ts.map +1 -0
- package/dist/types/src/utils/routerCommands.d.ts +78 -0
- package/dist/types/src/utils/routerCommands.d.ts.map +1 -0
- package/dist/types/src/utils/routerTradeAdapter.d.ts +74 -0
- package/dist/types/src/utils/routerTradeAdapter.d.ts.map +1 -0
- package/dist/types/src/utils/toV4URVersion.d.ts +4 -0
- package/dist/types/src/utils/toV4URVersion.d.ts.map +1 -0
- package/dist/types/src/utils/validateEncodeSwaps.d.ts +3 -0
- package/dist/types/src/utils/validateEncodeSwaps.d.ts.map +1 -0
- package/package.json +33 -52
- package/dist/entities/actions/uniswap.d.ts +0 -30
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -8
- package/dist/swapRouter.d.ts +0 -37
- package/dist/test/forge/writeInterop.d.ts +0 -2
- package/dist/test/utils/addresses.d.ts +0 -5
- package/dist/test/utils/hexToDecimalString.d.ts +0 -2
- package/dist/test/utils/permit2.d.ts +0 -7
- package/dist/test/utils/uniswapData.d.ts +0 -25
- package/dist/universal-router-sdk.cjs.development.js +0 -1500
- package/dist/universal-router-sdk.cjs.development.js.map +0 -1
- package/dist/universal-router-sdk.cjs.production.min.js +0 -2
- package/dist/universal-router-sdk.cjs.production.min.js.map +0 -1
- package/dist/universal-router-sdk.esm.js +0 -1493
- package/dist/universal-router-sdk.esm.js.map +0 -1
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapRouter = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
6
|
+
const UniversalRouter_json_1 = tslib_1.__importDefault(require("./abis/UniversalRouter.json"));
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
9
|
+
const v3_sdk_1 = require("@kittycorn-labs/v3-sdk");
|
|
10
|
+
const v4_sdk_1 = require("@kittycorn-labs/v4-sdk");
|
|
11
|
+
const sdk_core_1 = require("@kittycorn-labs/sdk-core");
|
|
12
|
+
const uniswap_1 = require("./entities/actions/uniswap");
|
|
13
|
+
const routerCommands_1 = require("./utils/routerCommands");
|
|
14
|
+
const inputTokens_1 = require("./utils/inputTokens");
|
|
15
|
+
const directTransfers_1 = require("./utils/directTransfers");
|
|
16
|
+
const constants_1 = require("./utils/constants");
|
|
17
|
+
const getCurrencyAddress_1 = require("./utils/getCurrencyAddress");
|
|
18
|
+
const numbers_1 = require("./utils/numbers");
|
|
19
|
+
const encodeSwapStep_1 = require("./utils/encodeSwapStep");
|
|
20
|
+
const routerBalanceSteps_1 = require("./utils/routerBalanceSteps");
|
|
21
|
+
const computeEncodeSwapsAmounts_1 = require("./utils/computeEncodeSwapsAmounts");
|
|
22
|
+
const normalizeEncodeSwapsSpec_1 = require("./utils/normalizeEncodeSwapsSpec");
|
|
23
|
+
const portionFees_1 = require("./utils/portionFees");
|
|
24
|
+
const validateEncodeSwaps_1 = require("./utils/validateEncodeSwaps");
|
|
25
|
+
const eip712_1 = require("./utils/eip712");
|
|
26
|
+
const DEFAULT_PROXY_DEADLINE_BUFFER_SECONDS = 30 * 60;
|
|
27
|
+
function isMint(options) {
|
|
28
|
+
return Object.keys(options).some((k) => k === 'recipient');
|
|
29
|
+
}
|
|
30
|
+
class SwapRouter {
|
|
31
|
+
static swapCallParameters(trades, options, bridgeOptions // Optional bridge parameters
|
|
32
|
+
) {
|
|
33
|
+
// TODO: use permit if signature included in swapOptions
|
|
34
|
+
const planner = new routerCommands_1.RoutePlanner();
|
|
35
|
+
const trade = new uniswap_1.UniswapTrade(trades, options);
|
|
36
|
+
const inputCurrency = trade.trade.inputAmount.currency;
|
|
37
|
+
if (options.tokenTransferMode === uniswap_1.TokenTransferMode.ApproveProxy) {
|
|
38
|
+
(0, tiny_invariant_1.default)(!inputCurrency.isNative, 'PROXY_NATIVE_INPUT: SwapProxy only supports ERC20 input');
|
|
39
|
+
(0, tiny_invariant_1.default)(!!options.chainId, 'PROXY_MISSING_CHAIN_ID: chainId required when tokenTransferMode is ApproveProxy');
|
|
40
|
+
(0, tiny_invariant_1.default)(!options.inputTokenPermit, 'PROXY_PERMIT_CONFLICT: Permit2 not used with SwapProxy');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
(0, tiny_invariant_1.default)(!(inputCurrency.isNative && !!options.inputTokenPermit), 'NATIVE_INPUT_PERMIT');
|
|
44
|
+
if (options.inputTokenPermit) {
|
|
45
|
+
(0, inputTokens_1.encodePermit)(planner, options.inputTokenPermit);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let nativeCurrencyValue;
|
|
49
|
+
if (inputCurrency.isNative) {
|
|
50
|
+
// routerBalanceInput: the delivered amount is unknown at encode time — the executor
|
|
51
|
+
// attaches it as msg.value on execute() (raw transfers to the router revert), so the
|
|
52
|
+
// encoded value is zero and the plan wraps whatever arrives.
|
|
53
|
+
nativeCurrencyValue = options.routerBalanceInput
|
|
54
|
+
? bignumber_1.BigNumber.from(0)
|
|
55
|
+
: bignumber_1.BigNumber.from(trade.trade.maximumAmountIn(options.slippageTolerance).quotient.toString());
|
|
56
|
+
}
|
|
57
|
+
else if (options.nativeErc20Input) {
|
|
58
|
+
// input token is the chain's native-ERC20 gas token (e.g. Arc USDC predeploy):
|
|
59
|
+
// fund the router via msg.value, scaled from token decimals to 18-decimal native units
|
|
60
|
+
(0, tiny_invariant_1.default)(inputCurrency.decimals <= 18, 'NATIVE_ERC20_INPUT_DECIMALS');
|
|
61
|
+
nativeCurrencyValue = bignumber_1.BigNumber.from(trade.trade.maximumAmountIn(options.slippageTolerance).quotient.toString()).mul(bignumber_1.BigNumber.from(10).pow(18 - inputCurrency.decimals));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
nativeCurrencyValue = bignumber_1.BigNumber.from(0);
|
|
65
|
+
}
|
|
66
|
+
trade.encode(planner, { allowRevert: false });
|
|
67
|
+
// Add bridge commands if provided
|
|
68
|
+
if (bridgeOptions) {
|
|
69
|
+
for (const bridge of bridgeOptions) {
|
|
70
|
+
planner.addAcrossBridge(bridge);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (options.tokenTransferMode === uniswap_1.TokenTransferMode.ApproveProxy) {
|
|
74
|
+
return SwapRouter.encodeProxyPlan(planner, trade, options);
|
|
75
|
+
}
|
|
76
|
+
return SwapRouter.encodePlan(planner, nativeCurrencyValue, {
|
|
77
|
+
deadline: options.deadlineOrPreviousBlockhash ? bignumber_1.BigNumber.from(options.deadlineOrPreviousBlockhash) : undefined,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Encodes router-provided swap steps inside the SDK safety envelope.
|
|
82
|
+
*
|
|
83
|
+
* Routers own `swapSteps` (V2/V3/V4 swaps, plus any `WRAP_ETH` / `UNWRAP_WETH` required by the route).
|
|
84
|
+
* The SDK owns ingress, fees, final settlement, exact-output refund, and optional `safeMode`.
|
|
85
|
+
*
|
|
86
|
+
* Two validation regimes:
|
|
87
|
+
* - Default (router custody): the single SDK ingress pull is the only user withdrawal and every step
|
|
88
|
+
* recipient must be the router; the final SWEEP floor enforces the minimum output.
|
|
89
|
+
* - `allowDirectTransfers`: steps may pull input straight from the user (`payerIsUser`,
|
|
90
|
+
* v4 SETTLE_ALL) and pay output straight to `recipient` (step recipients, v4 TAKE/TAKE_ALL,
|
|
91
|
+
* UNWRAP_WETH). Direct pulls may total at most exactOrMaxAmountIn — ingress pulls the
|
|
92
|
+
* remainder — and direct output minimums count toward the SWEEP floor. Portion fees still
|
|
93
|
+
* require output custody. Step amounts are never trusted, only counted or capped.
|
|
94
|
+
*
|
|
95
|
+
* Direct-transfer caveats:
|
|
96
|
+
* - Fee-on-transfer output: output minimums bind the amount each swap *produces* (pre-transfer), not the
|
|
97
|
+
* recipient's post-tax balance. A FoT token's own transfer tax reduces the final balance below the
|
|
98
|
+
* minimum — inherent to such tokens and expected when swapping into one, not a shortfall to guard.
|
|
99
|
+
* - A flat fee is a plain TRANSFER, so routing must keep at least the fee amount in router custody
|
|
100
|
+
* (not route 100% of output directly), or the fee TRANSFER reverts.
|
|
101
|
+
*
|
|
102
|
+
* Router contract: end with final output in `spec.routing.outputToken`; for `EXACT_OUTPUT`, unused input
|
|
103
|
+
* must end in `spec.routing.inputToken`. Don't include a top-level `SWEEP` — the SDK appends settlement,
|
|
104
|
+
* refund, and safeMode sweeps itself.
|
|
105
|
+
*
|
|
106
|
+
* Amount convention: on `EXACT_INPUT`, `spec.routing.quote` is the GROSS output (before fees).
|
|
107
|
+
* The fee cascade is deducted from it when sizing the sweep floor; passing a net
|
|
108
|
+
* (post-fee) quote double-counts the fees and floors the sweep below the real minimum.
|
|
109
|
+
*/
|
|
110
|
+
static encodeSwaps(spec, swapSteps) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
const normalizedSpec = (0, normalizeEncodeSwapsSpec_1.normalizeEncodeSwapsSpec)(spec);
|
|
113
|
+
const planner = new routerCommands_1.RoutePlanner();
|
|
114
|
+
(0, validateEncodeSwaps_1.validateEncodeSwaps)(normalizedSpec, swapSteps);
|
|
115
|
+
const { exactOrMaxAmountIn, netMinOrExactAmountOut } = (0, computeEncodeSwapsAmounts_1.computeEncodeSwapsAmounts)(normalizedSpec);
|
|
116
|
+
const { routing: { inputToken, outputToken }, } = normalizedSpec;
|
|
117
|
+
// Router-balance funding: assert the floor before anything spends, so an under-funded
|
|
118
|
+
// router reverts up front rather than swapping a short amount. A native balance input
|
|
119
|
+
// has no balance-check command, so its floor is asserted post-wrap as WETH instead
|
|
120
|
+
// (inside the step loop below).
|
|
121
|
+
const nativeBalanceInput = !!normalizedSpec.routerBalanceInput && inputToken.isNative;
|
|
122
|
+
const routerBalanceFloor = (_a = normalizedSpec.routerBalanceInput) === null || _a === void 0 ? void 0 : _a.minimumAmount;
|
|
123
|
+
const emitRouterBalanceFloor = () => planner.addCommand(routerCommands_1.CommandType.BALANCE_CHECK_ERC20, [
|
|
124
|
+
// BALANCE_CHECK_ERC20 reads `owner` verbatim (no sentinel resolution), so it
|
|
125
|
+
// needs the router's real address; validateEncodeSwaps requires chainId.
|
|
126
|
+
(0, constants_1.UNIVERSAL_ROUTER_ADDRESS)(normalizedSpec.urVersion, normalizedSpec.chainId),
|
|
127
|
+
inputToken.wrapped.address,
|
|
128
|
+
routerBalanceFloor,
|
|
129
|
+
], false, normalizedSpec.urVersion);
|
|
130
|
+
if (routerBalanceFloor !== undefined && !nativeBalanceInput) {
|
|
131
|
+
emitRouterBalanceFloor();
|
|
132
|
+
}
|
|
133
|
+
// Ingress: pull funds into the router. Native input is paid as msg.value at the bottom
|
|
134
|
+
// instead of via Permit2 — as is a native-ERC20 gas-token input (nativeErc20Input);
|
|
135
|
+
// ApproveProxy ingress is handled by the outer wrapper at the end. A router-balance
|
|
136
|
+
// swap is funded by a third party in the same transaction, so it has no ingress at all.
|
|
137
|
+
if (normalizedSpec.tokenTransferMode === uniswap_1.TokenTransferMode.Permit2 && !normalizedSpec.routerBalanceInput) {
|
|
138
|
+
if (normalizedSpec.permit) {
|
|
139
|
+
(0, inputTokens_1.encodePermit)(planner, normalizedSpec.permit);
|
|
140
|
+
}
|
|
141
|
+
if (!inputToken.isNative && !normalizedSpec.nativeErc20Input) {
|
|
142
|
+
// user-paid steps draw part of the budget straight from the wallet; ingress pulls only the rest
|
|
143
|
+
const ingressAmount = exactOrMaxAmountIn.sub((0, directTransfers_1.sumUserPaidMax)(swapSteps));
|
|
144
|
+
if (ingressAmount.gt(0)) {
|
|
145
|
+
planner.addCommand(routerCommands_1.CommandType.PERMIT2_TRANSFER_FROM, [(0, getCurrencyAddress_1.getCurrencyAddress)(inputToken), constants_1.ROUTER_AS_RECIPIENT, ingressAmount], false, normalizedSpec.urVersion);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// With router-balance funding the delivered amount is unknown at encode time, so the
|
|
150
|
+
// input-spending first hop is rewritten to the CONTRACT_BALANCE sentinel (v4: settle
|
|
151
|
+
// the whole balance, swap the open delta).
|
|
152
|
+
let stepsToEncode = swapSteps;
|
|
153
|
+
if (nativeBalanceInput) {
|
|
154
|
+
stepsToEncode = (0, routerBalanceSteps_1.applyNativeRouterBalanceInputToSteps)(swapSteps, inputToken.wrapped.address);
|
|
155
|
+
}
|
|
156
|
+
else if (normalizedSpec.routerBalanceInput) {
|
|
157
|
+
stepsToEncode = (0, routerBalanceSteps_1.applyRouterBalanceInputToSteps)(swapSteps, (0, getCurrencyAddress_1.getCurrencyAddress)(inputToken), (_b = sdk_core_1.WETH9[inputToken.chainId]) === null || _b === void 0 ? void 0 : _b.address);
|
|
158
|
+
}
|
|
159
|
+
stepsToEncode.forEach((step, index) => {
|
|
160
|
+
(0, encodeSwapStep_1.encodeSwapStep)(planner, step, normalizedSpec.urVersion);
|
|
161
|
+
// Native balance input: the WRAP_ETH just consumed the whole native balance, so the
|
|
162
|
+
// WETH floor is checkable only now.
|
|
163
|
+
if (index === 0 && nativeBalanceInput && routerBalanceFloor !== undefined) {
|
|
164
|
+
emitRouterBalanceFloor();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
// One command per recipient ahead of the settlement SWEEP, rescaled from gross fractions so each recipient gets its stated share.
|
|
168
|
+
const useFullPrecision = (0, constants_1.isAtLeastV2_1_1)(normalizedSpec.urVersion);
|
|
169
|
+
const scaledPortions = (0, portionFees_1.scalePortionFees)((0, normalizeEncodeSwapsSpec_1.toPortionFeeList)(normalizedSpec.fee));
|
|
170
|
+
let portionIndex = 0;
|
|
171
|
+
for (const fee of (0, normalizeEncodeSwapsSpec_1.toFeeList)(normalizedSpec.fee)) {
|
|
172
|
+
if (fee.kind === 'portion') {
|
|
173
|
+
const scaledFee = scaledPortions[portionIndex++].scaledFee;
|
|
174
|
+
planner.addCommand(useFullPrecision ? routerCommands_1.CommandType.PAY_PORTION_FULL_PRECISION : routerCommands_1.CommandType.PAY_PORTION, [
|
|
175
|
+
(0, getCurrencyAddress_1.getCurrencyAddress)(outputToken),
|
|
176
|
+
fee.recipient,
|
|
177
|
+
useFullPrecision ? (0, numbers_1.encodeFee1e18)(scaledFee) : (0, numbers_1.encodeFeeBips)(scaledFee),
|
|
178
|
+
], false, normalizedSpec.urVersion);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
planner.addCommand(routerCommands_1.CommandType.TRANSFER, [(0, getCurrencyAddress_1.getCurrencyAddress)(outputToken), fee.recipient, fee.amount], false, normalizedSpec.urVersion);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Assumes routers already normalized final gross output into `routing.outputToken`.
|
|
185
|
+
// Direct-output minimums (contract-enforced, delivered straight to the recipient)
|
|
186
|
+
// reduce the floor; the sweep remains unless `omitRedundantSettlementSweep` proves it redundant.
|
|
187
|
+
const sweepFloor = normalizedSpec.allowDirectTransfers
|
|
188
|
+
? (0, directTransfers_1.directTransferSweepFloor)(normalizedSpec, netMinOrExactAmountOut, swapSteps, (0, getCurrencyAddress_1.getCurrencyAddress)(outputToken))
|
|
189
|
+
: netMinOrExactAmountOut;
|
|
190
|
+
if (!(0, directTransfers_1.isSettlementSweepRedundant)(normalizedSpec, swapSteps, sweepFloor)) {
|
|
191
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [(0, getCurrencyAddress_1.getCurrencyAddress)(outputToken), normalizedSpec.recipient, sweepFloor], false, normalizedSpec.urVersion);
|
|
192
|
+
}
|
|
193
|
+
// Assumes routers already normalized unused input into `routing.inputToken`.
|
|
194
|
+
// Exact-output uses max input, so any unused slippage padding is refunded to the recipient.
|
|
195
|
+
// For nativeErc20Input the leftover lives in the router's native balance (18 decimals), so
|
|
196
|
+
// sweep it as native: an ERC20 sweep would floor to the token's decimals and strand dust.
|
|
197
|
+
if (normalizedSpec.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
198
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [normalizedSpec.nativeErc20Input ? constants_1.ETH_ADDRESS : (0, getCurrencyAddress_1.getCurrencyAddress)(inputToken), normalizedSpec.recipient, 0], false, normalizedSpec.urVersion);
|
|
199
|
+
}
|
|
200
|
+
// safeMode: zero-min ETH sweep recovers any native funds left on the router (dust or unintended msg.value)
|
|
201
|
+
// Native balance input always sweeps trailing ETH dust to the recipient: the funder is
|
|
202
|
+
// a third party, so anything left on the router would otherwise be stranded or swept
|
|
203
|
+
// by a stranger.
|
|
204
|
+
if (normalizedSpec.safeMode || nativeBalanceInput) {
|
|
205
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [constants_1.ETH_ADDRESS, normalizedSpec.recipient, 0], false, normalizedSpec.urVersion);
|
|
206
|
+
}
|
|
207
|
+
// ApproveProxy wraps the inner UR plan in an outer proxy.execute() that handles ingress upstream.
|
|
208
|
+
if (normalizedSpec.tokenTransferMode === uniswap_1.TokenTransferMode.ApproveProxy) {
|
|
209
|
+
return SwapRouter.encodeProxyCall(planner, (0, getCurrencyAddress_1.getCurrencyAddress)(inputToken), exactOrMaxAmountIn, normalizedSpec.chainId, normalizedSpec.urVersion, normalizedSpec.deadline);
|
|
210
|
+
}
|
|
211
|
+
// Native input pays via msg.value; ERC20 input is already in the router via Permit2.
|
|
212
|
+
// A native-ERC20 gas-token input (e.g. Arc USDC predeploy) also pays via msg.value,
|
|
213
|
+
// scaled from token decimals to 18-decimal native units.
|
|
214
|
+
let nativeCurrencyValue;
|
|
215
|
+
if (inputToken.isNative) {
|
|
216
|
+
// routerBalanceInput: the delivered amount is unknown at encode time — the executor
|
|
217
|
+
// attaches it as msg.value on execute() (raw transfers to the router revert), so the
|
|
218
|
+
// encoded value is zero and the plan wraps whatever arrives.
|
|
219
|
+
nativeCurrencyValue = normalizedSpec.routerBalanceInput ? bignumber_1.BigNumber.from(0) : exactOrMaxAmountIn;
|
|
220
|
+
}
|
|
221
|
+
else if (normalizedSpec.nativeErc20Input) {
|
|
222
|
+
nativeCurrencyValue = exactOrMaxAmountIn.mul(bignumber_1.BigNumber.from(10).pow(18 - inputToken.decimals));
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
nativeCurrencyValue = bignumber_1.BigNumber.from(0);
|
|
226
|
+
}
|
|
227
|
+
return SwapRouter.encodePlan(planner, nativeCurrencyValue, {
|
|
228
|
+
deadline: normalizedSpec.deadline ? bignumber_1.BigNumber.from(normalizedSpec.deadline) : undefined,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Generate EIP712 payload for signed execution (no signing performed)
|
|
233
|
+
* Decodes existing execute() calldata and prepares it for signing
|
|
234
|
+
*
|
|
235
|
+
* @param calldata The calldata from swapCallParameters() or similar
|
|
236
|
+
* @param signedOptions Options for signed execution (intent, data, sender, nonce)
|
|
237
|
+
* @param deadline The deadline timestamp
|
|
238
|
+
* @param chainId The chain ID
|
|
239
|
+
* @param routerAddress The Universal Router contract address
|
|
240
|
+
* @returns EIP712 payload ready to be signed externally
|
|
241
|
+
*/
|
|
242
|
+
static getExecuteSignedPayload(calldata, signedOptions, deadline, chainId, routerAddress) {
|
|
243
|
+
// Decode the execute() calldata to extract commands and inputs
|
|
244
|
+
// Try to decode with deadline first, then without
|
|
245
|
+
let decoded;
|
|
246
|
+
let commands;
|
|
247
|
+
let inputs;
|
|
248
|
+
try {
|
|
249
|
+
decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[],uint256)', calldata);
|
|
250
|
+
commands = decoded.commands;
|
|
251
|
+
inputs = decoded.inputs;
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
// Try without deadline
|
|
255
|
+
decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[])', calldata);
|
|
256
|
+
commands = decoded.commands;
|
|
257
|
+
inputs = decoded.inputs;
|
|
258
|
+
}
|
|
259
|
+
// Use provided nonce or generate random one
|
|
260
|
+
const nonce = signedOptions.nonce || (0, eip712_1.generateNonce)();
|
|
261
|
+
// sender is provided directly (address(0) = skip verification)
|
|
262
|
+
const sender = signedOptions.sender;
|
|
263
|
+
const domain = (0, eip712_1.getUniversalRouterDomain)(chainId, routerAddress);
|
|
264
|
+
const intent = signedOptions.intent;
|
|
265
|
+
const data = signedOptions.data;
|
|
266
|
+
const deadlineStr = bignumber_1.BigNumber.from(deadline).toString();
|
|
267
|
+
const value = {
|
|
268
|
+
commands,
|
|
269
|
+
inputs,
|
|
270
|
+
intent,
|
|
271
|
+
data,
|
|
272
|
+
sender,
|
|
273
|
+
nonce,
|
|
274
|
+
deadline: deadlineStr,
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
domain,
|
|
278
|
+
types: eip712_1.EXECUTE_SIGNED_TYPES,
|
|
279
|
+
value,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Encode executeSigned() call with signature
|
|
284
|
+
*
|
|
285
|
+
* @param calldata The original calldata from swapCallParameters()
|
|
286
|
+
* @param signature The signature obtained from external signing
|
|
287
|
+
* @param signedOptions The same options used in getExecuteSignedPayload()
|
|
288
|
+
* @param deadline The deadline timestamp
|
|
289
|
+
* @param nativeCurrencyValue The native currency value (ETH) to send
|
|
290
|
+
* @returns Method parameters for executeSigned()
|
|
291
|
+
*/
|
|
292
|
+
static encodeExecuteSigned(calldata, signature, signedOptions, deadline, nativeCurrencyValue = bignumber_1.BigNumber.from(0)) {
|
|
293
|
+
// Decode the execute() calldata to extract commands and inputs
|
|
294
|
+
// Try to decode with deadline first, then without
|
|
295
|
+
let decoded;
|
|
296
|
+
let commands;
|
|
297
|
+
let inputs;
|
|
298
|
+
try {
|
|
299
|
+
decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[],uint256)', calldata);
|
|
300
|
+
commands = decoded.commands;
|
|
301
|
+
inputs = decoded.inputs;
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
// Try without deadline
|
|
305
|
+
decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[])', calldata);
|
|
306
|
+
commands = decoded.commands;
|
|
307
|
+
inputs = decoded.inputs;
|
|
308
|
+
}
|
|
309
|
+
// Use provided nonce (must match what was signed)
|
|
310
|
+
// Nonce must match what was signed - require it to be provided
|
|
311
|
+
if (!signedOptions.nonce) {
|
|
312
|
+
throw new Error('Nonce is required for encodeExecuteSigned - use the nonce from getExecuteSignedPayload');
|
|
313
|
+
}
|
|
314
|
+
const nonce = signedOptions.nonce;
|
|
315
|
+
// Determine verifySender based on sender address
|
|
316
|
+
const verifySender = signedOptions.sender !== '0x0000000000000000000000000000000000000000';
|
|
317
|
+
// Encode executeSigned function call using the Universal Router v2.1 ABI
|
|
318
|
+
const signedCalldata = SwapRouter.INTERFACE.encodeFunctionData('executeSigned', [
|
|
319
|
+
commands,
|
|
320
|
+
inputs,
|
|
321
|
+
signedOptions.intent,
|
|
322
|
+
signedOptions.data,
|
|
323
|
+
verifySender,
|
|
324
|
+
nonce,
|
|
325
|
+
signature,
|
|
326
|
+
deadline,
|
|
327
|
+
]);
|
|
328
|
+
return { calldata: signedCalldata, value: nativeCurrencyValue.toHexString() };
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Builds the call parameters for a migration from a V3 position to a V4 position.
|
|
332
|
+
* Some requirements of the parameters:
|
|
333
|
+
* - v3RemoveLiquidityOptions.collectOptions.recipient must equal v4PositionManager
|
|
334
|
+
* - v3RemoveLiquidityOptions.liquidityPercentage must be 100%
|
|
335
|
+
* - input pool and output pool must have the same tokens
|
|
336
|
+
* - V3 NFT must be approved, or a valid v3RemoveLiquidityOptions.permit must be provided whose spender is the
|
|
337
|
+
* Universal Router for `urVersion` (defaults to V2_0)
|
|
338
|
+
*/
|
|
339
|
+
static migrateV3ToV4CallParameters(options, positionManagerOverride) {
|
|
340
|
+
var _a;
|
|
341
|
+
const v4Pool = options.outputPosition.pool;
|
|
342
|
+
const v3Token0 = options.inputPosition.pool.token0;
|
|
343
|
+
const v3Token1 = options.inputPosition.pool.token1;
|
|
344
|
+
const v4PositionManagerAddress = positionManagerOverride !== null && positionManagerOverride !== void 0 ? positionManagerOverride : sdk_core_1.CHAIN_TO_ADDRESSES_MAP[v4Pool.chainId].v4PositionManagerAddress;
|
|
345
|
+
const urVersion = (_a = options.urVersion) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_UR_VERSION;
|
|
346
|
+
// owner of the v3 nft must be the receiver of the v4 nft
|
|
347
|
+
// validate the parameters
|
|
348
|
+
// the position-manager commands this plan emits do not exist on the 1.2 router
|
|
349
|
+
(0, tiny_invariant_1.default)((0, constants_1.isAtLeastV2_0)(urVersion), 'UR_VERSION_TOO_OLD');
|
|
350
|
+
if (v4Pool.currency0.isNative) {
|
|
351
|
+
(0, tiny_invariant_1.default)((v4Pool.currency0.wrapped.equals(v3Token0) && v4Pool.currency1.equals(v3Token1)) ||
|
|
352
|
+
(v4Pool.currency0.wrapped.equals(v3Token1) && v4Pool.currency1.equals(v3Token0)), 'TOKEN_MISMATCH');
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
(0, tiny_invariant_1.default)(v3Token0 === v4Pool.token0, 'TOKEN0_MISMATCH');
|
|
356
|
+
(0, tiny_invariant_1.default)(v3Token1 === v4Pool.token1, 'TOKEN1_MISMATCH');
|
|
357
|
+
}
|
|
358
|
+
(0, tiny_invariant_1.default)(options.v3RemoveLiquidityOptions.liquidityPercentage.equalTo(new sdk_core_1.Percent(100, 100)), 'FULL_REMOVAL_REQUIRED');
|
|
359
|
+
(0, tiny_invariant_1.default)(options.v3RemoveLiquidityOptions.burnToken == true, 'BURN_TOKEN_REQUIRED');
|
|
360
|
+
(0, tiny_invariant_1.default)(options.v3RemoveLiquidityOptions.collectOptions.recipient === v4PositionManagerAddress, 'RECIPIENT_NOT_POSITION_MANAGER');
|
|
361
|
+
(0, tiny_invariant_1.default)(isMint(options.v4AddLiquidityOptions), 'MINT_REQUIRED');
|
|
362
|
+
(0, tiny_invariant_1.default)(options.v4AddLiquidityOptions.migrate, 'MIGRATE_REQUIRED');
|
|
363
|
+
const planner = new routerCommands_1.RoutePlanner();
|
|
364
|
+
// to prevent reentrancy by the pool hook, we initialize the v4 pool before moving funds
|
|
365
|
+
if (options.v4AddLiquidityOptions.createPool) {
|
|
366
|
+
const poolKey = v4_sdk_1.Pool.getPoolKey(v4Pool.currency0, v4Pool.currency1, v4Pool.fee, v4Pool.tickSpacing, v4Pool.hooks);
|
|
367
|
+
planner.addCommand(routerCommands_1.CommandType.V4_INITIALIZE_POOL, [poolKey, v4Pool.sqrtRatioX96.toString()]);
|
|
368
|
+
// remove createPool setting, so that it doesnt get encoded again later
|
|
369
|
+
delete options.v4AddLiquidityOptions.createPool;
|
|
370
|
+
}
|
|
371
|
+
// add position permit to the universal router planner
|
|
372
|
+
if (options.v3RemoveLiquidityOptions.permit) {
|
|
373
|
+
// permit spender must be the router that executes this migrate
|
|
374
|
+
const universalRouterAddress = (0, constants_1.UNIVERSAL_ROUTER_ADDRESS)(urVersion, options.inputPosition.pool.chainId);
|
|
375
|
+
(0, tiny_invariant_1.default)(universalRouterAddress.toLowerCase() === options.v3RemoveLiquidityOptions.permit.spender.toLowerCase(), 'INVALID_SPENDER');
|
|
376
|
+
// don't need to transfer it because v3posm uses isApprovedOrOwner()
|
|
377
|
+
(0, inputTokens_1.encodeV3PositionPermit)(planner, options.v3RemoveLiquidityOptions.permit, options.v3RemoveLiquidityOptions.tokenId);
|
|
378
|
+
// remove permit so that multicall doesnt add it again
|
|
379
|
+
delete options.v3RemoveLiquidityOptions.permit;
|
|
380
|
+
}
|
|
381
|
+
// encode v3 withdraw
|
|
382
|
+
const v3RemoveParams = v3_sdk_1.NonfungiblePositionManager.removeCallParameters(options.inputPosition, options.v3RemoveLiquidityOptions);
|
|
383
|
+
const v3Calls = v3_sdk_1.Multicall.decodeMulticall(v3RemoveParams.calldata);
|
|
384
|
+
for (const v3Call of v3Calls) {
|
|
385
|
+
// slice selector - 0x + 4 bytes = 10 characters
|
|
386
|
+
const selector = v3Call.slice(0, 10);
|
|
387
|
+
(0, tiny_invariant_1.default)(selector == v3_sdk_1.NonfungiblePositionManager.INTERFACE.getSighash('collect') ||
|
|
388
|
+
selector == v3_sdk_1.NonfungiblePositionManager.INTERFACE.getSighash('decreaseLiquidity') ||
|
|
389
|
+
selector == v3_sdk_1.NonfungiblePositionManager.INTERFACE.getSighash('burn'), 'INVALID_V3_CALL: ' + selector);
|
|
390
|
+
planner.addCommand(routerCommands_1.CommandType.V3_POSITION_MANAGER_CALL, [v3Call]);
|
|
391
|
+
}
|
|
392
|
+
// encode v4 mint
|
|
393
|
+
const v4AddParams = v4_sdk_1.V4PositionManager.addCallParameters(options.outputPosition, options.v4AddLiquidityOptions);
|
|
394
|
+
// only modifyLiquidities can be called by the UniversalRouter
|
|
395
|
+
const selector = v4AddParams.calldata.slice(0, 10);
|
|
396
|
+
(0, tiny_invariant_1.default)(selector == v4_sdk_1.V4PositionManager.INTERFACE.getSighash('modifyLiquidities'), 'INVALID_V4_CALL: ' + selector);
|
|
397
|
+
planner.addCommand(routerCommands_1.CommandType.V4_POSITION_MANAGER_CALL, [v4AddParams.calldata]);
|
|
398
|
+
return SwapRouter.encodePlan(planner, bignumber_1.BigNumber.from(0), {
|
|
399
|
+
deadline: bignumber_1.BigNumber.from(options.v4AddLiquidityOptions.deadline),
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Encodes a planned route into a method name and parameters for the Router contract.
|
|
404
|
+
* @param planner the planned route
|
|
405
|
+
* @param nativeCurrencyValue the native currency value of the planned route
|
|
406
|
+
* @param config the router config
|
|
407
|
+
*/
|
|
408
|
+
static encodePlan(planner, nativeCurrencyValue, config = {}) {
|
|
409
|
+
const { commands, inputs } = planner;
|
|
410
|
+
const functionSignature = !!config.deadline ? 'execute(bytes,bytes[],uint256)' : 'execute(bytes,bytes[])';
|
|
411
|
+
const parameters = !!config.deadline ? [commands, inputs, config.deadline] : [commands, inputs];
|
|
412
|
+
const calldata = SwapRouter.INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
413
|
+
return { calldata, value: nativeCurrencyValue.toHexString() };
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Wraps an inner UR plan in calldata targeting the SwapProxy contract.
|
|
417
|
+
* The proxy pulls ERC20 tokens from the user into the UR, then executes commands.
|
|
418
|
+
*/
|
|
419
|
+
static encodeProxyPlan(planner, trade, options) {
|
|
420
|
+
var _a;
|
|
421
|
+
return SwapRouter.encodeProxyCall(planner, trade.trade.inputAmount.currency.address, bignumber_1.BigNumber.from(trade.trade.maximumAmountIn(options.slippageTolerance).quotient.toString()), options.chainId, (_a = options.urVersion) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_UR_VERSION, options.deadlineOrPreviousBlockhash ? bignumber_1.BigNumber.from(options.deadlineOrPreviousBlockhash) : undefined);
|
|
422
|
+
}
|
|
423
|
+
static encodeProxyCall(planner, inputToken, inputAmount, chainId, urVersion, deadline) {
|
|
424
|
+
const { commands, inputs } = planner;
|
|
425
|
+
const routerAddress = (0, constants_1.UNIVERSAL_ROUTER_ADDRESS)(urVersion, chainId);
|
|
426
|
+
const resolvedDeadline = deadline
|
|
427
|
+
? bignumber_1.BigNumber.from(deadline)
|
|
428
|
+
: bignumber_1.BigNumber.from(Math.floor(Date.now() / 1000) + DEFAULT_PROXY_DEADLINE_BUFFER_SECONDS); // 30 min default
|
|
429
|
+
const calldata = SwapRouter.PROXY_INTERFACE.encodeFunctionData('execute', [
|
|
430
|
+
routerAddress,
|
|
431
|
+
inputToken,
|
|
432
|
+
inputAmount,
|
|
433
|
+
commands,
|
|
434
|
+
inputs,
|
|
435
|
+
resolvedDeadline,
|
|
436
|
+
]);
|
|
437
|
+
return { calldata, value: bignumber_1.BigNumber.from(0).toHexString() };
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
exports.SwapRouter = SwapRouter;
|
|
441
|
+
SwapRouter.INTERFACE = new abi_1.Interface(UniversalRouter_json_1.default.abi);
|
|
442
|
+
SwapRouter.PROXY_INTERFACE = new abi_1.Interface([
|
|
443
|
+
'function execute(address router, address token, uint256 amount, bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external',
|
|
444
|
+
]);
|
|
445
|
+
//# sourceMappingURL=swapRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swapRouter.js","sourceRoot":"","sources":["../../../src/swapRouter.ts"],"names":[],"mappings":";;;;AAAA,4EAAsC;AACtC,+FAAyD;AACzD,4CAA8C;AAC9C,wDAAkE;AAClE,mDAM+B;AAC/B,mDAO+B;AAE/B,uDAA2H;AAC3H,wDAAyF;AAGzF,2DAAkE;AAClE,qDAA0E;AAC1E,6DAA8G;AAC9G,iDAQ0B;AAC1B,mEAA+D;AAC/D,6CAA8D;AAC9D,2DAAuD;A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