@uniswap/router-sdk 1.11.0 → 1.11.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.
- package/dist/router-sdk.cjs.development.js +44 -20
- 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 +45 -21
- package/dist/router-sdk.esm.js.map +1 -1
- package/dist/utils/isValidTokenPath.d.ts +7 -0
- package/package.json +1 -1
|
@@ -622,6 +622,21 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
|
622
622
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
623
623
|
}
|
|
624
624
|
|
|
625
|
+
function isValidTokenPath(prevPool, currentPool, inputToken) {
|
|
626
|
+
if (currentPool.involvesToken(inputToken)) return true;
|
|
627
|
+
// throw if both v4 pools, native/wrapped tokens not interchangeable in v4
|
|
628
|
+
if (prevPool instanceof v4Sdk.Pool && currentPool instanceof v4Sdk.Pool) return false;
|
|
629
|
+
// v2/v3 --> v4 valid if v2/v3 output is the wrapped version of the v4 pool native currency
|
|
630
|
+
if (currentPool instanceof v4Sdk.Pool) {
|
|
631
|
+
if (currentPool.token0.wrapped.equals(inputToken) || currentPool.token1.wrapped.equals(inputToken)) return true;
|
|
632
|
+
}
|
|
633
|
+
// v4 --> v2/v3 valid if v4 output is the native version of the v2/v3 wrapped token
|
|
634
|
+
if (prevPool instanceof v4Sdk.Pool) {
|
|
635
|
+
if (currentPool.involvesToken(inputToken.wrapped)) return true;
|
|
636
|
+
}
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
|
|
625
640
|
/**
|
|
626
641
|
* Represents a list of pools or pairs through which a swap can occur
|
|
627
642
|
* @template TInput The input token
|
|
@@ -658,14 +673,14 @@ var MixedRouteSDK = /*#__PURE__*/function () {
|
|
|
658
673
|
* Normalizes token0-token1 order and selects the next token/fee step to add to the path
|
|
659
674
|
* */
|
|
660
675
|
var tokenPath = [this.adjustedInput];
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
var
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
tokenPath.push(
|
|
676
|
+
pools[0].token0.equals(this.adjustedInput) ? tokenPath.push(pools[0].token1) : tokenPath.push(pools[0].token0);
|
|
677
|
+
for (var i = 1; i < pools.length; i++) {
|
|
678
|
+
var prevPool = pools[i - 1];
|
|
679
|
+
var pool = pools[i];
|
|
680
|
+
var inputToken = tokenPath[i];
|
|
681
|
+
var outputToken = pool.token0.wrapped.equals(inputToken.wrapped) ? pool.token1 : pool.token0;
|
|
682
|
+
!isValidTokenPath(prevPool, pool, inputToken) ? invariant(false, 'PATH') : void 0;
|
|
683
|
+
tokenPath.push(outputToken);
|
|
669
684
|
}
|
|
670
685
|
this.pools = pools;
|
|
671
686
|
this.path = tokenPath;
|
|
@@ -716,32 +731,41 @@ function _getOutputAmount() {
|
|
|
716
731
|
while (1) switch (_context.prev = _context.next) {
|
|
717
732
|
case 0:
|
|
718
733
|
if (!(pool instanceof v4Sdk.Pool)) {
|
|
719
|
-
_context.next =
|
|
734
|
+
_context.next = 13;
|
|
720
735
|
break;
|
|
721
736
|
}
|
|
722
737
|
if (!pool.involvesCurrency(amountIn.currency)) {
|
|
723
|
-
_context.next =
|
|
738
|
+
_context.next = 5;
|
|
724
739
|
break;
|
|
725
740
|
}
|
|
726
741
|
_context.next = 4;
|
|
727
742
|
return pool.getOutputAmount(amountIn);
|
|
728
743
|
case 4:
|
|
729
744
|
return _context.abrupt("return", _context.sent);
|
|
730
|
-
case
|
|
731
|
-
if (!pool.
|
|
732
|
-
_context.next =
|
|
745
|
+
case 5:
|
|
746
|
+
if (!pool.token0.wrapped.equals(amountIn.currency)) {
|
|
747
|
+
_context.next = 9;
|
|
733
748
|
break;
|
|
734
749
|
}
|
|
735
|
-
_context.next =
|
|
736
|
-
return pool.getOutputAmount(amountIn.
|
|
737
|
-
case
|
|
750
|
+
_context.next = 8;
|
|
751
|
+
return pool.getOutputAmount(sdkCore.CurrencyAmount.fromRawAmount(pool.token0, amountIn.quotient));
|
|
752
|
+
case 8:
|
|
753
|
+
return _context.abrupt("return", _context.sent);
|
|
754
|
+
case 9:
|
|
755
|
+
if (!pool.token1.wrapped.equals(amountIn.currency)) {
|
|
756
|
+
_context.next = 13;
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
_context.next = 12;
|
|
760
|
+
return pool.getOutputAmount(sdkCore.CurrencyAmount.fromRawAmount(pool.token1, amountIn.quotient));
|
|
761
|
+
case 12:
|
|
738
762
|
return _context.abrupt("return", _context.sent);
|
|
739
|
-
case 11:
|
|
740
|
-
_context.next = 13;
|
|
741
|
-
return pool.getOutputAmount(amountIn.wrapped);
|
|
742
763
|
case 13:
|
|
764
|
+
_context.next = 15;
|
|
765
|
+
return pool.getOutputAmount(amountIn.wrapped);
|
|
766
|
+
case 15:
|
|
743
767
|
return _context.abrupt("return", _context.sent);
|
|
744
|
-
case
|
|
768
|
+
case 16:
|
|
745
769
|
case "end":
|
|
746
770
|
return _context.stop();
|
|
747
771
|
}
|