@toruslabs/ethereum-controllers 9.2.0 → 9.4.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 (31) hide show
  1. package/dist/lib.cjs/Currency/CurrencyController.js +9 -4
  2. package/dist/lib.cjs/Eip5792/walletGetCapabilities.js +9 -0
  3. package/dist/lib.cjs/Eip5792/walletSendCalls.js +8 -2
  4. package/dist/lib.cjs/Network/createEthereumMiddleware.js +7 -3
  5. package/dist/lib.cjs/Preferences/PreferencesController.js +34 -400
  6. package/dist/lib.cjs/Tokens/TokenRatesController.js +16 -7
  7. package/dist/lib.cjs/Transaction/TransactionController.js +1 -1
  8. package/dist/lib.cjs/index.js +2 -2
  9. package/dist/lib.cjs/types/Currency/CurrencyController.d.ts +4 -2
  10. package/dist/lib.cjs/types/Eip5792/walletGetCapabilities.d.ts +2 -1
  11. package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +4 -2
  12. package/dist/lib.cjs/types/Network/interfaces.d.ts +5 -1
  13. package/dist/lib.cjs/types/Preferences/IPreferencesController.d.ts +0 -6
  14. package/dist/lib.cjs/types/Preferences/PreferencesController.d.ts +5 -29
  15. package/dist/lib.cjs/types/Tokens/TokenRatesController.d.ts +5 -3
  16. package/dist/lib.cjs/types/utils/constants.d.ts +5 -0
  17. package/dist/lib.cjs/types/utils/helpers.d.ts +0 -13
  18. package/dist/lib.cjs/types/utils/interfaces.d.ts +6 -68
  19. package/dist/lib.cjs/utils/constants.js +7 -0
  20. package/dist/lib.cjs/utils/helpers.js +0 -119
  21. package/dist/lib.esm/Currency/CurrencyController.js +10 -5
  22. package/dist/lib.esm/Eip5792/walletGetCapabilities.js +9 -0
  23. package/dist/lib.esm/Eip5792/walletSendCalls.js +9 -2
  24. package/dist/lib.esm/Network/createEthereumMiddleware.js +7 -3
  25. package/dist/lib.esm/Preferences/PreferencesController.js +37 -405
  26. package/dist/lib.esm/Tokens/TokenRatesController.js +17 -8
  27. package/dist/lib.esm/index.js +2 -2
  28. package/dist/lib.esm/utils/constants.js +6 -1
  29. package/dist/lib.esm/utils/helpers.js +3 -120
  30. package/dist/lib.esm/utils/interfaces.js +0 -2
  31. package/package.json +6 -6
@@ -3,7 +3,6 @@
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 httpHelpers = require('@toruslabs/http-helpers');
7
6
  var log = require('loglevel');
8
7
  var constants = require('../utils/constants.js');
9
8
 
@@ -15,13 +14,15 @@ class TokenRatesController extends baseControllers.BaseController {
15
14
  idleTimeTracker,
16
15
  onPreferencesStateChange,
17
16
  onNetworkStateChange,
18
- onTokensStateChange
17
+ onTokensStateChange,
18
+ getAuthHttpClient
19
19
  }) {
20
20
  super({
21
21
  config,
22
22
  state
23
23
  });
24
24
  _defineProperty(this, "pollingManager", void 0);
25
+ _defineProperty(this, "getAuthHttpClient", void 0);
25
26
  this.defaultState = _objectSpread(_objectSpread({}, this.defaultState), {}, {
26
27
  contractExchangeRates: {}
27
28
  });
@@ -49,17 +50,18 @@ class TokenRatesController extends baseControllers.BaseController {
49
50
  tokens
50
51
  } = tokensState;
51
52
  const currentUserTokens = tokens[this.config.selectedAddress];
52
- if ((currentUserTokens === null || currentUserTokens === void 0 ? void 0 : currentUserTokens.length) > 0 && this.config.tokens !== tokens[this.config.selectedAddress]) {
53
+ if ((currentUserTokens === null || currentUserTokens === void 0 ? void 0 : currentUserTokens.length) > 0 && this.config.tokens !== currentUserTokens) {
53
54
  this.configure({
54
- tokens: tokens[this.config.selectedAddress]
55
+ tokens: currentUserTokens
55
56
  });
56
57
  this.updateExchangeRates();
57
58
  }
58
59
  });
60
+ this.getAuthHttpClient = getAuthHttpClient;
59
61
  this.pollingManager = new baseControllers.PollingManager(idleTimeTracker, this.config.pollInterval);
60
62
  }
61
63
  /**
62
- * Creates a new poll, using setInterval, to periodically call updateConversionRate. The id of the interval is
64
+ * Creates a new poll, using setInterval, to periodically call updateExchangeRates. The id of the interval is
63
65
  * stored at the controller's conversionInterval property. If it is called and such an id already exists, the
64
66
  * previous interval is clear and a new one is created.
65
67
  */
@@ -82,17 +84,24 @@ class TokenRatesController extends baseControllers.BaseController {
82
84
  });
83
85
  }
84
86
  async fetchExchangeRates(nativeCurrency, chainCodes) {
87
+ const httpClient = baseControllers.resolveAuthHttpClient(this.getAuthHttpClient, this.name);
85
88
  const contractAddresses = this.config.tokens.map(token => token.tokenAddress);
86
89
  const isNativeCurrencySupported = constants.COINGECKO_SUPPORTED_CURRENCIES.has(nativeCurrency.toLowerCase());
87
90
  if (isNativeCurrencySupported) {
88
- const response = await httpHelpers.get(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}`);
91
+ const response = await httpClient.get(`${this.config.currencyApi}/v2/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}`, {
92
+ authenticated: true
93
+ });
89
94
  const newContractExchangeRates = {};
90
95
  Object.keys(response).forEach(contractAddress => {
91
96
  newContractExchangeRates[contractAddress] = response[contractAddress][nativeCurrency.toLowerCase()] || 0;
92
97
  });
93
98
  return newContractExchangeRates;
94
99
  }
95
- const [response, currencyResponse] = await Promise.all([httpHelpers.get(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}`), httpHelpers.get(`${this.config.currencyApi}/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`)]);
100
+ const [response, currencyResponse] = await Promise.all([httpClient.get(`${this.config.currencyApi}/v2/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}`, {
101
+ authenticated: true
102
+ }), httpClient.get(`${this.config.currencyApi}/v2/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`, {
103
+ authenticated: true
104
+ })]);
96
105
  const newContractExchangeRates = {};
97
106
  Object.keys(response).forEach(contractAddress => {
98
107
  newContractExchangeRates[contractAddress] = response[contractAddress][DEFAULT_CURRENCY] * Number.parseFloat(currencyResponse[DEFAULT_CURRENCY]) || 0;
@@ -9,8 +9,8 @@ var bignumber_js = require('bignumber.js');
9
9
  var log = require('loglevel');
10
10
  var viem = require('viem');
11
11
  var eip7702Utils = require('../Eip7702/eip7702Utils.js');
12
- var walletSendCalls = require('../Eip5792/walletSendCalls.js');
13
12
  var constants = require('../utils/constants.js');
13
+ var walletSendCalls = require('../Eip5792/walletSendCalls.js');
14
14
  var conversionUtils = require('../utils/conversionUtils.js');
15
15
  var helpers = require('../utils/helpers.js');
16
16
  var interfaces = require('../utils/interfaces.js');
@@ -171,6 +171,7 @@ exports.CONTRACT_TYPE_ERC20 = constants.CONTRACT_TYPE_ERC20;
171
171
  exports.CONTRACT_TYPE_ERC721 = constants.CONTRACT_TYPE_ERC721;
172
172
  exports.CONTRACT_TYPE_ERC7821 = constants.CONTRACT_TYPE_ERC7821;
173
173
  exports.CONTRACT_TYPE_ETH = constants.CONTRACT_TYPE_ETH;
174
+ exports.EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES = constants.EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES;
174
175
  exports.ERC1155_INTERFACE_ID = constants.ERC1155_INTERFACE_ID;
175
176
  exports.ERC721_ENUMERABLE_INTERFACE_ID = constants.ERC721_ENUMERABLE_INTERFACE_ID;
176
177
  exports.ERC721_INTERFACE_ID = constants.ERC721_INTERFACE_ID;
@@ -191,6 +192,7 @@ exports.POLYGON_AMOY_CHAIN_ID = constants.POLYGON_AMOY_CHAIN_ID;
191
192
  exports.POLYGON_CHAIN_ID = constants.POLYGON_CHAIN_ID;
192
193
  exports.SEPOLIA_CHAIN_ID = constants.SEPOLIA_CHAIN_ID;
193
194
  exports.SMART_ACCOUNT = constants.SMART_ACCOUNT;
195
+ exports.SMART_ACCOUNT_EIP_STANDARD = constants.SMART_ACCOUNT_EIP_STANDARD;
194
196
  exports.SUPPORTED_NETWORKS = constants.SUPPORTED_NETWORKS;
195
197
  exports.TEST_CHAINS = constants.TEST_CHAINS;
196
198
  exports.TRANSACTION_ENVELOPE_TYPES = constants.TRANSACTION_ENVELOPE_TYPES;
@@ -218,10 +220,8 @@ exports.EIP_7702_PREFIX = eip7702Types.EIP_7702_PREFIX;
218
220
  exports.EIP_7702_REVOKE_ADDRESS = eip7702Types.EIP_7702_REVOKE_ADDRESS;
219
221
  exports.BNToHex = helpers.BNToHex;
220
222
  exports.GAS_LIMITS = helpers.GAS_LIMITS;
221
- exports.addEtherscanTransactions = helpers.addEtherscanTransactions;
222
223
  exports.bnLessThan = helpers.bnLessThan;
223
224
  exports.formatDate = helpers.formatDate;
224
- exports.formatPastTx = helpers.formatPastTx;
225
225
  exports.formatTime = helpers.formatTime;
226
226
  exports.getChainType = helpers.getChainType;
227
227
  exports.getEthTxStatus = helpers.getEthTxStatus;
@@ -1,4 +1,4 @@
1
- import { BaseCurrencyController, BaseCurrencyControllerConfig, BaseCurrencyControllerState, ICurrencyController, IdleTimeTracker } from "@toruslabs/base-controllers";
1
+ import { AuthHttpClientGetter, BaseCurrencyController, BaseCurrencyControllerConfig, BaseCurrencyControllerState, ICurrencyController, IdleTimeTracker } from "@toruslabs/base-controllers";
2
2
  import { EthereumNetworkState } from "../utils/interfaces";
3
3
  export interface IEthereumCurrencyControllerState extends BaseCurrencyControllerState {
4
4
  commonDenomination: string;
@@ -6,11 +6,13 @@ export interface IEthereumCurrencyControllerState extends BaseCurrencyController
6
6
  }
7
7
  export declare class CurrencyController extends BaseCurrencyController<BaseCurrencyControllerConfig, IEthereumCurrencyControllerState> implements ICurrencyController<BaseCurrencyControllerConfig, IEthereumCurrencyControllerState> {
8
8
  private pollingManager;
9
- constructor({ config, state, idleTimeTracker, onNetworkChanged, }: {
9
+ private readonly getAuthHttpClient;
10
+ constructor({ config, state, idleTimeTracker, onNetworkChanged, getAuthHttpClient, }: {
10
11
  config: Partial<BaseCurrencyControllerConfig>;
11
12
  state: Partial<IEthereumCurrencyControllerState>;
12
13
  idleTimeTracker: IdleTimeTracker;
13
14
  onNetworkChanged: (listener: (networkState: EthereumNetworkState) => void) => void;
15
+ getAuthHttpClient: AuthHttpClientGetter;
14
16
  });
15
17
  setCommonDenomination(commonDenomination: string): void;
16
18
  getCommonDenomination(): string;
@@ -1,10 +1,11 @@
1
1
  import { JRPCRequest } from "@web3auth/auth";
2
2
  import { Eip5792GetCapabilitiesParams, Eip5792GetCapabilitiesResponse, GetCachedDelegationsFn, GetSupportedChainsFn } from "../utils/eip5792Types";
3
- import { GetEthCodeFn } from "../utils/interfaces";
3
+ import { type GetEthCodeFn, type SmartAccountEipStandardType } from "../utils/interfaces";
4
4
  export interface WalletGetCapabilitiesContext {
5
5
  getSupportedChains: GetSupportedChainsFn;
6
6
  getCachedDelegations?: GetCachedDelegationsFn;
7
7
  updateDelegationCache?: (walletAddress: `0x${string}`, chainId: `0x${string}`, delegation: `0x${string}` | null) => void;
8
+ getSmartAccountEipStandard: () => SmartAccountEipStandardType | undefined;
8
9
  }
9
10
  /**
10
11
  * Handler for wallet_getCapabilities (EIP-5792).
@@ -1,10 +1,11 @@
1
1
  import { JRPCRequest } from "@web3auth/auth";
2
2
  import { IProviderHandlers } from "../Network/interfaces";
3
3
  import { BatchTransactionParams, Eip5792SendCallsParams } from "../utils/eip5792Types";
4
- import { GetEthCodeFn } from "../utils/interfaces";
4
+ import { GetEthCodeFn, SmartAccountEipStandardType } from "../utils/interfaces";
5
5
  export interface WalletSendCallsContext {
6
6
  processTransaction: IProviderHandlers["processTransaction"];
7
7
  processTransactionBatch: IProviderHandlers["processTransactionBatch"];
8
+ getSmartAccountEipStandard: () => SmartAccountEipStandardType | undefined;
8
9
  }
9
10
  /**
10
11
  * Generates a unique batch ID for EIP-5792 calls.
@@ -14,8 +15,9 @@ export declare function generateBatchId(): `0x${string}`;
14
15
  /**
15
16
  * Validates the parameters for wallet_sendCalls (EIP-5792).
16
17
  * @param sendCallsParams - The parameters to validate.
18
+ * @param context - The context
17
19
  */
18
- export declare function validateSendCallsParams(sendCallsParams: Eip5792SendCallsParams): void;
20
+ export declare function validateSendCallsParams(sendCallsParams: Eip5792SendCallsParams, context: WalletSendCallsContext): void;
19
21
  export declare function processMultipleTransactions({ from, transactions, request, chainId, getEthCode, processTransactionBatch, }: {
20
22
  from: `0x${string}`;
21
23
  transactions: {
@@ -2,7 +2,7 @@ import { InPageWalletProviderState, SwitchChainMessageParams } from "@toruslabs/
2
2
  import { JRPCRequest } from "@web3auth/auth";
3
3
  import { TransactionStateManager } from "../Transaction/TransactionStateManager";
4
4
  import { Eip5792SendCallsParams, TransactionBatchRequest } from "../utils/eip5792Types";
5
- import { AddChainMessageParams, EthereumTransactionMeta, GetEthCodeFn, MessageParams, TransactionParams, TypedMessageParams, UserOperationGas, UserRequestApprovalParams } from "../utils/interfaces";
5
+ import { AddChainMessageParams, EthereumTransactionMeta, GetEthCodeFn, MessageParams, SmartAccountEipStandardType, TransactionParams, TypedMessageParams, UserOperationGas, UserRequestApprovalParams } from "../utils/interfaces";
6
6
  export interface IProviderHandlers {
7
7
  version: string;
8
8
  aaConfig?: {
@@ -45,6 +45,10 @@ export interface IProviderHandlers {
45
45
  * Get the list of supported chain IDs for EIP-5792/EIP-7702.
46
46
  */
47
47
  getSupportedChains: () => `0x${string}`[];
48
+ /**
49
+ * Smart account EIP standard (4337 or 7702).
50
+ */
51
+ getSmartAccountEipStandard: () => SmartAccountEipStandardType | undefined;
48
52
  /**
49
53
  * Get cached delegation addresses.
50
54
  * Key format: `${walletAddress}-${chainId}`
@@ -1,10 +1,4 @@
1
1
  import { AddressPreferences } from "@toruslabs/base-controllers";
2
- import { CustomNetworks, FetchCommonTransaction, FetchedTransaction, FormattedTransactionActivity } from "../utils/interfaces";
3
2
  export interface ExtendedAddressPreferences extends AddressPreferences {
4
3
  eoaAddress?: string;
5
- fetchedPastTx?: FetchedTransaction[];
6
- formattedPastTransactions?: FormattedTransactionActivity[];
7
- paymentTx: FetchCommonTransaction[];
8
- customNetworks: CustomNetworks[];
9
- etherscanTransactions?: FormattedTransactionActivity[];
10
4
  }
@@ -1,42 +1,29 @@
1
- import { BasePreferencesController, CustomNft, CustomToken, InitPreferencesParams, IPreferencesController, PreferencesConfig, PreferencesState } from "@toruslabs/base-controllers";
2
- import { SafeEventEmitterProvider } from "@web3auth/auth";
1
+ import { AuthHttpClientGetter, BasePreferencesController, CustomNft, CustomToken, InitPreferencesParams, IPreferencesController, PreferencesConfig, PreferencesState } from "@toruslabs/base-controllers";
3
2
  import { KeyringController } from "../Keyring/KeyringController";
4
3
  import { NetworkController } from "../Network/NetworkController";
5
4
  import { EthereumNftInfo as CustomNftInfo } from "../Nfts/INftsController";
6
- import type { AddChainMessageParams, CustomNetworkPayload, CustomTokenInfo, EtherscanTransaction, TransactionPayload } from "../utils/interfaces";
5
+ import type { AddChainMessageParams, CustomTokenInfo } from "../utils/interfaces";
7
6
  import { ExtendedAddressPreferences } from "./IPreferencesController";
8
7
  export interface IPreferencesControllerOptions {
9
8
  config?: Partial<PreferencesConfig> & Pick<PreferencesConfig, "api" | "commonApiHost">;
10
9
  state?: Partial<PreferencesState<ExtendedAddressPreferences>>;
11
- provider: SafeEventEmitterProvider;
12
10
  signAuthMessage?: KeyringController["signAuthMessage"];
13
11
  getProviderConfig?: NetworkController["getProviderConfig"];
14
12
  setProviderConfig?: NetworkController["setProviderConfig"];
15
13
  validateSignMessage: (message: string) => Promise<void>;
14
+ getAuthHttpClient: AuthHttpClientGetter;
16
15
  }
17
16
  export declare class PreferencesController extends BasePreferencesController<ExtendedAddressPreferences, PreferencesConfig, PreferencesState<ExtendedAddressPreferences>> implements IPreferencesController<ExtendedAddressPreferences, PreferencesConfig, PreferencesState<ExtendedAddressPreferences>> {
18
17
  protected chainNamespace: "eip155";
19
- private _handle?;
20
- private _mutex;
21
18
  private getProviderConfig;
22
19
  private setProviderConfig;
23
- private provider;
24
- constructor({ config, state, provider, signAuthMessage, getProviderConfig, setProviderConfig, validateSignMessage, }: IPreferencesControllerOptions);
25
- poll(interval?: number): Promise<void>;
20
+ constructor({ config, state, signAuthMessage, getProviderConfig, setProviderConfig, validateSignMessage, getAuthHttpClient, }: IPreferencesControllerOptions);
26
21
  initPreferences(params: InitPreferencesParams & {
27
22
  eoaAddress?: string;
28
23
  aaProvider?: string;
29
24
  mainAddress?: string;
30
25
  }): Promise<void>;
31
26
  getSelectedAddress(): string;
32
- sync(address: string): Promise<boolean>;
33
- patchNewTx(tx: TransactionPayload, address: string): Promise<void>;
34
- recalculatePastTx(address?: string): void;
35
- refetchEtherscanTx(address?: string): Promise<EtherscanTransaction[]>;
36
- fetchEtherscanTx<T>(parameters: {
37
- selectedAddress: string;
38
- chainId: string;
39
- }): Promise<T[]>;
40
27
  fetchQuote<T>(parameters: {
41
28
  chainId: string;
42
29
  fromToken: string;
@@ -57,21 +44,10 @@ export declare class PreferencesController extends BasePreferencesController<Ext
57
44
  getSimpleHashNfts(address: string, chainId: string, skipCache?: boolean): Promise<CustomNftInfo[]>;
58
45
  getCustomTokens(address?: string): CustomToken[];
59
46
  getCustomNfts(address?: string): CustomNft[];
60
- isChainIdSupported(address: string, chainId: string): boolean;
47
+ isChainIdSupported(_address: string, chainId: string): boolean;
61
48
  addChain(network: AddChainMessageParams): Promise<void>;
62
49
  switchChain(data: {
63
50
  chainId: string;
64
51
  }): void;
65
- addCustomNetwork({ network }: {
66
- network: CustomNetworkPayload;
67
- }): Promise<number>;
68
- deleteCustomNetwork(id: number): Promise<boolean>;
69
- editCustomNetwork({ network, id }: {
70
- network: CustomNetworkPayload;
71
- id: number | null;
72
- }): Promise<boolean>;
73
52
  private getChainOptions;
74
- private getBlockExplorerUrl;
75
- private calculatePastTx;
76
- private cancelTxCalculate;
77
53
  }
@@ -1,4 +1,4 @@
1
- import { BaseController, BaseTokenRatesControllerConfig, BaseTokenRatesControllerState, IdleTimeTracker, ITokenRatesController, PreferencesState } from "@toruslabs/base-controllers";
1
+ import { AuthHttpClientGetter, BaseController, BaseTokenRatesControllerConfig, BaseTokenRatesControllerState, IdleTimeTracker, ITokenRatesController, PreferencesState } from "@toruslabs/base-controllers";
2
2
  import { ExtendedAddressPreferences } from "../Preferences/IPreferencesController";
3
3
  import { CustomTokenInfo, EthereumNetworkState } from "../utils/interfaces";
4
4
  import { EthereumTokensControllerState } from "./ITokensController";
@@ -20,12 +20,14 @@ export interface TokenRatesControllerOptions {
20
20
  onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
21
21
  onTokensStateChange: (listener: (tokensState: EthereumTokensControllerState) => void) => void;
22
22
  onNetworkStateChange: (listener: (networkState: EthereumNetworkState) => void) => void;
23
+ getAuthHttpClient: AuthHttpClientGetter;
23
24
  }
24
25
  export declare class TokenRatesController extends BaseController<ITokenRatesControllerConfig, ITokenRatesControllerState> implements ITokenRatesController<ITokenRatesControllerConfig, ITokenRatesControllerState> {
25
26
  private pollingManager;
26
- constructor({ config, state, idleTimeTracker, onPreferencesStateChange, onNetworkStateChange, onTokensStateChange }: TokenRatesControllerOptions);
27
+ private readonly getAuthHttpClient;
28
+ constructor({ config, state, idleTimeTracker, onPreferencesStateChange, onNetworkStateChange, onTokensStateChange, getAuthHttpClient, }: TokenRatesControllerOptions);
27
29
  /**
28
- * Creates a new poll, using setInterval, to periodically call updateConversionRate. The id of the interval is
30
+ * Creates a new poll, using setInterval, to periodically call updateExchangeRates. The id of the interval is
29
31
  * stored at the controller's conversionInterval property. If it is called and such an id already exists, the
30
32
  * previous interval is clear and a new one is created.
31
33
  */
@@ -107,3 +107,8 @@ export declare const SMART_ACCOUNT: {
107
107
  readonly NEXUS: "nexus";
108
108
  readonly METAMASK: "metamask";
109
109
  };
110
+ export declare const SMART_ACCOUNT_EIP_STANDARD: {
111
+ readonly ERC_4337: "4337";
112
+ readonly EIP_7702: "7702";
113
+ };
114
+ export declare const EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES: readonly ["metamask"];
@@ -1,14 +1,8 @@
1
1
  import { TransactionStatus } from "@toruslabs/base-controllers";
2
2
  import { SafeEventEmitterProvider } from "@web3auth/auth";
3
- import { EtherscanTransaction, FormattedTransactionActivity, TransactionPayload } from "./interfaces";
4
3
  export declare function hexToBn(hex: string): BigNumber;
5
4
  export declare function BNToHex(bn: BigNumber): string;
6
5
  export declare function getEtherScanHashLink(txHash: string, chainId: string): string;
7
- export declare const formatPastTx: (params: {
8
- transaction: TransactionPayload;
9
- blockExplorerUrl: string;
10
- lowerCaseSelectedAddress?: string;
11
- }) => FormattedTransactionActivity;
12
6
  /**
13
7
  * Ref - https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt
14
8
  */
@@ -25,10 +19,3 @@ export declare function bnLessThan(a: string | number, b: string | number): bool
25
19
  export declare const getIpfsEndpoint: (path: string) => string;
26
20
  export declare function sanitizeNftMetdataUrl(url: string): string;
27
21
  export declare function getChainType(chainId: string): "custom" | "mainnet" | "testnet";
28
- export declare const addEtherscanTransactions: (params: {
29
- txn: EtherscanTransaction[];
30
- lowerCaseSelectedAddress: string;
31
- provider: SafeEventEmitterProvider;
32
- chainId: string;
33
- blockExplorerUrl: string;
34
- }) => Promise<any[]>;
@@ -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, 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;
@@ -356,17 +337,6 @@ export interface FetchedTransaction extends TransactionPayload {
356
337
  export interface FetchCommonTransaction extends PaymentTransaction {
357
338
  etherscanLink?: string | null;
358
339
  }
359
- export interface FormattedTransactionActivity extends BaseFormattedTransactionActivity {
360
- from_aa_address?: string;
361
- etherscanLink: string;
362
- ethRate: string;
363
- isEtherscan?: boolean;
364
- nonce: string;
365
- gas: string;
366
- gasPrice: string;
367
- cancelGas?: string;
368
- cancelGasPrice?: string;
369
- }
370
340
  export interface ProviderChangeChannelEventData {
371
341
  newNetwork: EthereumProviderConfig;
372
342
  whitelabelData: PopupWhitelabelData;
@@ -379,38 +349,6 @@ export interface NonceLockRes {
379
349
  releaseLock: MutexInterface.Releaser;
380
350
  }
381
351
  export type METHOD_TYPES_TYPE = (typeof METHOD_TYPES)[keyof typeof METHOD_TYPES];
382
- export interface EtherscanTransaction {
383
- blockNumber: string;
384
- timeStamp: string;
385
- hash: string;
386
- nonce: string;
387
- blockHash: string;
388
- transactionIndex: string;
389
- from: string;
390
- to: string;
391
- value: string;
392
- gas: string;
393
- gasPrice: string;
394
- isError: string;
395
- txreceipt_status: string;
396
- input: string;
397
- contractAddress: string;
398
- cumulativeGasUsed: string;
399
- gasUsed: string;
400
- confirmations: string;
401
- methodId: string;
402
- functionName: string;
403
- transaction_category: string;
404
- type_name: string;
405
- type: string;
406
- type_image_link: string;
407
- chainId: string;
408
- tokenSymbol: string;
409
- tokenName: string;
410
- tokenID: string;
411
- tokenValue: string;
412
- tokenDecimal: string;
413
- }
414
352
  export interface NetworkControllerEvents<S> extends BaseControllerEvents<S> {
415
353
  networkDidChange: () => void;
416
354
  }
@@ -495,7 +433,9 @@ export interface ISmartAccount {
495
433
  }
496
434
  export type SmartAccountType = (typeof SMART_ACCOUNT)[keyof typeof SMART_ACCOUNT];
497
435
  export type SmartAccountConfig<TImplementation extends Implementation = Implementation.Hybrid> = BiconomySmartAccountConfig | KernelSmartAccountConfig | NexusSmartAccountConfig | SafeSmartAccountConfig | TrustSmartAccountConfig | MetamaskSmartAccountConfig<TImplementation>;
436
+ export type SmartAccountEipStandardType = (typeof SMART_ACCOUNT_EIP_STANDARD)[keyof typeof SMART_ACCOUNT_EIP_STANDARD];
498
437
  export type AccountAbstractionMultiChainConfig = {
438
+ smartAccountEipStandard?: SmartAccountEipStandardType;
499
439
  smartAccountType?: SmartAccountType;
500
440
  chains?: {
501
441
  chainId: string;
@@ -570,8 +510,6 @@ export type Numeric = number | bigint;
570
510
  export type BigNumberish = string | Numeric;
571
511
  /**
572
512
  * A SignatureLike
573
- *
574
- * @_docloc: api/crypto:Signing
575
513
  */
576
514
  export type SignatureLike = Signature | string | {
577
515
  r: string;
@@ -624,7 +562,7 @@ export interface TransactionLike<A = string> {
624
562
  */
625
563
  type?: null | number;
626
564
  /**
627
- * The recipient address or ``null`` for an ``init`` transaction.
565
+ * The recipient address or null for an init transaction.
628
566
  */
629
567
  to?: null | A;
630
568
  /**
@@ -691,7 +629,7 @@ export interface TransactionLike<A = string> {
691
629
  * An external library for computing the KZG commitments and
692
630
  * proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
693
631
  *
694
- * This is generally ``null``, unless you are creating BLOb
632
+ * This is generally null, unless you are creating BLOb
695
633
  * transactions.
696
634
  */
697
635
  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,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
3
  var baseControllers = require('@toruslabs/base-controllers');
5
4
  var metadataHelpers = require('@toruslabs/metadata-helpers');
6
5
  var bignumber_js = require('bignumber.js');
7
6
  var log = require('loglevel');
8
7
  var viem = require('viem');
9
- var TransactionUtils = require('../Transaction/TransactionUtils.js');
10
8
  var constants = require('./constants.js');
11
9
 
12
10
  function hexToBn(hex) {
@@ -19,51 +17,6 @@ function getEtherScanHashLink(txHash, chainId) {
19
17
  if (!constants.SUPPORTED_NETWORKS[chainId]) return "";
20
18
  return `${constants.SUPPORTED_NETWORKS[chainId].blockExplorerUrl}/tx/${txHash}`;
21
19
  }
22
- const formatPastTx = params => {
23
- var _transaction$to;
24
- const {
25
- transaction,
26
- lowerCaseSelectedAddress,
27
- blockExplorerUrl
28
- } = params;
29
- let totalAmountString = "";
30
- if (transaction.type === constants.CONTRACT_TYPE_ERC721 || transaction.type === constants.CONTRACT_TYPE_ERC1155) totalAmountString = transaction.symbol;else if (transaction.type === constants.CONTRACT_TYPE_ERC20) totalAmountString = baseControllers.formatSmallNumbers(Number.parseFloat(transaction.total_amount), transaction.symbol, true);else totalAmountString = baseControllers.formatSmallNumbers(Number.parseFloat(transaction.total_amount), transaction.type_name, true);
31
- const currencyAmountString = transaction.type === constants.CONTRACT_TYPE_ERC721 || transaction.type === constants.CONTRACT_TYPE_ERC1155 || transaction.isEtherscan ? "" : baseControllers.formatSmallNumbers(Number.parseFloat(transaction.currency_amount), transaction.selected_currency, true);
32
- const finalObject = {
33
- id: transaction.created_at.toString(),
34
- date: new Date(transaction.created_at).toString(),
35
- from: transaction.from,
36
- from_aa_address: transaction.from_aa_address,
37
- slicedFrom: typeof transaction.from === "string" ? baseControllers.addressSlicer(transaction.from) : "",
38
- to: transaction.to,
39
- slicedTo: typeof transaction.to === "string" ? baseControllers.addressSlicer(transaction.to) : "",
40
- action: lowerCaseSelectedAddress === ((_transaction$to = transaction.to) === null || _transaction$to === void 0 ? void 0 : _transaction$to.toLowerCase()) || "" ? baseControllers.ACTIVITY_ACTION_RECEIVE : baseControllers.ACTIVITY_ACTION_SEND,
41
- totalAmount: transaction.total_amount,
42
- totalAmountString,
43
- currencyAmount: transaction.currency_amount,
44
- currencyAmountString,
45
- amount: `${totalAmountString} / ${currencyAmountString}`,
46
- status: transaction.status,
47
- etherscanLink: blockExplorerUrl ? `${blockExplorerUrl}/tx/${transaction.transaction_hash}` : "",
48
- chainId: transaction.chain_id,
49
- ethRate: Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.total_amount) && Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.currency_amount) ? `1 ${transaction.symbol} = ${baseControllers.significantDigits(Number.parseFloat(transaction.currency_amount) / Number.parseFloat(transaction.total_amount))}` : "",
50
- currencyUsed: transaction.selected_currency,
51
- type: transaction.type,
52
- type_name: transaction.type_name,
53
- type_image_link: transaction.type_image_link,
54
- transaction_hash: transaction.transaction_hash,
55
- transaction_category: transaction.transaction_category,
56
- isEtherscan: transaction.isEtherscan,
57
- input: transaction.input || "",
58
- token_id: transaction.token_id || "",
59
- contract_address: transaction.contract_address || "",
60
- nonce: transaction.nonce || "",
61
- is_cancel: !!transaction.is_cancel || false,
62
- gas: transaction.gas || "",
63
- gasPrice: transaction.gasPrice || ""
64
- };
65
- return finalObject;
66
- };
67
20
  /**
68
21
  * Ref - https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt
69
22
  */
@@ -131,83 +84,11 @@ function getChainType(chainId) {
131
84
  }
132
85
  return "custom";
133
86
  }
134
- const addEtherscanTransactions = async params => {
135
- const {
136
- txn,
137
- lowerCaseSelectedAddress,
138
- provider,
139
- chainId,
140
- blockExplorerUrl
141
- } = params;
142
- const transactionPromises = await Promise.all(txn.map(async tx => {
143
- var _SUPPORTED_NETWORKS$c, _SUPPORTED_NETWORKS$c2;
144
- const {
145
- category,
146
- type
147
- } = await TransactionUtils.determineTransactionType(_objectSpread(_objectSpread({}, tx), {}, {
148
- data: tx.input
149
- }), provider);
150
- tx.transaction_category = tx.transaction_category || category;
151
- tx.type_image_link = ((_SUPPORTED_NETWORKS$c = constants.SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c === void 0 ? void 0 : _SUPPORTED_NETWORKS$c.logo) || "";
152
- tx.type_name = (_SUPPORTED_NETWORKS$c2 = constants.SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c2 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c2.ticker;
153
- tx.type = type;
154
- return tx;
155
- }));
156
- const finalTxs = transactionPromises.reduce((accumulator, x) => {
157
- var _SUPPORTED_NETWORKS$c3, _SUPPORTED_NETWORKS$c4;
158
- let totalAmountString = x.value ? new bignumber_js.BigNumber(x.value).div(new bignumber_js.BigNumber(10).pow(new bignumber_js.BigNumber(x.tokenDecimal || 18))).toString() : "";
159
- let type = constants.CONTRACT_TYPE_ETH;
160
- if (x.contractAddress !== "") {
161
- if (x.tokenID) {
162
- type = x.tokenValue ? constants.CONTRACT_TYPE_ERC1155 : constants.CONTRACT_TYPE_ERC721;
163
- } else {
164
- type = constants.CONTRACT_TYPE_ERC20;
165
- }
166
- }
167
- if (type === constants.CONTRACT_TYPE_ERC1155) {
168
- totalAmountString = x.tokenValue;
169
- }
170
- const etherscanTransaction = {
171
- type,
172
- type_image_link: x.type_image_link || "n/a",
173
- type_name: x.tokenName || ((_SUPPORTED_NETWORKS$c3 = constants.SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || "n/a",
174
- symbol: x.tokenSymbol || ((_SUPPORTED_NETWORKS$c4 = constants.SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c4 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c4.ticker),
175
- token_id: x.tokenID || "",
176
- total_amount: totalAmountString,
177
- created_at: new Date(Number(x.timeStamp) * 1000),
178
- from: x.from,
179
- to: x.to,
180
- transaction_hash: x.hash,
181
- status: x.txreceipt_status && x.txreceipt_status === "0" ? baseControllers.TransactionStatus.failed : baseControllers.TransactionStatus.confirmed,
182
- isEtherscan: true,
183
- input: x.input,
184
- contract_address: x.contractAddress,
185
- transaction_category: x.transaction_category,
186
- gas: `0x${new bignumber_js.BigNumber(x.gasUsed || 0, 10).toString(16)}`,
187
- gasPrice: `0x${new bignumber_js.BigNumber(x.gasPrice || 0, 10).toString(16)}`,
188
- chain_id: chainId,
189
- currency_amount: "",
190
- nonce: x.nonce,
191
- from_aa_address: "",
192
- is_cancel: false,
193
- selected_currency: ""
194
- };
195
- accumulator.push(formatPastTx({
196
- transaction: etherscanTransaction,
197
- lowerCaseSelectedAddress,
198
- blockExplorerUrl
199
- }));
200
- return accumulator;
201
- }, []);
202
- return finalTxs;
203
- };
204
87
 
205
88
  exports.BNToHex = BNToHex;
206
89
  exports.GAS_LIMITS = GAS_LIMITS;
207
- exports.addEtherscanTransactions = addEtherscanTransactions;
208
90
  exports.bnLessThan = bnLessThan;
209
91
  exports.formatDate = formatDate;
210
- exports.formatPastTx = formatPastTx;
211
92
  exports.formatTime = formatTime;
212
93
  exports.getChainType = getChainType;
213
94
  exports.getEthTxStatus = getEthTxStatus;