@pancakeswap/swap-sdk-core 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseCurrency.d.ts +1 -0
- package/dist/baseCurrency.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/fractions/currencyAmount.d.ts +2 -0
- package/dist/fractions/currencyAmount.d.ts.map +1 -1
- package/dist/fractions/percent.d.ts.map +1 -1
- package/dist/fractions/price.d.ts +11 -1
- package/dist/fractions/price.d.ts.map +1 -1
- package/dist/index.js +76 -11
- package/dist/index.mjs +73 -12
- package/dist/nativeCurrency.d.ts +2 -0
- package/dist/nativeCurrency.d.ts.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/baseCurrency.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAEhD,oBAAY,SAAS;IACnB,WAAW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,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"}
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -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,
|
|
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=currencyAmount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencyAmount.d.ts","sourceRoot":"","sources":["../../src/fractions/currencyAmount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"currencyAmount.d.ts","sourceRoot":"","sources":["../../src/fractions/currencyAmount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,OAAO,EAAE,SAAS,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI9D,qBAAa,cAAc,CAAC,CAAC,SAAS,QAAQ,CAAE,SAAQ,QAAQ;IAC9D,SAAgB,QAAQ,EAAE,CAAC,CAAA;IAE3B,SAAgB,YAAY,EAAE,MAAM,CAAA;IAEpC;;;;OAIG;WACW,aAAa,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC;IAIrG;;;;;OAKG;WACW,oBAAoB,CAAC,CAAC,SAAS,QAAQ,EACnD,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,SAAS,GACrB,cAAc,CAAC,CAAC,CAAC;IAIpB,SAAS,aAAa,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,SAAS;IAOzE,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAMhD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../src/fractions/percent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAIrC;;;GAGG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE9C;AAED,qBAAa,OAAQ,SAAQ,QAAQ;IACnC;;OAEG;IACH,SAAgB,SAAS,
|
|
1
|
+
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../src/fractions/percent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAIrC;;;GAGG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE9C;AAED,qBAAa,OAAQ,SAAQ,QAAQ;IACnC;;OAEG;IACH,SAAgB,SAAS,EAAG,IAAI,CAAS;IAEzC,MAAM,CAAC,SAAS,mBAAY;IAE5B,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO;IAIzC,QAAQ,CAAC,KAAK,EAAE,QAAQ,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,7 +1,8 @@
|
|
|
1
1
|
import { BigintIsh, Rounding } from '../constants';
|
|
2
2
|
import { Currency } from '../currency';
|
|
3
|
-
import {
|
|
3
|
+
import { Token } from '../token';
|
|
4
4
|
import { CurrencyAmount } from './currencyAmount';
|
|
5
|
+
import { Fraction } from './fraction';
|
|
5
6
|
export declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
|
|
6
7
|
readonly baseCurrency: TBase;
|
|
7
8
|
readonly quoteCurrency: TQuote;
|
|
@@ -35,5 +36,14 @@ export declare class Price<TBase extends Currency, TQuote extends Currency> exte
|
|
|
35
36
|
private get adjustedForDecimals();
|
|
36
37
|
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
37
38
|
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
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;
|
|
38
48
|
}
|
|
39
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,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,
|
|
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,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,qBAAa,KAAK,CAAC,KAAK,SAAS,QAAQ,EAAE,MAAM,SAAS,QAAQ,CAAE,SAAQ,QAAQ;IAClF,SAAgB,YAAY,EAAE,KAAK,CAAA;IAEnC,SAAgB,aAAa,EAAE,MAAM,CAAA;IAErC,SAAgB,MAAM,EAAE,QAAQ,CAAA;IAEhC;;;OAGG;gBAED,GAAG,IAAI,EACH,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,GACrC,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;QAAC,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IA0BlF;;OAEG;IACI,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC;IAIrC;;;OAGG;IACI,QAAQ,CAAC,WAAW,SAAS,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC;IAM3G;;;OAGG;IACI,KAAK,CAAC,cAAc,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC;IAM3E;;;OAGG;IACH,OAAO,KAAK,mBAAmB,GAE9B;IAEM,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;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"}
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var VM_TYPE_MAXIMA = {
|
|
|
44
44
|
["uint8" /* uint8 */]: BigInt("0xff"),
|
|
45
45
|
["uint256" /* uint256 */]: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
|
|
46
46
|
};
|
|
47
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
47
48
|
var BaseCurrency = class {
|
|
48
49
|
/**
|
|
49
50
|
* Constructs an instance of the base class `BaseCurrency`.
|
|
@@ -60,6 +61,9 @@ var BaseCurrency = class {
|
|
|
60
61
|
this.symbol = symbol;
|
|
61
62
|
this.name = name;
|
|
62
63
|
}
|
|
64
|
+
get asToken() {
|
|
65
|
+
return this.wrapped;
|
|
66
|
+
}
|
|
63
67
|
};
|
|
64
68
|
var Decimal = toFormat__default.default(_Decimal__default.default);
|
|
65
69
|
var Big = toFormat__default.default(_Big__default.default);
|
|
@@ -221,9 +225,16 @@ var CurrencyAmount = class extends Fraction {
|
|
|
221
225
|
const added = super.add(other);
|
|
222
226
|
return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
|
|
223
227
|
}
|
|
224
|
-
subtract(
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
subtract(value) {
|
|
229
|
+
if (typeof value === "bigint") {
|
|
230
|
+
return CurrencyAmount.fromFractionalAmount(
|
|
231
|
+
this.currency,
|
|
232
|
+
this.numerator - value * this.denominator,
|
|
233
|
+
this.denominator
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
invariant6__default.default(this.currency.equals(value.currency), "CURRENCY");
|
|
237
|
+
const subtracted = super.subtract(value);
|
|
227
238
|
return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
|
|
228
239
|
}
|
|
229
240
|
multiply(other) {
|
|
@@ -250,6 +261,9 @@ var CurrencyAmount = class extends Fraction {
|
|
|
250
261
|
return this;
|
|
251
262
|
return CurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
|
|
252
263
|
}
|
|
264
|
+
info() {
|
|
265
|
+
return `${this.toExact()}${this.currency.symbol}`;
|
|
266
|
+
}
|
|
253
267
|
};
|
|
254
268
|
var Price = class extends Fraction {
|
|
255
269
|
// used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
|
|
@@ -315,14 +329,29 @@ var Price = class extends Fraction {
|
|
|
315
329
|
toFixed(decimalPlaces = 4, format, rounding) {
|
|
316
330
|
return this.adjustedForDecimals.toFixed(decimalPlaces, format, rounding);
|
|
317
331
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
332
|
+
get wrapped() {
|
|
333
|
+
return new Price(this.baseCurrency.wrapped, this.quoteCurrency.wrapped, this.denominator, this.numerator);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Create a price from base and quote currency and a decimal string
|
|
337
|
+
* @param base
|
|
338
|
+
* @param quote
|
|
339
|
+
* @param value
|
|
340
|
+
* @returns Price<TBase, TQuote> | undefined
|
|
341
|
+
*/
|
|
342
|
+
static fromDecimal(base, quote, value) {
|
|
343
|
+
if (!value || value.length > 257 || !value.match(/^\d*\.?\d+$/)) {
|
|
344
|
+
return void 0;
|
|
345
|
+
}
|
|
346
|
+
const [whole, fraction] = value.split(".");
|
|
347
|
+
const decimals = fraction?.length ?? 0;
|
|
348
|
+
const withoutDecimals = BigInt((whole ?? "") + (fraction ?? ""));
|
|
349
|
+
return new Price(
|
|
350
|
+
base,
|
|
351
|
+
quote,
|
|
352
|
+
BigInt(10 ** decimals) * BigInt(10 ** base.decimals),
|
|
353
|
+
withoutDecimals * BigInt(10 ** quote.decimals)
|
|
354
|
+
);
|
|
326
355
|
}
|
|
327
356
|
};
|
|
328
357
|
var Token = class extends BaseCurrency {
|
|
@@ -369,6 +398,18 @@ var Token = class extends BaseCurrency {
|
|
|
369
398
|
}
|
|
370
399
|
};
|
|
371
400
|
|
|
401
|
+
// src/nativeCurrency.ts
|
|
402
|
+
var NativeCurrency = class extends BaseCurrency {
|
|
403
|
+
constructor() {
|
|
404
|
+
super(...arguments);
|
|
405
|
+
this.isNative = true;
|
|
406
|
+
this.isToken = false;
|
|
407
|
+
}
|
|
408
|
+
get asToken() {
|
|
409
|
+
return new Token(this.chainId, ZERO_ADDRESS, this.decimals, this.symbol, this.name);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
372
413
|
// src/errors.ts
|
|
373
414
|
var CAN_SET_PROTOTYPE = "setPrototypeOf" in Object;
|
|
374
415
|
var InsufficientReservesError = class extends Error {
|
|
@@ -474,6 +515,26 @@ function sortCurrencies(currencies) {
|
|
|
474
515
|
return a.sortsBefore(b) ? -1 : 1;
|
|
475
516
|
});
|
|
476
517
|
}
|
|
518
|
+
var isCurrencySorted = (currencyA, currencyB) => {
|
|
519
|
+
const [currency0] = sortCurrencies([currencyA, currencyB]);
|
|
520
|
+
return currency0 === currencyA;
|
|
521
|
+
};
|
|
522
|
+
function getCurrencyAddress(currency) {
|
|
523
|
+
if (currency.isNative) {
|
|
524
|
+
return ZERO_ADDRESS;
|
|
525
|
+
}
|
|
526
|
+
return currency.address;
|
|
527
|
+
}
|
|
528
|
+
function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
|
|
529
|
+
const c = matchWrappedCurrency ? currency.wrapped : currency;
|
|
530
|
+
for (const current of list) {
|
|
531
|
+
const checkAgainst = matchWrappedCurrency ? current.wrapped : current;
|
|
532
|
+
if (checkAgainst.equals(c)) {
|
|
533
|
+
return current;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return void 0;
|
|
537
|
+
}
|
|
477
538
|
|
|
478
539
|
exports.BaseCurrency = BaseCurrency;
|
|
479
540
|
exports.CurrencyAmount = CurrencyAmount;
|
|
@@ -496,11 +557,15 @@ exports.TradeType = TradeType;
|
|
|
496
557
|
exports.VMType = VMType;
|
|
497
558
|
exports.VM_TYPE_MAXIMA = VM_TYPE_MAXIMA;
|
|
498
559
|
exports.ZERO = ZERO;
|
|
560
|
+
exports.ZERO_ADDRESS = ZERO_ADDRESS;
|
|
499
561
|
exports._100 = _100;
|
|
500
562
|
exports._10000 = _10000;
|
|
501
563
|
exports._9975 = _9975;
|
|
502
564
|
exports.computePriceImpact = computePriceImpact;
|
|
565
|
+
exports.getCurrencyAddress = getCurrencyAddress;
|
|
566
|
+
exports.getMatchedCurrency = getMatchedCurrency;
|
|
503
567
|
exports.getTokenComparator = getTokenComparator;
|
|
568
|
+
exports.isCurrencySorted = isCurrencySorted;
|
|
504
569
|
exports.sortCurrencies = sortCurrencies;
|
|
505
570
|
exports.sortedInsert = sortedInsert;
|
|
506
571
|
exports.sqrt = sqrt;
|
package/dist/index.mjs
CHANGED
|
@@ -35,6 +35,7 @@ var VM_TYPE_MAXIMA = {
|
|
|
35
35
|
["uint8" /* uint8 */]: BigInt("0xff"),
|
|
36
36
|
["uint256" /* uint256 */]: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
|
|
37
37
|
};
|
|
38
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
38
39
|
var BaseCurrency = class {
|
|
39
40
|
/**
|
|
40
41
|
* Constructs an instance of the base class `BaseCurrency`.
|
|
@@ -51,6 +52,9 @@ var BaseCurrency = class {
|
|
|
51
52
|
this.symbol = symbol;
|
|
52
53
|
this.name = name;
|
|
53
54
|
}
|
|
55
|
+
get asToken() {
|
|
56
|
+
return this.wrapped;
|
|
57
|
+
}
|
|
54
58
|
};
|
|
55
59
|
var Decimal = toFormat(_Decimal);
|
|
56
60
|
var Big = toFormat(_Big);
|
|
@@ -212,9 +216,16 @@ var CurrencyAmount = class extends Fraction {
|
|
|
212
216
|
const added = super.add(other);
|
|
213
217
|
return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
|
|
214
218
|
}
|
|
215
|
-
subtract(
|
|
216
|
-
|
|
217
|
-
|
|
219
|
+
subtract(value) {
|
|
220
|
+
if (typeof value === "bigint") {
|
|
221
|
+
return CurrencyAmount.fromFractionalAmount(
|
|
222
|
+
this.currency,
|
|
223
|
+
this.numerator - value * this.denominator,
|
|
224
|
+
this.denominator
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
invariant6(this.currency.equals(value.currency), "CURRENCY");
|
|
228
|
+
const subtracted = super.subtract(value);
|
|
218
229
|
return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
|
|
219
230
|
}
|
|
220
231
|
multiply(other) {
|
|
@@ -241,6 +252,9 @@ var CurrencyAmount = class extends Fraction {
|
|
|
241
252
|
return this;
|
|
242
253
|
return CurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
|
|
243
254
|
}
|
|
255
|
+
info() {
|
|
256
|
+
return `${this.toExact()}${this.currency.symbol}`;
|
|
257
|
+
}
|
|
244
258
|
};
|
|
245
259
|
var Price = class extends Fraction {
|
|
246
260
|
// used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
|
|
@@ -306,14 +320,29 @@ var Price = class extends Fraction {
|
|
|
306
320
|
toFixed(decimalPlaces = 4, format, rounding) {
|
|
307
321
|
return this.adjustedForDecimals.toFixed(decimalPlaces, format, rounding);
|
|
308
322
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
323
|
+
get wrapped() {
|
|
324
|
+
return new Price(this.baseCurrency.wrapped, this.quoteCurrency.wrapped, this.denominator, this.numerator);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Create a price from base and quote currency and a decimal string
|
|
328
|
+
* @param base
|
|
329
|
+
* @param quote
|
|
330
|
+
* @param value
|
|
331
|
+
* @returns Price<TBase, TQuote> | undefined
|
|
332
|
+
*/
|
|
333
|
+
static fromDecimal(base, quote, value) {
|
|
334
|
+
if (!value || value.length > 257 || !value.match(/^\d*\.?\d+$/)) {
|
|
335
|
+
return void 0;
|
|
336
|
+
}
|
|
337
|
+
const [whole, fraction] = value.split(".");
|
|
338
|
+
const decimals = fraction?.length ?? 0;
|
|
339
|
+
const withoutDecimals = BigInt((whole ?? "") + (fraction ?? ""));
|
|
340
|
+
return new Price(
|
|
341
|
+
base,
|
|
342
|
+
quote,
|
|
343
|
+
BigInt(10 ** decimals) * BigInt(10 ** base.decimals),
|
|
344
|
+
withoutDecimals * BigInt(10 ** quote.decimals)
|
|
345
|
+
);
|
|
317
346
|
}
|
|
318
347
|
};
|
|
319
348
|
var Token = class extends BaseCurrency {
|
|
@@ -360,6 +389,18 @@ var Token = class extends BaseCurrency {
|
|
|
360
389
|
}
|
|
361
390
|
};
|
|
362
391
|
|
|
392
|
+
// src/nativeCurrency.ts
|
|
393
|
+
var NativeCurrency = class extends BaseCurrency {
|
|
394
|
+
constructor() {
|
|
395
|
+
super(...arguments);
|
|
396
|
+
this.isNative = true;
|
|
397
|
+
this.isToken = false;
|
|
398
|
+
}
|
|
399
|
+
get asToken() {
|
|
400
|
+
return new Token(this.chainId, ZERO_ADDRESS, this.decimals, this.symbol, this.name);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
363
404
|
// src/errors.ts
|
|
364
405
|
var CAN_SET_PROTOTYPE = "setPrototypeOf" in Object;
|
|
365
406
|
var InsufficientReservesError = class extends Error {
|
|
@@ -465,5 +506,25 @@ function sortCurrencies(currencies) {
|
|
|
465
506
|
return a.sortsBefore(b) ? -1 : 1;
|
|
466
507
|
});
|
|
467
508
|
}
|
|
509
|
+
var isCurrencySorted = (currencyA, currencyB) => {
|
|
510
|
+
const [currency0] = sortCurrencies([currencyA, currencyB]);
|
|
511
|
+
return currency0 === currencyA;
|
|
512
|
+
};
|
|
513
|
+
function getCurrencyAddress(currency) {
|
|
514
|
+
if (currency.isNative) {
|
|
515
|
+
return ZERO_ADDRESS;
|
|
516
|
+
}
|
|
517
|
+
return currency.address;
|
|
518
|
+
}
|
|
519
|
+
function getMatchedCurrency(currency, list, matchWrappedCurrency = true) {
|
|
520
|
+
const c = matchWrappedCurrency ? currency.wrapped : currency;
|
|
521
|
+
for (const current of list) {
|
|
522
|
+
const checkAgainst = matchWrappedCurrency ? current.wrapped : current;
|
|
523
|
+
if (checkAgainst.equals(c)) {
|
|
524
|
+
return current;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return void 0;
|
|
528
|
+
}
|
|
468
529
|
|
|
469
|
-
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, _100, _10000, _9975, computePriceImpact, getTokenComparator, sortCurrencies, sortedInsert, sqrt, validateVMTypeInstance };
|
|
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 };
|
package/dist/nativeCurrency.d.ts
CHANGED
|
@@ -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
6
|
export declare abstract class NativeCurrency extends BaseCurrency {
|
|
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,
|
|
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"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -16,4 +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;
|
|
20
|
+
export declare function getCurrencyAddress(currency: Currency): `0x${string}`;
|
|
21
|
+
export declare function getMatchedCurrency(currency: Currency, list: Currency[], matchWrappedCurrency?: boolean): Currency | undefined;
|
|
19
22
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,MAAM,
|
|
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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