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