@pancakeswap/swap-sdk-core 0.0.1 → 1.0.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 +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 -257
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +196 -182
- package/dist/index.mjs +156 -123
- 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 +20 -14
|
@@ -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,EAAE,IAAI,CAAO;;CAOzD;AAED;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,8BAA8B,EAAE,IAAI,CAAO;;CAO5D"}
|
|
@@ -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,257 +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
|
-
declare 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
|
-
|
|
257
|
-
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, 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;AAE3B,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"}
|