@toruslabs/ethereum-controllers 9.2.0 → 9.3.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.
@@ -1,11 +1,11 @@
1
1
  import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit";
2
- import { BASE_TX_EVENT_TYPE, BaseBlockTrackerState, BaseControllerEvents, BaseFormattedTransactionActivity, BaseTokenInfo, BaseTransactionEvents, MESSAGE_EVENTS, MessageStatus, NetworkConfig, NetworkState, PaymentTransaction, PollingBlockTrackerConfig, PopupWhitelabelData, ProviderConfig, TRANSACTION_TYPE, TransactionMeta, TransactionState, TransactionStatus, TX_CONFIRMED_EVENT_TYPE, TX_DROPPED_EVENT_TYPE, TX_EVENTS, TX_FAILED_EVENT_TYPE, TX_WARNING_EVENT_TYPE, User } from "@toruslabs/base-controllers";
2
+ import { BASE_TX_EVENT_TYPE, BaseBlockTrackerState, BaseControllerEvents, BaseFormattedTransactionActivity, BaseTokenInfo, BaseTransactionEvents, MESSAGE_EVENTS, MessageStatus, NetworkConfig, NetworkState, PaymentTransaction, PollingBlockTrackerConfig, PopupWhitelabelData, ProviderConfig, TRANSACTION_TYPE, TransactionMeta, TransactionState, TransactionStatus, TX_CONFIRMED_EVENT_TYPE, TX_DROPPED_EVENT_TYPE, TX_EVENTS, TX_FAILED_EVENT_TYPE, TX_WARNING_EVENT_TYPE } from "@toruslabs/base-controllers";
3
3
  import { JRPCRequest, Json } from "@web3auth/auth";
4
4
  import { MutexInterface } from "async-mutex";
5
5
  import { ToBiconomySmartAccountParameters, toEcdsaKernelSmartAccount, ToLightSmartAccountParameters, ToNexusSmartAccountParameters, toSafeSmartAccount, toSimpleSmartAccount, toTrustSmartAccount } from "permissionless/accounts";
6
6
  import { Client, Hex, Signature, WalletClient } from "viem";
7
7
  import { createBundlerClient, createPaymasterClient, SmartAccount, UserOperationReceipt, WebAuthnAccount } from "viem/account-abstraction";
8
- import { METHOD_TYPES, SMART_ACCOUNT, TRANSACTION_ENVELOPE_TYPES } from "./constants";
8
+ import { METHOD_TYPES, SMART_ACCOUNT, SMART_ACCOUNT_EIP_STANDARD, TRANSACTION_ENVELOPE_TYPES } from "./constants";
9
9
  import { NestedTransactionMetadata } from "./eip5792Types";
10
10
  import { Authorization } from "./eip7702Types";
11
11
  export type { BatchTransactionParams, NestedTransactionMetadata, TransactionBatchRequest, TransactionBatchSingleRequest } from "./eip5792Types";
@@ -262,25 +262,6 @@ export interface EthereumNetworkState extends NetworkState {
262
262
  export interface EthereumNetworkConfig extends NetworkConfig, Partial<PollingBlockTrackerConfig> {
263
263
  providerConfig: EthereumProviderConfig;
264
264
  }
265
- export type CustomNetworkPayload = Partial<EthereumProviderConfig> & Pick<EthereumProviderConfig, "chainId" | "displayName" | "rpcTarget" | "ticker">;
266
- export interface CustomNetworks {
267
- id: number;
268
- created_at: Date;
269
- updated_at: Date;
270
- network_name: string;
271
- public_address: string;
272
- chain_id: string;
273
- rpc_url: string;
274
- symbol?: string;
275
- symbol_name?: string;
276
- decimals?: string;
277
- logo?: string;
278
- block_explorer_url?: string;
279
- is_testnet?: boolean;
280
- }
281
- export interface EthereumUser extends User {
282
- customNetworks: CustomNetworks[];
283
- }
284
265
  export interface ContractParams {
285
266
  erc20?: boolean;
286
267
  erc721?: boolean;
@@ -495,7 +476,9 @@ export interface ISmartAccount {
495
476
  }
496
477
  export type SmartAccountType = (typeof SMART_ACCOUNT)[keyof typeof SMART_ACCOUNT];
497
478
  export type SmartAccountConfig<TImplementation extends Implementation = Implementation.Hybrid> = BiconomySmartAccountConfig | KernelSmartAccountConfig | NexusSmartAccountConfig | SafeSmartAccountConfig | TrustSmartAccountConfig | MetamaskSmartAccountConfig<TImplementation>;
479
+ export type SmartAccountEipStandardType = (typeof SMART_ACCOUNT_EIP_STANDARD)[keyof typeof SMART_ACCOUNT_EIP_STANDARD];
498
480
  export type AccountAbstractionMultiChainConfig = {
481
+ smartAccountEipStandard?: SmartAccountEipStandardType;
499
482
  smartAccountType?: SmartAccountType;
500
483
  chains?: {
501
484
  chainId: string;
@@ -570,8 +553,6 @@ export type Numeric = number | bigint;
570
553
  export type BigNumberish = string | Numeric;
571
554
  /**
572
555
  * A SignatureLike
573
- *
574
- * @_docloc: api/crypto:Signing
575
556
  */
576
557
  export type SignatureLike = Signature | string | {
577
558
  r: string;
@@ -624,7 +605,7 @@ export interface TransactionLike<A = string> {
624
605
  */
625
606
  type?: null | number;
626
607
  /**
627
- * The recipient address or ``null`` for an ``init`` transaction.
608
+ * The recipient address or null for an init transaction.
628
609
  */
629
610
  to?: null | A;
630
611
  /**
@@ -691,7 +672,7 @@ export interface TransactionLike<A = string> {
691
672
  * An external library for computing the KZG commitments and
692
673
  * proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
693
674
  *
694
- * This is generally ``null``, unless you are creating BLOb
675
+ * This is generally null, unless you are creating BLOb
695
676
  * transactions.
696
677
  */
697
678
  kzg?: null | KzgLibraryLike;
@@ -366,6 +366,11 @@ const SMART_ACCOUNT = {
366
366
  NEXUS: "nexus",
367
367
  METAMASK: "metamask"
368
368
  };
369
+ const SMART_ACCOUNT_EIP_STANDARD = {
370
+ ERC_4337: "4337",
371
+ EIP_7702: "7702"
372
+ };
373
+ const EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES = [SMART_ACCOUNT.METAMASK];
369
374
 
370
375
  exports.ARBITRUM_MAINNET_CHAIN_ID = ARBITRUM_MAINNET_CHAIN_ID;
371
376
  exports.ARBITRUM_TESTNET_CHAIN_ID = ARBITRUM_TESTNET_CHAIN_ID;
@@ -385,6 +390,7 @@ exports.CONTRACT_TYPE_ERC20 = CONTRACT_TYPE_ERC20;
385
390
  exports.CONTRACT_TYPE_ERC721 = CONTRACT_TYPE_ERC721;
386
391
  exports.CONTRACT_TYPE_ERC7821 = CONTRACT_TYPE_ERC7821;
387
392
  exports.CONTRACT_TYPE_ETH = CONTRACT_TYPE_ETH;
393
+ exports.EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES = EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES;
388
394
  exports.ERC1155_INTERFACE_ID = ERC1155_INTERFACE_ID;
389
395
  exports.ERC721_ENUMERABLE_INTERFACE_ID = ERC721_ENUMERABLE_INTERFACE_ID;
390
396
  exports.ERC721_INTERFACE_ID = ERC721_INTERFACE_ID;
@@ -405,6 +411,7 @@ exports.POLYGON_AMOY_CHAIN_ID = POLYGON_AMOY_CHAIN_ID;
405
411
  exports.POLYGON_CHAIN_ID = POLYGON_CHAIN_ID;
406
412
  exports.SEPOLIA_CHAIN_ID = SEPOLIA_CHAIN_ID;
407
413
  exports.SMART_ACCOUNT = SMART_ACCOUNT;
414
+ exports.SMART_ACCOUNT_EIP_STANDARD = SMART_ACCOUNT_EIP_STANDARD;
408
415
  exports.SUPPORTED_NETWORKS = SUPPORTED_NETWORKS;
409
416
  exports.TEST_CHAINS = TEST_CHAINS;
410
417
  exports.TRANSACTION_ENVELOPE_TYPES = TRANSACTION_ENVELOPE_TYPES;
@@ -1,5 +1,6 @@
1
1
  import { rpcErrors } from '@web3auth/auth';
2
2
  import { getIsEip7702UpgradeSupported } from '../Eip7702/eip7702Utils.js';
3
+ import { SMART_ACCOUNT_EIP_STANDARD } from '../utils/constants.js';
3
4
  import { EIP_5792_METHODS, Eip5792AtomicStatus } from '../utils/eip5792Types.js';
4
5
 
5
6
  /**
@@ -31,6 +32,14 @@ async function walletGetCapabilities(request, getEthCode, context) {
31
32
  const cachedDelegations = ((_context$getCachedDel = context.getCachedDelegations) === null || _context$getCachedDel === void 0 ? void 0 : _context$getCachedDel.call(context)) || {};
32
33
  const capabilities = {};
33
34
  for (const chainId of supportedChains) {
35
+ if (context.getSmartAccountEipStandard() !== SMART_ACCOUNT_EIP_STANDARD.EIP_7702) {
36
+ capabilities[chainId] = {
37
+ atomic: {
38
+ status: Eip5792AtomicStatus.UNSUPPORTED
39
+ }
40
+ };
41
+ continue;
42
+ }
34
43
  const cacheKey = `${walletAddress.toLowerCase()}-${chainId.toLowerCase()}`;
35
44
  let delegationAddress = cachedDelegations[cacheKey];
36
45
  let atomicStatus = Eip5792AtomicStatus.SUPPORTED;
@@ -2,6 +2,7 @@ import { rpcErrors } from '@web3auth/auth';
2
2
  import { v4, parse } from 'uuid';
3
3
  import { isHex, isAddress } from 'viem';
4
4
  import { getIsEip7702UpgradeSupported } from '../Eip7702/eip7702Utils.js';
5
+ import { SMART_ACCOUNT_EIP_STANDARD } from '../utils/constants.js';
5
6
  import { EIP_5792_METHODS } from '../utils/eip5792Types.js';
6
7
 
7
8
  /**
@@ -44,8 +45,9 @@ function validateCall(call, index) {
44
45
  /**
45
46
  * Validates the parameters for wallet_sendCalls (EIP-5792).
46
47
  * @param sendCallsParams - The parameters to validate.
48
+ * @param context - The context
47
49
  */
48
- function validateSendCallsParams(sendCallsParams) {
50
+ function validateSendCallsParams(sendCallsParams, context) {
49
51
  // Basic structure validation
50
52
  if (!sendCallsParams) {
51
53
  throw rpcErrors.invalidParams("Missing send calls parameters");
@@ -74,6 +76,11 @@ function validateSendCallsParams(sendCallsParams) {
74
76
  throw rpcErrors.invalidParams("Invalid calls: must be a non-empty array");
75
77
  }
76
78
 
79
+ // Validate smart account standard for batch calls
80
+ if (sendCallsParams.calls.length > 1 && context.getSmartAccountEipStandard() !== SMART_ACCOUNT_EIP_STANDARD.EIP_7702) {
81
+ throw rpcErrors.methodNotSupported("wallet_sendCalls is only supported for batch calls when smart account standard is EIP-7702");
82
+ }
83
+
77
84
  // Validate each call
78
85
  sendCallsParams.calls.forEach((call, index) => {
79
86
  validateCall(call, index);
@@ -137,7 +144,7 @@ async function walletSendCalls(request, getEthCode, context) {
137
144
  return;
138
145
  }
139
146
  const sendCallsParams = Array.isArray(params) ? params[0] : params;
140
- validateSendCallsParams(sendCallsParams);
147
+ validateSendCallsParams(sendCallsParams, context);
141
148
  const {
142
149
  chainId,
143
150
  from,
@@ -496,15 +496,19 @@ function createEip5792Middleware({
496
496
  const {
497
497
  getSupportedChains,
498
498
  getCachedDelegations,
499
- updateDelegationCache
499
+ updateDelegationCache,
500
+ getSmartAccountEipStandard
500
501
  } = eip5792Config;
501
502
  const getCapabilitiesContext = {
502
503
  getSupportedChains,
503
504
  getCachedDelegations,
504
- updateDelegationCache
505
+ updateDelegationCache,
506
+ getSmartAccountEipStandard
505
507
  };
506
508
  const sendCallsContext = {
507
- processTransactionBatch
509
+ processTransaction,
510
+ processTransactionBatch,
511
+ getSmartAccountEipStandard
508
512
  };
509
513
  return createScaffoldMiddlewareV2({
510
514
  [EIP_5792_METHODS.WALLET_GET_CAPABILITIES]: async ({
@@ -1,10 +1,9 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import { BasePreferencesController, CHAIN_NAMESPACES, isUnauthorizedError, TransactionStatus } from '@toruslabs/base-controllers';
2
+ import { BasePreferencesController, CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
3
3
  import { remove0x } from '@toruslabs/metadata-helpers';
4
- import { Mutex } from 'async-mutex';
5
4
  import log from 'loglevel';
6
5
  import { MM_TOKEN_API_SUPPORTED_CHAINS, SUPPORTED_NETWORKS } from '../utils/constants.js';
7
- import { formatPastTx, addEtherscanTransactions, getEthTxStatus, formatTime, formatDate } from '../utils/helpers.js';
6
+ import { addEtherscanTransactions } from '../utils/helpers.js';
8
7
 
9
8
  class PreferencesController extends BasePreferencesController {
10
9
  constructor({
@@ -20,17 +19,12 @@ class PreferencesController extends BasePreferencesController {
20
19
  config,
21
20
  state,
22
21
  defaultPreferences: {
23
- formattedPastTransactions: [],
24
- fetchedPastTx: [],
25
- paymentTx: [],
26
22
  etherscanTransactions: []
27
23
  },
28
24
  signAuthMessage,
29
25
  validateSignMessage
30
26
  });
31
27
  _defineProperty(this, "chainNamespace", CHAIN_NAMESPACES.EIP155);
32
- _defineProperty(this, "_handle", void 0);
33
- _defineProperty(this, "_mutex", new Mutex());
34
28
  _defineProperty(this, "getProviderConfig", void 0);
35
29
  _defineProperty(this, "setProviderConfig", void 0);
36
30
  _defineProperty(this, "provider", void 0);
@@ -38,24 +32,6 @@ class PreferencesController extends BasePreferencesController {
38
32
  this.getProviderConfig = getProviderConfig;
39
33
  this.setProviderConfig = setProviderConfig;
40
34
  }
41
- async poll(interval) {
42
- var _this$getAddressState;
43
- const releaseLock = await this._mutex.acquire();
44
- if (interval) this.configure({
45
- pollInterval: interval
46
- });
47
- if (this._handle) window.clearTimeout(this._handle);
48
- // call here
49
- const storeSelectedAddress = this.state.selectedAddress;
50
- if (!storeSelectedAddress) return;
51
- if (!((_this$getAddressState = this.getAddressState(storeSelectedAddress)) !== null && _this$getAddressState !== void 0 && _this$getAddressState.jwtToken)) return;
52
- // This should never throw
53
- await this.sync(storeSelectedAddress);
54
- releaseLock();
55
- this._handle = window.setTimeout(() => {
56
- this.poll(this.config.pollInterval);
57
- }, this.config.pollInterval);
58
- }
59
35
  async initPreferences(params) {
60
36
  const {
61
37
  address,
@@ -63,7 +39,6 @@ class PreferencesController extends BasePreferencesController {
63
39
  calledFromEmbed,
64
40
  userInfo,
65
41
  rehydrate,
66
- locale = "en",
67
42
  type,
68
43
  signatures,
69
44
  web3AuthClientId,
@@ -97,26 +72,6 @@ class PreferencesController extends BasePreferencesController {
97
72
  authConnectionId,
98
73
  userId
99
74
  } = userInfo || {};
100
- const userExists = await this.sync(address);
101
- if (!userExists) {
102
- const accountState = this.getAddressState(address);
103
- await this.createUser({
104
- selectedCurrency: accountState.selectedCurrency,
105
- theme: accountState.theme,
106
- groupedAuthConnectionId,
107
- authConnectionId,
108
- userId,
109
- locale,
110
- address,
111
- type,
112
- web3AuthNetwork,
113
- metadata: {
114
- aa_provider: aaProvider,
115
- chain_id: chainId,
116
- eoa_address: eoaAddress
117
- }
118
- });
119
- }
120
75
  if (eoaAddress) this.updateState({
121
76
  eoaAddress
122
77
  }, address);
@@ -138,104 +93,16 @@ class PreferencesController extends BasePreferencesController {
138
93
  getSelectedAddress() {
139
94
  return this.state.selectedAddress;
140
95
  }
141
- async sync(address) {
142
- try {
143
- const user = await this.getUser(address);
144
- if (user) {
145
- const {
146
- default_currency: defaultCurrency,
147
- contacts,
148
- theme,
149
- locale,
150
- public_address: userPublicAddress,
151
- default_public_address: defaultPublicAddress,
152
- customNetworks,
153
- customTokens,
154
- customNfts,
155
- account_type: accountType
156
- } = user || {};
157
-
158
- // update latest data in state.
159
- this.updateState({
160
- contacts,
161
- theme,
162
- selectedCurrency: defaultCurrency,
163
- locale,
164
- defaultPublicAddress: defaultPublicAddress || userPublicAddress,
165
- customTokens,
166
- customNfts,
167
- customNetworks,
168
- accountType: accountType
169
- }, address);
170
- return true;
171
- }
172
- return false;
173
- } catch (error) {
174
- if (isUnauthorizedError(error)) {
175
- throw error;
176
- }
177
- log.error(error);
178
- return false;
179
- } finally {
180
- this.getWalletOrders(address).then(walletTx => {
181
- // eslint-disable-next-line promise/always-return
182
- if (walletTx && walletTx.length > 0) {
183
- this.updateState({
184
- fetchedPastTx: [...walletTx]
185
- }, address);
186
- this.calculatePastTx(walletTx, address);
187
- }
188
- }).catch(error => log.error(error));
189
- }
190
- }
191
- async patchNewTx(tx, address) {
192
- var _this$getAddressState2;
193
- const formattedTx = formatPastTx({
194
- transaction: tx,
195
- blockExplorerUrl: this.getBlockExplorerUrl()
196
- });
197
- const storePastTx = ((_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions) || [];
198
- const duplicateIndex = storePastTx.findIndex(x => x.transaction_hash === tx.transaction_hash && x.chainId === tx.chain_id);
199
- if (tx.status === TransactionStatus.submitted || tx.status === TransactionStatus.confirmed) {
200
- if (duplicateIndex === -1) {
201
- var _tx$to;
202
- // No duplicate found
203
-
204
- const finalTx = this.cancelTxCalculate([...storePastTx, formattedTx]);
205
- tx.is_cancel = formattedTx.is_cancel;
206
- tx.to = (_tx$to = tx.to) === null || _tx$to === void 0 ? void 0 : _tx$to.toLowerCase();
207
- tx.from = tx.from.toLowerCase();
208
- this.updateState({
209
- formattedPastTransactions: finalTx
210
- }, address);
211
- this.postPastTx(tx, address);
212
- } else {
213
- // avoid overriding is_cancel
214
- formattedTx.is_cancel = storePastTx[duplicateIndex].is_cancel;
215
- storePastTx[duplicateIndex] = formattedTx;
216
- this.updateState({
217
- formattedPastTransactions: this.cancelTxCalculate([...storePastTx])
218
- }, address);
219
- }
220
- }
221
- }
222
- recalculatePastTx(address) {
223
- // This triggers store update which calculates past Tx status for that network
224
- const selectedAddress = address || this.state.selectedAddress;
225
- const state = this.getAddressState(selectedAddress);
226
- if (!(state !== null && state !== void 0 && state.fetchedPastTx)) return;
227
- this.calculatePastTx(state.fetchedPastTx, selectedAddress);
228
- }
229
96
  async refetchEtherscanTx(address) {
230
- var _this$getAddressState3;
97
+ var _this$getAddressState;
231
98
  const selectedAddress = address || this.state.selectedAddress;
232
99
  if (!selectedAddress) return [];
233
- const lowerCaseSelectedAddress = selectedAddress === null || selectedAddress === void 0 ? void 0 : selectedAddress.toLowerCase();
234
- if ((_this$getAddressState3 = this.getAddressState(selectedAddress)) !== null && _this$getAddressState3 !== void 0 && _this$getAddressState3.jwtToken) {
100
+ if ((_this$getAddressState = this.getAddressState(selectedAddress)) !== null && _this$getAddressState !== void 0 && _this$getAddressState.jwtToken) {
235
101
  const {
236
102
  chainId
237
103
  } = this.getProviderConfig();
238
104
  if (MM_TOKEN_API_SUPPORTED_CHAINS.includes(chainId)) {
105
+ const lowerCaseSelectedAddress = selectedAddress.toLowerCase();
239
106
  const etherscanTxn = await this.fetchEtherscanTx({
240
107
  selectedAddress,
241
108
  chainId: this.getProviderConfig().chainId
@@ -293,15 +160,17 @@ class PreferencesController extends BasePreferencesController {
293
160
  return result.data;
294
161
  }
295
162
  getCustomTokens(address) {
296
- var _this$getAddressState4, _this$getAddressState5;
297
- return (_this$getAddressState4 = (_this$getAddressState5 = this.getAddressState(address)) === null || _this$getAddressState5 === void 0 ? void 0 : _this$getAddressState5.customTokens) !== null && _this$getAddressState4 !== void 0 ? _this$getAddressState4 : [];
163
+ var _this$getAddressState2, _this$getAddressState3;
164
+ return (_this$getAddressState2 = (_this$getAddressState3 = this.getAddressState(address)) === null || _this$getAddressState3 === void 0 ? void 0 : _this$getAddressState3.customTokens) !== null && _this$getAddressState2 !== void 0 ? _this$getAddressState2 : [];
298
165
  }
299
166
  getCustomNfts(address) {
300
- var _this$getAddressState6, _this$getAddressState7;
301
- return (_this$getAddressState6 = (_this$getAddressState7 = this.getAddressState(address)) === null || _this$getAddressState7 === void 0 ? void 0 : _this$getAddressState7.customNfts) !== null && _this$getAddressState6 !== void 0 ? _this$getAddressState6 : [];
167
+ var _this$getAddressState4, _this$getAddressState5;
168
+ return (_this$getAddressState4 = (_this$getAddressState5 = this.getAddressState(address)) === null || _this$getAddressState5 === void 0 ? void 0 : _this$getAddressState5.customNfts) !== null && _this$getAddressState4 !== void 0 ? _this$getAddressState4 : [];
302
169
  }
303
- isChainIdSupported(address, chainId) {
304
- const approveChainOptions = this.getChainOptions(address);
170
+
171
+ // NOTE: keep address params for now, might need to handle aa addresses later
172
+ isChainIdSupported(_address, chainId) {
173
+ const approveChainOptions = this.getChainOptions();
305
174
  const providerConfig = approveChainOptions.find(x => remove0x(x.chainId) === chainId);
306
175
  return !!providerConfig;
307
176
  }
@@ -309,19 +178,7 @@ class PreferencesController extends BasePreferencesController {
309
178
  const approveChainOptions = this.getChainOptions();
310
179
  const providerConfig = approveChainOptions.find(x => x.chainId === network.chainId);
311
180
  if (providerConfig) return;
312
- const newNetwork = {
313
- displayName: network.chainName,
314
- rpcTarget: network.rpcUrls[0],
315
- ticker: network.nativeCurrency.symbol,
316
- chainId: network.chainId,
317
- blockExplorerUrl: network.blockExplorerUrls[0],
318
- tickerName: network.nativeCurrency.name,
319
- logo: network.nativeCurrency.symbol
320
- };
321
- const isSuccess = await this.addCustomNetwork({
322
- network: newNetwork
323
- });
324
- if (!isSuccess) throw new Error("unable to add custom network");
181
+ throw new Error(`chainId ${network.chainId} is not supported`);
325
182
  }
326
183
  switchChain(data) {
327
184
  const chainOptions = this.getChainOptions();
@@ -332,103 +189,8 @@ class PreferencesController extends BasePreferencesController {
332
189
  throw new Error(`chainId ${data.chainId} is not supported`);
333
190
  }
334
191
  }
335
-
336
- // Custom Network methods
337
- async addCustomNetwork({
338
- network
339
- }) {
340
- try {
341
- const {
342
- selectedAddress
343
- } = this.state;
344
- const payload = {
345
- network_name: network.displayName,
346
- rpc_url: network.rpcTarget,
347
- chain_id: network.chainId,
348
- symbol: network.ticker,
349
- block_explorer_url: network.blockExplorerUrl || undefined,
350
- is_testnet: network.isTestnet || false,
351
- logo: network.logo,
352
- symbol_name: network.tickerName
353
- };
354
- const res = await this.wsApiClient.authPost("customnetwork", payload, this.authCredentials(selectedAddress), {
355
- useAPIKey: true
356
- });
357
- await this.sync(selectedAddress);
358
- return res.data.id;
359
- } catch {
360
- log.error("error adding custom network");
361
- return null;
362
- }
363
- }
364
- async deleteCustomNetwork(id) {
365
- try {
366
- const {
367
- selectedAddress
368
- } = this.state;
369
- await this.wsApiClient.authRemove(`customnetwork/${id}`, {}, this.authCredentials(selectedAddress), {
370
- useAPIKey: true
371
- });
372
- await this.sync(selectedAddress);
373
- return true;
374
- } catch {
375
- log.error("error deleting custom network");
376
- return false;
377
- }
378
- }
379
- async editCustomNetwork({
380
- network,
381
- id
382
- }) {
383
- try {
384
- const {
385
- selectedAddress
386
- } = this.state;
387
- const payload = {
388
- network_name: network.displayName,
389
- rpc_url: network.rpcTarget,
390
- chain_id: network.chainId,
391
- symbol: network.ticker || undefined,
392
- block_explorer_url: network.blockExplorerUrl || undefined,
393
- is_testnet: network.isTestnet || false
394
- };
395
- await this.wsApiClient.authPatch(`customnetwork/${id}`, payload, this.authCredentials(selectedAddress), {
396
- useAPIKey: true
397
- });
398
- await this.sync(selectedAddress);
399
- return true;
400
- } catch {
401
- log.error("error editing custom network");
402
- return false;
403
- }
404
- }
405
- getChainOptions(address = this.state.selectedAddress) {
406
- var _identities$address$c, _identities$address;
407
- const {
408
- identities
409
- } = this.state;
410
- const customNetworks = (_identities$address$c = (_identities$address = identities[address]) === null || _identities$address === void 0 ? void 0 : _identities$address.customNetworks) !== null && _identities$address$c !== void 0 ? _identities$address$c : [];
411
- const custom = Object.values(customNetworks).reduce((chains, network) => {
412
- const networkItem = {
413
- blockExplorerUrl: network.block_explorer_url,
414
- chainId: network.chain_id,
415
- displayName: network.network_name,
416
- logo: "eth.svg",
417
- rpcTarget: network.rpc_url,
418
- ticker: network.symbol,
419
- tickerName: network.symbol.toUpperCase(),
420
- isCustom: true,
421
- id: network.id
422
- };
423
- if (Object.keys(SUPPORTED_NETWORKS).includes(networkItem.chainId)) return chains;
424
- chains.push(networkItem);
425
- return chains;
426
- }, []);
427
- const supported = Object.values(SUPPORTED_NETWORKS).reduce((chains, network) => {
428
- chains.push(network);
429
- return chains;
430
- }, []);
431
- return [...supported, ...custom];
192
+ getChainOptions() {
193
+ return Object.values(SUPPORTED_NETWORKS);
432
194
  }
433
195
  getBlockExplorerUrl() {
434
196
  const supportedNetworks = this.getChainOptions();
@@ -436,77 +198,6 @@ class PreferencesController extends BasePreferencesController {
436
198
  if (!network) return "";
437
199
  return `${network.blockExplorerUrl}`;
438
200
  }
439
- async calculatePastTx(txs, address) {
440
- const pastTx = [];
441
- const pendingTx = [];
442
- const lowerCaseSelectedAddress = address.toLowerCase();
443
- const supportedNetworks = this.getChainOptions(address);
444
- const supportedNetwork = supportedNetworks.find(x => x.chainId === this.getProviderConfig().chainId);
445
- for (const x of txs) {
446
- var _x$to;
447
- if ((supportedNetwork === null || supportedNetwork === void 0 ? void 0 : supportedNetwork.chainId) === x.chain_id && x.to && x.from && (lowerCaseSelectedAddress === x.from.toLowerCase() || lowerCaseSelectedAddress === ((_x$to = x.to) === null || _x$to === void 0 ? void 0 : _x$to.toLowerCase()))) {
448
- if (x.status !== "confirmed") {
449
- pendingTx.push(x);
450
- } else {
451
- const finalObject = formatPastTx({
452
- transaction: x,
453
- lowerCaseSelectedAddress,
454
- blockExplorerUrl: this.getBlockExplorerUrl()
455
- });
456
- pastTx.push(finalObject);
457
- }
458
- }
459
- }
460
- const pendingTxPromises = pendingTx.map(x => getEthTxStatus(x.transaction_hash, this.provider).catch(error => log.error(error)));
461
- const resolvedTxStatuses = await Promise.all(pendingTxPromises);
462
- for (const [index, element] of pendingTx.entries()) {
463
- const finalObject = formatPastTx({
464
- transaction: element,
465
- lowerCaseSelectedAddress,
466
- blockExplorerUrl: this.getBlockExplorerUrl()
467
- });
468
- finalObject.status = resolvedTxStatuses[index] || TransactionStatus.submitted;
469
- pastTx.push(finalObject);
470
- if (lowerCaseSelectedAddress === element.from.toLowerCase() && finalObject.status && finalObject.status !== element.status) this.patchPastTx({
471
- id: element.id,
472
- status: finalObject.status
473
- }, address);
474
- }
475
- const finalTx = this.cancelTxCalculate(pastTx);
476
- this.updateState({
477
- formattedPastTransactions: [...finalTx]
478
- }, address);
479
- }
480
- cancelTxCalculate(pastTx) {
481
- const nonceMap = {};
482
- for (const x of pastTx) {
483
- if (!nonceMap[x.nonce]) nonceMap[x.nonce] = [x];else {
484
- nonceMap[x.nonce].push(x);
485
- }
486
- }
487
- for (const [, value] of Object.entries(nonceMap)) {
488
- // has duplicate
489
- if (value.length > 1) {
490
- // get latest and mark it as is_cancel
491
- const latestTxs = value.sort((a, b) => {
492
- const aDate = new Date(a.date).getTime();
493
- const bDate = new Date(b.date).getTime();
494
- return bDate - aDate;
495
- });
496
- const latestCancelTx = latestTxs[0];
497
- latestCancelTx.is_cancel = true;
498
- latestTxs.slice(1).forEach(x => {
499
- x.hasCancel = true;
500
- x.status = latestCancelTx.status === "confirmed" ? TransactionStatus.cancelled : TransactionStatus.cancelling;
501
- x.cancelDateInitiated = `${formatTime(new Date(latestCancelTx.date).getTime())} - ${formatDate(latestCancelTx.date)}`;
502
- x.etherscanLink = latestCancelTx.etherscanLink;
503
- x.cancelGas = latestCancelTx.gas;
504
- x.cancelGasPrice = latestCancelTx.gasPrice;
505
- });
506
- }
507
- }
508
- return pastTx;
509
- }
510
201
  }
511
202
 
512
203
  export { PreferencesController };
@@ -25,7 +25,7 @@ export { generateHistoryEntry, replayHistory, snapshotFromTxMeta } from './Trans
25
25
  export { TransactionStateManager } from './Transaction/TransactionStateManager.js';
26
26
  export { createNestedTransactionMeta, determineTransactionType, ensureFieldIsString, ensureMutuallyExclusiveFieldsNotProvided, getFinalStates, isEIP1559Transaction, isEip7702SetCodeTx, isEip7702UpgradeWithDataToSelfTransaction, isLegacyTransaction, normalizeAndValidateTxParams, normalizeTxParameters, parseStandardTokenTransactionData, readAddressAsContract, transactionMatchesNetwork, validateFrom, validateRecipient, validateTxParameters } from './Transaction/TransactionUtils.js';
27
27
  export { erc1155Abi, erc20Abi, erc721Abi, erc7821Abi, singleBalanceCheckerAbi } from './utils/abis.js';
28
- export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID } from './utils/constants.js';
28
+ export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SMART_ACCOUNT_EIP_STANDARD, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID } from './utils/constants.js';
29
29
  export { addCurrencies, conversionGTE, conversionGreaterThan, conversionLTE, conversionLessThan, conversionMax, conversionUtil, decGWEIToHexWEI, getBigNumber, hexWEIToDecGWEI, multiplyCurrencies, subtractCurrencies, toNegative } from './utils/conversionUtils.js';
30
30
  export { EIP5792ErrorCode, EIP_5792_METHODS, Eip5792AtomicStatus, GetCallsStatusCode } from './utils/eip5792Types.js';
31
31
  export { DUMMY_AUTHORIZATION_SIGNATURE, EIP_7702_METHODS, EIP_7702_PREFIX, EIP_7702_REVOKE_ADDRESS } from './utils/eip7702Types.js';
@@ -366,5 +366,10 @@ const SMART_ACCOUNT = {
366
366
  NEXUS: "nexus",
367
367
  METAMASK: "metamask"
368
368
  };
369
+ const SMART_ACCOUNT_EIP_STANDARD = {
370
+ ERC_4337: "4337",
371
+ EIP_7702: "7702"
372
+ };
373
+ const EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES = [SMART_ACCOUNT.METAMASK];
369
374
 
370
- export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID };
375
+ export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SMART_ACCOUNT_EIP_STANDARD, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID };
@@ -67,8 +67,6 @@ const TRANSACTION_CATEGORY_EIP7702 = {
67
67
 
68
68
  /**
69
69
  * A SignatureLike
70
- *
71
- * @_docloc: api/crypto:Signing
72
70
  */
73
71
 
74
72
  /**