@pancakeswap/swap-sdk-core 1.3.0 → 1.5.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.
@@ -1,9 +1,7 @@
1
- import { Currency } from './currency';
2
- import type { Token } from './token';
3
1
  /**
4
2
  * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
5
3
  */
6
- export declare abstract class BaseCurrency {
4
+ export declare abstract class BaseCurrency<T extends BaseCurrency<any> = BaseCurrency<any>> {
7
5
  /**
8
6
  * Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
9
7
  */
@@ -40,11 +38,12 @@ export declare abstract class BaseCurrency {
40
38
  * Returns whether this currency is functionally equivalent to the other currency
41
39
  * @param other the other currency
42
40
  */
43
- abstract equals(other: Currency): boolean;
41
+ abstract equals(other: BaseCurrency<any>): boolean;
44
42
  /**
45
43
  * Return the wrapped version of this currency that can be used with the PancakeSwap contracts. Currencies must
46
44
  * implement this to be used in PancakeSwap
47
45
  */
48
- abstract get wrapped(): Token;
46
+ abstract get wrapped(): T;
47
+ get asToken(): T;
49
48
  }
50
49
  //# sourceMappingURL=baseCurrency.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"baseCurrency.d.ts","sourceRoot":"","sources":["../src/baseCurrency.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC;;GAEG;AACH,8BAAsB,YAAY;IAChC;;OAEG;IACH,kBAAyB,QAAQ,EAAE,OAAO,CAAA;IAE1C;;OAEG;IACH,kBAAyB,OAAO,EAAE,OAAO,CAAA;IAEzC;;OAEG;IACH,SAAgB,OAAO,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACH,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAEhC;;OAEG;IACH,SAAgB,MAAM,EAAE,MAAM,CAAA;IAE9B;;OAEG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAA;IAE7B;;;;;;OAMG;IACH,SAAS,aAAa,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAUtF;;;OAGG;aACa,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAEhD;;;OAGG;IACH,aAAoB,OAAO,IAAI,KAAK,CAAA;CACrC"}
1
+ {"version":3,"file":"baseCurrency.d.ts","sourceRoot":"","sources":["../src/baseCurrency.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,8BAAsB,YAAY,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC;IAChF;;OAEG;IACH,kBAAyB,QAAQ,EAAE,OAAO,CAAA;IAE1C;;OAEG;IACH,kBAAyB,OAAO,EAAE,OAAO,CAAA;IAEzC;;OAEG;IACH,SAAgB,OAAO,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACH,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAEhC;;OAEG;IACH,SAAgB,MAAM,EAAE,MAAM,CAAA;IAE9B;;OAEG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAA;IAE7B;;;;;;OAMG;IACH,SAAS,aAAa,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAWtF;;;OAGG;aACa,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO;IAEzD;;;OAGG;IACH,aAAoB,OAAO,IAAI,CAAC,CAAA;IAEhC,IAAW,OAAO,IAAI,CAAC,CAEtB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAA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B,eAAO,MAAM,IAAI,OAAO,CAAA;AACxB,eAAO,MAAM,KAAK,QAAQ,CAAA;AAC1B,eAAO,MAAM,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,UAAU,QAA+E,CAAA;AAEtG,oBAAY,MAAM;IAChB,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED,eAAO,MAAM,cAAc;;;CAG1B,CAAA;AAED,eAAO,MAAM,YAAY,EAAG,4CAAqD,CAAA"}
@@ -1,4 +1,9 @@
1
1
  import type { NativeCurrency } from './nativeCurrency';
2
+ import { SPLNativeCurrency } from './splNativeCurrency';
3
+ import { SPLToken } from './splToken';
2
4
  import type { Token } from './token';
3
5
  export type Currency = NativeCurrency | Token;
6
+ export type UnifiedNativeCurrency = NativeCurrency | SPLNativeCurrency;
7
+ export type UnifiedCurrency = SPLToken | SPLNativeCurrency | Currency;
8
+ export type UnifiedToken = SPLToken | Token;
4
9
  //# sourceMappingURL=currency.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,KAAK,CAAA;AAE7C,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG,iBAAiB,CAAA;AACtE,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,iBAAiB,GAAG,QAAQ,CAAA;AACrE,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,KAAK,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,SAAgB,2BAA2B,OAAgB;;CAO5D;AAED;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,8BAA8B,OAAgB;;CAO/D"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,SAAgB,2BAA2B,EAAG,IAAI,CAAS;;CAO5D;AAED;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,8BAA8B,EAAG,IAAI,CAAS;;CAO/D"}
@@ -20,6 +20,7 @@ export declare class CurrencyAmount<T extends Currency> extends Fraction {
20
20
  static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
21
21
  protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
22
22
  add(other: CurrencyAmount<T>): CurrencyAmount<T>;
23
+ subtract(value: bigint): CurrencyAmount<T>;
23
24
  subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
24
25
  multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
25
26
  divide(other: Fraction | BigintIsh): CurrencyAmount<T>;
@@ -27,5 +28,6 @@ export declare class CurrencyAmount<T extends Currency> extends Fraction {
27
28
  toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
28
29
  toExact(format?: object): string;
29
30
  get wrapped(): CurrencyAmount<Token>;
31
+ info(): string;
30
32
  }
31
33
  //# sourceMappingURL=currenc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,CAAC,CAAC;IAE1C,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAgBrD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC;IAKxD,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC;IAKtD,aAAa,CAAC,iBAAiB,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,QAA8B,GAAG,MAAM;IAIvG,OAAO,CACZ,aAAa,GAAE,MAA+B,EAC9C,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,GAAE,QAA8B,GACvC,MAAM;IAKF,OAAO,CAAC,MAAM,GAAE,MAA+B,GAAG,MAAM;IAK/D,IAAW,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAG1C;IAEM,IAAI;CAGZ"}
@@ -1,5 +1,6 @@
1
1
  export * from './fraction';
2
2
  export * from './percent';
3
3
  export * from './currencyAmount';
4
+ export * from './unifiedCurrencyAmount';
4
5
  export * from './price';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fractions/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fractions/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../src/fractions/percent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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AQ,GAAG,SAAS,GAAG,OAAO;IAI9C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO;IAI9C,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO;IAIrC,aAAa,CAAC,iBAAiB,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;IAIlF,OAAO,CAAC,aAAa,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;CAGhF"}
@@ -1,8 +1,8 @@
1
1
  import { BigintIsh, Rounding } from '../constants';
2
2
  import { Currency } from '../currency';
3
- import { Fraction } from './fraction';
4
- import { CurrencyAmount } from './currencyAmount';
5
3
  import { Token } from '../token';
4
+ import { CurrencyAmount } from './currencyAmount';
5
+ import { Fraction } from './fraction';
6
6
  export declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
7
7
  readonly baseCurrency: TBase;
8
8
  readonly quoteCurrency: TQuote;
@@ -37,5 +37,13 @@ export declare class Price<TBase extends Currency, TQuote extends Currency> exte
37
37
  toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
38
38
  toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
39
39
  get wrapped(): Price<Token, Token>;
40
+ /**
41
+ * Create a price from base and quote currency and a decimal string
42
+ * @param base
43
+ * @param quote
44
+ * @param value
45
+ * @returns Price<TBase, TQuote> | undefined
46
+ */
47
+ static fromDecimal<TBase extends Currency, TQuote extends Currency>(base: TBase, quote: TQuote, value: string): Price<TBase, TQuote> | undefined;
40
48
  }
41
49
  //# sourceMappingURL=price.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/fractions/price.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAA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,MAAM;IAIlF,OAAO,CAAC,aAAa,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;IAI/E,IAAW,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAExC;IAED;;;;;;OAMG;WACW,WAAW,CAAC,KAAK,SAAS,QAAQ,EAAE,MAAM,SAAS,QAAQ,EACvE,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS;CAiBpC"}
@@ -0,0 +1,32 @@
1
+ import { UnifiedCurrency, UnifiedToken } from '../currency';
2
+ import { Fraction } from './fraction';
3
+ import { BigintIsh, Rounding } from '../constants';
4
+ export declare class UnifiedCurrencyAmount<T extends UnifiedCurrency> extends Fraction {
5
+ readonly currency: T;
6
+ readonly decimalScale: bigint;
7
+ /**
8
+ * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
9
+ * @param currency the currency in the amount
10
+ * @param rawAmount the raw token or ether amount
11
+ */
12
+ static fromRawAmount<T extends UnifiedCurrency>(currency: T, rawAmount: BigintIsh): UnifiedCurrencyAmount<T>;
13
+ /**
14
+ * Construct a currency amount with a denominator that is not equal to 1
15
+ * @param currency the currency
16
+ * @param numerator the numerator of the fractional token amount
17
+ * @param denominator the denominator of the fractional token amount
18
+ */
19
+ static fromFractionalAmount<T extends UnifiedCurrency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): UnifiedCurrencyAmount<T>;
20
+ protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
21
+ add(other: UnifiedCurrencyAmount<T>): UnifiedCurrencyAmount<T>;
22
+ subtract(value: bigint): UnifiedCurrencyAmount<T>;
23
+ subtract(other: UnifiedCurrencyAmount<T>): UnifiedCurrencyAmount<T>;
24
+ multiply(other: Fraction | BigintIsh): UnifiedCurrencyAmount<T>;
25
+ divide(other: Fraction | BigintIsh): UnifiedCurrencyAmount<T>;
26
+ toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
27
+ toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
28
+ toExact(format?: object): string;
29
+ get wrapped(): UnifiedCurrencyAmount<UnifiedToken>;
30
+ info(): string;
31
+ }
32
+ //# sourceMappingURL=unifiedCurrencyAmount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unifiedCurrencyAmount.d.ts","sourceRoot":"","sources":["../../src/fractions/unifiedCurrencyAmount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,OAAO,EAAE,SAAS,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI9D,qBAAa,qBAAqB,CAAC,CAAC,SAAS,eAAe,CAAE,SAAQ,QAAQ;IAC5E,SAAgB,QAAQ,EAAE,CAAC,CAAA;IAE3B,SAAgB,YAAY,EAAE,MAAM,CAAA;IAEpC;;;;OAIG;WACW,aAAa,CAAC,CAAC,SAAS,eAAe,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAInH;;;;;OAKG;WACW,oBAAoB,CAAC,CAAC,SAAS,eAAe,EAC1D,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,SAAS,GACrB,qBAAqB,CAAC,CAAC,CAAC;IAI3B,SAAS,aAAa,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,SAAS;IAOzE,GAAG,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAM9D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAEjD,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAgBnE,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAK/D,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAK7D,aAAa,CAAC,iBAAiB,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,QAA8B,GAAG,MAAM;IAIvG,OAAO,CACZ,aAAa,GAAE,MAA+B,EAC9C,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,GAAE,QAA8B,GACvC,MAAM;IAKF,OAAO,CAAC,MAAM,GAAE,MAA+B,GAAG,MAAM;IAK/D,IAAW,OAAO,IAAI,qBAAqB,CAAC,YAAY,CAAC,CAGxD;IAEM,IAAI;CAGZ"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,9 @@ export * from './baseCurrency';
3
3
  export * from './currency';
4
4
  export * from './fractions';
5
5
  export * from './nativeCurrency';
6
+ export * from './splNativeCurrency';
6
7
  export * from './token';
8
+ export * from './splToken';
7
9
  export * from './errors';
8
10
  export * from './utils';
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var invariant6 = require('tiny-invariant');
3
+ 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
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
- var invariant6__default = /*#__PURE__*/_interopDefault(invariant6);
10
+ var invariant8__default = /*#__PURE__*/_interopDefault(invariant8);
11
11
  var _Decimal__default = /*#__PURE__*/_interopDefault(_Decimal);
12
12
  var _Big__default = /*#__PURE__*/_interopDefault(_Big);
13
13
  var toFormat__default = /*#__PURE__*/_interopDefault(toFormat);
@@ -54,13 +54,15 @@ var BaseCurrency = class {
54
54
  * @param name of the currency
55
55
  */
56
56
  constructor(chainId, decimals, symbol, name) {
57
- invariant6__default.default(Number.isSafeInteger(chainId), "CHAIN_ID");
58
- invariant6__default.default(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
57
+ invariant8__default.default(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
59
58
  this.chainId = chainId;
60
59
  this.decimals = decimals;
61
60
  this.symbol = symbol;
62
61
  this.name = name;
63
62
  }
63
+ get asToken() {
64
+ return this.wrapped;
65
+ }
64
66
  };
65
67
  var Decimal = toFormat__default.default(_Decimal__default.default);
66
68
  var Big = toFormat__default.default(_Big__default.default);
@@ -138,15 +140,15 @@ var Fraction = class {
138
140
  return new Fraction(this.numerator * otherParsed.denominator, this.denominator * otherParsed.numerator);
139
141
  }
140
142
  toSignificant(significantDigits, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
141
- invariant6__default.default(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
142
- invariant6__default.default(significantDigits > 0, `${significantDigits} is not positive.`);
143
+ invariant8__default.default(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
144
+ invariant8__default.default(significantDigits > 0, `${significantDigits} is not positive.`);
143
145
  Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] });
144
146
  const quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
145
147
  return quotient.toFormat(quotient.decimalPlaces(), format);
146
148
  }
147
149
  toFixed(decimalPlaces, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
148
- invariant6__default.default(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
149
- invariant6__default.default(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
150
+ invariant8__default.default(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
151
+ invariant8__default.default(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
150
152
  Big.DP = decimalPlaces;
151
153
  Big.RM = toFixedRounding[rounding];
152
154
  return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
@@ -196,7 +198,7 @@ var Big2 = toFormat__default.default(_Big__default.default);
196
198
  var CurrencyAmount = class extends Fraction {
197
199
  constructor(currency, numerator, denominator) {
198
200
  super(numerator, denominator);
199
- invariant6__default.default(this.quotient <= MaxUint256, "AMOUNT");
201
+ invariant8__default.default(this.quotient <= MaxUint256, "AMOUNT");
200
202
  this.currency = currency;
201
203
  this.decimalScale = 10n ** BigInt(currency.decimals);
202
204
  }
@@ -218,13 +220,20 @@ var CurrencyAmount = class extends Fraction {
218
220
  return new CurrencyAmount(currency, numerator, denominator);
219
221
  }
220
222
  add(other) {
221
- invariant6__default.default(this.currency.equals(other.currency), "CURRENCY");
223
+ invariant8__default.default(this.currency.equals(other.currency), "CURRENCY");
222
224
  const added = super.add(other);
223
225
  return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
224
226
  }
225
- subtract(other) {
226
- invariant6__default.default(this.currency.equals(other.currency), "CURRENCY");
227
- const subtracted = super.subtract(other);
227
+ subtract(value) {
228
+ if (typeof value === "bigint") {
229
+ return CurrencyAmount.fromFractionalAmount(
230
+ this.currency,
231
+ this.numerator - value * this.denominator,
232
+ this.denominator
233
+ );
234
+ }
235
+ invariant8__default.default(this.currency.equals(value.currency), "CURRENCY");
236
+ const subtracted = super.subtract(value);
228
237
  return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
229
238
  }
230
239
  multiply(other) {
@@ -239,7 +248,7 @@ var CurrencyAmount = class extends Fraction {
239
248
  return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
240
249
  }
241
250
  toFixed(decimalPlaces = this.currency.decimals, format, rounding = 0 /* ROUND_DOWN */) {
242
- invariant6__default.default(decimalPlaces <= this.currency.decimals, "DECIMALS");
251
+ invariant8__default.default(decimalPlaces <= this.currency.decimals, "DECIMALS");
243
252
  return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
244
253
  }
245
254
  toExact(format = { groupSeparator: "" }) {
@@ -251,6 +260,79 @@ var CurrencyAmount = class extends Fraction {
251
260
  return this;
252
261
  return CurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
253
262
  }
263
+ info() {
264
+ return `${this.toExact()}${this.currency.symbol}`;
265
+ }
266
+ };
267
+ var Big3 = toFormat__default.default(_Big__default.default);
268
+ var UnifiedCurrencyAmount = class extends Fraction {
269
+ constructor(currency, numerator, denominator) {
270
+ super(numerator, denominator);
271
+ invariant8__default.default(this.quotient <= MaxUint256, "AMOUNT");
272
+ this.currency = currency;
273
+ this.decimalScale = 10n ** BigInt(currency.decimals);
274
+ }
275
+ /**
276
+ * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
277
+ * @param currency the currency in the amount
278
+ * @param rawAmount the raw token or ether amount
279
+ */
280
+ static fromRawAmount(currency, rawAmount) {
281
+ return new UnifiedCurrencyAmount(currency, rawAmount);
282
+ }
283
+ /**
284
+ * Construct a currency amount with a denominator that is not equal to 1
285
+ * @param currency the currency
286
+ * @param numerator the numerator of the fractional token amount
287
+ * @param denominator the denominator of the fractional token amount
288
+ */
289
+ static fromFractionalAmount(currency, numerator, denominator) {
290
+ return new UnifiedCurrencyAmount(currency, numerator, denominator);
291
+ }
292
+ add(other) {
293
+ invariant8__default.default(this.currency.equals(other.currency), "CURRENCY");
294
+ const added = super.add(other);
295
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
296
+ }
297
+ subtract(value) {
298
+ if (typeof value === "bigint") {
299
+ return UnifiedCurrencyAmount.fromFractionalAmount(
300
+ this.currency,
301
+ this.numerator - value * this.denominator,
302
+ this.denominator
303
+ );
304
+ }
305
+ invariant8__default.default(this.currency.equals(value.currency), "CURRENCY");
306
+ const subtracted = super.subtract(value);
307
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
308
+ }
309
+ multiply(other) {
310
+ const multiplied = super.multiply(other);
311
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
312
+ }
313
+ divide(other) {
314
+ const divided = super.divide(other);
315
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
316
+ }
317
+ toSignificant(significantDigits = 6, format, rounding = 0 /* ROUND_DOWN */) {
318
+ return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
319
+ }
320
+ toFixed(decimalPlaces = this.currency.decimals, format, rounding = 0 /* ROUND_DOWN */) {
321
+ invariant8__default.default(decimalPlaces <= this.currency.decimals, "DECIMALS");
322
+ return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
323
+ }
324
+ toExact(format = { groupSeparator: "" }) {
325
+ Big3.DP = this.currency.decimals;
326
+ return new Big3(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(format);
327
+ }
328
+ get wrapped() {
329
+ if (this.currency.isToken)
330
+ return this;
331
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
332
+ }
333
+ info() {
334
+ return `${this.toExact()}${this.currency.symbol}`;
335
+ }
254
336
  };
255
337
  var Price = class extends Fraction {
256
338
  // used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
@@ -290,7 +372,7 @@ var Price = class extends Fraction {
290
372
  * @param other the other price
291
373
  */
292
374
  multiply(other) {
293
- invariant6__default.default(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
375
+ invariant8__default.default(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
294
376
  const fraction = super.multiply(other);
295
377
  return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
296
378
  }
@@ -299,7 +381,7 @@ var Price = class extends Fraction {
299
381
  * @param currencyAmount the amount of base currency to quote against the price
300
382
  */
301
383
  quote(currencyAmount) {
302
- invariant6__default.default(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
384
+ invariant8__default.default(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
303
385
  const result = super.multiply(currencyAmount);
304
386
  return CurrencyAmount.fromFractionalAmount(this.quoteCurrency, result.numerator, result.denominator);
305
387
  }
@@ -319,14 +401,26 @@ var Price = class extends Fraction {
319
401
  get wrapped() {
320
402
  return new Price(this.baseCurrency.wrapped, this.quoteCurrency.wrapped, this.denominator, this.numerator);
321
403
  }
322
- };
323
-
324
- // src/nativeCurrency.ts
325
- var NativeCurrency = class extends BaseCurrency {
326
- constructor() {
327
- super(...arguments);
328
- this.isNative = true;
329
- this.isToken = false;
404
+ /**
405
+ * Create a price from base and quote currency and a decimal string
406
+ * @param base
407
+ * @param quote
408
+ * @param value
409
+ * @returns Price<TBase, TQuote> | undefined
410
+ */
411
+ static fromDecimal(base, quote, value) {
412
+ if (!value || value.length > 257 || !value.match(/^\d*\.?\d+$/)) {
413
+ return void 0;
414
+ }
415
+ const [whole, fraction] = value.split(".");
416
+ const decimals = fraction?.length ?? 0;
417
+ const withoutDecimals = BigInt((whole ?? "") + (fraction ?? ""));
418
+ return new Price(
419
+ base,
420
+ quote,
421
+ BigInt(10 ** decimals) * BigInt(10 ** base.decimals),
422
+ withoutDecimals * BigInt(10 ** quote.decimals)
423
+ );
330
424
  }
331
425
  };
332
426
  var Token = class extends BaseCurrency {
@@ -351,8 +445,8 @@ var Token = class extends BaseCurrency {
351
445
  * @throws if the tokens are on different chains
352
446
  */
353
447
  sortsBefore(other) {
354
- invariant6__default.default(this.chainId === other.chainId, "CHAIN_IDS");
355
- invariant6__default.default(this.address !== other.address, "ADDRESSES");
448
+ invariant8__default.default(this.chainId === other.chainId, "CHAIN_IDS");
449
+ invariant8__default.default(this.address !== other.address, "ADDRESSES");
356
450
  return this.address.toLowerCase() < other.address.toLowerCase();
357
451
  }
358
452
  /**
@@ -373,6 +467,80 @@ var Token = class extends BaseCurrency {
373
467
  }
374
468
  };
375
469
 
470
+ // src/nativeCurrency.ts
471
+ var NativeCurrency = class extends BaseCurrency {
472
+ constructor() {
473
+ super(...arguments);
474
+ this.isNative = true;
475
+ this.isToken = false;
476
+ }
477
+ get asToken() {
478
+ return new Token(this.chainId, ZERO_ADDRESS, this.decimals, this.symbol, this.name);
479
+ }
480
+ };
481
+
482
+ // src/splNativeCurrency.ts
483
+ var SPLNativeCurrency = class extends BaseCurrency {
484
+ constructor() {
485
+ super(...arguments);
486
+ this.isNative = true;
487
+ this.isToken = false;
488
+ this.address = "";
489
+ }
490
+ };
491
+ var SPLToken = class extends BaseCurrency {
492
+ constructor({
493
+ chainId,
494
+ programId,
495
+ address,
496
+ decimals,
497
+ symbol,
498
+ logoURI,
499
+ name,
500
+ projectLink
501
+ }) {
502
+ super(chainId, decimals, symbol, name);
503
+ this.isNative = false;
504
+ this.isToken = true;
505
+ this.address = address;
506
+ this.programId = programId;
507
+ this.logoURI = logoURI;
508
+ this.projectLink = projectLink;
509
+ }
510
+ static isSPLToken(token) {
511
+ if (!token)
512
+ return false;
513
+ return "programId" in token || token.wrapped instanceof SPLToken;
514
+ }
515
+ /**
516
+ * Returns true if the two tokens are equivalent, i.e. have the same chainId and programId.
517
+ * @param other other token to compare
518
+ */
519
+ equals(other) {
520
+ return this.chainId === other.chainId && this.address === other.address;
521
+ }
522
+ 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
+ }
527
+ /* For compatibility */
528
+ get wrapped() {
529
+ return this;
530
+ }
531
+ get serialize() {
532
+ return {
533
+ address: this.address,
534
+ programId: this.programId,
535
+ chainId: this.chainId,
536
+ decimals: this.decimals,
537
+ symbol: this.symbol,
538
+ name: this.name,
539
+ projectLink: this.projectLink
540
+ };
541
+ }
542
+ };
543
+
376
544
  // src/errors.ts
377
545
  var CAN_SET_PROTOTYPE = "setPrototypeOf" in Object;
378
546
  var InsufficientReservesError = class extends Error {
@@ -394,11 +562,11 @@ var InsufficientInputAmountError = class extends Error {
394
562
  }
395
563
  };
396
564
  function validateVMTypeInstance(value, vmType) {
397
- invariant6__default.default(value >= ZERO, `${value} is not a ${vmType}.`);
398
- invariant6__default.default(value <= VM_TYPE_MAXIMA[vmType], `${value} is not a ${vmType}.`);
565
+ invariant8__default.default(value >= ZERO, `${value} is not a ${vmType}.`);
566
+ invariant8__default.default(value <= VM_TYPE_MAXIMA[vmType], `${value} is not a ${vmType}.`);
399
567
  }
400
568
  function sqrt(y) {
401
- invariant6__default.default(y >= ZERO, "NEGATIVE");
569
+ invariant8__default.default(y >= ZERO, "NEGATIVE");
402
570
  let z = ZERO;
403
571
  let x;
404
572
  if (y > THREE) {
@@ -414,8 +582,8 @@ function sqrt(y) {
414
582
  return z;
415
583
  }
416
584
  function sortedInsert(items, add, maxSize, comparator) {
417
- invariant6__default.default(maxSize > 0, "MAX_SIZE_ZERO");
418
- invariant6__default.default(items.length <= maxSize, "ITEMS_SIZE");
585
+ invariant8__default.default(maxSize > 0, "MAX_SIZE_ZERO");
586
+ invariant8__default.default(items.length <= maxSize, "ITEMS_SIZE");
419
587
  if (items.length === 0) {
420
588
  items.push(add);
421
589
  return null;
@@ -478,12 +646,26 @@ function sortCurrencies(currencies) {
478
646
  return a.sortsBefore(b) ? -1 : 1;
479
647
  });
480
648
  }
649
+ var isCurrencySorted = (currencyA, currencyB) => {
650
+ const [currency0] = sortCurrencies([currencyA, currencyB]);
651
+ return currency0 === currencyA;
652
+ };
481
653
  function getCurrencyAddress(currency) {
482
654
  if (currency.isNative) {
483
655
  return ZERO_ADDRESS;
484
656
  }
485
657
  return currency.address;
486
658
  }
659
+ function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
660
+ const c = matchWrappedCurrency ? currency.wrapped : currency;
661
+ for (const current of list) {
662
+ const checkAgainst = matchWrappedCurrency ? current.wrapped : current;
663
+ if (checkAgainst.equals(c)) {
664
+ return current;
665
+ }
666
+ }
667
+ return void 0;
668
+ }
487
669
 
488
670
  exports.BaseCurrency = BaseCurrency;
489
671
  exports.CurrencyAmount = CurrencyAmount;
@@ -498,11 +680,14 @@ exports.ONE = ONE;
498
680
  exports.Percent = Percent;
499
681
  exports.Price = Price;
500
682
  exports.Rounding = Rounding;
683
+ exports.SPLNativeCurrency = SPLNativeCurrency;
684
+ exports.SPLToken = SPLToken;
501
685
  exports.TEN = TEN;
502
686
  exports.THREE = THREE;
503
687
  exports.TWO = TWO;
504
688
  exports.Token = Token;
505
689
  exports.TradeType = TradeType;
690
+ exports.UnifiedCurrencyAmount = UnifiedCurrencyAmount;
506
691
  exports.VMType = VMType;
507
692
  exports.VM_TYPE_MAXIMA = VM_TYPE_MAXIMA;
508
693
  exports.ZERO = ZERO;
@@ -512,7 +697,9 @@ exports._10000 = _10000;
512
697
  exports._9975 = _9975;
513
698
  exports.computePriceImpact = computePriceImpact;
514
699
  exports.getCurrencyAddress = getCurrencyAddress;
700
+ exports.getMatchedCurrency = getMatchedCurrency;
515
701
  exports.getTokenComparator = getTokenComparator;
702
+ exports.isCurrencySorted = isCurrencySorted;
516
703
  exports.sortCurrencies = sortCurrencies;
517
704
  exports.sortedInsert = sortedInsert;
518
705
  exports.sqrt = sqrt;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import invariant6 from 'tiny-invariant';
1
+ 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';
@@ -45,13 +45,15 @@ var BaseCurrency = class {
45
45
  * @param name of the currency
46
46
  */
47
47
  constructor(chainId, decimals, symbol, name) {
48
- invariant6(Number.isSafeInteger(chainId), "CHAIN_ID");
49
- invariant6(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
48
+ invariant8(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), "DECIMALS");
50
49
  this.chainId = chainId;
51
50
  this.decimals = decimals;
52
51
  this.symbol = symbol;
53
52
  this.name = name;
54
53
  }
54
+ get asToken() {
55
+ return this.wrapped;
56
+ }
55
57
  };
56
58
  var Decimal = toFormat(_Decimal);
57
59
  var Big = toFormat(_Big);
@@ -129,15 +131,15 @@ var Fraction = class {
129
131
  return new Fraction(this.numerator * otherParsed.denominator, this.denominator * otherParsed.numerator);
130
132
  }
131
133
  toSignificant(significantDigits, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
132
- invariant6(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
133
- invariant6(significantDigits > 0, `${significantDigits} is not positive.`);
134
+ invariant8(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
135
+ invariant8(significantDigits > 0, `${significantDigits} is not positive.`);
134
136
  Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] });
135
137
  const quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
136
138
  return quotient.toFormat(quotient.decimalPlaces(), format);
137
139
  }
138
140
  toFixed(decimalPlaces, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
139
- invariant6(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
140
- invariant6(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
141
+ invariant8(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
142
+ invariant8(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
141
143
  Big.DP = decimalPlaces;
142
144
  Big.RM = toFixedRounding[rounding];
143
145
  return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
@@ -187,7 +189,7 @@ var Big2 = toFormat(_Big);
187
189
  var CurrencyAmount = class extends Fraction {
188
190
  constructor(currency, numerator, denominator) {
189
191
  super(numerator, denominator);
190
- invariant6(this.quotient <= MaxUint256, "AMOUNT");
192
+ invariant8(this.quotient <= MaxUint256, "AMOUNT");
191
193
  this.currency = currency;
192
194
  this.decimalScale = 10n ** BigInt(currency.decimals);
193
195
  }
@@ -209,13 +211,20 @@ var CurrencyAmount = class extends Fraction {
209
211
  return new CurrencyAmount(currency, numerator, denominator);
210
212
  }
211
213
  add(other) {
212
- invariant6(this.currency.equals(other.currency), "CURRENCY");
214
+ invariant8(this.currency.equals(other.currency), "CURRENCY");
213
215
  const added = super.add(other);
214
216
  return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
215
217
  }
216
- subtract(other) {
217
- invariant6(this.currency.equals(other.currency), "CURRENCY");
218
- const subtracted = super.subtract(other);
218
+ subtract(value) {
219
+ if (typeof value === "bigint") {
220
+ return CurrencyAmount.fromFractionalAmount(
221
+ this.currency,
222
+ this.numerator - value * this.denominator,
223
+ this.denominator
224
+ );
225
+ }
226
+ invariant8(this.currency.equals(value.currency), "CURRENCY");
227
+ const subtracted = super.subtract(value);
219
228
  return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
220
229
  }
221
230
  multiply(other) {
@@ -230,7 +239,7 @@ var CurrencyAmount = class extends Fraction {
230
239
  return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
231
240
  }
232
241
  toFixed(decimalPlaces = this.currency.decimals, format, rounding = 0 /* ROUND_DOWN */) {
233
- invariant6(decimalPlaces <= this.currency.decimals, "DECIMALS");
242
+ invariant8(decimalPlaces <= this.currency.decimals, "DECIMALS");
234
243
  return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
235
244
  }
236
245
  toExact(format = { groupSeparator: "" }) {
@@ -242,6 +251,79 @@ var CurrencyAmount = class extends Fraction {
242
251
  return this;
243
252
  return CurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
244
253
  }
254
+ info() {
255
+ return `${this.toExact()}${this.currency.symbol}`;
256
+ }
257
+ };
258
+ var Big3 = toFormat(_Big);
259
+ var UnifiedCurrencyAmount = class extends Fraction {
260
+ constructor(currency, numerator, denominator) {
261
+ super(numerator, denominator);
262
+ invariant8(this.quotient <= MaxUint256, "AMOUNT");
263
+ this.currency = currency;
264
+ this.decimalScale = 10n ** BigInt(currency.decimals);
265
+ }
266
+ /**
267
+ * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
268
+ * @param currency the currency in the amount
269
+ * @param rawAmount the raw token or ether amount
270
+ */
271
+ static fromRawAmount(currency, rawAmount) {
272
+ return new UnifiedCurrencyAmount(currency, rawAmount);
273
+ }
274
+ /**
275
+ * Construct a currency amount with a denominator that is not equal to 1
276
+ * @param currency the currency
277
+ * @param numerator the numerator of the fractional token amount
278
+ * @param denominator the denominator of the fractional token amount
279
+ */
280
+ static fromFractionalAmount(currency, numerator, denominator) {
281
+ return new UnifiedCurrencyAmount(currency, numerator, denominator);
282
+ }
283
+ add(other) {
284
+ invariant8(this.currency.equals(other.currency), "CURRENCY");
285
+ const added = super.add(other);
286
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
287
+ }
288
+ subtract(value) {
289
+ if (typeof value === "bigint") {
290
+ return UnifiedCurrencyAmount.fromFractionalAmount(
291
+ this.currency,
292
+ this.numerator - value * this.denominator,
293
+ this.denominator
294
+ );
295
+ }
296
+ invariant8(this.currency.equals(value.currency), "CURRENCY");
297
+ const subtracted = super.subtract(value);
298
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
299
+ }
300
+ multiply(other) {
301
+ const multiplied = super.multiply(other);
302
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
303
+ }
304
+ divide(other) {
305
+ const divided = super.divide(other);
306
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
307
+ }
308
+ toSignificant(significantDigits = 6, format, rounding = 0 /* ROUND_DOWN */) {
309
+ return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
310
+ }
311
+ toFixed(decimalPlaces = this.currency.decimals, format, rounding = 0 /* ROUND_DOWN */) {
312
+ invariant8(decimalPlaces <= this.currency.decimals, "DECIMALS");
313
+ return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
314
+ }
315
+ toExact(format = { groupSeparator: "" }) {
316
+ Big3.DP = this.currency.decimals;
317
+ return new Big3(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(format);
318
+ }
319
+ get wrapped() {
320
+ if (this.currency.isToken)
321
+ return this;
322
+ return UnifiedCurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
323
+ }
324
+ info() {
325
+ return `${this.toExact()}${this.currency.symbol}`;
326
+ }
245
327
  };
246
328
  var Price = class extends Fraction {
247
329
  // used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
@@ -281,7 +363,7 @@ var Price = class extends Fraction {
281
363
  * @param other the other price
282
364
  */
283
365
  multiply(other) {
284
- invariant6(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
366
+ invariant8(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
285
367
  const fraction = super.multiply(other);
286
368
  return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
287
369
  }
@@ -290,7 +372,7 @@ var Price = class extends Fraction {
290
372
  * @param currencyAmount the amount of base currency to quote against the price
291
373
  */
292
374
  quote(currencyAmount) {
293
- invariant6(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
375
+ invariant8(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
294
376
  const result = super.multiply(currencyAmount);
295
377
  return CurrencyAmount.fromFractionalAmount(this.quoteCurrency, result.numerator, result.denominator);
296
378
  }
@@ -310,14 +392,26 @@ var Price = class extends Fraction {
310
392
  get wrapped() {
311
393
  return new Price(this.baseCurrency.wrapped, this.quoteCurrency.wrapped, this.denominator, this.numerator);
312
394
  }
313
- };
314
-
315
- // src/nativeCurrency.ts
316
- var NativeCurrency = class extends BaseCurrency {
317
- constructor() {
318
- super(...arguments);
319
- this.isNative = true;
320
- this.isToken = false;
395
+ /**
396
+ * Create a price from base and quote currency and a decimal string
397
+ * @param base
398
+ * @param quote
399
+ * @param value
400
+ * @returns Price<TBase, TQuote> | undefined
401
+ */
402
+ static fromDecimal(base, quote, value) {
403
+ if (!value || value.length > 257 || !value.match(/^\d*\.?\d+$/)) {
404
+ return void 0;
405
+ }
406
+ const [whole, fraction] = value.split(".");
407
+ const decimals = fraction?.length ?? 0;
408
+ const withoutDecimals = BigInt((whole ?? "") + (fraction ?? ""));
409
+ return new Price(
410
+ base,
411
+ quote,
412
+ BigInt(10 ** decimals) * BigInt(10 ** base.decimals),
413
+ withoutDecimals * BigInt(10 ** quote.decimals)
414
+ );
321
415
  }
322
416
  };
323
417
  var Token = class extends BaseCurrency {
@@ -342,8 +436,8 @@ var Token = class extends BaseCurrency {
342
436
  * @throws if the tokens are on different chains
343
437
  */
344
438
  sortsBefore(other) {
345
- invariant6(this.chainId === other.chainId, "CHAIN_IDS");
346
- invariant6(this.address !== other.address, "ADDRESSES");
439
+ invariant8(this.chainId === other.chainId, "CHAIN_IDS");
440
+ invariant8(this.address !== other.address, "ADDRESSES");
347
441
  return this.address.toLowerCase() < other.address.toLowerCase();
348
442
  }
349
443
  /**
@@ -364,6 +458,80 @@ var Token = class extends BaseCurrency {
364
458
  }
365
459
  };
366
460
 
461
+ // src/nativeCurrency.ts
462
+ var NativeCurrency = class extends BaseCurrency {
463
+ constructor() {
464
+ super(...arguments);
465
+ this.isNative = true;
466
+ this.isToken = false;
467
+ }
468
+ get asToken() {
469
+ return new Token(this.chainId, ZERO_ADDRESS, this.decimals, this.symbol, this.name);
470
+ }
471
+ };
472
+
473
+ // src/splNativeCurrency.ts
474
+ var SPLNativeCurrency = class extends BaseCurrency {
475
+ constructor() {
476
+ super(...arguments);
477
+ this.isNative = true;
478
+ this.isToken = false;
479
+ this.address = "";
480
+ }
481
+ };
482
+ var SPLToken = class extends BaseCurrency {
483
+ constructor({
484
+ chainId,
485
+ programId,
486
+ address,
487
+ decimals,
488
+ symbol,
489
+ logoURI,
490
+ name,
491
+ projectLink
492
+ }) {
493
+ super(chainId, decimals, symbol, name);
494
+ this.isNative = false;
495
+ this.isToken = true;
496
+ this.address = address;
497
+ this.programId = programId;
498
+ this.logoURI = logoURI;
499
+ this.projectLink = projectLink;
500
+ }
501
+ static isSPLToken(token) {
502
+ if (!token)
503
+ return false;
504
+ return "programId" in token || token.wrapped instanceof SPLToken;
505
+ }
506
+ /**
507
+ * Returns true if the two tokens are equivalent, i.e. have the same chainId and programId.
508
+ * @param other other token to compare
509
+ */
510
+ equals(other) {
511
+ return this.chainId === other.chainId && this.address === other.address;
512
+ }
513
+ 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();
517
+ }
518
+ /* For compatibility */
519
+ get wrapped() {
520
+ return this;
521
+ }
522
+ get serialize() {
523
+ return {
524
+ address: this.address,
525
+ programId: this.programId,
526
+ chainId: this.chainId,
527
+ decimals: this.decimals,
528
+ symbol: this.symbol,
529
+ name: this.name,
530
+ projectLink: this.projectLink
531
+ };
532
+ }
533
+ };
534
+
367
535
  // src/errors.ts
368
536
  var CAN_SET_PROTOTYPE = "setPrototypeOf" in Object;
369
537
  var InsufficientReservesError = class extends Error {
@@ -385,11 +553,11 @@ var InsufficientInputAmountError = class extends Error {
385
553
  }
386
554
  };
387
555
  function validateVMTypeInstance(value, vmType) {
388
- invariant6(value >= ZERO, `${value} is not a ${vmType}.`);
389
- invariant6(value <= VM_TYPE_MAXIMA[vmType], `${value} is not a ${vmType}.`);
556
+ invariant8(value >= ZERO, `${value} is not a ${vmType}.`);
557
+ invariant8(value <= VM_TYPE_MAXIMA[vmType], `${value} is not a ${vmType}.`);
390
558
  }
391
559
  function sqrt(y) {
392
- invariant6(y >= ZERO, "NEGATIVE");
560
+ invariant8(y >= ZERO, "NEGATIVE");
393
561
  let z = ZERO;
394
562
  let x;
395
563
  if (y > THREE) {
@@ -405,8 +573,8 @@ function sqrt(y) {
405
573
  return z;
406
574
  }
407
575
  function sortedInsert(items, add, maxSize, comparator) {
408
- invariant6(maxSize > 0, "MAX_SIZE_ZERO");
409
- invariant6(items.length <= maxSize, "ITEMS_SIZE");
576
+ invariant8(maxSize > 0, "MAX_SIZE_ZERO");
577
+ invariant8(items.length <= maxSize, "ITEMS_SIZE");
410
578
  if (items.length === 0) {
411
579
  items.push(add);
412
580
  return null;
@@ -469,11 +637,25 @@ function sortCurrencies(currencies) {
469
637
  return a.sortsBefore(b) ? -1 : 1;
470
638
  });
471
639
  }
640
+ var isCurrencySorted = (currencyA, currencyB) => {
641
+ const [currency0] = sortCurrencies([currencyA, currencyB]);
642
+ return currency0 === currencyA;
643
+ };
472
644
  function getCurrencyAddress(currency) {
473
645
  if (currency.isNative) {
474
646
  return ZERO_ADDRESS;
475
647
  }
476
648
  return currency.address;
477
649
  }
650
+ function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
651
+ const c = matchWrappedCurrency ? currency.wrapped : currency;
652
+ for (const current of list) {
653
+ const checkAgainst = matchWrappedCurrency ? current.wrapped : current;
654
+ if (checkAgainst.equals(c)) {
655
+ return current;
656
+ }
657
+ }
658
+ return void 0;
659
+ }
478
660
 
479
- export { BaseCurrency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, TEN, THREE, TWO, Token, TradeType, VMType, VM_TYPE_MAXIMA, ZERO, ZERO_ADDRESS, _100, _10000, _9975, computePriceImpact, getCurrencyAddress, getTokenComparator, sortCurrencies, sortedInsert, sqrt, validateVMTypeInstance };
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 };
@@ -1,9 +1,11 @@
1
1
  import { BaseCurrency } from './baseCurrency';
2
+ import { Token } from './token';
2
3
  /**
3
4
  * Represents the native currency of the chain on which it resides, e.g.
4
5
  */
5
- export declare abstract class NativeCurrency extends BaseCurrency {
6
+ export declare abstract class NativeCurrency extends BaseCurrency<Token> {
6
7
  readonly isNative: true;
7
8
  readonly isToken: false;
9
+ get asToken(): Token;
8
10
  }
9
11
  //# sourceMappingURL=nativeCurrency.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nativeCurrency.d.ts","sourceRoot":"","sources":["../src/nativeCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,8BAAsB,cAAe,SAAQ,YAAY;IACvD,SAAgB,QAAQ,OAAgB;IAExC,SAAgB,OAAO,QAAiB;CACzC"}
1
+ {"version":3,"file":"nativeCurrency.d.ts","sourceRoot":"","sources":["../src/nativeCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B;;GAEG;AACH,8BAAsB,cAAe,SAAQ,YAAY,CAAC,KAAK,CAAC;IAC9D,SAAgB,QAAQ,EAAG,IAAI,CAAS;IAExC,SAAgB,OAAO,EAAG,KAAK,CAAS;IAExC,IAAoB,OAAO,IAAI,KAAK,CAEnC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { BaseCurrency } from './baseCurrency';
2
+ import { SPLToken } from './splToken';
3
+ /**
4
+ * Represents the native currency of the chain on which it resides, e.g.
5
+ */
6
+ export declare abstract class SPLNativeCurrency extends BaseCurrency<SPLToken> {
7
+ readonly isNative: true;
8
+ readonly isToken: false;
9
+ readonly address: string;
10
+ }
11
+ //# sourceMappingURL=splNativeCurrency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splNativeCurrency.d.ts","sourceRoot":"","sources":["../src/splNativeCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC;;GAEG;AACH,8BAAsB,iBAAkB,SAAQ,YAAY,CAAC,QAAQ,CAAC;IACpE,SAAgB,QAAQ,EAAG,IAAI,CAAS;IAExC,SAAgB,OAAO,EAAG,KAAK,CAAS;IAExC,SAAgB,OAAO,EAAE,MAAM,CAAK;CACrC"}
@@ -0,0 +1,43 @@
1
+ import { BaseCurrency } from './baseCurrency';
2
+ import { type UnifiedCurrency } from './currency';
3
+ export interface SerializedSPLToken {
4
+ chainId: number;
5
+ address: string;
6
+ programId: string;
7
+ decimals: number;
8
+ symbol: string;
9
+ name?: string;
10
+ projectLink?: string;
11
+ }
12
+ /**
13
+ * Represents an SPL token on Solana or other non-EVM chains.
14
+ */
15
+ export declare class SPLToken extends BaseCurrency<SPLToken> {
16
+ readonly isNative: false;
17
+ readonly isToken: true;
18
+ readonly address: string;
19
+ readonly programId: string;
20
+ readonly logoURI: string;
21
+ readonly projectLink?: string;
22
+ static isSPLToken(token?: UnifiedCurrency): boolean;
23
+ constructor({ chainId, programId, address, decimals, symbol, logoURI, name, projectLink, }: {
24
+ chainId: number;
25
+ programId: string;
26
+ address: string;
27
+ decimals: number;
28
+ symbol: string;
29
+ logoURI: string;
30
+ name?: string;
31
+ projectLink?: string;
32
+ isNative?: boolean;
33
+ });
34
+ /**
35
+ * Returns true if the two tokens are equivalent, i.e. have the same chainId and programId.
36
+ * @param other other token to compare
37
+ */
38
+ equals(other: BaseCurrency): boolean;
39
+ sortsBefore(other: SPLToken): boolean;
40
+ get wrapped(): SPLToken;
41
+ get serialize(): SerializedSPLToken;
42
+ }
43
+ //# sourceMappingURL=splToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splToken.d.ts","sourceRoot":"","sources":["../src/splToken.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAY,CAAC,QAAQ,CAAC;IAClD,SAAgB,QAAQ,EAAE,KAAK,CAAiB;IAEhD,SAAgB,OAAO,EAAE,IAAI,CAAgB;IAE7C,SAAgB,OAAO,EAAE,MAAM,CAAA;IAE/B,SAAgB,SAAS,EAAE,MAAM,CAAA;IAEjC,SAAgB,OAAO,EAAE,MAAM,CAAA;IAE/B,SAAgB,WAAW,CAAC,EAAE,MAAM,CAAA;WAEtB,UAAU,CAAC,KAAK,CAAC,EAAE,eAAe;gBAM7B,EACjB,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,EACJ,WAAW,GACZ,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB;IAQD;;;OAGG;IACI,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAIpC,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAO5C,IAAW,OAAO,IAAI,QAAQ,CAE7B;IAED,IAAW,SAAS,IAAI,kBAAkB,CAUzC;CACF"}
package/dist/token.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { BaseCurrency } from './baseCurrency';
2
- import { Currency } from './currency';
3
2
  export interface SerializedToken {
4
3
  chainId: number;
5
4
  address: `0x${string}`;
@@ -11,7 +10,7 @@ export interface SerializedToken {
11
10
  /**
12
11
  * Represents an ERC20 token with a unique address and some metadata.
13
12
  */
14
- export declare class Token extends BaseCurrency {
13
+ export declare class Token extends BaseCurrency<Token> {
15
14
  readonly isNative: false;
16
15
  readonly isToken: true;
17
16
  /**
@@ -24,7 +23,7 @@ export declare class Token extends BaseCurrency {
24
23
  * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
25
24
  * @param other other token to compare
26
25
  */
27
- equals(other: Currency): boolean;
26
+ equals(other: BaseCurrency): boolean;
28
27
  /**
29
28
  * Returns true if the address of this token sorts before the address of the other token
30
29
  * @param other other token to compare
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,KAAM,SAAQ,YAAY;IACrC,SAAgB,QAAQ,EAAE,KAAK,CAAiB;IAEhD,SAAgB,OAAO,EAAE,IAAI,CAAgB;IAE7C;;OAEG;IACH,SAAgB,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;IAEtC,SAAgB,WAAW,CAAC,EAAE,MAAM,CAAA;gBAGlC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,KAAK,MAAM,EAAE,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM;IAOtB;;;OAGG;IACI,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAIvC;;;;;OAKG;IACI,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAMzC;;OAEG;IACH,IAAW,OAAO,IAAI,KAAK,CAE1B;IAED,IAAW,SAAS,IAAI,eAAe,CAStC;CACF"}
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,KAAM,SAAQ,YAAY,CAAC,KAAK,CAAC;IAC5C,SAAgB,QAAQ,EAAE,KAAK,CAAiB;IAEhD,SAAgB,OAAO,EAAE,IAAI,CAAgB;IAE7C;;OAEG;IACH,SAAgB,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;IAEtC,SAAgB,WAAW,CAAC,EAAE,MAAM,CAAA;gBAGlC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,KAAK,MAAM,EAAE,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM;IAOtB;;;OAGG;IACI,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAI3C;;;;;OAKG;IACI,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAMzC;;OAEG;IACH,IAAW,OAAO,IAAI,KAAK,CAE1B;IAED,IAAW,SAAS,IAAI,eAAe,CAStC;CACF"}
package/dist/utils.d.ts CHANGED
@@ -16,5 +16,7 @@ export declare function getTokenComparator(balances: {
16
16
  [tokenAddress: string]: CurrencyAmount<Token> | undefined;
17
17
  }): (tokenA: Token, tokenB: Token) => number;
18
18
  export declare function sortCurrencies<T extends Currency>(currencies: T[]): T[];
19
+ export declare const isCurrencySorted: (currencyA: Currency, currencyB: Currency) => boolean;
19
20
  export declare function getCurrencyAddress(currency: Currency): `0x${string}`;
21
+ export declare function getMatchedCurrency(currency: Currency, list: Currency[], matchWrappedCurrency?: boolean): Currency | undefined;
20
22
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,MAAM,EAAsC,MAAM,aAAa,CAAA;AACzF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAG1E;AAGD,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBtC;AAKD,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,IAAI,CA8BjH;AAGD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,SAAS,QAAQ,EAAE,MAAM,SAAS,QAAQ,EAChF,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,EAC9B,WAAW,EAAE,cAAc,CAAC,KAAK,CAAC,EAClC,YAAY,EAAE,cAAc,CAAC,MAAM,CAAC,GACnC,OAAO,CAKT;AAgBD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE;IAC3C,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;CAC1D,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,KAAK,MAAM,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E,KAAK,EAAE,MAAM,EAAE,KAAK,KAAK,MAAM,CAkB3C;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,QAAQ,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAUvE;AAED,eAAO,MAAM,gBAAgB,cAAe,QAAQ,aAAa,QAAQ,KAAG,OAG3E,CAAA;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,iBAKpD;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,QAAQ,EAAE,EAChB,oBAAoB,UAAO,GAC1B,QAAQ,GAAG,SAAS,CAStB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pancakeswap/swap-sdk-core",
3
3
  "license": "MIT",
4
- "version": "1.3.0",
4
+ "version": "1.5.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",