@uniswap/router-sdk 1.0.3 → 1.0.4
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 +8 -1
- package/dist/router-sdk.cjs.development.js +37 -7
- 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 +38 -8
- package/dist/router-sdk.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/router-sdk.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import JSBI from 'jsbi';
|
|
|
2
2
|
import { Interface } from '@ethersproject/abi';
|
|
3
3
|
import invariant from 'tiny-invariant';
|
|
4
4
|
import { abi } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json';
|
|
5
|
-
import { NonfungiblePositionManager, toHex, Multicall, Payments, Route as Route$1, Pool, Trade as Trade$1, encodeRouteToPath, SelfPermit } from '@uniswap/v3-sdk';
|
|
5
|
+
import { NonfungiblePositionManager, toHex, Multicall, Payments, Route as Route$1, Pool, Trade as Trade$1, encodeRouteToPath, SelfPermit, Position } from '@uniswap/v3-sdk';
|
|
6
6
|
import { abi as abi$1 } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json';
|
|
7
7
|
import { validateAndParseAddress, TradeType, Fraction, CurrencyAmount, Price, Percent, WETH9 } from '@uniswap/sdk-core';
|
|
8
8
|
import { abi as abi$2 } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json';
|
|
@@ -61,12 +61,31 @@ var ApproveAndCall = /*#__PURE__*/function () {
|
|
|
61
61
|
var encodedMulticall = NonfungiblePositionManager.INTERFACE.encodeFunctionData('multicall', [calldatas]);
|
|
62
62
|
return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', [encodedMulticall]);
|
|
63
63
|
}
|
|
64
|
-
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Encode adding liquidity to a position in the nft manager contract
|
|
67
|
+
* @param position Forcasted position with expected amount out from swap
|
|
68
|
+
* @param minimalPosition Forcasted position with custom minimal token amounts
|
|
69
|
+
* @param addLiquidityOptions Options for adding liquidity
|
|
70
|
+
* @param slippageTolerance Defines maximum slippage
|
|
71
|
+
*/
|
|
72
|
+
;
|
|
65
73
|
|
|
66
|
-
ApproveAndCall.encodeAddLiquidity = function encodeAddLiquidity(position, addLiquidityOptions, slippageTolerance) {
|
|
74
|
+
ApproveAndCall.encodeAddLiquidity = function encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, slippageTolerance) {
|
|
67
75
|
var _position$mintAmounts = position.mintAmountsWithSlippage(slippageTolerance),
|
|
68
76
|
amount0Min = _position$mintAmounts.amount0,
|
|
69
|
-
amount1Min = _position$mintAmounts.amount1;
|
|
77
|
+
amount1Min = _position$mintAmounts.amount1; // position.mintAmountsWithSlippage() can create amounts not dependenable in scenarios
|
|
78
|
+
// such as range orders. Allow the option to provide a position with custom minimum amounts
|
|
79
|
+
// for these scenarios
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if (JSBI.lessThan(minimalPosition.amount0.quotient, amount0Min)) {
|
|
83
|
+
amount0Min = minimalPosition.amount0.quotient;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (JSBI.lessThan(minimalPosition.amount1.quotient, amount1Min)) {
|
|
87
|
+
amount1Min = minimalPosition.amount1.quotient;
|
|
88
|
+
}
|
|
70
89
|
|
|
71
90
|
if (isMint(addLiquidityOptions)) {
|
|
72
91
|
return ApproveAndCall.INTERFACE.encodeFunctionData('mint', [{
|
|
@@ -1687,7 +1706,8 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1687
1706
|
outputIsNative = _SwapRouter$encodeSwa2.outputIsNative,
|
|
1688
1707
|
sampleTrade = _SwapRouter$encodeSwa2.sampleTrade,
|
|
1689
1708
|
totalAmountSwapped = _SwapRouter$encodeSwa2.totalAmountIn,
|
|
1690
|
-
quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut
|
|
1709
|
+
quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut,
|
|
1710
|
+
minimumAmountOut = _SwapRouter$encodeSwa2.minimumAmountOut; // encode output token permit if necessary
|
|
1691
1711
|
|
|
1692
1712
|
|
|
1693
1713
|
if (options.outputTokenPermit) {
|
|
@@ -1718,9 +1738,19 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1718
1738
|
inputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient)); // approve token balances to NFTManager
|
|
1719
1739
|
|
|
1720
1740
|
if (tokenInApprovalType !== ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenIn, tokenInApprovalType));
|
|
1721
|
-
if (tokenOutApprovalType !== ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType)); //
|
|
1722
|
-
|
|
1723
|
-
|
|
1741
|
+
if (tokenOutApprovalType !== ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType)); // represents a position with token amounts resulting from a swap with maximum slippage
|
|
1742
|
+
// hence the minimal amount out possible.
|
|
1743
|
+
|
|
1744
|
+
var minimalPosition = Position.fromAmounts({
|
|
1745
|
+
pool: position.pool,
|
|
1746
|
+
tickLower: position.tickLower,
|
|
1747
|
+
tickUpper: position.tickUpper,
|
|
1748
|
+
amount0: zeroForOne ? position.amount0.quotient.toString() : minimumAmountOut.quotient.toString(),
|
|
1749
|
+
amount1: zeroForOne ? minimumAmountOut.quotient.toString() : position.amount1.quotient.toString(),
|
|
1750
|
+
useFullPrecision: false
|
|
1751
|
+
}); // encode NFTManager add liquidity
|
|
1752
|
+
|
|
1753
|
+
calldatas.push(ApproveAndCall.encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, options.slippageTolerance)); // sweep remaining tokens
|
|
1724
1754
|
|
|
1725
1755
|
inputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenIn, ZERO$1));
|
|
1726
1756
|
outputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenOut, ZERO$1));
|