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