@toruslabs/ethereum-controllers 7.2.1 → 8.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 (95) hide show
  1. package/dist/ethereumControllers.umd.min.js +1 -1
  2. package/dist/lib.cjs/Account/AccountTrackerController.js +3 -2
  3. package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +0 -2
  4. package/dist/lib.cjs/Block/PollingBlockTracker.js +1 -3
  5. package/dist/lib.cjs/Currency/CurrencyController.js +0 -2
  6. package/dist/lib.cjs/Gas/GasFeeController.js +1 -3
  7. package/dist/lib.cjs/Gas/gasUtil.js +0 -1
  8. package/dist/lib.cjs/Keyring/KeyringController.js +0 -2
  9. package/dist/lib.cjs/Message/utils.js +4 -2
  10. package/dist/lib.cjs/Network/NetworkController.js +0 -4
  11. package/dist/lib.cjs/Network/cacheIdentifier.js +20 -14
  12. package/dist/lib.cjs/Nfts/NftsController.js +0 -1
  13. package/dist/lib.cjs/Preferences/PreferencesController.js +7 -10
  14. package/dist/lib.cjs/Tokens/TokenRatesController.js +0 -1
  15. package/dist/lib.cjs/Tokens/TokensController.js +24 -34
  16. package/dist/lib.cjs/Transaction/NonceTracker.js +2 -4
  17. package/dist/lib.cjs/Transaction/PendingTransactionTracker.js +3 -10
  18. package/dist/lib.cjs/Transaction/TransactionController.js +0 -6
  19. package/dist/lib.cjs/Transaction/TransactionGasUtil.js +0 -4
  20. package/dist/lib.cjs/Transaction/TransactionStateHistoryHelper.js +0 -1
  21. package/dist/lib.cjs/Transaction/TransactionStateManager.js +3 -11
  22. package/dist/lib.cjs/Transaction/TransactionUtils.js +1 -14
  23. package/dist/lib.cjs/index.js +10 -10
  24. package/dist/{types → lib.cjs/types}/Keyring/KeyringController.d.ts +1 -1
  25. package/dist/{types → lib.cjs/types}/Tokens/TokensController.d.ts +1 -1
  26. package/dist/lib.cjs/utils/constants.js +0 -1
  27. package/dist/lib.cjs/utils/conversionUtils.js +0 -4
  28. package/dist/lib.cjs/utils/helpers.js +0 -1
  29. package/dist/lib.esm/Account/AccountTrackerController.js +3 -1
  30. package/dist/lib.esm/Block/PollingBlockTracker.js +1 -1
  31. package/dist/lib.esm/Gas/GasFeeController.js +1 -1
  32. package/dist/lib.esm/Message/utils.js +4 -2
  33. package/dist/lib.esm/Network/cacheIdentifier.js +12 -0
  34. package/dist/lib.esm/Preferences/PreferencesController.js +7 -7
  35. package/dist/lib.esm/Tokens/TokenRatesController.js +3 -0
  36. package/dist/lib.esm/Tokens/TokensController.js +25 -33
  37. package/dist/lib.esm/Transaction/TransactionStateManager.js +1 -2
  38. package/dist/lib.esm/Transaction/TransactionUtils.js +2 -2
  39. package/dist/lib.esm/utils/contractAddresses.js +1 -1
  40. package/dist/lib.esm/utils/helpers.js +2 -2
  41. package/package.json +20 -18
  42. package/dist/757.ethereumControllers.cjs.js +0 -226
  43. package/dist/ethereumControllers.cjs.js +0 -24043
  44. package/dist/ethereumControllers.esm.js +0 -6314
  45. package/dist/lib.cjs/utils/lodashUtils.js +0 -25
  46. package/dist/lib.esm/utils/lodashUtils.js +0 -21
  47. package/dist/types/utils/lodashUtils.d.ts +0 -5
  48. /package/dist/{types → lib.cjs/types}/Account/AccountTrackerController.d.ts +0 -0
  49. /package/dist/{types → lib.cjs/types}/AccountAbstraction/AccountAbstractionController.d.ts +0 -0
  50. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/BiconomySmartAccount.d.ts +0 -0
  51. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/KernelSmartAccount.d.ts +0 -0
  52. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/LightSmartAccount.d.ts +0 -0
  53. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/NexusSmartAccount.d.ts +0 -0
  54. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/SafeSmartAccount.d.ts +0 -0
  55. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/SimpleSmartAccount.d.ts +0 -0
  56. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/TrustSmartAccount.d.ts +0 -0
  57. /package/dist/{types → lib.cjs/types}/AccountAbstraction/smartAccounts/index.d.ts +0 -0
  58. /package/dist/{types → lib.cjs/types}/Block/PollingBlockTracker.d.ts +0 -0
  59. /package/dist/{types → lib.cjs/types}/Currency/CurrencyController.d.ts +0 -0
  60. /package/dist/{types → lib.cjs/types}/Gas/GasFeeController.d.ts +0 -0
  61. /package/dist/{types → lib.cjs/types}/Gas/IGasFeeController.d.ts +0 -0
  62. /package/dist/{types → lib.cjs/types}/Gas/gasUtil.d.ts +0 -0
  63. /package/dist/{types → lib.cjs/types}/Message/AddChainController.d.ts +0 -0
  64. /package/dist/{types → lib.cjs/types}/Message/MessageController.d.ts +0 -0
  65. /package/dist/{types → lib.cjs/types}/Message/PersonalMessageController.d.ts +0 -0
  66. /package/dist/{types → lib.cjs/types}/Message/SwitchChainController.d.ts +0 -0
  67. /package/dist/{types → lib.cjs/types}/Message/TypedMessageController.d.ts +0 -0
  68. /package/dist/{types → lib.cjs/types}/Message/types.d.ts +0 -0
  69. /package/dist/{types → lib.cjs/types}/Message/utils.d.ts +0 -0
  70. /package/dist/{types → lib.cjs/types}/Network/NetworkController.d.ts +0 -0
  71. /package/dist/{types → lib.cjs/types}/Network/cacheIdentifier.d.ts +0 -0
  72. /package/dist/{types → lib.cjs/types}/Network/createEthereumMiddleware.d.ts +0 -0
  73. /package/dist/{types → lib.cjs/types}/Network/createJsonRpcClient.d.ts +0 -0
  74. /package/dist/{types → lib.cjs/types}/Nfts/INftsController.d.ts +0 -0
  75. /package/dist/{types → lib.cjs/types}/Nfts/NftHandler.d.ts +0 -0
  76. /package/dist/{types → lib.cjs/types}/Nfts/NftsController.d.ts +0 -0
  77. /package/dist/{types → lib.cjs/types}/Preferences/IPreferencesController.d.ts +0 -0
  78. /package/dist/{types → lib.cjs/types}/Preferences/PreferencesController.d.ts +0 -0
  79. /package/dist/{types → lib.cjs/types}/Tokens/ITokensController.d.ts +0 -0
  80. /package/dist/{types → lib.cjs/types}/Tokens/TokenHandler.d.ts +0 -0
  81. /package/dist/{types → lib.cjs/types}/Tokens/TokenRatesController.d.ts +0 -0
  82. /package/dist/{types → lib.cjs/types}/Transaction/NonceTracker.d.ts +0 -0
  83. /package/dist/{types → lib.cjs/types}/Transaction/PendingTransactionTracker.d.ts +0 -0
  84. /package/dist/{types → lib.cjs/types}/Transaction/TransactionController.d.ts +0 -0
  85. /package/dist/{types → lib.cjs/types}/Transaction/TransactionGasUtil.d.ts +0 -0
  86. /package/dist/{types → lib.cjs/types}/Transaction/TransactionStateHistoryHelper.d.ts +0 -0
  87. /package/dist/{types → lib.cjs/types}/Transaction/TransactionStateManager.d.ts +0 -0
  88. /package/dist/{types → lib.cjs/types}/Transaction/TransactionUtils.d.ts +0 -0
  89. /package/dist/{types → lib.cjs/types}/index.d.ts +0 -0
  90. /package/dist/{types → lib.cjs/types}/utils/abis.d.ts +0 -0
  91. /package/dist/{types → lib.cjs/types}/utils/constants.d.ts +0 -0
  92. /package/dist/{types → lib.cjs/types}/utils/contractAddresses.d.ts +0 -0
  93. /package/dist/{types → lib.cjs/types}/utils/conversionUtils.d.ts +0 -0
  94. /package/dist/{types → lib.cjs/types}/utils/helpers.d.ts +0 -0
  95. /package/dist/{types → lib.cjs/types}/utils/interfaces.d.ts +0 -0
@@ -2,7 +2,6 @@
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var baseControllers = require('@toruslabs/base-controllers');
5
- var lodashUtils = require('../utils/lodashUtils.js');
6
5
  var TransactionStateHistoryHelper = require('./TransactionStateHistoryHelper.js');
7
6
  var TransactionUtils = require('./TransactionUtils.js');
8
7
 
@@ -23,7 +22,6 @@ class TransactionStateManager extends baseControllers.BaseTransactionStateManage
23
22
  const chainId = this.getCurrentChainId();
24
23
  if (chainId === "loading") throw new Error("Torus is having trouble connecting to the network");
25
24
  let dappSuggestedGasFees = null;
26
-
27
25
  // If we are dealing with a transaction suggested by a dapp and not
28
26
  // an internally created transaction, we need to keep record of
29
27
  // the originally submitted gasParams.
@@ -75,7 +73,6 @@ class TransactionStateManager extends baseControllers.BaseTransactionStateManage
75
73
  const {
76
74
  txHistoryLimit
77
75
  } = this.config;
78
-
79
76
  // checks if the length of the tx history is longer then desired persistence
80
77
  // limit and then if it is removes the oldest confirmed or rejected tx.
81
78
  // Pending or unapproved transactions will not be removed by this
@@ -112,7 +109,6 @@ class TransactionStateManager extends baseControllers.BaseTransactionStateManage
112
109
  this._addTransactionsToState([txMeta]);
113
110
  return txMeta;
114
111
  }
115
-
116
112
  /**
117
113
  Removes transaction from the given address for the current network
118
114
  from the txList
@@ -142,17 +138,15 @@ class TransactionStateManager extends baseControllers.BaseTransactionStateManage
142
138
  // with the provided value". To conform this object to be only methods, we
143
139
  // mapValues (lodash) such that every value on the object is a method that
144
140
  // returns a boolean.
145
- const predicateMethods = lodashUtils.mapValues(searchCriteria, predicate => typeof predicate === "function" ? predicate : v => v === predicate);
146
-
141
+ const predicateMethods = baseControllers.mapValues(searchCriteria, predicate => typeof predicate === "function" ? predicate : v => v === predicate);
147
142
  // If an initial list is provided we need to change it back into an object
148
143
  // first, so that it matches the shape of our state. This is done by the
149
144
  // lodash keyBy method. This is the edge case for this method, typically
150
145
  // initialList will be undefined.
151
- const transactionsToFilter = initialList ? lodashUtils.keyBy(initialList, "id") : this.state.transactions;
152
-
146
+ const transactionsToFilter = initialList ? baseControllers.keyBy(initialList, "id") : this.state.transactions;
153
147
  // Combine sortBy and pickBy to transform our state object into an array of
154
148
  // matching transactions that are sorted by time.
155
- const filteredTransactions = lodashUtils.sortBy(Object.values(baseControllers.pickBy(transactionsToFilter, txMeta => {
149
+ const filteredTransactions = baseControllers.sortBy(Object.values(baseControllers.pickBy(transactionsToFilter, txMeta => {
156
150
  // default matchesCriteria to the value of transactionMatchesNetwork
157
151
  // when filterToCurrentNetwork is true.
158
152
  const transactionMatches = baseControllers.transactionMatchesNetwork(txMeta, chainId);
@@ -259,7 +253,6 @@ class TransactionStateManager extends baseControllers.BaseTransactionStateManage
259
253
  if (txMeta.transaction) {
260
254
  txMeta.transaction = TransactionUtils.normalizeAndValidateTxParams(txMeta.transaction, false);
261
255
  }
262
-
263
256
  // create txMeta snapshot for history
264
257
  const currentState = TransactionStateHistoryHelper.snapshotFromTxMeta(txMeta);
265
258
  // recover previous tx state obj
@@ -270,7 +263,6 @@ class TransactionStateManager extends baseControllers.BaseTransactionStateManage
270
263
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
264
  txMeta.history.push(entry);
272
265
  }
273
-
274
266
  // commit txMeta to state
275
267
  this.updateTransaction(txMeta);
276
268
  }
@@ -11,9 +11,6 @@ var constants = require('../utils/constants.js');
11
11
  const erc20Interface = new ethers.Interface(abis.erc20Abi);
12
12
  const erc721Interface = new ethers.Interface(abis.erc721Abi);
13
13
  const erc1155Interface = new ethers.Interface(abis.erc1155Abi);
14
-
15
- // functions that handle normalizing of that key in txParams
16
-
17
14
  const normalizers = {
18
15
  from: (from, LowerCase = true) => LowerCase ? util.addHexPrefix(from).toLowerCase() : util.addHexPrefix(from),
19
16
  to: (to, LowerCase = true) => LowerCase ? util.addHexPrefix(to).toLowerCase() : util.addHexPrefix(to),
@@ -32,7 +29,6 @@ const normalizers = {
32
29
  paymasterVerificationGasLimit: util.addHexPrefix,
33
30
  paymasterPostOpGasLimit: util.addHexPrefix
34
31
  };
35
-
36
32
  /**
37
33
  * normalizes txParams
38
34
  */
@@ -56,7 +52,6 @@ function transactionMatchesNetwork(transaction, chainId) {
56
52
  }
57
53
  return false;
58
54
  }
59
-
60
55
  /**
61
56
  * Determines if the maxFeePerGas and maxPriorityFeePerGas fields are supplied
62
57
  * and valid inputs. This will return false for non hex string inputs.
@@ -67,7 +62,6 @@ function isEIP1559Transaction(transaction) {
67
62
  var _transaction$transact, _transaction$transact2;
68
63
  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));
69
64
  }
70
-
71
65
  /**
72
66
  * Determine if the maxFeePerGas and maxPriorityFeePerGas fields are not
73
67
  * supplied and that the gasPrice field is valid if it is provided. This will
@@ -80,7 +74,6 @@ function isEIP1559Transaction(transaction) {
80
74
  function isLegacyTransaction(transaction) {
81
75
  return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || util.isHexString(util.addHexPrefix(transaction.transaction.gasPrice)));
82
76
  }
83
-
84
77
  /**
85
78
  * Given two fields, ensure that the second field is not included in txParams,
86
79
  * and if it is throw an invalidParams error.
@@ -90,7 +83,6 @@ function ensureMutuallyExclusiveFieldsNotProvided(txParams, fieldBeingValidated,
90
83
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`);
91
84
  }
92
85
  }
93
-
94
86
  /**
95
87
  * Ensures that the provided value for field is a string, throws an
96
88
  * invalidParams error if field is not a string.
@@ -100,7 +92,6 @@ function ensureFieldIsString(txParams, field) {
100
92
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`);
101
93
  }
102
94
  }
103
-
104
95
  /**
105
96
  * Ensures that the provided txParams has the proper 'type' specified for the
106
97
  * given field, if it is provided. If types do not match throws an
@@ -121,7 +112,6 @@ function ensureProperTransactionEnvelopeTypeProvided(txParams, field) {
121
112
  }
122
113
  }
123
114
  }
124
-
125
115
  /**
126
116
  * validates the from field in txParams
127
117
  */
@@ -133,7 +123,6 @@ function validateFrom(txParams) {
133
123
  throw auth.rpcErrors.invalidParams('Invalid "from" address.');
134
124
  }
135
125
  }
136
-
137
126
  /**
138
127
  * validates the to field in txParams
139
128
  */
@@ -149,7 +138,6 @@ function validateRecipient(txParameters) {
149
138
  }
150
139
  return txParameters;
151
140
  }
152
-
153
141
  /**
154
142
  * Validates the given tx parameters
155
143
  * @throws if the tx params contains invalid fields
@@ -215,7 +203,6 @@ function normalizeAndValidateTxParams(txParams, lowerCase = true) {
215
203
  validateTxParameters(normalizedTxParams);
216
204
  return normalizedTxParams;
217
205
  }
218
-
219
206
  /**
220
207
  * @returns an array of states that can be considered final
221
208
  */
@@ -275,7 +262,7 @@ const readAddressAsContract = async (provider, address) => {
275
262
  method: constants.METHOD_TYPES.ETH_GET_CODE,
276
263
  params: [address, "latest"]
277
264
  });
278
- } catch (e) {
265
+ } catch {
279
266
  contractCode = null;
280
267
  }
281
268
  const isContractAddress = contractCode ? contractCode !== "0x" && contractCode !== "0x0" : false;
@@ -2,6 +2,11 @@
2
2
 
3
3
  var AccountTrackerController = require('./Account/AccountTrackerController.js');
4
4
  var AccountAbstractionController = require('./AccountAbstraction/AccountAbstractionController.js');
5
+ var BiconomySmartAccount = require('./AccountAbstraction/smartAccounts/BiconomySmartAccount.js');
6
+ var KernelSmartAccount = require('./AccountAbstraction/smartAccounts/KernelSmartAccount.js');
7
+ var NexusSmartAccount = require('./AccountAbstraction/smartAccounts/NexusSmartAccount.js');
8
+ var SafeSmartAccount = require('./AccountAbstraction/smartAccounts/SafeSmartAccount.js');
9
+ var TrustSmartAccount = require('./AccountAbstraction/smartAccounts/TrustSmartAccount.js');
5
10
  var PollingBlockTracker = require('./Block/PollingBlockTracker.js');
6
11
  var CurrencyController = require('./Currency/CurrencyController.js');
7
12
  var GasFeeController = require('./Gas/GasFeeController.js');
@@ -32,11 +37,6 @@ var abis = require('./utils/abis.js');
32
37
  var constants = require('./utils/constants.js');
33
38
  var conversionUtils = require('./utils/conversionUtils.js');
34
39
  var helpers = require('./utils/helpers.js');
35
- var BiconomySmartAccount = require('./AccountAbstraction/smartAccounts/BiconomySmartAccount.js');
36
- var KernelSmartAccount = require('./AccountAbstraction/smartAccounts/KernelSmartAccount.js');
37
- var NexusSmartAccount = require('./AccountAbstraction/smartAccounts/NexusSmartAccount.js');
38
- var SafeSmartAccount = require('./AccountAbstraction/smartAccounts/SafeSmartAccount.js');
39
- var TrustSmartAccount = require('./AccountAbstraction/smartAccounts/TrustSmartAccount.js');
40
40
 
41
41
 
42
42
 
@@ -44,6 +44,11 @@ exports.AccountTrackerController = AccountTrackerController.AccountTrackerContro
44
44
  exports.AccountAbstractionController = AccountAbstractionController.AccountAbstractionController;
45
45
  exports.eoaInterceptorMiddleware = AccountAbstractionController.eoaInterceptorMiddleware;
46
46
  exports.eoaProviderAsMiddleware = AccountAbstractionController.eoaProviderAsMiddleware;
47
+ exports.BiconomySmartAccount = BiconomySmartAccount.BiconomySmartAccount;
48
+ exports.KernelSmartAccount = KernelSmartAccount.KernelSmartAccount;
49
+ exports.NexusSmartAccount = NexusSmartAccount.NexusSmartAccount;
50
+ exports.SafeSmartAccount = SafeSmartAccount.SafeSmartAccount;
51
+ exports.TrustSmartAccount = TrustSmartAccount.TrustSmartAccount;
47
52
  exports.PollingBlockTracker = PollingBlockTracker.PollingBlockTracker;
48
53
  exports.CurrencyController = CurrencyController.CurrencyController;
49
54
  exports.GasFeeController = GasFeeController.GasFeeController;
@@ -175,8 +180,3 @@ exports.hexToBn = helpers.hexToBn;
175
180
  exports.isAddressByChainId = helpers.isAddressByChainId;
176
181
  exports.sanitizeNftMetdataUrl = helpers.sanitizeNftMetdataUrl;
177
182
  exports.toChecksumAddressByChainId = helpers.toChecksumAddressByChainId;
178
- exports.BiconomySmartAccount = BiconomySmartAccount.BiconomySmartAccount;
179
- exports.KernelSmartAccount = KernelSmartAccount.KernelSmartAccount;
180
- exports.NexusSmartAccount = NexusSmartAccount.NexusSmartAccount;
181
- exports.SafeSmartAccount = SafeSmartAccount.SafeSmartAccount;
182
- exports.TrustSmartAccount = TrustSmartAccount.TrustSmartAccount;
@@ -9,7 +9,7 @@ export declare class KeyringController extends BaseKeyringController<Partial<Bas
9
9
  getAccounts(): string[];
10
10
  importAccount(accountPrivateKey: string): string;
11
11
  removeAccount(address: string): void;
12
- getBufferPrivateKey(privateKey: string): Buffer;
12
+ getBufferPrivateKey(privateKey: string): Buffer<ArrayBuffer>;
13
13
  signMessage(data: string, address: string): Promise<string>;
14
14
  signPersonalMessage(data: string, address: string): Promise<string>;
15
15
  signTypedData(typedData: SignTypedDataMessageV4, address: string): Promise<string>;
@@ -37,5 +37,5 @@ export declare class TokensController extends BaseController<EthereumTokensContr
37
37
  restartTokenDetection(): void;
38
38
  detectNewTokens(): void;
39
39
  refreshTokenBalances(skipCache?: boolean): Promise<void>;
40
- getTokenBalancesUsingHandler(customTokens: CustomTokenInfo[]): Promise<void>;
40
+ getTokenBalancesUsingHandler(customTokens: CustomTokenInfo[]): Promise<CustomTokenInfo[]>;
41
41
  }
@@ -254,7 +254,6 @@ const GAS_ESTIMATE_TYPES = {
254
254
  // estimate.
255
255
  NONE: "none"
256
256
  };
257
-
258
257
  // https://help.optimism.io/hc/en-us/articles/4411895794715-Transaction-fees
259
258
  const CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP = {
260
259
  [OPTIMISM_MAINNET_CHAIN_ID]: 1,
@@ -10,7 +10,6 @@ var BN = require('bn.js');
10
10
  const _excluded = ["aBase", "bBase"],
11
11
  _excluded2 = ["aBase", "bBase"],
12
12
  _excluded3 = ["multiplicandBase", "multiplierBase"];
13
-
14
13
  // Big Number Constants
15
14
  const BIG_NUMBER_WEI_MULTIPLIER = new bignumber_js.BigNumber("1000000000000000000");
16
15
  const BIG_NUMBER_GWEI_MULTIPLIER = new bignumber_js.BigNumber("1000000000");
@@ -36,10 +35,8 @@ const baseChange = {
36
35
  dec: n => new bignumber_js.BigNumber(n).toString(10),
37
36
  BN: n => new BN(n.toString(16))
38
37
  };
39
-
40
38
  // Utility function for checking base types
41
39
  const isValidBase = base => Number.isInteger(base) && base > 1;
42
-
43
40
  /**
44
41
  * Utility method to convert a value between denominations, formats and currencies.
45
42
  */
@@ -115,7 +112,6 @@ const getBigNumber = (value, base) => {
115
112
  if (!isValidBase(base)) {
116
113
  throw new Error("Must specificy valid base");
117
114
  }
118
-
119
115
  // We don't include 'number' here, because BigNumber will throw if passed
120
116
  // a number primitive it considers unsafe.
121
117
  if (typeof value === "string" || value instanceof bignumber_js.BigNumber) {
@@ -63,7 +63,6 @@ const formatPastTx = params => {
63
63
  };
64
64
  return finalObject;
65
65
  };
66
-
67
66
  /**
68
67
  * Ref - https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt
69
68
  */
@@ -95,7 +95,9 @@ class AccountTrackerController extends BaseController {
95
95
  const releaseLock = await this.mutex.acquire();
96
96
  try {
97
97
  this._updateAccounts();
98
- } catch (error) {} finally {
98
+ } catch {
99
+ // do nothing
100
+ } finally {
99
101
  releaseLock();
100
102
  }
101
103
  }
@@ -47,7 +47,7 @@ class PollingBlockTracker extends BaseBlockTracker {
47
47
  const newErr = new Error(`PollingBlockTracker - encountered an error while attempting to update latest block:\n${err.stack}`);
48
48
  try {
49
49
  this.emit("error", newErr);
50
- } catch (emitErr) {
50
+ } catch {
51
51
  log.error(newErr);
52
52
  }
53
53
  await timeout(this.config.retryTimeout);
@@ -140,7 +140,7 @@ class GasFeeController extends BaseController {
140
140
  } else {
141
141
  throw new Error("ChainId not supported by api");
142
142
  }
143
- } catch (error) {
143
+ } catch {
144
144
  estimates = await this.fetchGasEstimatesViaEthFeeHistory(this.provider);
145
145
  }
146
146
  const {
@@ -24,7 +24,9 @@ function normalizeMessageData(data) {
24
24
  if (stripped.match(hexRe)) {
25
25
  return addHexPrefix(stripped);
26
26
  }
27
- } catch (e) {}
27
+ } catch {
28
+ // do nothing
29
+ }
28
30
  return bytesToHex(Buffer.from(data, "utf8"));
29
31
  }
30
32
  async function validateTypedSignMessageDataV4(messageData, currentChainId) {
@@ -38,7 +40,7 @@ async function validateTypedSignMessageDataV4(messageData, currentChainId) {
38
40
  } else {
39
41
  try {
40
42
  data = JSON.parse(messageData.data);
41
- } catch (e) {
43
+ } catch {
42
44
  throw new Error("Data must be passed as a valid JSON string.");
43
45
  }
44
46
  }
@@ -1,9 +1,21 @@
1
1
  import stringify from 'fast-safe-stringify';
2
2
 
3
3
  let CacheStrategy = /*#__PURE__*/function (CacheStrategy) {
4
+ /**
5
+ * Cache per-block.
6
+ */
4
7
  CacheStrategy["Block"] = "block";
8
+ /**
9
+ * Cache until a chain reorganization occurs.
10
+ */
5
11
  CacheStrategy["Fork"] = "fork";
12
+ /**
13
+ * Never cache.
14
+ */
6
15
  CacheStrategy["Never"] = "never";
16
+ /**
17
+ * Permanently cache.
18
+ */
7
19
  CacheStrategy["Permanent"] = "perma";
8
20
  return CacheStrategy;
9
21
  }({});
@@ -93,9 +93,9 @@ class PreferencesController extends BasePreferencesController {
93
93
  }
94
94
  });
95
95
  const {
96
- aggregateVerifier,
97
- verifier,
98
- verifierId
96
+ groupedAuthConnectionId,
97
+ authConnection,
98
+ userId
99
99
  } = userInfo || {};
100
100
  const userExists = await this.sync(address);
101
101
  if (!userExists) {
@@ -103,8 +103,8 @@ class PreferencesController extends BasePreferencesController {
103
103
  await this.createUser({
104
104
  selectedCurrency: accountState.selectedCurrency,
105
105
  theme: accountState.theme,
106
- verifier: aggregateVerifier || verifier,
107
- verifierId,
106
+ verifier: groupedAuthConnectionId || authConnection,
107
+ verifierId: userId,
108
108
  locale,
109
109
  address,
110
110
  type,
@@ -120,8 +120,8 @@ class PreferencesController extends BasePreferencesController {
120
120
  eoaAddress
121
121
  }, address);
122
122
  this.storeUserLogin({
123
- verifier: aggregateVerifier || verifier,
124
- verifierId,
123
+ verifier: groupedAuthConnectionId || authConnection,
124
+ verifierId: userId,
125
125
  options: {
126
126
  calledFromEmbed,
127
127
  rehydrate
@@ -6,6 +6,9 @@ import log from 'loglevel';
6
6
  import { COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES } from '../utils/constants.js';
7
7
 
8
8
  const DEFAULT_CURRENCY = "eth";
9
+
10
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
11
+
9
12
  class TokenRatesController extends BaseController {
10
13
  constructor({
11
14
  config,
@@ -8,23 +8,6 @@ import { ETHERSCAN_SUPPORTED_CHAINS } from '../utils/constants.js';
8
8
  import { SINGLE_CALL_BALANCES_ADDRESSES } from '../utils/contractAddresses.js';
9
9
  import { TokenHandler } from './TokenHandler.js';
10
10
 
11
- function getObjectFromArrayBasedonKey(oldArray, key) {
12
- return oldArray.reduce((acc, x) => {
13
- const xkey = x[key];
14
- if (typeof xkey === "boolean") return acc;
15
- acc[xkey] = x;
16
- return acc;
17
- }, {});
18
- }
19
- const mergeTokenArrays = (oldArray, newArray) => {
20
- const oldMap = getObjectFromArrayBasedonKey(oldArray || [], "tokenAddress");
21
- const newMap = getObjectFromArrayBasedonKey(newArray || [], "tokenAddress");
22
- const finalArr = newArray;
23
- Object.keys(oldMap).forEach(x => {
24
- if (!newMap[x] && oldMap[x].isEtherScan) finalArr.push(oldMap[x]);
25
- });
26
- return finalArr;
27
- };
28
11
  const DEFAULT_INTERVAL = 180 * 1000;
29
12
  class TokensController extends BaseController {
30
13
  constructor({
@@ -177,45 +160,58 @@ class TokensController extends BaseController {
177
160
  const userAddress = this.userSelectedAddress;
178
161
  if (userAddress === "") return;
179
162
  const oldTokens = [...this.userTokens];
180
- const tokenAddresses = oldTokens.map(x => x.tokenAddress);
181
- const nonZeroTokens = [];
163
+ // - fetch from Etherscan, if failed then fetch from TokenHandler
164
+ // - if there are remaining tokens, fetch either from SingleAddressContract (if failed then use TokenHandler) or TokenHandler
182
165
  try {
166
+ const nonZeroTokens = [];
183
167
  const currentChainId = this.config.chainId;
184
168
  if (ETHERSCAN_SUPPORTED_CHAINS.includes(currentChainId)) {
185
169
  const etherscanBalances = await this.getEtherScanTokens(userAddress, currentChainId, skipCache);
186
170
  nonZeroTokens.push(...etherscanBalances);
187
171
  }
188
- if (tokenAddresses.length > 0) {
172
+
173
+ // only fetch balances for tokens that are not already in the nonZeroTokens array
174
+ const remainingTokens = oldTokens.filter(x => !nonZeroTokens.find(y => {
175
+ var _y$tokenAddress, _x$tokenAddress;
176
+ return ((_y$tokenAddress = y.tokenAddress) === null || _y$tokenAddress === void 0 ? void 0 : _y$tokenAddress.toLocaleLowerCase()) === ((_x$tokenAddress = x.tokenAddress) === null || _x$tokenAddress === void 0 ? void 0 : _x$tokenAddress.toLocaleLowerCase());
177
+ }));
178
+ if (remainingTokens.length > 0) {
179
+ const remainingTokensAddresses = remainingTokens.map(x => x.tokenAddress);
189
180
  const currentSingleCallAddress = SINGLE_CALL_BALANCES_ADDRESSES[currentChainId];
190
181
  if (currentSingleCallAddress) {
191
182
  const ethContract = new Contract(currentSingleCallAddress, singleBalanceCheckerAbi, this.ethersProvider);
192
- const result = await ethContract.balances([userAddress], tokenAddresses);
193
- tokenAddresses.forEach((_, index) => {
183
+ const result = await ethContract.balances([userAddress], remainingTokensAddresses);
184
+ remainingTokensAddresses.forEach((_, index) => {
194
185
  const balance = toQuantity(result[index]);
195
186
  if (balance && balance !== "0x0") {
196
- nonZeroTokens.push(_objectSpread(_objectSpread({}, oldTokens[index]), {}, {
187
+ nonZeroTokens.push(_objectSpread(_objectSpread({}, remainingTokens[index]), {}, {
197
188
  balance,
198
189
  chainId: currentChainId
199
190
  }));
200
191
  }
201
192
  });
202
193
  } else {
203
- this.getTokenBalancesUsingHandler(oldTokens);
194
+ const fetchedRemainingTokens = await this.getTokenBalancesUsingHandler(remainingTokens);
195
+ nonZeroTokens.push(...fetchedRemainingTokens);
204
196
  }
205
197
  }
198
+ this.update({
199
+ tokens: {
200
+ [userAddress]: nonZeroTokens
201
+ }
202
+ });
206
203
  } catch (error) {
207
204
  log.error(error, "unable to fetch token balances using single call balance address");
208
- this.getTokenBalancesUsingHandler(oldTokens);
209
- } finally {
205
+ const fetchedTokens = await this.getTokenBalancesUsingHandler(oldTokens);
210
206
  this.update({
211
207
  tokens: {
212
- [userAddress]: nonZeroTokens
208
+ [userAddress]: fetchedTokens
213
209
  }
214
210
  });
215
211
  }
216
212
  }
217
213
  async getTokenBalancesUsingHandler(customTokens) {
218
- if (!this.userSelectedAddress) return;
214
+ if (!this.userSelectedAddress) return [];
219
215
  const currentNetworkTokens = customTokens;
220
216
  const promiseSettledResult = await Promise.allSettled(currentNetworkTokens.map(async x => {
221
217
  try {
@@ -248,11 +244,7 @@ class TokensController extends BaseController {
248
244
  if (x.status === "fulfilled" && x.value) acc.push(x.value);
249
245
  return acc;
250
246
  }, []);
251
- this.update({
252
- tokens: {
253
- [this.userSelectedAddress]: mergeTokenArrays(this.userTokens, nonZeroTokens)
254
- }
255
- });
247
+ return nonZeroTokens;
256
248
  }
257
249
  }
258
250
 
@@ -1,6 +1,5 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
- import { BaseTransactionStateManager, randomId, TransactionStatus, omitBy, transactionMatchesNetwork, pickBy, TX_EVENTS } from '@toruslabs/base-controllers';
3
- import { mapValues, keyBy, sortBy } from '../utils/lodashUtils.js';
2
+ import { BaseTransactionStateManager, TransactionStatus, randomId, omitBy, transactionMatchesNetwork, mapValues, keyBy, sortBy, pickBy, TX_EVENTS } from '@toruslabs/base-controllers';
4
3
  import { snapshotFromTxMeta, replayHistory, generateHistoryEntry } from './TransactionStateHistoryHelper.js';
5
4
  import { normalizeAndValidateTxParams, getFinalStates } from './TransactionUtils.js';
6
5
 
@@ -1,4 +1,4 @@
1
- import { isHexString, addHexPrefix, isValidAddress } from '@ethereumjs/util';
1
+ import { addHexPrefix, isHexString, isValidAddress } from '@ethereumjs/util';
2
2
  import { randomId, TransactionStatus, TRANSACTION_TYPES } from '@toruslabs/base-controllers';
3
3
  import { rpcErrors } from '@web3auth/auth';
4
4
  import { Interface } from 'ethers';
@@ -273,7 +273,7 @@ const readAddressAsContract = async (provider, address) => {
273
273
  method: METHOD_TYPES.ETH_GET_CODE,
274
274
  params: [address, "latest"]
275
275
  });
276
- } catch (e) {
276
+ } catch {
277
277
  contractCode = null;
278
278
  }
279
279
  const isContractAddress = contractCode ? contractCode !== "0x" && contractCode !== "0x0" : false;
@@ -1,4 +1,4 @@
1
- import { MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, POLYGON_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID } from './constants.js';
1
+ import { ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, POLYGON_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, MAINNET_CHAIN_ID } from './constants.js';
2
2
 
3
3
  const SINGLE_CALL_BALANCES_ADDRESSES = {
4
4
  [MAINNET_CHAIN_ID]: "0xb1f8e55c7f64d203c1400b9d8555d050f94adf39",
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
- import { stripHexPrefix, addHexPrefix, isValidAddress, toChecksumAddress } from '@ethereumjs/util';
3
- import { formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, TransactionStatus } from '@toruslabs/base-controllers';
2
+ import { addHexPrefix, stripHexPrefix, isValidAddress, toChecksumAddress } from '@ethereumjs/util';
3
+ import { formatSmallNumbers, significantDigits, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, addressSlicer, TransactionStatus } from '@toruslabs/base-controllers';
4
4
  import { BigNumber } from 'bignumber.js';
5
5
  import log from 'loglevel';
6
6
  import { determineTransactionType } from '../Transaction/TransactionUtils.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "7.2.1",
3
+ "version": "8.0.0",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "sideEffects": false,
@@ -8,11 +8,11 @@
8
8
  "module": "dist/lib.esm/index.js",
9
9
  "unpkg": "dist/ethereumControllers.umd.min.js",
10
10
  "jsdelivr": "dist/ethereumControllers.umd.min.js",
11
- "types": "dist/types/index.d.ts",
11
+ "types": "dist/lib.cjs/types/index.d.ts",
12
12
  "author": "Torus Labs",
13
13
  "scripts": {
14
- "test": "TS_NODE_PROJECT=./tsconfig.test.json mocha --config ../../.mocharc.json test/**/*.ts",
15
- "test-debugger": "TS_NODE_PROJECT=./tsconfig.test.json mocha --config ../../.mocharc.json --inspect-brk test/**/*.ts",
14
+ "test": "TS_NODE_PROJECT=./tsconfig.test.json mocha -r dotenv/config --config ../../.mocharc.json test/**/*.ts",
15
+ "test-debugger": "TS_NODE_PROJECT=./tsconfig.test.json mocha -r dotenv/config --config ../../.mocharc.json --inspect-brk test/**/*.ts",
16
16
  "dev": "rimraf dist/ && cross-env NODE_ENV=development torus-scripts start",
17
17
  "build": "rimraf dist/ && cross-env NODE_ENV=production torus-scripts build",
18
18
  "lint": "eslint --fix 'src/**/*.ts' 'test/**/*.ts'",
@@ -21,20 +21,20 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@ethereumjs/util": "^9.1.0",
24
- "@toruslabs/base-controllers": "^7.2.1",
25
- "@toruslabs/http-helpers": "^7.0.0",
26
- "@web3auth/auth": "^9.6.4",
24
+ "@toruslabs/base-controllers": "^8.0.0",
25
+ "@toruslabs/http-helpers": "^8.1.1",
26
+ "@web3auth/auth": "^10.2.3",
27
27
  "async-mutex": "^0.5.0",
28
28
  "bignumber.js": "^9.1.2",
29
29
  "bn.js": "^5.2.1",
30
30
  "deepmerge": "^4.3.1",
31
- "ethers": "^6.13.4",
31
+ "ethers": "^6.13.5",
32
32
  "fast-json-patch": "^3.1.1",
33
33
  "fast-safe-stringify": "^2.1.1",
34
- "jsonschema": "^1.4.1",
34
+ "jsonschema": "^1.5.0",
35
35
  "loglevel": "^1.9.2",
36
- "permissionless": "^0.2.23",
37
- "viem": "^2.22.8"
36
+ "permissionless": "^0.2.38",
37
+ "viem": "^2.23.14"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@babel/runtime": "7.x"
@@ -56,27 +56,29 @@
56
56
  "url": "https://github.com/torusresearch/controllers/issues"
57
57
  },
58
58
  "engines": {
59
- "node": ">=16.18.1",
60
- "npm": ">=8.x"
59
+ "node": ">=20.x",
60
+ "npm": ">=9.x"
61
61
  },
62
62
  "keywords": [],
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "2f3e1955a917f7c3c70218da523bcf12af692f96",
66
+ "gitHead": "33783889e1d36eeae03c6a220acf19b06da4df40",
67
67
  "devDependencies": {
68
68
  "@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
69
69
  "@nomicfoundation/hardhat-ethers": "^3.0.8",
70
- "@nomicfoundation/hardhat-ignition-ethers": "^0.15.9",
70
+ "@nomicfoundation/hardhat-ignition-ethers": "^0.15.10",
71
71
  "@nomicfoundation/hardhat-network-helpers": "^1.0.12",
72
72
  "@nomicfoundation/hardhat-toolbox": "^5.0.0",
73
- "@nomicfoundation/hardhat-verify": "^2.0.12",
73
+ "@nomicfoundation/hardhat-verify": "^2.0.13",
74
74
  "@typechain/ethers-v6": "^0.5.1",
75
75
  "@typechain/hardhat": "^9.1.0",
76
76
  "@types/proxyquire": "^1.3.31",
77
- "hardhat": "^2.22.17",
77
+ "@types/sinon": "^17.0.4",
78
+ "hardhat": "^2.22.19",
78
79
  "proxyquire": "^2.1.3",
79
80
  "solidity-coverage": "^0.8.14",
80
- "typechain": "^8.3.2"
81
+ "typechain": "^8.3.2",
82
+ "undici": "^7.5.0"
81
83
  }
82
84
  }