@pancakeswap/sdk 3.1.0 → 3.1.2

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Pancakeswap SDK
1
+ # PancakeSwap SDK
2
2
 
3
3
  Forked from the [Uniswap SDK](https://github.com/Uniswap/uniswap-v2-sdk/commit/a88048e9c4198a5bdaea00883ca00c8c8e582605).
4
4
 
package/dist/index.d.ts CHANGED
@@ -1,316 +1,78 @@
1
- import JSBI from 'jsbi';
2
1
  export { default as JSBI } from 'jsbi';
2
+ import { Token, CurrencyAmount, Price, BigintIsh, Currency, TradeType, Percent, NativeCurrency } from '@pancakeswap/swap-sdk-core';
3
+ export * from '@pancakeswap/swap-sdk-core';
3
4
 
4
- /**
5
- * Represents the native currency of the chain on which it resides, e.g.
6
- */
7
- declare abstract class NativeCurrency extends BaseCurrency {
8
- readonly isNative: true;
9
- readonly isToken: false;
10
- }
11
-
12
- declare type Currency = NativeCurrency | Token;
13
-
14
- /**
15
- * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
16
- */
17
- declare abstract class BaseCurrency {
18
- /**
19
- * Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
20
- */
21
- abstract readonly isNative: boolean;
22
- /**
23
- * Returns whether the currency is a token that is usable in PancakeSwap without wrapping
24
- */
25
- abstract readonly isToken: boolean;
26
- /**
27
- * The chain ID on which this currency resides
28
- */
29
- readonly chainId: number;
30
- /**
31
- * The decimals used in representing currency amounts
32
- */
33
- readonly decimals: number;
34
- /**
35
- * The symbol of the currency, i.e. a short textual non-unique identifier
36
- */
37
- readonly symbol: string;
38
- /**
39
- * The name of the currency, i.e. a descriptive textual non-unique identifier
40
- */
41
- readonly name?: string;
42
- /**
43
- * Constructs an instance of the base class `BaseCurrency`.
44
- * @param chainId the chain ID on which this currency resides
45
- * @param decimals decimals of the currency
46
- * @param symbol symbol of the currency
47
- * @param name of the currency
48
- */
49
- protected constructor(chainId: number, decimals: number, symbol: string, name?: string);
50
- /**
51
- * Returns whether this currency is functionally equivalent to the other currency
52
- * @param other the other currency
53
- */
54
- abstract equals(other: Currency): boolean;
55
- /**
56
- * Return the wrapped version of this currency that can be used with the PancakeSwap contracts. Currencies must
57
- * implement this to be used in PancakeSwap
58
- */
59
- abstract get wrapped(): Token;
60
- }
61
-
62
- interface SerializedToken {
63
- chainId: number;
64
- address: string;
65
- decimals: number;
66
- symbol: string;
67
- name?: string;
68
- projectLink?: string;
69
- }
70
- /**
71
- * Represents an ERC20 token with a unique address and some metadata.
72
- */
73
- declare class Token extends BaseCurrency {
74
- readonly isNative: false;
75
- readonly isToken: true;
76
- /**
77
- * The contract address on the chain on which this token lives
78
- */
79
- readonly address: string;
80
- readonly projectLink?: string;
5
+ declare class ERC20Token extends Token {
81
6
  constructor(chainId: number, address: string, decimals: number, symbol: string, name?: string, projectLink?: string);
82
- /**
83
- * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
84
- * @param other other token to compare
85
- */
86
- equals(other: Currency): boolean;
87
- /**
88
- * Returns true if the address of this token sorts before the address of the other token
89
- * @param other other token to compare
90
- * @throws if the tokens have the same address
91
- * @throws if the tokens are on different chains
92
- */
93
- sortsBefore(other: Token): boolean;
94
- /**
95
- * Return this token, which does not need to be wrapped
96
- */
97
- get wrapped(): Token;
98
- get serialize(): SerializedToken;
99
7
  }
100
8
 
101
- declare type BigintIsh = JSBI | number | string;
102
9
  declare enum ChainId {
103
10
  ETHEREUM = 1,
104
- RINKEBY = 4,
105
11
  GOERLI = 5,
106
12
  BSC = 56,
107
13
  BSC_TESTNET = 97
108
14
  }
109
- declare enum TradeType {
110
- EXACT_INPUT = 0,
111
- EXACT_OUTPUT = 1
112
- }
113
- declare enum Rounding {
114
- ROUND_DOWN = 0,
115
- ROUND_HALF_UP = 1,
116
- ROUND_UP = 2
117
- }
118
15
  declare const FACTORY_ADDRESS = "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73";
119
16
  declare const FACTORY_ADDRESS_MAP: Record<number, string>;
120
17
  declare const INIT_CODE_HASH = "0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5";
121
18
  declare const INIT_CODE_HASH_MAP: Record<number, string>;
122
- declare const MINIMUM_LIQUIDITY: JSBI;
123
- declare const ZERO: JSBI;
124
- declare const ONE: JSBI;
125
- declare const TWO: JSBI;
126
- declare const THREE: JSBI;
127
- declare const FIVE: JSBI;
128
- declare const TEN: JSBI;
129
- declare const _100: JSBI;
130
- declare const _9975: JSBI;
131
- declare const _10000: JSBI;
132
- declare const MaxUint256: JSBI;
133
- declare enum SolidityType {
134
- uint8 = "uint8",
135
- uint256 = "uint256"
136
- }
137
- declare const SOLIDITY_TYPE_MAXIMA: {
138
- uint8: JSBI;
139
- uint256: JSBI;
140
- };
141
19
  declare const WETH9: {
142
- 1: Token;
143
- 4: Token;
144
- 5: Token;
20
+ 1: ERC20Token;
21
+ 5: ERC20Token;
145
22
  };
146
23
  declare const WBNB: {
147
- 1: Token;
148
- 56: Token;
149
- 97: Token;
24
+ 1: ERC20Token;
25
+ 56: ERC20Token;
26
+ 97: ERC20Token;
150
27
  };
151
- declare const WNATIVE: Record<number, Token>;
28
+ declare const WNATIVE: Record<number, ERC20Token>;
152
29
  declare const NATIVE: Record<number, {
153
30
  name: string;
154
31
  symbol: string;
155
32
  decimals: number;
156
33
  }>;
157
34
 
158
- /**
159
- * Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
160
- * obtained by sending any amount of input.
161
- */
162
- declare class InsufficientReservesError extends Error {
163
- readonly isInsufficientReservesError: true;
164
- constructor();
165
- }
166
- /**
167
- * Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
168
- * than the price of a single unit of output after fees.
169
- */
170
- declare class InsufficientInputAmountError extends Error {
171
- readonly isInsufficientInputAmountError: true;
172
- constructor();
173
- }
174
-
175
- declare class Fraction {
176
- readonly numerator: JSBI;
177
- readonly denominator: JSBI;
178
- constructor(numerator: BigintIsh, denominator?: BigintIsh);
179
- private static tryParseFraction;
180
- get quotient(): JSBI;
181
- get remainder(): Fraction;
182
- invert(): Fraction;
183
- add(other: Fraction | BigintIsh): Fraction;
184
- subtract(other: Fraction | BigintIsh): Fraction;
185
- lessThan(other: Fraction | BigintIsh): boolean;
186
- equalTo(other: Fraction | BigintIsh): boolean;
187
- greaterThan(other: Fraction | BigintIsh): boolean;
188
- multiply(other: Fraction | BigintIsh): Fraction;
189
- divide(other: Fraction | BigintIsh): Fraction;
190
- toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
191
- toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
192
- /**
193
- * Helper method for converting any super class back to a fraction
194
- */
195
- get asFraction(): Fraction;
196
- }
197
-
198
- declare class CurrencyAmount<T extends Currency> extends Fraction {
199
- readonly currency: T;
200
- readonly decimalScale: JSBI;
201
- /**
202
- * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
203
- * @param currency the currency in the amount
204
- * @param rawAmount the raw token or ether amount
205
- */
206
- static fromRawAmount<T extends Currency>(currency: T, rawAmount: BigintIsh): CurrencyAmount<T>;
207
- /**
208
- * Construct a currency amount with a denominator that is not equal to 1
209
- * @param currency the currency
210
- * @param numerator the numerator of the fractional token amount
211
- * @param denominator the denominator of the fractional token amount
212
- */
213
- static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
214
- protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
215
- add(other: CurrencyAmount<T>): CurrencyAmount<T>;
216
- subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
217
- multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
218
- divide(other: Fraction | BigintIsh): CurrencyAmount<T>;
219
- toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
220
- toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
221
- toExact(format?: object): string;
222
- get wrapped(): CurrencyAmount<Token>;
223
- }
224
-
225
- declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
226
- readonly baseCurrency: TBase;
227
- readonly quoteCurrency: TQuote;
228
- readonly scalar: Fraction;
229
- /**
230
- * Construct a price, either with the base and quote currency amount, or the
231
- * @param args
232
- */
233
- constructor(...args: [TBase, TQuote, BigintIsh, BigintIsh] | [{
234
- baseAmount: CurrencyAmount<TBase>;
235
- quoteAmount: CurrencyAmount<TQuote>;
236
- }]);
237
- /**
238
- * Flip the price, switching the base and quote currency
239
- */
240
- invert(): Price<TQuote, TBase>;
241
- /**
242
- * 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
243
- * @param other the other price
244
- */
245
- multiply<TOtherQuote extends Currency>(other: Price<TQuote, TOtherQuote>): Price<TBase, TOtherQuote>;
246
- /**
247
- * Return the amount of quote currency corresponding to a given amount of the base currency
248
- * @param currencyAmount the amount of base currency to quote against the price
249
- */
250
- quote(currencyAmount: CurrencyAmount<TBase>): CurrencyAmount<TQuote>;
251
- /**
252
- * Get the value scaled by decimals for formatting
253
- * @private
254
- */
255
- private get adjustedForDecimals();
256
- toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
257
- toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
258
- }
259
-
260
- declare class Percent extends Fraction {
261
- /**
262
- * This boolean prevents a fraction from being interpreted as a Percent
263
- */
264
- readonly isPercent: true;
265
- add(other: Fraction | BigintIsh): Percent;
266
- subtract(other: Fraction | BigintIsh): Percent;
267
- multiply(other: Fraction | BigintIsh): Percent;
268
- divide(other: Fraction | BigintIsh): Percent;
269
- toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
270
- toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
271
- }
272
-
273
35
  declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, }: {
274
36
  factoryAddress: string;
275
- tokenA: Token;
276
- tokenB: Token;
37
+ tokenA: ERC20Token;
38
+ tokenB: ERC20Token;
277
39
  }) => string;
278
40
  declare class Pair {
279
- readonly liquidityToken: Token;
41
+ readonly liquidityToken: ERC20Token;
280
42
  private readonly tokenAmounts;
281
- static getAddress(tokenA: Token, tokenB: Token): string;
282
- constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>);
43
+ static getAddress(tokenA: ERC20Token, tokenB: ERC20Token): string;
44
+ constructor(currencyAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>);
283
45
  /**
284
46
  * Returns true if the token is either token0 or token1
285
47
  * @param token to check
286
48
  */
287
- involvesToken(token: Token): boolean;
49
+ involvesToken(token: ERC20Token): boolean;
288
50
  /**
289
51
  * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
290
52
  */
291
- get token0Price(): Price<Token, Token>;
53
+ get token0Price(): Price<ERC20Token, ERC20Token>;
292
54
  /**
293
55
  * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
294
56
  */
295
- get token1Price(): Price<Token, Token>;
57
+ get token1Price(): Price<ERC20Token, ERC20Token>;
296
58
  /**
297
59
  * Return the price of the given token in terms of the other token in the pair.
298
60
  * @param token token to return price of
299
61
  */
300
- priceOf(token: Token): Price<Token, Token>;
62
+ priceOf(token: ERC20Token): Price<ERC20Token, ERC20Token>;
301
63
  /**
302
64
  * Returns the chain ID of the tokens in the pair.
303
65
  */
304
66
  get chainId(): number;
305
- get token0(): Token;
306
- get token1(): Token;
307
- get reserve0(): CurrencyAmount<Token>;
308
- get reserve1(): CurrencyAmount<Token>;
309
- reserveOf(token: Token): CurrencyAmount<Token>;
310
- getOutputAmount(inputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair];
311
- getInputAmount(outputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair];
312
- getLiquidityMinted(totalSupply: CurrencyAmount<Token>, tokenAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>): CurrencyAmount<Token>;
313
- getLiquidityValue(token: Token, totalSupply: CurrencyAmount<Token>, liquidity: CurrencyAmount<Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<Token>;
67
+ get token0(): ERC20Token;
68
+ get token1(): ERC20Token;
69
+ get reserve0(): CurrencyAmount<ERC20Token>;
70
+ get reserve1(): CurrencyAmount<ERC20Token>;
71
+ reserveOf(token: ERC20Token): CurrencyAmount<ERC20Token>;
72
+ getOutputAmount(inputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair];
73
+ getInputAmount(outputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair];
74
+ getLiquidityMinted(totalSupply: CurrencyAmount<ERC20Token>, tokenAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>): CurrencyAmount<ERC20Token>;
75
+ getLiquidityValue(token: ERC20Token, totalSupply: CurrencyAmount<ERC20Token>, liquidity: CurrencyAmount<ERC20Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<ERC20Token>;
314
76
  }
315
77
 
316
78
  declare class Route<TInput extends Currency, TOutput extends Currency> {
@@ -504,12 +266,4 @@ declare abstract class Router {
504
266
  static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters;
505
267
  }
506
268
 
507
- /**
508
- * Returns the percent difference between the mid price and the execution price, i.e. price impact.
509
- * @param midPrice mid price before the trade
510
- * @param inputAmount the input amount of the trade
511
- * @param outputAmount the output amount of the trade
512
- */
513
- declare function computePriceImpact<TBase extends Currency, TQuote extends Currency>(midPrice: Price<TBase, TQuote>, inputAmount: CurrencyAmount<TBase>, outputAmount: CurrencyAmount<TQuote>): Percent;
514
-
515
- export { BaseCurrency, BestTradeOptions, BigintIsh, ChainId, Currency, CurrencyAmount, FACTORY_ADDRESS, FACTORY_ADDRESS_MAP, FIVE, Fraction, INIT_CODE_HASH, INIT_CODE_HASH_MAP, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, MaxUint256, NATIVE, Native, NativeCurrency, ONE, Pair, Percent, Price, Rounding, Route, Router, SOLIDITY_TYPE_MAXIMA, SerializedToken, SolidityType, SwapParameters, TEN, THREE, TWO, Token, Trade, TradeOptions, TradeOptionsDeadline, TradeType, WBNB, WETH9, WNATIVE, ZERO, _100, _10000, _9975, computePairAddress, computePriceImpact, inputOutputComparator, tradeComparator };
269
+ export { BestTradeOptions, ChainId, ERC20Token, FACTORY_ADDRESS, FACTORY_ADDRESS_MAP, INIT_CODE_HASH, INIT_CODE_HASH_MAP, NATIVE, Native, Pair, Route, Router, SwapParameters, Trade, TradeOptions, TradeOptionsDeadline, WBNB, WETH9, WNATIVE, computePairAddress, inputOutputComparator, tradeComparator };