@pancakeswap/swap-sdk-core 1.4.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,12 +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;
49
- get asToken(): Token;
46
+ abstract get wrapped(): T;
47
+ get asToken(): T;
50
48
  }
51
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;IAEpC,IAAW,OAAO,IAAI,KAAK,CAE1B;CACF"}
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,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,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"}
@@ -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,8 +54,7 @@ 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;
@@ -141,15 +140,15 @@ var Fraction = class {
141
140
  return new Fraction(this.numerator * otherParsed.denominator, this.denominator * otherParsed.numerator);
142
141
  }
143
142
  toSignificant(significantDigits, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
144
- invariant6__default.default(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
145
- 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.`);
146
145
  Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] });
147
146
  const quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
148
147
  return quotient.toFormat(quotient.decimalPlaces(), format);
149
148
  }
150
149
  toFixed(decimalPlaces, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
151
- invariant6__default.default(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
152
- 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.`);
153
152
  Big.DP = decimalPlaces;
154
153
  Big.RM = toFixedRounding[rounding];
155
154
  return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
@@ -199,7 +198,7 @@ var Big2 = toFormat__default.default(_Big__default.default);
199
198
  var CurrencyAmount = class extends Fraction {
200
199
  constructor(currency, numerator, denominator) {
201
200
  super(numerator, denominator);
202
- invariant6__default.default(this.quotient <= MaxUint256, "AMOUNT");
201
+ invariant8__default.default(this.quotient <= MaxUint256, "AMOUNT");
203
202
  this.currency = currency;
204
203
  this.decimalScale = 10n ** BigInt(currency.decimals);
205
204
  }
@@ -221,7 +220,7 @@ var CurrencyAmount = class extends Fraction {
221
220
  return new CurrencyAmount(currency, numerator, denominator);
222
221
  }
223
222
  add(other) {
224
- invariant6__default.default(this.currency.equals(other.currency), "CURRENCY");
223
+ invariant8__default.default(this.currency.equals(other.currency), "CURRENCY");
225
224
  const added = super.add(other);
226
225
  return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
227
226
  }
@@ -233,7 +232,7 @@ var CurrencyAmount = class extends Fraction {
233
232
  this.denominator
234
233
  );
235
234
  }
236
- invariant6__default.default(this.currency.equals(value.currency), "CURRENCY");
235
+ invariant8__default.default(this.currency.equals(value.currency), "CURRENCY");
237
236
  const subtracted = super.subtract(value);
238
237
  return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
239
238
  }
@@ -249,7 +248,7 @@ var CurrencyAmount = class extends Fraction {
249
248
  return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
250
249
  }
251
250
  toFixed(decimalPlaces = this.currency.decimals, format, rounding = 0 /* ROUND_DOWN */) {
252
- invariant6__default.default(decimalPlaces <= this.currency.decimals, "DECIMALS");
251
+ invariant8__default.default(decimalPlaces <= this.currency.decimals, "DECIMALS");
253
252
  return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
254
253
  }
255
254
  toExact(format = { groupSeparator: "" }) {
@@ -265,6 +264,76 @@ var CurrencyAmount = class extends Fraction {
265
264
  return `${this.toExact()}${this.currency.symbol}`;
266
265
  }
267
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
+ }
336
+ };
268
337
  var Price = class extends Fraction {
269
338
  // used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
270
339
  /**
@@ -303,7 +372,7 @@ var Price = class extends Fraction {
303
372
  * @param other the other price
304
373
  */
305
374
  multiply(other) {
306
- invariant6__default.default(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
375
+ invariant8__default.default(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
307
376
  const fraction = super.multiply(other);
308
377
  return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
309
378
  }
@@ -312,7 +381,7 @@ var Price = class extends Fraction {
312
381
  * @param currencyAmount the amount of base currency to quote against the price
313
382
  */
314
383
  quote(currencyAmount) {
315
- invariant6__default.default(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
384
+ invariant8__default.default(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
316
385
  const result = super.multiply(currencyAmount);
317
386
  return CurrencyAmount.fromFractionalAmount(this.quoteCurrency, result.numerator, result.denominator);
318
387
  }
@@ -376,8 +445,8 @@ var Token = class extends BaseCurrency {
376
445
  * @throws if the tokens are on different chains
377
446
  */
378
447
  sortsBefore(other) {
379
- invariant6__default.default(this.chainId === other.chainId, "CHAIN_IDS");
380
- 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");
381
450
  return this.address.toLowerCase() < other.address.toLowerCase();
382
451
  }
383
452
  /**
@@ -410,6 +479,68 @@ var NativeCurrency = class extends BaseCurrency {
410
479
  }
411
480
  };
412
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
+
413
544
  // src/errors.ts
414
545
  var CAN_SET_PROTOTYPE = "setPrototypeOf" in Object;
415
546
  var InsufficientReservesError = class extends Error {
@@ -431,11 +562,11 @@ var InsufficientInputAmountError = class extends Error {
431
562
  }
432
563
  };
433
564
  function validateVMTypeInstance(value, vmType) {
434
- invariant6__default.default(value >= ZERO, `${value} is not a ${vmType}.`);
435
- 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}.`);
436
567
  }
437
568
  function sqrt(y) {
438
- invariant6__default.default(y >= ZERO, "NEGATIVE");
569
+ invariant8__default.default(y >= ZERO, "NEGATIVE");
439
570
  let z = ZERO;
440
571
  let x;
441
572
  if (y > THREE) {
@@ -451,8 +582,8 @@ function sqrt(y) {
451
582
  return z;
452
583
  }
453
584
  function sortedInsert(items, add, maxSize, comparator) {
454
- invariant6__default.default(maxSize > 0, "MAX_SIZE_ZERO");
455
- 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");
456
587
  if (items.length === 0) {
457
588
  items.push(add);
458
589
  return null;
@@ -549,11 +680,14 @@ exports.ONE = ONE;
549
680
  exports.Percent = Percent;
550
681
  exports.Price = Price;
551
682
  exports.Rounding = Rounding;
683
+ exports.SPLNativeCurrency = SPLNativeCurrency;
684
+ exports.SPLToken = SPLToken;
552
685
  exports.TEN = TEN;
553
686
  exports.THREE = THREE;
554
687
  exports.TWO = TWO;
555
688
  exports.Token = Token;
556
689
  exports.TradeType = TradeType;
690
+ exports.UnifiedCurrencyAmount = UnifiedCurrencyAmount;
557
691
  exports.VMType = VMType;
558
692
  exports.VM_TYPE_MAXIMA = VM_TYPE_MAXIMA;
559
693
  exports.ZERO = ZERO;
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,8 +45,7 @@ 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;
@@ -132,15 +131,15 @@ var Fraction = class {
132
131
  return new Fraction(this.numerator * otherParsed.denominator, this.denominator * otherParsed.numerator);
133
132
  }
134
133
  toSignificant(significantDigits, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
135
- invariant6(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
136
- 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.`);
137
136
  Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] });
138
137
  const quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
139
138
  return quotient.toFormat(quotient.decimalPlaces(), format);
140
139
  }
141
140
  toFixed(decimalPlaces, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
142
- invariant6(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
143
- invariant6(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
141
+ invariant8(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
142
+ invariant8(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
144
143
  Big.DP = decimalPlaces;
145
144
  Big.RM = toFixedRounding[rounding];
146
145
  return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
@@ -190,7 +189,7 @@ var Big2 = toFormat(_Big);
190
189
  var CurrencyAmount = class extends Fraction {
191
190
  constructor(currency, numerator, denominator) {
192
191
  super(numerator, denominator);
193
- invariant6(this.quotient <= MaxUint256, "AMOUNT");
192
+ invariant8(this.quotient <= MaxUint256, "AMOUNT");
194
193
  this.currency = currency;
195
194
  this.decimalScale = 10n ** BigInt(currency.decimals);
196
195
  }
@@ -212,7 +211,7 @@ var CurrencyAmount = class extends Fraction {
212
211
  return new CurrencyAmount(currency, numerator, denominator);
213
212
  }
214
213
  add(other) {
215
- invariant6(this.currency.equals(other.currency), "CURRENCY");
214
+ invariant8(this.currency.equals(other.currency), "CURRENCY");
216
215
  const added = super.add(other);
217
216
  return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
218
217
  }
@@ -224,7 +223,7 @@ var CurrencyAmount = class extends Fraction {
224
223
  this.denominator
225
224
  );
226
225
  }
227
- invariant6(this.currency.equals(value.currency), "CURRENCY");
226
+ invariant8(this.currency.equals(value.currency), "CURRENCY");
228
227
  const subtracted = super.subtract(value);
229
228
  return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
230
229
  }
@@ -240,7 +239,7 @@ var CurrencyAmount = class extends Fraction {
240
239
  return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
241
240
  }
242
241
  toFixed(decimalPlaces = this.currency.decimals, format, rounding = 0 /* ROUND_DOWN */) {
243
- invariant6(decimalPlaces <= this.currency.decimals, "DECIMALS");
242
+ invariant8(decimalPlaces <= this.currency.decimals, "DECIMALS");
244
243
  return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
245
244
  }
246
245
  toExact(format = { groupSeparator: "" }) {
@@ -256,6 +255,76 @@ var CurrencyAmount = class extends Fraction {
256
255
  return `${this.toExact()}${this.currency.symbol}`;
257
256
  }
258
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
+ }
327
+ };
259
328
  var Price = class extends Fraction {
260
329
  // used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
261
330
  /**
@@ -294,7 +363,7 @@ var Price = class extends Fraction {
294
363
  * @param other the other price
295
364
  */
296
365
  multiply(other) {
297
- invariant6(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
366
+ invariant8(this.quoteCurrency.equals(other.baseCurrency), "TOKEN");
298
367
  const fraction = super.multiply(other);
299
368
  return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
300
369
  }
@@ -303,7 +372,7 @@ var Price = class extends Fraction {
303
372
  * @param currencyAmount the amount of base currency to quote against the price
304
373
  */
305
374
  quote(currencyAmount) {
306
- invariant6(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
375
+ invariant8(currencyAmount.currency.equals(this.baseCurrency), "TOKEN");
307
376
  const result = super.multiply(currencyAmount);
308
377
  return CurrencyAmount.fromFractionalAmount(this.quoteCurrency, result.numerator, result.denominator);
309
378
  }
@@ -367,8 +436,8 @@ var Token = class extends BaseCurrency {
367
436
  * @throws if the tokens are on different chains
368
437
  */
369
438
  sortsBefore(other) {
370
- invariant6(this.chainId === other.chainId, "CHAIN_IDS");
371
- invariant6(this.address !== other.address, "ADDRESSES");
439
+ invariant8(this.chainId === other.chainId, "CHAIN_IDS");
440
+ invariant8(this.address !== other.address, "ADDRESSES");
372
441
  return this.address.toLowerCase() < other.address.toLowerCase();
373
442
  }
374
443
  /**
@@ -401,6 +470,68 @@ var NativeCurrency = class extends BaseCurrency {
401
470
  }
402
471
  };
403
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
+
404
535
  // src/errors.ts
405
536
  var CAN_SET_PROTOTYPE = "setPrototypeOf" in Object;
406
537
  var InsufficientReservesError = class extends Error {
@@ -422,11 +553,11 @@ var InsufficientInputAmountError = class extends Error {
422
553
  }
423
554
  };
424
555
  function validateVMTypeInstance(value, vmType) {
425
- invariant6(value >= ZERO, `${value} is not a ${vmType}.`);
426
- 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}.`);
427
558
  }
428
559
  function sqrt(y) {
429
- invariant6(y >= ZERO, "NEGATIVE");
560
+ invariant8(y >= ZERO, "NEGATIVE");
430
561
  let z = ZERO;
431
562
  let x;
432
563
  if (y > THREE) {
@@ -442,8 +573,8 @@ function sqrt(y) {
442
573
  return z;
443
574
  }
444
575
  function sortedInsert(items, add, maxSize, comparator) {
445
- invariant6(maxSize > 0, "MAX_SIZE_ZERO");
446
- invariant6(items.length <= maxSize, "ITEMS_SIZE");
576
+ invariant8(maxSize > 0, "MAX_SIZE_ZERO");
577
+ invariant8(items.length <= maxSize, "ITEMS_SIZE");
447
578
  if (items.length === 0) {
448
579
  items.push(add);
449
580
  return null;
@@ -527,4 +658,4 @@ function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
527
658
  return void 0;
528
659
  }
529
660
 
530
- 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, getMatchedCurrency, getTokenComparator, isCurrencySorted, 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 };
@@ -3,7 +3,7 @@ import { Token } from './token';
3
3
  /**
4
4
  * Represents the native currency of the chain on which it resides, e.g.
5
5
  */
6
- export declare abstract class NativeCurrency extends BaseCurrency {
6
+ export declare abstract class NativeCurrency extends BaseCurrency<Token> {
7
7
  readonly isNative: true;
8
8
  readonly isToken: false;
9
9
  get asToken(): Token;
@@ -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,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B;;GAEG;AACH,8BAAsB,cAAe,SAAQ,YAAY;IACvD,SAAgB,QAAQ,EAAG,IAAI,CAAS;IAExC,SAAgB,OAAO,EAAG,KAAK,CAAS;IAExC,IAAoB,OAAO,IAAI,KAAK,CAEnC;CACF"}
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pancakeswap/swap-sdk-core",
3
3
  "license": "MIT",
4
- "version": "1.4.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",