@toruslabs/ethereum-controllers 8.17.1 → 9.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.
Files changed (61) hide show
  1. package/dist/lib.cjs/Account/AccountTrackerController.js +15 -7
  2. package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +4 -6
  3. package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
  4. package/dist/lib.cjs/Eip5792/walletSendCalls.js +6 -7
  5. package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
  6. package/dist/lib.cjs/Gas/GasFeeController.js +3 -2
  7. package/dist/lib.cjs/Keyring/KeyringController.js +69 -40
  8. package/dist/lib.cjs/Message/utils.js +15 -14
  9. package/dist/lib.cjs/Nfts/NftHandler.js +54 -12
  10. package/dist/lib.cjs/Nfts/NftsController.js +1 -4
  11. package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
  12. package/dist/lib.cjs/Tokens/TokenHandler.js +39 -7
  13. package/dist/lib.cjs/Tokens/TokensController.js +15 -7
  14. package/dist/lib.cjs/Transaction/TransactionController.js +17 -20
  15. package/dist/lib.cjs/Transaction/TransactionGasUtil.js +11 -12
  16. package/dist/lib.cjs/Transaction/TransactionUtils.js +44 -39
  17. package/dist/lib.cjs/types/Account/AccountTrackerController.d.ts +1 -1
  18. package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +1 -3
  19. package/dist/lib.cjs/types/Keyring/KeyringController.d.ts +4 -4
  20. package/dist/lib.cjs/types/Nfts/NftHandler.d.ts +4 -3
  21. package/dist/lib.cjs/types/Nfts/NftsController.d.ts +0 -1
  22. package/dist/lib.cjs/types/Tokens/TokenHandler.d.ts +4 -3
  23. package/dist/lib.cjs/types/Tokens/TokensController.d.ts +1 -1
  24. package/dist/lib.cjs/types/Transaction/TransactionUtils.d.ts +11 -3
  25. package/dist/lib.cjs/types/utils/abis.d.ts +544 -99
  26. package/dist/lib.cjs/types/utils/hex.d.ts +9 -0
  27. package/dist/lib.cjs/types/utils/interfaces.d.ts +205 -2
  28. package/dist/lib.cjs/types/utils/transaction.d.ts +1 -1
  29. package/dist/lib.cjs/types/utils/viem.d.ts +8 -0
  30. package/dist/lib.cjs/utils/abis.js +12 -0
  31. package/dist/lib.cjs/utils/conversionUtils.js +3 -4
  32. package/dist/lib.cjs/utils/helpers.js +9 -8
  33. package/dist/lib.cjs/utils/hex.js +23 -0
  34. package/dist/lib.cjs/utils/transaction.js +7 -11
  35. package/dist/lib.cjs/utils/viem.js +214 -0
  36. package/dist/lib.esm/Account/AccountTrackerController.js +15 -7
  37. package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +5 -7
  38. package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +1 -1
  39. package/dist/lib.esm/Eip5792/walletSendCalls.js +6 -7
  40. package/dist/lib.esm/Eip7702/eip7702Utils.js +1 -1
  41. package/dist/lib.esm/Gas/GasFeeController.js +3 -2
  42. package/dist/lib.esm/Keyring/KeyringController.js +68 -40
  43. package/dist/lib.esm/Message/utils.js +13 -12
  44. package/dist/lib.esm/Nfts/NftHandler.js +54 -12
  45. package/dist/lib.esm/Nfts/NftsController.js +1 -4
  46. package/dist/lib.esm/Preferences/PreferencesController.js +1 -1
  47. package/dist/lib.esm/Tokens/TokenHandler.js +39 -7
  48. package/dist/lib.esm/Tokens/TokensController.js +15 -7
  49. package/dist/lib.esm/Transaction/TransactionController.js +6 -9
  50. package/dist/lib.esm/Transaction/TransactionGasUtil.js +11 -12
  51. package/dist/lib.esm/Transaction/TransactionUtils.js +28 -24
  52. package/dist/lib.esm/utils/abis.js +12 -0
  53. package/dist/lib.esm/utils/conversionUtils.js +2 -3
  54. package/dist/lib.esm/utils/helpers.js +6 -5
  55. package/dist/lib.esm/utils/hex.js +21 -0
  56. package/dist/lib.esm/utils/interfaces.js +64 -0
  57. package/dist/lib.esm/utils/transaction.js +7 -11
  58. package/dist/lib.esm/utils/viem.js +214 -0
  59. package/package.json +13 -18
  60. package/dist/ethereumControllers.umd.min.js +0 -2
  61. package/dist/ethereumControllers.umd.min.js.LICENSE.txt +0 -50
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var ethers = require('ethers');
5
4
  var log = require('loglevel');
5
+ var viem = require('viem');
6
6
  var abis = require('../utils/abis.js');
7
7
 
8
8
  class TokenHandler {
@@ -17,20 +17,38 @@ class TokenHandler {
17
17
  _defineProperty(this, "symbol", void 0);
18
18
  _defineProperty(this, "decimals", void 0);
19
19
  _defineProperty(this, "name", void 0);
20
- _defineProperty(this, "contract", void 0);
20
+ _defineProperty(this, "provider", void 0);
21
+ _defineProperty(this, "publicClient", void 0);
21
22
  this.address = address;
22
- this.contract = new ethers.Contract(address, abis.erc20Abi, provider);
23
+ this.provider = provider;
24
+ this.publicClient = viem.createPublicClient({
25
+ transport: viem.custom(this.provider)
26
+ });
23
27
  this.symbol = symbol;
24
28
  this.decimals = decimals;
25
29
  this.name = name;
26
30
  }
27
31
  async getSymbol() {
28
- if (!this.symbol || this.symbol === "ERC20") this.symbol = await this.contract.symbol();
32
+ if (!this.symbol || this.symbol === "ERC20") {
33
+ this.symbol = await this.publicClient.readContract({
34
+ address: this.address,
35
+ abi: abis.erc20Abi,
36
+ functionName: "symbol",
37
+ authorizationList: undefined
38
+ });
39
+ }
29
40
  return this.symbol;
30
41
  }
31
42
  async getDecimals() {
32
43
  try {
33
- if (!this.decimals) this.decimals = await this.contract.decimals();
44
+ if (!this.decimals) {
45
+ this.decimals = Number(await this.publicClient.readContract({
46
+ address: this.address,
47
+ abi: abis.erc20Abi,
48
+ functionName: "decimals",
49
+ authorizationList: undefined
50
+ }));
51
+ }
34
52
  return this.decimals;
35
53
  } catch (error) {
36
54
  log.warn(`Could not get decimals for token ${this.address}`, error);
@@ -38,12 +56,26 @@ class TokenHandler {
38
56
  }
39
57
  }
40
58
  async getName() {
41
- if (!this.name) this.name = await this.contract.name();
59
+ if (!this.name) {
60
+ const name = await this.publicClient.readContract({
61
+ address: this.address,
62
+ abi: abis.erc20Abi,
63
+ functionName: "name",
64
+ authorizationList: undefined
65
+ });
66
+ this.name = name;
67
+ }
42
68
  return this.name;
43
69
  }
44
70
  async getUserBalance(userAddress) {
45
71
  if (!this.decimals) await this.getDecimals();
46
- const balance = await this.contract.balanceOf(userAddress);
72
+ const balance = await this.publicClient.readContract({
73
+ address: this.address,
74
+ abi: abis.erc20Abi,
75
+ functionName: "balanceOf",
76
+ args: [userAddress],
77
+ authorizationList: undefined
78
+ });
47
79
  return balance.toString(16);
48
80
  }
49
81
  }
@@ -3,8 +3,8 @@
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
5
  var baseControllers = require('@toruslabs/base-controllers');
6
- var ethers = require('ethers');
7
6
  var log = require('loglevel');
7
+ var viem = require('viem');
8
8
  var abis = require('../utils/abis.js');
9
9
  var constants = require('../utils/constants.js');
10
10
  var contractAddresses = require('../utils/contractAddresses.js');
@@ -29,13 +29,15 @@ class TokensController extends baseControllers.BaseController {
29
29
  });
30
30
  _defineProperty(this, "name", "TokensController");
31
31
  _defineProperty(this, "provider", void 0);
32
- _defineProperty(this, "ethersProvider", void 0);
32
+ _defineProperty(this, "publicClient", void 0);
33
33
  _defineProperty(this, "pollingManager", void 0);
34
34
  _defineProperty(this, "getProviderConfig", void 0);
35
35
  _defineProperty(this, "getCustomTokens", void 0);
36
36
  _defineProperty(this, "getEtherScanTokens", void 0);
37
37
  this.provider = provider;
38
- this.ethersProvider = new ethers.BrowserProvider(this.provider, "any");
38
+ this.publicClient = viem.createPublicClient({
39
+ transport: viem.custom(this.provider)
40
+ });
39
41
  this.getCustomTokens = getCustomTokens;
40
42
  this.getEtherScanTokens = getEtherScanTokens;
41
43
  this.getProviderConfig = getProviderConfig;
@@ -167,10 +169,16 @@ class TokensController extends baseControllers.BaseController {
167
169
  const remainingTokensAddresses = remainingTokens.map(x => x.tokenAddress);
168
170
  const currentSingleCallAddress = contractAddresses.SINGLE_CALL_BALANCES_ADDRESSES[currentChainId];
169
171
  if (currentSingleCallAddress) {
170
- const ethContract = new ethers.Contract(currentSingleCallAddress, abis.singleBalanceCheckerAbi, this.ethersProvider);
171
- const result = await ethContract.balances([userAddress], remainingTokensAddresses);
172
+ const result = await this.publicClient.readContract({
173
+ address: currentSingleCallAddress,
174
+ abi: abis.singleBalanceCheckerAbi,
175
+ functionName: "balances",
176
+ args: [[userAddress], remainingTokensAddresses],
177
+ authorizationList: undefined
178
+ });
172
179
  remainingTokensAddresses.forEach((_, index) => {
173
- const balance = ethers.toQuantity(result[index]);
180
+ var _result$index;
181
+ const balance = viem.toHex((_result$index = result[index]) !== null && _result$index !== void 0 ? _result$index : 0n);
174
182
  if (balance && balance !== "0x0") {
175
183
  nonZeroTokens.push(_objectSpread(_objectSpread({}, remainingTokens[index]), {}, {
176
184
  balance,
@@ -208,7 +216,7 @@ class TokensController extends baseControllers.BaseController {
208
216
  decimals: Number.parseInt(x.decimals),
209
217
  name: x.name,
210
218
  symbol: x.symbol,
211
- provider: this.ethersProvider
219
+ provider: this.provider
212
220
  });
213
221
  const balance = await tokenInstance.getUserBalance(this.userSelectedAddress);
214
222
  return {
@@ -2,13 +2,12 @@
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- var util = require('@ethereumjs/util');
6
5
  var baseControllers = require('@toruslabs/base-controllers');
7
6
  var auth = require('@web3auth/auth');
8
7
  var bignumber_js = require('bignumber.js');
9
- var ethers = require('ethers');
10
8
  var log = require('loglevel');
11
9
  var viem = require('viem');
10
+ var hex = require('../utils/hex.js');
12
11
  var eip7702Utils = require('../Eip7702/eip7702Utils.js');
13
12
  var walletSendCalls = require('../Eip5792/walletSendCalls.js');
14
13
  var constants = require('../utils/constants.js');
@@ -131,7 +130,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
131
130
  }
132
131
  txParams.authorizationList = [{
133
132
  address: delegationAddress,
134
- chainId: util.addHexPrefix(chainId)
133
+ chainId: hex.addHexPrefix(chainId)
135
134
  }];
136
135
  txParams.type = constants.TRANSACTION_ENVELOPE_TYPES.SET_CODE;
137
136
  }
@@ -182,7 +181,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
182
181
  // higher gas settings and therefor the nonce should not be recalculated
183
182
  const nonce = nonceLock.nextNonce;
184
183
  const customOrNonce = customNonceValueNumber === 0 ? customNonceValue : customNonceValue || nonce;
185
- txMeta.transaction.nonce = util.addHexPrefix(customOrNonce.toString(16));
184
+ txMeta.transaction.nonce = hex.addHexPrefix(customOrNonce.toString(16));
186
185
  // add nonce debugging information to txMeta
187
186
  txMeta.nonceDetails = nonceLock.nonceDetails;
188
187
  this.updateTransactionInState(txMeta, "transactions#approveTransaction");
@@ -245,20 +244,19 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
245
244
  address: signedAuthorization.address,
246
245
  chainId: BigInt(signedAuthorization.chainId),
247
246
  nonce: BigInt(signedAuthorization.nonce),
248
- signature: ethers.Signature.from({
247
+ signature: {
249
248
  r: signedAuthorization.r,
250
249
  s: signedAuthorization.s,
251
250
  yParity: parseInt(signedAuthorization.yParity, 16)
252
- })
251
+ }
253
252
  });
254
253
  }
255
254
  txMeta.transaction.authorizationList = signedAuthorizations;
256
255
  }
257
- const tx = ethers.Transaction.from(txParams);
258
- const signedEthTx = await this.signEthTx(tx, fromAddress);
256
+ const signedEthTx = await this.signEthTx(txParams, fromAddress);
259
257
  txMeta.r = signedEthTx.signature.r;
260
258
  txMeta.s = signedEthTx.signature.s;
261
- txMeta.v = util.addHexPrefix(signedEthTx.signature.v.toString(16));
259
+ txMeta.v = signedEthTx.signature.v != null ? viem.toHex(signedEthTx.signature.v) : undefined;
262
260
  const rawTx = signedEthTx.serialized;
263
261
  txMeta.rawTransaction = rawTx;
264
262
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values and rawTx");
@@ -276,8 +274,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
276
274
  });
277
275
  } catch (error) {
278
276
  if (error.message.toLowerCase().includes("known transaction")) {
279
- txHash = ethers.keccak256(util.addHexPrefix(rawTx));
280
- txHash = util.addHexPrefix(txHash);
277
+ txHash = viem.keccak256(hex.addHexPrefix(rawTx));
281
278
  } else {
282
279
  throw error;
283
280
  }
@@ -353,7 +350,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
353
350
  txMeta.transaction.maxFeePerGas = txMeta.transaction.gasPrice;
354
351
  // If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas
355
352
  // then we set maxFeePerGas to the suggested gasPrice.
356
- txMeta.transaction.maxPriorityFeePerGas = helpers.bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? util.stripHexPrefix(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? util.stripHexPrefix(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
353
+ txMeta.transaction.maxPriorityFeePerGas = helpers.bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? hex.stripHexPrefix(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? hex.stripHexPrefix(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
357
354
  } else {
358
355
  if (defaultMaxFeePerGas && !txMeta.transaction.maxFeePerGas) {
359
356
  // If the dapp has not set the gasPrice or the maxFeePerGas, then we set maxFeePerGas
@@ -425,8 +422,8 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
425
422
  if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
426
423
  return {
427
424
  // send to controller in hex wei
428
- maxFeePerGas: util.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxFeePerGas)).toString(16)),
429
- maxPriorityFeePerGas: util.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
425
+ maxFeePerGas: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxFeePerGas)).toString(16)),
426
+ maxPriorityFeePerGas: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
430
427
  };
431
428
  }
432
429
  } else if (gasEstimateType === constants.GAS_ESTIMATE_TYPES.LEGACY) {
@@ -436,7 +433,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
436
433
  // The LEGACY type includes low, medium and high estimates of
437
434
  // gas price values.
438
435
  return {
439
- gasPrice: util.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(medium)).toString(16))
436
+ gasPrice: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(medium)).toString(16))
440
437
  };
441
438
  } else if (gasEstimateType === constants.GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
442
439
  const {
@@ -445,7 +442,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
445
442
  // The ETH_GASPRICE type just includes a single gas price property,
446
443
  // which we can assume was retrieved from eth_gasPrice
447
444
  return {
448
- gasPrice: util.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(gasPrice)).toString(16))
445
+ gasPrice: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(gasPrice)).toString(16))
449
446
  };
450
447
  }
451
448
  } catch (error) {
@@ -455,7 +452,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
455
452
  method: constants.METHOD_TYPES.ETH_GET_GAS_PRICE
456
453
  });
457
454
  return {
458
- gasPrice: gasPrice && util.addHexPrefix(gasPrice)
455
+ gasPrice: gasPrice && hex.addHexPrefix(gasPrice)
459
456
  };
460
457
  }
461
458
  async getDefaultGasLimit(txMeta) {
@@ -489,9 +486,9 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
489
486
  const baseMultiplier = 1.5;
490
487
  const perCallBuffer = 0.1;
491
488
  const eip7702UpgradeWithDataToSelfGasBufferMultiplier = baseMultiplier + perCallBuffer * batchCallsCount;
492
- gasLimit = this.txGasUtil.addGasBuffer(util.addHexPrefix(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
489
+ gasLimit = this.txGasUtil.addGasBuffer(hex.addHexPrefix(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
493
490
  } else {
494
- gasLimit = this.txGasUtil.addGasBuffer(util.addHexPrefix(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
491
+ gasLimit = this.txGasUtil.addGasBuffer(hex.addHexPrefix(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
495
492
  }
496
493
  return {
497
494
  gasLimit,
@@ -516,7 +513,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
516
513
  txMeta.methodParams = methodParams;
517
514
  txMeta.isUserOperation = req.isUserOperation;
518
515
  txMeta.isSignOnly = req.isSignOnly;
519
- txMeta.transaction.value = txMeta.transaction.value ? util.addHexPrefix(txMeta.transaction.value) : "0x0";
516
+ txMeta.transaction.value = txMeta.transaction.value ? hex.addHexPrefix(txMeta.transaction.value) : "0x0";
520
517
  txMeta.batchId = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.batchId;
521
518
  txMeta.nestedTransactions = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.nestedTransactions;
522
519
  this.emit(`${txMeta.id}:unapproved`, txMeta);
@@ -2,11 +2,10 @@
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- var util = require('@ethereumjs/util');
6
5
  var baseControllers = require('@toruslabs/base-controllers');
7
- var BN = require('bn.js');
8
6
  var log = require('loglevel');
9
7
  var eip7702Types = require('../utils/eip7702Types.js');
8
+ var hex = require('../utils/hex.js');
10
9
  var TransactionUtils = require('./TransactionUtils.js');
11
10
 
12
11
  class TransactionGasUtil {
@@ -19,9 +18,9 @@ class TransactionGasUtil {
19
18
  async analyzeGasUsage(txMeta) {
20
19
  const block = await this.blockTracker.getLatestBlock();
21
20
  // fallback to block gasLimit
22
- const blockGasLimitBN = new BN.BN(util.stripHexPrefix(block.gasLimit), 16);
23
- const saferGasLimitBN = blockGasLimitBN.mul(new BN.BN(19)).div(new BN.BN(20));
24
- let estimatedGasHex = util.addHexPrefix(saferGasLimitBN.toString("hex"));
21
+ const blockGasLimit = BigInt(hex.addHexPrefix(block.gasLimit));
22
+ const saferGasLimit = blockGasLimit * 19n / 20n;
23
+ let estimatedGasHex = hex.addHexPrefix(saferGasLimit.toString(16));
25
24
  let simulationFails;
26
25
  try {
27
26
  estimatedGasHex = await this.estimateTxGas(txMeta);
@@ -46,16 +45,16 @@ class TransactionGasUtil {
46
45
  Adds a gas buffer with out exceeding the block gas limit
47
46
  */
48
47
  addGasBuffer(initialGasLimitHex, blockGasLimitHex, multiplier = 1.5) {
49
- const initialGasLimitBn = new BN.BN(util.stripHexPrefix(initialGasLimitHex), 16);
50
- const blockGasLimitBn = new BN.BN(util.stripHexPrefix(blockGasLimitHex), 16);
51
- const upperGasLimitBn = blockGasLimitBn.muln(0.9);
52
- const bufferedGasLimitBn = initialGasLimitBn.muln(multiplier);
48
+ const initialGasLimit = BigInt(hex.addHexPrefix(initialGasLimitHex));
49
+ const blockGasLimit = BigInt(hex.addHexPrefix(blockGasLimitHex));
50
+ const upperGasLimit = blockGasLimit * 9n / 10n;
51
+ const bufferedGasLimit = initialGasLimit * BigInt(Math.round(multiplier * 10)) / 10n;
53
52
  // if initialGasLimit is above blockGasLimit, dont modify it
54
- if (initialGasLimitBn.gt(upperGasLimitBn)) return util.addHexPrefix(initialGasLimitBn.toString("hex"));
53
+ if (initialGasLimit > upperGasLimit) return hex.addHexPrefix(initialGasLimit.toString(16));
55
54
  // if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
56
- if (bufferedGasLimitBn.lt(upperGasLimitBn)) return util.addHexPrefix(bufferedGasLimitBn.toString("hex"));
55
+ if (bufferedGasLimit < upperGasLimit) return hex.addHexPrefix(bufferedGasLimit.toString(16));
57
56
  // otherwise use blockGasLimit
58
- return util.addHexPrefix(upperGasLimitBn.toString("hex"));
57
+ return hex.addHexPrefix(upperGasLimit.toString(16));
59
58
  }
60
59
  /**
61
60
  Estimates the tx's gas usage
@@ -1,34 +1,31 @@
1
1
  'use strict';
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var util = require('@ethereumjs/util');
5
4
  var baseControllers = require('@toruslabs/base-controllers');
6
5
  var auth = require('@web3auth/auth');
7
- var ethers = require('ethers');
8
6
  var log = require('loglevel');
7
+ var viem = require('viem');
9
8
  var abis = require('../utils/abis.js');
10
9
  var constants = require('../utils/constants.js');
10
+ var hex = require('../utils/hex.js');
11
11
 
12
- const erc20Interface = new ethers.Interface(abis.erc20Abi);
13
- const erc721Interface = new ethers.Interface(abis.erc721Abi);
14
- const erc1155Interface = new ethers.Interface(abis.erc1155Abi);
15
12
  const normalizers = {
16
- from: (from, LowerCase = true) => LowerCase ? util.addHexPrefix(from).toLowerCase() : util.addHexPrefix(from),
17
- to: (to, LowerCase = true) => LowerCase ? util.addHexPrefix(to).toLowerCase() : util.addHexPrefix(to),
18
- nonce: nonce => util.addHexPrefix(nonce),
19
- customNonceValue: nonce => util.addHexPrefix(nonce),
20
- value: value => util.addHexPrefix(value),
21
- data: data => util.addHexPrefix(data),
22
- gas: gas => util.addHexPrefix(gas),
23
- gasPrice: gasPrice => util.addHexPrefix(gasPrice),
24
- type: util.addHexPrefix,
25
- maxFeePerGas: util.addHexPrefix,
26
- maxPriorityFeePerGas: util.addHexPrefix,
27
- callGasLimit: util.addHexPrefix,
28
- preVerificationGas: util.addHexPrefix,
29
- verificationGasLimit: util.addHexPrefix,
30
- paymasterVerificationGasLimit: util.addHexPrefix,
31
- paymasterPostOpGasLimit: util.addHexPrefix,
13
+ from: (from, LowerCase = true) => LowerCase ? hex.addHexPrefix(from).toLowerCase() : hex.addHexPrefix(from),
14
+ to: (to, LowerCase = true) => LowerCase ? hex.addHexPrefix(to).toLowerCase() : hex.addHexPrefix(to),
15
+ nonce: nonce => hex.addHexPrefix(nonce),
16
+ customNonceValue: nonce => hex.addHexPrefix(nonce),
17
+ value: value => hex.addHexPrefix(value),
18
+ data: data => hex.addHexPrefix(data),
19
+ gas: gas => hex.addHexPrefix(gas),
20
+ gasPrice: gasPrice => hex.addHexPrefix(gasPrice),
21
+ type: hex.addHexPrefix,
22
+ maxFeePerGas: hex.addHexPrefix,
23
+ maxPriorityFeePerGas: hex.addHexPrefix,
24
+ callGasLimit: hex.addHexPrefix,
25
+ preVerificationGas: hex.addHexPrefix,
26
+ verificationGasLimit: hex.addHexPrefix,
27
+ paymasterVerificationGasLimit: hex.addHexPrefix,
28
+ paymasterPostOpGasLimit: hex.addHexPrefix,
32
29
  authorizationList: authorizationList => authorizationList
33
30
  };
34
31
  /**
@@ -62,7 +59,9 @@ function transactionMatchesNetwork(transaction, chainId) {
62
59
  */
63
60
  function isEIP1559Transaction(transaction) {
64
61
  var _transaction$transact, _transaction$transact2;
65
- return util.isHexString(util.addHexPrefix(transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas)) && util.isHexString(util.addHexPrefix(transaction === null || transaction === void 0 || (_transaction$transact2 = transaction.transaction) === null || _transaction$transact2 === void 0 ? void 0 : _transaction$transact2.maxPriorityFeePerGas));
62
+ const maxFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas;
63
+ const maxPriorityFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact2 = transaction.transaction) === null || _transaction$transact2 === void 0 ? void 0 : _transaction$transact2.maxPriorityFeePerGas;
64
+ return typeof maxFeePerGas === "string" && typeof maxPriorityFeePerGas === "string" && viem.isHex(hex.addHexPrefix(maxFeePerGas)) && viem.isHex(hex.addHexPrefix(maxPriorityFeePerGas));
66
65
  }
67
66
  /**
68
67
  * Determine if the maxFeePerGas and maxPriorityFeePerGas fields are not
@@ -74,7 +73,7 @@ function isEIP1559Transaction(transaction) {
74
73
  * EIP1559 fields
75
74
  */
76
75
  function isLegacyTransaction(transaction) {
77
- return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || util.isHexString(util.addHexPrefix(transaction.transaction.gasPrice)));
76
+ return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || viem.isHex(hex.addHexPrefix(transaction.transaction.gasPrice)));
78
77
  }
79
78
  /**
80
79
  * Given two fields, ensure that the second field is not included in txParams,
@@ -121,7 +120,7 @@ function validateFrom(txParams) {
121
120
  if (!(typeof txParams.from === "string")) {
122
121
  throw auth.rpcErrors.invalidParams(`Invalid "from" address "${txParams.from}": not a string.`);
123
122
  }
124
- if (!util.isValidAddress(txParams.from)) {
123
+ if (!viem.isAddress(txParams.from)) {
125
124
  throw auth.rpcErrors.invalidParams('Invalid "from" address.');
126
125
  }
127
126
  }
@@ -135,7 +134,7 @@ function validateRecipient(txParameters) {
135
134
  } else {
136
135
  throw auth.rpcErrors.invalidParams('Invalid "to" address.');
137
136
  }
138
- } else if (txParameters.to !== undefined && !util.isValidAddress(txParameters.to)) {
137
+ } else if (txParameters.to !== undefined && !viem.isAddress(txParameters.to)) {
139
138
  throw auth.rpcErrors.invalidParams('Invalid "to" address.');
140
139
  }
141
140
  return txParameters;
@@ -203,10 +202,10 @@ function validateTxParameters(txParams, eip1559Compatibility = true) {
203
202
  if (typeof authorization !== "object" || authorization === null) {
204
203
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: ${key} is not an object. got: (${authorization})`);
205
204
  }
206
- if (typeof authorization.address !== "string" || !util.isValidAddress(authorization.address)) {
205
+ if (typeof authorization.address !== "string" || !viem.isAddress(authorization.address)) {
207
206
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: authorization.address is not a valid address. got: (${authorization.address})`);
208
207
  }
209
- if (typeof authorization.chainId !== "string" || !util.isHexString(util.addHexPrefix(authorization.chainId))) {
208
+ if (typeof authorization.chainId !== "string" || !viem.isHex(hex.addHexPrefix(authorization.chainId))) {
210
209
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: authorization.chainId is not a valid hex string. got: (${authorization.chainId})`);
211
210
  }
212
211
  });
@@ -236,36 +235,42 @@ function getFinalStates() {
236
235
  }
237
236
  function parseStandardTokenTransactionData(data) {
238
237
  try {
239
- const txDesc = erc20Interface.parseTransaction({
240
- data
238
+ var _txDesc$args;
239
+ const txDesc = viem.decodeFunctionData({
240
+ abi: abis.erc20Abi,
241
+ data: data
241
242
  });
242
243
  if (txDesc) return {
243
- name: txDesc.name,
244
- methodParams: txDesc.args.toArray(),
244
+ name: txDesc.functionName,
245
+ methodParams: [...((_txDesc$args = txDesc.args) !== null && _txDesc$args !== void 0 ? _txDesc$args : [])],
245
246
  type: constants.CONTRACT_TYPE_ERC20
246
247
  };
247
248
  } catch {
248
249
  // ignore and next try to parse with erc721 ABI
249
250
  }
250
251
  try {
251
- const txDesc = erc721Interface.parseTransaction({
252
- data
252
+ var _txDesc$args2;
253
+ const txDesc = viem.decodeFunctionData({
254
+ abi: abis.erc721Abi,
255
+ data: data
253
256
  });
254
257
  if (txDesc) return {
255
- name: txDesc.name,
256
- methodParams: txDesc.args.toArray(),
258
+ name: txDesc.functionName,
259
+ methodParams: [...((_txDesc$args2 = txDesc.args) !== null && _txDesc$args2 !== void 0 ? _txDesc$args2 : [])],
257
260
  type: constants.CONTRACT_TYPE_ERC721
258
261
  };
259
262
  } catch {
260
263
  // ignore and next try to parse with erc1155 ABI
261
264
  }
262
265
  try {
263
- const txDesc = erc1155Interface.parseTransaction({
264
- data
266
+ var _txDesc$args3;
267
+ const txDesc = viem.decodeFunctionData({
268
+ abi: abis.erc1155Abi,
269
+ data: data
265
270
  });
266
271
  if (txDesc) return {
267
- name: txDesc.name,
268
- methodParams: txDesc.args.toArray(),
272
+ name: txDesc.functionName,
273
+ methodParams: [...((_txDesc$args3 = txDesc.args) !== null && _txDesc$args3 !== void 0 ? _txDesc$args3 : [])],
269
274
  type: constants.CONTRACT_TYPE_ERC1155
270
275
  };
271
276
  } catch {
@@ -23,7 +23,7 @@ export declare class AccountTrackerController extends BaseController<AccountTrac
23
23
  private provider;
24
24
  private blockTracker;
25
25
  private mutex;
26
- private ethersProvider;
26
+ private publicClient;
27
27
  private getIdentities;
28
28
  private getCurrentChainId;
29
29
  constructor({ config, state, provider, blockTracker, getIdentities, onPreferencesStateChange, getCurrentChainId, }: AccountTrackerControllerOptions);
@@ -52,8 +52,6 @@ export declare class AccountAbstractionController extends BaseController<Account
52
52
  estimateGas(txParams: TransactionParams, address: string): Promise<UserOperationGas>;
53
53
  signMessage(message: string, address: string): Promise<string>;
54
54
  signPersonalMessage(message: string, address: string): Promise<string>;
55
- signTypedData(data: SignTypedDataMessageV4 & {
56
- primaryType: string;
57
- }, address: string): Promise<string>;
55
+ signTypedData(data: SignTypedDataMessageV4, address: string): Promise<string>;
58
56
  private updateUserOpMeta;
59
57
  }
@@ -9,11 +9,11 @@ export declare class KeyringController extends BaseKeyringController<Partial<Bas
9
9
  signTransaction<T, U>(tx: T, address: string): Promise<U>;
10
10
  signEip7702Authorization(authorization: UnsignedAuthorization, address: string): Promise<Required<Authorization>>;
11
11
  getAccounts(): string[];
12
- importAccount(accountPrivateKey: string): string;
12
+ importAccount(accountPrivateKey: string): Promise<string>;
13
13
  removeAccount(address: string): void;
14
- getBufferPrivateKey(privateKey: string): Buffer<ArrayBuffer>;
14
+ getPrivateKeyBytes(privateKey: string): Uint8Array;
15
15
  signMessage(data: string, address: string): Promise<string>;
16
- signPersonalMessage(data: string, address: string): Promise<string>;
17
- signTypedData(typedData: SignTypedDataMessageV4, address: string): Promise<string>;
16
+ signPersonalMessage(data: string, address: string): Promise<`0x${string}`>;
17
+ signTypedData(typedData: SignTypedDataMessageV4, address: string): Promise<`0x${string}`>;
18
18
  private _getWalletForAccount;
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import { CustomNftItemInfo } from "@toruslabs/base-controllers";
2
- import { Provider } from "ethers";
2
+ import { SafeEventEmitterProvider } from "@web3auth/auth";
3
3
  import { EthereumNftInfo as CustomNftInfo } from "../Nfts/INftsController";
4
4
  export interface INftOptions {
5
5
  contractAddress: string;
@@ -11,7 +11,7 @@ export interface INftOptions {
11
11
  nftStandard?: "erc721" | "erc1155";
12
12
  contractDescription?: string;
13
13
  chainId: string;
14
- provider: Provider;
14
+ provider: SafeEventEmitterProvider;
15
15
  }
16
16
  export declare class NftHandler {
17
17
  contractAddress: string;
@@ -23,8 +23,9 @@ export declare class NftHandler {
23
23
  nftStandard: "erc721" | "erc1155";
24
24
  contractDescription?: string;
25
25
  chainId: string;
26
- provider: Provider;
26
+ provider: SafeEventEmitterProvider;
27
27
  isSpecial?: boolean;
28
+ private publicClient;
28
29
  constructor({ chainId, contractAddress, contractImage, contractName, contractSymbol, nftStandard, provider, contractDescription, contractFallbackLogo, contractSupply, }: INftOptions);
29
30
  getNftMetadata(userAddress: string, tokenInfo: Partial<CustomNftItemInfo>): Promise<CustomNftItemInfo>;
30
31
  getContractMetadata(): Promise<Omit<CustomNftInfo, "assets">>;
@@ -17,7 +17,6 @@ export interface INftsControllerOptions {
17
17
  export declare class NftsController extends BaseController<EthereumNftsControllerConfig, EthereumNftsControllerState> implements INftsController<EthereumNftsControllerConfig, EthereumNftsControllerState> {
18
18
  name: string;
19
19
  private provider;
20
- private ethersProvider;
21
20
  private getCustomNfts;
22
21
  private getSimpleHashNfts;
23
22
  private pollingManager;
@@ -1,17 +1,18 @@
1
- import { BrowserProvider, Contract } from "ethers";
1
+ import { SafeEventEmitterProvider } from "@web3auth/auth";
2
2
  export interface ITokenOptions {
3
3
  address: string;
4
4
  symbol: string;
5
5
  decimals: number;
6
6
  name: string;
7
- provider: BrowserProvider;
7
+ provider: SafeEventEmitterProvider;
8
8
  }
9
9
  export declare class TokenHandler {
10
10
  address: string;
11
11
  symbol: string;
12
12
  decimals: number;
13
13
  name: string;
14
- contract: Contract;
14
+ provider: SafeEventEmitterProvider;
15
+ private publicClient;
15
16
  constructor({ address, symbol, decimals, name, provider }: ITokenOptions);
16
17
  getSymbol(): Promise<string>;
17
18
  getDecimals(): Promise<number>;
@@ -19,7 +19,7 @@ export interface ITokensControllerOptions {
19
19
  export declare class TokensController extends BaseController<EthereumTokensControllerConfig, EthereumTokensControllerState> implements ITokensController<EthereumTokensControllerConfig, EthereumTokensControllerState, CustomTokenInfo> {
20
20
  name: string;
21
21
  private provider;
22
- private ethersProvider;
22
+ private publicClient;
23
23
  private pollingManager;
24
24
  private getProviderConfig;
25
25
  private getCustomTokens;
@@ -54,8 +54,16 @@ export declare function normalizeAndValidateTxParams(txParams: TransactionParams
54
54
  */
55
55
  export declare function getFinalStates(): TransactionStatus[];
56
56
  export declare function parseStandardTokenTransactionData(data: string): {
57
- name: string;
58
- methodParams: any[];
57
+ name: "symbol" | "decimals" | "transfer" | "transferFrom" | "approve" | "name" | "totalSupply" | "balanceOf" | "approveAndCall" | "allowance";
58
+ methodParams: (bigint | `0x${string}`)[];
59
+ type: string;
60
+ } | {
61
+ name: "symbol" | "transferFrom" | "approve" | "safeTransferFrom" | "name" | "totalSupply" | "balanceOf" | "supportsInterface" | "getApproved" | "tokenOfOwnerByIndex" | "tokenByIndex" | "ownerOf" | "tokenURI";
62
+ methodParams: (bigint | `0x${string}`)[];
63
+ type: string;
64
+ } | {
65
+ name: "safeTransferFrom" | "setApprovalForAll" | "balanceOf" | "supportsInterface" | "balanceOfBatch" | "isApprovedForAll" | "uri";
66
+ methodParams: (bigint | boolean | `0x${string}` | readonly `0x${string}`[] | readonly bigint[])[];
59
67
  type: string;
60
68
  };
61
69
  export declare const readAddressAsContract: (provider: SafeEventEmitterProvider, address: string) => Promise<{
@@ -65,7 +73,7 @@ export declare const readAddressAsContract: (provider: SafeEventEmitterProvider,
65
73
  export declare function determineTransactionType(txParams: TransactionParams, provider: SafeEventEmitterProvider, overrideTxMeta?: Partial<EthereumTransactionMeta>): Promise<{
66
74
  type: string;
67
75
  category: string;
68
- methodParams: any[];
76
+ methodParams: unknown[];
69
77
  getCodeResponse: string;
70
78
  }>;
71
79
  /**