@uniswap/router-sdk 1.22.0 → 1.22.1

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.
@@ -18,8 +18,9 @@ export declare class MixedRouteSDK<TInput extends Currency, TOutput extends Curr
18
18
  * @param pools An array of `TPool` objects (pools or pairs), ordered by the route the swap will take
19
19
  * @param input The input token
20
20
  * @param output The output token
21
+ * @param retainsFakePool Set to true to filter out a pool that has a fake eth-weth pool
21
22
  */
22
- constructor(pools: TPool[], input: TInput, output: TOutput);
23
+ constructor(pools: TPool[], input: TInput, output: TOutput, retainFakePools?: boolean);
23
24
  get chainId(): number;
24
25
  /**
25
26
  * Returns the mid price of the route
package/dist/index.d.ts CHANGED
@@ -12,4 +12,3 @@ export * from './utils/encodeMixedRouteToPath';
12
12
  export * from './utils/TPool';
13
13
  export * from './utils/pathCurrency';
14
14
  export * from './utils';
15
- export * from './utils/isValidTokenPath';
@@ -628,22 +628,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
628
628
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
629
629
  }
630
630
 
631
- function isValidTokenPath(prevPool, currentPool, inputToken) {
632
- if (inputToken instanceof sdkCore.Token && currentPool.involvesToken(inputToken)) return true;
633
- if (currentPool instanceof v4Sdk.Pool && currentPool.involvesToken(inputToken)) return true;
634
- // throw if both v4 pools, native/wrapped tokens not interchangeable in v4
635
- if (prevPool instanceof v4Sdk.Pool && currentPool instanceof v4Sdk.Pool) return false;
636
- // v2/v3 --> v4 valid if v2/v3 output is the wrapped version of the v4 pool native currency
637
- if (currentPool instanceof v4Sdk.Pool) {
638
- if (currentPool.token0.wrapped.equals(inputToken) || currentPool.token1.wrapped.equals(inputToken)) return true;
639
- }
640
- // v4 --> v2/v3 valid if v4 output is the native version of the v2/v3 wrapped token
641
- if (prevPool instanceof v4Sdk.Pool) {
642
- if (currentPool.involvesToken(inputToken.wrapped)) return true;
643
- }
644
- return false;
645
- }
646
-
647
631
  function amountWithPathCurrency(amount, pool) {
648
632
  return sdkCore.CurrencyAmount.fromFractionalAmount(getPathCurrency(amount.currency, pool), amount.numerator, amount.denominator);
649
633
  }
@@ -679,10 +663,18 @@ var MixedRouteSDK = /*#__PURE__*/function () {
679
663
  * @param pools An array of `TPool` objects (pools or pairs), ordered by the route the swap will take
680
664
  * @param input The input token
681
665
  * @param output The output token
666
+ * @param retainsFakePool Set to true to filter out a pool that has a fake eth-weth pool
682
667
  */
683
- function MixedRouteSDK(pools, input, output) {
668
+ function MixedRouteSDK(pools, input, output, retainFakePools) {
669
+ if (retainFakePools === void 0) {
670
+ retainFakePools = false;
671
+ }
684
672
  this._midPrice = null;
673
+ pools = retainFakePools ? pools : pools.filter(function (pool) {
674
+ return !(pool instanceof v4Sdk.Pool && pool.tickSpacing === 0);
675
+ });
685
676
  !(pools.length > 0) ? invariant(false, 'POOLS') : void 0;
677
+ // there is a pool mismatched to the path if we do not retain the fake eth-weth pools
686
678
  var chainId = pools[0].chainId;
687
679
  var allOnSameChain = pools.every(function (pool) {
688
680
  return pool.chainId === chainId;
@@ -690,7 +682,11 @@ var MixedRouteSDK = /*#__PURE__*/function () {
690
682
  !allOnSameChain ? invariant(false, 'CHAIN_IDS') : void 0;
691
683
  this.pathInput = getPathCurrency(input, pools[0]);
692
684
  this.pathOutput = getPathCurrency(output, pools[pools.length - 1]);
693
- !pools[0].involvesToken(this.pathInput) ? invariant(false, 'INPUT') : void 0;
685
+ if (!(pools[0] instanceof v4Sdk.Pool)) {
686
+ !pools[0].involvesToken(this.pathInput) ? invariant(false, 'INPUT') : void 0;
687
+ } else {
688
+ !pools[0].v4InvolvesToken(this.pathInput) ? invariant(false, 'INPUT') : void 0;
689
+ }
694
690
  var lastPool = pools[pools.length - 1];
695
691
  if (lastPool instanceof v4Sdk.Pool) {
696
692
  !(lastPool.v4InvolvesToken(output) || lastPool.v4InvolvesToken(output.wrapped)) ? invariant(false, 'OUTPUT') : void 0;
@@ -703,11 +699,31 @@ var MixedRouteSDK = /*#__PURE__*/function () {
703
699
  var tokenPath = [this.pathInput];
704
700
  pools[0].token0.equals(this.pathInput) ? tokenPath.push(pools[0].token1) : tokenPath.push(pools[0].token0);
705
701
  for (var i = 1; i < pools.length; i++) {
706
- var prevPool = pools[i - 1];
707
702
  var pool = pools[i];
708
703
  var inputToken = tokenPath[i];
709
- var outputToken = pool instanceof v4Sdk.Pool ? pool.token0.equals(inputToken) ? pool.token1 : pool.token0 : pool.token0.wrapped.equals(inputToken.wrapped) ? pool.token1 : pool.token0;
710
- !isValidTokenPath(prevPool, pool, inputToken) ? invariant(false, "PATH") : void 0;
704
+ var outputToken = void 0;
705
+ if (
706
+ // 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
707
+ pool instanceof v4Sdk.Pool && !pool.involvesToken(inputToken) || !(pool instanceof v4Sdk.Pool) && inputToken.isNative) {
708
+ // We handle the case where the inputToken =/= pool.token0 or pool.token1. There are 2 specific cases.
709
+ if (inputToken.equals(pool.token0.wrapped)) {
710
+ // 1) the inputToken is WETH and the current pool has ETH
711
+ // for example, pools: USDC-WETH, ETH-PEPE, path: USDC, WETH, PEPE
712
+ // second pool is a v4 pool, the first could be any version
713
+ outputToken = pool.token1;
714
+ } else if (inputToken.wrapped.equals(pool.token0) || inputToken.wrapped.equals(pool.token1)) {
715
+ // 2) the inputToken is ETH and the current pool has WETH
716
+ // for example, pools: USDC-ETH, WETH-PEPE, path: USDC, ETH, PEPE
717
+ // first pool is a v4 pool, the second could be any version
718
+ outputToken = inputToken.wrapped.equals(pool.token0) ? pool.token1 : pool.token0;
719
+ } else {
720
+ throw new Error("POOL_MISMATCH pool: " + JSON.stringify(pool) + " inputToken: " + JSON.stringify(inputToken));
721
+ }
722
+ } else {
723
+ // then the input token must equal either token0 or token1
724
+ !(inputToken.equals(pool.token0) || inputToken.equals(pool.token1)) ? invariant(false, "PATH pool " + JSON.stringify(pool) + " inputToken " + JSON.stringify(inputToken)) : void 0;
725
+ outputToken = inputToken.equals(pool.token0) ? pool.token1 : pool.token0;
726
+ }
711
727
  tokenPath.push(outputToken);
712
728
  }
713
729
  this.pools = pools;
@@ -2421,7 +2437,6 @@ exports.getOutputOfPools = getOutputOfPools;
2421
2437
  exports.getPathCurrency = getPathCurrency;
2422
2438
  exports.getPathToken = getPathToken;
2423
2439
  exports.isMint = isMint;
2424
- exports.isValidTokenPath = isValidTokenPath;
2425
2440
  exports.partitionMixedRouteByProtocol = partitionMixedRouteByProtocol;
2426
2441
  exports.tradeComparator = tradeComparator;
2427
2442
  //# sourceMappingURL=router-sdk.cjs.development.js.map