@sidhujag/sysweb3-keyring 1.0.509 → 1.0.511
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/cjs/keyring-manager.js +9 -7
- package/cjs/keyring-manager.js.map +1 -1
- package/cjs/ledger/index.js +9 -8
- package/cjs/ledger/index.js.map +1 -1
- package/cjs/providers.js +68 -20
- package/cjs/providers.js.map +1 -1
- package/cjs/transactions/ethereum.js +76 -67
- package/cjs/transactions/ethereum.js.map +1 -1
- package/cjs/trezor/index.js +10 -9
- package/cjs/trezor/index.js.map +1 -1
- package/cjs/types.js.map +1 -1
- package/cjs/utils.js +12 -11
- package/cjs/utils.js.map +1 -1
- package/package.json +23 -8
- package/types/keyring-manager.d.ts +3 -3
- package/types/ledger/types.d.ts +2 -2
- package/types/providers.d.ts +14 -11
- package/types/transactions/ethereum.d.ts +6 -5
- package/types/trezor/index.d.ts +3 -3
- package/types/types.d.ts +18 -16
|
@@ -4,11 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EthereumTransactions = void 0;
|
|
7
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
8
|
+
const bytes_1 = require("@ethersproject/bytes");
|
|
9
|
+
const constants_1 = require("@ethersproject/constants");
|
|
10
|
+
const contracts_1 = require("@ethersproject/contracts");
|
|
11
|
+
const transactions_1 = require("@ethersproject/transactions");
|
|
12
|
+
const units_1 = require("@ethersproject/units");
|
|
13
|
+
const wallet_1 = require("@ethersproject/wallet");
|
|
14
|
+
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
7
15
|
const sysweb3_network_1 = require("@sidhujag/sysweb3-network");
|
|
8
16
|
const sysweb3_utils_1 = require("@sidhujag/sysweb3-utils");
|
|
9
|
-
const eth_sig_util_1 = require("eth-sig-util");
|
|
10
17
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
11
|
-
const ethers_1 = require("ethers");
|
|
12
18
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
13
19
|
const providers_1 = require("../providers");
|
|
14
20
|
const types_1 = require("../types");
|
|
@@ -34,13 +40,17 @@ class EthereumTransactions {
|
|
|
34
40
|
message: `Account state mismatch detected. Expected ${activeAccount.address} but got ${address}. Please try again after account switching completes.`,
|
|
35
41
|
};
|
|
36
42
|
}
|
|
37
|
-
const
|
|
43
|
+
const signTypedDataLocal = () => {
|
|
38
44
|
if (addr.toLowerCase() !== address.toLowerCase())
|
|
39
45
|
throw {
|
|
40
46
|
message: 'Decrypting for wrong address, change activeAccount maybe',
|
|
41
47
|
};
|
|
42
48
|
const privKey = Buffer.from((0, ethereumjs_util_1.stripHexPrefix)(decryptedPrivateKey), 'hex');
|
|
43
|
-
return (0, eth_sig_util_1.
|
|
49
|
+
return (0, eth_sig_util_1.signTypedData)({
|
|
50
|
+
privateKey: privKey,
|
|
51
|
+
data: typedData,
|
|
52
|
+
version,
|
|
53
|
+
});
|
|
44
54
|
};
|
|
45
55
|
const signTypedDataWithLedger = async () => {
|
|
46
56
|
if (addr.toLowerCase() !== activeAccount.address.toLowerCase())
|
|
@@ -71,16 +81,12 @@ class EthereumTransactions {
|
|
|
71
81
|
case types_1.KeyringAccountType.Ledger:
|
|
72
82
|
return await signTypedDataWithLedger();
|
|
73
83
|
default:
|
|
74
|
-
return
|
|
84
|
+
return signTypedDataLocal();
|
|
75
85
|
}
|
|
76
86
|
};
|
|
77
87
|
this.verifyTypedSignature = (data, signature, version) => {
|
|
78
88
|
try {
|
|
79
|
-
|
|
80
|
-
data,
|
|
81
|
-
sig: signature,
|
|
82
|
-
};
|
|
83
|
-
return (0, eth_sig_util_1.recoverTypedMessage)(msgParams, version);
|
|
89
|
+
return (0, eth_sig_util_1.recoverTypedSignature)({ data: data, signature, version });
|
|
84
90
|
}
|
|
85
91
|
catch (error) {
|
|
86
92
|
throw error;
|
|
@@ -287,7 +293,7 @@ class EthereumTransactions {
|
|
|
287
293
|
try {
|
|
288
294
|
const msgParams = {
|
|
289
295
|
data: message,
|
|
290
|
-
|
|
296
|
+
signature: sign,
|
|
291
297
|
};
|
|
292
298
|
return (0, eth_sig_util_1.recoverPersonalSignature)(msgParams);
|
|
293
299
|
}
|
|
@@ -321,14 +327,17 @@ class EthereumTransactions {
|
|
|
321
327
|
try {
|
|
322
328
|
const buff = Buffer.from(encryptedData, 'hex');
|
|
323
329
|
const cleanData = JSON.parse(buff.toString('utf8'));
|
|
324
|
-
const sig = (0, eth_sig_util_1.decrypt)(
|
|
330
|
+
const sig = (0, eth_sig_util_1.decrypt)({
|
|
331
|
+
encryptedData: cleanData,
|
|
332
|
+
privateKey: (0, ethereumjs_util_1.stripHexPrefix)(decryptedPrivateKey),
|
|
333
|
+
});
|
|
325
334
|
return sig;
|
|
326
335
|
}
|
|
327
336
|
catch (error) {
|
|
328
337
|
throw error;
|
|
329
338
|
}
|
|
330
339
|
};
|
|
331
|
-
this.toBigNumber = (aBigNumberish) =>
|
|
340
|
+
this.toBigNumber = (aBigNumberish) => bignumber_1.BigNumber.from(String(aBigNumberish));
|
|
332
341
|
this.getData = ({ contractAddress, receivingAddress, value, }) => {
|
|
333
342
|
const abi = (0, sysweb3_utils_1.getErc20Abi)();
|
|
334
343
|
try {
|
|
@@ -350,11 +359,11 @@ class EthereumTransactions {
|
|
|
350
359
|
if (block && block.baseFeePerGas) {
|
|
351
360
|
try {
|
|
352
361
|
const ethMaxPriorityFee = await this.web3Provider.send('eth_maxPriorityFeePerGas', []);
|
|
353
|
-
maxPriorityFeePerGas =
|
|
362
|
+
maxPriorityFeePerGas = bignumber_1.BigNumber.from(ethMaxPriorityFee);
|
|
354
363
|
maxFeePerGas = block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas);
|
|
355
364
|
}
|
|
356
365
|
catch (e) {
|
|
357
|
-
maxPriorityFeePerGas =
|
|
366
|
+
maxPriorityFeePerGas = bignumber_1.BigNumber.from('1500000000');
|
|
358
367
|
maxFeePerGas = block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas);
|
|
359
368
|
}
|
|
360
369
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
@@ -383,7 +392,7 @@ class EthereumTransactions {
|
|
|
383
392
|
const calculateAndConvertNewValue = (feeValue) => {
|
|
384
393
|
const calculateValue = String(feeValue * multiplierToUse);
|
|
385
394
|
const convertValueToHex = '0x' + parseInt(calculateValue, 10).toString(16);
|
|
386
|
-
return
|
|
395
|
+
return bignumber_1.BigNumber.from(convertValueToHex);
|
|
387
396
|
};
|
|
388
397
|
const maxFeePerGasToNumber = maxFeePerGas?.toNumber();
|
|
389
398
|
const maxPriorityFeePerGasToNumber = maxPriorityFeePerGas?.toNumber();
|
|
@@ -400,7 +409,7 @@ class EthereumTransactions {
|
|
|
400
409
|
if (isForCancel) {
|
|
401
410
|
const DEFAULT_GAS_LIMIT_VALUE = '21000';
|
|
402
411
|
const convertToHex = '0x' + parseInt(DEFAULT_GAS_LIMIT_VALUE, 10).toString(16);
|
|
403
|
-
newGasValues.gasLimit =
|
|
412
|
+
newGasValues.gasLimit = bignumber_1.BigNumber.from(convertToHex);
|
|
404
413
|
}
|
|
405
414
|
if (!isForCancel) {
|
|
406
415
|
newGasValues.gasLimit = calculateAndConvertNewValue(gasLimitToNumber);
|
|
@@ -418,7 +427,7 @@ class EthereumTransactions {
|
|
|
418
427
|
};
|
|
419
428
|
}
|
|
420
429
|
const { decryptedPrivateKey } = this.getDecryptedPrivateKey();
|
|
421
|
-
const wallet = new
|
|
430
|
+
const wallet = new wallet_1.Wallet(decryptedPrivateKey, this.web3Provider);
|
|
422
431
|
let changedTxToCancel;
|
|
423
432
|
const oldTxsGasValues = {
|
|
424
433
|
maxFeePerGas: tx.maxFeePerGas,
|
|
@@ -434,7 +443,7 @@ class EthereumTransactions {
|
|
|
434
443
|
nonce: tx.nonce,
|
|
435
444
|
from: wallet.address,
|
|
436
445
|
to: wallet.address,
|
|
437
|
-
value:
|
|
446
|
+
value: constants_1.Zero,
|
|
438
447
|
maxFeePerGas: newGasValues.maxFeePerGas,
|
|
439
448
|
maxPriorityFeePerGas: newGasValues.maxPriorityFeePerGas,
|
|
440
449
|
gasLimit: newGasValues.gasLimit,
|
|
@@ -448,7 +457,7 @@ class EthereumTransactions {
|
|
|
448
457
|
nonce: tx.nonce,
|
|
449
458
|
from: wallet.address,
|
|
450
459
|
to: wallet.address,
|
|
451
|
-
value:
|
|
460
|
+
value: constants_1.Zero,
|
|
452
461
|
gasLimit: newGasValues.gasLimit,
|
|
453
462
|
gasPrice: newGasValues.gasPrice,
|
|
454
463
|
};
|
|
@@ -498,7 +507,7 @@ class EthereumTransactions {
|
|
|
498
507
|
chainId: activeNetwork.chainId,
|
|
499
508
|
type: 2,
|
|
500
509
|
};
|
|
501
|
-
const rawTx =
|
|
510
|
+
const rawTx = (0, transactions_1.serialize)(txFormattedForEthers);
|
|
502
511
|
const signature = await this.ledgerSigner.evm.signEVMTransaction({
|
|
503
512
|
rawTx: rawTx.replace('0x', ''),
|
|
504
513
|
accountIndex: activeAccountId,
|
|
@@ -510,7 +519,7 @@ class EthereumTransactions {
|
|
|
510
519
|
};
|
|
511
520
|
if (signature) {
|
|
512
521
|
try {
|
|
513
|
-
const signedTx =
|
|
522
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, formattedSignature);
|
|
514
523
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
515
524
|
return finalTx;
|
|
516
525
|
}
|
|
@@ -613,7 +622,7 @@ class EthereumTransactions {
|
|
|
613
622
|
type: 2,
|
|
614
623
|
};
|
|
615
624
|
signature.payload.v = parseInt(signature.payload.v, 16); //v parameter must be a number by ethers standards
|
|
616
|
-
const signedTx =
|
|
625
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, signature.payload);
|
|
617
626
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
618
627
|
return finalTx;
|
|
619
628
|
}
|
|
@@ -633,7 +642,7 @@ class EthereumTransactions {
|
|
|
633
642
|
throw new Error(`Account state mismatch detected during transaction. Expected ${activeAccount.address} but got ${address}. Please wait for account switching to complete and try again.`);
|
|
634
643
|
}
|
|
635
644
|
const tx = params;
|
|
636
|
-
const wallet = new
|
|
645
|
+
const wallet = new wallet_1.Wallet(decryptedPrivateKey, this.web3Provider);
|
|
637
646
|
try {
|
|
638
647
|
const transaction = await wallet.sendTransaction(tx);
|
|
639
648
|
const response = await this.web3Provider.getTransaction(transaction.hash);
|
|
@@ -667,7 +676,7 @@ class EthereumTransactions {
|
|
|
667
676
|
};
|
|
668
677
|
}
|
|
669
678
|
const { decryptedPrivateKey, address } = this.getDecryptedPrivateKey();
|
|
670
|
-
const wallet = new
|
|
679
|
+
const wallet = new wallet_1.Wallet(decryptedPrivateKey, this.web3Provider);
|
|
671
680
|
// Check if this might be a max send transaction by comparing total cost to balance
|
|
672
681
|
const currentBalance = await this.web3Provider.getBalance(address);
|
|
673
682
|
// Ensure all transaction values are resolved from promises
|
|
@@ -714,7 +723,7 @@ class EthereumTransactions {
|
|
|
714
723
|
// For non-contract calls, reduce value to fit within balance
|
|
715
724
|
adjustedValue = currentBalance.sub(newGasCost);
|
|
716
725
|
// Ensure we don't go below a minimum threshold (0.0001 ETH)
|
|
717
|
-
const minValue =
|
|
726
|
+
const minValue = (0, units_1.parseEther)('0.0001');
|
|
718
727
|
if (adjustedValue.lt(minValue)) {
|
|
719
728
|
console.warn('[SpeedUp] Adjusted value too low, keeping original');
|
|
720
729
|
adjustedValue = txValue;
|
|
@@ -751,7 +760,7 @@ class EthereumTransactions {
|
|
|
751
760
|
// For non-contract calls, reduce value to fit within balance
|
|
752
761
|
adjustedValue = currentBalance.sub(newGasCost);
|
|
753
762
|
// Ensure we don't go below a minimum threshold (0.0001 ETH)
|
|
754
|
-
const minValue =
|
|
763
|
+
const minValue = (0, units_1.parseEther)('0.0001');
|
|
755
764
|
if (adjustedValue.lt(minValue)) {
|
|
756
765
|
console.warn('[SpeedUp] Adjusted value too low, keeping original');
|
|
757
766
|
adjustedValue = txValue;
|
|
@@ -799,9 +808,9 @@ class EthereumTransactions {
|
|
|
799
808
|
this.sendTransaction = async ({ sender, receivingAddress, amount, gasLimit, token, }) => {
|
|
800
809
|
const tokenDecimals = token && token.decimals ? token.decimals : 18;
|
|
801
810
|
const decimals = this.toBigNumber(tokenDecimals);
|
|
802
|
-
const parsedAmount =
|
|
811
|
+
const parsedAmount = (0, units_1.parseEther)(String(amount));
|
|
803
812
|
const { decryptedPrivateKey } = this.getDecryptedPrivateKey();
|
|
804
|
-
const wallet = new
|
|
813
|
+
const wallet = new wallet_1.Wallet(decryptedPrivateKey, this.web3Provider);
|
|
805
814
|
const value = token && token.contract_address
|
|
806
815
|
? parsedAmount.mul(this.toBigNumber('10').pow(decimals))
|
|
807
816
|
: parsedAmount;
|
|
@@ -845,13 +854,13 @@ class EthereumTransactions {
|
|
|
845
854
|
const { accounts, activeAccountType, activeAccountId, activeNetwork } = this.getState();
|
|
846
855
|
const { address: activeAccountAddress } = accounts[activeAccountType][activeAccountId];
|
|
847
856
|
const sendERC20Token = async () => {
|
|
848
|
-
const currentWallet = new
|
|
857
|
+
const currentWallet = new wallet_1.Wallet(decryptedPrivateKey);
|
|
849
858
|
const walletSigned = currentWallet.connect(this.web3Provider);
|
|
850
859
|
try {
|
|
851
|
-
const _contract = new
|
|
852
|
-
const calculatedTokenAmount =
|
|
853
|
-
?
|
|
854
|
-
:
|
|
860
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc20Abi)(), walletSigned);
|
|
861
|
+
const calculatedTokenAmount = bignumber_1.BigNumber.from(decimals
|
|
862
|
+
? (0, units_1.parseUnits)(tokenAmount, this.toBigNumber(decimals))
|
|
863
|
+
: (0, units_1.parseEther)(tokenAmount));
|
|
855
864
|
let transferMethod;
|
|
856
865
|
if (isLegacy) {
|
|
857
866
|
const overrides = {
|
|
@@ -880,8 +889,8 @@ class EthereumTransactions {
|
|
|
880
889
|
const signer = this.web3Provider.getSigner(activeAccountAddress);
|
|
881
890
|
const transactionNonce = await this.getRecommendedNonce(activeAccountAddress);
|
|
882
891
|
try {
|
|
883
|
-
const _contract = new
|
|
884
|
-
const calculatedTokenAmount =
|
|
892
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc20Abi)(), signer);
|
|
893
|
+
const calculatedTokenAmount = bignumber_1.BigNumber.from((0, units_1.parseEther)(tokenAmount));
|
|
885
894
|
const txData = _contract.interface.encodeFunctionData('transfer', [
|
|
886
895
|
receiver,
|
|
887
896
|
calculatedTokenAmount,
|
|
@@ -914,7 +923,7 @@ class EthereumTransactions {
|
|
|
914
923
|
type: 2,
|
|
915
924
|
};
|
|
916
925
|
}
|
|
917
|
-
const rawTx =
|
|
926
|
+
const rawTx = (0, transactions_1.serialize)(txFormattedForEthers);
|
|
918
927
|
const signature = await this.ledgerSigner.evm.signEVMTransaction({
|
|
919
928
|
rawTx: rawTx.replace('0x', ''),
|
|
920
929
|
accountIndex: activeAccountId,
|
|
@@ -926,7 +935,7 @@ class EthereumTransactions {
|
|
|
926
935
|
};
|
|
927
936
|
if (signature) {
|
|
928
937
|
try {
|
|
929
|
-
const signedTx =
|
|
938
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, formattedSignature);
|
|
930
939
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
931
940
|
saveTrezorTx && saveTrezorTx(finalTx);
|
|
932
941
|
return finalTx;
|
|
@@ -947,8 +956,8 @@ class EthereumTransactions {
|
|
|
947
956
|
const signer = this.web3Provider.getSigner(activeAccountAddress);
|
|
948
957
|
const transactionNonce = await this.getRecommendedNonce(activeAccountAddress);
|
|
949
958
|
try {
|
|
950
|
-
const _contract = new
|
|
951
|
-
const calculatedTokenAmount =
|
|
959
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc20Abi)(), signer);
|
|
960
|
+
const calculatedTokenAmount = bignumber_1.BigNumber.from((0, units_1.parseEther)(tokenAmount));
|
|
952
961
|
const txData = _contract.interface.encodeFunctionData('transfer', [
|
|
953
962
|
receiver,
|
|
954
963
|
calculatedTokenAmount,
|
|
@@ -1019,7 +1028,7 @@ class EthereumTransactions {
|
|
|
1019
1028
|
};
|
|
1020
1029
|
}
|
|
1021
1030
|
signature.payload.v = parseInt(signature.payload.v, 16); //v parameter must be a number by ethers standards
|
|
1022
|
-
const signedTx =
|
|
1031
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, signature.payload);
|
|
1023
1032
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
1024
1033
|
saveTrezorTx && saveTrezorTx(finalTx);
|
|
1025
1034
|
return finalTx;
|
|
@@ -1050,11 +1059,11 @@ class EthereumTransactions {
|
|
|
1050
1059
|
const { accounts, activeAccountType, activeAccountId, activeNetwork } = this.getState();
|
|
1051
1060
|
const { address: activeAccountAddress } = accounts[activeAccountType][activeAccountId];
|
|
1052
1061
|
const sendERC721Token = async () => {
|
|
1053
|
-
const currentWallet = new
|
|
1062
|
+
const currentWallet = new wallet_1.Wallet(decryptedPrivateKey);
|
|
1054
1063
|
const walletSigned = currentWallet.connect(this.web3Provider);
|
|
1055
1064
|
let transferMethod;
|
|
1056
1065
|
try {
|
|
1057
|
-
const _contract = new
|
|
1066
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc21Abi)(), walletSigned);
|
|
1058
1067
|
if (isLegacy) {
|
|
1059
1068
|
const overrides = {
|
|
1060
1069
|
nonce: await this.web3Provider.getTransactionCount(walletSigned.address, 'pending'),
|
|
@@ -1079,7 +1088,7 @@ class EthereumTransactions {
|
|
|
1079
1088
|
const signer = this.web3Provider.getSigner(activeAccountAddress);
|
|
1080
1089
|
const transactionNonce = await this.getRecommendedNonce(activeAccountAddress);
|
|
1081
1090
|
try {
|
|
1082
|
-
const _contract = new
|
|
1091
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc21Abi)(), signer);
|
|
1083
1092
|
const txData = _contract.interface.encodeFunctionData('transferFrom', [
|
|
1084
1093
|
activeAccountAddress,
|
|
1085
1094
|
receiver,
|
|
@@ -1113,7 +1122,7 @@ class EthereumTransactions {
|
|
|
1113
1122
|
type: 2,
|
|
1114
1123
|
};
|
|
1115
1124
|
}
|
|
1116
|
-
const rawTx =
|
|
1125
|
+
const rawTx = (0, transactions_1.serialize)(txFormattedForEthers);
|
|
1117
1126
|
const signature = await this.ledgerSigner.evm.signEVMTransaction({
|
|
1118
1127
|
rawTx: rawTx.replace('0x', ''),
|
|
1119
1128
|
accountIndex: activeAccountId,
|
|
@@ -1125,7 +1134,7 @@ class EthereumTransactions {
|
|
|
1125
1134
|
};
|
|
1126
1135
|
if (signature) {
|
|
1127
1136
|
try {
|
|
1128
|
-
const signedTx =
|
|
1137
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, formattedSignature);
|
|
1129
1138
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
1130
1139
|
return finalTx;
|
|
1131
1140
|
}
|
|
@@ -1145,7 +1154,7 @@ class EthereumTransactions {
|
|
|
1145
1154
|
const signer = this.web3Provider.getSigner(activeAccountAddress);
|
|
1146
1155
|
const transactionNonce = await this.getRecommendedNonce(activeAccountAddress);
|
|
1147
1156
|
try {
|
|
1148
|
-
const _contract = new
|
|
1157
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc21Abi)(), signer);
|
|
1149
1158
|
const txData = _contract.interface.encodeFunctionData('transferFrom', [
|
|
1150
1159
|
activeAccountAddress,
|
|
1151
1160
|
receiver,
|
|
@@ -1220,7 +1229,7 @@ class EthereumTransactions {
|
|
|
1220
1229
|
};
|
|
1221
1230
|
}
|
|
1222
1231
|
signature.payload.v = parseInt(signature.payload.v, 16); //v parameter must be a number by ethers standards
|
|
1223
|
-
const signedTx =
|
|
1232
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, signature.payload);
|
|
1224
1233
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
1225
1234
|
return finalTx;
|
|
1226
1235
|
}
|
|
@@ -1252,11 +1261,11 @@ class EthereumTransactions {
|
|
|
1252
1261
|
const { accounts, activeAccountType, activeAccountId, activeNetwork } = this.getState();
|
|
1253
1262
|
const { address: activeAccountAddress } = accounts[activeAccountType][activeAccountId];
|
|
1254
1263
|
const sendERC1155Token = async () => {
|
|
1255
|
-
const currentWallet = new
|
|
1264
|
+
const currentWallet = new wallet_1.Wallet(decryptedPrivateKey);
|
|
1256
1265
|
const walletSigned = currentWallet.connect(this.web3Provider);
|
|
1257
1266
|
let transferMethod;
|
|
1258
1267
|
try {
|
|
1259
|
-
const _contract = new
|
|
1268
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc55Abi)(), walletSigned);
|
|
1260
1269
|
const amount = tokenAmount ? parseInt(tokenAmount) : 1;
|
|
1261
1270
|
const overrides = {};
|
|
1262
1271
|
transferMethod = await _contract.safeTransferFrom(walletSigned.address, receiver, tokenId, amount, [], overrides);
|
|
@@ -1270,7 +1279,7 @@ class EthereumTransactions {
|
|
|
1270
1279
|
const signer = this.web3Provider.getSigner(activeAccountAddress);
|
|
1271
1280
|
const transactionNonce = await this.getRecommendedNonce(activeAccountAddress);
|
|
1272
1281
|
try {
|
|
1273
|
-
const _contract = new
|
|
1282
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc55Abi)(), signer);
|
|
1274
1283
|
const amount = tokenAmount ? parseInt(tokenAmount) : 1;
|
|
1275
1284
|
const txData = _contract.interface.encodeFunctionData('safeTransferFrom', [activeAccountAddress, receiver, tokenId, amount, []]);
|
|
1276
1285
|
// Use fallback gas limit if not provided (for auto-estimation)
|
|
@@ -1301,7 +1310,7 @@ class EthereumTransactions {
|
|
|
1301
1310
|
type: 2,
|
|
1302
1311
|
};
|
|
1303
1312
|
}
|
|
1304
|
-
const rawTx =
|
|
1313
|
+
const rawTx = (0, transactions_1.serialize)(txFormattedForEthers);
|
|
1305
1314
|
const signature = await this.ledgerSigner.evm.signEVMTransaction({
|
|
1306
1315
|
rawTx: rawTx.replace('0x', ''),
|
|
1307
1316
|
accountIndex: activeAccountId,
|
|
@@ -1313,7 +1322,7 @@ class EthereumTransactions {
|
|
|
1313
1322
|
};
|
|
1314
1323
|
if (signature) {
|
|
1315
1324
|
try {
|
|
1316
|
-
const signedTx =
|
|
1325
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, formattedSignature);
|
|
1317
1326
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
1318
1327
|
return finalTx;
|
|
1319
1328
|
}
|
|
@@ -1333,7 +1342,7 @@ class EthereumTransactions {
|
|
|
1333
1342
|
const signer = this.web3Provider.getSigner(activeAccountAddress);
|
|
1334
1343
|
const transactionNonce = await this.getRecommendedNonce(activeAccountAddress);
|
|
1335
1344
|
try {
|
|
1336
|
-
const _contract = new
|
|
1345
|
+
const _contract = new contracts_1.Contract(tokenAddress, (0, sysweb3_utils_1.getErc55Abi)(), signer);
|
|
1337
1346
|
const amount = tokenAmount ? parseInt(tokenAmount) : 1;
|
|
1338
1347
|
const txData = _contract.interface.encodeFunctionData('safeTransferFrom', [activeAccountAddress, receiver, tokenId, amount, []]);
|
|
1339
1348
|
// Use fallback gas limit if not provided (for auto-estimation)
|
|
@@ -1402,7 +1411,7 @@ class EthereumTransactions {
|
|
|
1402
1411
|
};
|
|
1403
1412
|
}
|
|
1404
1413
|
signature.payload.v = parseInt(signature.payload.v, 16); //v parameter must be a number by ethers standards
|
|
1405
|
-
const signedTx =
|
|
1414
|
+
const signedTx = (0, transactions_1.serialize)(txFormattedForEthers, signature.payload);
|
|
1406
1415
|
const finalTx = await this.web3Provider.sendTransaction(signedTx);
|
|
1407
1416
|
return finalTx;
|
|
1408
1417
|
}
|
|
@@ -1440,12 +1449,12 @@ class EthereumTransactions {
|
|
|
1440
1449
|
this.getFeeByType = async (type) => {
|
|
1441
1450
|
const gasPrice = (await this.getRecommendedGasPrice(false));
|
|
1442
1451
|
const low = this.toBigNumber(gasPrice)
|
|
1443
|
-
.mul(
|
|
1444
|
-
.div(
|
|
1452
|
+
.mul(bignumber_1.BigNumber.from('8'))
|
|
1453
|
+
.div(bignumber_1.BigNumber.from('10'))
|
|
1445
1454
|
.toString();
|
|
1446
1455
|
const high = this.toBigNumber(gasPrice)
|
|
1447
|
-
.mul(
|
|
1448
|
-
.div(
|
|
1456
|
+
.mul(bignumber_1.BigNumber.from('11'))
|
|
1457
|
+
.div(bignumber_1.BigNumber.from('10'))
|
|
1449
1458
|
.toString();
|
|
1450
1459
|
if (type === 'low')
|
|
1451
1460
|
return low;
|
|
@@ -1458,7 +1467,7 @@ class EthereumTransactions {
|
|
|
1458
1467
|
const estimated = await this.web3Provider.estimateGas({
|
|
1459
1468
|
to: toAddress,
|
|
1460
1469
|
});
|
|
1461
|
-
return Number(
|
|
1470
|
+
return Number((0, units_1.formatUnits)(estimated, 'gwei'));
|
|
1462
1471
|
}
|
|
1463
1472
|
catch (error) {
|
|
1464
1473
|
throw error;
|
|
@@ -1477,8 +1486,8 @@ class EthereumTransactions {
|
|
|
1477
1486
|
const gasPriceBN = await this.web3Provider.getGasPrice();
|
|
1478
1487
|
if (formatted) {
|
|
1479
1488
|
return {
|
|
1480
|
-
gwei: Number(
|
|
1481
|
-
ethers:
|
|
1489
|
+
gwei: Number((0, units_1.formatUnits)(gasPriceBN, 'gwei')).toFixed(2),
|
|
1490
|
+
ethers: (0, units_1.formatEther)(gasPriceBN),
|
|
1482
1491
|
};
|
|
1483
1492
|
}
|
|
1484
1493
|
return gasPriceBN.toString();
|
|
@@ -1490,7 +1499,7 @@ class EthereumTransactions {
|
|
|
1490
1499
|
this.getBalance = async (address) => {
|
|
1491
1500
|
try {
|
|
1492
1501
|
const balance = await this.web3Provider.getBalance(address);
|
|
1493
|
-
const formattedBalance =
|
|
1502
|
+
const formattedBalance = (0, units_1.formatEther)(balance);
|
|
1494
1503
|
return parseFloat(formattedBalance); // Return full precision
|
|
1495
1504
|
}
|
|
1496
1505
|
catch (error) {
|
|
@@ -1505,11 +1514,11 @@ class EthereumTransactions {
|
|
|
1505
1514
|
};
|
|
1506
1515
|
};
|
|
1507
1516
|
this.importAccount = (mnemonicOrPrivKey) => {
|
|
1508
|
-
if (
|
|
1509
|
-
return new
|
|
1517
|
+
if ((0, bytes_1.isHexString)(mnemonicOrPrivKey)) {
|
|
1518
|
+
return new wallet_1.Wallet(mnemonicOrPrivKey);
|
|
1510
1519
|
}
|
|
1511
|
-
const { privateKey } =
|
|
1512
|
-
const account = new
|
|
1520
|
+
const { privateKey } = wallet_1.Wallet.fromMnemonic(mnemonicOrPrivKey);
|
|
1521
|
+
const account = new wallet_1.Wallet(privateKey);
|
|
1513
1522
|
return account;
|
|
1514
1523
|
};
|
|
1515
1524
|
this.getNetwork = getNetwork;
|