@pancakeswap/sdk 3.2.0 → 4.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/index.mjs CHANGED
@@ -1,13 +1,14 @@
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';
1
+ import { Percent, Token, Price, ZERO, InsufficientReservesError, _9975, _10000, CurrencyAmount, InsufficientInputAmountError, ONE, sqrt, MINIMUM_LIQUIDITY, TradeType, computePriceImpact, Fraction, sortedInsert, NativeCurrency, FIVE } from '@pancakeswap/swap-sdk-core';
4
2
  export * from '@pancakeswap/swap-sdk-core';
5
3
  import { getAddress, getCreate2Address } from '@ethersproject/address';
6
4
  import invariant4 from 'tiny-invariant';
7
5
  import warning from 'tiny-warning';
8
6
  import { keccak256, pack } from '@ethersproject/solidity';
7
+ import { Contract } from '@ethersproject/contracts';
8
+ import { getNetwork } from '@ethersproject/networks';
9
+ import { getDefaultProvider } from '@ethersproject/providers';
9
10
 
10
- // src/index.ts
11
+ // src/constants.ts
11
12
  function validateAndParseAddress(address) {
12
13
  try {
13
14
  const checksummedAddress = getAddress(address);
@@ -67,6 +68,22 @@ var WETH9 = {
67
68
  "WETH",
68
69
  "Wrapped Ether",
69
70
  "https://weth.io"
71
+ ),
72
+ [56 /* BSC */]: new ERC20Token(
73
+ 56 /* BSC */,
74
+ "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
75
+ 18,
76
+ "ETH",
77
+ "Binance-Peg Ethereum Token",
78
+ "https://ethereum.org"
79
+ ),
80
+ [97 /* BSC_TESTNET */]: new ERC20Token(
81
+ 56 /* BSC */,
82
+ "0xE7bCB9e341D546b66a46298f4893f5650a56e99E",
83
+ 18,
84
+ "ETH",
85
+ "ETH",
86
+ "https://ethereum.org"
70
87
  )
71
88
  };
72
89
  var WBNB = {
@@ -141,7 +158,7 @@ var computePairAddress = ({
141
158
  }) => {
142
159
  const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA];
143
160
  const key = composeKey(token0, token1);
144
- if ((PAIR_ADDRESS_CACHE == null ? void 0 : PAIR_ADDRESS_CACHE[key]) === void 0) {
161
+ if (PAIR_ADDRESS_CACHE?.[key] === void 0) {
145
162
  PAIR_ADDRESS_CACHE = {
146
163
  ...PAIR_ADDRESS_CACHE,
147
164
  [key]: getCreate2Address(
@@ -221,35 +238,35 @@ var Pair = class {
221
238
  }
222
239
  getOutputAmount(inputAmount) {
223
240
  invariant4(this.involvesToken(inputAmount.currency), "TOKEN");
224
- if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {
241
+ if (this.reserve0.quotient === ZERO || this.reserve1.quotient === ZERO) {
225
242
  throw new InsufficientReservesError();
226
243
  }
227
244
  const inputReserve = this.reserveOf(inputAmount.currency);
228
245
  const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
229
- const inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _9975);
230
- const numerator = JSBI.multiply(inputAmountWithFee, outputReserve.quotient);
231
- const denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _10000), inputAmountWithFee);
246
+ const inputAmountWithFee = inputAmount.quotient * _9975;
247
+ const numerator = inputAmountWithFee * outputReserve.quotient;
248
+ const denominator = inputReserve.quotient * _10000 + inputAmountWithFee;
232
249
  const outputAmount = CurrencyAmount.fromRawAmount(
233
250
  inputAmount.currency.equals(this.token0) ? this.token1 : this.token0,
234
- JSBI.divide(numerator, denominator)
251
+ numerator / denominator
235
252
  );
236
- if (JSBI.equal(outputAmount.quotient, ZERO)) {
253
+ if (outputAmount.quotient === ZERO) {
237
254
  throw new InsufficientInputAmountError();
238
255
  }
239
256
  return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
240
257
  }
241
258
  getInputAmount(outputAmount) {
242
259
  invariant4(this.involvesToken(outputAmount.currency), "TOKEN");
243
- if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient)) {
260
+ if (this.reserve0.quotient === ZERO || this.reserve1.quotient === ZERO || outputAmount.quotient >= this.reserveOf(outputAmount.currency).quotient) {
244
261
  throw new InsufficientReservesError();
245
262
  }
246
263
  const outputReserve = this.reserveOf(outputAmount.currency);
247
264
  const inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
248
- const numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmount.quotient), _10000);
249
- const denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmount.quotient), _9975);
265
+ const numerator = inputReserve.quotient * outputAmount.quotient * _10000;
266
+ const denominator = (outputReserve.quotient - outputAmount.quotient) * _9975;
250
267
  const inputAmount = CurrencyAmount.fromRawAmount(
251
268
  outputAmount.currency.equals(this.token0) ? this.token1 : this.token0,
252
- JSBI.add(JSBI.divide(numerator, denominator), ONE)
269
+ numerator / denominator + ONE
253
270
  );
254
271
  return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
255
272
  }
@@ -258,17 +275,14 @@ var Pair = class {
258
275
  const tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) ? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
259
276
  invariant4(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), "TOKEN");
260
277
  let liquidity;
261
- if (JSBI.equal(totalSupply.quotient, ZERO)) {
262
- liquidity = JSBI.subtract(
263
- sqrt(JSBI.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)),
264
- MINIMUM_LIQUIDITY
265
- );
278
+ if (totalSupply.quotient === ZERO) {
279
+ liquidity = sqrt(tokenAmounts[0].quotient * tokenAmounts[1].quotient) - MINIMUM_LIQUIDITY;
266
280
  } else {
267
- const amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient);
268
- const amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient);
269
- liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1;
281
+ const amount0 = tokenAmounts[0].quotient * totalSupply.quotient / this.reserve0.quotient;
282
+ const amount1 = tokenAmounts[1].quotient * totalSupply.quotient / this.reserve1.quotient;
283
+ liquidity = amount0 <= amount1 ? amount0 : amount1;
270
284
  }
271
- if (!JSBI.greaterThan(liquidity, ZERO)) {
285
+ if (!(liquidity > ZERO)) {
272
286
  throw new InsufficientInputAmountError();
273
287
  }
274
288
  return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity);
@@ -277,20 +291,20 @@ var Pair = class {
277
291
  invariant4(this.involvesToken(token), "TOKEN");
278
292
  invariant4(totalSupply.currency.equals(this.liquidityToken), "TOTAL_SUPPLY");
279
293
  invariant4(liquidity.currency.equals(this.liquidityToken), "LIQUIDITY");
280
- invariant4(JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), "LIQUIDITY");
294
+ invariant4(liquidity.quotient <= totalSupply.quotient, "LIQUIDITY");
281
295
  let totalSupplyAdjusted;
282
296
  if (!feeOn) {
283
297
  totalSupplyAdjusted = totalSupply;
284
298
  } else {
285
299
  invariant4(!!kLast, "K_LAST");
286
- const kLastParsed = JSBI.BigInt(kLast);
287
- if (!JSBI.equal(kLastParsed, ZERO)) {
288
- const rootK = sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient));
300
+ const kLastParsed = BigInt(kLast);
301
+ if (!(kLastParsed === ZERO)) {
302
+ const rootK = sqrt(this.reserve0.quotient * this.reserve1.quotient);
289
303
  const rootKLast = sqrt(kLastParsed);
290
- if (JSBI.greaterThan(rootK, rootKLast)) {
291
- const numerator = JSBI.multiply(totalSupply.quotient, JSBI.subtract(rootK, rootKLast));
292
- const denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast);
293
- const feeLiquidity = JSBI.divide(numerator, denominator);
304
+ if (rootK > rootKLast) {
305
+ const numerator = totalSupply.quotient * (rootK - rootKLast);
306
+ const denominator = rootK * FIVE + rootKLast;
307
+ const feeLiquidity = numerator / denominator;
294
308
  totalSupplyAdjusted = totalSupply.add(CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity));
295
309
  } else {
296
310
  totalSupplyAdjusted = totalSupply;
@@ -301,7 +315,7 @@ var Pair = class {
301
315
  }
302
316
  return CurrencyAmount.fromRawAmount(
303
317
  token,
304
- JSBI.divide(JSBI.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient)
318
+ liquidity.quotient * this.reserveOf(token).quotient / totalSupplyAdjusted.quotient
305
319
  );
306
320
  }
307
321
  };
@@ -309,7 +323,7 @@ var Route = class {
309
323
  constructor(pairs, input, output) {
310
324
  this._midPrice = null;
311
325
  invariant4(pairs.length > 0, "PAIRS");
312
- const chainId = pairs[0].chainId;
326
+ const { chainId } = pairs[0];
313
327
  invariant4(
314
328
  pairs.every((pair) => pair.chainId === chainId),
315
329
  "CHAIN_IDS"
@@ -715,4 +729,785 @@ var _Ether = class extends NativeCurrency {
715
729
  var Ether = _Ether;
716
730
  Ether._etherCache = {};
717
731
 
718
- export { ChainId, ERC20Token, Ether, FACTORY_ADDRESS, FACTORY_ADDRESS_MAP, 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 };
732
+ // src/abis/ERC20.json
733
+ var ERC20_default = [
734
+ {
735
+ constant: true,
736
+ inputs: [],
737
+ name: "decimals",
738
+ outputs: [{ name: "", type: "uint8" }],
739
+ payable: false,
740
+ stateMutability: "view",
741
+ type: "function"
742
+ },
743
+ {
744
+ constant: true,
745
+ inputs: [{ name: "", type: "address" }],
746
+ name: "balanceOf",
747
+ outputs: [{ name: "", type: "uint256" }],
748
+ payable: false,
749
+ stateMutability: "view",
750
+ type: "function"
751
+ }
752
+ ];
753
+
754
+ // src/abis/IPancakePair.json
755
+ var IPancakePair_default = [
756
+ {
757
+ anonymous: false,
758
+ inputs: [
759
+ {
760
+ indexed: true,
761
+ internalType: "address",
762
+ name: "owner",
763
+ type: "address"
764
+ },
765
+ {
766
+ indexed: true,
767
+ internalType: "address",
768
+ name: "spender",
769
+ type: "address"
770
+ },
771
+ {
772
+ indexed: false,
773
+ internalType: "uint256",
774
+ name: "value",
775
+ type: "uint256"
776
+ }
777
+ ],
778
+ name: "Approval",
779
+ type: "event"
780
+ },
781
+ {
782
+ anonymous: false,
783
+ inputs: [
784
+ {
785
+ indexed: true,
786
+ internalType: "address",
787
+ name: "sender",
788
+ type: "address"
789
+ },
790
+ {
791
+ indexed: false,
792
+ internalType: "uint256",
793
+ name: "amount0",
794
+ type: "uint256"
795
+ },
796
+ {
797
+ indexed: false,
798
+ internalType: "uint256",
799
+ name: "amount1",
800
+ type: "uint256"
801
+ },
802
+ {
803
+ indexed: true,
804
+ internalType: "address",
805
+ name: "to",
806
+ type: "address"
807
+ }
808
+ ],
809
+ name: "Burn",
810
+ type: "event"
811
+ },
812
+ {
813
+ anonymous: false,
814
+ inputs: [
815
+ {
816
+ indexed: true,
817
+ internalType: "address",
818
+ name: "sender",
819
+ type: "address"
820
+ },
821
+ {
822
+ indexed: false,
823
+ internalType: "uint256",
824
+ name: "amount0",
825
+ type: "uint256"
826
+ },
827
+ {
828
+ indexed: false,
829
+ internalType: "uint256",
830
+ name: "amount1",
831
+ type: "uint256"
832
+ }
833
+ ],
834
+ name: "Mint",
835
+ type: "event"
836
+ },
837
+ {
838
+ anonymous: false,
839
+ inputs: [
840
+ {
841
+ indexed: true,
842
+ internalType: "address",
843
+ name: "sender",
844
+ type: "address"
845
+ },
846
+ {
847
+ indexed: false,
848
+ internalType: "uint256",
849
+ name: "amount0In",
850
+ type: "uint256"
851
+ },
852
+ {
853
+ indexed: false,
854
+ internalType: "uint256",
855
+ name: "amount1In",
856
+ type: "uint256"
857
+ },
858
+ {
859
+ indexed: false,
860
+ internalType: "uint256",
861
+ name: "amount0Out",
862
+ type: "uint256"
863
+ },
864
+ {
865
+ indexed: false,
866
+ internalType: "uint256",
867
+ name: "amount1Out",
868
+ type: "uint256"
869
+ },
870
+ {
871
+ indexed: true,
872
+ internalType: "address",
873
+ name: "to",
874
+ type: "address"
875
+ }
876
+ ],
877
+ name: "Swap",
878
+ type: "event"
879
+ },
880
+ {
881
+ anonymous: false,
882
+ inputs: [
883
+ {
884
+ indexed: false,
885
+ internalType: "uint112",
886
+ name: "reserve0",
887
+ type: "uint112"
888
+ },
889
+ {
890
+ indexed: false,
891
+ internalType: "uint112",
892
+ name: "reserve1",
893
+ type: "uint112"
894
+ }
895
+ ],
896
+ name: "Sync",
897
+ type: "event"
898
+ },
899
+ {
900
+ anonymous: false,
901
+ inputs: [
902
+ {
903
+ indexed: true,
904
+ internalType: "address",
905
+ name: "from",
906
+ type: "address"
907
+ },
908
+ {
909
+ indexed: true,
910
+ internalType: "address",
911
+ name: "to",
912
+ type: "address"
913
+ },
914
+ {
915
+ indexed: false,
916
+ internalType: "uint256",
917
+ name: "value",
918
+ type: "uint256"
919
+ }
920
+ ],
921
+ name: "Transfer",
922
+ type: "event"
923
+ },
924
+ {
925
+ constant: true,
926
+ inputs: [],
927
+ name: "DOMAIN_SEPARATOR",
928
+ outputs: [
929
+ {
930
+ internalType: "bytes32",
931
+ name: "",
932
+ type: "bytes32"
933
+ }
934
+ ],
935
+ payable: false,
936
+ stateMutability: "view",
937
+ type: "function"
938
+ },
939
+ {
940
+ constant: true,
941
+ inputs: [],
942
+ name: "MINIMUM_LIQUIDITY",
943
+ outputs: [
944
+ {
945
+ internalType: "uint256",
946
+ name: "",
947
+ type: "uint256"
948
+ }
949
+ ],
950
+ payable: false,
951
+ stateMutability: "pure",
952
+ type: "function"
953
+ },
954
+ {
955
+ constant: true,
956
+ inputs: [],
957
+ name: "PERMIT_TYPEHASH",
958
+ outputs: [
959
+ {
960
+ internalType: "bytes32",
961
+ name: "",
962
+ type: "bytes32"
963
+ }
964
+ ],
965
+ payable: false,
966
+ stateMutability: "pure",
967
+ type: "function"
968
+ },
969
+ {
970
+ constant: true,
971
+ inputs: [
972
+ {
973
+ internalType: "address",
974
+ name: "owner",
975
+ type: "address"
976
+ },
977
+ {
978
+ internalType: "address",
979
+ name: "spender",
980
+ type: "address"
981
+ }
982
+ ],
983
+ name: "allowance",
984
+ outputs: [
985
+ {
986
+ internalType: "uint256",
987
+ name: "",
988
+ type: "uint256"
989
+ }
990
+ ],
991
+ payable: false,
992
+ stateMutability: "view",
993
+ type: "function"
994
+ },
995
+ {
996
+ constant: false,
997
+ inputs: [
998
+ {
999
+ internalType: "address",
1000
+ name: "spender",
1001
+ type: "address"
1002
+ },
1003
+ {
1004
+ internalType: "uint256",
1005
+ name: "value",
1006
+ type: "uint256"
1007
+ }
1008
+ ],
1009
+ name: "approve",
1010
+ outputs: [
1011
+ {
1012
+ internalType: "bool",
1013
+ name: "",
1014
+ type: "bool"
1015
+ }
1016
+ ],
1017
+ payable: false,
1018
+ stateMutability: "nonpayable",
1019
+ type: "function"
1020
+ },
1021
+ {
1022
+ constant: true,
1023
+ inputs: [
1024
+ {
1025
+ internalType: "address",
1026
+ name: "owner",
1027
+ type: "address"
1028
+ }
1029
+ ],
1030
+ name: "balanceOf",
1031
+ outputs: [
1032
+ {
1033
+ internalType: "uint256",
1034
+ name: "",
1035
+ type: "uint256"
1036
+ }
1037
+ ],
1038
+ payable: false,
1039
+ stateMutability: "view",
1040
+ type: "function"
1041
+ },
1042
+ {
1043
+ constant: false,
1044
+ inputs: [
1045
+ {
1046
+ internalType: "address",
1047
+ name: "to",
1048
+ type: "address"
1049
+ }
1050
+ ],
1051
+ name: "burn",
1052
+ outputs: [
1053
+ {
1054
+ internalType: "uint256",
1055
+ name: "amount0",
1056
+ type: "uint256"
1057
+ },
1058
+ {
1059
+ internalType: "uint256",
1060
+ name: "amount1",
1061
+ type: "uint256"
1062
+ }
1063
+ ],
1064
+ payable: false,
1065
+ stateMutability: "nonpayable",
1066
+ type: "function"
1067
+ },
1068
+ {
1069
+ constant: true,
1070
+ inputs: [],
1071
+ name: "decimals",
1072
+ outputs: [
1073
+ {
1074
+ internalType: "uint8",
1075
+ name: "",
1076
+ type: "uint8"
1077
+ }
1078
+ ],
1079
+ payable: false,
1080
+ stateMutability: "pure",
1081
+ type: "function"
1082
+ },
1083
+ {
1084
+ constant: true,
1085
+ inputs: [],
1086
+ name: "factory",
1087
+ outputs: [
1088
+ {
1089
+ internalType: "address",
1090
+ name: "",
1091
+ type: "address"
1092
+ }
1093
+ ],
1094
+ payable: false,
1095
+ stateMutability: "view",
1096
+ type: "function"
1097
+ },
1098
+ {
1099
+ constant: true,
1100
+ inputs: [],
1101
+ name: "getReserves",
1102
+ outputs: [
1103
+ {
1104
+ internalType: "uint112",
1105
+ name: "reserve0",
1106
+ type: "uint112"
1107
+ },
1108
+ {
1109
+ internalType: "uint112",
1110
+ name: "reserve1",
1111
+ type: "uint112"
1112
+ },
1113
+ {
1114
+ internalType: "uint32",
1115
+ name: "blockTimestampLast",
1116
+ type: "uint32"
1117
+ }
1118
+ ],
1119
+ payable: false,
1120
+ stateMutability: "view",
1121
+ type: "function"
1122
+ },
1123
+ {
1124
+ constant: false,
1125
+ inputs: [
1126
+ {
1127
+ internalType: "address",
1128
+ name: "",
1129
+ type: "address"
1130
+ },
1131
+ {
1132
+ internalType: "address",
1133
+ name: "",
1134
+ type: "address"
1135
+ }
1136
+ ],
1137
+ name: "initialize",
1138
+ outputs: [],
1139
+ payable: false,
1140
+ stateMutability: "nonpayable",
1141
+ type: "function"
1142
+ },
1143
+ {
1144
+ constant: true,
1145
+ inputs: [],
1146
+ name: "kLast",
1147
+ outputs: [
1148
+ {
1149
+ internalType: "uint256",
1150
+ name: "",
1151
+ type: "uint256"
1152
+ }
1153
+ ],
1154
+ payable: false,
1155
+ stateMutability: "view",
1156
+ type: "function"
1157
+ },
1158
+ {
1159
+ constant: false,
1160
+ inputs: [
1161
+ {
1162
+ internalType: "address",
1163
+ name: "to",
1164
+ type: "address"
1165
+ }
1166
+ ],
1167
+ name: "mint",
1168
+ outputs: [
1169
+ {
1170
+ internalType: "uint256",
1171
+ name: "liquidity",
1172
+ type: "uint256"
1173
+ }
1174
+ ],
1175
+ payable: false,
1176
+ stateMutability: "nonpayable",
1177
+ type: "function"
1178
+ },
1179
+ {
1180
+ constant: true,
1181
+ inputs: [],
1182
+ name: "name",
1183
+ outputs: [
1184
+ {
1185
+ internalType: "string",
1186
+ name: "",
1187
+ type: "string"
1188
+ }
1189
+ ],
1190
+ payable: false,
1191
+ stateMutability: "pure",
1192
+ type: "function"
1193
+ },
1194
+ {
1195
+ constant: true,
1196
+ inputs: [
1197
+ {
1198
+ internalType: "address",
1199
+ name: "owner",
1200
+ type: "address"
1201
+ }
1202
+ ],
1203
+ name: "nonces",
1204
+ outputs: [
1205
+ {
1206
+ internalType: "uint256",
1207
+ name: "",
1208
+ type: "uint256"
1209
+ }
1210
+ ],
1211
+ payable: false,
1212
+ stateMutability: "view",
1213
+ type: "function"
1214
+ },
1215
+ {
1216
+ constant: false,
1217
+ inputs: [
1218
+ {
1219
+ internalType: "address",
1220
+ name: "owner",
1221
+ type: "address"
1222
+ },
1223
+ {
1224
+ internalType: "address",
1225
+ name: "spender",
1226
+ type: "address"
1227
+ },
1228
+ {
1229
+ internalType: "uint256",
1230
+ name: "value",
1231
+ type: "uint256"
1232
+ },
1233
+ {
1234
+ internalType: "uint256",
1235
+ name: "deadline",
1236
+ type: "uint256"
1237
+ },
1238
+ {
1239
+ internalType: "uint8",
1240
+ name: "v",
1241
+ type: "uint8"
1242
+ },
1243
+ {
1244
+ internalType: "bytes32",
1245
+ name: "r",
1246
+ type: "bytes32"
1247
+ },
1248
+ {
1249
+ internalType: "bytes32",
1250
+ name: "s",
1251
+ type: "bytes32"
1252
+ }
1253
+ ],
1254
+ name: "permit",
1255
+ outputs: [],
1256
+ payable: false,
1257
+ stateMutability: "nonpayable",
1258
+ type: "function"
1259
+ },
1260
+ {
1261
+ constant: true,
1262
+ inputs: [],
1263
+ name: "price0CumulativeLast",
1264
+ outputs: [
1265
+ {
1266
+ internalType: "uint256",
1267
+ name: "",
1268
+ type: "uint256"
1269
+ }
1270
+ ],
1271
+ payable: false,
1272
+ stateMutability: "view",
1273
+ type: "function"
1274
+ },
1275
+ {
1276
+ constant: true,
1277
+ inputs: [],
1278
+ name: "price1CumulativeLast",
1279
+ outputs: [
1280
+ {
1281
+ internalType: "uint256",
1282
+ name: "",
1283
+ type: "uint256"
1284
+ }
1285
+ ],
1286
+ payable: false,
1287
+ stateMutability: "view",
1288
+ type: "function"
1289
+ },
1290
+ {
1291
+ constant: false,
1292
+ inputs: [
1293
+ {
1294
+ internalType: "address",
1295
+ name: "to",
1296
+ type: "address"
1297
+ }
1298
+ ],
1299
+ name: "skim",
1300
+ outputs: [],
1301
+ payable: false,
1302
+ stateMutability: "nonpayable",
1303
+ type: "function"
1304
+ },
1305
+ {
1306
+ constant: false,
1307
+ inputs: [
1308
+ {
1309
+ internalType: "uint256",
1310
+ name: "amount0Out",
1311
+ type: "uint256"
1312
+ },
1313
+ {
1314
+ internalType: "uint256",
1315
+ name: "amount1Out",
1316
+ type: "uint256"
1317
+ },
1318
+ {
1319
+ internalType: "address",
1320
+ name: "to",
1321
+ type: "address"
1322
+ },
1323
+ {
1324
+ internalType: "bytes",
1325
+ name: "data",
1326
+ type: "bytes"
1327
+ }
1328
+ ],
1329
+ name: "swap",
1330
+ outputs: [],
1331
+ payable: false,
1332
+ stateMutability: "nonpayable",
1333
+ type: "function"
1334
+ },
1335
+ {
1336
+ constant: true,
1337
+ inputs: [],
1338
+ name: "symbol",
1339
+ outputs: [
1340
+ {
1341
+ internalType: "string",
1342
+ name: "",
1343
+ type: "string"
1344
+ }
1345
+ ],
1346
+ payable: false,
1347
+ stateMutability: "pure",
1348
+ type: "function"
1349
+ },
1350
+ {
1351
+ constant: false,
1352
+ inputs: [],
1353
+ name: "sync",
1354
+ outputs: [],
1355
+ payable: false,
1356
+ stateMutability: "nonpayable",
1357
+ type: "function"
1358
+ },
1359
+ {
1360
+ constant: true,
1361
+ inputs: [],
1362
+ name: "token0",
1363
+ outputs: [
1364
+ {
1365
+ internalType: "address",
1366
+ name: "",
1367
+ type: "address"
1368
+ }
1369
+ ],
1370
+ payable: false,
1371
+ stateMutability: "view",
1372
+ type: "function"
1373
+ },
1374
+ {
1375
+ constant: true,
1376
+ inputs: [],
1377
+ name: "token1",
1378
+ outputs: [
1379
+ {
1380
+ internalType: "address",
1381
+ name: "",
1382
+ type: "address"
1383
+ }
1384
+ ],
1385
+ payable: false,
1386
+ stateMutability: "view",
1387
+ type: "function"
1388
+ },
1389
+ {
1390
+ constant: true,
1391
+ inputs: [],
1392
+ name: "totalSupply",
1393
+ outputs: [
1394
+ {
1395
+ internalType: "uint256",
1396
+ name: "",
1397
+ type: "uint256"
1398
+ }
1399
+ ],
1400
+ payable: false,
1401
+ stateMutability: "view",
1402
+ type: "function"
1403
+ },
1404
+ {
1405
+ constant: false,
1406
+ inputs: [
1407
+ {
1408
+ internalType: "address",
1409
+ name: "to",
1410
+ type: "address"
1411
+ },
1412
+ {
1413
+ internalType: "uint256",
1414
+ name: "value",
1415
+ type: "uint256"
1416
+ }
1417
+ ],
1418
+ name: "transfer",
1419
+ outputs: [
1420
+ {
1421
+ internalType: "bool",
1422
+ name: "",
1423
+ type: "bool"
1424
+ }
1425
+ ],
1426
+ payable: false,
1427
+ stateMutability: "nonpayable",
1428
+ type: "function"
1429
+ },
1430
+ {
1431
+ constant: false,
1432
+ inputs: [
1433
+ {
1434
+ internalType: "address",
1435
+ name: "from",
1436
+ type: "address"
1437
+ },
1438
+ {
1439
+ internalType: "address",
1440
+ name: "to",
1441
+ type: "address"
1442
+ },
1443
+ {
1444
+ internalType: "uint256",
1445
+ name: "value",
1446
+ type: "uint256"
1447
+ }
1448
+ ],
1449
+ name: "transferFrom",
1450
+ outputs: [
1451
+ {
1452
+ internalType: "bool",
1453
+ name: "",
1454
+ type: "bool"
1455
+ }
1456
+ ],
1457
+ payable: false,
1458
+ stateMutability: "nonpayable",
1459
+ type: "function"
1460
+ }
1461
+ ];
1462
+
1463
+ // src/fetcher.ts
1464
+ var TOKEN_DECIMALS_CACHE = {
1465
+ [56 /* BSC */]: {}
1466
+ };
1467
+ var Fetcher = class {
1468
+ /**
1469
+ * Cannot be constructed.
1470
+ */
1471
+ // eslint-disable-next-line no-useless-constructor,@typescript-eslint/no-empty-function
1472
+ constructor() {
1473
+ }
1474
+ /**
1475
+ * Fetch information for a given token on the given chain, using the given ethers provider.
1476
+ * @param chainId chain of the token
1477
+ * @param address address of the token on the chain
1478
+ * @param provider provider used to fetch the token
1479
+ * @param symbol symbol of the token
1480
+ * @param name optional name of the token
1481
+ */
1482
+ static async fetchTokenData(chainId, address, provider = getDefaultProvider(getNetwork(chainId)), symbol, name) {
1483
+ const parsedDecimals = typeof TOKEN_DECIMALS_CACHE?.[chainId]?.[address] === "number" ? TOKEN_DECIMALS_CACHE[chainId][address] : await new Contract(address, ERC20_default, provider).decimals().then((decimals) => {
1484
+ TOKEN_DECIMALS_CACHE = {
1485
+ ...TOKEN_DECIMALS_CACHE,
1486
+ [chainId]: {
1487
+ ...TOKEN_DECIMALS_CACHE?.[chainId],
1488
+ [address]: decimals
1489
+ }
1490
+ };
1491
+ return decimals;
1492
+ });
1493
+ return new Token(chainId, address, parsedDecimals, symbol, name);
1494
+ }
1495
+ /**
1496
+ * Fetches information about a pair and constructs a pair from the given two tokens.
1497
+ * @param tokenA first token
1498
+ * @param tokenB second token
1499
+ * @param provider the provider to use to fetch the data
1500
+ */
1501
+ static async fetchPairData(tokenA, tokenB, provider = getDefaultProvider(getNetwork(tokenA.chainId))) {
1502
+ invariant4(tokenA.chainId === tokenB.chainId, "CHAIN_ID");
1503
+ const address = Pair.getAddress(tokenA, tokenB);
1504
+ const [reserves0, reserves1] = await new Contract(address, IPancakePair_default, provider).getReserves();
1505
+ const balances = tokenA.sortsBefore(tokenB) ? [reserves0, reserves1] : [reserves1, reserves0];
1506
+ return new Pair(
1507
+ CurrencyAmount.fromRawAmount(tokenA, balances[0]),
1508
+ CurrencyAmount.fromRawAmount(tokenB, balances[1])
1509
+ );
1510
+ }
1511
+ };
1512
+
1513
+ 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 };