@uniswap/router-sdk 1.0.3 → 1.0.6
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 +38 -8
- 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 +39 -9
- package/dist/router-sdk.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/approveAndCall.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ export declare abstract class ApproveAndCall {
|
|
|
21
21
|
static encodeApproveZeroThenMax(token: Token): string;
|
|
22
22
|
static encodeApproveZeroThenMaxMinusOne(token: Token): string;
|
|
23
23
|
static encodeCallPositionManager(calldatas: string[]): string;
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Encode adding liquidity to a position in the nft manager contract
|
|
26
|
+
* @param position Forcasted position with expected amount out from swap
|
|
27
|
+
* @param minimalPosition Forcasted position with custom minimal token amounts
|
|
28
|
+
* @param addLiquidityOptions Options for adding liquidity
|
|
29
|
+
* @param slippageTolerance Defines maximum slippage
|
|
30
|
+
*/
|
|
31
|
+
static encodeAddLiquidity(position: Position, minimalPosition: Position, addLiquidityOptions: CondensedAddLiquidityOptions, slippageTolerance: Percent): string;
|
|
25
32
|
static encodeApprove(token: Currency, approvalType: ApprovalTypes): string;
|
|
26
33
|
}
|
|
@@ -65,12 +65,31 @@ var ApproveAndCall = /*#__PURE__*/function () {
|
|
|
65
65
|
var encodedMulticall = v3Sdk.NonfungiblePositionManager.INTERFACE.encodeFunctionData('multicall', [calldatas]);
|
|
66
66
|
return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', [encodedMulticall]);
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Encode adding liquidity to a position in the nft manager contract
|
|
71
|
+
* @param position Forcasted position with expected amount out from swap
|
|
72
|
+
* @param minimalPosition Forcasted position with custom minimal token amounts
|
|
73
|
+
* @param addLiquidityOptions Options for adding liquidity
|
|
74
|
+
* @param slippageTolerance Defines maximum slippage
|
|
75
|
+
*/
|
|
76
|
+
;
|
|
69
77
|
|
|
70
|
-
ApproveAndCall.encodeAddLiquidity = function encodeAddLiquidity(position, addLiquidityOptions, slippageTolerance) {
|
|
78
|
+
ApproveAndCall.encodeAddLiquidity = function encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, slippageTolerance) {
|
|
71
79
|
var _position$mintAmounts = position.mintAmountsWithSlippage(slippageTolerance),
|
|
72
80
|
amount0Min = _position$mintAmounts.amount0,
|
|
73
|
-
amount1Min = _position$mintAmounts.amount1;
|
|
81
|
+
amount1Min = _position$mintAmounts.amount1; // position.mintAmountsWithSlippage() can create amounts not dependenable in scenarios
|
|
82
|
+
// such as range orders. Allow the option to provide a position with custom minimum amounts
|
|
83
|
+
// for these scenarios
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (JSBI.lessThan(minimalPosition.amount0.quotient, amount0Min)) {
|
|
87
|
+
amount0Min = minimalPosition.amount0.quotient;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (JSBI.lessThan(minimalPosition.amount1.quotient, amount1Min)) {
|
|
91
|
+
amount1Min = minimalPosition.amount1.quotient;
|
|
92
|
+
}
|
|
74
93
|
|
|
75
94
|
if (isMint(addLiquidityOptions)) {
|
|
76
95
|
return ApproveAndCall.INTERFACE.encodeFunctionData('mint', [{
|
|
@@ -1689,7 +1708,8 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1689
1708
|
outputIsNative = _SwapRouter$encodeSwa2.outputIsNative,
|
|
1690
1709
|
sampleTrade = _SwapRouter$encodeSwa2.sampleTrade,
|
|
1691
1710
|
totalAmountSwapped = _SwapRouter$encodeSwa2.totalAmountIn,
|
|
1692
|
-
quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut
|
|
1711
|
+
quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut,
|
|
1712
|
+
minimumAmountOut = _SwapRouter$encodeSwa2.minimumAmountOut; // encode output token permit if necessary
|
|
1693
1713
|
|
|
1694
1714
|
|
|
1695
1715
|
if (options.outputTokenPermit) {
|
|
@@ -1698,7 +1718,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1698
1718
|
}
|
|
1699
1719
|
|
|
1700
1720
|
var chainId = sampleTrade.route.chainId;
|
|
1701
|
-
var zeroForOne = position.pool.token0 === totalAmountSwapped.currency.wrapped;
|
|
1721
|
+
var zeroForOne = position.pool.token0.wrapped.address === totalAmountSwapped.currency.wrapped.address;
|
|
1702
1722
|
|
|
1703
1723
|
var _SwapRouter$getPositi = SwapRouter.getPositionAmounts(position, zeroForOne),
|
|
1704
1724
|
positionAmountIn = _SwapRouter$getPositi.positionAmountIn,
|
|
@@ -1720,9 +1740,19 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1720
1740
|
inputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient)); // approve token balances to NFTManager
|
|
1721
1741
|
|
|
1722
1742
|
if (tokenInApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenIn, tokenInApprovalType));
|
|
1723
|
-
if (tokenOutApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType)); //
|
|
1724
|
-
|
|
1725
|
-
|
|
1743
|
+
if (tokenOutApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType)); // represents a position with token amounts resulting from a swap with maximum slippage
|
|
1744
|
+
// hence the minimal amount out possible.
|
|
1745
|
+
|
|
1746
|
+
var minimalPosition = v3Sdk.Position.fromAmounts({
|
|
1747
|
+
pool: position.pool,
|
|
1748
|
+
tickLower: position.tickLower,
|
|
1749
|
+
tickUpper: position.tickUpper,
|
|
1750
|
+
amount0: zeroForOne ? position.amount0.quotient.toString() : minimumAmountOut.quotient.toString(),
|
|
1751
|
+
amount1: zeroForOne ? minimumAmountOut.quotient.toString() : position.amount1.quotient.toString(),
|
|
1752
|
+
useFullPrecision: false
|
|
1753
|
+
}); // encode NFTManager add liquidity
|
|
1754
|
+
|
|
1755
|
+
calldatas.push(ApproveAndCall.encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, options.slippageTolerance)); // sweep remaining tokens
|
|
1726
1756
|
|
|
1727
1757
|
inputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenIn, ZERO$1));
|
|
1728
1758
|
outputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenOut, ZERO$1));
|