@pancakeswap/swap-sdk-core 1.5.1 → 1.6.0

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/index.d.ts CHANGED
@@ -356,8 +356,11 @@ declare function getTokenComparator(balances: {
356
356
  [tokenAddress: string]: CurrencyAmount<Token> | undefined;
357
357
  }): (tokenA: Token, tokenB: Token) => number;
358
358
  declare function sortCurrencies<T extends Currency>(currencies: T[]): T[];
359
+ declare function sortUnifiedCurrencies<T extends UnifiedCurrency>(currencies: T[]): T[];
359
360
  declare const isCurrencySorted: (currencyA: Currency, currencyB: Currency) => boolean;
361
+ declare const isUnifiedCurrencySorted: (currencyA: UnifiedCurrency, currencyB: UnifiedCurrency) => boolean;
360
362
  declare function getCurrencyAddress(currency: Currency): `0x${string}`;
363
+ declare function getUnifiedCurrencyAddress(currency: UnifiedCurrency): string;
361
364
  declare function getMatchedCurrency(currency: Currency, list: Currency[], matchWrappedCurrency?: boolean): Currency | undefined;
362
365
 
363
- export { BaseCurrency, BigintIsh, Currency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, SPLNativeCurrency, SPLToken, SerializedSPLToken, SerializedToken, TEN, THREE, TWO, Token, TradeType, UnifiedCurrency, UnifiedCurrencyAmount, UnifiedNativeCurrency, UnifiedToken, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, computePriceImpact, getCurrencyAddress, getMatchedCurrency, getTokenComparator, isCurrencySorted, sortCurrencies, sortedInsert, sqrt, validateVMTypeInstance };
366
+ export { BaseCurrency, BigintIsh, Currency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, SPLNativeCurrency, SPLToken, SerializedSPLToken, SerializedToken, TEN, THREE, TWO, Token, TradeType, UnifiedCurrency, UnifiedCurrencyAmount, UnifiedNativeCurrency, UnifiedToken, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, computePriceImpact, getCurrencyAddress, getMatchedCurrency, getTokenComparator, getUnifiedCurrencyAddress, isCurrencySorted, isUnifiedCurrencySorted, sortCurrencies, sortUnifiedCurrencies, sortedInsert, sqrt, validateVMTypeInstance };
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ var invariant8 = require('tiny-invariant');
4
4
  var _Decimal = require('decimal.js-light');
5
5
  var _Big = require('big.js');
6
6
  var toFormat = require('toformat');
7
+ var web3_js = require('@solana/web3.js');
8
+ var BN = require('bn.js');
7
9
 
8
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
11
 
@@ -11,6 +13,7 @@ var invariant8__default = /*#__PURE__*/_interopDefault(invariant8);
11
13
  var _Decimal__default = /*#__PURE__*/_interopDefault(_Decimal);
12
14
  var _Big__default = /*#__PURE__*/_interopDefault(_Big);
13
15
  var toFormat__default = /*#__PURE__*/_interopDefault(toFormat);
16
+ var BN__default = /*#__PURE__*/_interopDefault(BN);
14
17
 
15
18
  // src/constants.ts
16
19
  var TradeType = /* @__PURE__ */ ((TradeType2) => {
@@ -520,9 +523,8 @@ var SPLToken = class extends BaseCurrency {
520
523
  return this.chainId === other.chainId && this.address === other.address;
521
524
  }
522
525
  sortsBefore(other) {
523
- invariant8__default.default(this.chainId === other.chainId, "CHAIN_IDS");
524
- invariant8__default.default(this.programId !== other.programId, "ADDRESSES");
525
- return this.programId.toLowerCase() < other.programId.toLowerCase();
526
+ invariant8__default.default(this.chainId === other.chainId, "CHAIN_IDS_MUST_MATCH");
527
+ return new BN__default.default(new web3_js.PublicKey(this.address).toBuffer()).lt(new BN__default.default(new web3_js.PublicKey(other.address).toBuffer()));
526
528
  }
527
529
  /* For compatibility */
528
530
  get wrapped() {
@@ -646,16 +648,46 @@ function sortCurrencies(currencies) {
646
648
  return a.sortsBefore(b) ? -1 : 1;
647
649
  });
648
650
  }
651
+ function sortUnifiedCurrencies(currencies) {
652
+ return currencies.sort((a, b) => {
653
+ if (a instanceof SPLToken && a.chainId === b.chainId) {
654
+ return a.sortsBefore(b.wrapped) ? -1 : 1;
655
+ }
656
+ if (b instanceof SPLToken && a.chainId === b.chainId) {
657
+ return b.sortsBefore(a.wrapped) ? 1 : -1;
658
+ }
659
+ if (a.isNative) {
660
+ return -1;
661
+ }
662
+ if (b.isNative) {
663
+ return 1;
664
+ }
665
+ if (a instanceof Token && b instanceof Token) {
666
+ return a.sortsBefore(b) ? -1 : 1;
667
+ }
668
+ return 0;
669
+ });
670
+ }
649
671
  var isCurrencySorted = (currencyA, currencyB) => {
650
672
  const [currency0] = sortCurrencies([currencyA, currencyB]);
651
673
  return currency0 === currencyA;
652
674
  };
675
+ var isUnifiedCurrencySorted = (currencyA, currencyB) => {
676
+ const [currency0] = sortUnifiedCurrencies([currencyA, currencyB]);
677
+ return currency0 === currencyA;
678
+ };
653
679
  function getCurrencyAddress(currency) {
654
680
  if (currency.isNative) {
655
681
  return ZERO_ADDRESS;
656
682
  }
657
683
  return currency.address;
658
684
  }
685
+ function getUnifiedCurrencyAddress(currency) {
686
+ if (currency.isNative) {
687
+ return currency instanceof SPLNativeCurrency ? currency.address : ZERO_ADDRESS;
688
+ }
689
+ return currency.address;
690
+ }
659
691
  function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
660
692
  const c = matchWrappedCurrency ? currency.wrapped : currency;
661
693
  for (const current of list) {
@@ -699,8 +731,11 @@ exports.computePriceImpact = computePriceImpact;
699
731
  exports.getCurrencyAddress = getCurrencyAddress;
700
732
  exports.getMatchedCurrency = getMatchedCurrency;
701
733
  exports.getTokenComparator = getTokenComparator;
734
+ exports.getUnifiedCurrencyAddress = getUnifiedCurrencyAddress;
702
735
  exports.isCurrencySorted = isCurrencySorted;
736
+ exports.isUnifiedCurrencySorted = isUnifiedCurrencySorted;
703
737
  exports.sortCurrencies = sortCurrencies;
738
+ exports.sortUnifiedCurrencies = sortUnifiedCurrencies;
704
739
  exports.sortedInsert = sortedInsert;
705
740
  exports.sqrt = sqrt;
706
741
  exports.validateVMTypeInstance = validateVMTypeInstance;
package/dist/index.mjs CHANGED
@@ -2,6 +2,8 @@ import invariant8 from 'tiny-invariant';
2
2
  import _Decimal from 'decimal.js-light';
3
3
  import _Big from 'big.js';
4
4
  import toFormat from 'toformat';
5
+ import { PublicKey } from '@solana/web3.js';
6
+ import BN from 'bn.js';
5
7
 
6
8
  // src/constants.ts
7
9
  var TradeType = /* @__PURE__ */ ((TradeType2) => {
@@ -511,9 +513,8 @@ var SPLToken = class extends BaseCurrency {
511
513
  return this.chainId === other.chainId && this.address === other.address;
512
514
  }
513
515
  sortsBefore(other) {
514
- invariant8(this.chainId === other.chainId, "CHAIN_IDS");
515
- invariant8(this.programId !== other.programId, "ADDRESSES");
516
- return this.programId.toLowerCase() < other.programId.toLowerCase();
516
+ invariant8(this.chainId === other.chainId, "CHAIN_IDS_MUST_MATCH");
517
+ return new BN(new PublicKey(this.address).toBuffer()).lt(new BN(new PublicKey(other.address).toBuffer()));
517
518
  }
518
519
  /* For compatibility */
519
520
  get wrapped() {
@@ -637,16 +638,46 @@ function sortCurrencies(currencies) {
637
638
  return a.sortsBefore(b) ? -1 : 1;
638
639
  });
639
640
  }
641
+ function sortUnifiedCurrencies(currencies) {
642
+ return currencies.sort((a, b) => {
643
+ if (a instanceof SPLToken && a.chainId === b.chainId) {
644
+ return a.sortsBefore(b.wrapped) ? -1 : 1;
645
+ }
646
+ if (b instanceof SPLToken && a.chainId === b.chainId) {
647
+ return b.sortsBefore(a.wrapped) ? 1 : -1;
648
+ }
649
+ if (a.isNative) {
650
+ return -1;
651
+ }
652
+ if (b.isNative) {
653
+ return 1;
654
+ }
655
+ if (a instanceof Token && b instanceof Token) {
656
+ return a.sortsBefore(b) ? -1 : 1;
657
+ }
658
+ return 0;
659
+ });
660
+ }
640
661
  var isCurrencySorted = (currencyA, currencyB) => {
641
662
  const [currency0] = sortCurrencies([currencyA, currencyB]);
642
663
  return currency0 === currencyA;
643
664
  };
665
+ var isUnifiedCurrencySorted = (currencyA, currencyB) => {
666
+ const [currency0] = sortUnifiedCurrencies([currencyA, currencyB]);
667
+ return currency0 === currencyA;
668
+ };
644
669
  function getCurrencyAddress(currency) {
645
670
  if (currency.isNative) {
646
671
  return ZERO_ADDRESS;
647
672
  }
648
673
  return currency.address;
649
674
  }
675
+ function getUnifiedCurrencyAddress(currency) {
676
+ if (currency.isNative) {
677
+ return currency instanceof SPLNativeCurrency ? currency.address : ZERO_ADDRESS;
678
+ }
679
+ return currency.address;
680
+ }
650
681
  function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
651
682
  const c = matchWrappedCurrency ? currency.wrapped : currency;
652
683
  for (const current of list) {
@@ -658,4 +689,4 @@ function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
658
689
  return void 0;
659
690
  }
660
691
 
661
- export { BaseCurrency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, SPLNativeCurrency, SPLToken, TEN, THREE, TWO, Token, TradeType, UnifiedCurrencyAmount, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, computePriceImpact, getCurrencyAddress, getMatchedCurrency, getTokenComparator, isCurrencySorted, sortCurrencies, sortedInsert, sqrt, validateVMTypeInstance };
692
+ export { BaseCurrency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, SPLNativeCurrency, SPLToken, TEN, THREE, TWO, Token, TradeType, UnifiedCurrencyAmount, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, computePriceImpact, getCurrencyAddress, getMatchedCurrency, getTokenComparator, getUnifiedCurrencyAddress, isCurrencySorted, isUnifiedCurrencySorted, sortCurrencies, sortUnifiedCurrencies, sortedInsert, sqrt, validateVMTypeInstance };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pancakeswap/swap-sdk-core",
3
3
  "license": "MIT",
4
- "version": "1.5.1",
4
+ "version": "1.6.0",
5
5
  "description": "🛠 An SDK for building applications on top of Pancakeswap.",
6
6
  "main": "dist/index.js",
7
7
  "typings": "dist/index.d.ts",
@@ -26,7 +26,9 @@
26
26
  "pancakeswap"
27
27
  ],
28
28
  "dependencies": {
29
+ "@solana/web3.js": "1.98.4",
29
30
  "big.js": "^5.2.2",
31
+ "bn.js": "5.2.1",
30
32
  "decimal.js-light": "^2.5.0",
31
33
  "tiny-invariant": "^1.3.0",
32
34
  "tiny-warning": "^1.0.3",
@@ -35,6 +37,7 @@
35
37
  "peerDependencies": {},
36
38
  "devDependencies": {
37
39
  "@types/big.js": "^4.0.5",
40
+ "@types/bn.js": "5.2.0",
38
41
  "tsup": "^6.7.0"
39
42
  },
40
43
  "engines": {