@uniswap/router-sdk 1.22.0 → 1.22.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/entities/mixedRoute/route.d.ts +2 -1
- package/dist/index.d.ts +0 -1
- package/dist/router-sdk.cjs.development.js +37 -22
- 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 -23
- package/dist/router-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/dist/utils/isValidTokenPath.d.ts +0 -3
package/dist/router-sdk.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Percent, validateAndParseAddress,
|
|
1
|
+
import { Percent, validateAndParseAddress, CurrencyAmount, Price, Fraction, TradeType, sortedInsert, WETH9 } from '@uniswap/sdk-core';
|
|
2
2
|
import JSBI from 'jsbi';
|
|
3
3
|
import { Interface } from '@ethersproject/abi';
|
|
4
4
|
import invariant from 'tiny-invariant';
|
|
@@ -623,22 +623,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
|
623
623
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
-
function isValidTokenPath(prevPool, currentPool, inputToken) {
|
|
627
|
-
if (inputToken instanceof Token && currentPool.involvesToken(inputToken)) return true;
|
|
628
|
-
if (currentPool instanceof Pool && currentPool.involvesToken(inputToken)) return true;
|
|
629
|
-
// throw if both v4 pools, native/wrapped tokens not interchangeable in v4
|
|
630
|
-
if (prevPool instanceof Pool && currentPool instanceof Pool) return false;
|
|
631
|
-
// v2/v3 --> v4 valid if v2/v3 output is the wrapped version of the v4 pool native currency
|
|
632
|
-
if (currentPool instanceof Pool) {
|
|
633
|
-
if (currentPool.token0.wrapped.equals(inputToken) || currentPool.token1.wrapped.equals(inputToken)) return true;
|
|
634
|
-
}
|
|
635
|
-
// v4 --> v2/v3 valid if v4 output is the native version of the v2/v3 wrapped token
|
|
636
|
-
if (prevPool instanceof Pool) {
|
|
637
|
-
if (currentPool.involvesToken(inputToken.wrapped)) return true;
|
|
638
|
-
}
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
626
|
function amountWithPathCurrency(amount, pool) {
|
|
643
627
|
return CurrencyAmount.fromFractionalAmount(getPathCurrency(amount.currency, pool), amount.numerator, amount.denominator);
|
|
644
628
|
}
|
|
@@ -674,10 +658,18 @@ var MixedRouteSDK = /*#__PURE__*/function () {
|
|
|
674
658
|
* @param pools An array of `TPool` objects (pools or pairs), ordered by the route the swap will take
|
|
675
659
|
* @param input The input token
|
|
676
660
|
* @param output The output token
|
|
661
|
+
* @param retainsFakePool Set to true to filter out a pool that has a fake eth-weth pool
|
|
677
662
|
*/
|
|
678
|
-
function MixedRouteSDK(pools, input, output) {
|
|
663
|
+
function MixedRouteSDK(pools, input, output, retainFakePools) {
|
|
664
|
+
if (retainFakePools === void 0) {
|
|
665
|
+
retainFakePools = false;
|
|
666
|
+
}
|
|
679
667
|
this._midPrice = null;
|
|
668
|
+
pools = retainFakePools ? pools : pools.filter(function (pool) {
|
|
669
|
+
return !(pool instanceof Pool && pool.tickSpacing === 0);
|
|
670
|
+
});
|
|
680
671
|
!(pools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS') : invariant(false) : void 0;
|
|
672
|
+
// there is a pool mismatched to the path if we do not retain the fake eth-weth pools
|
|
681
673
|
var chainId = pools[0].chainId;
|
|
682
674
|
var allOnSameChain = pools.every(function (pool) {
|
|
683
675
|
return pool.chainId === chainId;
|
|
@@ -685,7 +677,11 @@ var MixedRouteSDK = /*#__PURE__*/function () {
|
|
|
685
677
|
!allOnSameChain ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0;
|
|
686
678
|
this.pathInput = getPathCurrency(input, pools[0]);
|
|
687
679
|
this.pathOutput = getPathCurrency(output, pools[pools.length - 1]);
|
|
688
|
-
!pools[0]
|
|
680
|
+
if (!(pools[0] instanceof Pool)) {
|
|
681
|
+
!pools[0].involvesToken(this.pathInput) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
|
|
682
|
+
} else {
|
|
683
|
+
!pools[0].v4InvolvesToken(this.pathInput) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
|
|
684
|
+
}
|
|
689
685
|
var lastPool = pools[pools.length - 1];
|
|
690
686
|
if (lastPool instanceof Pool) {
|
|
691
687
|
!(lastPool.v4InvolvesToken(output) || lastPool.v4InvolvesToken(output.wrapped)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
|
|
@@ -698,11 +694,31 @@ var MixedRouteSDK = /*#__PURE__*/function () {
|
|
|
698
694
|
var tokenPath = [this.pathInput];
|
|
699
695
|
pools[0].token0.equals(this.pathInput) ? tokenPath.push(pools[0].token1) : tokenPath.push(pools[0].token0);
|
|
700
696
|
for (var i = 1; i < pools.length; i++) {
|
|
701
|
-
var prevPool = pools[i - 1];
|
|
702
697
|
var pool = pools[i];
|
|
703
698
|
var inputToken = tokenPath[i];
|
|
704
|
-
var outputToken =
|
|
705
|
-
|
|
699
|
+
var outputToken = void 0;
|
|
700
|
+
if (
|
|
701
|
+
// we hit an edge case if it's a v4 pool and neither of the tokens are in the pool OR it is not a v4 pool but the input currency is eth
|
|
702
|
+
pool instanceof Pool && !pool.involvesToken(inputToken) || !(pool instanceof Pool) && inputToken.isNative) {
|
|
703
|
+
// We handle the case where the inputToken =/= pool.token0 or pool.token1. There are 2 specific cases.
|
|
704
|
+
if (inputToken.equals(pool.token0.wrapped)) {
|
|
705
|
+
// 1) the inputToken is WETH and the current pool has ETH
|
|
706
|
+
// for example, pools: USDC-WETH, ETH-PEPE, path: USDC, WETH, PEPE
|
|
707
|
+
// second pool is a v4 pool, the first could be any version
|
|
708
|
+
outputToken = pool.token1;
|
|
709
|
+
} else if (inputToken.wrapped.equals(pool.token0) || inputToken.wrapped.equals(pool.token1)) {
|
|
710
|
+
// 2) the inputToken is ETH and the current pool has WETH
|
|
711
|
+
// for example, pools: USDC-ETH, WETH-PEPE, path: USDC, ETH, PEPE
|
|
712
|
+
// first pool is a v4 pool, the second could be any version
|
|
713
|
+
outputToken = inputToken.wrapped.equals(pool.token0) ? pool.token1 : pool.token0;
|
|
714
|
+
} else {
|
|
715
|
+
throw new Error("POOL_MISMATCH pool: " + JSON.stringify(pool) + " inputToken: " + JSON.stringify(inputToken));
|
|
716
|
+
}
|
|
717
|
+
} else {
|
|
718
|
+
// then the input token must equal either token0 or token1
|
|
719
|
+
!(inputToken.equals(pool.token0) || inputToken.equals(pool.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, "PATH pool " + JSON.stringify(pool) + " inputToken " + JSON.stringify(inputToken)) : invariant(false) : void 0;
|
|
720
|
+
outputToken = inputToken.equals(pool.token0) ? pool.token1 : pool.token0;
|
|
721
|
+
}
|
|
706
722
|
tokenPath.push(outputToken);
|
|
707
723
|
}
|
|
708
724
|
this.pools = pools;
|
|
@@ -2389,5 +2405,5 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
2389
2405
|
}();
|
|
2390
2406
|
SwapRouter.INTERFACE = /*#__PURE__*/new Interface(abi$3);
|
|
2391
2407
|
|
|
2392
|
-
export { ADDRESS_THIS, ADDRESS_ZERO, ApprovalTypes, ApproveAndCall, MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, ONE_HUNDRED_PERCENT, PaymentsExtended, Protocol, RouteV2, RouteV3, RouteV4, SwapRouter, Trade, ZERO, ZERO_PERCENT, amountWithPathCurrency, encodeMixedRouteToPath, getOutputOfPools, getPathCurrency, getPathToken, isMint,
|
|
2408
|
+
export { ADDRESS_THIS, ADDRESS_ZERO, ApprovalTypes, ApproveAndCall, MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, ONE_HUNDRED_PERCENT, PaymentsExtended, Protocol, RouteV2, RouteV3, RouteV4, SwapRouter, Trade, ZERO, ZERO_PERCENT, amountWithPathCurrency, encodeMixedRouteToPath, getOutputOfPools, getPathCurrency, getPathToken, isMint, partitionMixedRouteByProtocol, tradeComparator };
|
|
2393
2409
|
//# sourceMappingURL=router-sdk.esm.js.map
|