@pancakeswap/sdk 3.1.5 → 3.2.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/index.mjs CHANGED
@@ -1,23 +1,23 @@
1
- // src/index.ts
2
- import JSBI2 from "jsbi";
3
-
4
- // src/constants.ts
5
- import { Percent } from "@pancakeswap/swap-sdk-core";
6
-
7
- // src/entities/token.ts
8
- import { Token } from "@pancakeswap/swap-sdk-core";
1
+ import JSBI from 'jsbi';
2
+ export { default as JSBI } from 'jsbi';
3
+ import { Percent, Token, Price, ZERO, InsufficientReservesError, _9975, _10000, CurrencyAmount, InsufficientInputAmountError, ONE, sqrt, MINIMUM_LIQUIDITY, FIVE, TradeType, computePriceImpact, Fraction, sortedInsert, NativeCurrency } from '@pancakeswap/swap-sdk-core';
4
+ export * from '@pancakeswap/swap-sdk-core';
5
+ import { getAddress, getCreate2Address } from '@ethersproject/address';
6
+ import invariant4 from 'tiny-invariant';
7
+ import warning from 'tiny-warning';
8
+ import { keccak256, pack } from '@ethersproject/solidity';
9
+ import { Contract } from '@ethersproject/contracts';
10
+ import { getNetwork } from '@ethersproject/networks';
11
+ import { getDefaultProvider } from '@ethersproject/providers';
9
12
 
10
- // src/utils.ts
11
- import { getAddress } from "@ethersproject/address";
12
- import invariant from "tiny-invariant";
13
- import warning from "tiny-warning";
13
+ // src/index.ts
14
14
  function validateAndParseAddress(address) {
15
15
  try {
16
16
  const checksummedAddress = getAddress(address);
17
17
  warning(address === checksummedAddress, `${address} is not checksummed.`);
18
18
  return checksummedAddress;
19
19
  } catch (error) {
20
- invariant(false, `${address} is not a valid address.`);
20
+ invariant4(false, `${address} is not a valid address.`);
21
21
  }
22
22
  }
23
23
 
@@ -29,12 +29,12 @@ var ERC20Token = class extends Token {
29
29
  };
30
30
 
31
31
  // src/constants.ts
32
- var ChainId = /* @__PURE__ */ ((ChainId2) => {
33
- ChainId2[ChainId2["ETHEREUM"] = 1] = "ETHEREUM";
34
- ChainId2[ChainId2["GOERLI"] = 5] = "GOERLI";
35
- ChainId2[ChainId2["BSC"] = 56] = "BSC";
36
- ChainId2[ChainId2["BSC_TESTNET"] = 97] = "BSC_TESTNET";
37
- return ChainId2;
32
+ var ChainId = /* @__PURE__ */ ((ChainId3) => {
33
+ ChainId3[ChainId3["ETHEREUM"] = 1] = "ETHEREUM";
34
+ ChainId3[ChainId3["GOERLI"] = 5] = "GOERLI";
35
+ ChainId3[ChainId3["BSC"] = 56] = "BSC";
36
+ ChainId3[ChainId3["BSC_TESTNET"] = 97] = "BSC_TESTNET";
37
+ return ChainId3;
38
38
  })(ChainId || {});
39
39
  var ZERO_PERCENT = new Percent("0");
40
40
  var ONE_HUNDRED_PERCENT = new Percent("1");
@@ -70,6 +70,22 @@ var WETH9 = {
70
70
  "WETH",
71
71
  "Wrapped Ether",
72
72
  "https://weth.io"
73
+ ),
74
+ [56 /* BSC */]: new ERC20Token(
75
+ 56 /* BSC */,
76
+ "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
77
+ 18,
78
+ "ETH",
79
+ "Binance-Peg Ethereum Token",
80
+ "https://ethereum.org"
81
+ ),
82
+ [97 /* BSC_TESTNET */]: new ERC20Token(
83
+ 56 /* BSC */,
84
+ "0xE7bCB9e341D546b66a46298f4893f5650a56e99E",
85
+ 18,
86
+ "ETH",
87
+ "ETH",
88
+ "https://ethereum.org"
73
89
  )
74
90
  };
75
91
  var WBNB = {
@@ -135,25 +151,6 @@ function isTradeBetter(tradeA, tradeB, minimumDelta = ZERO_PERCENT) {
135
151
  }
136
152
  return tradeA.executionPrice.asFraction.multiply(minimumDelta.add(ONE_HUNDRED_PERCENT)).lessThan(tradeB.executionPrice);
137
153
  }
138
-
139
- // src/entities/pair.ts
140
- import {
141
- InsufficientInputAmountError,
142
- InsufficientReservesError,
143
- sqrt,
144
- CurrencyAmount,
145
- Price,
146
- FIVE,
147
- ONE,
148
- ZERO,
149
- _10000,
150
- _9975,
151
- MINIMUM_LIQUIDITY
152
- } from "@pancakeswap/swap-sdk-core";
153
- import { getCreate2Address } from "@ethersproject/address";
154
- import { keccak256, pack } from "@ethersproject/solidity";
155
- import JSBI from "jsbi";
156
- import invariant2 from "tiny-invariant";
157
154
  var PAIR_ADDRESS_CACHE = {};
158
155
  var composeKey = (token0, token1) => `${token0.chainId}-${token0.address}-${token1.address}`;
159
156
  var computePairAddress = ({
@@ -216,7 +213,7 @@ var Pair = class {
216
213
  * @param token token to return price of
217
214
  */
218
215
  priceOf(token) {
219
- invariant2(this.involvesToken(token), "TOKEN");
216
+ invariant4(this.involvesToken(token), "TOKEN");
220
217
  return token.equals(this.token0) ? this.token0Price : this.token1Price;
221
218
  }
222
219
  /**
@@ -238,11 +235,11 @@ var Pair = class {
238
235
  return this.tokenAmounts[1];
239
236
  }
240
237
  reserveOf(token) {
241
- invariant2(this.involvesToken(token), "TOKEN");
238
+ invariant4(this.involvesToken(token), "TOKEN");
242
239
  return token.equals(this.token0) ? this.reserve0 : this.reserve1;
243
240
  }
244
241
  getOutputAmount(inputAmount) {
245
- invariant2(this.involvesToken(inputAmount.currency), "TOKEN");
242
+ invariant4(this.involvesToken(inputAmount.currency), "TOKEN");
246
243
  if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {
247
244
  throw new InsufficientReservesError();
248
245
  }
@@ -261,7 +258,7 @@ var Pair = class {
261
258
  return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
262
259
  }
263
260
  getInputAmount(outputAmount) {
264
- invariant2(this.involvesToken(outputAmount.currency), "TOKEN");
261
+ invariant4(this.involvesToken(outputAmount.currency), "TOKEN");
265
262
  if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient)) {
266
263
  throw new InsufficientReservesError();
267
264
  }
@@ -276,9 +273,9 @@ var Pair = class {
276
273
  return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
277
274
  }
278
275
  getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) {
279
- invariant2(totalSupply.currency.equals(this.liquidityToken), "LIQUIDITY");
276
+ invariant4(totalSupply.currency.equals(this.liquidityToken), "LIQUIDITY");
280
277
  const tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) ? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
281
- invariant2(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), "TOKEN");
278
+ invariant4(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), "TOKEN");
282
279
  let liquidity;
283
280
  if (JSBI.equal(totalSupply.quotient, ZERO)) {
284
281
  liquidity = JSBI.subtract(
@@ -296,15 +293,15 @@ var Pair = class {
296
293
  return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity);
297
294
  }
298
295
  getLiquidityValue(token, totalSupply, liquidity, feeOn = false, kLast) {
299
- invariant2(this.involvesToken(token), "TOKEN");
300
- invariant2(totalSupply.currency.equals(this.liquidityToken), "TOTAL_SUPPLY");
301
- invariant2(liquidity.currency.equals(this.liquidityToken), "LIQUIDITY");
302
- invariant2(JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), "LIQUIDITY");
296
+ invariant4(this.involvesToken(token), "TOKEN");
297
+ invariant4(totalSupply.currency.equals(this.liquidityToken), "TOTAL_SUPPLY");
298
+ invariant4(liquidity.currency.equals(this.liquidityToken), "LIQUIDITY");
299
+ invariant4(JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), "LIQUIDITY");
303
300
  let totalSupplyAdjusted;
304
301
  if (!feeOn) {
305
302
  totalSupplyAdjusted = totalSupply;
306
303
  } else {
307
- invariant2(!!kLast, "K_LAST");
304
+ invariant4(!!kLast, "K_LAST");
308
305
  const kLastParsed = JSBI.BigInt(kLast);
309
306
  if (!JSBI.equal(kLastParsed, ZERO)) {
310
307
  const rootK = sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient));
@@ -327,26 +324,22 @@ var Pair = class {
327
324
  );
328
325
  }
329
326
  };
330
-
331
- // src/entities/route.ts
332
- import invariant3 from "tiny-invariant";
333
- import { Price as Price2 } from "@pancakeswap/swap-sdk-core";
334
327
  var Route = class {
335
328
  constructor(pairs, input, output) {
336
329
  this._midPrice = null;
337
- invariant3(pairs.length > 0, "PAIRS");
330
+ invariant4(pairs.length > 0, "PAIRS");
338
331
  const chainId = pairs[0].chainId;
339
- invariant3(
332
+ invariant4(
340
333
  pairs.every((pair) => pair.chainId === chainId),
341
334
  "CHAIN_IDS"
342
335
  );
343
336
  const wrappedInput = input.wrapped;
344
- invariant3(pairs[0].involvesToken(wrappedInput), "INPUT");
345
- invariant3(typeof output === "undefined" || pairs[pairs.length - 1].involvesToken(output.wrapped), "OUTPUT");
337
+ invariant4(pairs[0].involvesToken(wrappedInput), "INPUT");
338
+ invariant4(typeof output === "undefined" || pairs[pairs.length - 1].involvesToken(output.wrapped), "OUTPUT");
346
339
  const path = [wrappedInput];
347
340
  for (const [i, pair] of pairs.entries()) {
348
341
  const currentInput = path[i];
349
- invariant3(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), "PATH");
342
+ invariant4(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), "PATH");
350
343
  const output2 = currentInput.equals(pair.token0) ? pair.token1 : pair.token0;
351
344
  path.push(output2);
352
345
  }
@@ -361,29 +354,16 @@ var Route = class {
361
354
  const prices = [];
362
355
  for (const [i, pair] of this.pairs.entries()) {
363
356
  prices.push(
364
- this.path[i].equals(pair.token0) ? new Price2(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient) : new Price2(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient)
357
+ this.path[i].equals(pair.token0) ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient) : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient)
365
358
  );
366
359
  }
367
360
  const reduced = prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0]);
368
- return this._midPrice = new Price2(this.input, this.output, reduced.denominator, reduced.numerator);
361
+ return this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator);
369
362
  }
370
363
  get chainId() {
371
364
  return this.pairs[0].chainId;
372
365
  }
373
366
  };
374
-
375
- // src/entities/trade.ts
376
- import invariant4 from "tiny-invariant";
377
- import {
378
- ONE as ONE2,
379
- TradeType,
380
- ZERO as ZERO2,
381
- CurrencyAmount as CurrencyAmount2,
382
- Fraction,
383
- Price as Price3,
384
- sortedInsert,
385
- computePriceImpact
386
- } from "@pancakeswap/swap-sdk-core";
387
367
  function inputOutputComparator(a, b) {
388
368
  invariant4(a.inputAmount.currency.equals(b.inputAmount.currency), "INPUT_CURRENCY");
389
369
  invariant4(a.outputAmount.currency.equals(b.outputAmount.currency), "OUTPUT_CURRENCY");
@@ -443,8 +423,8 @@ var Trade = class {
443
423
  const [outputAmount] = pair.getOutputAmount(tokenAmounts[i]);
444
424
  tokenAmounts[i + 1] = outputAmount;
445
425
  }
446
- this.inputAmount = CurrencyAmount2.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
447
- this.outputAmount = CurrencyAmount2.fromFractionalAmount(
426
+ this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
427
+ this.outputAmount = CurrencyAmount.fromFractionalAmount(
448
428
  route.output,
449
429
  tokenAmounts[tokenAmounts.length - 1].numerator,
450
430
  tokenAmounts[tokenAmounts.length - 1].denominator
@@ -457,14 +437,14 @@ var Trade = class {
457
437
  const [inputAmount] = pair.getInputAmount(tokenAmounts[i]);
458
438
  tokenAmounts[i - 1] = inputAmount;
459
439
  }
460
- this.inputAmount = CurrencyAmount2.fromFractionalAmount(
440
+ this.inputAmount = CurrencyAmount.fromFractionalAmount(
461
441
  route.input,
462
442
  tokenAmounts[0].numerator,
463
443
  tokenAmounts[0].denominator
464
444
  );
465
- this.outputAmount = CurrencyAmount2.fromFractionalAmount(route.output, amount.numerator, amount.denominator);
445
+ this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator);
466
446
  }
467
- this.executionPrice = new Price3(
447
+ this.executionPrice = new Price(
468
448
  this.inputAmount.currency,
469
449
  this.outputAmount.currency,
470
450
  this.inputAmount.quotient,
@@ -477,24 +457,24 @@ var Trade = class {
477
457
  * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
478
458
  */
479
459
  minimumAmountOut(slippageTolerance) {
480
- invariant4(!slippageTolerance.lessThan(ZERO2), "SLIPPAGE_TOLERANCE");
460
+ invariant4(!slippageTolerance.lessThan(ZERO), "SLIPPAGE_TOLERANCE");
481
461
  if (this.tradeType === TradeType.EXACT_OUTPUT) {
482
462
  return this.outputAmount;
483
463
  }
484
- const slippageAdjustedAmountOut = new Fraction(ONE2).add(slippageTolerance).invert().multiply(this.outputAmount.quotient).quotient;
485
- return CurrencyAmount2.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut);
464
+ const slippageAdjustedAmountOut = new Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.quotient).quotient;
465
+ return CurrencyAmount.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut);
486
466
  }
487
467
  /**
488
468
  * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
489
469
  * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
490
470
  */
491
471
  maximumAmountIn(slippageTolerance) {
492
- invariant4(!slippageTolerance.lessThan(ZERO2), "SLIPPAGE_TOLERANCE");
472
+ invariant4(!slippageTolerance.lessThan(ZERO), "SLIPPAGE_TOLERANCE");
493
473
  if (this.tradeType === TradeType.EXACT_INPUT) {
494
474
  return this.inputAmount;
495
475
  }
496
- const slippageAdjustedAmountIn = new Fraction(ONE2).add(slippageTolerance).multiply(this.inputAmount.quotient).quotient;
497
- return CurrencyAmount2.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn);
476
+ const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.quotient).quotient;
477
+ return CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn);
498
478
  }
499
479
  /**
500
480
  * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
@@ -520,7 +500,7 @@ var Trade = class {
520
500
  const pair = pairs[i];
521
501
  if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency))
522
502
  continue;
523
- if (pair.reserve0.equalTo(ZERO2) || pair.reserve1.equalTo(ZERO2))
503
+ if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO))
524
504
  continue;
525
505
  let amountOut;
526
506
  try {
@@ -566,7 +546,7 @@ var Trade = class {
566
546
  * @param slippageTolerance the allowed tolerated slippage
567
547
  */
568
548
  worstExecutionPrice(slippageTolerance) {
569
- return new Price3(
549
+ return new Price(
570
550
  this.inputAmount.currency,
571
551
  this.outputAmount.currency,
572
552
  this.maximumAmountIn(slippageTolerance).quotient,
@@ -598,7 +578,7 @@ var Trade = class {
598
578
  const pair = pairs[i];
599
579
  if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency))
600
580
  continue;
601
- if (pair.reserve0.equalTo(ZERO2) || pair.reserve1.equalTo(ZERO2))
581
+ if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO))
602
582
  continue;
603
583
  let amountIn;
604
584
  try {
@@ -640,10 +620,6 @@ var Trade = class {
640
620
  return bestTrades;
641
621
  }
642
622
  };
643
-
644
- // src/entities/native.ts
645
- import invariant5 from "tiny-invariant";
646
- import { NativeCurrency } from "@pancakeswap/swap-sdk-core";
647
623
  var _Native = class extends NativeCurrency {
648
624
  constructor({
649
625
  chainId,
@@ -655,14 +631,14 @@ var _Native = class extends NativeCurrency {
655
631
  }
656
632
  get wrapped() {
657
633
  const wnative = WNATIVE[this.chainId];
658
- invariant5(!!wnative, "WRAPPED");
634
+ invariant4(!!wnative, "WRAPPED");
659
635
  return wnative;
660
636
  }
661
637
  static onChain(chainId) {
662
638
  if (chainId in this.cache) {
663
639
  return this.cache[chainId];
664
640
  }
665
- invariant5(!!NATIVE[chainId], "NATIVE_CURRENCY");
641
+ invariant4(!!NATIVE[chainId], "NATIVE_CURRENCY");
666
642
  const { decimals, name, symbol } = NATIVE[chainId];
667
643
  return this.cache[chainId] = new _Native({ chainId, decimals, symbol, name });
668
644
  }
@@ -672,20 +648,11 @@ var _Native = class extends NativeCurrency {
672
648
  };
673
649
  var Native = _Native;
674
650
  Native.cache = {};
675
-
676
- // src/router.ts
677
- import { TradeType as TradeType2 } from "@pancakeswap/swap-sdk-core";
678
- import invariant6 from "tiny-invariant";
679
651
  function toHex(currencyAmount) {
680
652
  return `0x${currencyAmount.quotient.toString(16)}`;
681
653
  }
682
654
  var ZERO_HEX = "0x0";
683
655
  var Router = class {
684
- /**
685
- * Cannot be constructed.
686
- */
687
- constructor() {
688
- }
689
656
  /**
690
657
  * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
691
658
  * @param trade to produce call parameters for
@@ -694,19 +661,19 @@ var Router = class {
694
661
  static swapCallParameters(trade, options) {
695
662
  const etherIn = trade.inputAmount.currency.isNative;
696
663
  const etherOut = trade.outputAmount.currency.isNative;
697
- invariant6(!(etherIn && etherOut), "ETHER_IN_OUT");
698
- invariant6(!("ttl" in options) || options.ttl > 0, "TTL");
664
+ invariant4(!(etherIn && etherOut), "ETHER_IN_OUT");
665
+ invariant4(!("ttl" in options) || options.ttl > 0, "TTL");
699
666
  const to = validateAndParseAddress(options.recipient);
700
667
  const amountIn = toHex(trade.maximumAmountIn(options.allowedSlippage));
701
668
  const amountOut = toHex(trade.minimumAmountOut(options.allowedSlippage));
702
669
  const path = trade.route.path.map((token) => token.address);
703
- const deadline = "ttl" in options ? `0x${(Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) + options.ttl).toString(16)}` : `0x${options.deadline.toString(16)}`;
670
+ const deadline = "ttl" in options ? `0x${(Math.floor(( new Date()).getTime() / 1e3) + options.ttl).toString(16)}` : `0x${options.deadline.toString(16)}`;
704
671
  const useFeeOnTransfer = Boolean(options.feeOnTransfer);
705
672
  let methodName;
706
673
  let args;
707
674
  let value;
708
675
  switch (trade.tradeType) {
709
- case TradeType2.EXACT_INPUT:
676
+ case TradeType.EXACT_INPUT:
710
677
  if (etherIn) {
711
678
  methodName = useFeeOnTransfer ? "swapExactETHForTokensSupportingFeeOnTransferTokens" : "swapExactETHForTokens";
712
679
  args = [amountOut, path, to, deadline];
@@ -721,8 +688,8 @@ var Router = class {
721
688
  value = ZERO_HEX;
722
689
  }
723
690
  break;
724
- case TradeType2.EXACT_OUTPUT:
725
- invariant6(!useFeeOnTransfer, "EXACT_OUT_FOT");
691
+ case TradeType.EXACT_OUTPUT:
692
+ invariant4(!useFeeOnTransfer, "EXACT_OUT_FOT");
726
693
  if (etherIn) {
727
694
  methodName = "swapETHForExactTokens";
728
695
  args = [amountOut, path, to, deadline];
@@ -745,30 +712,808 @@ var Router = class {
745
712
  };
746
713
  }
747
714
  };
715
+ var _Ether = class extends NativeCurrency {
716
+ constructor(chainId) {
717
+ super(chainId, 18, "ETH", "Ether");
718
+ }
719
+ get wrapped() {
720
+ const weth9 = WETH9[this.chainId];
721
+ invariant4(!!weth9, "WRAPPED");
722
+ return weth9;
723
+ }
724
+ static onChain(chainId) {
725
+ if (!this._etherCache[chainId]) {
726
+ this._etherCache[chainId] = new _Ether(chainId);
727
+ }
728
+ return this._etherCache[chainId];
729
+ }
730
+ equals(other) {
731
+ return other.isNative && other.chainId === this.chainId;
732
+ }
733
+ };
734
+ var Ether = _Ether;
735
+ Ether._etherCache = {};
748
736
 
749
- // src/index.ts
750
- export * from "@pancakeswap/swap-sdk-core";
751
- export {
752
- ChainId,
753
- ERC20Token,
754
- FACTORY_ADDRESS,
755
- FACTORY_ADDRESS_MAP,
756
- INIT_CODE_HASH,
757
- INIT_CODE_HASH_MAP,
758
- JSBI2 as JSBI,
759
- NATIVE,
760
- Native,
761
- ONE_HUNDRED_PERCENT,
762
- Pair,
763
- Route,
764
- Router,
765
- Trade,
766
- WBNB,
767
- WETH9,
768
- WNATIVE,
769
- ZERO_PERCENT,
770
- computePairAddress,
771
- inputOutputComparator,
772
- isTradeBetter,
773
- tradeComparator
737
+ // src/abis/ERC20.json
738
+ var ERC20_default = [
739
+ {
740
+ constant: true,
741
+ inputs: [],
742
+ name: "decimals",
743
+ outputs: [{ name: "", type: "uint8" }],
744
+ payable: false,
745
+ stateMutability: "view",
746
+ type: "function"
747
+ },
748
+ {
749
+ constant: true,
750
+ inputs: [{ name: "", type: "address" }],
751
+ name: "balanceOf",
752
+ outputs: [{ name: "", type: "uint256" }],
753
+ payable: false,
754
+ stateMutability: "view",
755
+ type: "function"
756
+ }
757
+ ];
758
+
759
+ // src/abis/IPancakePair.json
760
+ var IPancakePair_default = [
761
+ {
762
+ anonymous: false,
763
+ inputs: [
764
+ {
765
+ indexed: true,
766
+ internalType: "address",
767
+ name: "owner",
768
+ type: "address"
769
+ },
770
+ {
771
+ indexed: true,
772
+ internalType: "address",
773
+ name: "spender",
774
+ type: "address"
775
+ },
776
+ {
777
+ indexed: false,
778
+ internalType: "uint256",
779
+ name: "value",
780
+ type: "uint256"
781
+ }
782
+ ],
783
+ name: "Approval",
784
+ type: "event"
785
+ },
786
+ {
787
+ anonymous: false,
788
+ inputs: [
789
+ {
790
+ indexed: true,
791
+ internalType: "address",
792
+ name: "sender",
793
+ type: "address"
794
+ },
795
+ {
796
+ indexed: false,
797
+ internalType: "uint256",
798
+ name: "amount0",
799
+ type: "uint256"
800
+ },
801
+ {
802
+ indexed: false,
803
+ internalType: "uint256",
804
+ name: "amount1",
805
+ type: "uint256"
806
+ },
807
+ {
808
+ indexed: true,
809
+ internalType: "address",
810
+ name: "to",
811
+ type: "address"
812
+ }
813
+ ],
814
+ name: "Burn",
815
+ type: "event"
816
+ },
817
+ {
818
+ anonymous: false,
819
+ inputs: [
820
+ {
821
+ indexed: true,
822
+ internalType: "address",
823
+ name: "sender",
824
+ type: "address"
825
+ },
826
+ {
827
+ indexed: false,
828
+ internalType: "uint256",
829
+ name: "amount0",
830
+ type: "uint256"
831
+ },
832
+ {
833
+ indexed: false,
834
+ internalType: "uint256",
835
+ name: "amount1",
836
+ type: "uint256"
837
+ }
838
+ ],
839
+ name: "Mint",
840
+ type: "event"
841
+ },
842
+ {
843
+ anonymous: false,
844
+ inputs: [
845
+ {
846
+ indexed: true,
847
+ internalType: "address",
848
+ name: "sender",
849
+ type: "address"
850
+ },
851
+ {
852
+ indexed: false,
853
+ internalType: "uint256",
854
+ name: "amount0In",
855
+ type: "uint256"
856
+ },
857
+ {
858
+ indexed: false,
859
+ internalType: "uint256",
860
+ name: "amount1In",
861
+ type: "uint256"
862
+ },
863
+ {
864
+ indexed: false,
865
+ internalType: "uint256",
866
+ name: "amount0Out",
867
+ type: "uint256"
868
+ },
869
+ {
870
+ indexed: false,
871
+ internalType: "uint256",
872
+ name: "amount1Out",
873
+ type: "uint256"
874
+ },
875
+ {
876
+ indexed: true,
877
+ internalType: "address",
878
+ name: "to",
879
+ type: "address"
880
+ }
881
+ ],
882
+ name: "Swap",
883
+ type: "event"
884
+ },
885
+ {
886
+ anonymous: false,
887
+ inputs: [
888
+ {
889
+ indexed: false,
890
+ internalType: "uint112",
891
+ name: "reserve0",
892
+ type: "uint112"
893
+ },
894
+ {
895
+ indexed: false,
896
+ internalType: "uint112",
897
+ name: "reserve1",
898
+ type: "uint112"
899
+ }
900
+ ],
901
+ name: "Sync",
902
+ type: "event"
903
+ },
904
+ {
905
+ anonymous: false,
906
+ inputs: [
907
+ {
908
+ indexed: true,
909
+ internalType: "address",
910
+ name: "from",
911
+ type: "address"
912
+ },
913
+ {
914
+ indexed: true,
915
+ internalType: "address",
916
+ name: "to",
917
+ type: "address"
918
+ },
919
+ {
920
+ indexed: false,
921
+ internalType: "uint256",
922
+ name: "value",
923
+ type: "uint256"
924
+ }
925
+ ],
926
+ name: "Transfer",
927
+ type: "event"
928
+ },
929
+ {
930
+ constant: true,
931
+ inputs: [],
932
+ name: "DOMAIN_SEPARATOR",
933
+ outputs: [
934
+ {
935
+ internalType: "bytes32",
936
+ name: "",
937
+ type: "bytes32"
938
+ }
939
+ ],
940
+ payable: false,
941
+ stateMutability: "view",
942
+ type: "function"
943
+ },
944
+ {
945
+ constant: true,
946
+ inputs: [],
947
+ name: "MINIMUM_LIQUIDITY",
948
+ outputs: [
949
+ {
950
+ internalType: "uint256",
951
+ name: "",
952
+ type: "uint256"
953
+ }
954
+ ],
955
+ payable: false,
956
+ stateMutability: "pure",
957
+ type: "function"
958
+ },
959
+ {
960
+ constant: true,
961
+ inputs: [],
962
+ name: "PERMIT_TYPEHASH",
963
+ outputs: [
964
+ {
965
+ internalType: "bytes32",
966
+ name: "",
967
+ type: "bytes32"
968
+ }
969
+ ],
970
+ payable: false,
971
+ stateMutability: "pure",
972
+ type: "function"
973
+ },
974
+ {
975
+ constant: true,
976
+ inputs: [
977
+ {
978
+ internalType: "address",
979
+ name: "owner",
980
+ type: "address"
981
+ },
982
+ {
983
+ internalType: "address",
984
+ name: "spender",
985
+ type: "address"
986
+ }
987
+ ],
988
+ name: "allowance",
989
+ outputs: [
990
+ {
991
+ internalType: "uint256",
992
+ name: "",
993
+ type: "uint256"
994
+ }
995
+ ],
996
+ payable: false,
997
+ stateMutability: "view",
998
+ type: "function"
999
+ },
1000
+ {
1001
+ constant: false,
1002
+ inputs: [
1003
+ {
1004
+ internalType: "address",
1005
+ name: "spender",
1006
+ type: "address"
1007
+ },
1008
+ {
1009
+ internalType: "uint256",
1010
+ name: "value",
1011
+ type: "uint256"
1012
+ }
1013
+ ],
1014
+ name: "approve",
1015
+ outputs: [
1016
+ {
1017
+ internalType: "bool",
1018
+ name: "",
1019
+ type: "bool"
1020
+ }
1021
+ ],
1022
+ payable: false,
1023
+ stateMutability: "nonpayable",
1024
+ type: "function"
1025
+ },
1026
+ {
1027
+ constant: true,
1028
+ inputs: [
1029
+ {
1030
+ internalType: "address",
1031
+ name: "owner",
1032
+ type: "address"
1033
+ }
1034
+ ],
1035
+ name: "balanceOf",
1036
+ outputs: [
1037
+ {
1038
+ internalType: "uint256",
1039
+ name: "",
1040
+ type: "uint256"
1041
+ }
1042
+ ],
1043
+ payable: false,
1044
+ stateMutability: "view",
1045
+ type: "function"
1046
+ },
1047
+ {
1048
+ constant: false,
1049
+ inputs: [
1050
+ {
1051
+ internalType: "address",
1052
+ name: "to",
1053
+ type: "address"
1054
+ }
1055
+ ],
1056
+ name: "burn",
1057
+ outputs: [
1058
+ {
1059
+ internalType: "uint256",
1060
+ name: "amount0",
1061
+ type: "uint256"
1062
+ },
1063
+ {
1064
+ internalType: "uint256",
1065
+ name: "amount1",
1066
+ type: "uint256"
1067
+ }
1068
+ ],
1069
+ payable: false,
1070
+ stateMutability: "nonpayable",
1071
+ type: "function"
1072
+ },
1073
+ {
1074
+ constant: true,
1075
+ inputs: [],
1076
+ name: "decimals",
1077
+ outputs: [
1078
+ {
1079
+ internalType: "uint8",
1080
+ name: "",
1081
+ type: "uint8"
1082
+ }
1083
+ ],
1084
+ payable: false,
1085
+ stateMutability: "pure",
1086
+ type: "function"
1087
+ },
1088
+ {
1089
+ constant: true,
1090
+ inputs: [],
1091
+ name: "factory",
1092
+ outputs: [
1093
+ {
1094
+ internalType: "address",
1095
+ name: "",
1096
+ type: "address"
1097
+ }
1098
+ ],
1099
+ payable: false,
1100
+ stateMutability: "view",
1101
+ type: "function"
1102
+ },
1103
+ {
1104
+ constant: true,
1105
+ inputs: [],
1106
+ name: "getReserves",
1107
+ outputs: [
1108
+ {
1109
+ internalType: "uint112",
1110
+ name: "reserve0",
1111
+ type: "uint112"
1112
+ },
1113
+ {
1114
+ internalType: "uint112",
1115
+ name: "reserve1",
1116
+ type: "uint112"
1117
+ },
1118
+ {
1119
+ internalType: "uint32",
1120
+ name: "blockTimestampLast",
1121
+ type: "uint32"
1122
+ }
1123
+ ],
1124
+ payable: false,
1125
+ stateMutability: "view",
1126
+ type: "function"
1127
+ },
1128
+ {
1129
+ constant: false,
1130
+ inputs: [
1131
+ {
1132
+ internalType: "address",
1133
+ name: "",
1134
+ type: "address"
1135
+ },
1136
+ {
1137
+ internalType: "address",
1138
+ name: "",
1139
+ type: "address"
1140
+ }
1141
+ ],
1142
+ name: "initialize",
1143
+ outputs: [],
1144
+ payable: false,
1145
+ stateMutability: "nonpayable",
1146
+ type: "function"
1147
+ },
1148
+ {
1149
+ constant: true,
1150
+ inputs: [],
1151
+ name: "kLast",
1152
+ outputs: [
1153
+ {
1154
+ internalType: "uint256",
1155
+ name: "",
1156
+ type: "uint256"
1157
+ }
1158
+ ],
1159
+ payable: false,
1160
+ stateMutability: "view",
1161
+ type: "function"
1162
+ },
1163
+ {
1164
+ constant: false,
1165
+ inputs: [
1166
+ {
1167
+ internalType: "address",
1168
+ name: "to",
1169
+ type: "address"
1170
+ }
1171
+ ],
1172
+ name: "mint",
1173
+ outputs: [
1174
+ {
1175
+ internalType: "uint256",
1176
+ name: "liquidity",
1177
+ type: "uint256"
1178
+ }
1179
+ ],
1180
+ payable: false,
1181
+ stateMutability: "nonpayable",
1182
+ type: "function"
1183
+ },
1184
+ {
1185
+ constant: true,
1186
+ inputs: [],
1187
+ name: "name",
1188
+ outputs: [
1189
+ {
1190
+ internalType: "string",
1191
+ name: "",
1192
+ type: "string"
1193
+ }
1194
+ ],
1195
+ payable: false,
1196
+ stateMutability: "pure",
1197
+ type: "function"
1198
+ },
1199
+ {
1200
+ constant: true,
1201
+ inputs: [
1202
+ {
1203
+ internalType: "address",
1204
+ name: "owner",
1205
+ type: "address"
1206
+ }
1207
+ ],
1208
+ name: "nonces",
1209
+ outputs: [
1210
+ {
1211
+ internalType: "uint256",
1212
+ name: "",
1213
+ type: "uint256"
1214
+ }
1215
+ ],
1216
+ payable: false,
1217
+ stateMutability: "view",
1218
+ type: "function"
1219
+ },
1220
+ {
1221
+ constant: false,
1222
+ inputs: [
1223
+ {
1224
+ internalType: "address",
1225
+ name: "owner",
1226
+ type: "address"
1227
+ },
1228
+ {
1229
+ internalType: "address",
1230
+ name: "spender",
1231
+ type: "address"
1232
+ },
1233
+ {
1234
+ internalType: "uint256",
1235
+ name: "value",
1236
+ type: "uint256"
1237
+ },
1238
+ {
1239
+ internalType: "uint256",
1240
+ name: "deadline",
1241
+ type: "uint256"
1242
+ },
1243
+ {
1244
+ internalType: "uint8",
1245
+ name: "v",
1246
+ type: "uint8"
1247
+ },
1248
+ {
1249
+ internalType: "bytes32",
1250
+ name: "r",
1251
+ type: "bytes32"
1252
+ },
1253
+ {
1254
+ internalType: "bytes32",
1255
+ name: "s",
1256
+ type: "bytes32"
1257
+ }
1258
+ ],
1259
+ name: "permit",
1260
+ outputs: [],
1261
+ payable: false,
1262
+ stateMutability: "nonpayable",
1263
+ type: "function"
1264
+ },
1265
+ {
1266
+ constant: true,
1267
+ inputs: [],
1268
+ name: "price0CumulativeLast",
1269
+ outputs: [
1270
+ {
1271
+ internalType: "uint256",
1272
+ name: "",
1273
+ type: "uint256"
1274
+ }
1275
+ ],
1276
+ payable: false,
1277
+ stateMutability: "view",
1278
+ type: "function"
1279
+ },
1280
+ {
1281
+ constant: true,
1282
+ inputs: [],
1283
+ name: "price1CumulativeLast",
1284
+ outputs: [
1285
+ {
1286
+ internalType: "uint256",
1287
+ name: "",
1288
+ type: "uint256"
1289
+ }
1290
+ ],
1291
+ payable: false,
1292
+ stateMutability: "view",
1293
+ type: "function"
1294
+ },
1295
+ {
1296
+ constant: false,
1297
+ inputs: [
1298
+ {
1299
+ internalType: "address",
1300
+ name: "to",
1301
+ type: "address"
1302
+ }
1303
+ ],
1304
+ name: "skim",
1305
+ outputs: [],
1306
+ payable: false,
1307
+ stateMutability: "nonpayable",
1308
+ type: "function"
1309
+ },
1310
+ {
1311
+ constant: false,
1312
+ inputs: [
1313
+ {
1314
+ internalType: "uint256",
1315
+ name: "amount0Out",
1316
+ type: "uint256"
1317
+ },
1318
+ {
1319
+ internalType: "uint256",
1320
+ name: "amount1Out",
1321
+ type: "uint256"
1322
+ },
1323
+ {
1324
+ internalType: "address",
1325
+ name: "to",
1326
+ type: "address"
1327
+ },
1328
+ {
1329
+ internalType: "bytes",
1330
+ name: "data",
1331
+ type: "bytes"
1332
+ }
1333
+ ],
1334
+ name: "swap",
1335
+ outputs: [],
1336
+ payable: false,
1337
+ stateMutability: "nonpayable",
1338
+ type: "function"
1339
+ },
1340
+ {
1341
+ constant: true,
1342
+ inputs: [],
1343
+ name: "symbol",
1344
+ outputs: [
1345
+ {
1346
+ internalType: "string",
1347
+ name: "",
1348
+ type: "string"
1349
+ }
1350
+ ],
1351
+ payable: false,
1352
+ stateMutability: "pure",
1353
+ type: "function"
1354
+ },
1355
+ {
1356
+ constant: false,
1357
+ inputs: [],
1358
+ name: "sync",
1359
+ outputs: [],
1360
+ payable: false,
1361
+ stateMutability: "nonpayable",
1362
+ type: "function"
1363
+ },
1364
+ {
1365
+ constant: true,
1366
+ inputs: [],
1367
+ name: "token0",
1368
+ outputs: [
1369
+ {
1370
+ internalType: "address",
1371
+ name: "",
1372
+ type: "address"
1373
+ }
1374
+ ],
1375
+ payable: false,
1376
+ stateMutability: "view",
1377
+ type: "function"
1378
+ },
1379
+ {
1380
+ constant: true,
1381
+ inputs: [],
1382
+ name: "token1",
1383
+ outputs: [
1384
+ {
1385
+ internalType: "address",
1386
+ name: "",
1387
+ type: "address"
1388
+ }
1389
+ ],
1390
+ payable: false,
1391
+ stateMutability: "view",
1392
+ type: "function"
1393
+ },
1394
+ {
1395
+ constant: true,
1396
+ inputs: [],
1397
+ name: "totalSupply",
1398
+ outputs: [
1399
+ {
1400
+ internalType: "uint256",
1401
+ name: "",
1402
+ type: "uint256"
1403
+ }
1404
+ ],
1405
+ payable: false,
1406
+ stateMutability: "view",
1407
+ type: "function"
1408
+ },
1409
+ {
1410
+ constant: false,
1411
+ inputs: [
1412
+ {
1413
+ internalType: "address",
1414
+ name: "to",
1415
+ type: "address"
1416
+ },
1417
+ {
1418
+ internalType: "uint256",
1419
+ name: "value",
1420
+ type: "uint256"
1421
+ }
1422
+ ],
1423
+ name: "transfer",
1424
+ outputs: [
1425
+ {
1426
+ internalType: "bool",
1427
+ name: "",
1428
+ type: "bool"
1429
+ }
1430
+ ],
1431
+ payable: false,
1432
+ stateMutability: "nonpayable",
1433
+ type: "function"
1434
+ },
1435
+ {
1436
+ constant: false,
1437
+ inputs: [
1438
+ {
1439
+ internalType: "address",
1440
+ name: "from",
1441
+ type: "address"
1442
+ },
1443
+ {
1444
+ internalType: "address",
1445
+ name: "to",
1446
+ type: "address"
1447
+ },
1448
+ {
1449
+ internalType: "uint256",
1450
+ name: "value",
1451
+ type: "uint256"
1452
+ }
1453
+ ],
1454
+ name: "transferFrom",
1455
+ outputs: [
1456
+ {
1457
+ internalType: "bool",
1458
+ name: "",
1459
+ type: "bool"
1460
+ }
1461
+ ],
1462
+ payable: false,
1463
+ stateMutability: "nonpayable",
1464
+ type: "function"
1465
+ }
1466
+ ];
1467
+
1468
+ // src/fetcher.ts
1469
+ var TOKEN_DECIMALS_CACHE = {
1470
+ [56 /* BSC */]: {}
1471
+ };
1472
+ var Fetcher = class {
1473
+ /**
1474
+ * Cannot be constructed.
1475
+ */
1476
+ // eslint-disable-next-line no-useless-constructor,@typescript-eslint/no-empty-function
1477
+ constructor() {
1478
+ }
1479
+ /**
1480
+ * Fetch information for a given token on the given chain, using the given ethers provider.
1481
+ * @param chainId chain of the token
1482
+ * @param address address of the token on the chain
1483
+ * @param provider provider used to fetch the token
1484
+ * @param symbol symbol of the token
1485
+ * @param name optional name of the token
1486
+ */
1487
+ static async fetchTokenData(chainId, address, provider = getDefaultProvider(getNetwork(chainId)), symbol, name) {
1488
+ var _a;
1489
+ const parsedDecimals = typeof ((_a = TOKEN_DECIMALS_CACHE == null ? void 0 : TOKEN_DECIMALS_CACHE[chainId]) == null ? void 0 : _a[address]) === "number" ? TOKEN_DECIMALS_CACHE[chainId][address] : await new Contract(address, ERC20_default, provider).decimals().then((decimals) => {
1490
+ TOKEN_DECIMALS_CACHE = {
1491
+ ...TOKEN_DECIMALS_CACHE,
1492
+ [chainId]: {
1493
+ ...TOKEN_DECIMALS_CACHE == null ? void 0 : TOKEN_DECIMALS_CACHE[chainId],
1494
+ [address]: decimals
1495
+ }
1496
+ };
1497
+ return decimals;
1498
+ });
1499
+ return new Token(chainId, address, parsedDecimals, symbol, name);
1500
+ }
1501
+ /**
1502
+ * Fetches information about a pair and constructs a pair from the given two tokens.
1503
+ * @param tokenA first token
1504
+ * @param tokenB second token
1505
+ * @param provider the provider to use to fetch the data
1506
+ */
1507
+ static async fetchPairData(tokenA, tokenB, provider = getDefaultProvider(getNetwork(tokenA.chainId))) {
1508
+ invariant4(tokenA.chainId === tokenB.chainId, "CHAIN_ID");
1509
+ const address = Pair.getAddress(tokenA, tokenB);
1510
+ const [reserves0, reserves1] = await new Contract(address, IPancakePair_default, provider).getReserves();
1511
+ const balances = tokenA.sortsBefore(tokenB) ? [reserves0, reserves1] : [reserves1, reserves0];
1512
+ return new Pair(
1513
+ CurrencyAmount.fromRawAmount(tokenA, balances[0]),
1514
+ CurrencyAmount.fromRawAmount(tokenB, balances[1])
1515
+ );
1516
+ }
774
1517
  };
1518
+
1519
+ export { ChainId, ERC20Token, Ether, FACTORY_ADDRESS, FACTORY_ADDRESS_MAP, Fetcher, INIT_CODE_HASH, INIT_CODE_HASH_MAP, NATIVE, Native, ONE_HUNDRED_PERCENT, Pair, Route, Router, Trade, WBNB, WETH9, WNATIVE, ZERO_PERCENT, computePairAddress, inputOutputComparator, isTradeBetter, tradeComparator, validateAndParseAddress };