@uniswap/router-sdk 1.0.0-beta.7 → 1.0.2
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/approveAndCall.d.ts +22 -0
- package/dist/constants.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/router-sdk.cjs.development.js +198 -35
- package/dist/router-sdk.cjs.development.js.map +1 -1
- package/dist/router-sdk.cjs.production.min.js +1 -1
- package/dist/router-sdk.cjs.production.min.js.map +1 -1
- package/dist/router-sdk.esm.js +209 -45
- package/dist/router-sdk.esm.js.map +1 -1
- package/dist/swapRouter.d.ts +10 -1
- package/package.json +2 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { Currency, Token } from '@uniswap/sdk-core';
|
|
3
|
+
export declare enum ApprovalTypes {
|
|
4
|
+
NOT_REQUIRED = 0,
|
|
5
|
+
MAX = 1,
|
|
6
|
+
MAX_MINUS_ONE = 2,
|
|
7
|
+
ZERO_THEN_MAX = 3,
|
|
8
|
+
ZERO_THEN_MAX_MINUS_ONE = 4
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class ApproveAndCall {
|
|
11
|
+
static INTERFACE: Interface;
|
|
12
|
+
/**
|
|
13
|
+
* Cannot be constructed.
|
|
14
|
+
*/
|
|
15
|
+
private constructor();
|
|
16
|
+
static encodeApproveMax(token: Token): string;
|
|
17
|
+
static encodeApproveMaxMinusOne(token: Token): string;
|
|
18
|
+
static encodeApproveZeroThenMax(token: Token): string;
|
|
19
|
+
static encodeApproveZeroThenMaxMinusOne(token: Token): string;
|
|
20
|
+
static encodeCallPositionManager(calldatas: string[]): string;
|
|
21
|
+
static encodeApprove(token: Currency, approvalType: ApprovalTypes): string;
|
|
22
|
+
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import JSBI from 'jsbi';
|
|
2
|
-
export declare const MSG_SENDER = "
|
|
3
|
-
export declare const ADDRESS_THIS = "
|
|
2
|
+
export declare const MSG_SENDER = "0x0000000000000000000000000000000000000001";
|
|
3
|
+
export declare const ADDRESS_THIS = "0x0000000000000000000000000000000000000002";
|
|
4
4
|
export declare const ZERO: JSBI;
|
|
5
5
|
export declare const ONE: JSBI;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,19 +6,84 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var JSBI = _interopDefault(require('jsbi'));
|
|
8
8
|
var abi = require('@ethersproject/abi');
|
|
9
|
-
var
|
|
9
|
+
var invariant = _interopDefault(require('tiny-invariant'));
|
|
10
|
+
var IApproveAndCall_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json');
|
|
10
11
|
var v3Sdk = require('@uniswap/v3-sdk');
|
|
12
|
+
var IMulticallExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json');
|
|
11
13
|
var sdkCore = require('@uniswap/sdk-core');
|
|
12
14
|
var IPeripheryPaymentsWithFeeExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json');
|
|
13
15
|
var ISwapRouter02_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json');
|
|
14
16
|
var v2Sdk = require('@uniswap/v2-sdk');
|
|
15
|
-
var invariant = _interopDefault(require('tiny-invariant'));
|
|
16
17
|
|
|
17
|
-
var MSG_SENDER = '
|
|
18
|
-
var ADDRESS_THIS = '
|
|
18
|
+
var MSG_SENDER = '0x0000000000000000000000000000000000000001';
|
|
19
|
+
var ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
|
|
19
20
|
var ZERO = /*#__PURE__*/JSBI.BigInt(0);
|
|
20
21
|
var ONE = /*#__PURE__*/JSBI.BigInt(1);
|
|
21
22
|
|
|
23
|
+
(function (ApprovalTypes) {
|
|
24
|
+
ApprovalTypes[ApprovalTypes["NOT_REQUIRED"] = 0] = "NOT_REQUIRED";
|
|
25
|
+
ApprovalTypes[ApprovalTypes["MAX"] = 1] = "MAX";
|
|
26
|
+
ApprovalTypes[ApprovalTypes["MAX_MINUS_ONE"] = 2] = "MAX_MINUS_ONE";
|
|
27
|
+
ApprovalTypes[ApprovalTypes["ZERO_THEN_MAX"] = 3] = "ZERO_THEN_MAX";
|
|
28
|
+
ApprovalTypes[ApprovalTypes["ZERO_THEN_MAX_MINUS_ONE"] = 4] = "ZERO_THEN_MAX_MINUS_ONE";
|
|
29
|
+
})(exports.ApprovalTypes || (exports.ApprovalTypes = {}));
|
|
30
|
+
|
|
31
|
+
var ApproveAndCall = /*#__PURE__*/function () {
|
|
32
|
+
/**
|
|
33
|
+
* Cannot be constructed.
|
|
34
|
+
*/
|
|
35
|
+
function ApproveAndCall() {}
|
|
36
|
+
|
|
37
|
+
ApproveAndCall.encodeApproveMax = function encodeApproveMax(token) {
|
|
38
|
+
return ApproveAndCall.INTERFACE.encodeFunctionData('approveMax', [token.address]);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
ApproveAndCall.encodeApproveMaxMinusOne = function encodeApproveMaxMinusOne(token) {
|
|
42
|
+
return ApproveAndCall.INTERFACE.encodeFunctionData('approveMaxMinusOne', [token.address]);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
ApproveAndCall.encodeApproveZeroThenMax = function encodeApproveZeroThenMax(token) {
|
|
46
|
+
return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMax', [token.address]);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
ApproveAndCall.encodeApproveZeroThenMaxMinusOne = function encodeApproveZeroThenMaxMinusOne(token) {
|
|
50
|
+
return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMaxMinusOne', [token.address]);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
ApproveAndCall.encodeCallPositionManager = function encodeCallPositionManager(calldatas) {
|
|
54
|
+
!(calldatas.length > 0) ? invariant(false, 'NULL_CALLDATA') : void 0;
|
|
55
|
+
|
|
56
|
+
if (calldatas.length == 1) {
|
|
57
|
+
return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', calldatas);
|
|
58
|
+
} else {
|
|
59
|
+
var encodedMulticall = v3Sdk.NonfungiblePositionManager.INTERFACE.encodeFunctionData('multicall', [calldatas]);
|
|
60
|
+
return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', [encodedMulticall]);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
ApproveAndCall.encodeApprove = function encodeApprove(token, approvalType) {
|
|
65
|
+
switch (approvalType) {
|
|
66
|
+
case exports.ApprovalTypes.MAX:
|
|
67
|
+
return ApproveAndCall.encodeApproveMax(token.wrapped);
|
|
68
|
+
|
|
69
|
+
case exports.ApprovalTypes.MAX_MINUS_ONE:
|
|
70
|
+
return ApproveAndCall.encodeApproveMaxMinusOne(token.wrapped);
|
|
71
|
+
|
|
72
|
+
case exports.ApprovalTypes.ZERO_THEN_MAX:
|
|
73
|
+
return ApproveAndCall.encodeApproveZeroThenMax(token.wrapped);
|
|
74
|
+
|
|
75
|
+
case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:
|
|
76
|
+
return ApproveAndCall.encodeApproveZeroThenMaxMinusOne(token.wrapped);
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
throw 'Error: invalid ApprovalType';
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return ApproveAndCall;
|
|
84
|
+
}();
|
|
85
|
+
ApproveAndCall.INTERFACE = /*#__PURE__*/new abi.Interface(IApproveAndCall_json.abi);
|
|
86
|
+
|
|
22
87
|
function validateAndParseBytes32(bytes32) {
|
|
23
88
|
if (!bytes32.match(/^0x[0-9a-fA-F]{64}$/)) {
|
|
24
89
|
throw new Error(bytes32 + " is not valid bytes32.");
|
|
@@ -216,11 +281,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
|
216
281
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
217
282
|
}
|
|
218
283
|
|
|
219
|
-
(function (Protocol) {
|
|
220
|
-
Protocol["V2"] = "V2";
|
|
221
|
-
Protocol["V3"] = "V3";
|
|
222
|
-
})(exports.Protocol || (exports.Protocol = {}));
|
|
223
|
-
|
|
224
284
|
function createCommonjsModule(fn, module) {
|
|
225
285
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
226
286
|
}
|
|
@@ -981,6 +1041,11 @@ try {
|
|
|
981
1041
|
}
|
|
982
1042
|
});
|
|
983
1043
|
|
|
1044
|
+
(function (Protocol) {
|
|
1045
|
+
Protocol["V2"] = "V2";
|
|
1046
|
+
Protocol["V3"] = "V3";
|
|
1047
|
+
})(exports.Protocol || (exports.Protocol = {}));
|
|
1048
|
+
|
|
984
1049
|
var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
|
|
985
1050
|
_inheritsLoose(RouteV2, _V2RouteSDK);
|
|
986
1051
|
|
|
@@ -1347,6 +1412,7 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1347
1412
|
return Trade;
|
|
1348
1413
|
}();
|
|
1349
1414
|
|
|
1415
|
+
var ZERO$1 = /*#__PURE__*/JSBI.BigInt(0);
|
|
1350
1416
|
/**
|
|
1351
1417
|
* Represents the Uniswap V2 + V3 SwapRouter02, and has static methods for helping execute trades.
|
|
1352
1418
|
*/
|
|
@@ -1436,15 +1502,9 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1436
1502
|
}
|
|
1437
1503
|
|
|
1438
1504
|
return calldatas;
|
|
1439
|
-
}
|
|
1440
|
-
/**
|
|
1441
|
-
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
1442
|
-
* @param trade to produce call parameters for
|
|
1443
|
-
* @param options options for the call parameters
|
|
1444
|
-
*/
|
|
1445
|
-
;
|
|
1505
|
+
};
|
|
1446
1506
|
|
|
1447
|
-
SwapRouter.
|
|
1507
|
+
SwapRouter.encodeSwaps = function encodeSwaps(trades, options, isSwapAndAdd) {
|
|
1448
1508
|
// If dealing with an instance of the aggregated Trade object, unbundle it to individual V2Trade and V3Trade objects.
|
|
1449
1509
|
if (trades instanceof Trade) {
|
|
1450
1510
|
!trades.swaps.every(function (swap) {
|
|
@@ -1492,16 +1552,8 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1492
1552
|
return trade.tradeType === sampleTrade.tradeType;
|
|
1493
1553
|
}) ? invariant(false, 'TRADE_TYPE_DIFF') : void 0;
|
|
1494
1554
|
var calldatas = [];
|
|
1495
|
-
var ZERO_IN = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.inputAmount.currency, 0);
|
|
1496
|
-
var ZERO_OUT = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.outputAmount.currency, 0);
|
|
1497
|
-
var totalAmountOut = trades.reduce(function (sum, trade) {
|
|
1498
|
-
return sum.add(trade.minimumAmountOut(options.slippageTolerance));
|
|
1499
|
-
}, ZERO_OUT);
|
|
1500
1555
|
var inputIsNative = sampleTrade.inputAmount.currency.isNative;
|
|
1501
|
-
var outputIsNative = sampleTrade.outputAmount.currency.isNative; // flag for whether
|
|
1502
|
-
// 1. when paying in ETH, but with an uncertain input amount
|
|
1503
|
-
|
|
1504
|
-
var mustRefund = inputIsNative && sampleTrade.tradeType === sdkCore.TradeType.EXACT_OUTPUT; // flag for whether we want to perform an aggregated slippage check
|
|
1556
|
+
var outputIsNative = sampleTrade.outputAmount.currency.isNative; // flag for whether we want to perform an aggregated slippage check
|
|
1505
1557
|
// 1. when there are >2 exact input trades. this is only a heuristic,
|
|
1506
1558
|
// as it's still more gas-expensive even in this case, but has benefits
|
|
1507
1559
|
// in that the reversion probability is lower
|
|
@@ -1509,12 +1561,10 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1509
1561
|
var performAggregatedSlippageCheck = sampleTrade.tradeType === sdkCore.TradeType.EXACT_INPUT && numberOfTrades > 2; // flag for whether funds should be send first to the router
|
|
1510
1562
|
// 1. when receiving ETH (which much be unwrapped from WETH)
|
|
1511
1563
|
// 2. when a fee on the output is being taken
|
|
1512
|
-
// 3. when performing
|
|
1564
|
+
// 3. when performing swap and add
|
|
1565
|
+
// 4. when performing an aggregated slippage check
|
|
1513
1566
|
|
|
1514
|
-
var routerMustCustody = outputIsNative || !!options.fee || performAggregatedSlippageCheck;
|
|
1515
|
-
var totalValue = inputIsNative ? trades.reduce(function (sum, trade) {
|
|
1516
|
-
return sum.add(trade.maximumAmountIn(options.slippageTolerance));
|
|
1517
|
-
}, ZERO_IN) : ZERO_IN; // encode permit if necessary
|
|
1567
|
+
var routerMustCustody = outputIsNative || !!options.fee || !!isSwapAndAdd || performAggregatedSlippageCheck; // encode permit if necessary
|
|
1518
1568
|
|
|
1519
1569
|
if (options.inputTokenPermit) {
|
|
1520
1570
|
!sampleTrade.inputAmount.currency.isToken ? invariant(false, 'NON_TOKEN_PERMIT') : void 0;
|
|
@@ -1532,7 +1582,42 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1532
1582
|
calldatas.push(calldata);
|
|
1533
1583
|
}
|
|
1534
1584
|
}
|
|
1535
|
-
}
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
var ZERO_IN = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.inputAmount.currency, 0);
|
|
1588
|
+
var ZERO_OUT = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.outputAmount.currency, 0);
|
|
1589
|
+
var totalAmountOut = trades.reduce(function (sum, trade) {
|
|
1590
|
+
return sum.add(trade.minimumAmountOut(options.slippageTolerance));
|
|
1591
|
+
}, ZERO_OUT);
|
|
1592
|
+
var totalAmountIn = trades.reduce(function (sum, trade) {
|
|
1593
|
+
return sum.add(trade.maximumAmountIn(options.slippageTolerance));
|
|
1594
|
+
}, ZERO_IN);
|
|
1595
|
+
return {
|
|
1596
|
+
calldatas: calldatas,
|
|
1597
|
+
sampleTrade: sampleTrade,
|
|
1598
|
+
routerMustCustody: routerMustCustody,
|
|
1599
|
+
inputIsNative: inputIsNative,
|
|
1600
|
+
outputIsNative: outputIsNative,
|
|
1601
|
+
totalAmountIn: totalAmountIn,
|
|
1602
|
+
totalAmountOut: totalAmountOut
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
1607
|
+
* @param trade to produce call parameters for
|
|
1608
|
+
* @param options options for the call parameters
|
|
1609
|
+
*/
|
|
1610
|
+
;
|
|
1611
|
+
|
|
1612
|
+
SwapRouter.swapCallParameters = function swapCallParameters(trades, options) {
|
|
1613
|
+
var _SwapRouter$encodeSwa = SwapRouter.encodeSwaps(trades, options),
|
|
1614
|
+
calldatas = _SwapRouter$encodeSwa.calldatas,
|
|
1615
|
+
sampleTrade = _SwapRouter$encodeSwa.sampleTrade,
|
|
1616
|
+
routerMustCustody = _SwapRouter$encodeSwa.routerMustCustody,
|
|
1617
|
+
inputIsNative = _SwapRouter$encodeSwa.inputIsNative,
|
|
1618
|
+
outputIsNative = _SwapRouter$encodeSwa.outputIsNative,
|
|
1619
|
+
totalAmountIn = _SwapRouter$encodeSwa.totalAmountIn,
|
|
1620
|
+
totalAmountOut = _SwapRouter$encodeSwa.totalAmountOut; // unwrap or sweep
|
|
1536
1621
|
|
|
1537
1622
|
|
|
1538
1623
|
if (routerMustCustody) {
|
|
@@ -1541,16 +1626,93 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1541
1626
|
} else {
|
|
1542
1627
|
calldatas.push(PaymentsExtended.encodeSweepToken(sampleTrade.outputAmount.currency.wrapped, totalAmountOut.quotient, options.recipient, options.fee));
|
|
1543
1628
|
}
|
|
1544
|
-
} // refund
|
|
1629
|
+
} // must refund when paying in ETH, but with an uncertain input amount
|
|
1545
1630
|
|
|
1546
1631
|
|
|
1547
|
-
if (
|
|
1632
|
+
if (inputIsNative && sampleTrade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
|
|
1548
1633
|
calldatas.push(v3Sdk.Payments.encodeRefundETH());
|
|
1549
1634
|
}
|
|
1550
1635
|
|
|
1551
1636
|
return {
|
|
1552
1637
|
calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
|
|
1553
|
-
value: v3Sdk.toHex(
|
|
1638
|
+
value: v3Sdk.toHex(inputIsNative ? totalAmountIn.quotient : ZERO$1)
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
1643
|
+
* @param trade to produce call parameters for
|
|
1644
|
+
* @param options options for the call parameters
|
|
1645
|
+
*/
|
|
1646
|
+
;
|
|
1647
|
+
|
|
1648
|
+
SwapRouter.swapAndAddCallParameters = function swapAndAddCallParameters(trades, options, position, addLiquidityOptions, tokenInApprovalType, tokenOutApprovalType) {
|
|
1649
|
+
var _SwapRouter$encodeSwa2 = SwapRouter.encodeSwaps(trades, options, true),
|
|
1650
|
+
calldatas = _SwapRouter$encodeSwa2.calldatas,
|
|
1651
|
+
inputIsNative = _SwapRouter$encodeSwa2.inputIsNative,
|
|
1652
|
+
outputIsNative = _SwapRouter$encodeSwa2.outputIsNative,
|
|
1653
|
+
sampleTrade = _SwapRouter$encodeSwa2.sampleTrade,
|
|
1654
|
+
totalAmountSwapped = _SwapRouter$encodeSwa2.totalAmountIn,
|
|
1655
|
+
totalAmountOut = _SwapRouter$encodeSwa2.totalAmountOut;
|
|
1656
|
+
|
|
1657
|
+
var chainId = sampleTrade.route.chainId;
|
|
1658
|
+
var zeroForOne = position.pool.token0 === totalAmountSwapped.currency.wrapped;
|
|
1659
|
+
|
|
1660
|
+
var _SwapRouter$getPositi = SwapRouter.getPositionAmounts(position, zeroForOne),
|
|
1661
|
+
positionAmountIn = _SwapRouter$getPositi.positionAmountIn,
|
|
1662
|
+
positionAmountOut = _SwapRouter$getPositi.positionAmountOut; // if tokens are native they will be converted to WETH9
|
|
1663
|
+
|
|
1664
|
+
|
|
1665
|
+
var tokenIn = inputIsNative ? sdkCore.WETH9[chainId] : positionAmountIn.currency.wrapped;
|
|
1666
|
+
var tokenOut = outputIsNative ? sdkCore.WETH9[chainId] : positionAmountOut.currency.wrapped; // if swap output does not make up whole outputTokenBalanceDesired, pull in remaining tokens for adding liquidity
|
|
1667
|
+
|
|
1668
|
+
var amountOutRemaining = positionAmountOut.subtract(totalAmountOut.wrapped);
|
|
1669
|
+
|
|
1670
|
+
if (amountOutRemaining.greaterThan(sdkCore.CurrencyAmount.fromRawAmount(positionAmountOut.currency, 0))) {
|
|
1671
|
+
// if output is native, this means the remaining portion is included as native value in the transaction
|
|
1672
|
+
// and must be wrapped. Otherwise, pull in remaining ERC20 token.
|
|
1673
|
+
outputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(amountOutRemaining.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenOut, amountOutRemaining.quotient));
|
|
1674
|
+
} // if input is native, convert to WETH9, else pull ERC20 token
|
|
1675
|
+
|
|
1676
|
+
|
|
1677
|
+
inputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient)); // approve token balances to NFTManager
|
|
1678
|
+
|
|
1679
|
+
if (tokenInApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenIn, tokenInApprovalType));
|
|
1680
|
+
if (tokenOutApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType)); // encode NFTManager add liquidity
|
|
1681
|
+
|
|
1682
|
+
calldatas.push(ApproveAndCall.encodeCallPositionManager([v3Sdk.NonfungiblePositionManager.addCallParameters(position, addLiquidityOptions).calldata])); // sweep remaining tokens
|
|
1683
|
+
|
|
1684
|
+
inputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenIn, ZERO$1));
|
|
1685
|
+
outputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenOut, ZERO$1));
|
|
1686
|
+
var value;
|
|
1687
|
+
|
|
1688
|
+
if (inputIsNative) {
|
|
1689
|
+
value = totalAmountSwapped.wrapped.add(positionAmountIn.wrapped).quotient;
|
|
1690
|
+
} else if (outputIsNative) {
|
|
1691
|
+
value = amountOutRemaining.quotient;
|
|
1692
|
+
} else {
|
|
1693
|
+
value = ZERO$1;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
return {
|
|
1697
|
+
calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
|
|
1698
|
+
value: value.toString()
|
|
1699
|
+
};
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
SwapRouter.getPositionAmounts = function getPositionAmounts(position, zeroForOne) {
|
|
1703
|
+
var _position$mintAmounts = position.mintAmounts,
|
|
1704
|
+
amount0 = _position$mintAmounts.amount0,
|
|
1705
|
+
amount1 = _position$mintAmounts.amount1;
|
|
1706
|
+
var currencyAmount0 = sdkCore.CurrencyAmount.fromRawAmount(position.pool.token0, amount0);
|
|
1707
|
+
var currencyAmount1 = sdkCore.CurrencyAmount.fromRawAmount(position.pool.token1, amount1);
|
|
1708
|
+
|
|
1709
|
+
var _ref = zeroForOne ? [currencyAmount0, currencyAmount1] : [currencyAmount1, currencyAmount0],
|
|
1710
|
+
positionAmountIn = _ref[0],
|
|
1711
|
+
positionAmountOut = _ref[1];
|
|
1712
|
+
|
|
1713
|
+
return {
|
|
1714
|
+
positionAmountIn: positionAmountIn,
|
|
1715
|
+
positionAmountOut: positionAmountOut
|
|
1554
1716
|
};
|
|
1555
1717
|
};
|
|
1556
1718
|
|
|
@@ -1559,6 +1721,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1559
1721
|
SwapRouter.INTERFACE = /*#__PURE__*/new abi.Interface(ISwapRouter02_json.abi);
|
|
1560
1722
|
|
|
1561
1723
|
exports.ADDRESS_THIS = ADDRESS_THIS;
|
|
1724
|
+
exports.ApproveAndCall = ApproveAndCall;
|
|
1562
1725
|
exports.MSG_SENDER = MSG_SENDER;
|
|
1563
1726
|
exports.MulticallExtended = MulticallExtended;
|
|
1564
1727
|
exports.ONE = ONE;
|