@pancakeswap/swap-sdk-core 1.5.1 → 1.6.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/index.d.ts +101 -1
- package/dist/index.js +81 -3
- package/dist/index.mjs +69 -4
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -356,8 +356,108 @@ 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
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Multiplier precision: ERC-8056 fixes this at 18 decimals. No precision-query function
|
|
368
|
+
* exists in the spec; do not query from chain or token metadata.
|
|
369
|
+
*/
|
|
370
|
+
declare const SCALED_UI_MULTIPLIER_DECIMALS: 18;
|
|
371
|
+
/**
|
|
372
|
+
* Denominator for all multiplier math (`10n ** 18n`). Equivalent to a multiplier of `1.0×`.
|
|
373
|
+
*/
|
|
374
|
+
declare const SCALED_UI_DENOMINATOR: bigint;
|
|
375
|
+
/**
|
|
376
|
+
* Branded type marking a `bigint` as a RAW on-chain token amount.
|
|
377
|
+
*
|
|
378
|
+
* Use `asRawAmount(n)` to mark an unbranded bigint. The math functions in this module
|
|
379
|
+
* accept plain `bigint` for ergonomic interop with the rest of the codebase; this brand
|
|
380
|
+
* exists as opt-in documentation at boundaries that want extra type-level discipline.
|
|
381
|
+
*/
|
|
382
|
+
type RawAmount = bigint & {
|
|
383
|
+
readonly __brand: 'ScaledUI.RawAmount';
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Branded type marking a `bigint` as a UI-display token amount (post-multiplier).
|
|
387
|
+
*
|
|
388
|
+
* See `RawAmount` for usage notes — this brand exists for boundary discipline, not
|
|
389
|
+
* enforced runtime checking.
|
|
390
|
+
*/
|
|
391
|
+
type UiAmount = bigint & {
|
|
392
|
+
readonly __brand: 'ScaledUI.UiAmount';
|
|
393
|
+
};
|
|
394
|
+
declare const asRawAmount: (n: bigint) => RawAmount;
|
|
395
|
+
declare const asUiAmount: (n: bigint) => UiAmount;
|
|
396
|
+
/**
|
|
397
|
+
* Returns true if the multiplier represents the identity transform (`1.0×` = `1e18`).
|
|
398
|
+
* Use this for fast-path short-circuits in hot rendering paths (tokenlist render etc.).
|
|
399
|
+
*/
|
|
400
|
+
declare function isIdentityScaledUIMultiplier(multiplier: bigint): boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Convert a raw on-chain amount to its UI-display equivalent by applying the multiplier.
|
|
403
|
+
*
|
|
404
|
+
* uiAmount = (rawAmount × multiplier) / 1e18
|
|
405
|
+
*
|
|
406
|
+
* For non-scaled tokens (`multiplier === 1e18`), this is the identity function and
|
|
407
|
+
* short-circuits without bigint mul/div.
|
|
408
|
+
*
|
|
409
|
+
* Prefer the on-chain helper `toUIAmount(rawAmount)` when the contract supports it
|
|
410
|
+
* (interface ID `0xa60bf13d`) for exact rounding-match with the contract. Use this
|
|
411
|
+
* JS implementation as a fallback when the contract lacks the helper, or in pure-math
|
|
412
|
+
* contexts (router, server-side, tests).
|
|
413
|
+
*
|
|
414
|
+
* @param rawAmount the on-chain token amount (as returned by `balanceOf`, transfer events, etc.)
|
|
415
|
+
* @param multiplier the ERC-8056 multiplier (18-decimal fixed point; `1e18 = 1.0×`)
|
|
416
|
+
* @returns the UI-display equivalent
|
|
417
|
+
*/
|
|
418
|
+
declare function toScaledUIAmount(rawAmount: bigint, multiplier: bigint): bigint;
|
|
419
|
+
/**
|
|
420
|
+
* Convert a UI-display amount back to its raw on-chain equivalent.
|
|
421
|
+
*
|
|
422
|
+
* rawAmount = (uiAmount × 1e18) / multiplier
|
|
423
|
+
*
|
|
424
|
+
* For non-scaled tokens (`multiplier === 1e18`), this is the identity function and
|
|
425
|
+
* short-circuits without bigint mul/div.
|
|
426
|
+
*
|
|
427
|
+
* Prefer the on-chain helper `fromUIAmount(uiAmount)` when the contract supports it
|
|
428
|
+
* (interface ID `0xa60bf13d`) for exact rounding-match with the contract. Use this
|
|
429
|
+
* JS implementation as a fallback when the contract lacks the helper.
|
|
430
|
+
*
|
|
431
|
+
* @param uiAmount the user-facing amount (post-multiplier)
|
|
432
|
+
* @param multiplier the ERC-8056 multiplier (18-decimal fixed point; `1e18 = 1.0×`)
|
|
433
|
+
* @returns the raw on-chain equivalent (safe to pass to `transfer`/`approve`/router calldata)
|
|
434
|
+
*/
|
|
435
|
+
declare function fromScaledUIAmount(uiAmount: bigint, multiplier: bigint): bigint;
|
|
436
|
+
/**
|
|
437
|
+
* Convert a RAW pool price to its UI-display equivalent.
|
|
438
|
+
*
|
|
439
|
+
* A price is "quote per base". Each side scales by its own token's multiplier, so the
|
|
440
|
+
* displayed ratio scales by `quoteMultiplier / baseMultiplier`:
|
|
441
|
+
*
|
|
442
|
+
* uiPrice = rawPrice × (quoteMultiplier / baseMultiplier)
|
|
443
|
+
*
|
|
444
|
+
* Implemented on the underlying fraction (`numerator × mQuote`, `denominator × mBase`), so the
|
|
445
|
+
* decimal `scalar` is untouched — the multiplier is a pure ratio on the human amount and is
|
|
446
|
+
* decimal-agnostic. For an all-identity pair this returns the input Price unchanged (no alloc).
|
|
447
|
+
*
|
|
448
|
+
* Mirror of `toScaledUIAmount` for the two-sided price case. Used by the add-liquidity current
|
|
449
|
+
* price / range / rate displays and the swap execution-price display.
|
|
450
|
+
*/
|
|
451
|
+
declare function toScaledUIPrice<TBase extends UnifiedCurrency, TQuote extends UnifiedCurrency>(price: Price<TBase, TQuote>, baseMultiplier: bigint, quoteMultiplier: bigint): Price<TBase, TQuote>;
|
|
452
|
+
/**
|
|
453
|
+
* Convert a UI-display price back to its RAW equivalent — the inverse of `toScaledUIPrice`:
|
|
454
|
+
*
|
|
455
|
+
* rawPrice = uiPrice × (baseMultiplier / quoteMultiplier)
|
|
456
|
+
*
|
|
457
|
+
* Used at the range-input boundary: a user types a UI price into the min/max boxes, which must
|
|
458
|
+
* be converted to the raw price before it feeds tick math. For an all-identity pair this returns
|
|
459
|
+
* the input Price unchanged.
|
|
460
|
+
*/
|
|
461
|
+
declare function fromScaledUIPrice<TBase extends UnifiedCurrency, TQuote extends UnifiedCurrency>(price: Price<TBase, TQuote>, baseMultiplier: bigint, quoteMultiplier: bigint): Price<TBase, TQuote>;
|
|
462
|
+
|
|
463
|
+
export { BaseCurrency, BigintIsh, Currency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, RawAmount, Rounding, SCALED_UI_DENOMINATOR, SCALED_UI_MULTIPLIER_DECIMALS, SPLNativeCurrency, SPLToken, SerializedSPLToken, SerializedToken, TEN, THREE, TWO, Token, TradeType, UiAmount, UnifiedCurrency, UnifiedCurrencyAmount, UnifiedNativeCurrency, UnifiedToken, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, asRawAmount, asUiAmount, computePriceImpact, fromScaledUIAmount, fromScaledUIPrice, getCurrencyAddress, getMatchedCurrency, getTokenComparator, getUnifiedCurrencyAddress, isCurrencySorted, isIdentityScaledUIMultiplier, isUnifiedCurrencySorted, sortCurrencies, sortUnifiedCurrencies, sortedInsert, sqrt, toScaledUIAmount, toScaledUIPrice, 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, "
|
|
524
|
-
|
|
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) {
|
|
@@ -667,6 +699,40 @@ function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
|
|
|
667
699
|
return void 0;
|
|
668
700
|
}
|
|
669
701
|
|
|
702
|
+
// src/scaledUIAmount.ts
|
|
703
|
+
var SCALED_UI_MULTIPLIER_DECIMALS = 18;
|
|
704
|
+
var SCALED_UI_DENOMINATOR = 10n ** 18n;
|
|
705
|
+
var asRawAmount = (n) => n;
|
|
706
|
+
var asUiAmount = (n) => n;
|
|
707
|
+
function isIdentityScaledUIMultiplier(multiplier) {
|
|
708
|
+
return multiplier === SCALED_UI_DENOMINATOR;
|
|
709
|
+
}
|
|
710
|
+
function toScaledUIAmount(rawAmount, multiplier) {
|
|
711
|
+
if (multiplier === 0n)
|
|
712
|
+
return rawAmount;
|
|
713
|
+
return isIdentityScaledUIMultiplier(multiplier) ? rawAmount : rawAmount * multiplier / SCALED_UI_DENOMINATOR;
|
|
714
|
+
}
|
|
715
|
+
function fromScaledUIAmount(uiAmount, multiplier) {
|
|
716
|
+
if (multiplier === 0n)
|
|
717
|
+
return uiAmount;
|
|
718
|
+
return isIdentityScaledUIMultiplier(multiplier) ? uiAmount : uiAmount * SCALED_UI_DENOMINATOR / multiplier;
|
|
719
|
+
}
|
|
720
|
+
var sanitizeMultiplier = (m) => m === 0n ? SCALED_UI_DENOMINATOR : m;
|
|
721
|
+
function toScaledUIPrice(price, baseMultiplier, quoteMultiplier) {
|
|
722
|
+
const mBase = sanitizeMultiplier(baseMultiplier);
|
|
723
|
+
const mQuote = sanitizeMultiplier(quoteMultiplier);
|
|
724
|
+
if (isIdentityScaledUIMultiplier(mBase) && isIdentityScaledUIMultiplier(mQuote))
|
|
725
|
+
return price;
|
|
726
|
+
return new Price(price.baseCurrency, price.quoteCurrency, price.denominator * mBase, price.numerator * mQuote);
|
|
727
|
+
}
|
|
728
|
+
function fromScaledUIPrice(price, baseMultiplier, quoteMultiplier) {
|
|
729
|
+
const mBase = sanitizeMultiplier(baseMultiplier);
|
|
730
|
+
const mQuote = sanitizeMultiplier(quoteMultiplier);
|
|
731
|
+
if (isIdentityScaledUIMultiplier(mBase) && isIdentityScaledUIMultiplier(mQuote))
|
|
732
|
+
return price;
|
|
733
|
+
return new Price(price.baseCurrency, price.quoteCurrency, price.denominator * mQuote, price.numerator * mBase);
|
|
734
|
+
}
|
|
735
|
+
|
|
670
736
|
exports.BaseCurrency = BaseCurrency;
|
|
671
737
|
exports.CurrencyAmount = CurrencyAmount;
|
|
672
738
|
exports.FIVE = FIVE;
|
|
@@ -680,6 +746,8 @@ exports.ONE = ONE;
|
|
|
680
746
|
exports.Percent = Percent;
|
|
681
747
|
exports.Price = Price;
|
|
682
748
|
exports.Rounding = Rounding;
|
|
749
|
+
exports.SCALED_UI_DENOMINATOR = SCALED_UI_DENOMINATOR;
|
|
750
|
+
exports.SCALED_UI_MULTIPLIER_DECIMALS = SCALED_UI_MULTIPLIER_DECIMALS;
|
|
683
751
|
exports.SPLNativeCurrency = SPLNativeCurrency;
|
|
684
752
|
exports.SPLToken = SPLToken;
|
|
685
753
|
exports.TEN = TEN;
|
|
@@ -695,12 +763,22 @@ exports.ZERO_ADDRESS = ZERO_ADDRESS;
|
|
|
695
763
|
exports._100 = _100;
|
|
696
764
|
exports._10000 = _10000;
|
|
697
765
|
exports._9975 = _9975;
|
|
766
|
+
exports.asRawAmount = asRawAmount;
|
|
767
|
+
exports.asUiAmount = asUiAmount;
|
|
698
768
|
exports.computePriceImpact = computePriceImpact;
|
|
769
|
+
exports.fromScaledUIAmount = fromScaledUIAmount;
|
|
770
|
+
exports.fromScaledUIPrice = fromScaledUIPrice;
|
|
699
771
|
exports.getCurrencyAddress = getCurrencyAddress;
|
|
700
772
|
exports.getMatchedCurrency = getMatchedCurrency;
|
|
701
773
|
exports.getTokenComparator = getTokenComparator;
|
|
774
|
+
exports.getUnifiedCurrencyAddress = getUnifiedCurrencyAddress;
|
|
702
775
|
exports.isCurrencySorted = isCurrencySorted;
|
|
776
|
+
exports.isIdentityScaledUIMultiplier = isIdentityScaledUIMultiplier;
|
|
777
|
+
exports.isUnifiedCurrencySorted = isUnifiedCurrencySorted;
|
|
703
778
|
exports.sortCurrencies = sortCurrencies;
|
|
779
|
+
exports.sortUnifiedCurrencies = sortUnifiedCurrencies;
|
|
704
780
|
exports.sortedInsert = sortedInsert;
|
|
705
781
|
exports.sqrt = sqrt;
|
|
782
|
+
exports.toScaledUIAmount = toScaledUIAmount;
|
|
783
|
+
exports.toScaledUIPrice = toScaledUIPrice;
|
|
706
784
|
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, "
|
|
515
|
-
|
|
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,38 @@ function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
|
|
|
658
689
|
return void 0;
|
|
659
690
|
}
|
|
660
691
|
|
|
661
|
-
|
|
692
|
+
// src/scaledUIAmount.ts
|
|
693
|
+
var SCALED_UI_MULTIPLIER_DECIMALS = 18;
|
|
694
|
+
var SCALED_UI_DENOMINATOR = 10n ** 18n;
|
|
695
|
+
var asRawAmount = (n) => n;
|
|
696
|
+
var asUiAmount = (n) => n;
|
|
697
|
+
function isIdentityScaledUIMultiplier(multiplier) {
|
|
698
|
+
return multiplier === SCALED_UI_DENOMINATOR;
|
|
699
|
+
}
|
|
700
|
+
function toScaledUIAmount(rawAmount, multiplier) {
|
|
701
|
+
if (multiplier === 0n)
|
|
702
|
+
return rawAmount;
|
|
703
|
+
return isIdentityScaledUIMultiplier(multiplier) ? rawAmount : rawAmount * multiplier / SCALED_UI_DENOMINATOR;
|
|
704
|
+
}
|
|
705
|
+
function fromScaledUIAmount(uiAmount, multiplier) {
|
|
706
|
+
if (multiplier === 0n)
|
|
707
|
+
return uiAmount;
|
|
708
|
+
return isIdentityScaledUIMultiplier(multiplier) ? uiAmount : uiAmount * SCALED_UI_DENOMINATOR / multiplier;
|
|
709
|
+
}
|
|
710
|
+
var sanitizeMultiplier = (m) => m === 0n ? SCALED_UI_DENOMINATOR : m;
|
|
711
|
+
function toScaledUIPrice(price, baseMultiplier, quoteMultiplier) {
|
|
712
|
+
const mBase = sanitizeMultiplier(baseMultiplier);
|
|
713
|
+
const mQuote = sanitizeMultiplier(quoteMultiplier);
|
|
714
|
+
if (isIdentityScaledUIMultiplier(mBase) && isIdentityScaledUIMultiplier(mQuote))
|
|
715
|
+
return price;
|
|
716
|
+
return new Price(price.baseCurrency, price.quoteCurrency, price.denominator * mBase, price.numerator * mQuote);
|
|
717
|
+
}
|
|
718
|
+
function fromScaledUIPrice(price, baseMultiplier, quoteMultiplier) {
|
|
719
|
+
const mBase = sanitizeMultiplier(baseMultiplier);
|
|
720
|
+
const mQuote = sanitizeMultiplier(quoteMultiplier);
|
|
721
|
+
if (isIdentityScaledUIMultiplier(mBase) && isIdentityScaledUIMultiplier(mQuote))
|
|
722
|
+
return price;
|
|
723
|
+
return new Price(price.baseCurrency, price.quoteCurrency, price.denominator * mQuote, price.numerator * mBase);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export { BaseCurrency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, SCALED_UI_DENOMINATOR, SCALED_UI_MULTIPLIER_DECIMALS, SPLNativeCurrency, SPLToken, TEN, THREE, TWO, Token, TradeType, UnifiedCurrencyAmount, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, asRawAmount, asUiAmount, computePriceImpact, fromScaledUIAmount, fromScaledUIPrice, getCurrencyAddress, getMatchedCurrency, getTokenComparator, getUnifiedCurrencyAddress, isCurrencySorted, isIdentityScaledUIMultiplier, isUnifiedCurrencySorted, sortCurrencies, sortUnifiedCurrencies, sortedInsert, sqrt, toScaledUIAmount, toScaledUIPrice, 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.
|
|
4
|
+
"version": "1.6.1",
|
|
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": {
|