@uniswap/universal-router-sdk 4.19.5 → 4.19.7

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.
@@ -756,39 +756,67 @@ var UniswapTrade = /*#__PURE__*/function () {
756
756
  }
757
757
  return result;
758
758
  }
759
+ // this.trade.swaps is an array of swaps / trades.
760
+ // we are iterating over one swap (trade) at a time so length is 1
761
+ // route is either v2, v3, v4, or mixed
762
+ // pathInput and pathOutput are the currencies of the input and output of the route
763
+ // this.trade.inputAmount is the input currency of the trade (could be different from pathInput)
764
+ // this.trade.outputAmount is the output currency of the trade (could be different from pathOutput)
765
+ // each route can have multiple pools
759
766
  }, {
760
767
  key: "inputRequiresWrap",
761
768
  get: function get() {
762
- if (this.isAllV4) {
769
+ var swap = this.trade.swaps[0];
770
+ var route = swap.route;
771
+ var firstPool = route.pools[0];
772
+ if (firstPool instanceof v4Sdk.Pool) {
773
+ // If first pool is a v4 pool and input currency is native and the path input currency in the route is not native, we need to wrap.
763
774
  return this.trade.inputAmount.currency.isNative && !this.trade.swaps[0].route.pathInput.isNative;
764
- } else {
765
- return this.trade.inputAmount.currency.isNative;
766
775
  }
776
+ // If first pool is not a v4 pool and input currency is native, we need to wrap
777
+ return this.trade.inputAmount.currency.isNative;
767
778
  }
768
779
  }, {
769
780
  key: "inputRequiresUnwrap",
770
781
  get: function get() {
771
- if (this.isAllV4) {
782
+ var swap = this.trade.swaps[0];
783
+ var route = swap.route;
784
+ var firstPool = route.pools[0];
785
+ if (firstPool instanceof v4Sdk.Pool) {
786
+ // If the first pool is a v4 pool and input currency is not native and the path input currency is native, we need to unwrap
772
787
  return !this.trade.inputAmount.currency.isNative && this.trade.swaps[0].route.pathInput.isNative;
773
788
  }
789
+ // If the first pool is not a v4 pool, we don't need to unwrap.
774
790
  return false;
775
791
  }
776
792
  }, {
777
793
  key: "outputRequiresWrap",
778
794
  get: function get() {
779
- if (this.isAllV4) {
780
- return !this.trade.outputAmount.currency.isNative && this.trade.swaps[0].route.pathOutput.isNative;
795
+ var swap = this.trade.swaps[0];
796
+ var lastRoute = swap.route;
797
+ var lastPool = lastRoute.pools[lastRoute.pools.length - 1];
798
+ // if last pool is v4:
799
+ if (lastPool instanceof v4Sdk.Pool) {
800
+ // If output currency is not native but path currency output is native, we need to wrap
801
+ return !this.trade.outputAmount.currency.isNative && lastRoute.pathOutput.isNative;
781
802
  }
803
+ // if last pool is not v4:
804
+ // we do not need to wrap because v2 and v3 pools already require wrapped tokens
782
805
  return false;
783
806
  }
784
807
  }, {
785
808
  key: "outputRequiresUnwrap",
786
809
  get: function get() {
787
- if (this.isAllV4) {
810
+ var swap = this.trade.swaps[0];
811
+ var lastRoute = swap.route;
812
+ var lastPool = lastRoute.pools[lastRoute.pools.length - 1];
813
+ // if last pool is v4:
814
+ if (lastPool instanceof v4Sdk.Pool) {
815
+ // If output currency is native and path currency output is not native, we need to unwrap
788
816
  return this.trade.outputAmount.currency.isNative && !this.trade.swaps[0].route.pathOutput.isNative;
789
- } else {
790
- return this.trade.outputAmount.currency.isNative;
791
817
  }
818
+ // else: if path output currency is native, we need to unwrap because v2 and v3 pools already require wrapped tokens
819
+ return this.trade.outputAmount.currency.isNative;
792
820
  }
793
821
  }, {
794
822
  key: "outputRequiresTransition",