@reactmore/crypto-wallet-sdk 1.2.0 → 1.3.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.
@@ -819,38 +819,50 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
819
819
  }();
820
820
  _proto.generateWallet = /*#__PURE__*/function () {
821
821
  var _generateWallet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
822
- var mnemonic, derivationPath, hdPath, getMnemonic, derivePrivateKey, _yield$this$wallet$ge, address, publicKey, _t2;
822
+ var mnemonic, privateKey, derivationPath, hdPath, derivePrivateKey, _yield$this$wallet$ge, address, publicKey;
823
823
  return _regenerator().w(function (_context2) {
824
824
  while (1) switch (_context2.n) {
825
825
  case 0:
826
- mnemonic = _ref2.mnemonic, derivationPath = _ref2.derivationPath;
826
+ mnemonic = _ref2.mnemonic, privateKey = _ref2.privateKey, derivationPath = _ref2.derivationPath;
827
827
  hdPath = derivationPath || "m/44'/60'/0'/0/0";
828
- if (!(mnemonic != null)) {
828
+ if (!(mnemonic && privateKey)) {
829
829
  _context2.n = 1;
830
830
  break;
831
831
  }
832
- _t2 = mnemonic;
833
- _context2.n = 3;
834
- break;
832
+ throw new Error("Provide either mnemonic or privateKey, not both");
835
833
  case 1:
836
- _context2.n = 2;
837
- return this.generateMnemonic(12);
834
+ if (!privateKey) {
835
+ _context2.n = 2;
836
+ break;
837
+ }
838
+ derivePrivateKey = privateKey;
839
+ _context2.n = 6;
840
+ break;
838
841
  case 2:
839
- _t2 = _context2.v;
840
- case 3:
841
- getMnemonic = _t2;
842
- _context2.n = 4;
842
+ if (!mnemonic) {
843
+ _context2.n = 4;
844
+ break;
845
+ }
846
+ _context2.n = 3;
843
847
  return this.wallet.getDerivedPrivateKey({
844
- mnemonic: getMnemonic,
848
+ mnemonic: mnemonic,
845
849
  hdPath: hdPath
846
850
  });
847
- case 4:
851
+ case 3:
848
852
  derivePrivateKey = _context2.v;
853
+ _context2.n = 6;
854
+ break;
855
+ case 4:
849
856
  _context2.n = 5;
857
+ return this.wallet.getRandomPrivateKey();
858
+ case 5:
859
+ derivePrivateKey = _context2.v;
860
+ case 6:
861
+ _context2.n = 7;
850
862
  return this.wallet.getNewAddress({
851
863
  privateKey: derivePrivateKey
852
864
  });
853
- case 5:
865
+ case 7:
854
866
  _yield$this$wallet$ge = _context2.v;
855
867
  address = _yield$this$wallet$ge.address;
856
868
  publicKey = _yield$this$wallet$ge.publicKey;
@@ -920,7 +932,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
920
932
  }();
921
933
  _proto.transfer = /*#__PURE__*/function () {
922
934
  var _transfer = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref4) {
923
- var privateKey, contractAddress, rpcUrl, args, _yield$this$getContra2, contract, providerInstance, gasFeeData, nonce, recipientAddress, prio, max, value, gasLimit, decimals, noFeeProvided, estimate, fee, signParams, signedTx, broadcast, _t3;
935
+ var privateKey, contractAddress, rpcUrl, args, _yield$this$getContra2, contract, providerInstance, gasFeeData, nonce, signer, recipientAddress, prio, max, txTo, txData, txValue, gasLimit, decimals, amount, noFeeProvided, estimate, fee, signParams, signedTx, broadcast, _t2, _t3, _t4, _t5, _t6;
924
936
  return _regenerator().w(function (_context4) {
925
937
  while (1) switch (_context4.n) {
926
938
  case 0:
@@ -937,6 +949,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
937
949
  providerInstance = _yield$this$getContra2.providerInstance;
938
950
  gasFeeData = _yield$this$getContra2.gasFeeData;
939
951
  nonce = _yield$this$getContra2.nonce;
952
+ signer = _yield$this$getContra2.signer;
940
953
  _context4.n = 2;
941
954
  return this.wallet.validAddress({
942
955
  address: args.recipientAddress
@@ -947,7 +960,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
947
960
  _context4.n = 3;
948
961
  break;
949
962
  }
950
- throw new Error("address not valid");
963
+ throw new Error("recipient address not valid");
951
964
  case 3:
952
965
  if (!(args.maxPriorityFeePerGas && args.maxFeePerGas)) {
953
966
  _context4.n = 4;
@@ -965,10 +978,10 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
965
978
  _context4.n = 5;
966
979
  break;
967
980
  }
968
- throw new Error("Cannot use gasPrice with EIP-1559 fee fields");
981
+ throw new Error("Cannot mix gasPrice with EIP-1559 fields");
969
982
  case 5:
970
983
  if (!contractAddress) {
971
- _context4.n = 11;
984
+ _context4.n = 12;
972
985
  break;
973
986
  }
974
987
  if (contract) {
@@ -981,93 +994,97 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
981
994
  return contract.decimals();
982
995
  case 7:
983
996
  decimals = _context4.v;
984
- value = parseAmount(args.amount.toString(), decimals);
997
+ amount = parseAmount(args.amount.toString(), decimals);
998
+ txData = contract["interface"].encodeFunctionData("transfer", [args.recipientAddress, amount]);
999
+ txTo = contractAddress;
1000
+ txValue = 0n;
985
1001
  if (!args.gasLimit) {
986
1002
  _context4.n = 8;
987
1003
  break;
988
1004
  }
989
- _t3 = BigInt(args.gasLimit);
990
- _context4.n = 10;
1005
+ _t2 = BigInt(args.gasLimit);
1006
+ _context4.n = 11;
991
1007
  break;
992
1008
  case 8:
1009
+ _t3 = providerInstance;
993
1010
  _context4.n = 9;
994
- return contract.transfer.estimateGas(args.recipientAddress, value);
1011
+ return signer.getAddress();
995
1012
  case 9:
996
- _t3 = _context4.v;
1013
+ _t4 = _context4.v;
1014
+ _t5 = contractAddress;
1015
+ _t6 = txData;
1016
+ _context4.n = 10;
1017
+ return _t3.estimateGas.call(_t3, {
1018
+ from: _t4,
1019
+ to: _t5,
1020
+ data: _t6
1021
+ });
997
1022
  case 10:
998
- gasLimit = _t3;
999
- _context4.n = 12;
1000
- break;
1023
+ _t2 = _context4.v;
1001
1024
  case 11:
1002
- value = parseEther(args.amount.toString());
1003
- gasLimit = args.gasLimit ? BigInt(args.gasLimit) : 21000n;
1025
+ gasLimit = _t2;
1026
+ _context4.n = 13;
1027
+ break;
1004
1028
  case 12:
1005
- // DEFAULT FEE
1029
+ // ===== NATIVE TRANSFER =====
1030
+ txTo = args.recipientAddress;
1031
+ txValue = parseEther(args.amount.toString());
1032
+ txData = args.data ? ethers.hexlify(ethers.toUtf8Bytes(args.data)) : '0x';
1033
+ gasLimit = args.gasLimit ? BigInt(args.gasLimit) : 21000n;
1034
+ case 13:
1035
+ // =========================
1036
+ // AUTO ESTIMATE FEE
1037
+ // =========================
1006
1038
  noFeeProvided = !args.gasPrice && !args.maxFeePerGas && !args.maxPriorityFeePerGas;
1007
- if (!noFeeProvided) {
1008
- _context4.n = 17;
1039
+ if (!(noFeeProvided && !contractAddress)) {
1040
+ _context4.n = 16;
1009
1041
  break;
1010
1042
  }
1011
- _context4.n = 13;
1043
+ _context4.n = 14;
1012
1044
  return this.estimateGas({
1013
1045
  rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl,
1014
- recipientAddress: args.recipientAddress,
1046
+ recipientAddress: txTo,
1015
1047
  amount: args.amount.toString(),
1016
- data: args.data
1048
+ data: txData !== '0x' ? txData : undefined
1017
1049
  });
1018
- case 13:
1050
+ case 14:
1019
1051
  estimate = _context4.v;
1020
1052
  gasLimit = BigInt(estimate.gasLimit);
1021
- // ===== LEGACY =====
1022
1053
  if (!(estimate.model === "LEGACY")) {
1023
1054
  _context4.n = 15;
1024
1055
  break;
1025
1056
  }
1026
- if (estimate.gasPrice) {
1027
- _context4.n = 14;
1028
- break;
1029
- }
1030
- throw new Error("LEGACY estimate missing gasPrice");
1031
- case 14:
1032
- args.gasPrice = estimate.gasPrice; // wei
1057
+ args.gasPrice = estimate.gasPrice;
1033
1058
  return _context4.a(2, this.transfer(_extends({
1034
1059
  privateKey: privateKey,
1035
1060
  contractAddress: contractAddress,
1036
1061
  rpcUrl: rpcUrl
1037
1062
  }, args)));
1038
1063
  case 15:
1039
- // ===== EIP-1559 =====
1040
1064
  fee = estimate.fees.regular;
1041
- if (!(!(fee != null && fee.maxFeePerGas) || !(fee != null && fee.maxPriorityFeePerGas))) {
1042
- _context4.n = 16;
1043
- break;
1044
- }
1045
- throw new Error("EIP1559 estimate missing fee fields");
1046
- case 16:
1047
1065
  args.maxFeePerGas = fee.maxFeePerGas;
1048
1066
  args.maxPriorityFeePerGas = fee.maxPriorityFeePerGas;
1049
- case 17:
1050
- _context4.n = 18;
1067
+ case 16:
1068
+ _context4.n = 17;
1051
1069
  return this.buildSignParams({
1052
- args: _extends({}, args, {
1053
- privateKey: privateKey,
1054
- gasLimit: gasLimit
1055
- }),
1070
+ privateKey: privateKey,
1056
1071
  nonce: nonce,
1057
1072
  gasFeeData: gasFeeData,
1058
- recipientAddress: recipientAddress,
1059
- value: value,
1060
- contractAddress: contractAddress
1073
+ txTo: txTo,
1074
+ txData: txData,
1075
+ txValue: txValue,
1076
+ gasLimit: gasLimit,
1077
+ args: args
1061
1078
  });
1062
- case 18:
1079
+ case 17:
1063
1080
  signParams = _context4.v;
1064
- _context4.n = 19;
1081
+ _context4.n = 18;
1065
1082
  return this.wallet.signTransaction(signParams);
1066
- case 19:
1083
+ case 18:
1067
1084
  signedTx = _context4.v;
1068
- _context4.n = 20;
1085
+ _context4.n = 19;
1069
1086
  return providerInstance.broadcastTransaction(signedTx);
1070
- case 20:
1087
+ case 19:
1071
1088
  broadcast = _context4.v;
1072
1089
  return _context4.a(2, successResponse(_extends({}, broadcast)));
1073
1090
  }
@@ -1080,7 +1097,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1080
1097
  }();
1081
1098
  _proto.getTransaction = /*#__PURE__*/function () {
1082
1099
  var _getTransaction = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref5) {
1083
- var hash, rpcUrl, withReceipt, _yield$this$getContra3, providerInstance, _yield$Promise$all, _tx, receipt, memo, tx, _t4;
1100
+ var hash, rpcUrl, withReceipt, _yield$this$getContra3, providerInstance, _yield$Promise$all, _tx, receipt, memo, tx, _t7;
1084
1101
  return _regenerator().w(function (_context5) {
1085
1102
  while (1) switch (_context5.p = _context5.n) {
1086
1103
  case 0:
@@ -1119,8 +1136,8 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1119
1136
  }));
1120
1137
  case 6:
1121
1138
  _context5.p = 6;
1122
- _t4 = _context5.v;
1123
- throw _t4;
1139
+ _t7 = _context5.v;
1140
+ throw _t7;
1124
1141
  case 7:
1125
1142
  return _context5.a(2);
1126
1143
  }
@@ -1180,7 +1197,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1180
1197
  _proto.smartContractCall = /*#__PURE__*/function () {
1181
1198
  var _smartContractCall = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(args) {
1182
1199
  var _args$rpcUrl;
1183
- var _yield$this$getContra5, contract, gasFeeData, nonce, tx, overrides, _t5;
1200
+ var _yield$this$getContra5, contract, gasFeeData, nonce, tx, overrides, _t8;
1184
1201
  return _regenerator().w(function (_context7) {
1185
1202
  while (1) switch (_context7.p = _context7.n) {
1186
1203
  case 0:
@@ -1231,8 +1248,8 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1231
1248
  }));
1232
1249
  case 7:
1233
1250
  _context7.p = 7;
1234
- _t5 = _context7.v;
1235
- throw _t5;
1251
+ _t8 = _context7.v;
1252
+ throw _t8;
1236
1253
  case 8:
1237
1254
  return _context7.a(2);
1238
1255
  }
@@ -1245,7 +1262,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1245
1262
  }();
1246
1263
  _proto.estimateGas = /*#__PURE__*/function () {
1247
1264
  var _estimateGas = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(_ref7) {
1248
- var rpcUrl, recipientAddress, amount, data, _yield$this$getContra6, providerInstance, _block$baseFeePerGas, _feeData$maxPriorityF, network, chainId, tx, _yield$Promise$all3, feeData, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, applyMultiplier, isEip1559, baseGasPrice, regularGasPrice, expressGasPrice, instantGasPrice, _regularFee, _expressFee, _instantFee, baseFee, priorityFee, block, regularPriority, regularMaxFee, expressPriority, expressMaxFee, instantPriority, instantMaxFee, MAX_GAS_GWEI, cap, regularFee, expressFee, instantFee, _t6;
1265
+ var rpcUrl, recipientAddress, amount, data, _yield$this$getContra6, providerInstance, _block$baseFeePerGas, _feeData$maxPriorityF, network, chainId, tx, _yield$Promise$all3, feeData, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, applyMultiplier, isEip1559, baseGasPrice, regularGasPrice, expressGasPrice, instantGasPrice, _regularFee, _expressFee, _instantFee, baseFee, priorityFee, block, regularPriority, regularMaxFee, expressPriority, expressMaxFee, instantPriority, instantMaxFee, MAX_GAS_GWEI, cap, regularFee, expressFee, instantFee, _t9;
1249
1266
  return _regenerator().w(function (_context8) {
1250
1267
  while (1) switch (_context8.p = _context8.n) {
1251
1268
  case 0:
@@ -1348,8 +1365,8 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1348
1365
  }));
1349
1366
  case 7:
1350
1367
  _context8.p = 7;
1351
- _t6 = _context8.v;
1352
- throw _t6;
1368
+ _t9 = _context8.v;
1369
+ throw _t9;
1353
1370
  case 8:
1354
1371
  return _context8.a(2);
1355
1372
  }
@@ -1362,56 +1379,57 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1362
1379
  }();
1363
1380
  _proto.buildSignParams = /*#__PURE__*/function () {
1364
1381
  var _buildSignParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(_ref8) {
1365
- var args, nonce, gasFeeData, recipientAddress, value, contractAddress, txBase, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12;
1382
+ var _args$nonce, _args$maxPriorityFeeP, _args$maxFeePerGas;
1383
+ var privateKey, nonce, gasFeeData, txTo, txData, txValue, gasLimit, args, txBase, _t0, _t1, _t10, _t11, _t12, _t13, _t14;
1366
1384
  return _regenerator().w(function (_context9) {
1367
1385
  while (1) switch (_context9.n) {
1368
1386
  case 0:
1369
- args = _ref8.args, nonce = _ref8.nonce, gasFeeData = _ref8.gasFeeData, recipientAddress = _ref8.recipientAddress, value = _ref8.value, contractAddress = _ref8.contractAddress;
1370
- _t7 = _extends;
1371
- _t8 = recipientAddress.address;
1372
- _t9 = BigNumber$1(value.toString());
1373
- _t0 = args.data ? ethers.hexlify(ethers.toUtf8Bytes(args.data)) : '0x';
1374
- _t1 = args.nonce;
1375
- if (_t1) {
1376
- _context9.n = 2;
1387
+ privateKey = _ref8.privateKey, nonce = _ref8.nonce, gasFeeData = _ref8.gasFeeData, txTo = _ref8.txTo, txData = _ref8.txData, txValue = _ref8.txValue, gasLimit = _ref8.gasLimit, args = _ref8.args;
1388
+ _t0 = txTo;
1389
+ _t1 = BigNumber$1(txValue.toString());
1390
+ _t10 = txData;
1391
+ if (!((_args$nonce = args.nonce) != null)) {
1392
+ _context9.n = 1;
1377
1393
  break;
1378
1394
  }
1379
- _context9.n = 1;
1380
- return nonce;
1395
+ _t11 = _args$nonce;
1396
+ _context9.n = 3;
1397
+ break;
1381
1398
  case 1:
1382
- _t1 = _context9.v;
1399
+ _context9.n = 2;
1400
+ return nonce;
1383
1401
  case 2:
1384
- _t10 = _t1;
1385
- _t11 = args.gasLimit ? BigNumber$1(args.gasLimit) : BigNumber$1(21000);
1386
- _t12 = Number(this.currentChain.id);
1387
- txBase = _t7({
1388
- to: _t8,
1389
- value: _t9,
1390
- data: _t0,
1391
- nonce: _t10,
1392
- gasLimit: _t11,
1393
- chainId: _t12
1394
- }, contractAddress ? {
1395
- contractAddress: contractAddress
1396
- } : {});
1402
+ _t11 = _context9.v;
1403
+ case 3:
1404
+ _t12 = _t11;
1405
+ _t13 = BigNumber$1(gasLimit.toString());
1406
+ _t14 = Number(this.currentChain.id);
1407
+ txBase = {
1408
+ to: _t0,
1409
+ value: _t1,
1410
+ data: _t10,
1411
+ nonce: _t12,
1412
+ gasLimit: _t13,
1413
+ chainId: _t14
1414
+ };
1397
1415
  if (!args.gasPrice) {
1398
- _context9.n = 3;
1416
+ _context9.n = 4;
1399
1417
  break;
1400
1418
  }
1401
1419
  return _context9.a(2, {
1402
- privateKey: args.privateKey,
1420
+ privateKey: privateKey,
1403
1421
  data: _extends({}, txBase, {
1404
1422
  gasPrice: BigNumber$1(parseGwei(args.gasPrice).toString()),
1405
1423
  type: 0
1406
1424
  })
1407
1425
  });
1408
- case 3:
1426
+ case 4:
1409
1427
  return _context9.a(2, {
1410
- privateKey: args.privateKey,
1428
+ privateKey: privateKey,
1411
1429
  data: _extends({}, txBase, {
1412
1430
  type: 2,
1413
- maxPriorityFeePerGas: BigNumber$1(args.maxPriorityFeePerGas ? args.maxPriorityFeePerGas : gasFeeData.maxPriorityFeePerGas.toString()),
1414
- maxFeePerGas: BigNumber$1(args.maxFeePerGas ? args.maxFeePerGas : gasFeeData.maxFeePerGas.toString())
1431
+ maxPriorityFeePerGas: BigNumber$1((_args$maxPriorityFeeP = args.maxPriorityFeePerGas) != null ? _args$maxPriorityFeeP : gasFeeData.maxPriorityFeePerGas.toString()),
1432
+ maxFeePerGas: BigNumber$1((_args$maxFeePerGas = args.maxFeePerGas) != null ? _args$maxFeePerGas : gasFeeData.maxFeePerGas.toString())
1415
1433
  })
1416
1434
  });
1417
1435
  }