@pancakeswap/swap-sdk-core 0.1.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseCurrency.d.ts +50 -0
- package/dist/baseCurrency.d.ts.map +1 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/currency.d.ts +4 -0
- package/dist/currency.d.ts.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/fractions/currencyAmount.d.ts +31 -0
- package/dist/fractions/currencyAmount.d.ts.map +1 -0
- package/dist/fractions/fraction.d.ts +24 -0
- package/dist/fractions/fraction.d.ts.map +1 -0
- package/dist/fractions/index.d.ts +5 -0
- package/dist/fractions/index.d.ts.map +1 -0
- package/dist/fractions/percent.d.ts +15 -0
- package/dist/fractions/percent.d.ts.map +1 -0
- package/dist/fractions/price.d.ts +39 -0
- package/dist/fractions/price.d.ts.map +1 -0
- package/dist/index.d.ts +9 -260
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -75
- package/dist/index.mjs +47 -71
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/nativeCurrency.d.ts +9 -0
- package/dist/nativeCurrency.d.ts.map +1 -0
- package/dist/token.d.ts +41 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +11 -16
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Currency } from './currency';
|
|
2
|
+
import type { Token } from './token';
|
|
3
|
+
/**
|
|
4
|
+
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseCurrency {
|
|
7
|
+
/**
|
|
8
|
+
* Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
|
|
9
|
+
*/
|
|
10
|
+
abstract readonly isNative: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Returns whether the currency is a token that is usable in PancakeSwap without wrapping
|
|
13
|
+
*/
|
|
14
|
+
abstract readonly isToken: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The chain ID on which this currency resides
|
|
17
|
+
*/
|
|
18
|
+
readonly chainId: number;
|
|
19
|
+
/**
|
|
20
|
+
* The decimals used in representing currency amounts
|
|
21
|
+
*/
|
|
22
|
+
readonly decimals: number;
|
|
23
|
+
/**
|
|
24
|
+
* The symbol of the currency, i.e. a short textual non-unique identifier
|
|
25
|
+
*/
|
|
26
|
+
readonly symbol: string;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the currency, i.e. a descriptive textual non-unique identifier
|
|
29
|
+
*/
|
|
30
|
+
readonly name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Constructs an instance of the base class `BaseCurrency`.
|
|
33
|
+
* @param chainId the chain ID on which this currency resides
|
|
34
|
+
* @param decimals decimals of the currency
|
|
35
|
+
* @param symbol symbol of the currency
|
|
36
|
+
* @param name of the currency
|
|
37
|
+
*/
|
|
38
|
+
protected constructor(chainId: number, decimals: number, symbol: string, name?: string);
|
|
39
|
+
/**
|
|
40
|
+
* Returns whether this currency is functionally equivalent to the other currency
|
|
41
|
+
* @param other the other currency
|
|
42
|
+
*/
|
|
43
|
+
abstract equals(other: Currency): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Return the wrapped version of this currency that can be used with the PancakeSwap contracts. Currencies must
|
|
46
|
+
* implement this to be used in PancakeSwap
|
|
47
|
+
*/
|
|
48
|
+
abstract get wrapped(): Token;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=baseCurrency.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type BigintIsh = bigint | number | string;
|
|
2
|
+
export declare enum TradeType {
|
|
3
|
+
EXACT_INPUT = 0,
|
|
4
|
+
EXACT_OUTPUT = 1
|
|
5
|
+
}
|
|
6
|
+
export declare enum Rounding {
|
|
7
|
+
ROUND_DOWN = 0,
|
|
8
|
+
ROUND_HALF_UP = 1,
|
|
9
|
+
ROUND_UP = 2
|
|
10
|
+
}
|
|
11
|
+
export declare const MINIMUM_LIQUIDITY = 1000n;
|
|
12
|
+
export declare const ZERO = 0n;
|
|
13
|
+
export declare const ONE = 1n;
|
|
14
|
+
export declare const TWO = 2n;
|
|
15
|
+
export declare const THREE = 3n;
|
|
16
|
+
export declare const FIVE = 5n;
|
|
17
|
+
export declare const TEN = 10n;
|
|
18
|
+
export declare const _100 = 100n;
|
|
19
|
+
export declare const _9975 = 9975n;
|
|
20
|
+
export declare const _10000 = 10000n;
|
|
21
|
+
export declare const MaxUint256: bigint;
|
|
22
|
+
export declare enum VMType {
|
|
23
|
+
uint8 = "uint8",
|
|
24
|
+
uint256 = "uint256"
|
|
25
|
+
}
|
|
26
|
+
export declare const VM_TYPE_MAXIMA: {
|
|
27
|
+
uint8: bigint;
|
|
28
|
+
uint256: bigint;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +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,IAAA;IACX,YAAY,IAAA;CACb;AAED,oBAAY,QAAQ;IAClB,UAAU,IAAA;IACV,aAAa,IAAA;IACb,QAAQ,IAAA;CACT;AAED,eAAO,MAAM,iBAAiB,QAAQ,CAAA;AAGtC,eAAO,MAAM,IAAI,KAAK,CAAA;AACtB,eAAO,MAAM,GAAG,KAAK,CAAA;AACrB,eAAO,MAAM,GAAG,KAAK,CAAA;AACrB,eAAO,MAAM,KAAK,KAAK,CAAA;AACvB,eAAO,MAAM,IAAI,KAAK,CAAA;AACtB,eAAO,MAAM,GAAG,MAAM,CAAA;AACtB,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"}
|
|
@@ -0,0 +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"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
|
|
3
|
+
* obtained by sending any amount of input.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InsufficientReservesError extends Error {
|
|
6
|
+
readonly isInsufficientReservesError: true;
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
|
|
11
|
+
* than the price of a single unit of output after fees.
|
|
12
|
+
*/
|
|
13
|
+
export declare class InsufficientInputAmountError extends Error {
|
|
14
|
+
readonly isInsufficientInputAmountError: true;
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Currency } from '../currency';
|
|
2
|
+
import { Token } from '../token';
|
|
3
|
+
import { Fraction } from './fraction';
|
|
4
|
+
import { BigintIsh, Rounding } from '../constants';
|
|
5
|
+
export declare class CurrencyAmount<T extends Currency> extends Fraction {
|
|
6
|
+
readonly currency: T;
|
|
7
|
+
readonly decimalScale: bigint;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
10
|
+
* @param currency the currency in the amount
|
|
11
|
+
* @param rawAmount the raw token or ether amount
|
|
12
|
+
*/
|
|
13
|
+
static fromRawAmount<T extends Currency>(currency: T, rawAmount: BigintIsh): CurrencyAmount<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Construct a currency amount with a denominator that is not equal to 1
|
|
16
|
+
* @param currency the currency
|
|
17
|
+
* @param numerator the numerator of the fractional token amount
|
|
18
|
+
* @param denominator the denominator of the fractional token amount
|
|
19
|
+
*/
|
|
20
|
+
static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
|
|
21
|
+
protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
|
|
22
|
+
add(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
23
|
+
subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
24
|
+
multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
25
|
+
divide(other: Fraction | BigintIsh): CurrencyAmount<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(): CurrencyAmount<Token>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=currencyAmount.d.ts.map
|
|
@@ -0,0 +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,EAAE,QAAQ,EAAc,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,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAMrD,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;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BigintIsh, Rounding } from '../constants';
|
|
2
|
+
export declare class Fraction {
|
|
3
|
+
readonly numerator: bigint;
|
|
4
|
+
readonly denominator: bigint;
|
|
5
|
+
constructor(numerator: BigintIsh, denominator?: BigintIsh);
|
|
6
|
+
private static tryParseFraction;
|
|
7
|
+
get quotient(): bigint;
|
|
8
|
+
get remainder(): Fraction;
|
|
9
|
+
invert(): Fraction;
|
|
10
|
+
add(other: Fraction | BigintIsh): Fraction;
|
|
11
|
+
subtract(other: Fraction | BigintIsh): Fraction;
|
|
12
|
+
lessThan(other: Fraction | BigintIsh): boolean;
|
|
13
|
+
equalTo(other: Fraction | BigintIsh): boolean;
|
|
14
|
+
greaterThan(other: Fraction | BigintIsh): boolean;
|
|
15
|
+
multiply(other: Fraction | BigintIsh): Fraction;
|
|
16
|
+
divide(other: Fraction | BigintIsh): Fraction;
|
|
17
|
+
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
|
|
18
|
+
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
|
|
19
|
+
/**
|
|
20
|
+
* Helper method for converting any super class back to a fraction
|
|
21
|
+
*/
|
|
22
|
+
get asFraction(): Fraction;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=fraction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fraction.d.ts","sourceRoot":"","sources":["../../src/fractions/fraction.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAuClD,qBAAa,QAAQ;IACnB,SAAgB,SAAS,EAAE,MAAM,CAAA;IAEjC,SAAgB,WAAW,EAAE,MAAM,CAAA;gBAEhB,SAAS,EAAE,SAAS,EAAE,WAAW,GAAE,SAAc;IAKpE,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAS/B,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAGD,IAAW,SAAS,IAAI,QAAQ,CAE/B;IAEM,MAAM,IAAI,QAAQ;IAIlB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ;IAW1C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ;IAW/C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO;IAK9C,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO;IAK7C,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO;IAKjD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ;IAK/C,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ;IAK7C,aAAa,CAClB,iBAAiB,EAAE,MAAM,EACzB,MAAM,GAAE,MAA+B,EACvC,QAAQ,GAAE,QAAiC,GAC1C,MAAM;IAWF,OAAO,CACZ,aAAa,EAAE,MAAM,EACrB,MAAM,GAAE,MAA+B,EACvC,QAAQ,GAAE,QAAiC,GAC1C,MAAM;IAST;;OAEG;IACH,IAAW,UAAU,IAAI,QAAQ,CAEhC;CACF"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BigintIsh, Rounding } from '../constants';
|
|
2
|
+
import { Fraction } from './fraction';
|
|
3
|
+
export declare class Percent extends Fraction {
|
|
4
|
+
/**
|
|
5
|
+
* This boolean prevents a fraction from being interpreted as a Percent
|
|
6
|
+
*/
|
|
7
|
+
readonly isPercent: true;
|
|
8
|
+
add(other: Fraction | BigintIsh): Percent;
|
|
9
|
+
subtract(other: Fraction | BigintIsh): Percent;
|
|
10
|
+
multiply(other: Fraction | BigintIsh): Percent;
|
|
11
|
+
divide(other: Fraction | BigintIsh): Percent;
|
|
12
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
13
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=percent.d.ts.map
|
|
@@ -0,0 +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;AAYrC,qBAAa,OAAQ,SAAQ,QAAQ;IACnC;;OAEG;IACH,SAAgB,SAAS,OAAgB;IAEzC,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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BigintIsh, Rounding } from '../constants';
|
|
2
|
+
import { Currency } from '../currency';
|
|
3
|
+
import { Fraction } from './fraction';
|
|
4
|
+
import { CurrencyAmount } from './currencyAmount';
|
|
5
|
+
export declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
|
|
6
|
+
readonly baseCurrency: TBase;
|
|
7
|
+
readonly quoteCurrency: TQuote;
|
|
8
|
+
readonly scalar: Fraction;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a price, either with the base and quote currency amount, or the
|
|
11
|
+
* @param args
|
|
12
|
+
*/
|
|
13
|
+
constructor(...args: [TBase, TQuote, BigintIsh, BigintIsh] | [{
|
|
14
|
+
baseAmount: CurrencyAmount<TBase>;
|
|
15
|
+
quoteAmount: CurrencyAmount<TQuote>;
|
|
16
|
+
}]);
|
|
17
|
+
/**
|
|
18
|
+
* Flip the price, switching the base and quote currency
|
|
19
|
+
*/
|
|
20
|
+
invert(): Price<TQuote, TBase>;
|
|
21
|
+
/**
|
|
22
|
+
* Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
|
|
23
|
+
* @param other the other price
|
|
24
|
+
*/
|
|
25
|
+
multiply<TOtherQuote extends Currency>(other: Price<TQuote, TOtherQuote>): Price<TBase, TOtherQuote>;
|
|
26
|
+
/**
|
|
27
|
+
* Return the amount of quote currency corresponding to a given amount of the base currency
|
|
28
|
+
* @param currencyAmount the amount of base currency to quote against the price
|
|
29
|
+
*/
|
|
30
|
+
quote(currencyAmount: CurrencyAmount<TBase>): CurrencyAmount<TQuote>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the value scaled by decimals for formatting
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private get adjustedForDecimals();
|
|
36
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
37
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=price.d.ts.map
|
|
@@ -0,0 +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,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,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;CAGhF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,260 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ROUND_DOWN = 0,
|
|
11
|
-
ROUND_HALF_UP = 1,
|
|
12
|
-
ROUND_UP = 2
|
|
13
|
-
}
|
|
14
|
-
declare const MINIMUM_LIQUIDITY: JSBI;
|
|
15
|
-
declare const ZERO: JSBI;
|
|
16
|
-
declare const ONE: JSBI;
|
|
17
|
-
declare const TWO: JSBI;
|
|
18
|
-
declare const THREE: JSBI;
|
|
19
|
-
declare const FIVE: JSBI;
|
|
20
|
-
declare const TEN: JSBI;
|
|
21
|
-
declare const _100: JSBI;
|
|
22
|
-
declare const _9975: JSBI;
|
|
23
|
-
declare const _10000: JSBI;
|
|
24
|
-
declare const MaxUint256: JSBI;
|
|
25
|
-
declare enum VMType {
|
|
26
|
-
uint8 = "uint8",
|
|
27
|
-
uint256 = "uint256"
|
|
28
|
-
}
|
|
29
|
-
declare const VM_TYPE_MAXIMA: {
|
|
30
|
-
uint8: JSBI;
|
|
31
|
-
uint256: JSBI;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Represents the native currency of the chain on which it resides, e.g.
|
|
36
|
-
*/
|
|
37
|
-
declare abstract class NativeCurrency extends BaseCurrency {
|
|
38
|
-
readonly isNative: true;
|
|
39
|
-
readonly isToken: false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface SerializedToken {
|
|
43
|
-
chainId: number;
|
|
44
|
-
address: string;
|
|
45
|
-
decimals: number;
|
|
46
|
-
symbol: string;
|
|
47
|
-
name?: string;
|
|
48
|
-
projectLink?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Represents an ERC20 token with a unique address and some metadata.
|
|
52
|
-
*/
|
|
53
|
-
declare class Token extends BaseCurrency {
|
|
54
|
-
readonly isNative: false;
|
|
55
|
-
readonly isToken: true;
|
|
56
|
-
/**
|
|
57
|
-
* The contract address on the chain on which this token lives
|
|
58
|
-
*/
|
|
59
|
-
readonly address: string;
|
|
60
|
-
readonly projectLink?: string;
|
|
61
|
-
constructor(chainId: number, address: string, decimals: number, symbol: string, name?: string, projectLink?: string);
|
|
62
|
-
/**
|
|
63
|
-
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
|
64
|
-
* @param other other token to compare
|
|
65
|
-
*/
|
|
66
|
-
equals(other: Currency): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Returns true if the address of this token sorts before the address of the other token
|
|
69
|
-
* @param other other token to compare
|
|
70
|
-
* @throws if the tokens have the same address
|
|
71
|
-
* @throws if the tokens are on different chains
|
|
72
|
-
*/
|
|
73
|
-
sortsBefore(other: Token): boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Return this token, which does not need to be wrapped
|
|
76
|
-
*/
|
|
77
|
-
get wrapped(): Token;
|
|
78
|
-
get serialize(): SerializedToken;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
type Currency = NativeCurrency | Token;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
|
|
85
|
-
*/
|
|
86
|
-
declare abstract class BaseCurrency {
|
|
87
|
-
/**
|
|
88
|
-
* Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
|
|
89
|
-
*/
|
|
90
|
-
abstract readonly isNative: boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Returns whether the currency is a token that is usable in PancakeSwap without wrapping
|
|
93
|
-
*/
|
|
94
|
-
abstract readonly isToken: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* The chain ID on which this currency resides
|
|
97
|
-
*/
|
|
98
|
-
readonly chainId: number;
|
|
99
|
-
/**
|
|
100
|
-
* The decimals used in representing currency amounts
|
|
101
|
-
*/
|
|
102
|
-
readonly decimals: number;
|
|
103
|
-
/**
|
|
104
|
-
* The symbol of the currency, i.e. a short textual non-unique identifier
|
|
105
|
-
*/
|
|
106
|
-
readonly symbol: string;
|
|
107
|
-
/**
|
|
108
|
-
* The name of the currency, i.e. a descriptive textual non-unique identifier
|
|
109
|
-
*/
|
|
110
|
-
readonly name?: string;
|
|
111
|
-
/**
|
|
112
|
-
* Constructs an instance of the base class `BaseCurrency`.
|
|
113
|
-
* @param chainId the chain ID on which this currency resides
|
|
114
|
-
* @param decimals decimals of the currency
|
|
115
|
-
* @param symbol symbol of the currency
|
|
116
|
-
* @param name of the currency
|
|
117
|
-
*/
|
|
118
|
-
protected constructor(chainId: number, decimals: number, symbol: string, name?: string);
|
|
119
|
-
/**
|
|
120
|
-
* Returns whether this currency is functionally equivalent to the other currency
|
|
121
|
-
* @param other the other currency
|
|
122
|
-
*/
|
|
123
|
-
abstract equals(other: Currency): boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Return the wrapped version of this currency that can be used with the PancakeSwap contracts. Currencies must
|
|
126
|
-
* implement this to be used in PancakeSwap
|
|
127
|
-
*/
|
|
128
|
-
abstract get wrapped(): Token;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
declare class Fraction {
|
|
132
|
-
readonly numerator: JSBI;
|
|
133
|
-
readonly denominator: JSBI;
|
|
134
|
-
constructor(numerator: BigintIsh, denominator?: BigintIsh);
|
|
135
|
-
private static tryParseFraction;
|
|
136
|
-
get quotient(): JSBI;
|
|
137
|
-
get remainder(): Fraction;
|
|
138
|
-
invert(): Fraction;
|
|
139
|
-
add(other: Fraction | BigintIsh): Fraction;
|
|
140
|
-
subtract(other: Fraction | BigintIsh): Fraction;
|
|
141
|
-
lessThan(other: Fraction | BigintIsh): boolean;
|
|
142
|
-
equalTo(other: Fraction | BigintIsh): boolean;
|
|
143
|
-
greaterThan(other: Fraction | BigintIsh): boolean;
|
|
144
|
-
multiply(other: Fraction | BigintIsh): Fraction;
|
|
145
|
-
divide(other: Fraction | BigintIsh): Fraction;
|
|
146
|
-
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
|
|
147
|
-
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
|
|
148
|
-
/**
|
|
149
|
-
* Helper method for converting any super class back to a fraction
|
|
150
|
-
*/
|
|
151
|
-
get asFraction(): Fraction;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
declare class Percent extends Fraction {
|
|
155
|
-
/**
|
|
156
|
-
* This boolean prevents a fraction from being interpreted as a Percent
|
|
157
|
-
*/
|
|
158
|
-
readonly isPercent: true;
|
|
159
|
-
add(other: Fraction | BigintIsh): Percent;
|
|
160
|
-
subtract(other: Fraction | BigintIsh): Percent;
|
|
161
|
-
multiply(other: Fraction | BigintIsh): Percent;
|
|
162
|
-
divide(other: Fraction | BigintIsh): Percent;
|
|
163
|
-
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
164
|
-
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
declare class CurrencyAmount<T extends Currency> extends Fraction {
|
|
168
|
-
readonly currency: T;
|
|
169
|
-
readonly decimalScale: JSBI;
|
|
170
|
-
/**
|
|
171
|
-
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
172
|
-
* @param currency the currency in the amount
|
|
173
|
-
* @param rawAmount the raw token or ether amount
|
|
174
|
-
*/
|
|
175
|
-
static fromRawAmount<T extends Currency>(currency: T, rawAmount: BigintIsh): CurrencyAmount<T>;
|
|
176
|
-
/**
|
|
177
|
-
* Construct a currency amount with a denominator that is not equal to 1
|
|
178
|
-
* @param currency the currency
|
|
179
|
-
* @param numerator the numerator of the fractional token amount
|
|
180
|
-
* @param denominator the denominator of the fractional token amount
|
|
181
|
-
*/
|
|
182
|
-
static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
|
|
183
|
-
protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
|
|
184
|
-
add(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
185
|
-
subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
186
|
-
multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
187
|
-
divide(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
188
|
-
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
189
|
-
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
190
|
-
toExact(format?: object): string;
|
|
191
|
-
get wrapped(): CurrencyAmount<Token>;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
|
|
195
|
-
readonly baseCurrency: TBase;
|
|
196
|
-
readonly quoteCurrency: TQuote;
|
|
197
|
-
readonly scalar: Fraction;
|
|
198
|
-
/**
|
|
199
|
-
* Construct a price, either with the base and quote currency amount, or the
|
|
200
|
-
* @param args
|
|
201
|
-
*/
|
|
202
|
-
constructor(...args: [TBase, TQuote, BigintIsh, BigintIsh] | [{
|
|
203
|
-
baseAmount: CurrencyAmount<TBase>;
|
|
204
|
-
quoteAmount: CurrencyAmount<TQuote>;
|
|
205
|
-
}]);
|
|
206
|
-
/**
|
|
207
|
-
* Flip the price, switching the base and quote currency
|
|
208
|
-
*/
|
|
209
|
-
invert(): Price<TQuote, TBase>;
|
|
210
|
-
/**
|
|
211
|
-
* Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
|
|
212
|
-
* @param other the other price
|
|
213
|
-
*/
|
|
214
|
-
multiply<TOtherQuote extends Currency>(other: Price<TQuote, TOtherQuote>): Price<TBase, TOtherQuote>;
|
|
215
|
-
/**
|
|
216
|
-
* Return the amount of quote currency corresponding to a given amount of the base currency
|
|
217
|
-
* @param currencyAmount the amount of base currency to quote against the price
|
|
218
|
-
*/
|
|
219
|
-
quote(currencyAmount: CurrencyAmount<TBase>): CurrencyAmount<TQuote>;
|
|
220
|
-
/**
|
|
221
|
-
* Get the value scaled by decimals for formatting
|
|
222
|
-
* @private
|
|
223
|
-
*/
|
|
224
|
-
private get adjustedForDecimals();
|
|
225
|
-
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
226
|
-
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
|
|
231
|
-
* obtained by sending any amount of input.
|
|
232
|
-
*/
|
|
233
|
-
declare class InsufficientReservesError extends Error {
|
|
234
|
-
readonly isInsufficientReservesError: true;
|
|
235
|
-
constructor();
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
|
|
239
|
-
* than the price of a single unit of output after fees.
|
|
240
|
-
*/
|
|
241
|
-
declare class InsufficientInputAmountError extends Error {
|
|
242
|
-
readonly isInsufficientInputAmountError: true;
|
|
243
|
-
constructor();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
declare function validateVMTypeInstance(value: JSBI, vmType: VMType): void;
|
|
247
|
-
declare function sqrt(y: JSBI): JSBI;
|
|
248
|
-
declare function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null;
|
|
249
|
-
/**
|
|
250
|
-
* Returns the percent difference between the mid price and the execution price, i.e. price impact.
|
|
251
|
-
* @param midPrice mid price before the trade
|
|
252
|
-
* @param inputAmount the input amount of the trade
|
|
253
|
-
* @param outputAmount the output amount of the trade
|
|
254
|
-
*/
|
|
255
|
-
declare function computePriceImpact<TBase extends Currency, TQuote extends Currency>(midPrice: Price<TBase, TQuote>, inputAmount: CurrencyAmount<TBase>, outputAmount: CurrencyAmount<TQuote>): Percent;
|
|
256
|
-
declare function getTokenComparator(balances: {
|
|
257
|
-
[tokenAddress: string]: CurrencyAmount<Token> | undefined;
|
|
258
|
-
}): (tokenA: Token, tokenB: Token) => number;
|
|
259
|
-
|
|
260
|
-
export { BaseCurrency, BigintIsh, Currency, CurrencyAmount, FIVE, Fraction, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NativeCurrency, ONE, Percent, Price, Rounding, SerializedToken, TEN, THREE, TWO, Token, TradeType, VMType, VM_TYPE_MAXIMA, ZERO, _100, _10000, _9975, computePriceImpact, getTokenComparator, sortedInsert, sqrt, validateVMTypeInstance };
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './baseCurrency';
|
|
3
|
+
export * from './currency';
|
|
4
|
+
export * from './fractions';
|
|
5
|
+
export * from './nativeCurrency';
|
|
6
|
+
export * from './token';
|
|
7
|
+
export * from './errors';
|
|
8
|
+
export * from './utils';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var JSBI2 = require('jsbi');
|
|
4
3
|
var invariant6 = require('tiny-invariant');
|
|
5
4
|
var _Decimal = require('decimal.js-light');
|
|
6
5
|
var _Big = require('big.js');
|
|
@@ -8,13 +7,12 @@ var toFormat = require('toformat');
|
|
|
8
7
|
|
|
9
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
|
|
11
|
-
var JSBI2__default = /*#__PURE__*/_interopDefault(JSBI2);
|
|
12
10
|
var invariant6__default = /*#__PURE__*/_interopDefault(invariant6);
|
|
13
11
|
var _Decimal__default = /*#__PURE__*/_interopDefault(_Decimal);
|
|
14
12
|
var _Big__default = /*#__PURE__*/_interopDefault(_Big);
|
|
15
13
|
var toFormat__default = /*#__PURE__*/_interopDefault(toFormat);
|
|
16
14
|
|
|
17
|
-
// src/
|
|
15
|
+
// src/constants.ts
|
|
18
16
|
var TradeType = /* @__PURE__ */ ((TradeType2) => {
|
|
19
17
|
TradeType2[TradeType2["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
|
20
18
|
TradeType2[TradeType2["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
|
|
@@ -26,25 +24,25 @@ var Rounding = /* @__PURE__ */ ((Rounding2) => {
|
|
|
26
24
|
Rounding2[Rounding2["ROUND_UP"] = 2] = "ROUND_UP";
|
|
27
25
|
return Rounding2;
|
|
28
26
|
})(Rounding || {});
|
|
29
|
-
var MINIMUM_LIQUIDITY =
|
|
30
|
-
var ZERO =
|
|
31
|
-
var ONE =
|
|
32
|
-
var TWO =
|
|
33
|
-
var THREE =
|
|
34
|
-
var FIVE =
|
|
35
|
-
var TEN =
|
|
36
|
-
var _100 =
|
|
37
|
-
var _9975 =
|
|
38
|
-
var _10000 =
|
|
39
|
-
var MaxUint256 =
|
|
27
|
+
var MINIMUM_LIQUIDITY = 1000n;
|
|
28
|
+
var ZERO = 0n;
|
|
29
|
+
var ONE = 1n;
|
|
30
|
+
var TWO = 2n;
|
|
31
|
+
var THREE = 3n;
|
|
32
|
+
var FIVE = 5n;
|
|
33
|
+
var TEN = 10n;
|
|
34
|
+
var _100 = 100n;
|
|
35
|
+
var _9975 = 9975n;
|
|
36
|
+
var _10000 = 10000n;
|
|
37
|
+
var MaxUint256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
40
38
|
var VMType = /* @__PURE__ */ ((VMType3) => {
|
|
41
39
|
VMType3["uint8"] = "uint8";
|
|
42
40
|
VMType3["uint256"] = "uint256";
|
|
43
41
|
return VMType3;
|
|
44
42
|
})(VMType || {});
|
|
45
43
|
var VM_TYPE_MAXIMA = {
|
|
46
|
-
["uint8" /* uint8 */]:
|
|
47
|
-
["uint256" /* uint256 */]:
|
|
44
|
+
["uint8" /* uint8 */]: BigInt("0xff"),
|
|
45
|
+
["uint256" /* uint256 */]: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
|
|
48
46
|
};
|
|
49
47
|
var BaseCurrency = class {
|
|
50
48
|
/**
|
|
@@ -76,12 +74,12 @@ var toFixedRounding = {
|
|
|
76
74
|
[2 /* ROUND_UP */]: 3 /* RoundUp */
|
|
77
75
|
};
|
|
78
76
|
var Fraction = class {
|
|
79
|
-
constructor(numerator, denominator =
|
|
80
|
-
this.numerator =
|
|
81
|
-
this.denominator =
|
|
77
|
+
constructor(numerator, denominator = 1n) {
|
|
78
|
+
this.numerator = BigInt(numerator);
|
|
79
|
+
this.denominator = BigInt(denominator);
|
|
82
80
|
}
|
|
83
81
|
static tryParseFraction(fractionish) {
|
|
84
|
-
if (fractionish
|
|
82
|
+
if (typeof fractionish === "bigint" || typeof fractionish === "number" || typeof fractionish === "string")
|
|
85
83
|
return new Fraction(fractionish);
|
|
86
84
|
if ("numerator" in fractionish && "denominator" in fractionish)
|
|
87
85
|
return fractionish;
|
|
@@ -89,75 +87,54 @@ var Fraction = class {
|
|
|
89
87
|
}
|
|
90
88
|
// performs floor division
|
|
91
89
|
get quotient() {
|
|
92
|
-
return
|
|
90
|
+
return this.numerator / this.denominator;
|
|
93
91
|
}
|
|
94
92
|
// remainder after floor division
|
|
95
93
|
get remainder() {
|
|
96
|
-
return new Fraction(
|
|
94
|
+
return new Fraction(this.numerator % this.denominator, this.denominator);
|
|
97
95
|
}
|
|
98
96
|
invert() {
|
|
99
97
|
return new Fraction(this.denominator, this.numerator);
|
|
100
98
|
}
|
|
101
99
|
add(other) {
|
|
102
100
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
103
|
-
if (
|
|
104
|
-
return new Fraction(
|
|
101
|
+
if (this.denominator === otherParsed.denominator) {
|
|
102
|
+
return new Fraction(this.numerator + otherParsed.numerator, this.denominator);
|
|
105
103
|
}
|
|
106
104
|
return new Fraction(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
JSBI2__default.default.multiply(otherParsed.numerator, this.denominator)
|
|
110
|
-
),
|
|
111
|
-
JSBI2__default.default.multiply(this.denominator, otherParsed.denominator)
|
|
105
|
+
this.numerator * otherParsed.denominator + otherParsed.numerator * this.denominator,
|
|
106
|
+
this.denominator * otherParsed.denominator
|
|
112
107
|
);
|
|
113
108
|
}
|
|
114
109
|
subtract(other) {
|
|
115
110
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
116
|
-
if (
|
|
117
|
-
return new Fraction(
|
|
111
|
+
if (this.denominator === otherParsed.denominator) {
|
|
112
|
+
return new Fraction(this.numerator - otherParsed.numerator, this.denominator);
|
|
118
113
|
}
|
|
119
114
|
return new Fraction(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
JSBI2__default.default.multiply(otherParsed.numerator, this.denominator)
|
|
123
|
-
),
|
|
124
|
-
JSBI2__default.default.multiply(this.denominator, otherParsed.denominator)
|
|
115
|
+
this.numerator * otherParsed.denominator - otherParsed.numerator * this.denominator,
|
|
116
|
+
this.denominator * otherParsed.denominator
|
|
125
117
|
);
|
|
126
118
|
}
|
|
127
119
|
lessThan(other) {
|
|
128
120
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
129
|
-
return
|
|
130
|
-
JSBI2__default.default.multiply(this.numerator, otherParsed.denominator),
|
|
131
|
-
JSBI2__default.default.multiply(otherParsed.numerator, this.denominator)
|
|
132
|
-
);
|
|
121
|
+
return this.numerator * otherParsed.denominator < otherParsed.numerator * this.denominator;
|
|
133
122
|
}
|
|
134
123
|
equalTo(other) {
|
|
135
124
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
136
|
-
return
|
|
137
|
-
JSBI2__default.default.multiply(this.numerator, otherParsed.denominator),
|
|
138
|
-
JSBI2__default.default.multiply(otherParsed.numerator, this.denominator)
|
|
139
|
-
);
|
|
125
|
+
return this.numerator * otherParsed.denominator === otherParsed.numerator * this.denominator;
|
|
140
126
|
}
|
|
141
127
|
greaterThan(other) {
|
|
142
128
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
143
|
-
return
|
|
144
|
-
JSBI2__default.default.multiply(this.numerator, otherParsed.denominator),
|
|
145
|
-
JSBI2__default.default.multiply(otherParsed.numerator, this.denominator)
|
|
146
|
-
);
|
|
129
|
+
return this.numerator * otherParsed.denominator > otherParsed.numerator * this.denominator;
|
|
147
130
|
}
|
|
148
131
|
multiply(other) {
|
|
149
132
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
150
|
-
return new Fraction(
|
|
151
|
-
JSBI2__default.default.multiply(this.numerator, otherParsed.numerator),
|
|
152
|
-
JSBI2__default.default.multiply(this.denominator, otherParsed.denominator)
|
|
153
|
-
);
|
|
133
|
+
return new Fraction(this.numerator * otherParsed.numerator, this.denominator * otherParsed.denominator);
|
|
154
134
|
}
|
|
155
135
|
divide(other) {
|
|
156
136
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
157
|
-
return new Fraction(
|
|
158
|
-
JSBI2__default.default.multiply(this.numerator, otherParsed.denominator),
|
|
159
|
-
JSBI2__default.default.multiply(this.denominator, otherParsed.numerator)
|
|
160
|
-
);
|
|
137
|
+
return new Fraction(this.numerator * otherParsed.denominator, this.denominator * otherParsed.numerator);
|
|
161
138
|
}
|
|
162
139
|
toSignificant(significantDigits, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
|
|
163
140
|
invariant6__default.default(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
|
|
@@ -180,7 +157,9 @@ var Fraction = class {
|
|
|
180
157
|
return new Fraction(this.numerator, this.denominator);
|
|
181
158
|
}
|
|
182
159
|
};
|
|
183
|
-
|
|
160
|
+
|
|
161
|
+
// src/fractions/percent.ts
|
|
162
|
+
var ONE_HUNDRED = new Fraction(100n);
|
|
184
163
|
function toPercent(fraction) {
|
|
185
164
|
return new Percent(fraction.numerator, fraction.denominator);
|
|
186
165
|
}
|
|
@@ -215,9 +194,9 @@ var Big2 = toFormat__default.default(_Big__default.default);
|
|
|
215
194
|
var CurrencyAmount = class extends Fraction {
|
|
216
195
|
constructor(currency, numerator, denominator) {
|
|
217
196
|
super(numerator, denominator);
|
|
218
|
-
invariant6__default.default(
|
|
197
|
+
invariant6__default.default(this.quotient <= MaxUint256, "AMOUNT");
|
|
219
198
|
this.currency = currency;
|
|
220
|
-
this.decimalScale =
|
|
199
|
+
this.decimalScale = 10n ** BigInt(currency.decimals);
|
|
221
200
|
}
|
|
222
201
|
/**
|
|
223
202
|
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
@@ -296,10 +275,7 @@ var Price = class extends Fraction {
|
|
|
296
275
|
super(numerator, denominator);
|
|
297
276
|
this.baseCurrency = baseCurrency;
|
|
298
277
|
this.quoteCurrency = quoteCurrency;
|
|
299
|
-
this.scalar = new Fraction(
|
|
300
|
-
JSBI2__default.default.exponentiate(JSBI2__default.default.BigInt(10), JSBI2__default.default.BigInt(baseCurrency.decimals)),
|
|
301
|
-
JSBI2__default.default.exponentiate(JSBI2__default.default.BigInt(10), JSBI2__default.default.BigInt(quoteCurrency.decimals))
|
|
302
|
-
);
|
|
278
|
+
this.scalar = new Fraction(10n ** BigInt(baseCurrency.decimals), 10n ** BigInt(quoteCurrency.decimals));
|
|
303
279
|
}
|
|
304
280
|
/**
|
|
305
281
|
* Flip the price, switching the base and quote currency
|
|
@@ -413,21 +389,21 @@ var InsufficientInputAmountError = class extends Error {
|
|
|
413
389
|
}
|
|
414
390
|
};
|
|
415
391
|
function validateVMTypeInstance(value, vmType) {
|
|
416
|
-
invariant6__default.default(
|
|
417
|
-
invariant6__default.default(
|
|
392
|
+
invariant6__default.default(value >= ZERO, `${value} is not a ${vmType}.`);
|
|
393
|
+
invariant6__default.default(value <= VM_TYPE_MAXIMA[vmType], `${value} is not a ${vmType}.`);
|
|
418
394
|
}
|
|
419
395
|
function sqrt(y) {
|
|
420
|
-
invariant6__default.default(
|
|
396
|
+
invariant6__default.default(y >= ZERO, "NEGATIVE");
|
|
421
397
|
let z = ZERO;
|
|
422
398
|
let x;
|
|
423
|
-
if (
|
|
399
|
+
if (y > THREE) {
|
|
424
400
|
z = y;
|
|
425
|
-
x =
|
|
426
|
-
while (
|
|
401
|
+
x = y / TWO + ONE;
|
|
402
|
+
while (x < z) {
|
|
427
403
|
z = x;
|
|
428
|
-
x =
|
|
404
|
+
x = (y / x + x) / TWO;
|
|
429
405
|
}
|
|
430
|
-
} else if (
|
|
406
|
+
} else if (y !== ZERO) {
|
|
431
407
|
z = ONE;
|
|
432
408
|
}
|
|
433
409
|
return z;
|
|
@@ -487,10 +463,6 @@ function getTokenComparator(balances) {
|
|
|
487
463
|
};
|
|
488
464
|
}
|
|
489
465
|
|
|
490
|
-
Object.defineProperty(exports, 'JSBI', {
|
|
491
|
-
enumerable: true,
|
|
492
|
-
get: function () { return JSBI2__default.default; }
|
|
493
|
-
});
|
|
494
466
|
exports.BaseCurrency = BaseCurrency;
|
|
495
467
|
exports.CurrencyAmount = CurrencyAmount;
|
|
496
468
|
exports.FIVE = FIVE;
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import JSBI2 from 'jsbi';
|
|
2
|
-
export { default as JSBI } from 'jsbi';
|
|
3
1
|
import invariant6 from 'tiny-invariant';
|
|
4
2
|
import _Decimal from 'decimal.js-light';
|
|
5
3
|
import _Big from 'big.js';
|
|
6
4
|
import toFormat from 'toformat';
|
|
7
5
|
|
|
8
|
-
// src/
|
|
6
|
+
// src/constants.ts
|
|
9
7
|
var TradeType = /* @__PURE__ */ ((TradeType2) => {
|
|
10
8
|
TradeType2[TradeType2["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
|
11
9
|
TradeType2[TradeType2["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
|
|
@@ -17,25 +15,25 @@ var Rounding = /* @__PURE__ */ ((Rounding2) => {
|
|
|
17
15
|
Rounding2[Rounding2["ROUND_UP"] = 2] = "ROUND_UP";
|
|
18
16
|
return Rounding2;
|
|
19
17
|
})(Rounding || {});
|
|
20
|
-
var MINIMUM_LIQUIDITY =
|
|
21
|
-
var ZERO =
|
|
22
|
-
var ONE =
|
|
23
|
-
var TWO =
|
|
24
|
-
var THREE =
|
|
25
|
-
var FIVE =
|
|
26
|
-
var TEN =
|
|
27
|
-
var _100 =
|
|
28
|
-
var _9975 =
|
|
29
|
-
var _10000 =
|
|
30
|
-
var MaxUint256 =
|
|
18
|
+
var MINIMUM_LIQUIDITY = 1000n;
|
|
19
|
+
var ZERO = 0n;
|
|
20
|
+
var ONE = 1n;
|
|
21
|
+
var TWO = 2n;
|
|
22
|
+
var THREE = 3n;
|
|
23
|
+
var FIVE = 5n;
|
|
24
|
+
var TEN = 10n;
|
|
25
|
+
var _100 = 100n;
|
|
26
|
+
var _9975 = 9975n;
|
|
27
|
+
var _10000 = 10000n;
|
|
28
|
+
var MaxUint256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
31
29
|
var VMType = /* @__PURE__ */ ((VMType3) => {
|
|
32
30
|
VMType3["uint8"] = "uint8";
|
|
33
31
|
VMType3["uint256"] = "uint256";
|
|
34
32
|
return VMType3;
|
|
35
33
|
})(VMType || {});
|
|
36
34
|
var VM_TYPE_MAXIMA = {
|
|
37
|
-
["uint8" /* uint8 */]:
|
|
38
|
-
["uint256" /* uint256 */]:
|
|
35
|
+
["uint8" /* uint8 */]: BigInt("0xff"),
|
|
36
|
+
["uint256" /* uint256 */]: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
|
|
39
37
|
};
|
|
40
38
|
var BaseCurrency = class {
|
|
41
39
|
/**
|
|
@@ -67,12 +65,12 @@ var toFixedRounding = {
|
|
|
67
65
|
[2 /* ROUND_UP */]: 3 /* RoundUp */
|
|
68
66
|
};
|
|
69
67
|
var Fraction = class {
|
|
70
|
-
constructor(numerator, denominator =
|
|
71
|
-
this.numerator =
|
|
72
|
-
this.denominator =
|
|
68
|
+
constructor(numerator, denominator = 1n) {
|
|
69
|
+
this.numerator = BigInt(numerator);
|
|
70
|
+
this.denominator = BigInt(denominator);
|
|
73
71
|
}
|
|
74
72
|
static tryParseFraction(fractionish) {
|
|
75
|
-
if (fractionish
|
|
73
|
+
if (typeof fractionish === "bigint" || typeof fractionish === "number" || typeof fractionish === "string")
|
|
76
74
|
return new Fraction(fractionish);
|
|
77
75
|
if ("numerator" in fractionish && "denominator" in fractionish)
|
|
78
76
|
return fractionish;
|
|
@@ -80,75 +78,54 @@ var Fraction = class {
|
|
|
80
78
|
}
|
|
81
79
|
// performs floor division
|
|
82
80
|
get quotient() {
|
|
83
|
-
return
|
|
81
|
+
return this.numerator / this.denominator;
|
|
84
82
|
}
|
|
85
83
|
// remainder after floor division
|
|
86
84
|
get remainder() {
|
|
87
|
-
return new Fraction(
|
|
85
|
+
return new Fraction(this.numerator % this.denominator, this.denominator);
|
|
88
86
|
}
|
|
89
87
|
invert() {
|
|
90
88
|
return new Fraction(this.denominator, this.numerator);
|
|
91
89
|
}
|
|
92
90
|
add(other) {
|
|
93
91
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
94
|
-
if (
|
|
95
|
-
return new Fraction(
|
|
92
|
+
if (this.denominator === otherParsed.denominator) {
|
|
93
|
+
return new Fraction(this.numerator + otherParsed.numerator, this.denominator);
|
|
96
94
|
}
|
|
97
95
|
return new Fraction(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
JSBI2.multiply(otherParsed.numerator, this.denominator)
|
|
101
|
-
),
|
|
102
|
-
JSBI2.multiply(this.denominator, otherParsed.denominator)
|
|
96
|
+
this.numerator * otherParsed.denominator + otherParsed.numerator * this.denominator,
|
|
97
|
+
this.denominator * otherParsed.denominator
|
|
103
98
|
);
|
|
104
99
|
}
|
|
105
100
|
subtract(other) {
|
|
106
101
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
107
|
-
if (
|
|
108
|
-
return new Fraction(
|
|
102
|
+
if (this.denominator === otherParsed.denominator) {
|
|
103
|
+
return new Fraction(this.numerator - otherParsed.numerator, this.denominator);
|
|
109
104
|
}
|
|
110
105
|
return new Fraction(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
JSBI2.multiply(otherParsed.numerator, this.denominator)
|
|
114
|
-
),
|
|
115
|
-
JSBI2.multiply(this.denominator, otherParsed.denominator)
|
|
106
|
+
this.numerator * otherParsed.denominator - otherParsed.numerator * this.denominator,
|
|
107
|
+
this.denominator * otherParsed.denominator
|
|
116
108
|
);
|
|
117
109
|
}
|
|
118
110
|
lessThan(other) {
|
|
119
111
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
120
|
-
return
|
|
121
|
-
JSBI2.multiply(this.numerator, otherParsed.denominator),
|
|
122
|
-
JSBI2.multiply(otherParsed.numerator, this.denominator)
|
|
123
|
-
);
|
|
112
|
+
return this.numerator * otherParsed.denominator < otherParsed.numerator * this.denominator;
|
|
124
113
|
}
|
|
125
114
|
equalTo(other) {
|
|
126
115
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
127
|
-
return
|
|
128
|
-
JSBI2.multiply(this.numerator, otherParsed.denominator),
|
|
129
|
-
JSBI2.multiply(otherParsed.numerator, this.denominator)
|
|
130
|
-
);
|
|
116
|
+
return this.numerator * otherParsed.denominator === otherParsed.numerator * this.denominator;
|
|
131
117
|
}
|
|
132
118
|
greaterThan(other) {
|
|
133
119
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
134
|
-
return
|
|
135
|
-
JSBI2.multiply(this.numerator, otherParsed.denominator),
|
|
136
|
-
JSBI2.multiply(otherParsed.numerator, this.denominator)
|
|
137
|
-
);
|
|
120
|
+
return this.numerator * otherParsed.denominator > otherParsed.numerator * this.denominator;
|
|
138
121
|
}
|
|
139
122
|
multiply(other) {
|
|
140
123
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
141
|
-
return new Fraction(
|
|
142
|
-
JSBI2.multiply(this.numerator, otherParsed.numerator),
|
|
143
|
-
JSBI2.multiply(this.denominator, otherParsed.denominator)
|
|
144
|
-
);
|
|
124
|
+
return new Fraction(this.numerator * otherParsed.numerator, this.denominator * otherParsed.denominator);
|
|
145
125
|
}
|
|
146
126
|
divide(other) {
|
|
147
127
|
const otherParsed = Fraction.tryParseFraction(other);
|
|
148
|
-
return new Fraction(
|
|
149
|
-
JSBI2.multiply(this.numerator, otherParsed.denominator),
|
|
150
|
-
JSBI2.multiply(this.denominator, otherParsed.numerator)
|
|
151
|
-
);
|
|
128
|
+
return new Fraction(this.numerator * otherParsed.denominator, this.denominator * otherParsed.numerator);
|
|
152
129
|
}
|
|
153
130
|
toSignificant(significantDigits, format = { groupSeparator: "" }, rounding = 1 /* ROUND_HALF_UP */) {
|
|
154
131
|
invariant6(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
|
|
@@ -171,7 +148,9 @@ var Fraction = class {
|
|
|
171
148
|
return new Fraction(this.numerator, this.denominator);
|
|
172
149
|
}
|
|
173
150
|
};
|
|
174
|
-
|
|
151
|
+
|
|
152
|
+
// src/fractions/percent.ts
|
|
153
|
+
var ONE_HUNDRED = new Fraction(100n);
|
|
175
154
|
function toPercent(fraction) {
|
|
176
155
|
return new Percent(fraction.numerator, fraction.denominator);
|
|
177
156
|
}
|
|
@@ -206,9 +185,9 @@ var Big2 = toFormat(_Big);
|
|
|
206
185
|
var CurrencyAmount = class extends Fraction {
|
|
207
186
|
constructor(currency, numerator, denominator) {
|
|
208
187
|
super(numerator, denominator);
|
|
209
|
-
invariant6(
|
|
188
|
+
invariant6(this.quotient <= MaxUint256, "AMOUNT");
|
|
210
189
|
this.currency = currency;
|
|
211
|
-
this.decimalScale =
|
|
190
|
+
this.decimalScale = 10n ** BigInt(currency.decimals);
|
|
212
191
|
}
|
|
213
192
|
/**
|
|
214
193
|
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
@@ -287,10 +266,7 @@ var Price = class extends Fraction {
|
|
|
287
266
|
super(numerator, denominator);
|
|
288
267
|
this.baseCurrency = baseCurrency;
|
|
289
268
|
this.quoteCurrency = quoteCurrency;
|
|
290
|
-
this.scalar = new Fraction(
|
|
291
|
-
JSBI2.exponentiate(JSBI2.BigInt(10), JSBI2.BigInt(baseCurrency.decimals)),
|
|
292
|
-
JSBI2.exponentiate(JSBI2.BigInt(10), JSBI2.BigInt(quoteCurrency.decimals))
|
|
293
|
-
);
|
|
269
|
+
this.scalar = new Fraction(10n ** BigInt(baseCurrency.decimals), 10n ** BigInt(quoteCurrency.decimals));
|
|
294
270
|
}
|
|
295
271
|
/**
|
|
296
272
|
* Flip the price, switching the base and quote currency
|
|
@@ -404,21 +380,21 @@ var InsufficientInputAmountError = class extends Error {
|
|
|
404
380
|
}
|
|
405
381
|
};
|
|
406
382
|
function validateVMTypeInstance(value, vmType) {
|
|
407
|
-
invariant6(
|
|
408
|
-
invariant6(
|
|
383
|
+
invariant6(value >= ZERO, `${value} is not a ${vmType}.`);
|
|
384
|
+
invariant6(value <= VM_TYPE_MAXIMA[vmType], `${value} is not a ${vmType}.`);
|
|
409
385
|
}
|
|
410
386
|
function sqrt(y) {
|
|
411
|
-
invariant6(
|
|
387
|
+
invariant6(y >= ZERO, "NEGATIVE");
|
|
412
388
|
let z = ZERO;
|
|
413
389
|
let x;
|
|
414
|
-
if (
|
|
390
|
+
if (y > THREE) {
|
|
415
391
|
z = y;
|
|
416
|
-
x =
|
|
417
|
-
while (
|
|
392
|
+
x = y / TWO + ONE;
|
|
393
|
+
while (x < z) {
|
|
418
394
|
z = x;
|
|
419
|
-
x =
|
|
395
|
+
x = (y / x + x) / TWO;
|
|
420
396
|
}
|
|
421
|
-
} else if (
|
|
397
|
+
} else if (y !== ZERO) {
|
|
422
398
|
z = ONE;
|
|
423
399
|
}
|
|
424
400
|
return z;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseCurrency } from './baseCurrency';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the native currency of the chain on which it resides, e.g.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class NativeCurrency extends BaseCurrency {
|
|
6
|
+
readonly isNative: true;
|
|
7
|
+
readonly isToken: false;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=nativeCurrency.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseCurrency } from './baseCurrency';
|
|
2
|
+
import { Currency } from './currency';
|
|
3
|
+
export interface SerializedToken {
|
|
4
|
+
chainId: number;
|
|
5
|
+
address: `0x${string}`;
|
|
6
|
+
decimals: number;
|
|
7
|
+
symbol: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
projectLink?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Token extends BaseCurrency {
|
|
15
|
+
readonly isNative: false;
|
|
16
|
+
readonly isToken: true;
|
|
17
|
+
/**
|
|
18
|
+
* The contract address on the chain on which this token lives
|
|
19
|
+
*/
|
|
20
|
+
readonly address: `0x${string}`;
|
|
21
|
+
readonly projectLink?: string;
|
|
22
|
+
constructor(chainId: number, address: `0x${string}`, decimals: number, symbol: string, name?: string, projectLink?: string);
|
|
23
|
+
/**
|
|
24
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
|
25
|
+
* @param other other token to compare
|
|
26
|
+
*/
|
|
27
|
+
equals(other: Currency): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns true if the address of this token sorts before the address of the other token
|
|
30
|
+
* @param other other token to compare
|
|
31
|
+
* @throws if the tokens have the same address
|
|
32
|
+
* @throws if the tokens are on different chains
|
|
33
|
+
*/
|
|
34
|
+
sortsBefore(other: Token): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Return this token, which does not need to be wrapped
|
|
37
|
+
*/
|
|
38
|
+
get wrapped(): Token;
|
|
39
|
+
get serialize(): SerializedToken;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=token.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { VMType } from './constants';
|
|
2
|
+
import { Currency } from './currency';
|
|
3
|
+
import { CurrencyAmount, Percent, Price } from './fractions';
|
|
4
|
+
import { Token } from './token';
|
|
5
|
+
export declare function validateVMTypeInstance(value: bigint, vmType: VMType): void;
|
|
6
|
+
export declare function sqrt(y: bigint): bigint;
|
|
7
|
+
export declare function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the percent difference between the mid price and the execution price, i.e. price impact.
|
|
10
|
+
* @param midPrice mid price before the trade
|
|
11
|
+
* @param inputAmount the input amount of the trade
|
|
12
|
+
* @param outputAmount the output amount of the trade
|
|
13
|
+
*/
|
|
14
|
+
export declare function computePriceImpact<TBase extends Currency, TQuote extends Currency>(midPrice: Price<TBase, TQuote>, inputAmount: CurrencyAmount<TBase>, outputAmount: CurrencyAmount<TQuote>): Percent;
|
|
15
|
+
export declare function getTokenComparator(balances: {
|
|
16
|
+
[tokenAddress: string]: CurrencyAmount<Token> | undefined;
|
|
17
|
+
}): (tokenA: Token, tokenB: Token) => number;
|
|
18
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAkB,MAAM,aAAa,CAAA;AAC3E,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,CAkB3C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pancakeswap/swap-sdk-core",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "🛠 An SDK for building applications on top of Pancakeswap.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"typings": "dist/index.d.ts",
|
|
@@ -25,29 +25,17 @@
|
|
|
25
25
|
"keywords": [
|
|
26
26
|
"pancakeswap"
|
|
27
27
|
],
|
|
28
|
-
"scripts": {
|
|
29
|
-
"lint": "eslint src test",
|
|
30
|
-
"build": "tsup",
|
|
31
|
-
"dev": "tsup --watch",
|
|
32
|
-
"test": "jest",
|
|
33
|
-
"prepublishOnly": "yarn run build",
|
|
34
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
35
|
-
},
|
|
36
28
|
"dependencies": {
|
|
37
29
|
"big.js": "^5.2.2",
|
|
38
30
|
"decimal.js-light": "^2.5.0",
|
|
39
|
-
"
|
|
40
|
-
"tiny-invariant": "^1.1.0",
|
|
31
|
+
"tiny-invariant": "^1.3.0",
|
|
41
32
|
"tiny-warning": "^1.0.3",
|
|
42
33
|
"toformat": "^2.0.0"
|
|
43
34
|
},
|
|
44
35
|
"peerDependencies": {},
|
|
45
36
|
"devDependencies": {
|
|
46
|
-
"@swc/core": "^1.2.215",
|
|
47
|
-
"@swc/jest": "^0.2.21",
|
|
48
37
|
"@types/big.js": "^4.0.5",
|
|
49
|
-
"
|
|
50
|
-
"babel-plugin-transform-jsbi-to-bigint": "^1.3.1"
|
|
38
|
+
"tsup": "^6.7.0"
|
|
51
39
|
},
|
|
52
40
|
"engines": {
|
|
53
41
|
"node": ">=10"
|
|
@@ -56,5 +44,12 @@
|
|
|
56
44
|
"printWidth": 120,
|
|
57
45
|
"semi": false,
|
|
58
46
|
"singleQuote": true
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"lint": "eslint src test",
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"dev": "tsup --watch",
|
|
52
|
+
"test": "vitest --run",
|
|
53
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
59
54
|
}
|
|
60
|
-
}
|
|
55
|
+
}
|