@metamask-previews/network-controller 27.0.0-preview-7cfbb337 → 27.0.0-preview-bea9ae5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/rpc-service/rpc-service.cjs.map +1 -1
- package/dist/rpc-service/rpc-service.d.cts +1 -2
- package/dist/rpc-service/rpc-service.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service.d.mts +1 -2
- package/dist/rpc-service/rpc-service.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkController.cjs","sourceRoot":"","sources":["../src/NetworkController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+DAA2D;AAE3D,iEAWoC;AAGpC,oEAA2C;AAE3C,qDAAkD;AAClD,uEAGuC;AAGvC,2CAAgF;AAChF,sEAAwC;AAExC,iCAAgC;AAChC,mCAAmC;AAEnC,uCAA0C;AAC1C,4CAA8B;AAC9B,+BAAoC;AAEpC,+CAIqB;AAKrB,iGAAsF;AACtF,yCAA6D;AAE7D,uCAA4C;AAU5C,MAAM,QAAQ,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,mBAAmB,CAAC,CAAC;AAExE,MAAM,gBAAgB,GACpB,qEAAqE,CAAC;AAsBxE;;;;;GAKG;AACH,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;AACnB,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B;AA2LD;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW;AACzB,gCAAgC;AAChC,8DAA8D;AAC9D,MAA+B;IAE/B,OAAO,MA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AI,mDAA0B,CAAC,YAAY,CAC5C,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,uBAAA,IAAI,wCAAsB,IAAA,6CAAuB,EAC/C,uBAAA,IAAI,mDAA0B,CAAC,YAAY,EAC3C;YACE,WAAW,EAAE,cAAc;SAC5B,CACF,MAAA,CAAC;IACJ,CAAC;IAED,uBAAA,IAAI,+BAAa,IAAI,mBAAQ,CAAC,uBAAA,IAAI,wCAAe,CAAC,MAAA,CAAC;AACrD,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Partialize } from '@metamask/controller-utils';\nimport {\n InfuraNetworkType,\n CustomNetworkType,\n NetworkType,\n isSafeChainId,\n isInfuraNetworkType,\n ChainId,\n NetworksTicker,\n NetworkNickname,\n BUILT_IN_CUSTOM_NETWORKS_RPC,\n BUILT_IN_NETWORKS,\n} from '@metamask/controller-utils';\nimport type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\nimport type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker';\nimport EthQuery from '@metamask/eth-query';\nimport type { Messenger } from '@metamask/messenger';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport {\n createEventEmitterProxy,\n createSwappableProxy,\n} from '@metamask/swappable-obj-proxy';\nimport type { SwappableProxy } from '@metamask/swappable-obj-proxy';\nimport type { Hex } from '@metamask/utils';\nimport { hasProperty, isPlainObject, isStrictHexString } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport { cloneDeep } from 'lodash';\nimport type { Logger } from 'loglevel';\nimport { createSelector } from 'reselect';\nimport * as URI from 'uri-js';\nimport { v4 as uuidV4 } from 'uuid';\n\nimport {\n DEPRECATED_NETWORKS,\n INFURA_BLOCKED_KEY,\n NetworkStatus,\n} from './constants';\nimport type {\n AutoManagedNetworkClient,\n ProxyWithAccessibleTarget,\n} from './create-auto-managed-network-client';\nimport { createAutoManagedNetworkClient } from './create-auto-managed-network-client';\nimport { projectLogger, createModuleLogger } from './logger';\nimport type { RpcServiceOptions } from './rpc-service/rpc-service';\nimport { NetworkClientType } from './types';\nimport type {\n BlockTracker,\n Provider,\n CustomNetworkClientConfiguration,\n InfuraNetworkClientConfiguration,\n NetworkClientConfiguration,\n AdditionalDefaultNetwork,\n} from './types';\n\nconst debugLog = createModuleLogger(projectLogger, 'NetworkController');\n\nconst INFURA_URL_REGEX =\n /^https:\\/\\/(?<networkName>[^.]+)\\.infura\\.io\\/v\\d+\\/(?<apiKey>.+)$/u;\n\nexport type Block = {\n baseFeePerGas?: string;\n};\n\n/**\n * Information about a network not held by any other part of state.\n */\nexport type NetworkMetadata = {\n /**\n * EIPs supported by the network.\n */\n EIPS: {\n [eipNumber: number]: boolean;\n };\n /**\n * Indicates the availability of the network\n */\n status: NetworkStatus;\n};\n\n/**\n * The type of an RPC endpoint.\n *\n * @see {@link CustomRpcEndpoint}\n * @see {@link InfuraRpcEndpoint}\n */\nexport enum RpcEndpointType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * An Infura RPC endpoint is a reference to a specific network that Infura\n * supports as well as an Infura account we own that we allow users to make use\n * of for free. We need to disambiguate these endpoints from custom RPC\n * endpoints, because while the types for these kinds of object both have the\n * same interface, the URL for an Infura endpoint contains the Infura project\n * ID, and we don't want this to be present in state. We therefore hide it by\n * representing it in the URL as `{infuraProjectId}`, which we replace this when\n * create network clients. But we need to know somehow that we only need to do\n * this replacement for Infura endpoints and not custom endpoints — hence the\n * separate type.\n */\nexport type InfuraRpcEndpoint = {\n /**\n * Alternate RPC endpoints to use when this endpoint is down.\n */\n failoverUrls?: string[];\n /**\n * The optional user-facing nickname of the endpoint.\n */\n name?: string;\n /**\n * The identifier for the network client that has been created for this RPC\n * endpoint. This is also used to uniquely identify the RPC endpoint in a\n * set of RPC endpoints as well: once assigned, it is used to determine\n * whether the `name`, `type`, or `url` of the RPC endpoint has changed.\n */\n networkClientId: BuiltInNetworkClientId;\n /**\n * The type of this endpoint, always \"default\".\n */\n type: RpcEndpointType.Infura;\n /**\n * The URL of the endpoint. Expected to be a template with the string\n * `{infuraProjectId}`, which will get replaced with the Infura project ID\n * when the network client is created.\n */\n url: `https://${InfuraNetworkType}.infura.io/v3/{infuraProjectId}`;\n};\n\n/**\n * A custom RPC endpoint is a reference to a user-defined server which fronts an\n * EVM chain. It may refer to an Infura network, but only by coincidence.\n */\nexport type CustomRpcEndpoint = {\n /**\n * Alternate RPC endpoints to use when this endpoint is down.\n */\n failoverUrls?: string[];\n /**\n * The optional user-facing nickname of the endpoint.\n */\n name?: string;\n /**\n * The identifier for the network client that has been created for this RPC\n * endpoint. This is also used to uniquely identify the RPC endpoint in a\n * set of RPC endpoints as well: once assigned, it is used to determine\n * whether the `name`, `type`, or `url` of the RPC endpoint has changed.\n */\n networkClientId: CustomNetworkClientId;\n /**\n * The type of this endpoint, always \"custom\".\n */\n type: RpcEndpointType.Custom;\n /**\n * The URL of the endpoint.\n */\n url: string;\n};\n\n/**\n * An RPC endpoint is a reference to a server which fronts an EVM chain. There\n * are two varieties of RPC endpoints: Infura and custom.\n *\n * @see {@link CustomRpcEndpoint}\n * @see {@link InfuraRpcEndpoint}\n */\nexport type RpcEndpoint = InfuraRpcEndpoint | CustomRpcEndpoint;\n\n/**\n * From a user perspective, a network configuration holds information about a\n * network that a user can select through the client. A \"network\" in this sense\n * can explicitly refer to an EVM chain that the user explicitly adds or doesn't\n * need to add (because it comes shipped with the client). The properties here\n * therefore directly map to fields that a user sees and can edit for a network\n * within the client.\n *\n * Internally, a network configuration represents a single conceptual EVM chain,\n * which is represented tangibly via multiple RPC endpoints. A \"network\" is then\n * something for which a network client object is created automatically or\n * created on demand when it is added to the client.\n */\nexport type NetworkConfiguration = {\n /**\n * A set of URLs that allows the user to view activity that has occurred on\n * the chain.\n */\n blockExplorerUrls: string[];\n /**\n * The ID of the chain. Represented in hexadecimal format with a leading \"0x\"\n * instead of decimal format so that when viewed out of context it can be\n * unambiguously interpreted.\n */\n chainId: Hex;\n /**\n * A reference to a URL that the client will use by default to allow the user\n * to view activity that has occurred on the chain. This index must refer to\n * an item in `blockExplorerUrls`.\n */\n defaultBlockExplorerUrlIndex?: number;\n /**\n * A reference to an RPC endpoint that all requests will use by default in order to\n * interact with the chain. This index must refer to an item in\n * `rpcEndpoints`.\n */\n defaultRpcEndpointIndex: number;\n /**\n * The user-facing nickname assigned to the chain.\n */\n name: string;\n /**\n * The name of the currency to use for the chain.\n */\n nativeCurrency: string;\n /**\n * The collection of possible RPC endpoints that the client can use to\n * interact with the chain.\n */\n rpcEndpoints: RpcEndpoint[];\n /**\n * Profile Sync - Network Sync field.\n * Allows comparison of local network state with state to sync.\n */\n lastUpdatedAt?: number;\n};\n\n/**\n * A custom RPC endpoint in a new network configuration, meant to be used in\n * conjunction with `AddNetworkFields`.\n *\n * Custom RPC endpoints do not need a `networkClientId` property because it is\n * assumed that they have not already been added and therefore network clients\n * do not exist for them yet (and hence IDs need to be generated).\n */\nexport type AddNetworkCustomRpcEndpointFields = Omit<\n CustomRpcEndpoint,\n 'networkClientId'\n>;\n\n/**\n * A new network configuration that `addNetwork` takes.\n *\n * Custom RPC endpoints do not need a `networkClientId` property because it is\n * assumed that they have not already been added and are not represented by\n * network clients yet.\n */\nexport type AddNetworkFields = Omit<NetworkConfiguration, 'rpcEndpoints'> & {\n rpcEndpoints: (InfuraRpcEndpoint | AddNetworkCustomRpcEndpointFields)[];\n};\n\n/**\n * A custom RPC endpoint in an updated representation of a network\n * configuration, meant to be used in conjunction with `UpdateNetworkFields`.\n *\n * Custom RPC endpoints do not need a `networkClientId` property because it is\n * assumed that they have not already been added and therefore network clients\n * do not exist for them yet (and hence IDs need to be generated).\n */\nexport type UpdateNetworkCustomRpcEndpointFields = Partialize<\n CustomRpcEndpoint,\n 'networkClientId'\n>;\n\n/**\n * An updated representation of an existing network configuration that\n * `updateNetwork` takes.\n *\n * Custom RPC endpoints may or may not have a `networkClientId` property; if\n * they do, then it is assumed that they already exist, and if not, then it is\n * assumed that they are new and are not represented by network clients yet.\n */\nexport type UpdateNetworkFields = Omit<NetworkConfiguration, 'rpcEndpoints'> & {\n rpcEndpoints: (InfuraRpcEndpoint | UpdateNetworkCustomRpcEndpointFields)[];\n};\n\n/**\n * `Object.keys()` is intentionally generic: it returns the keys of an object,\n * but it cannot make guarantees about the contents of that object, so the type\n * of the keys is merely `string[]`. While this is technically accurate, it is\n * also unnecessary if we have an object that we own and whose contents are\n * known exactly.\n *\n * TODO: Move to @metamask/utils.\n *\n * @param object - The object.\n * @returns The keys of an object, typed according to the type of the object\n * itself.\n */\nexport function knownKeysOf<K extends PropertyKey>(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n object: Partial<Record<K, any>>,\n) {\n return Object.keys(object) as K[];\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `code` property, such as an instance of Error.\n *\n * TODO: Move this to @metamask/utils.\n *\n * @param error - The object to check.\n * @returns True if `error` has a `code`, false otherwise.\n */\nfunction isErrorWithCode(error: unknown): error is { code: string | number } {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n\n/**\n * The string that uniquely identifies an Infura network client.\n */\nexport type BuiltInNetworkClientId = InfuraNetworkType;\n\n/**\n * The string that uniquely identifies a custom network client.\n */\nexport type CustomNetworkClientId = string;\n\n/**\n * The string that uniquely identifies a network client.\n */\nexport type NetworkClientId = BuiltInNetworkClientId | CustomNetworkClientId;\n\n/**\n * Extra information about each network, such as whether it is accessible or\n * blocked and whether it supports EIP-1559, keyed by network client ID.\n */\nexport type NetworksMetadata = Record<NetworkClientId, NetworkMetadata>;\n\n/**\n * The state that NetworkController stores.\n */\nexport type NetworkState = {\n /**\n * The ID of the network client that the proxies returned by\n * `getSelectedNetworkClient` currently point to.\n */\n selectedNetworkClientId: NetworkClientId;\n /**\n * The registry of networks and corresponding RPC endpoints that the\n * controller can use to make requests for various chains.\n *\n * @see {@link NetworkConfiguration}\n */\n networkConfigurationsByChainId: Record<Hex, NetworkConfiguration>;\n /**\n * Extra information about each network, such as whether it is accessible or\n * blocked and whether it supports EIP-1559, keyed by network client ID.\n */\n networksMetadata: NetworksMetadata;\n};\n\nconst controllerName = 'NetworkController';\n\n/**\n * Represents the block tracker for the currently selected network. (Note that\n * this is a proxy around a proxy: the inner one exists so that the block\n * tracker doesn't have to exist until it's used, and the outer one exists so\n * that the currently selected network can change without consumers needing to\n * refresh the object reference to that network.)\n */\nexport type BlockTrackerProxy = SwappableProxy<\n ProxyWithAccessibleTarget<BlockTracker>\n>;\n\n/**\n * Represents the provider for the currently selected network. (Note that this\n * is a proxy around a proxy: the inner one exists so that the provider doesn't\n * have to exist until it's used, and the outer one exists so that the currently\n * selected network can change without consumers needing to refresh the object\n * reference to that network.)\n */\nexport type ProviderProxy = SwappableProxy<ProxyWithAccessibleTarget<Provider>>;\n\nexport type NetworkControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n NetworkState\n>;\n\n/**\n * `networkWillChange` is published when the current network is about to be\n * switched, but the new provider has not been created and no state changes have\n * occurred yet.\n */\nexport type NetworkControllerNetworkWillChangeEvent = {\n type: 'NetworkController:networkWillChange';\n payload: [NetworkState];\n};\n\n/**\n * `networkDidChange` is published after a provider has been created for a newly\n * switched network (but before the network has been confirmed to be available).\n */\nexport type NetworkControllerNetworkDidChangeEvent = {\n type: 'NetworkController:networkDidChange';\n payload: [NetworkState];\n};\n\n/**\n * `infuraIsBlocked` is published after the network is switched to an Infura\n * network, but when Infura returns an error blocking the user based on their\n * location.\n */\nexport type NetworkControllerInfuraIsBlockedEvent = {\n type: 'NetworkController:infuraIsBlocked';\n payload: [];\n};\n\n/**\n * `infuraIsBlocked` is published either after the network is switched to an\n * Infura network and Infura does not return an error blocking the user based on\n * their location, or the network is switched to a non-Infura network.\n */\nexport type NetworkControllerInfuraIsUnblockedEvent = {\n type: 'NetworkController:infuraIsUnblocked';\n payload: [];\n};\n\n/**\n * `networkAdded` is published after a network configuration is added to the\n * network configuration registry and network clients are created for it.\n */\nexport type NetworkControllerNetworkAddedEvent = {\n type: 'NetworkController:networkAdded';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n/**\n * `networkRemoved` is published after a network configuration is removed from the\n * network configuration registry and once the network clients have been removed.\n */\nexport type NetworkControllerNetworkRemovedEvent = {\n type: 'NetworkController:networkRemoved';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n/**\n * `NetworkController:rpcEndpointChainUnavailable` is published when, after\n * trying all endpoints in an endpoint chain, the last failover reaches a\n * maximum number of consecutive 5xx responses, breaking the underlying circuit.\n *\n * In other words, this event will not be published if a failover is available,\n * even if the primary is not.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.error - The last error produced by the last failover in the\n * endpoint chain.\n * @param payload.networkClientId - The target network's client ID.\n */\nexport type NetworkControllerRpcEndpointChainUnavailableEvent = {\n type: 'NetworkController:rpcEndpointChainUnavailable';\n payload: [\n {\n chainId: Hex;\n error: unknown;\n networkClientId: NetworkClientId;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointUnavailable` is published when any\n * endpoint in an endpoint chain reaches a maximum number of consecutive 5xx\n * responses, breaking the underlying circuit.\n *\n * In other words, this event will be published if a primary is not available,\n * even if a failover is.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.endpointUrl - The URL of the endpoint which reached the\n * maximum number of consecutive 5xx responses. You can compare this to\n * `primaryEndpointUrl` to know whether it was a failover or a primary.\n * @param payload.error - The last error produced by the endpoint.\n * @param payload.networkClientId - The target network's client ID.\n * @param payload.primaryEndpointUrl - The endpoint chain's primary URL.\n */\nexport type NetworkControllerRpcEndpointUnavailableEvent = {\n type: 'NetworkController:rpcEndpointUnavailable';\n payload: [\n {\n chainId: Hex;\n endpointUrl: string;\n error: unknown;\n networkClientId: NetworkClientId;\n primaryEndpointUrl: string;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointChainDegraded` is published for any of the\n * endpoints in an endpoint chain when one of the following two conditions hold\n * (and the chain is not already in a degraded state):\n *\n * 1. A successful (2xx) request, even after being retried, cannot be made to\n * the endpoint.\n * 2. A successful (2xx) request can be made to the endpoint, but it takes\n * longer than expected to complete.\n *\n * Note that this event will be published even if there are local connectivity\n * issues which prevent requests from being initiated. This is intentional.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.error - The last error produced by the endpoint (or\n * `undefined` if the request was slow).\n * @param payload.networkClientId - The target network's client ID.\n */\nexport type NetworkControllerRpcEndpointChainDegradedEvent = {\n type: 'NetworkController:rpcEndpointChainDegraded';\n payload: [\n {\n chainId: Hex;\n error: unknown;\n networkClientId: NetworkClientId;\n },\n ];\n};\n\n/**\n *\n * `NetworkController:rpcEndpointDegraded` is published for any of the endpoints\n * in an endpoint chain when:\n *\n * 1. A successful (2xx) request, even after being retried, cannot be made to\n * the endpoint.\n * 2. A successful (2xx) request can be made to the endpoint, but it takes\n * longer than expected to complete.\n *\n * Note that this event will be published even if there are local connectivity\n * issues which prevent requests from being initiated. This is intentional.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.endpointUrl - The URL of the endpoint for which requests\n * failed or were slow to complete. You can compare this to `primaryEndpointUrl`\n * to know whether it was a failover or a primary.\n * @param payload.error - The last error produced by the endpoint (or\n * `undefined` if the request was slow).\n * @param payload.networkClientId - The target network's client ID.\n * @param payload.primaryEndpointUrl - The endpoint chain's primary URL.\n */\nexport type NetworkControllerRpcEndpointDegradedEvent = {\n type: 'NetworkController:rpcEndpointDegraded';\n payload: [\n {\n chainId: Hex;\n endpointUrl: string;\n error: unknown;\n networkClientId: NetworkClientId;\n primaryEndpointUrl: string;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointChainAvailable` is published in one of two\n * cases:\n *\n * 1. The first time that a 2xx request is made to any of the endpoints in an\n * endpoint chain.\n * 2. When requests to any of the endpoints previously failed (placing the\n * endpoint in a degraded or unavailable status), but are now succeeding again.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.networkClientId - The target network's client ID.\n */\nexport type NetworkControllerRpcEndpointChainAvailableEvent = {\n type: 'NetworkController:rpcEndpointChainAvailable';\n payload: [\n {\n chainId: Hex;\n networkClientId: NetworkClientId;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointRetried` is published before a request to any\n * endpoint in an endpoint chain is retried.\n *\n * This is mainly useful for tests.\n *\n * @param payload - The event payload.\n * @param payload.attempt - The current attempt counter for the endpoint\n * (starting from 0).\n * @param payload.chainId - The target network's chain ID.\n * @param payload.endpointUrl - The URL of the endpoint being retried.\n * @param payload.networkClientId - The target network's client ID.\n * @param payload.primaryEndpointUrl - The endpoint chain's primary URL.\n * @see {@link RpcService} for the list of retriable errors.\n */\nexport type NetworkControllerRpcEndpointRetriedEvent = {\n type: 'NetworkController:rpcEndpointRetried';\n payload: [\n {\n attempt: number;\n chainId: Hex;\n endpointUrl: string;\n networkClientId: NetworkClientId;\n primaryEndpointUrl: string;\n },\n ];\n};\n\nexport type NetworkControllerEvents =\n | NetworkControllerStateChangeEvent\n | NetworkControllerNetworkWillChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | NetworkControllerInfuraIsBlockedEvent\n | NetworkControllerInfuraIsUnblockedEvent\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkRemovedEvent\n | NetworkControllerRpcEndpointChainUnavailableEvent\n | NetworkControllerRpcEndpointUnavailableEvent\n | NetworkControllerRpcEndpointChainDegradedEvent\n | NetworkControllerRpcEndpointDegradedEvent\n | NetworkControllerRpcEndpointChainAvailableEvent\n | NetworkControllerRpcEndpointRetriedEvent;\n\n/**\n * All events that {@link NetworkController} calls internally.\n */\ntype AllowedEvents = never;\n\nexport type NetworkControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n NetworkState\n>;\n\nexport type NetworkControllerGetEthQueryAction = {\n type: `NetworkController:getEthQuery`;\n handler: () => EthQuery | undefined;\n};\n\nexport type NetworkControllerGetNetworkClientByIdAction = {\n type: `NetworkController:getNetworkClientById`;\n handler: NetworkController['getNetworkClientById'];\n};\n\nexport type NetworkControllerGetSelectedNetworkClientAction = {\n type: `NetworkController:getSelectedNetworkClient`;\n handler: NetworkController['getSelectedNetworkClient'];\n};\n\nexport type NetworkControllerGetSelectedChainIdAction = {\n type: 'NetworkController:getSelectedChainId';\n handler: NetworkController['getSelectedChainId'];\n};\n\nexport type NetworkControllerGetEIP1559CompatibilityAction = {\n type: `NetworkController:getEIP1559Compatibility`;\n handler: NetworkController['getEIP1559Compatibility'];\n};\n\nexport type NetworkControllerFindNetworkClientIdByChainIdAction = {\n type: `NetworkController:findNetworkClientIdByChainId`;\n handler: NetworkController['findNetworkClientIdByChainId'];\n};\n\n/**\n * Change the currently selected network to the given built-in network type.\n *\n * @deprecated This action has been replaced by `setActiveNetwork`, and will be\n * removed in a future release.\n */\nexport type NetworkControllerSetProviderTypeAction = {\n type: `NetworkController:setProviderType`;\n handler: NetworkController['setProviderType'];\n};\n\nexport type NetworkControllerSetActiveNetworkAction = {\n type: `NetworkController:setActiveNetwork`;\n handler: NetworkController['setActiveNetwork'];\n};\n\nexport type NetworkControllerGetNetworkConfigurationByChainId = {\n type: `NetworkController:getNetworkConfigurationByChainId`;\n handler: NetworkController['getNetworkConfigurationByChainId'];\n};\n\nexport type NetworkControllerGetNetworkConfigurationByNetworkClientId = {\n type: `NetworkController:getNetworkConfigurationByNetworkClientId`;\n handler: NetworkController['getNetworkConfigurationByNetworkClientId'];\n};\n\nexport type NetworkControllerAddNetworkAction = {\n type: 'NetworkController:addNetwork';\n handler: NetworkController['addNetwork'];\n};\n\nexport type NetworkControllerRemoveNetworkAction = {\n type: 'NetworkController:removeNetwork';\n handler: NetworkController['removeNetwork'];\n};\n\nexport type NetworkControllerUpdateNetworkAction = {\n type: 'NetworkController:updateNetwork';\n handler: NetworkController['updateNetwork'];\n};\n\nexport type NetworkControllerActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetEthQueryAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetSelectedNetworkClientAction\n | NetworkControllerGetSelectedChainIdAction\n | NetworkControllerGetEIP1559CompatibilityAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerSetActiveNetworkAction\n | NetworkControllerSetProviderTypeAction\n | NetworkControllerGetNetworkConfigurationByChainId\n | NetworkControllerGetNetworkConfigurationByNetworkClientId\n | NetworkControllerAddNetworkAction\n | NetworkControllerRemoveNetworkAction\n | NetworkControllerUpdateNetworkAction;\n\n/**\n * All actions that {@link NetworkController} calls internally.\n */\ntype AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n\nexport type NetworkControllerMessenger = Messenger<\n typeof controllerName,\n NetworkControllerActions | AllowedActions,\n NetworkControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for the NetworkController constructor.\n */\nexport type NetworkControllerOptions = {\n /**\n * The messenger suited for this controller.\n */\n messenger: NetworkControllerMessenger;\n /**\n * The API key for Infura, used to make requests to Infura.\n */\n infuraProjectId: string;\n /**\n * The desired state with which to initialize this controller.\n * Missing properties will be filled in with defaults. For instance, if not\n * specified, `networkConfigurationsByChainId` will default to a basic set of\n * network configurations (see {@link InfuraNetworkType} for the list).\n */\n state?: Partial<NetworkState>;\n /**\n * A `loglevel` logger object.\n */\n log?: Logger;\n /**\n * A function that can be used to customize a RPC service constructed for an\n * RPC endpoint. The function takes the URL of the endpoint and should return\n * an object with type {@link RpcServiceOptions}, minus `failoverService`\n * and `endpointUrl` (as they are filled in automatically).\n */\n getRpcServiceOptions: (\n rpcEndpointUrl: string,\n ) => Omit<RpcServiceOptions, 'failoverService' | 'endpointUrl'>;\n /**\n * A function that can be used to customize a block tracker constructed for an\n * RPC endpoint. The function takes the URL of the endpoint and should return\n * an object of type {@link PollingBlockTrackerOptions}, minus `provider` (as\n * it is filled in automatically).\n */\n getBlockTrackerOptions?: (\n rpcEndpointUrl: string,\n ) => Omit<PollingBlockTrackerOptions, 'provider'>;\n /**\n * An array of Hex Chain IDs representing the additional networks to be included as default.\n */\n additionalDefaultNetworks?: AdditionalDefaultNetwork[];\n /**\n * Whether or not requests sent to unavailable RPC endpoints should be\n * automatically diverted to configured failover RPC endpoints.\n */\n isRpcFailoverEnabled?: boolean;\n};\n\n/**\n * Constructs a value for the state property `networkConfigurationsByChainId`\n * which will be used if it has not been provided to the constructor.\n *\n * @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.\n * @returns The default value for `networkConfigurationsByChainId`.\n */\nfunction getDefaultNetworkConfigurationsByChainId(\n additionalDefaultNetworks: AdditionalDefaultNetwork[] = [],\n): Record<Hex, NetworkConfiguration> {\n const infuraNetworks = getDefaultInfuraNetworkConfigurationsByChainId();\n const customNetworks = getDefaultCustomNetworkConfigurationsByChainId();\n\n return additionalDefaultNetworks.reduce<Record<Hex, NetworkConfiguration>>(\n (obj, chainId) => {\n if (hasProperty(customNetworks, chainId)) {\n obj[chainId] = customNetworks[chainId];\n }\n return obj;\n },\n // Always include the infura networks in the default networks\n infuraNetworks,\n );\n}\n\n/**\n * Constructs a `networkConfigurationsByChainId` object for all default Infura networks.\n *\n * @returns The `networkConfigurationsByChainId` object of all Infura networks.\n */\nfunction getDefaultInfuraNetworkConfigurationsByChainId(): Record<\n Hex,\n NetworkConfiguration\n> {\n return Object.values(InfuraNetworkType).reduce<\n Record<Hex, NetworkConfiguration>\n >((obj, infuraNetworkType) => {\n const chainId = ChainId[infuraNetworkType];\n\n // Skip deprecated network as default network.\n if (DEPRECATED_NETWORKS.has(chainId)) {\n return obj;\n }\n\n const rpcEndpointUrl =\n `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const;\n\n const networkConfiguration: NetworkConfiguration = {\n blockExplorerUrls: [],\n chainId,\n defaultRpcEndpointIndex: 0,\n name: NetworkNickname[infuraNetworkType],\n nativeCurrency: NetworksTicker[infuraNetworkType],\n rpcEndpoints: [\n {\n failoverUrls: [],\n networkClientId: infuraNetworkType,\n type: RpcEndpointType.Infura,\n url: rpcEndpointUrl,\n },\n ],\n };\n\n return { ...obj, [chainId]: networkConfiguration };\n }, {});\n}\n\n/**\n * Constructs a `networkConfigurationsByChainId` object for all default custom networks.\n *\n * @returns The `networkConfigurationsByChainId` object of all custom networks.\n */\nfunction getDefaultCustomNetworkConfigurationsByChainId(): Record<\n Hex,\n NetworkConfiguration\n> {\n // Create the `networkConfigurationsByChainId` objects explicitly,\n // Because it is not always guaranteed that the custom networks are included in the\n // default networks.\n return {\n [ChainId['megaeth-testnet']]: getCustomNetworkConfiguration(\n CustomNetworkType['megaeth-testnet'],\n ),\n [ChainId['monad-testnet']]: getCustomNetworkConfiguration(\n CustomNetworkType['monad-testnet'],\n ),\n };\n}\n\n/**\n * Constructs a `NetworkConfiguration` object by `CustomNetworkType`.\n *\n * @param customNetworkType - The type of the custom network.\n * @returns The `NetworkConfiguration` object.\n */\nfunction getCustomNetworkConfiguration(\n customNetworkType: CustomNetworkType,\n): NetworkConfiguration {\n const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType];\n const rpcEndpointUrl = BUILT_IN_CUSTOM_NETWORKS_RPC[customNetworkType];\n\n return {\n blockExplorerUrls: [rpcPrefs.blockExplorerUrl],\n chainId: ChainId[customNetworkType],\n defaultRpcEndpointIndex: 0,\n defaultBlockExplorerUrlIndex: 0,\n name: NetworkNickname[customNetworkType],\n nativeCurrency: ticker,\n rpcEndpoints: [\n {\n failoverUrls: [],\n networkClientId: customNetworkType,\n type: RpcEndpointType.Custom,\n url: rpcEndpointUrl,\n },\n ],\n };\n}\n\n/**\n * Constructs properties for the NetworkController state whose values will be\n * used if not provided to the constructor.\n *\n * @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.\n * @returns The default NetworkController state.\n */\nexport function getDefaultNetworkControllerState(\n additionalDefaultNetworks?: AdditionalDefaultNetwork[],\n): NetworkState {\n const networksMetadata = {};\n const networkConfigurationsByChainId =\n getDefaultNetworkConfigurationsByChainId(additionalDefaultNetworks);\n\n return {\n selectedNetworkClientId: InfuraNetworkType.mainnet,\n networksMetadata,\n networkConfigurationsByChainId,\n };\n}\n\n/**\n * Redux selector for getting all network configurations from NetworkController\n * state, keyed by chain ID.\n *\n * @param state - NetworkController state\n * @returns All registered network configurations, keyed by chain ID.\n */\nconst selectNetworkConfigurationsByChainId = (state: NetworkState) =>\n state.networkConfigurationsByChainId;\n\n/**\n * Get a list of all network configurations.\n *\n * @param state - NetworkController state\n * @returns A list of all available network configurations\n */\nexport function getNetworkConfigurations(\n state: NetworkState,\n): NetworkConfiguration[] {\n return Object.values(state.networkConfigurationsByChainId);\n}\n\n/**\n * Redux selector for getting a list of all network configurations from\n * NetworkController state.\n *\n * @param state - NetworkController state\n * @returns A list of all available network configurations\n */\nexport const selectNetworkConfigurations = createSelector(\n selectNetworkConfigurationsByChainId,\n (networkConfigurationsByChainId) =>\n Object.values(networkConfigurationsByChainId),\n);\n\n/**\n * Get a list of all available network client IDs from a list of network\n * configurations.\n *\n * @param networkConfigurations - The array of network configurations\n * @returns A list of all available client IDs\n */\nexport function getAvailableNetworkClientIds(\n networkConfigurations: NetworkConfiguration[],\n): string[] {\n return networkConfigurations.flatMap((networkConfiguration) =>\n networkConfiguration.rpcEndpoints.map(\n (rpcEndpoint) => rpcEndpoint.networkClientId,\n ),\n );\n}\n\n/**\n * Redux selector for getting a list of all available network client IDs\n * from NetworkController state.\n *\n * @param state - NetworkController state\n * @returns A list of all available network client IDs.\n */\nexport const selectAvailableNetworkClientIds = createSelector(\n selectNetworkConfigurations,\n getAvailableNetworkClientIds,\n);\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\nexport type AutoManagedBuiltInNetworkClientRegistry = Record<\n BuiltInNetworkClientId,\n AutoManagedNetworkClient<InfuraNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\nexport type AutoManagedCustomNetworkClientRegistry = Record<\n CustomNetworkClientId,\n AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks\n * as well as custom networks that users have added.\n */\nexport type AutoManagedNetworkClientRegistry = {\n [NetworkClientType.Infura]: AutoManagedBuiltInNetworkClientRegistry;\n [NetworkClientType.Custom]: AutoManagedCustomNetworkClientRegistry;\n};\n\n/**\n * Instructs `addNetwork` and `updateNetwork` to create a network client for an\n * RPC endpoint.\n *\n * @see {@link NetworkClientOperation}\n */\ntype AddNetworkClientOperation = {\n type: 'add';\n rpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `updateNetwork` and `removeNetwork` to remove a network client for\n * an RPC endpoint.\n *\n * @see {@link NetworkClientOperation}\n */\ntype RemoveNetworkClientOperation = {\n type: 'remove';\n rpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `addNetwork` and `updateNetwork` to replace the network client for\n * an RPC endpoint.\n *\n * @see {@link NetworkClientOperation}\n */\ntype ReplaceNetworkClientOperation = {\n type: 'replace';\n oldRpcEndpoint: RpcEndpoint;\n newRpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `addNetwork` and `updateNetwork` not to do anything with an RPC\n * endpoint, as far as the network client registry is concerned.\n *\n * @see {@link NetworkClientOperation}\n */\ntype NoopNetworkClientOperation = {\n type: 'noop';\n rpcEndpoint: RpcEndpoint;\n};\n\n/* eslint-disable jsdoc/check-indentation */\n/**\n * Instructs `addNetwork`, `updateNetwork`, and `removeNetwork` how to\n * update the network client registry.\n *\n * - When `addNetwork` is called, represents a network client that should be\n * created for a new RPC endpoint.\n * - When `removeNetwork` is called, represents a network client that should be\n * destroyed for a previously existing RPC endpoint.\n * - When `updateNetwork` is called, represents either:\n * - a network client that should be added for a new RPC endpoint\n * - a network client that should be removed for a previously existing RPC\n * endpoint\n * - a network client that should be replaced for an RPC endpoint that was\n * changed in a non-major way, or\n * - a network client that should be unchanged for an RPC endpoint that was\n * also unchanged.\n */\n/* eslint-enable jsdoc/check-indentation */\ntype NetworkClientOperation =\n | AddNetworkClientOperation\n | RemoveNetworkClientOperation\n | ReplaceNetworkClientOperation\n | NoopNetworkClientOperation;\n\n/**\n * Determines whether the given URL is valid by attempting to parse it.\n *\n * @param url - The URL to test.\n * @returns True if the URL is valid, false otherwise.\n */\nfunction isValidUrl(url: string) {\n const uri = URI.parse(url);\n return (\n uri.error === undefined && (uri.scheme === 'http' || uri.scheme === 'https')\n );\n}\n\n/**\n * Given an Infura API URL, extracts the subdomain that identifies the Infura\n * network.\n *\n * @param rpcEndpointUrl - The URL to operate on.\n * @returns The Infura network name that the URL references.\n * @throws if the URL is not an Infura API URL, or if an Infura network is not\n * present in the URL.\n */\nfunction deriveInfuraNetworkNameFromRpcEndpointUrl(\n rpcEndpointUrl: string,\n): InfuraNetworkType {\n const match = INFURA_URL_REGEX.exec(rpcEndpointUrl);\n\n if (match?.groups) {\n if (isInfuraNetworkType(match.groups.networkName)) {\n return match.groups.networkName;\n }\n\n throw new Error(`Unknown Infura network '${match.groups.networkName}'`);\n }\n\n throw new Error('Could not derive Infura network from RPC endpoint URL');\n}\n\n/**\n * Performs a series of checks that the given NetworkController state is\n * internally consistent — that all parts of state that are supposed to match in\n * fact do — so that working with the state later on doesn't cause unexpected\n * errors.\n *\n * In the case of NetworkController, there are several parts of state that need\n * to match. For instance, `defaultRpcEndpointIndex` needs to match an entry\n * within `rpcEndpoints`, and `selectedNetworkClientId` needs to point to an RPC\n * endpoint within a network configuration.\n *\n * @param state - The NetworkController state to verify.\n * @throws if the state is invalid in some way.\n */\nfunction validateInitialState(state: NetworkState) {\n const networkConfigurationEntries = Object.entries(\n state.networkConfigurationsByChainId,\n );\n const networkClientIds = getAvailableNetworkClientIds(\n getNetworkConfigurations(state),\n );\n\n if (networkConfigurationEntries.length === 0) {\n throw new Error(\n 'NetworkController state is invalid: `networkConfigurationsByChainId` cannot be empty',\n );\n }\n\n for (const [chainId, networkConfiguration] of networkConfigurationEntries) {\n if (chainId !== networkConfiguration.chainId) {\n throw new Error(\n `NetworkController state has invalid \\`networkConfigurationsByChainId\\`: Network configuration '${networkConfiguration.name}' is filed under '${chainId}' which does not match its \\`chainId\\` of '${networkConfiguration.chainId}'`,\n );\n }\n\n const isInvalidDefaultBlockExplorerUrlIndex =\n networkConfiguration.blockExplorerUrls.length > 0\n ? networkConfiguration.defaultBlockExplorerUrlIndex === undefined ||\n networkConfiguration.blockExplorerUrls[\n networkConfiguration.defaultBlockExplorerUrlIndex\n ] === undefined\n : networkConfiguration.defaultBlockExplorerUrlIndex !== undefined;\n\n if (isInvalidDefaultBlockExplorerUrlIndex) {\n throw new Error(\n `NetworkController state has invalid \\`networkConfigurationsByChainId\\`: Network configuration '${networkConfiguration.name}' has a \\`defaultBlockExplorerUrlIndex\\` that does not refer to an entry in \\`blockExplorerUrls\\``,\n );\n }\n\n if (\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ] === undefined\n ) {\n throw new Error(\n `NetworkController state has invalid \\`networkConfigurationsByChainId\\`: Network configuration '${networkConfiguration.name}' has a \\`defaultRpcEndpointIndex\\` that does not refer to an entry in \\`rpcEndpoints\\``,\n );\n }\n }\n\n if ([...new Set(networkClientIds)].length < networkClientIds.length) {\n throw new Error(\n 'NetworkController state has invalid `networkConfigurationsByChainId`: Every RPC endpoint across all network configurations must have a unique `networkClientId`',\n );\n }\n}\n\n/**\n * Checks that the given initial NetworkController state is internally\n * consistent similar to `validateInitialState`, but if an anomaly is detected,\n * it does its best to correct the state and logs an error to Sentry.\n *\n * @param state - The NetworkController state to verify.\n * @param messenger - The NetworkController messenger.\n * @returns The corrected state.\n */\nfunction correctInitialState(\n state: NetworkState,\n messenger: NetworkControllerMessenger,\n): NetworkState {\n const networkConfigurationsSortedByChainId = getNetworkConfigurations(\n state,\n ).sort((a, b) => a.chainId.localeCompare(b.chainId));\n const availableNetworkClientIds = getAvailableNetworkClientIds(\n networkConfigurationsSortedByChainId,\n );\n const invalidNetworkClientIdsWithMetadata = Object.keys(\n state.networksMetadata,\n ).filter(\n (networkClientId) => !availableNetworkClientIds.includes(networkClientId),\n );\n\n return produce(state, (newState) => {\n if (!availableNetworkClientIds.includes(state.selectedNetworkClientId)) {\n const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];\n const newSelectedNetworkClientId =\n firstNetworkConfiguration.rpcEndpoints[\n firstNetworkConfiguration.defaultRpcEndpointIndex\n ].networkClientId;\n messenger.call(\n 'ErrorReportingService:captureException',\n new Error(\n `\\`selectedNetworkClientId\\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`,\n ),\n );\n newState.selectedNetworkClientId = newSelectedNetworkClientId;\n }\n\n if (invalidNetworkClientIdsWithMetadata.length > 0) {\n for (const invalidNetworkClientId of invalidNetworkClientIdsWithMetadata) {\n delete newState.networksMetadata[invalidNetworkClientId];\n }\n messenger.call(\n 'ErrorReportingService:captureException',\n new Error(\n '`networksMetadata` had invalid network client IDs, which have been removed',\n ),\n );\n }\n });\n}\n\n/**\n * Transforms a map of chain ID to network configuration to a map of network\n * client ID to network configuration.\n *\n * @param networkConfigurationsByChainId - The network configurations, keyed by\n * chain ID.\n * @returns The network configurations, keyed by network client ID.\n */\nfunction buildNetworkConfigurationsByNetworkClientId(\n networkConfigurationsByChainId: Record<Hex, NetworkConfiguration>,\n): Map<NetworkClientId, NetworkConfiguration> {\n return new Map(\n Object.values(networkConfigurationsByChainId).flatMap(\n (networkConfiguration) => {\n return networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {\n return [rpcEndpoint.networkClientId, networkConfiguration];\n });\n },\n ),\n );\n}\n\n/**\n * Controller that creates and manages an Ethereum network provider.\n */\nexport class NetworkController extends BaseController<\n typeof controllerName,\n NetworkState,\n NetworkControllerMessenger\n> {\n #ethQuery?: EthQuery;\n\n readonly #infuraProjectId: string;\n\n #previouslySelectedNetworkClientId: string;\n\n #providerProxy: ProviderProxy | undefined;\n\n #blockTrackerProxy: BlockTrackerProxy | undefined;\n\n #autoManagedNetworkClientRegistry?: AutoManagedNetworkClientRegistry;\n\n #autoManagedNetworkClient?:\n | AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n | AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n readonly #log: Logger | undefined;\n\n readonly #getRpcServiceOptions: NetworkControllerOptions['getRpcServiceOptions'];\n\n readonly #getBlockTrackerOptions: NetworkControllerOptions['getBlockTrackerOptions'];\n\n #networkConfigurationsByNetworkClientId: Map<\n NetworkClientId,\n NetworkConfiguration\n >;\n\n #isRpcFailoverEnabled: Exclude<\n NetworkControllerOptions['isRpcFailoverEnabled'],\n undefined\n >;\n\n /**\n * Constructs a NetworkController.\n *\n * @param options - The options; see {@link NetworkControllerOptions}.\n */\n constructor(options: NetworkControllerOptions) {\n const {\n messenger,\n state,\n infuraProjectId,\n log,\n getRpcServiceOptions,\n getBlockTrackerOptions,\n additionalDefaultNetworks,\n isRpcFailoverEnabled = false,\n } = options;\n const initialState = {\n ...getDefaultNetworkControllerState(additionalDefaultNetworks),\n ...state,\n };\n validateInitialState(initialState);\n const correctedInitialState = correctInitialState(initialState, messenger);\n\n if (!infuraProjectId || typeof infuraProjectId !== 'string') {\n throw new Error('Invalid Infura project ID');\n }\n\n super({\n name: controllerName,\n metadata: {\n selectedNetworkClientId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n networksMetadata: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n networkConfigurationsByChainId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n },\n messenger,\n state: correctedInitialState,\n });\n\n this.#infuraProjectId = infuraProjectId;\n this.#log = log;\n this.#getRpcServiceOptions = getRpcServiceOptions;\n this.#getBlockTrackerOptions = getBlockTrackerOptions;\n this.#isRpcFailoverEnabled = isRpcFailoverEnabled;\n\n this.#previouslySelectedNetworkClientId =\n this.state.selectedNetworkClientId;\n this.#networkConfigurationsByNetworkClientId =\n buildNetworkConfigurationsByNetworkClientId(\n this.state.networkConfigurationsByChainId,\n );\n\n this.messenger.registerActionHandler(`${this.name}:getEthQuery`, () => {\n return this.#ethQuery;\n });\n\n this.messenger.registerActionHandler(\n `${this.name}:getNetworkClientById`,\n this.getNetworkClientById.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getEIP1559Compatibility`,\n this.getEIP1559Compatibility.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:setActiveNetwork`,\n this.setActiveNetwork.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:setProviderType`,\n this.setProviderType.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:findNetworkClientIdByChainId`,\n this.findNetworkClientIdByChainId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getNetworkConfigurationByChainId`,\n this.getNetworkConfigurationByChainId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getNetworkConfigurationByNetworkClientId`,\n this.getNetworkConfigurationByNetworkClientId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getSelectedNetworkClient`,\n this.getSelectedNetworkClient.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getSelectedChainId`,\n this.getSelectedChainId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:addNetwork`,\n this.addNetwork.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:removeNetwork`,\n this.removeNetwork.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:updateNetwork`,\n this.updateNetwork.bind(this),\n );\n\n this.messenger.subscribe(\n `${this.name}:rpcEndpointChainUnavailable`,\n ({ networkClientId }) => {\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus: NetworkStatus.Unavailable,\n });\n },\n );\n this.messenger.subscribe(\n `${this.name}:rpcEndpointChainDegraded`,\n ({ networkClientId }) => {\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus: NetworkStatus.Degraded,\n });\n },\n );\n this.messenger.subscribe(\n `${this.name}:rpcEndpointChainAvailable`,\n ({ networkClientId }) => {\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus: NetworkStatus.Available,\n });\n },\n );\n }\n\n /**\n * Enables the RPC failover functionality. That is, if any RPC endpoints are\n * configured with failover URLs, then traffic will automatically be diverted\n * to them if those RPC endpoints are unavailable.\n */\n enableRpcFailover() {\n this.#updateRpcFailoverEnabled(true);\n }\n\n /**\n * Disables the RPC failover functionality. That is, even if any RPC endpoints\n * are configured with failover URLs, then traffic will not automatically be\n * diverted to them if those RPC endpoints are unavailable.\n */\n disableRpcFailover() {\n this.#updateRpcFailoverEnabled(false);\n }\n\n /**\n * Enables or disables the RPC failover functionality, depending on the\n * boolean given. This is done by reconstructing all network clients that were\n * originally configured with failover URLs so that those URLs are either\n * honored or ignored. Network client IDs will be preserved so as not to\n * invalidate state in other controllers.\n *\n * @param newIsRpcFailoverEnabled - Whether or not to enable or disable the\n * RPC failover functionality.\n */\n #updateRpcFailoverEnabled(newIsRpcFailoverEnabled: boolean) {\n if (this.#isRpcFailoverEnabled === newIsRpcFailoverEnabled) {\n return;\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n for (const networkClientsById of Object.values(\n autoManagedNetworkClientRegistry,\n )) {\n for (const networkClientId of Object.keys(networkClientsById)) {\n // Type assertion: We can assume that `networkClientId` is valid here.\n const networkClient =\n networkClientsById[\n networkClientId as keyof typeof networkClientsById\n ];\n if (\n networkClient.configuration.failoverRpcUrls &&\n networkClient.configuration.failoverRpcUrls.length > 0\n ) {\n newIsRpcFailoverEnabled\n ? networkClient.enableRpcFailover()\n : networkClient.disableRpcFailover();\n }\n }\n }\n\n this.#isRpcFailoverEnabled = newIsRpcFailoverEnabled;\n }\n\n /**\n * Accesses the provider and block tracker for the currently selected network.\n *\n * @returns The proxy and block tracker proxies.\n * @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.\n */\n getProviderAndBlockTracker(): {\n provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>> | undefined;\n blockTracker:\n | SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>\n | undefined;\n } {\n return {\n provider: this.#providerProxy,\n blockTracker: this.#blockTrackerProxy,\n };\n }\n\n /**\n * Accesses the provider and block tracker for the currently selected network.\n *\n * @returns an object with the provider and block tracker proxies for the currently selected network.\n */\n getSelectedNetworkClient():\n | {\n provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>>;\n blockTracker: SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>;\n }\n | undefined {\n if (this.#providerProxy && this.#blockTrackerProxy) {\n return {\n provider: this.#providerProxy,\n blockTracker: this.#blockTrackerProxy,\n };\n }\n return undefined;\n }\n\n /**\n * Accesses the chain ID from the selected network client.\n *\n * @returns The chain ID of the selected network client in hex format or undefined if there is no network client.\n */\n getSelectedChainId(): Hex | undefined {\n const networkConfiguration = this.getNetworkConfigurationByNetworkClientId(\n this.state.selectedNetworkClientId,\n );\n return networkConfiguration?.chainId;\n }\n\n /**\n * Internally, the Infura and custom network clients are categorized by type\n * so that when accessing either kind of network client, TypeScript knows\n * which type to assign to the network client. For some cases it's more useful\n * to be able to access network clients by ID instead of by type and then ID,\n * so this function makes that possible.\n *\n * @returns The network clients registered so far, keyed by ID.\n */\n getNetworkClientRegistry(): AutoManagedBuiltInNetworkClientRegistry &\n AutoManagedCustomNetworkClientRegistry {\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n return Object.assign(\n {},\n autoManagedNetworkClientRegistry[NetworkClientType.Infura],\n autoManagedNetworkClientRegistry[NetworkClientType.Custom],\n );\n }\n\n /**\n * Returns the Infura network client with the given ID.\n *\n * @param infuraNetworkClientId - An Infura network client ID.\n * @returns The Infura network client.\n * @throws If an Infura network client does not exist with the given ID.\n */\n getNetworkClientById(\n infuraNetworkClientId: BuiltInNetworkClientId,\n ): AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n /**\n * Returns the custom network client with the given ID.\n *\n * @param customNetworkClientId - A custom network client ID.\n * @returns The custom network client.\n * @throws If a custom network client does not exist with the given ID.\n */\n getNetworkClientById(\n customNetworkClientId: CustomNetworkClientId,\n ): AutoManagedNetworkClient<CustomNetworkClientConfiguration>;\n\n getNetworkClientById(\n networkClientId: NetworkClientId,\n ): AutoManagedNetworkClient<NetworkClientConfiguration> {\n if (!networkClientId) {\n throw new Error('No network client ID was provided.');\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n if (isInfuraNetworkType(networkClientId)) {\n const infuraNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n networkClientId\n ];\n // This is impossible to reach\n /* istanbul ignore if */\n if (!infuraNetworkClient) {\n throw new Error(\n `No Infura network client was found with the ID \"${networkClientId}\".`,\n );\n }\n return infuraNetworkClient;\n }\n\n const customNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n networkClientId\n ];\n if (!customNetworkClient) {\n throw new Error(\n `No custom network client was found with the ID \"${networkClientId}\".`,\n );\n }\n return customNetworkClient;\n }\n\n /**\n * Executes a series of steps to switch the network:\n *\n * 1. Notifies subscribers via the messenger that the network is about to be\n * switched (and, really, that the global provider and block tracker proxies\n * will be re-pointed to a new network).\n * 2. Looks up a known and preinitialized network client matching the given\n * ID and uses it to re-point the aforementioned provider and block tracker\n * proxies.\n * 3. Notifies subscribers via the messenger that the network has switched.\n * 4. Captures metadata for the newly switched network in state.\n *\n * @param networkClientId - The ID of a network client that requests will be\n * routed through (either the name of an Infura network or the ID of a custom\n * network configuration).\n * @param options - Options for this method.\n * @param options.updateState - Allows for updating state.\n */\n async #refreshNetwork(\n networkClientId: string,\n options: {\n updateState?: (state: Draft<NetworkState>) => void;\n } = {},\n ) {\n this.messenger.publish('NetworkController:networkWillChange', this.state);\n this.#applyNetworkSelection(networkClientId, options);\n this.messenger.publish('NetworkController:networkDidChange', this.state);\n await this.lookupNetwork();\n }\n\n /**\n * Creates proxies for accessing the global network client and its block\n * tracker. You must call this method in order to use\n * `getProviderAndBlockTracker` (or its replacement,\n * `getSelectedNetworkClient`).\n *\n * @param options - Optional arguments.\n * @param options.lookupNetwork - Usually, metadata for the global network\n * will be populated via a call to `lookupNetwork` after creating the provider\n * and block tracker proxies. This allows for responding to the status of the\n * global network after initializing this controller; however, it requires\n * making a request to the network to do so. In the clients, where controllers\n * are initialized before the UI is shown, this may be undesirable, as it\n * means that if the user has just installed MetaMask, their IP address may be\n * shared with a third party before they have a chance to finish onboarding.\n * You can pass `false` if you'd like to disable this request and call\n * `lookupNetwork` yourself.\n */\n initializeProvider(options: { lookupNetwork: false }): void;\n\n /**\n * Creates proxies for accessing the global network client and its block\n * tracker. You must call this method in order to use\n * `getProviderAndBlockTracker` (or its replacement,\n * `getSelectedNetworkClient`).\n *\n * @param options - Optional arguments.\n * @param options.lookupNetwork - Usually, metadata for the global network\n * will be populated via a call to `lookupNetwork` after creating the provider\n * and block tracker proxies. This allows for responding to the status of the\n * global network after initializing this controller; however, it requires\n * making a request to the network to do so. In the clients, where controllers\n * are initialized before the UI is shown, this may be undesirable, as it\n * means that if the user has just installed MetaMask, their IP address may be\n * shared with a third party before they have a chance to finish onboarding.\n * You can pass `false` if you'd like to disable this request and call\n * `lookupNetwork` yourself.\n * @returns A promise that resolves when the network lookup completes.\n */\n initializeProvider(options?: { lookupNetwork?: boolean }): Promise<void>;\n\n initializeProvider({\n lookupNetwork = true,\n }: {\n lookupNetwork?: boolean;\n } = {}) {\n this.#applyNetworkSelection(this.state.selectedNetworkClientId);\n\n if (lookupNetwork) {\n return this.lookupNetwork();\n }\n\n return undefined;\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given network:\n *\n * - The connectivity status: whether it is available, geo-blocked (Infura\n * only), unavailable, or unknown\n * - The capabilities status: whether it supports EIP-1559, whether it does\n * not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n * If no ID is provided, uses the currently selected network.\n * @returns The resulting metadata for the network.\n */\n async #determineNetworkMetadata(networkClientId: NetworkClientId) {\n // Force TypeScript to use one of the two overloads explicitly\n const networkClient = isInfuraNetworkType(networkClientId)\n ? this.getNetworkClientById(networkClientId)\n : this.getNetworkClientById(networkClientId);\n\n const isInfura =\n networkClient.configuration.type === NetworkClientType.Infura;\n let networkStatus: NetworkStatus;\n let isEIP1559Compatible: boolean | undefined;\n\n try {\n isEIP1559Compatible =\n await this.#determineEIP1559Compatibility(networkClientId);\n networkStatus = NetworkStatus.Available;\n } catch (error) {\n debugLog('NetworkController: lookupNetwork: ', error);\n\n if (isErrorWithCode(error)) {\n let responseBody;\n if (\n isInfura &&\n hasProperty(error, 'message') &&\n typeof error.message === 'string'\n ) {\n try {\n responseBody = JSON.parse(error.message);\n } catch {\n // error.message must not be JSON\n this.#log?.warn(\n 'NetworkController: lookupNetwork: json parse error: ',\n error,\n );\n }\n }\n\n if (\n isPlainObject(responseBody) &&\n responseBody.error === INFURA_BLOCKED_KEY\n ) {\n networkStatus = NetworkStatus.Blocked;\n } else if (error.code === errorCodes.rpc.internal) {\n networkStatus = NetworkStatus.Unknown;\n this.#log?.warn(\n 'NetworkController: lookupNetwork: rpc internal error: ',\n error,\n );\n } else {\n networkStatus = NetworkStatus.Unavailable;\n this.#log?.warn('NetworkController: lookupNetwork: ', error);\n }\n } else {\n debugLog(\n 'NetworkController - could not determine network status',\n error,\n );\n networkStatus = NetworkStatus.Unknown;\n this.#log?.warn('NetworkController: lookupNetwork: ', error);\n }\n }\n\n return { isInfura, networkStatus, isEIP1559Compatible };\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given or selected network, persisting it to state:\n *\n * - The connectivity status: whether it is available, geo-blocked (Infura\n * only), unavailable, or unknown\n * - The capabilities status: whether it supports EIP-1559, whether it does\n * not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n * If no ID is provided, uses the currently selected network.\n */\n async lookupNetwork(networkClientId?: NetworkClientId) {\n if (networkClientId) {\n await this.#lookupGivenNetwork(networkClientId);\n } else {\n await this.#lookupSelectedNetwork();\n }\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given network, persisting it to state:\n *\n * - The connectivity status: whether the network is available, geo-blocked\n * (Infura only), unavailable, or unknown\n * - The feature compatibility status: whether the network supports EIP-1559,\n * whether it does not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n * @deprecated Please use `lookupNetwork` and pass a network client ID\n * instead. This method will be removed in a future major version.\n */\n // We are planning on removing this so we aren't interested in testing this\n // right now.\n /* istanbul ignore next */\n async lookupNetworkByClientId(networkClientId: NetworkClientId) {\n await this.#lookupGivenNetwork(networkClientId);\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given network, persisting it to state:\n *\n * - The connectivity status: whether the network is available, geo-blocked\n * (Infura only), unavailable, or unknown\n * - The feature compatibility status: whether the network supports EIP-1559,\n * whether it does not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n */\n async #lookupGivenNetwork(networkClientId: NetworkClientId) {\n const { networkStatus, isEIP1559Compatible } =\n await this.#determineNetworkMetadata(networkClientId);\n\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus,\n isEIP1559Compatible,\n });\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the currently selected network, persisting it to state:\n *\n * - The connectivity status: whether the network is available, geo-blocked\n * (Infura only), unavailable, or unknown\n * - The feature compatibility status: whether the network supports EIP-1559,\n * whether it does not, or whether it is unknown\n *\n * Note that it is possible for the current network to be switched while this\n * method is running. If that is the case, it will exit early (as this method\n * will also run for the new network).\n */\n async #lookupSelectedNetwork() {\n if (!this.#ethQuery) {\n return;\n }\n\n let networkChanged = false;\n const listener = () => {\n networkChanged = true;\n try {\n this.messenger.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n } catch (error) {\n // In theory, this `catch` should not be necessary given that this error\n // would occur \"inside\" of the call to `#determineEIP1559Compatibility`\n // below and so it should be caught by the `try`/`catch` below (it is\n // impossible to reproduce in tests for that reason). However, somehow\n // it occurs within Mobile and so we have to add our own `try`/`catch`\n // here.\n /* istanbul ignore next */\n if (\n !(error instanceof Error) ||\n error.message !==\n 'Subscription not found for event: NetworkController:networkDidChange'\n ) {\n // Again, this error should not happen and is impossible to reproduce\n // in tests.\n /* istanbul ignore next */\n throw error;\n }\n }\n };\n this.messenger.subscribe('NetworkController:networkDidChange', listener);\n\n const { isInfura, networkStatus, isEIP1559Compatible } =\n await this.#determineNetworkMetadata(this.state.selectedNetworkClientId);\n\n if (networkChanged) {\n // If the network has changed, then `lookupNetwork` either has been or is\n // in the process of being called, so we don't need to go further.\n return;\n }\n\n try {\n this.messenger.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n } catch (error) {\n if (\n !(error instanceof Error) ||\n error.message !==\n 'Subscription not found for event: NetworkController:networkDidChange'\n ) {\n throw error;\n }\n }\n\n this.#updateMetadataForNetwork(this.state.selectedNetworkClientId, {\n networkStatus,\n isEIP1559Compatible,\n });\n\n if (isInfura) {\n if (networkStatus === NetworkStatus.Available) {\n this.messenger.publish('NetworkController:infuraIsUnblocked');\n } else if (networkStatus === NetworkStatus.Blocked) {\n this.messenger.publish('NetworkController:infuraIsBlocked');\n }\n } else {\n // Always publish infuraIsUnblocked regardless of network status to\n // prevent consumers from being stuck in a blocked state if they were\n // previously connected to an Infura network that was blocked\n this.messenger.publish('NetworkController:infuraIsUnblocked');\n }\n }\n\n /**\n * Updates the metadata for the given network in state.\n *\n * @param networkClientId - The associated network client ID.\n * @param metadata - The metadata to store in state.\n * @param metadata.networkStatus - The network status to store in state.\n * @param metadata.isEIP1559Compatible - The EIP-1559 compatibility status to\n * store in state.\n */\n #updateMetadataForNetwork(\n networkClientId: NetworkClientId,\n metadata: {\n networkStatus: NetworkStatus;\n isEIP1559Compatible?: boolean | undefined;\n },\n ) {\n this.update((state) => {\n if (state.networksMetadata[networkClientId] === undefined) {\n state.networksMetadata[networkClientId] = {\n status: NetworkStatus.Unknown,\n EIPS: {},\n };\n }\n const newMetadata = state.networksMetadata[networkClientId];\n newMetadata.status = metadata.networkStatus;\n\n if ('isEIP1559Compatible' in metadata) {\n if (metadata.isEIP1559Compatible === undefined) {\n delete newMetadata.EIPS[1559];\n } else {\n newMetadata.EIPS[1559] = metadata.isEIP1559Compatible;\n }\n }\n });\n }\n\n /**\n * Convenience method to update provider network type settings.\n *\n * @param type - Human readable network name.\n * @deprecated This has been replaced by `setActiveNetwork`, and will be\n * removed in a future release\n */\n async setProviderType(type: InfuraNetworkType) {\n if ((type as unknown) === NetworkType.rpc) {\n throw new Error(\n `NetworkController - cannot call \"setProviderType\" with type \"${NetworkType.rpc}\". Use \"setActiveNetwork\"`,\n );\n }\n if (!isInfuraNetworkType(type)) {\n throw new Error(`Unknown Infura provider type \"${String(type)}\".`);\n }\n\n await this.setActiveNetwork(type);\n }\n\n /**\n * Changes the selected network.\n *\n * @param networkClientId - The ID of a network client that will be used to\n * make requests.\n * @param options - Options for this method.\n * @param options.updateState - Allows for updating state.\n * @throws if no network client is associated with the given\n * network client ID.\n */\n async setActiveNetwork(\n networkClientId: string,\n options: {\n updateState?: (state: Draft<NetworkState>) => void;\n } = {},\n ) {\n this.#previouslySelectedNetworkClientId =\n this.state.selectedNetworkClientId;\n\n await this.#refreshNetwork(networkClientId, options);\n }\n\n /**\n * Fetches the latest block for the network.\n *\n * @param networkClientId - The networkClientId to fetch the correct provider against which to check the latest block. Defaults to the selectedNetworkClientId.\n * @returns A promise that either resolves to the block header or null if\n * there is no latest block, or rejects with an error.\n */\n #getLatestBlock(networkClientId: NetworkClientId): Promise<Block> {\n if (networkClientId === undefined) {\n networkClientId = this.state.selectedNetworkClientId;\n }\n\n const networkClient = this.getNetworkClientById(networkClientId);\n const ethQuery = new EthQuery(networkClient.provider);\n\n return new Promise((resolve, reject) => {\n ethQuery.sendAsync(\n { method: 'eth_getBlockByNumber', params: ['latest', false] },\n (error: unknown, block?: unknown) => {\n if (error) {\n // This error comes from JsonRpcEngine, we don't control it.\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n } else {\n // TODO: Validate this type\n resolve(block as Block);\n }\n },\n );\n });\n }\n\n /**\n * Determines whether the network supports EIP-1559 by checking whether the\n * latest block has a `baseFeePerGas` property, then updates state\n * appropriately.\n *\n * @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility.\n * @returns A promise that resolves to true if the network supports EIP-1559\n * , false otherwise, or `undefined` if unable to determine the compatibility.\n */\n async getEIP1559Compatibility(networkClientId?: NetworkClientId) {\n if (networkClientId) {\n return this.get1559CompatibilityWithNetworkClientId(networkClientId);\n }\n if (!this.#ethQuery) {\n return false;\n }\n\n const { EIPS } =\n this.state.networksMetadata[this.state.selectedNetworkClientId];\n\n if (EIPS[1559] !== undefined) {\n return EIPS[1559];\n }\n\n const isEIP1559Compatible = await this.#determineEIP1559Compatibility(\n this.state.selectedNetworkClientId,\n );\n this.update((state) => {\n if (isEIP1559Compatible !== undefined) {\n state.networksMetadata[state.selectedNetworkClientId].EIPS[1559] =\n isEIP1559Compatible;\n }\n });\n return isEIP1559Compatible;\n }\n\n async get1559CompatibilityWithNetworkClientId(\n networkClientId: NetworkClientId,\n ) {\n let metadata = this.state.networksMetadata[networkClientId];\n if (metadata === undefined) {\n await this.lookupNetwork(networkClientId);\n metadata = this.state.networksMetadata[networkClientId];\n }\n const { EIPS } = metadata;\n\n // may want to include some 'freshness' value - something to make sure we refetch this from time to time\n return EIPS[1559];\n }\n\n /**\n * Retrieves and checks the latest block from the currently selected\n * network; if the block has a `baseFeePerGas` property, then we know\n * that the network supports EIP-1559; otherwise it doesn't.\n *\n * @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility\n * @returns A promise that resolves to `true` if the network supports EIP-1559,\n * `false` otherwise, or `undefined` if unable to retrieve the last block.\n */\n async #determineEIP1559Compatibility(\n networkClientId: NetworkClientId,\n ): Promise<boolean | undefined> {\n const latestBlock = await this.#getLatestBlock(networkClientId);\n\n if (!latestBlock) {\n return undefined;\n }\n\n return latestBlock.baseFeePerGas !== undefined;\n }\n\n /**\n * Ensures that the provider and block tracker proxies are pointed to the\n * currently selected network and refreshes the metadata for the\n */\n async resetConnection() {\n await this.#refreshNetwork(this.state.selectedNetworkClientId);\n }\n\n /**\n * Returns the network configuration that has been filed under the given chain\n * ID.\n *\n * @param chainId - The chain ID to use as a key.\n * @returns The network configuration if one exists, or undefined.\n */\n getNetworkConfigurationByChainId(\n chainId: Hex,\n ): NetworkConfiguration | undefined {\n return this.state.networkConfigurationsByChainId[chainId];\n }\n\n /**\n * Returns the network configuration that contains an RPC endpoint with the\n * given network client ID.\n *\n * @param networkClientId - The network client ID to use as a key.\n * @returns The network configuration if one exists, or undefined.\n */\n getNetworkConfigurationByNetworkClientId(\n networkClientId: NetworkClientId,\n ): NetworkConfiguration | undefined {\n return this.#networkConfigurationsByNetworkClientId.get(networkClientId);\n }\n\n /**\n * Creates and registers network clients for the collection of Infura and\n * custom RPC endpoints that can be used to make requests for a particular\n * chain, storing the given configuration object in state for later reference.\n *\n * @param fields - The object that describes the new network/chain and lists\n * the RPC endpoints which front that chain.\n * @returns The newly added network configuration.\n * @throws if any part of `fields` would produce invalid state.\n * @see {@link NetworkConfiguration}\n */\n addNetwork(fields: AddNetworkFields): NetworkConfiguration {\n const { rpcEndpoints: setOfRpcEndpointFields } = fields;\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.#validateNetworkFields({\n mode: 'add',\n networkFields: fields,\n autoManagedNetworkClientRegistry,\n });\n\n const networkClientOperations = setOfRpcEndpointFields.map(\n (defaultOrCustomRpcEndpointFields) => {\n const rpcEndpoint =\n defaultOrCustomRpcEndpointFields.type === RpcEndpointType.Custom\n ? {\n ...defaultOrCustomRpcEndpointFields,\n networkClientId: uuidV4(),\n }\n : defaultOrCustomRpcEndpointFields;\n return {\n type: 'add' as const,\n rpcEndpoint,\n };\n },\n );\n\n const newNetworkConfiguration =\n this.#determineNetworkConfigurationToPersist({\n networkFields: fields,\n networkClientOperations,\n });\n this.#registerNetworkClientsAsNeeded({\n networkFields: fields,\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n this.update((state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'add',\n networkFields: fields,\n networkConfigurationToPersist: newNetworkConfiguration,\n });\n });\n\n this.messenger.publish(\n `${controllerName}:networkAdded`,\n newNetworkConfiguration,\n );\n\n return newNetworkConfiguration;\n }\n\n /**\n * Updates the configuration for a previously stored network filed under the\n * given chain ID, creating + registering new network clients to represent RPC\n * endpoints that have been added and destroying + unregistering existing\n * network clients for RPC endpoints that have been removed.\n *\n * Note that if `chainId` is changed, then all network clients associated with\n * that chain will be removed and re-added, even if none of the RPC endpoints\n * have changed.\n *\n * @param chainId - The chain ID associated with an existing network.\n * @param fields - The object that describes the updates to the network/chain,\n * including the new set of RPC endpoints which should front that chain.\n * @param options - Options to provide.\n * @param options.replacementSelectedRpcEndpointIndex - Usually you cannot\n * remove an RPC endpoint that is being represented by the currently selected\n * network client. This option allows you to specify another RPC endpoint\n * (either an existing one or a new one) that should be used to select a new\n * network instead.\n * @returns The updated network configuration.\n * @throws if `chainId` does not refer to an existing network configuration,\n * if any part of `fields` would produce invalid state, etc.\n * @see {@link NetworkConfiguration}\n */\n async updateNetwork(\n chainId: Hex,\n fields: UpdateNetworkFields,\n {\n replacementSelectedRpcEndpointIndex,\n }: { replacementSelectedRpcEndpointIndex?: number } = {},\n ): Promise<NetworkConfiguration> {\n const existingNetworkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n\n if (existingNetworkConfiguration === undefined) {\n throw new Error(\n `Could not update network: Cannot find network configuration for chain '${chainId}'`,\n );\n }\n\n const existingChainId = chainId;\n const { chainId: newChainId, rpcEndpoints: setOfNewRpcEndpointFields } =\n fields;\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.#validateNetworkFields({\n mode: 'update',\n networkFields: fields,\n existingNetworkConfiguration,\n autoManagedNetworkClientRegistry,\n });\n\n const networkClientOperations: NetworkClientOperation[] = [];\n\n for (const newRpcEndpointFields of setOfNewRpcEndpointFields) {\n const existingRpcEndpointForNoop =\n existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {\n return (\n rpcEndpoint.type === newRpcEndpointFields.type &&\n rpcEndpoint.url === newRpcEndpointFields.url &&\n (rpcEndpoint.networkClientId ===\n newRpcEndpointFields.networkClientId ||\n newRpcEndpointFields.networkClientId === undefined)\n );\n });\n const existingRpcEndpointForReplaceWhenChainChanged =\n existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {\n return (\n (rpcEndpoint.type === RpcEndpointType.Infura &&\n newRpcEndpointFields.type === RpcEndpointType.Infura) ||\n (rpcEndpoint.type === newRpcEndpointFields.type &&\n rpcEndpoint.networkClientId ===\n newRpcEndpointFields.networkClientId &&\n rpcEndpoint.url === newRpcEndpointFields.url)\n );\n });\n const existingRpcEndpointForReplaceWhenChainNotChanged =\n existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {\n return (\n rpcEndpoint.type === newRpcEndpointFields.type &&\n (rpcEndpoint.url === newRpcEndpointFields.url ||\n rpcEndpoint.networkClientId ===\n newRpcEndpointFields.networkClientId)\n );\n });\n\n if (\n newChainId !== existingChainId &&\n existingRpcEndpointForReplaceWhenChainChanged !== undefined\n ) {\n const newRpcEndpoint =\n newRpcEndpointFields.type === RpcEndpointType.Infura\n ? newRpcEndpointFields\n : { ...newRpcEndpointFields, networkClientId: uuidV4() };\n\n networkClientOperations.push({\n type: 'replace' as const,\n oldRpcEndpoint: existingRpcEndpointForReplaceWhenChainChanged,\n newRpcEndpoint,\n });\n } else if (existingRpcEndpointForNoop !== undefined) {\n let newRpcEndpoint;\n if (existingRpcEndpointForNoop.type === RpcEndpointType.Infura) {\n newRpcEndpoint = existingRpcEndpointForNoop;\n } else {\n // `networkClientId` shouldn't be missing at this point; if it is,\n // that's a mistake, so fill it back in\n newRpcEndpoint = Object.assign({}, newRpcEndpointFields, {\n networkClientId: existingRpcEndpointForNoop.networkClientId,\n });\n }\n networkClientOperations.push({\n type: 'noop' as const,\n rpcEndpoint: newRpcEndpoint,\n });\n } else if (\n existingRpcEndpointForReplaceWhenChainNotChanged !== undefined\n ) {\n let newRpcEndpoint;\n /* istanbul ignore if */\n if (newRpcEndpointFields.type === RpcEndpointType.Infura) {\n // This case can't actually happen. If we're here, it means that some\n // part of the RPC endpoint changed. But there is no part of an Infura\n // RPC endpoint that can be changed (as it would immediately make that\n // RPC endpoint self-inconsistent). This is just here to appease\n // TypeScript.\n newRpcEndpoint = newRpcEndpointFields;\n } else {\n newRpcEndpoint = {\n ...newRpcEndpointFields,\n networkClientId: uuidV4(),\n };\n }\n\n networkClientOperations.push({\n type: 'replace' as const,\n oldRpcEndpoint: existingRpcEndpointForReplaceWhenChainNotChanged,\n newRpcEndpoint,\n });\n } else {\n const newRpcEndpoint =\n newRpcEndpointFields.type === RpcEndpointType.Infura\n ? newRpcEndpointFields\n : { ...newRpcEndpointFields, networkClientId: uuidV4() };\n const networkClientOperation = {\n type: 'add' as const,\n rpcEndpoint: newRpcEndpoint,\n };\n networkClientOperations.push(networkClientOperation);\n }\n }\n\n for (const existingRpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {\n if (\n !networkClientOperations.some((networkClientOperation) => {\n const otherRpcEndpoint =\n networkClientOperation.type === 'replace'\n ? networkClientOperation.oldRpcEndpoint\n : networkClientOperation.rpcEndpoint;\n return (\n otherRpcEndpoint.type === existingRpcEndpoint.type &&\n otherRpcEndpoint.networkClientId ===\n existingRpcEndpoint.networkClientId &&\n otherRpcEndpoint.url === existingRpcEndpoint.url\n );\n })\n ) {\n const networkClientOperation = {\n type: 'remove' as const,\n rpcEndpoint: existingRpcEndpoint,\n };\n networkClientOperations.push(networkClientOperation);\n }\n }\n\n const updatedNetworkConfiguration =\n this.#determineNetworkConfigurationToPersist({\n networkFields: fields,\n networkClientOperations,\n });\n\n if (\n replacementSelectedRpcEndpointIndex === undefined &&\n networkClientOperations.some((networkClientOperation) => {\n return (\n networkClientOperation.type === 'remove' &&\n networkClientOperation.rpcEndpoint.networkClientId ===\n this.state.selectedNetworkClientId\n );\n }) &&\n !networkClientOperations.some((networkClientOperation) => {\n return (\n networkClientOperation.type === 'replace' &&\n networkClientOperation.oldRpcEndpoint.networkClientId ===\n this.state.selectedNetworkClientId\n );\n })\n ) {\n throw new Error(\n `Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \\`replacementSelectedRpcEndpointIndex\\` option.`,\n );\n }\n\n this.#registerNetworkClientsAsNeeded({\n networkFields: fields,\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n\n const replacementSelectedRpcEndpointWithIndex = networkClientOperations\n .map(\n (networkClientOperation, index) =>\n [networkClientOperation, index] as const,\n )\n .find(([networkClientOperation, _index]) => {\n return (\n networkClientOperation.type === 'replace' &&\n networkClientOperation.oldRpcEndpoint.networkClientId ===\n this.state.selectedNetworkClientId\n );\n });\n const correctedReplacementSelectedRpcEndpointIndex =\n replacementSelectedRpcEndpointIndex ??\n replacementSelectedRpcEndpointWithIndex?.[1];\n\n let rpcEndpointToSelect: RpcEndpoint | undefined;\n if (correctedReplacementSelectedRpcEndpointIndex !== undefined) {\n rpcEndpointToSelect =\n updatedNetworkConfiguration.rpcEndpoints[\n correctedReplacementSelectedRpcEndpointIndex\n ];\n\n if (rpcEndpointToSelect === undefined) {\n throw new Error(\n `Could not update network: \\`replacementSelectedRpcEndpointIndex\\` ${correctedReplacementSelectedRpcEndpointIndex} does not refer to an entry in \\`rpcEndpoints\\``,\n );\n }\n }\n\n if (\n rpcEndpointToSelect &&\n rpcEndpointToSelect.networkClientId !== this.state.selectedNetworkClientId\n ) {\n await this.setActiveNetwork(rpcEndpointToSelect.networkClientId, {\n updateState: (state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'update',\n networkFields: fields,\n networkConfigurationToPersist: updatedNetworkConfiguration,\n existingNetworkConfiguration,\n });\n },\n });\n } else {\n this.update((state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'update',\n networkFields: fields,\n networkConfigurationToPersist: updatedNetworkConfiguration,\n existingNetworkConfiguration,\n });\n });\n }\n\n this.#unregisterNetworkClientsAsNeeded({\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n\n return updatedNetworkConfiguration;\n }\n\n /**\n * Destroys and unregisters the network identified by the given chain ID, also\n * removing the associated network configuration from state.\n *\n * @param chainId - The chain ID associated with an existing network.\n * @throws if `chainId` does not refer to an existing network configuration,\n * or if the currently selected network is being removed.\n * @see {@link NetworkConfiguration}\n */\n removeNetwork(chainId: Hex) {\n const existingNetworkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n\n if (existingNetworkConfiguration === undefined) {\n throw new Error(\n `Cannot find network configuration for chain '${chainId}'`,\n );\n }\n\n if (\n existingNetworkConfiguration.rpcEndpoints.some(\n (rpcEndpoint) =>\n rpcEndpoint.networkClientId === this.state.selectedNetworkClientId,\n )\n ) {\n throw new Error(`Cannot remove the currently selected network`);\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n const networkClientOperations =\n existingNetworkConfiguration.rpcEndpoints.map((rpcEndpoint) => {\n return {\n type: 'remove' as const,\n rpcEndpoint,\n };\n });\n\n this.#unregisterNetworkClientsAsNeeded({\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n this.update((state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'remove',\n existingNetworkConfiguration,\n });\n\n for (const rpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {\n delete state.networksMetadata[rpcEndpoint.networkClientId];\n }\n });\n\n this.messenger.publish(\n 'NetworkController:networkRemoved',\n existingNetworkConfiguration,\n );\n }\n\n /**\n * Assuming that the network has been previously switched, switches to this\n * new network.\n *\n * If the network has not been previously switched, this method is equivalent\n * to {@link resetConnection}.\n */\n async rollbackToPreviousProvider() {\n await this.#refreshNetwork(this.#previouslySelectedNetworkClientId);\n }\n\n /**\n * Deactivates the controller, stopping any ongoing polling.\n *\n * In-progress requests will not be aborted.\n */\n // We're intentionally changing the signature of an extended method.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async destroy() {\n await this.#blockTrackerProxy?.destroy();\n }\n\n /**\n * Merges the given backup data into controller state.\n *\n * @param backup - The data that has been backed up.\n * @param backup.networkConfigurationsByChainId - Network configurations,\n * keyed by chain ID.\n */\n loadBackup({\n networkConfigurationsByChainId,\n }: Pick<NetworkState, 'networkConfigurationsByChainId'>): void {\n this.update((state) => {\n state.networkConfigurationsByChainId = {\n ...state.networkConfigurationsByChainId,\n ...networkConfigurationsByChainId,\n };\n });\n }\n\n /**\n * Searches for the default RPC endpoint configured for the given chain and\n * returns its network client ID. This can then be passed to\n * {@link getNetworkClientById} to retrieve the network client.\n *\n * @param chainId - Chain ID to search for.\n * @returns The ID of the network client created for the chain's default RPC\n * endpoint.\n */\n findNetworkClientIdByChainId(chainId: Hex): NetworkClientId {\n const networkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n\n if (!networkConfiguration) {\n throw new Error(`Invalid chain ID \"${chainId}\"`);\n }\n\n const { networkClientId } =\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ];\n return networkClientId;\n }\n\n /**\n * Ensure that the given fields which will be used to either add or update a\n * network are valid.\n *\n * @param args - The arguments.\n */\n #validateNetworkFields(\n args: {\n autoManagedNetworkClientRegistry: AutoManagedNetworkClientRegistry;\n } & (\n | {\n mode: 'add';\n networkFields: AddNetworkFields;\n }\n | {\n mode: 'update';\n existingNetworkConfiguration: NetworkConfiguration;\n networkFields: UpdateNetworkFields;\n }\n ),\n ) {\n const { mode, networkFields, autoManagedNetworkClientRegistry } = args;\n const existingNetworkConfiguration =\n 'existingNetworkConfiguration' in args\n ? args.existingNetworkConfiguration\n : null;\n\n const errorMessagePrefix =\n mode === 'update' ? 'Could not update network' : 'Could not add network';\n\n if (\n !isStrictHexString(networkFields.chainId) ||\n !isSafeChainId(networkFields.chainId)\n ) {\n throw new Error(\n `${errorMessagePrefix}: Invalid \\`chainId\\` '${networkFields.chainId}' (must start with \"0x\" and not exceed the maximum)`,\n );\n }\n\n if (\n existingNetworkConfiguration === null ||\n networkFields.chainId !== existingNetworkConfiguration.chainId\n ) {\n const existingNetworkConfigurationViaChainId =\n this.state.networkConfigurationsByChainId[networkFields.chainId];\n if (existingNetworkConfigurationViaChainId !== undefined) {\n if (existingNetworkConfiguration === null) {\n throw new Error(\n `Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`,\n );\n } else {\n throw new Error(\n `Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`,\n );\n }\n }\n }\n\n const isInvalidDefaultBlockExplorerUrlIndex =\n networkFields.blockExplorerUrls.length > 0\n ? networkFields.defaultBlockExplorerUrlIndex === undefined ||\n networkFields.blockExplorerUrls[\n networkFields.defaultBlockExplorerUrlIndex\n ] === undefined\n : networkFields.defaultBlockExplorerUrlIndex !== undefined;\n\n if (isInvalidDefaultBlockExplorerUrlIndex) {\n throw new Error(\n `${errorMessagePrefix}: \\`defaultBlockExplorerUrlIndex\\` must refer to an entry in \\`blockExplorerUrls\\``,\n );\n }\n\n if (networkFields.rpcEndpoints.length === 0) {\n throw new Error(\n `${errorMessagePrefix}: \\`rpcEndpoints\\` must be a non-empty array`,\n );\n }\n for (const rpcEndpointFields of networkFields.rpcEndpoints) {\n if (!isValidUrl(rpcEndpointFields.url)) {\n throw new Error(\n `${errorMessagePrefix}: An entry in \\`rpcEndpoints\\` has invalid URL '${rpcEndpointFields.url}'`,\n );\n }\n const networkClientId =\n 'networkClientId' in rpcEndpointFields\n ? rpcEndpointFields.networkClientId\n : undefined;\n\n if (\n rpcEndpointFields.type === RpcEndpointType.Custom &&\n networkClientId !== undefined &&\n isInfuraNetworkType(networkClientId)\n ) {\n throw new Error(\n `${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`,\n );\n }\n\n if (\n mode === 'update' &&\n networkClientId !== undefined &&\n rpcEndpointFields.type === RpcEndpointType.Custom &&\n !Object.values(autoManagedNetworkClientRegistry).some(\n (networkClientsById) => networkClientId in networkClientsById,\n )\n ) {\n throw new Error(\n `${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`,\n );\n }\n\n if (\n networkFields.rpcEndpoints.some(\n (otherRpcEndpointFields) =>\n otherRpcEndpointFields !== rpcEndpointFields &&\n URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url),\n )\n ) {\n throw new Error(\n `${errorMessagePrefix}: Each entry in rpcEndpoints must have a unique URL`,\n );\n }\n\n const networkConfigurationsForOtherChains = Object.values(\n this.state.networkConfigurationsByChainId,\n ).filter((networkConfiguration) =>\n existingNetworkConfiguration\n ? networkConfiguration.chainId !==\n existingNetworkConfiguration.chainId\n : true,\n );\n for (const networkConfiguration of networkConfigurationsForOtherChains) {\n const rpcEndpoint = networkConfiguration.rpcEndpoints.find(\n (existingRpcEndpoint) =>\n URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url),\n );\n if (rpcEndpoint) {\n if (mode === 'update') {\n throw new Error(\n `Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`,\n );\n } else {\n throw new Error(\n `Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`,\n );\n }\n }\n }\n }\n\n if (\n [...new Set(networkFields.rpcEndpoints)].length <\n networkFields.rpcEndpoints.length\n ) {\n throw new Error(\n `${errorMessagePrefix}: Each entry in rpcEndpoints must be unique`,\n );\n }\n\n const networkClientIds = networkFields.rpcEndpoints\n .map((rpcEndpoint) =>\n 'networkClientId' in rpcEndpoint\n ? rpcEndpoint.networkClientId\n : undefined,\n )\n .filter(\n (networkClientId): networkClientId is NetworkClientId =>\n networkClientId !== undefined,\n );\n if ([...new Set(networkClientIds)].length < networkClientIds.length) {\n throw new Error(\n `${errorMessagePrefix}: Each entry in rpcEndpoints must have a unique networkClientId`,\n );\n }\n\n const infuraRpcEndpoints = networkFields.rpcEndpoints.filter(\n (rpcEndpointFields): rpcEndpointFields is InfuraRpcEndpoint =>\n rpcEndpointFields.type === RpcEndpointType.Infura,\n );\n if (infuraRpcEndpoints.length > 1) {\n throw new Error(\n `${errorMessagePrefix}: There cannot be more than one Infura RPC endpoint`,\n );\n }\n\n const soleInfuraRpcEndpoint = infuraRpcEndpoints[0];\n if (soleInfuraRpcEndpoint) {\n const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(\n soleInfuraRpcEndpoint.url,\n );\n const infuraNetworkNickname = NetworkNickname[infuraNetworkName];\n const infuraChainId = ChainId[infuraNetworkName];\n if (networkFields.chainId !== infuraChainId) {\n throw new Error(\n mode === 'add'\n ? `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`\n : `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`,\n );\n }\n }\n\n if (\n networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===\n undefined\n ) {\n throw new Error(\n `${errorMessagePrefix}: \\`defaultRpcEndpointIndex\\` must refer to an entry in \\`rpcEndpoints\\``,\n );\n }\n }\n\n /**\n * Constructs a network configuration that will be persisted to state when\n * adding or updating a network.\n *\n * @param args - The arguments to this function.\n * @param args.networkFields - The fields used to add or update a network.\n * @param args.networkClientOperations - Operations which were calculated for\n * updating the network client registry but which also map back to RPC\n * endpoints (and so can be used to save those RPC endpoints).\n * @returns The network configuration to persist.\n */\n #determineNetworkConfigurationToPersist({\n networkFields,\n networkClientOperations,\n }: {\n networkFields: AddNetworkFields | UpdateNetworkFields;\n networkClientOperations: NetworkClientOperation[];\n }): NetworkConfiguration {\n const rpcEndpointsToPersist = networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is\n | AddNetworkClientOperation\n | NoopNetworkClientOperation => {\n return (\n networkClientOperation.type === 'add' ||\n networkClientOperation.type === 'noop'\n );\n },\n )\n .map((networkClientOperation) => networkClientOperation.rpcEndpoint)\n .concat(\n networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is ReplaceNetworkClientOperation => {\n return networkClientOperation.type === 'replace';\n },\n )\n .map(\n (networkClientOperation) => networkClientOperation.newRpcEndpoint,\n ),\n );\n\n return { ...networkFields, rpcEndpoints: rpcEndpointsToPersist };\n }\n\n /**\n * Creates and registers network clients using the given operations calculated\n * as a part of adding or updating a network.\n *\n * @param args - The arguments to this function.\n * @param args.networkFields - The fields used to add or update a network.\n * @param args.networkClientOperations - Dictate which network clients need to\n * be created.\n * @param args.autoManagedNetworkClientRegistry - The network client registry\n * to update.\n */\n #registerNetworkClientsAsNeeded({\n networkFields,\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n }: {\n networkFields: AddNetworkFields | UpdateNetworkFields;\n networkClientOperations: NetworkClientOperation[];\n autoManagedNetworkClientRegistry: AutoManagedNetworkClientRegistry;\n }) {\n const addedRpcEndpoints = networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is AddNetworkClientOperation => {\n return networkClientOperation.type === 'add';\n },\n )\n .map((networkClientOperation) => networkClientOperation.rpcEndpoint)\n .concat(\n networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is ReplaceNetworkClientOperation => {\n return networkClientOperation.type === 'replace';\n },\n )\n .map(\n (networkClientOperation) => networkClientOperation.newRpcEndpoint,\n ),\n );\n\n for (const addedRpcEndpoint of addedRpcEndpoints) {\n if (addedRpcEndpoint.type === RpcEndpointType.Infura) {\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n addedRpcEndpoint.networkClientId\n ] = createAutoManagedNetworkClient({\n networkClientId: addedRpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Infura,\n chainId: networkFields.chainId,\n network: addedRpcEndpoint.networkClientId,\n failoverRpcUrls: addedRpcEndpoint.failoverUrls,\n infuraProjectId: this.#infuraProjectId,\n ticker: networkFields.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n });\n } else {\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n addedRpcEndpoint.networkClientId\n ] = createAutoManagedNetworkClient({\n networkClientId: addedRpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Custom,\n chainId: networkFields.chainId,\n failoverRpcUrls: addedRpcEndpoint.failoverUrls,\n rpcUrl: addedRpcEndpoint.url,\n ticker: networkFields.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n });\n }\n }\n }\n\n /**\n * Destroys and removes network clients using the given operations calculated\n * as a part of updating or removing a network.\n *\n * @param args - The arguments to this function.\n * @param args.networkClientOperations - Dictate which network clients to\n * remove.\n * @param args.autoManagedNetworkClientRegistry - The network client registry\n * to update.\n */\n #unregisterNetworkClientsAsNeeded({\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n }: {\n networkClientOperations: NetworkClientOperation[];\n autoManagedNetworkClientRegistry: AutoManagedNetworkClientRegistry;\n }) {\n const removedRpcEndpoints = networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is RemoveNetworkClientOperation => {\n return networkClientOperation.type === 'remove';\n },\n )\n .map((networkClientOperation) => networkClientOperation.rpcEndpoint)\n .concat(\n networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is ReplaceNetworkClientOperation => {\n return networkClientOperation.type === 'replace';\n },\n )\n .map(\n (networkClientOperation) => networkClientOperation.oldRpcEndpoint,\n ),\n );\n\n for (const rpcEndpoint of removedRpcEndpoints) {\n const networkClient = this.getNetworkClientById(\n rpcEndpoint.networkClientId,\n );\n networkClient.destroy();\n delete autoManagedNetworkClientRegistry[networkClient.configuration.type][\n rpcEndpoint.networkClientId\n ];\n }\n }\n\n /**\n * Updates `networkConfigurationsByChainId` in state depending on whether a\n * network is being added, updated, or removed.\n *\n * - The existing network configuration will be removed when a network is\n * being filed under a different chain or removed.\n * - A network configuration will be stored when a network is being added or\n * when a network is being updated.\n *\n * @param args - The arguments to this function.\n */\n #updateNetworkConfigurations(\n args: { state: Draft<NetworkState> } & (\n | {\n mode: 'add';\n networkFields: AddNetworkFields;\n networkConfigurationToPersist: NetworkConfiguration;\n }\n | {\n mode: 'update';\n networkFields: UpdateNetworkFields;\n networkConfigurationToPersist: NetworkConfiguration;\n existingNetworkConfiguration: NetworkConfiguration;\n }\n | {\n mode: 'remove';\n existingNetworkConfiguration: NetworkConfiguration;\n }\n ),\n ) {\n const { state, mode } = args;\n\n if (\n mode === 'remove' ||\n (mode === 'update' &&\n args.networkFields.chainId !==\n args.existingNetworkConfiguration.chainId)\n ) {\n delete state.networkConfigurationsByChainId[\n args.existingNetworkConfiguration.chainId\n ];\n }\n\n if (mode === 'add' || mode === 'update') {\n if (\n !deepEqual(\n state.networkConfigurationsByChainId[args.networkFields.chainId],\n args.networkConfigurationToPersist,\n )\n ) {\n args.networkConfigurationToPersist.lastUpdatedAt = Date.now();\n }\n state.networkConfigurationsByChainId[args.networkFields.chainId] =\n args.networkConfigurationToPersist;\n }\n\n this.#networkConfigurationsByNetworkClientId =\n buildNetworkConfigurationsByNetworkClientId(\n cloneDeep(state.networkConfigurationsByChainId),\n );\n }\n\n /**\n * Before accessing or switching the network, the registry of network clients\n * needs to be populated. Otherwise, `#applyNetworkSelection` and\n * `getNetworkClientRegistry` will throw an error. This method checks to see if the\n * population step has happened yet, and if not, makes it happen.\n *\n * @returns The populated network client registry.\n */\n #ensureAutoManagedNetworkClientRegistryPopulated(): AutoManagedNetworkClientRegistry {\n return (this.#autoManagedNetworkClientRegistry ??=\n this.#createAutoManagedNetworkClientRegistry());\n }\n\n /**\n * Constructs the registry of network clients based on the set of default\n * and custom networks in state.\n *\n * @returns The network clients keyed by ID.\n */\n #createAutoManagedNetworkClientRegistry(): AutoManagedNetworkClientRegistry {\n const chainIds = knownKeysOf(this.state.networkConfigurationsByChainId);\n const networkClientsWithIds = chainIds.flatMap((chainId) => {\n const networkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n return networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {\n if (rpcEndpoint.type === RpcEndpointType.Infura) {\n const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(\n rpcEndpoint.url,\n );\n return [\n rpcEndpoint.networkClientId,\n createAutoManagedNetworkClient({\n networkClientId: rpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Infura,\n network: infuraNetworkName,\n failoverRpcUrls: rpcEndpoint.failoverUrls,\n infuraProjectId: this.#infuraProjectId,\n chainId: networkConfiguration.chainId,\n ticker: networkConfiguration.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n }),\n ] as const;\n }\n return [\n rpcEndpoint.networkClientId,\n createAutoManagedNetworkClient({\n networkClientId: rpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Custom,\n chainId: networkConfiguration.chainId,\n failoverRpcUrls: rpcEndpoint.failoverUrls,\n rpcUrl: rpcEndpoint.url,\n ticker: networkConfiguration.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n }),\n ] as const;\n });\n });\n\n return networkClientsWithIds.reduce(\n (\n obj: {\n [NetworkClientType.Custom]: Partial<AutoManagedCustomNetworkClientRegistry>;\n [NetworkClientType.Infura]: Partial<AutoManagedBuiltInNetworkClientRegistry>;\n },\n [networkClientId, networkClient],\n ) => {\n return {\n ...obj,\n [networkClient.configuration.type]: {\n ...obj[networkClient.configuration.type],\n [networkClientId]: networkClient,\n },\n };\n },\n {\n [NetworkClientType.Custom]: {},\n [NetworkClientType.Infura]: {},\n },\n ) as AutoManagedNetworkClientRegistry;\n }\n\n /**\n * Updates the global provider and block tracker proxies (accessible via\n * {@link getSelectedNetworkClient}) to point to the same ones within the\n * given network client, thereby magically switching any consumers using these\n * proxies to use the new network.\n *\n * Also refreshes the EthQuery instance accessible via the `getEthQuery`\n * action to wrap the provider from the new network client. Note that this is\n * not a proxy, so consumers will need to call `getEthQuery` again after the\n * network switch.\n *\n * @param networkClientId - The ID of a network client that requests will be\n * routed through (either the name of an Infura network or the ID of a custom\n * network configuration).\n * @param options - Options for this method.\n * @param options.updateState - Allows for updating state.\n * @throws if no network client could be found matching the given ID.\n */\n #applyNetworkSelection(\n networkClientId: string,\n {\n updateState,\n }: {\n updateState?: (state: Draft<NetworkState>) => void;\n } = {},\n ) {\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n let autoManagedNetworkClient:\n | AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n | AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n if (isInfuraNetworkType(networkClientId)) {\n const possibleAutoManagedNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n networkClientId\n ];\n\n // This is impossible to reach\n /* istanbul ignore if */\n if (!possibleAutoManagedNetworkClient) {\n throw new Error(\n `No Infura network client found with ID '${networkClientId}'`,\n );\n }\n\n autoManagedNetworkClient = possibleAutoManagedNetworkClient;\n } else {\n const possibleAutoManagedNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n networkClientId\n ];\n\n if (!possibleAutoManagedNetworkClient) {\n throw new Error(`No network client found with ID '${networkClientId}'`);\n }\n\n autoManagedNetworkClient = possibleAutoManagedNetworkClient;\n }\n\n this.#autoManagedNetworkClient = autoManagedNetworkClient;\n\n this.update((state) => {\n state.selectedNetworkClientId = networkClientId;\n if (state.networksMetadata[networkClientId] === undefined) {\n state.networksMetadata[networkClientId] = {\n status: NetworkStatus.Unknown,\n EIPS: {},\n };\n }\n updateState?.(state);\n });\n\n if (this.#providerProxy) {\n this.#providerProxy.setTarget(this.#autoManagedNetworkClient.provider);\n } else {\n this.#providerProxy = createSwappableProxy(\n this.#autoManagedNetworkClient.provider,\n );\n }\n\n if (this.#blockTrackerProxy) {\n this.#blockTrackerProxy.setTarget(\n this.#autoManagedNetworkClient.blockTracker,\n );\n } else {\n this.#blockTrackerProxy = createEventEmitterProxy(\n this.#autoManagedNetworkClient.blockTracker,\n {\n eventFilter: 'skipInternal',\n },\n );\n }\n\n this.#ethQuery = new EthQuery(this.#providerProxy);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NetworkController.cjs","sourceRoot":"","sources":["../src/NetworkController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+DAA2D;AAE3D,iEAWoC;AAGpC,oEAA2C;AAE3C,qDAAkD;AAClD,uEAGuC;AA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G;gBACxC,MAAM,EAAE,yBAAa,CAAC,OAAO;gBAC7B,IAAI,EAAE,EAAE;aACT,CAAC;QACJ,CAAC;QACD,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,IAAI,uBAAA,IAAI,wCAAe,EAAE,CAAC;QACxB,uBAAA,IAAI,wCAAe,CAAC,SAAS,CAAC,uBAAA,IAAI,mDAA0B,CAAC,QAAQ,CAAC,CAAC;IACzE,CAAC;SAAM,CAAC;QACN,uBAAA,IAAI,oCAAkB,IAAA,0CAAoB,EACxC,uBAAA,IAAI,mDAA0B,CAAC,QAAQ,CACxC,MAAA,CAAC;IACJ,CAAC;IAED,IAAI,uBAAA,IAAI,4CAAmB,EAAE,CAAC;QAC5B,uBAAA,IAAI,4CAAmB,CAAC,SAAS,CAC/B,uBAAA,IAAI,mDAA0B,CAAC,YAAY,CAC5C,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,uBAAA,IAAI,wCAAsB,IAAA,6CAAuB,EAC/C,uBAAA,IAAI,mDAA0B,CAAC,YAAY,EAC3C;YACE,WAAW,EAAE,cAAc;SAC5B,CACF,MAAA,CAAC;IACJ,CAAC;IAED,uBAAA,IAAI,+BAAa,IAAI,mBAAQ,CAAC,uBAAA,IAAI,wCAAe,CAAC,MAAA,CAAC;AACrD,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Partialize } from '@metamask/controller-utils';\nimport {\n InfuraNetworkType,\n CustomNetworkType,\n NetworkType,\n isSafeChainId,\n isInfuraNetworkType,\n ChainId,\n NetworksTicker,\n NetworkNickname,\n BUILT_IN_CUSTOM_NETWORKS_RPC,\n BUILT_IN_NETWORKS,\n} from '@metamask/controller-utils';\nimport type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\nimport type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker';\nimport EthQuery from '@metamask/eth-query';\nimport type { Messenger } from '@metamask/messenger';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport {\n createEventEmitterProxy,\n createSwappableProxy,\n} from '@metamask/swappable-obj-proxy';\nimport type { SwappableProxy } from '@metamask/swappable-obj-proxy';\nimport type { Hex } from '@metamask/utils';\nimport { hasProperty, isPlainObject, isStrictHexString } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport { cloneDeep } from 'lodash';\nimport type { Logger } from 'loglevel';\nimport { createSelector } from 'reselect';\nimport * as URI from 'uri-js';\nimport { v4 as uuidV4 } from 'uuid';\n\nimport {\n DEPRECATED_NETWORKS,\n INFURA_BLOCKED_KEY,\n NetworkStatus,\n} from './constants';\nimport type {\n AutoManagedNetworkClient,\n ProxyWithAccessibleTarget,\n} from './create-auto-managed-network-client';\nimport { createAutoManagedNetworkClient } from './create-auto-managed-network-client';\nimport { projectLogger, createModuleLogger } from './logger';\nimport type { RpcServiceOptions } from './rpc-service/rpc-service';\nimport { NetworkClientType } from './types';\nimport type {\n BlockTracker,\n Provider,\n CustomNetworkClientConfiguration,\n InfuraNetworkClientConfiguration,\n NetworkClientConfiguration,\n AdditionalDefaultNetwork,\n} from './types';\n\nconst debugLog = createModuleLogger(projectLogger, 'NetworkController');\n\nconst INFURA_URL_REGEX =\n /^https:\\/\\/(?<networkName>[^.]+)\\.infura\\.io\\/v\\d+\\/(?<apiKey>.+)$/u;\n\nexport type Block = {\n baseFeePerGas?: string;\n};\n\n/**\n * Information about a network not held by any other part of state.\n */\nexport type NetworkMetadata = {\n /**\n * EIPs supported by the network.\n */\n EIPS: {\n [eipNumber: number]: boolean;\n };\n /**\n * Indicates the availability of the network\n */\n status: NetworkStatus;\n};\n\n/**\n * The type of an RPC endpoint.\n *\n * @see {@link CustomRpcEndpoint}\n * @see {@link InfuraRpcEndpoint}\n */\nexport enum RpcEndpointType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * An Infura RPC endpoint is a reference to a specific network that Infura\n * supports as well as an Infura account we own that we allow users to make use\n * of for free. We need to disambiguate these endpoints from custom RPC\n * endpoints, because while the types for these kinds of object both have the\n * same interface, the URL for an Infura endpoint contains the Infura project\n * ID, and we don't want this to be present in state. We therefore hide it by\n * representing it in the URL as `{infuraProjectId}`, which we replace this when\n * create network clients. But we need to know somehow that we only need to do\n * this replacement for Infura endpoints and not custom endpoints — hence the\n * separate type.\n */\nexport type InfuraRpcEndpoint = {\n /**\n * Alternate RPC endpoints to use when this endpoint is down.\n */\n failoverUrls?: string[];\n /**\n * The optional user-facing nickname of the endpoint.\n */\n name?: string;\n /**\n * The identifier for the network client that has been created for this RPC\n * endpoint. This is also used to uniquely identify the RPC endpoint in a\n * set of RPC endpoints as well: once assigned, it is used to determine\n * whether the `name`, `type`, or `url` of the RPC endpoint has changed.\n */\n networkClientId: BuiltInNetworkClientId;\n /**\n * The type of this endpoint, always \"default\".\n */\n type: RpcEndpointType.Infura;\n /**\n * The URL of the endpoint. Expected to be a template with the string\n * `{infuraProjectId}`, which will get replaced with the Infura project ID\n * when the network client is created.\n */\n url: `https://${InfuraNetworkType}.infura.io/v3/{infuraProjectId}`;\n};\n\n/**\n * A custom RPC endpoint is a reference to a user-defined server which fronts an\n * EVM chain. It may refer to an Infura network, but only by coincidence.\n */\nexport type CustomRpcEndpoint = {\n /**\n * Alternate RPC endpoints to use when this endpoint is down.\n */\n failoverUrls?: string[];\n /**\n * The optional user-facing nickname of the endpoint.\n */\n name?: string;\n /**\n * The identifier for the network client that has been created for this RPC\n * endpoint. This is also used to uniquely identify the RPC endpoint in a\n * set of RPC endpoints as well: once assigned, it is used to determine\n * whether the `name`, `type`, or `url` of the RPC endpoint has changed.\n */\n networkClientId: CustomNetworkClientId;\n /**\n * The type of this endpoint, always \"custom\".\n */\n type: RpcEndpointType.Custom;\n /**\n * The URL of the endpoint.\n */\n url: string;\n};\n\n/**\n * An RPC endpoint is a reference to a server which fronts an EVM chain. There\n * are two varieties of RPC endpoints: Infura and custom.\n *\n * @see {@link CustomRpcEndpoint}\n * @see {@link InfuraRpcEndpoint}\n */\nexport type RpcEndpoint = InfuraRpcEndpoint | CustomRpcEndpoint;\n\n/**\n * From a user perspective, a network configuration holds information about a\n * network that a user can select through the client. A \"network\" in this sense\n * can explicitly refer to an EVM chain that the user explicitly adds or doesn't\n * need to add (because it comes shipped with the client). The properties here\n * therefore directly map to fields that a user sees and can edit for a network\n * within the client.\n *\n * Internally, a network configuration represents a single conceptual EVM chain,\n * which is represented tangibly via multiple RPC endpoints. A \"network\" is then\n * something for which a network client object is created automatically or\n * created on demand when it is added to the client.\n */\nexport type NetworkConfiguration = {\n /**\n * A set of URLs that allows the user to view activity that has occurred on\n * the chain.\n */\n blockExplorerUrls: string[];\n /**\n * The ID of the chain. Represented in hexadecimal format with a leading \"0x\"\n * instead of decimal format so that when viewed out of context it can be\n * unambiguously interpreted.\n */\n chainId: Hex;\n /**\n * A reference to a URL that the client will use by default to allow the user\n * to view activity that has occurred on the chain. This index must refer to\n * an item in `blockExplorerUrls`.\n */\n defaultBlockExplorerUrlIndex?: number;\n /**\n * A reference to an RPC endpoint that all requests will use by default in order to\n * interact with the chain. This index must refer to an item in\n * `rpcEndpoints`.\n */\n defaultRpcEndpointIndex: number;\n /**\n * The user-facing nickname assigned to the chain.\n */\n name: string;\n /**\n * The name of the currency to use for the chain.\n */\n nativeCurrency: string;\n /**\n * The collection of possible RPC endpoints that the client can use to\n * interact with the chain.\n */\n rpcEndpoints: RpcEndpoint[];\n /**\n * Profile Sync - Network Sync field.\n * Allows comparison of local network state with state to sync.\n */\n lastUpdatedAt?: number;\n};\n\n/**\n * A custom RPC endpoint in a new network configuration, meant to be used in\n * conjunction with `AddNetworkFields`.\n *\n * Custom RPC endpoints do not need a `networkClientId` property because it is\n * assumed that they have not already been added and therefore network clients\n * do not exist for them yet (and hence IDs need to be generated).\n */\nexport type AddNetworkCustomRpcEndpointFields = Omit<\n CustomRpcEndpoint,\n 'networkClientId'\n>;\n\n/**\n * A new network configuration that `addNetwork` takes.\n *\n * Custom RPC endpoints do not need a `networkClientId` property because it is\n * assumed that they have not already been added and are not represented by\n * network clients yet.\n */\nexport type AddNetworkFields = Omit<NetworkConfiguration, 'rpcEndpoints'> & {\n rpcEndpoints: (InfuraRpcEndpoint | AddNetworkCustomRpcEndpointFields)[];\n};\n\n/**\n * A custom RPC endpoint in an updated representation of a network\n * configuration, meant to be used in conjunction with `UpdateNetworkFields`.\n *\n * Custom RPC endpoints do not need a `networkClientId` property because it is\n * assumed that they have not already been added and therefore network clients\n * do not exist for them yet (and hence IDs need to be generated).\n */\nexport type UpdateNetworkCustomRpcEndpointFields = Partialize<\n CustomRpcEndpoint,\n 'networkClientId'\n>;\n\n/**\n * An updated representation of an existing network configuration that\n * `updateNetwork` takes.\n *\n * Custom RPC endpoints may or may not have a `networkClientId` property; if\n * they do, then it is assumed that they already exist, and if not, then it is\n * assumed that they are new and are not represented by network clients yet.\n */\nexport type UpdateNetworkFields = Omit<NetworkConfiguration, 'rpcEndpoints'> & {\n rpcEndpoints: (InfuraRpcEndpoint | UpdateNetworkCustomRpcEndpointFields)[];\n};\n\n/**\n * `Object.keys()` is intentionally generic: it returns the keys of an object,\n * but it cannot make guarantees about the contents of that object, so the type\n * of the keys is merely `string[]`. While this is technically accurate, it is\n * also unnecessary if we have an object that we own and whose contents are\n * known exactly.\n *\n * TODO: Move to @metamask/utils.\n *\n * @param object - The object.\n * @returns The keys of an object, typed according to the type of the object\n * itself.\n */\nexport function knownKeysOf<K extends PropertyKey>(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n object: Partial<Record<K, any>>,\n) {\n return Object.keys(object) as K[];\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `code` property, such as an instance of Error.\n *\n * TODO: Move this to @metamask/utils.\n *\n * @param error - The object to check.\n * @returns True if `error` has a `code`, false otherwise.\n */\nfunction isErrorWithCode(error: unknown): error is { code: string | number } {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n\n/**\n * The string that uniquely identifies an Infura network client.\n */\nexport type BuiltInNetworkClientId = InfuraNetworkType;\n\n/**\n * The string that uniquely identifies a custom network client.\n */\nexport type CustomNetworkClientId = string;\n\n/**\n * The string that uniquely identifies a network client.\n */\nexport type NetworkClientId = BuiltInNetworkClientId | CustomNetworkClientId;\n\n/**\n * Extra information about each network, such as whether it is accessible or\n * blocked and whether it supports EIP-1559, keyed by network client ID.\n */\nexport type NetworksMetadata = Record<NetworkClientId, NetworkMetadata>;\n\n/**\n * The state that NetworkController stores.\n */\nexport type NetworkState = {\n /**\n * The ID of the network client that the proxies returned by\n * `getSelectedNetworkClient` currently point to.\n */\n selectedNetworkClientId: NetworkClientId;\n /**\n * The registry of networks and corresponding RPC endpoints that the\n * controller can use to make requests for various chains.\n *\n * @see {@link NetworkConfiguration}\n */\n networkConfigurationsByChainId: Record<Hex, NetworkConfiguration>;\n /**\n * Extra information about each network, such as whether it is accessible or\n * blocked and whether it supports EIP-1559, keyed by network client ID.\n */\n networksMetadata: NetworksMetadata;\n};\n\nconst controllerName = 'NetworkController';\n\n/**\n * Represents the block tracker for the currently selected network. (Note that\n * this is a proxy around a proxy: the inner one exists so that the block\n * tracker doesn't have to exist until it's used, and the outer one exists so\n * that the currently selected network can change without consumers needing to\n * refresh the object reference to that network.)\n */\nexport type BlockTrackerProxy = SwappableProxy<\n ProxyWithAccessibleTarget<BlockTracker>\n>;\n\n/**\n * Represents the provider for the currently selected network. (Note that this\n * is a proxy around a proxy: the inner one exists so that the provider doesn't\n * have to exist until it's used, and the outer one exists so that the currently\n * selected network can change without consumers needing to refresh the object\n * reference to that network.)\n */\nexport type ProviderProxy = SwappableProxy<ProxyWithAccessibleTarget<Provider>>;\n\nexport type NetworkControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n NetworkState\n>;\n\n/**\n * `networkWillChange` is published when the current network is about to be\n * switched, but the new provider has not been created and no state changes have\n * occurred yet.\n */\nexport type NetworkControllerNetworkWillChangeEvent = {\n type: 'NetworkController:networkWillChange';\n payload: [NetworkState];\n};\n\n/**\n * `networkDidChange` is published after a provider has been created for a newly\n * switched network (but before the network has been confirmed to be available).\n */\nexport type NetworkControllerNetworkDidChangeEvent = {\n type: 'NetworkController:networkDidChange';\n payload: [NetworkState];\n};\n\n/**\n * `infuraIsBlocked` is published after the network is switched to an Infura\n * network, but when Infura returns an error blocking the user based on their\n * location.\n */\nexport type NetworkControllerInfuraIsBlockedEvent = {\n type: 'NetworkController:infuraIsBlocked';\n payload: [];\n};\n\n/**\n * `infuraIsBlocked` is published either after the network is switched to an\n * Infura network and Infura does not return an error blocking the user based on\n * their location, or the network is switched to a non-Infura network.\n */\nexport type NetworkControllerInfuraIsUnblockedEvent = {\n type: 'NetworkController:infuraIsUnblocked';\n payload: [];\n};\n\n/**\n * `networkAdded` is published after a network configuration is added to the\n * network configuration registry and network clients are created for it.\n */\nexport type NetworkControllerNetworkAddedEvent = {\n type: 'NetworkController:networkAdded';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n/**\n * `networkRemoved` is published after a network configuration is removed from the\n * network configuration registry and once the network clients have been removed.\n */\nexport type NetworkControllerNetworkRemovedEvent = {\n type: 'NetworkController:networkRemoved';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n/**\n * `NetworkController:rpcEndpointChainUnavailable` is published when, after\n * trying all endpoints in an endpoint chain, the last failover reaches a\n * maximum number of consecutive 5xx responses, breaking the underlying circuit.\n *\n * In other words, this event will not be published if a failover is available,\n * even if the primary is not.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.error - The last error produced by the last failover in the\n * endpoint chain.\n * @param payload.networkClientId - The target network's client ID.\n */\nexport type NetworkControllerRpcEndpointChainUnavailableEvent = {\n type: 'NetworkController:rpcEndpointChainUnavailable';\n payload: [\n {\n chainId: Hex;\n error: unknown;\n networkClientId: NetworkClientId;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointUnavailable` is published when any\n * endpoint in an endpoint chain reaches a maximum number of consecutive 5xx\n * responses, breaking the underlying circuit.\n *\n * In other words, this event will be published if a primary is not available,\n * even if a failover is.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.endpointUrl - The URL of the endpoint which reached the\n * maximum number of consecutive 5xx responses. You can compare this to\n * `primaryEndpointUrl` to know whether it was a failover or a primary.\n * @param payload.error - The last error produced by the endpoint.\n * @param payload.networkClientId - The target network's client ID.\n * @param payload.primaryEndpointUrl - The endpoint chain's primary URL.\n */\nexport type NetworkControllerRpcEndpointUnavailableEvent = {\n type: 'NetworkController:rpcEndpointUnavailable';\n payload: [\n {\n chainId: Hex;\n endpointUrl: string;\n error: unknown;\n networkClientId: NetworkClientId;\n primaryEndpointUrl: string;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointChainDegraded` is published for any of the\n * endpoints in an endpoint chain when one of the following two conditions hold\n * (and the chain is not already in a degraded state):\n *\n * 1. A successful (2xx) request, even after being retried, cannot be made to\n * the endpoint.\n * 2. A successful (2xx) request can be made to the endpoint, but it takes\n * longer than expected to complete.\n *\n * Note that this event will be published even if there are local connectivity\n * issues which prevent requests from being initiated. This is intentional.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.error - The last error produced by the endpoint (or\n * `undefined` if the request was slow).\n * @param payload.networkClientId - The target network's client ID.\n */\nexport type NetworkControllerRpcEndpointChainDegradedEvent = {\n type: 'NetworkController:rpcEndpointChainDegraded';\n payload: [\n {\n chainId: Hex;\n error: unknown;\n networkClientId: NetworkClientId;\n },\n ];\n};\n\n/**\n *\n * `NetworkController:rpcEndpointDegraded` is published for any of the endpoints\n * in an endpoint chain when:\n *\n * 1. A successful (2xx) request, even after being retried, cannot be made to\n * the endpoint.\n * 2. A successful (2xx) request can be made to the endpoint, but it takes\n * longer than expected to complete.\n *\n * Note that this event will be published even if there are local connectivity\n * issues which prevent requests from being initiated. This is intentional.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.endpointUrl - The URL of the endpoint for which requests\n * failed or were slow to complete. You can compare this to `primaryEndpointUrl`\n * to know whether it was a failover or a primary.\n * @param payload.error - The last error produced by the endpoint (or\n * `undefined` if the request was slow).\n * @param payload.networkClientId - The target network's client ID.\n * @param payload.primaryEndpointUrl - The endpoint chain's primary URL.\n */\nexport type NetworkControllerRpcEndpointDegradedEvent = {\n type: 'NetworkController:rpcEndpointDegraded';\n payload: [\n {\n chainId: Hex;\n endpointUrl: string;\n error: unknown;\n networkClientId: NetworkClientId;\n primaryEndpointUrl: string;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointChainAvailable` is published in one of two\n * cases:\n *\n * 1. The first time that a 2xx request is made to any of the endpoints in an\n * endpoint chain.\n * 2. When requests to any of the endpoints previously failed (placing the\n * endpoint in a degraded or unavailable status), but are now succeeding again.\n *\n * @param payload - The event payload.\n * @param payload.chainId - The target network's chain ID.\n * @param payload.networkClientId - The target network's client ID.\n */\nexport type NetworkControllerRpcEndpointChainAvailableEvent = {\n type: 'NetworkController:rpcEndpointChainAvailable';\n payload: [\n {\n chainId: Hex;\n networkClientId: NetworkClientId;\n },\n ];\n};\n\n/**\n * `NetworkController:rpcEndpointRetried` is published before a request to any\n * endpoint in an endpoint chain is retried.\n *\n * This is mainly useful for tests.\n *\n * @param payload - The event payload.\n * @param payload.attempt - The current attempt counter for the endpoint\n * (starting from 0).\n * @param payload.chainId - The target network's chain ID.\n * @param payload.endpointUrl - The URL of the endpoint being retried.\n * @param payload.networkClientId - The target network's client ID.\n * @param payload.primaryEndpointUrl - The endpoint chain's primary URL.\n * @see {@link RpcService} for the list of retriable errors.\n */\nexport type NetworkControllerRpcEndpointRetriedEvent = {\n type: 'NetworkController:rpcEndpointRetried';\n payload: [\n {\n attempt: number;\n chainId: Hex;\n endpointUrl: string;\n networkClientId: NetworkClientId;\n primaryEndpointUrl: string;\n },\n ];\n};\n\nexport type NetworkControllerEvents =\n | NetworkControllerStateChangeEvent\n | NetworkControllerNetworkWillChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | NetworkControllerInfuraIsBlockedEvent\n | NetworkControllerInfuraIsUnblockedEvent\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkRemovedEvent\n | NetworkControllerRpcEndpointChainUnavailableEvent\n | NetworkControllerRpcEndpointUnavailableEvent\n | NetworkControllerRpcEndpointChainDegradedEvent\n | NetworkControllerRpcEndpointDegradedEvent\n | NetworkControllerRpcEndpointChainAvailableEvent\n | NetworkControllerRpcEndpointRetriedEvent;\n\n/**\n * All events that {@link NetworkController} calls internally.\n */\ntype AllowedEvents = never;\n\nexport type NetworkControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n NetworkState\n>;\n\nexport type NetworkControllerGetEthQueryAction = {\n type: `NetworkController:getEthQuery`;\n handler: () => EthQuery | undefined;\n};\n\nexport type NetworkControllerGetNetworkClientByIdAction = {\n type: `NetworkController:getNetworkClientById`;\n handler: NetworkController['getNetworkClientById'];\n};\n\nexport type NetworkControllerGetSelectedNetworkClientAction = {\n type: `NetworkController:getSelectedNetworkClient`;\n handler: NetworkController['getSelectedNetworkClient'];\n};\n\nexport type NetworkControllerGetSelectedChainIdAction = {\n type: 'NetworkController:getSelectedChainId';\n handler: NetworkController['getSelectedChainId'];\n};\n\nexport type NetworkControllerGetEIP1559CompatibilityAction = {\n type: `NetworkController:getEIP1559Compatibility`;\n handler: NetworkController['getEIP1559Compatibility'];\n};\n\nexport type NetworkControllerFindNetworkClientIdByChainIdAction = {\n type: `NetworkController:findNetworkClientIdByChainId`;\n handler: NetworkController['findNetworkClientIdByChainId'];\n};\n\n/**\n * Change the currently selected network to the given built-in network type.\n *\n * @deprecated This action has been replaced by `setActiveNetwork`, and will be\n * removed in a future release.\n */\nexport type NetworkControllerSetProviderTypeAction = {\n type: `NetworkController:setProviderType`;\n handler: NetworkController['setProviderType'];\n};\n\nexport type NetworkControllerSetActiveNetworkAction = {\n type: `NetworkController:setActiveNetwork`;\n handler: NetworkController['setActiveNetwork'];\n};\n\nexport type NetworkControllerGetNetworkConfigurationByChainId = {\n type: `NetworkController:getNetworkConfigurationByChainId`;\n handler: NetworkController['getNetworkConfigurationByChainId'];\n};\n\nexport type NetworkControllerGetNetworkConfigurationByNetworkClientId = {\n type: `NetworkController:getNetworkConfigurationByNetworkClientId`;\n handler: NetworkController['getNetworkConfigurationByNetworkClientId'];\n};\n\nexport type NetworkControllerAddNetworkAction = {\n type: 'NetworkController:addNetwork';\n handler: NetworkController['addNetwork'];\n};\n\nexport type NetworkControllerRemoveNetworkAction = {\n type: 'NetworkController:removeNetwork';\n handler: NetworkController['removeNetwork'];\n};\n\nexport type NetworkControllerUpdateNetworkAction = {\n type: 'NetworkController:updateNetwork';\n handler: NetworkController['updateNetwork'];\n};\n\nexport type NetworkControllerActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetEthQueryAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetSelectedNetworkClientAction\n | NetworkControllerGetSelectedChainIdAction\n | NetworkControllerGetEIP1559CompatibilityAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerSetActiveNetworkAction\n | NetworkControllerSetProviderTypeAction\n | NetworkControllerGetNetworkConfigurationByChainId\n | NetworkControllerGetNetworkConfigurationByNetworkClientId\n | NetworkControllerAddNetworkAction\n | NetworkControllerRemoveNetworkAction\n | NetworkControllerUpdateNetworkAction;\n\n/**\n * All actions that {@link NetworkController} calls internally.\n */\ntype AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n\nexport type NetworkControllerMessenger = Messenger<\n typeof controllerName,\n NetworkControllerActions | AllowedActions,\n NetworkControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for the NetworkController constructor.\n */\nexport type NetworkControllerOptions = {\n /**\n * The messenger suited for this controller.\n */\n messenger: NetworkControllerMessenger;\n /**\n * The API key for Infura, used to make requests to Infura.\n */\n infuraProjectId: string;\n /**\n * The desired state with which to initialize this controller.\n * Missing properties will be filled in with defaults. For instance, if not\n * specified, `networkConfigurationsByChainId` will default to a basic set of\n * network configurations (see {@link InfuraNetworkType} for the list).\n */\n state?: Partial<NetworkState>;\n /**\n * A `loglevel` logger object.\n */\n log?: Logger;\n /**\n * A function that can be used to customize a RPC service constructed for an\n * RPC endpoint. The function takes the URL of the endpoint and should return\n * an object with type {@link RpcServiceOptions}, minus `failoverService`\n * and `endpointUrl` (as they are filled in automatically).\n */\n getRpcServiceOptions: (\n rpcEndpointUrl: string,\n ) => Omit<RpcServiceOptions, 'failoverService' | 'endpointUrl'>;\n /**\n * A function that can be used to customize a block tracker constructed for an\n * RPC endpoint. The function takes the URL of the endpoint and should return\n * an object of type {@link PollingBlockTrackerOptions}, minus `provider` (as\n * it is filled in automatically).\n */\n getBlockTrackerOptions?: (\n rpcEndpointUrl: string,\n ) => Omit<PollingBlockTrackerOptions, 'provider'>;\n /**\n * An array of Hex Chain IDs representing the additional networks to be included as default.\n */\n additionalDefaultNetworks?: AdditionalDefaultNetwork[];\n /**\n * Whether or not requests sent to unavailable RPC endpoints should be\n * automatically diverted to configured failover RPC endpoints.\n */\n isRpcFailoverEnabled?: boolean;\n};\n\n/**\n * Constructs a value for the state property `networkConfigurationsByChainId`\n * which will be used if it has not been provided to the constructor.\n *\n * @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.\n * @returns The default value for `networkConfigurationsByChainId`.\n */\nfunction getDefaultNetworkConfigurationsByChainId(\n additionalDefaultNetworks: AdditionalDefaultNetwork[] = [],\n): Record<Hex, NetworkConfiguration> {\n const infuraNetworks = getDefaultInfuraNetworkConfigurationsByChainId();\n const customNetworks = getDefaultCustomNetworkConfigurationsByChainId();\n\n return additionalDefaultNetworks.reduce<Record<Hex, NetworkConfiguration>>(\n (obj, chainId) => {\n if (hasProperty(customNetworks, chainId)) {\n obj[chainId] = customNetworks[chainId];\n }\n return obj;\n },\n // Always include the infura networks in the default networks\n infuraNetworks,\n );\n}\n\n/**\n * Constructs a `networkConfigurationsByChainId` object for all default Infura networks.\n *\n * @returns The `networkConfigurationsByChainId` object of all Infura networks.\n */\nfunction getDefaultInfuraNetworkConfigurationsByChainId(): Record<\n Hex,\n NetworkConfiguration\n> {\n return Object.values(InfuraNetworkType).reduce<\n Record<Hex, NetworkConfiguration>\n >((obj, infuraNetworkType) => {\n const chainId = ChainId[infuraNetworkType];\n\n // Skip deprecated network as default network.\n if (DEPRECATED_NETWORKS.has(chainId)) {\n return obj;\n }\n\n const rpcEndpointUrl =\n `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const;\n\n const networkConfiguration: NetworkConfiguration = {\n blockExplorerUrls: [],\n chainId,\n defaultRpcEndpointIndex: 0,\n name: NetworkNickname[infuraNetworkType],\n nativeCurrency: NetworksTicker[infuraNetworkType],\n rpcEndpoints: [\n {\n failoverUrls: [],\n networkClientId: infuraNetworkType,\n type: RpcEndpointType.Infura,\n url: rpcEndpointUrl,\n },\n ],\n };\n\n return { ...obj, [chainId]: networkConfiguration };\n }, {});\n}\n\n/**\n * Constructs a `networkConfigurationsByChainId` object for all default custom networks.\n *\n * @returns The `networkConfigurationsByChainId` object of all custom networks.\n */\nfunction getDefaultCustomNetworkConfigurationsByChainId(): Record<\n Hex,\n NetworkConfiguration\n> {\n // Create the `networkConfigurationsByChainId` objects explicitly,\n // Because it is not always guaranteed that the custom networks are included in the\n // default networks.\n return {\n [ChainId['megaeth-testnet']]: getCustomNetworkConfiguration(\n CustomNetworkType['megaeth-testnet'],\n ),\n [ChainId['monad-testnet']]: getCustomNetworkConfiguration(\n CustomNetworkType['monad-testnet'],\n ),\n };\n}\n\n/**\n * Constructs a `NetworkConfiguration` object by `CustomNetworkType`.\n *\n * @param customNetworkType - The type of the custom network.\n * @returns The `NetworkConfiguration` object.\n */\nfunction getCustomNetworkConfiguration(\n customNetworkType: CustomNetworkType,\n): NetworkConfiguration {\n const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType];\n const rpcEndpointUrl = BUILT_IN_CUSTOM_NETWORKS_RPC[customNetworkType];\n\n return {\n blockExplorerUrls: [rpcPrefs.blockExplorerUrl],\n chainId: ChainId[customNetworkType],\n defaultRpcEndpointIndex: 0,\n defaultBlockExplorerUrlIndex: 0,\n name: NetworkNickname[customNetworkType],\n nativeCurrency: ticker,\n rpcEndpoints: [\n {\n failoverUrls: [],\n networkClientId: customNetworkType,\n type: RpcEndpointType.Custom,\n url: rpcEndpointUrl,\n },\n ],\n };\n}\n\n/**\n * Constructs properties for the NetworkController state whose values will be\n * used if not provided to the constructor.\n *\n * @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.\n * @returns The default NetworkController state.\n */\nexport function getDefaultNetworkControllerState(\n additionalDefaultNetworks?: AdditionalDefaultNetwork[],\n): NetworkState {\n const networksMetadata = {};\n const networkConfigurationsByChainId =\n getDefaultNetworkConfigurationsByChainId(additionalDefaultNetworks);\n\n return {\n selectedNetworkClientId: InfuraNetworkType.mainnet,\n networksMetadata,\n networkConfigurationsByChainId,\n };\n}\n\n/**\n * Redux selector for getting all network configurations from NetworkController\n * state, keyed by chain ID.\n *\n * @param state - NetworkController state\n * @returns All registered network configurations, keyed by chain ID.\n */\nconst selectNetworkConfigurationsByChainId = (state: NetworkState) =>\n state.networkConfigurationsByChainId;\n\n/**\n * Get a list of all network configurations.\n *\n * @param state - NetworkController state\n * @returns A list of all available network configurations\n */\nexport function getNetworkConfigurations(\n state: NetworkState,\n): NetworkConfiguration[] {\n return Object.values(state.networkConfigurationsByChainId);\n}\n\n/**\n * Redux selector for getting a list of all network configurations from\n * NetworkController state.\n *\n * @param state - NetworkController state\n * @returns A list of all available network configurations\n */\nexport const selectNetworkConfigurations = createSelector(\n selectNetworkConfigurationsByChainId,\n (networkConfigurationsByChainId) =>\n Object.values(networkConfigurationsByChainId),\n);\n\n/**\n * Get a list of all available network client IDs from a list of network\n * configurations.\n *\n * @param networkConfigurations - The array of network configurations\n * @returns A list of all available client IDs\n */\nexport function getAvailableNetworkClientIds(\n networkConfigurations: NetworkConfiguration[],\n): string[] {\n return networkConfigurations.flatMap((networkConfiguration) =>\n networkConfiguration.rpcEndpoints.map(\n (rpcEndpoint) => rpcEndpoint.networkClientId,\n ),\n );\n}\n\n/**\n * Redux selector for getting a list of all available network client IDs\n * from NetworkController state.\n *\n * @param state - NetworkController state\n * @returns A list of all available network client IDs.\n */\nexport const selectAvailableNetworkClientIds = createSelector(\n selectNetworkConfigurations,\n getAvailableNetworkClientIds,\n);\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\nexport type AutoManagedBuiltInNetworkClientRegistry = Record<\n BuiltInNetworkClientId,\n AutoManagedNetworkClient<InfuraNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\nexport type AutoManagedCustomNetworkClientRegistry = Record<\n CustomNetworkClientId,\n AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks\n * as well as custom networks that users have added.\n */\nexport type AutoManagedNetworkClientRegistry = {\n [NetworkClientType.Infura]: AutoManagedBuiltInNetworkClientRegistry;\n [NetworkClientType.Custom]: AutoManagedCustomNetworkClientRegistry;\n};\n\n/**\n * Instructs `addNetwork` and `updateNetwork` to create a network client for an\n * RPC endpoint.\n *\n * @see {@link NetworkClientOperation}\n */\ntype AddNetworkClientOperation = {\n type: 'add';\n rpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `updateNetwork` and `removeNetwork` to remove a network client for\n * an RPC endpoint.\n *\n * @see {@link NetworkClientOperation}\n */\ntype RemoveNetworkClientOperation = {\n type: 'remove';\n rpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `addNetwork` and `updateNetwork` to replace the network client for\n * an RPC endpoint.\n *\n * @see {@link NetworkClientOperation}\n */\ntype ReplaceNetworkClientOperation = {\n type: 'replace';\n oldRpcEndpoint: RpcEndpoint;\n newRpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `addNetwork` and `updateNetwork` not to do anything with an RPC\n * endpoint, as far as the network client registry is concerned.\n *\n * @see {@link NetworkClientOperation}\n */\ntype NoopNetworkClientOperation = {\n type: 'noop';\n rpcEndpoint: RpcEndpoint;\n};\n\n/**\n * Instructs `addNetwork`, `updateNetwork`, and `removeNetwork` how to\n * update the network client registry.\n *\n * - When `addNetwork` is called, represents a network client that should be\n * created for a new RPC endpoint.\n * - When `removeNetwork` is called, represents a network client that should be\n * destroyed for a previously existing RPC endpoint.\n * - When `updateNetwork` is called, represents either:\n * - a network client that should be added for a new RPC endpoint\n * - a network client that should be removed for a previously existing RPC\n * endpoint\n * - a network client that should be replaced for an RPC endpoint that was\n * changed in a non-major way, or\n * - a network client that should be unchanged for an RPC endpoint that was\n * also unchanged.\n */\ntype NetworkClientOperation =\n | AddNetworkClientOperation\n | RemoveNetworkClientOperation\n | ReplaceNetworkClientOperation\n | NoopNetworkClientOperation;\n\n/**\n * Determines whether the given URL is valid by attempting to parse it.\n *\n * @param url - The URL to test.\n * @returns True if the URL is valid, false otherwise.\n */\nfunction isValidUrl(url: string) {\n const uri = URI.parse(url);\n return (\n uri.error === undefined && (uri.scheme === 'http' || uri.scheme === 'https')\n );\n}\n\n/**\n * Given an Infura API URL, extracts the subdomain that identifies the Infura\n * network.\n *\n * @param rpcEndpointUrl - The URL to operate on.\n * @returns The Infura network name that the URL references.\n * @throws if the URL is not an Infura API URL, or if an Infura network is not\n * present in the URL.\n */\nfunction deriveInfuraNetworkNameFromRpcEndpointUrl(\n rpcEndpointUrl: string,\n): InfuraNetworkType {\n const match = INFURA_URL_REGEX.exec(rpcEndpointUrl);\n\n if (match?.groups) {\n if (isInfuraNetworkType(match.groups.networkName)) {\n return match.groups.networkName;\n }\n\n throw new Error(`Unknown Infura network '${match.groups.networkName}'`);\n }\n\n throw new Error('Could not derive Infura network from RPC endpoint URL');\n}\n\n/**\n * Performs a series of checks that the given NetworkController state is\n * internally consistent — that all parts of state that are supposed to match in\n * fact do — so that working with the state later on doesn't cause unexpected\n * errors.\n *\n * In the case of NetworkController, there are several parts of state that need\n * to match. For instance, `defaultRpcEndpointIndex` needs to match an entry\n * within `rpcEndpoints`, and `selectedNetworkClientId` needs to point to an RPC\n * endpoint within a network configuration.\n *\n * @param state - The NetworkController state to verify.\n * @throws if the state is invalid in some way.\n */\nfunction validateInitialState(state: NetworkState) {\n const networkConfigurationEntries = Object.entries(\n state.networkConfigurationsByChainId,\n );\n const networkClientIds = getAvailableNetworkClientIds(\n getNetworkConfigurations(state),\n );\n\n if (networkConfigurationEntries.length === 0) {\n throw new Error(\n 'NetworkController state is invalid: `networkConfigurationsByChainId` cannot be empty',\n );\n }\n\n for (const [chainId, networkConfiguration] of networkConfigurationEntries) {\n if (chainId !== networkConfiguration.chainId) {\n throw new Error(\n `NetworkController state has invalid \\`networkConfigurationsByChainId\\`: Network configuration '${networkConfiguration.name}' is filed under '${chainId}' which does not match its \\`chainId\\` of '${networkConfiguration.chainId}'`,\n );\n }\n\n const isInvalidDefaultBlockExplorerUrlIndex =\n networkConfiguration.blockExplorerUrls.length > 0\n ? networkConfiguration.defaultBlockExplorerUrlIndex === undefined ||\n networkConfiguration.blockExplorerUrls[\n networkConfiguration.defaultBlockExplorerUrlIndex\n ] === undefined\n : networkConfiguration.defaultBlockExplorerUrlIndex !== undefined;\n\n if (isInvalidDefaultBlockExplorerUrlIndex) {\n throw new Error(\n `NetworkController state has invalid \\`networkConfigurationsByChainId\\`: Network configuration '${networkConfiguration.name}' has a \\`defaultBlockExplorerUrlIndex\\` that does not refer to an entry in \\`blockExplorerUrls\\``,\n );\n }\n\n if (\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ] === undefined\n ) {\n throw new Error(\n `NetworkController state has invalid \\`networkConfigurationsByChainId\\`: Network configuration '${networkConfiguration.name}' has a \\`defaultRpcEndpointIndex\\` that does not refer to an entry in \\`rpcEndpoints\\``,\n );\n }\n }\n\n if ([...new Set(networkClientIds)].length < networkClientIds.length) {\n throw new Error(\n 'NetworkController state has invalid `networkConfigurationsByChainId`: Every RPC endpoint across all network configurations must have a unique `networkClientId`',\n );\n }\n}\n\n/**\n * Checks that the given initial NetworkController state is internally\n * consistent similar to `validateInitialState`, but if an anomaly is detected,\n * it does its best to correct the state and logs an error to Sentry.\n *\n * @param state - The NetworkController state to verify.\n * @param messenger - The NetworkController messenger.\n * @returns The corrected state.\n */\nfunction correctInitialState(\n state: NetworkState,\n messenger: NetworkControllerMessenger,\n): NetworkState {\n const networkConfigurationsSortedByChainId = getNetworkConfigurations(\n state,\n ).sort((a, b) => a.chainId.localeCompare(b.chainId));\n const availableNetworkClientIds = getAvailableNetworkClientIds(\n networkConfigurationsSortedByChainId,\n );\n const invalidNetworkClientIdsWithMetadata = Object.keys(\n state.networksMetadata,\n ).filter(\n (networkClientId) => !availableNetworkClientIds.includes(networkClientId),\n );\n\n return produce(state, (newState) => {\n if (!availableNetworkClientIds.includes(state.selectedNetworkClientId)) {\n const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];\n const newSelectedNetworkClientId =\n firstNetworkConfiguration.rpcEndpoints[\n firstNetworkConfiguration.defaultRpcEndpointIndex\n ].networkClientId;\n messenger.call(\n 'ErrorReportingService:captureException',\n new Error(\n `\\`selectedNetworkClientId\\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`,\n ),\n );\n newState.selectedNetworkClientId = newSelectedNetworkClientId;\n }\n\n if (invalidNetworkClientIdsWithMetadata.length > 0) {\n for (const invalidNetworkClientId of invalidNetworkClientIdsWithMetadata) {\n delete newState.networksMetadata[invalidNetworkClientId];\n }\n messenger.call(\n 'ErrorReportingService:captureException',\n new Error(\n '`networksMetadata` had invalid network client IDs, which have been removed',\n ),\n );\n }\n });\n}\n\n/**\n * Transforms a map of chain ID to network configuration to a map of network\n * client ID to network configuration.\n *\n * @param networkConfigurationsByChainId - The network configurations, keyed by\n * chain ID.\n * @returns The network configurations, keyed by network client ID.\n */\nfunction buildNetworkConfigurationsByNetworkClientId(\n networkConfigurationsByChainId: Record<Hex, NetworkConfiguration>,\n): Map<NetworkClientId, NetworkConfiguration> {\n return new Map(\n Object.values(networkConfigurationsByChainId).flatMap(\n (networkConfiguration) => {\n return networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {\n return [rpcEndpoint.networkClientId, networkConfiguration];\n });\n },\n ),\n );\n}\n\n/**\n * Controller that creates and manages an Ethereum network provider.\n */\nexport class NetworkController extends BaseController<\n typeof controllerName,\n NetworkState,\n NetworkControllerMessenger\n> {\n #ethQuery?: EthQuery;\n\n readonly #infuraProjectId: string;\n\n #previouslySelectedNetworkClientId: string;\n\n #providerProxy: ProviderProxy | undefined;\n\n #blockTrackerProxy: BlockTrackerProxy | undefined;\n\n #autoManagedNetworkClientRegistry?: AutoManagedNetworkClientRegistry;\n\n #autoManagedNetworkClient?:\n | AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n | AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n readonly #log: Logger | undefined;\n\n readonly #getRpcServiceOptions: NetworkControllerOptions['getRpcServiceOptions'];\n\n readonly #getBlockTrackerOptions: NetworkControllerOptions['getBlockTrackerOptions'];\n\n #networkConfigurationsByNetworkClientId: Map<\n NetworkClientId,\n NetworkConfiguration\n >;\n\n #isRpcFailoverEnabled: Exclude<\n NetworkControllerOptions['isRpcFailoverEnabled'],\n undefined\n >;\n\n /**\n * Constructs a NetworkController.\n *\n * @param options - The options; see {@link NetworkControllerOptions}.\n */\n constructor(options: NetworkControllerOptions) {\n const {\n messenger,\n state,\n infuraProjectId,\n log,\n getRpcServiceOptions,\n getBlockTrackerOptions,\n additionalDefaultNetworks,\n isRpcFailoverEnabled = false,\n } = options;\n const initialState = {\n ...getDefaultNetworkControllerState(additionalDefaultNetworks),\n ...state,\n };\n validateInitialState(initialState);\n const correctedInitialState = correctInitialState(initialState, messenger);\n\n if (!infuraProjectId || typeof infuraProjectId !== 'string') {\n throw new Error('Invalid Infura project ID');\n }\n\n super({\n name: controllerName,\n metadata: {\n selectedNetworkClientId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n networksMetadata: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n networkConfigurationsByChainId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n },\n messenger,\n state: correctedInitialState,\n });\n\n this.#infuraProjectId = infuraProjectId;\n this.#log = log;\n this.#getRpcServiceOptions = getRpcServiceOptions;\n this.#getBlockTrackerOptions = getBlockTrackerOptions;\n this.#isRpcFailoverEnabled = isRpcFailoverEnabled;\n\n this.#previouslySelectedNetworkClientId =\n this.state.selectedNetworkClientId;\n this.#networkConfigurationsByNetworkClientId =\n buildNetworkConfigurationsByNetworkClientId(\n this.state.networkConfigurationsByChainId,\n );\n\n this.messenger.registerActionHandler(`${this.name}:getEthQuery`, () => {\n return this.#ethQuery;\n });\n\n this.messenger.registerActionHandler(\n `${this.name}:getNetworkClientById`,\n this.getNetworkClientById.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getEIP1559Compatibility`,\n this.getEIP1559Compatibility.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:setActiveNetwork`,\n this.setActiveNetwork.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:setProviderType`,\n this.setProviderType.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:findNetworkClientIdByChainId`,\n this.findNetworkClientIdByChainId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getNetworkConfigurationByChainId`,\n this.getNetworkConfigurationByChainId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getNetworkConfigurationByNetworkClientId`,\n this.getNetworkConfigurationByNetworkClientId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getSelectedNetworkClient`,\n this.getSelectedNetworkClient.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:getSelectedChainId`,\n this.getSelectedChainId.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:addNetwork`,\n this.addNetwork.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:removeNetwork`,\n this.removeNetwork.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${this.name}:updateNetwork`,\n this.updateNetwork.bind(this),\n );\n\n this.messenger.subscribe(\n `${this.name}:rpcEndpointChainUnavailable`,\n ({ networkClientId }) => {\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus: NetworkStatus.Unavailable,\n });\n },\n );\n this.messenger.subscribe(\n `${this.name}:rpcEndpointChainDegraded`,\n ({ networkClientId }) => {\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus: NetworkStatus.Degraded,\n });\n },\n );\n this.messenger.subscribe(\n `${this.name}:rpcEndpointChainAvailable`,\n ({ networkClientId }) => {\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus: NetworkStatus.Available,\n });\n },\n );\n }\n\n /**\n * Enables the RPC failover functionality. That is, if any RPC endpoints are\n * configured with failover URLs, then traffic will automatically be diverted\n * to them if those RPC endpoints are unavailable.\n */\n enableRpcFailover() {\n this.#updateRpcFailoverEnabled(true);\n }\n\n /**\n * Disables the RPC failover functionality. That is, even if any RPC endpoints\n * are configured with failover URLs, then traffic will not automatically be\n * diverted to them if those RPC endpoints are unavailable.\n */\n disableRpcFailover() {\n this.#updateRpcFailoverEnabled(false);\n }\n\n /**\n * Enables or disables the RPC failover functionality, depending on the\n * boolean given. This is done by reconstructing all network clients that were\n * originally configured with failover URLs so that those URLs are either\n * honored or ignored. Network client IDs will be preserved so as not to\n * invalidate state in other controllers.\n *\n * @param newIsRpcFailoverEnabled - Whether or not to enable or disable the\n * RPC failover functionality.\n */\n #updateRpcFailoverEnabled(newIsRpcFailoverEnabled: boolean) {\n if (this.#isRpcFailoverEnabled === newIsRpcFailoverEnabled) {\n return;\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n for (const networkClientsById of Object.values(\n autoManagedNetworkClientRegistry,\n )) {\n for (const networkClientId of Object.keys(networkClientsById)) {\n // Type assertion: We can assume that `networkClientId` is valid here.\n const networkClient =\n networkClientsById[\n networkClientId as keyof typeof networkClientsById\n ];\n if (\n networkClient.configuration.failoverRpcUrls &&\n networkClient.configuration.failoverRpcUrls.length > 0\n ) {\n newIsRpcFailoverEnabled\n ? networkClient.enableRpcFailover()\n : networkClient.disableRpcFailover();\n }\n }\n }\n\n this.#isRpcFailoverEnabled = newIsRpcFailoverEnabled;\n }\n\n /**\n * Accesses the provider and block tracker for the currently selected network.\n *\n * @returns The proxy and block tracker proxies.\n * @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.\n */\n getProviderAndBlockTracker(): {\n provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>> | undefined;\n blockTracker:\n | SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>\n | undefined;\n } {\n return {\n provider: this.#providerProxy,\n blockTracker: this.#blockTrackerProxy,\n };\n }\n\n /**\n * Accesses the provider and block tracker for the currently selected network.\n *\n * @returns an object with the provider and block tracker proxies for the currently selected network.\n */\n getSelectedNetworkClient():\n | {\n provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>>;\n blockTracker: SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>;\n }\n | undefined {\n if (this.#providerProxy && this.#blockTrackerProxy) {\n return {\n provider: this.#providerProxy,\n blockTracker: this.#blockTrackerProxy,\n };\n }\n return undefined;\n }\n\n /**\n * Accesses the chain ID from the selected network client.\n *\n * @returns The chain ID of the selected network client in hex format or undefined if there is no network client.\n */\n getSelectedChainId(): Hex | undefined {\n const networkConfiguration = this.getNetworkConfigurationByNetworkClientId(\n this.state.selectedNetworkClientId,\n );\n return networkConfiguration?.chainId;\n }\n\n /**\n * Internally, the Infura and custom network clients are categorized by type\n * so that when accessing either kind of network client, TypeScript knows\n * which type to assign to the network client. For some cases it's more useful\n * to be able to access network clients by ID instead of by type and then ID,\n * so this function makes that possible.\n *\n * @returns The network clients registered so far, keyed by ID.\n */\n getNetworkClientRegistry(): AutoManagedBuiltInNetworkClientRegistry &\n AutoManagedCustomNetworkClientRegistry {\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n return Object.assign(\n {},\n autoManagedNetworkClientRegistry[NetworkClientType.Infura],\n autoManagedNetworkClientRegistry[NetworkClientType.Custom],\n );\n }\n\n /**\n * Returns the Infura network client with the given ID.\n *\n * @param infuraNetworkClientId - An Infura network client ID.\n * @returns The Infura network client.\n * @throws If an Infura network client does not exist with the given ID.\n */\n getNetworkClientById(\n infuraNetworkClientId: BuiltInNetworkClientId,\n ): AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n /**\n * Returns the custom network client with the given ID.\n *\n * @param customNetworkClientId - A custom network client ID.\n * @returns The custom network client.\n * @throws If a custom network client does not exist with the given ID.\n */\n getNetworkClientById(\n customNetworkClientId: CustomNetworkClientId,\n ): AutoManagedNetworkClient<CustomNetworkClientConfiguration>;\n\n getNetworkClientById(\n networkClientId: NetworkClientId,\n ): AutoManagedNetworkClient<NetworkClientConfiguration> {\n if (!networkClientId) {\n throw new Error('No network client ID was provided.');\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n if (isInfuraNetworkType(networkClientId)) {\n const infuraNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n networkClientId\n ];\n // This is impossible to reach\n /* istanbul ignore if */\n if (!infuraNetworkClient) {\n throw new Error(\n `No Infura network client was found with the ID \"${networkClientId}\".`,\n );\n }\n return infuraNetworkClient;\n }\n\n const customNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n networkClientId\n ];\n if (!customNetworkClient) {\n throw new Error(\n `No custom network client was found with the ID \"${networkClientId}\".`,\n );\n }\n return customNetworkClient;\n }\n\n /**\n * Executes a series of steps to switch the network:\n *\n * 1. Notifies subscribers via the messenger that the network is about to be\n * switched (and, really, that the global provider and block tracker proxies\n * will be re-pointed to a new network).\n * 2. Looks up a known and preinitialized network client matching the given\n * ID and uses it to re-point the aforementioned provider and block tracker\n * proxies.\n * 3. Notifies subscribers via the messenger that the network has switched.\n * 4. Captures metadata for the newly switched network in state.\n *\n * @param networkClientId - The ID of a network client that requests will be\n * routed through (either the name of an Infura network or the ID of a custom\n * network configuration).\n * @param options - Options for this method.\n * @param options.updateState - Allows for updating state.\n */\n async #refreshNetwork(\n networkClientId: string,\n options: {\n updateState?: (state: Draft<NetworkState>) => void;\n } = {},\n ) {\n this.messenger.publish('NetworkController:networkWillChange', this.state);\n this.#applyNetworkSelection(networkClientId, options);\n this.messenger.publish('NetworkController:networkDidChange', this.state);\n await this.lookupNetwork();\n }\n\n /**\n * Creates proxies for accessing the global network client and its block\n * tracker. You must call this method in order to use\n * `getProviderAndBlockTracker` (or its replacement,\n * `getSelectedNetworkClient`).\n *\n * @param options - Optional arguments.\n * @param options.lookupNetwork - Usually, metadata for the global network\n * will be populated via a call to `lookupNetwork` after creating the provider\n * and block tracker proxies. This allows for responding to the status of the\n * global network after initializing this controller; however, it requires\n * making a request to the network to do so. In the clients, where controllers\n * are initialized before the UI is shown, this may be undesirable, as it\n * means that if the user has just installed MetaMask, their IP address may be\n * shared with a third party before they have a chance to finish onboarding.\n * You can pass `false` if you'd like to disable this request and call\n * `lookupNetwork` yourself.\n */\n initializeProvider(options: { lookupNetwork: false }): void;\n\n /**\n * Creates proxies for accessing the global network client and its block\n * tracker. You must call this method in order to use\n * `getProviderAndBlockTracker` (or its replacement,\n * `getSelectedNetworkClient`).\n *\n * @param options - Optional arguments.\n * @param options.lookupNetwork - Usually, metadata for the global network\n * will be populated via a call to `lookupNetwork` after creating the provider\n * and block tracker proxies. This allows for responding to the status of the\n * global network after initializing this controller; however, it requires\n * making a request to the network to do so. In the clients, where controllers\n * are initialized before the UI is shown, this may be undesirable, as it\n * means that if the user has just installed MetaMask, their IP address may be\n * shared with a third party before they have a chance to finish onboarding.\n * You can pass `false` if you'd like to disable this request and call\n * `lookupNetwork` yourself.\n * @returns A promise that resolves when the network lookup completes.\n */\n initializeProvider(options?: { lookupNetwork?: boolean }): Promise<void>;\n\n initializeProvider({\n lookupNetwork = true,\n }: {\n lookupNetwork?: boolean;\n } = {}) {\n this.#applyNetworkSelection(this.state.selectedNetworkClientId);\n\n if (lookupNetwork) {\n return this.lookupNetwork();\n }\n\n return undefined;\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given network:\n *\n * - The connectivity status: whether it is available, geo-blocked (Infura\n * only), unavailable, or unknown\n * - The capabilities status: whether it supports EIP-1559, whether it does\n * not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n * If no ID is provided, uses the currently selected network.\n * @returns The resulting metadata for the network.\n */\n async #determineNetworkMetadata(networkClientId: NetworkClientId) {\n // Force TypeScript to use one of the two overloads explicitly\n const networkClient = isInfuraNetworkType(networkClientId)\n ? this.getNetworkClientById(networkClientId)\n : this.getNetworkClientById(networkClientId);\n\n const isInfura =\n networkClient.configuration.type === NetworkClientType.Infura;\n let networkStatus: NetworkStatus;\n let isEIP1559Compatible: boolean | undefined;\n\n try {\n isEIP1559Compatible =\n await this.#determineEIP1559Compatibility(networkClientId);\n networkStatus = NetworkStatus.Available;\n } catch (error) {\n debugLog('NetworkController: lookupNetwork: ', error);\n\n if (isErrorWithCode(error)) {\n let responseBody;\n if (\n isInfura &&\n hasProperty(error, 'message') &&\n typeof error.message === 'string'\n ) {\n try {\n responseBody = JSON.parse(error.message);\n } catch {\n // error.message must not be JSON\n this.#log?.warn(\n 'NetworkController: lookupNetwork: json parse error: ',\n error,\n );\n }\n }\n\n if (\n isPlainObject(responseBody) &&\n responseBody.error === INFURA_BLOCKED_KEY\n ) {\n networkStatus = NetworkStatus.Blocked;\n } else if (error.code === errorCodes.rpc.internal) {\n networkStatus = NetworkStatus.Unknown;\n this.#log?.warn(\n 'NetworkController: lookupNetwork: rpc internal error: ',\n error,\n );\n } else {\n networkStatus = NetworkStatus.Unavailable;\n this.#log?.warn('NetworkController: lookupNetwork: ', error);\n }\n } else {\n debugLog(\n 'NetworkController - could not determine network status',\n error,\n );\n networkStatus = NetworkStatus.Unknown;\n this.#log?.warn('NetworkController: lookupNetwork: ', error);\n }\n }\n\n return { isInfura, networkStatus, isEIP1559Compatible };\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given or selected network, persisting it to state:\n *\n * - The connectivity status: whether it is available, geo-blocked (Infura\n * only), unavailable, or unknown\n * - The capabilities status: whether it supports EIP-1559, whether it does\n * not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n * If no ID is provided, uses the currently selected network.\n */\n async lookupNetwork(networkClientId?: NetworkClientId) {\n if (networkClientId) {\n await this.#lookupGivenNetwork(networkClientId);\n } else {\n await this.#lookupSelectedNetwork();\n }\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given network, persisting it to state:\n *\n * - The connectivity status: whether the network is available, geo-blocked\n * (Infura only), unavailable, or unknown\n * - The feature compatibility status: whether the network supports EIP-1559,\n * whether it does not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n * @deprecated Please use `lookupNetwork` and pass a network client ID\n * instead. This method will be removed in a future major version.\n */\n // We are planning on removing this so we aren't interested in testing this\n // right now.\n /* istanbul ignore next */\n async lookupNetworkByClientId(networkClientId: NetworkClientId) {\n await this.#lookupGivenNetwork(networkClientId);\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the given network, persisting it to state:\n *\n * - The connectivity status: whether the network is available, geo-blocked\n * (Infura only), unavailable, or unknown\n * - The feature compatibility status: whether the network supports EIP-1559,\n * whether it does not, or whether it is unknown\n *\n * @param networkClientId - The ID of the network client to inspect.\n */\n async #lookupGivenNetwork(networkClientId: NetworkClientId) {\n const { networkStatus, isEIP1559Compatible } =\n await this.#determineNetworkMetadata(networkClientId);\n\n this.#updateMetadataForNetwork(networkClientId, {\n networkStatus,\n isEIP1559Compatible,\n });\n }\n\n /**\n * Uses a request for the latest block to gather the following information on\n * the currently selected network, persisting it to state:\n *\n * - The connectivity status: whether the network is available, geo-blocked\n * (Infura only), unavailable, or unknown\n * - The feature compatibility status: whether the network supports EIP-1559,\n * whether it does not, or whether it is unknown\n *\n * Note that it is possible for the current network to be switched while this\n * method is running. If that is the case, it will exit early (as this method\n * will also run for the new network).\n */\n async #lookupSelectedNetwork() {\n if (!this.#ethQuery) {\n return;\n }\n\n let networkChanged = false;\n const listener = () => {\n networkChanged = true;\n try {\n this.messenger.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n } catch (error) {\n // In theory, this `catch` should not be necessary given that this error\n // would occur \"inside\" of the call to `#determineEIP1559Compatibility`\n // below and so it should be caught by the `try`/`catch` below (it is\n // impossible to reproduce in tests for that reason). However, somehow\n // it occurs within Mobile and so we have to add our own `try`/`catch`\n // here.\n /* istanbul ignore next */\n if (\n !(error instanceof Error) ||\n error.message !==\n 'Subscription not found for event: NetworkController:networkDidChange'\n ) {\n // Again, this error should not happen and is impossible to reproduce\n // in tests.\n /* istanbul ignore next */\n throw error;\n }\n }\n };\n this.messenger.subscribe('NetworkController:networkDidChange', listener);\n\n const { isInfura, networkStatus, isEIP1559Compatible } =\n await this.#determineNetworkMetadata(this.state.selectedNetworkClientId);\n\n if (networkChanged) {\n // If the network has changed, then `lookupNetwork` either has been or is\n // in the process of being called, so we don't need to go further.\n return;\n }\n\n try {\n this.messenger.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n } catch (error) {\n if (\n !(error instanceof Error) ||\n error.message !==\n 'Subscription not found for event: NetworkController:networkDidChange'\n ) {\n throw error;\n }\n }\n\n this.#updateMetadataForNetwork(this.state.selectedNetworkClientId, {\n networkStatus,\n isEIP1559Compatible,\n });\n\n if (isInfura) {\n if (networkStatus === NetworkStatus.Available) {\n this.messenger.publish('NetworkController:infuraIsUnblocked');\n } else if (networkStatus === NetworkStatus.Blocked) {\n this.messenger.publish('NetworkController:infuraIsBlocked');\n }\n } else {\n // Always publish infuraIsUnblocked regardless of network status to\n // prevent consumers from being stuck in a blocked state if they were\n // previously connected to an Infura network that was blocked\n this.messenger.publish('NetworkController:infuraIsUnblocked');\n }\n }\n\n /**\n * Updates the metadata for the given network in state.\n *\n * @param networkClientId - The associated network client ID.\n * @param metadata - The metadata to store in state.\n * @param metadata.networkStatus - The network status to store in state.\n * @param metadata.isEIP1559Compatible - The EIP-1559 compatibility status to\n * store in state.\n */\n #updateMetadataForNetwork(\n networkClientId: NetworkClientId,\n metadata: {\n networkStatus: NetworkStatus;\n isEIP1559Compatible?: boolean | undefined;\n },\n ) {\n this.update((state) => {\n if (state.networksMetadata[networkClientId] === undefined) {\n state.networksMetadata[networkClientId] = {\n status: NetworkStatus.Unknown,\n EIPS: {},\n };\n }\n const newMetadata = state.networksMetadata[networkClientId];\n newMetadata.status = metadata.networkStatus;\n\n if ('isEIP1559Compatible' in metadata) {\n if (metadata.isEIP1559Compatible === undefined) {\n delete newMetadata.EIPS[1559];\n } else {\n newMetadata.EIPS[1559] = metadata.isEIP1559Compatible;\n }\n }\n });\n }\n\n /**\n * Convenience method to update provider network type settings.\n *\n * @param type - Human readable network name.\n * @deprecated This has been replaced by `setActiveNetwork`, and will be\n * removed in a future release\n */\n async setProviderType(type: InfuraNetworkType) {\n if ((type as unknown) === NetworkType.rpc) {\n throw new Error(\n `NetworkController - cannot call \"setProviderType\" with type \"${NetworkType.rpc}\". Use \"setActiveNetwork\"`,\n );\n }\n if (!isInfuraNetworkType(type)) {\n throw new Error(`Unknown Infura provider type \"${String(type)}\".`);\n }\n\n await this.setActiveNetwork(type);\n }\n\n /**\n * Changes the selected network.\n *\n * @param networkClientId - The ID of a network client that will be used to\n * make requests.\n * @param options - Options for this method.\n * @param options.updateState - Allows for updating state.\n * @throws if no network client is associated with the given\n * network client ID.\n */\n async setActiveNetwork(\n networkClientId: string,\n options: {\n updateState?: (state: Draft<NetworkState>) => void;\n } = {},\n ) {\n this.#previouslySelectedNetworkClientId =\n this.state.selectedNetworkClientId;\n\n await this.#refreshNetwork(networkClientId, options);\n }\n\n /**\n * Fetches the latest block for the network.\n *\n * @param networkClientId - The networkClientId to fetch the correct provider against which to check the latest block. Defaults to the selectedNetworkClientId.\n * @returns A promise that either resolves to the block header or null if\n * there is no latest block, or rejects with an error.\n */\n #getLatestBlock(networkClientId: NetworkClientId): Promise<Block> {\n if (networkClientId === undefined) {\n networkClientId = this.state.selectedNetworkClientId;\n }\n\n const networkClient = this.getNetworkClientById(networkClientId);\n const ethQuery = new EthQuery(networkClient.provider);\n\n return new Promise((resolve, reject) => {\n ethQuery.sendAsync(\n { method: 'eth_getBlockByNumber', params: ['latest', false] },\n (error: unknown, block?: unknown) => {\n if (error) {\n // This error comes from JsonRpcEngine, we don't control it.\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n } else {\n // TODO: Validate this type\n resolve(block as Block);\n }\n },\n );\n });\n }\n\n /**\n * Determines whether the network supports EIP-1559 by checking whether the\n * latest block has a `baseFeePerGas` property, then updates state\n * appropriately.\n *\n * @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility.\n * @returns A promise that resolves to true if the network supports EIP-1559\n * , false otherwise, or `undefined` if unable to determine the compatibility.\n */\n async getEIP1559Compatibility(networkClientId?: NetworkClientId) {\n if (networkClientId) {\n return this.get1559CompatibilityWithNetworkClientId(networkClientId);\n }\n if (!this.#ethQuery) {\n return false;\n }\n\n const { EIPS } =\n this.state.networksMetadata[this.state.selectedNetworkClientId];\n\n if (EIPS[1559] !== undefined) {\n return EIPS[1559];\n }\n\n const isEIP1559Compatible = await this.#determineEIP1559Compatibility(\n this.state.selectedNetworkClientId,\n );\n this.update((state) => {\n if (isEIP1559Compatible !== undefined) {\n state.networksMetadata[state.selectedNetworkClientId].EIPS[1559] =\n isEIP1559Compatible;\n }\n });\n return isEIP1559Compatible;\n }\n\n async get1559CompatibilityWithNetworkClientId(\n networkClientId: NetworkClientId,\n ) {\n let metadata = this.state.networksMetadata[networkClientId];\n if (metadata === undefined) {\n await this.lookupNetwork(networkClientId);\n metadata = this.state.networksMetadata[networkClientId];\n }\n const { EIPS } = metadata;\n\n // may want to include some 'freshness' value - something to make sure we refetch this from time to time\n return EIPS[1559];\n }\n\n /**\n * Retrieves and checks the latest block from the currently selected\n * network; if the block has a `baseFeePerGas` property, then we know\n * that the network supports EIP-1559; otherwise it doesn't.\n *\n * @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility\n * @returns A promise that resolves to `true` if the network supports EIP-1559,\n * `false` otherwise, or `undefined` if unable to retrieve the last block.\n */\n async #determineEIP1559Compatibility(\n networkClientId: NetworkClientId,\n ): Promise<boolean | undefined> {\n const latestBlock = await this.#getLatestBlock(networkClientId);\n\n if (!latestBlock) {\n return undefined;\n }\n\n return latestBlock.baseFeePerGas !== undefined;\n }\n\n /**\n * Ensures that the provider and block tracker proxies are pointed to the\n * currently selected network and refreshes the metadata for the\n */\n async resetConnection() {\n await this.#refreshNetwork(this.state.selectedNetworkClientId);\n }\n\n /**\n * Returns the network configuration that has been filed under the given chain\n * ID.\n *\n * @param chainId - The chain ID to use as a key.\n * @returns The network configuration if one exists, or undefined.\n */\n getNetworkConfigurationByChainId(\n chainId: Hex,\n ): NetworkConfiguration | undefined {\n return this.state.networkConfigurationsByChainId[chainId];\n }\n\n /**\n * Returns the network configuration that contains an RPC endpoint with the\n * given network client ID.\n *\n * @param networkClientId - The network client ID to use as a key.\n * @returns The network configuration if one exists, or undefined.\n */\n getNetworkConfigurationByNetworkClientId(\n networkClientId: NetworkClientId,\n ): NetworkConfiguration | undefined {\n return this.#networkConfigurationsByNetworkClientId.get(networkClientId);\n }\n\n /**\n * Creates and registers network clients for the collection of Infura and\n * custom RPC endpoints that can be used to make requests for a particular\n * chain, storing the given configuration object in state for later reference.\n *\n * @param fields - The object that describes the new network/chain and lists\n * the RPC endpoints which front that chain.\n * @returns The newly added network configuration.\n * @throws if any part of `fields` would produce invalid state.\n * @see {@link NetworkConfiguration}\n */\n addNetwork(fields: AddNetworkFields): NetworkConfiguration {\n const { rpcEndpoints: setOfRpcEndpointFields } = fields;\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.#validateNetworkFields({\n mode: 'add',\n networkFields: fields,\n autoManagedNetworkClientRegistry,\n });\n\n const networkClientOperations = setOfRpcEndpointFields.map(\n (defaultOrCustomRpcEndpointFields) => {\n const rpcEndpoint =\n defaultOrCustomRpcEndpointFields.type === RpcEndpointType.Custom\n ? {\n ...defaultOrCustomRpcEndpointFields,\n networkClientId: uuidV4(),\n }\n : defaultOrCustomRpcEndpointFields;\n return {\n type: 'add' as const,\n rpcEndpoint,\n };\n },\n );\n\n const newNetworkConfiguration =\n this.#determineNetworkConfigurationToPersist({\n networkFields: fields,\n networkClientOperations,\n });\n this.#registerNetworkClientsAsNeeded({\n networkFields: fields,\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n this.update((state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'add',\n networkFields: fields,\n networkConfigurationToPersist: newNetworkConfiguration,\n });\n });\n\n this.messenger.publish(\n `${controllerName}:networkAdded`,\n newNetworkConfiguration,\n );\n\n return newNetworkConfiguration;\n }\n\n /**\n * Updates the configuration for a previously stored network filed under the\n * given chain ID, creating + registering new network clients to represent RPC\n * endpoints that have been added and destroying + unregistering existing\n * network clients for RPC endpoints that have been removed.\n *\n * Note that if `chainId` is changed, then all network clients associated with\n * that chain will be removed and re-added, even if none of the RPC endpoints\n * have changed.\n *\n * @param chainId - The chain ID associated with an existing network.\n * @param fields - The object that describes the updates to the network/chain,\n * including the new set of RPC endpoints which should front that chain.\n * @param options - Options to provide.\n * @param options.replacementSelectedRpcEndpointIndex - Usually you cannot\n * remove an RPC endpoint that is being represented by the currently selected\n * network client. This option allows you to specify another RPC endpoint\n * (either an existing one or a new one) that should be used to select a new\n * network instead.\n * @returns The updated network configuration.\n * @throws if `chainId` does not refer to an existing network configuration,\n * if any part of `fields` would produce invalid state, etc.\n * @see {@link NetworkConfiguration}\n */\n async updateNetwork(\n chainId: Hex,\n fields: UpdateNetworkFields,\n {\n replacementSelectedRpcEndpointIndex,\n }: { replacementSelectedRpcEndpointIndex?: number } = {},\n ): Promise<NetworkConfiguration> {\n const existingNetworkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n\n if (existingNetworkConfiguration === undefined) {\n throw new Error(\n `Could not update network: Cannot find network configuration for chain '${chainId}'`,\n );\n }\n\n const existingChainId = chainId;\n const { chainId: newChainId, rpcEndpoints: setOfNewRpcEndpointFields } =\n fields;\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.#validateNetworkFields({\n mode: 'update',\n networkFields: fields,\n existingNetworkConfiguration,\n autoManagedNetworkClientRegistry,\n });\n\n const networkClientOperations: NetworkClientOperation[] = [];\n\n for (const newRpcEndpointFields of setOfNewRpcEndpointFields) {\n const existingRpcEndpointForNoop =\n existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {\n return (\n rpcEndpoint.type === newRpcEndpointFields.type &&\n rpcEndpoint.url === newRpcEndpointFields.url &&\n (rpcEndpoint.networkClientId ===\n newRpcEndpointFields.networkClientId ||\n newRpcEndpointFields.networkClientId === undefined)\n );\n });\n const existingRpcEndpointForReplaceWhenChainChanged =\n existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {\n return (\n (rpcEndpoint.type === RpcEndpointType.Infura &&\n newRpcEndpointFields.type === RpcEndpointType.Infura) ||\n (rpcEndpoint.type === newRpcEndpointFields.type &&\n rpcEndpoint.networkClientId ===\n newRpcEndpointFields.networkClientId &&\n rpcEndpoint.url === newRpcEndpointFields.url)\n );\n });\n const existingRpcEndpointForReplaceWhenChainNotChanged =\n existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {\n return (\n rpcEndpoint.type === newRpcEndpointFields.type &&\n (rpcEndpoint.url === newRpcEndpointFields.url ||\n rpcEndpoint.networkClientId ===\n newRpcEndpointFields.networkClientId)\n );\n });\n\n if (\n newChainId !== existingChainId &&\n existingRpcEndpointForReplaceWhenChainChanged !== undefined\n ) {\n const newRpcEndpoint =\n newRpcEndpointFields.type === RpcEndpointType.Infura\n ? newRpcEndpointFields\n : { ...newRpcEndpointFields, networkClientId: uuidV4() };\n\n networkClientOperations.push({\n type: 'replace' as const,\n oldRpcEndpoint: existingRpcEndpointForReplaceWhenChainChanged,\n newRpcEndpoint,\n });\n } else if (existingRpcEndpointForNoop !== undefined) {\n let newRpcEndpoint;\n if (existingRpcEndpointForNoop.type === RpcEndpointType.Infura) {\n newRpcEndpoint = existingRpcEndpointForNoop;\n } else {\n // `networkClientId` shouldn't be missing at this point; if it is,\n // that's a mistake, so fill it back in\n newRpcEndpoint = Object.assign({}, newRpcEndpointFields, {\n networkClientId: existingRpcEndpointForNoop.networkClientId,\n });\n }\n networkClientOperations.push({\n type: 'noop' as const,\n rpcEndpoint: newRpcEndpoint,\n });\n } else if (\n existingRpcEndpointForReplaceWhenChainNotChanged !== undefined\n ) {\n let newRpcEndpoint;\n /* istanbul ignore if */\n if (newRpcEndpointFields.type === RpcEndpointType.Infura) {\n // This case can't actually happen. If we're here, it means that some\n // part of the RPC endpoint changed. But there is no part of an Infura\n // RPC endpoint that can be changed (as it would immediately make that\n // RPC endpoint self-inconsistent). This is just here to appease\n // TypeScript.\n newRpcEndpoint = newRpcEndpointFields;\n } else {\n newRpcEndpoint = {\n ...newRpcEndpointFields,\n networkClientId: uuidV4(),\n };\n }\n\n networkClientOperations.push({\n type: 'replace' as const,\n oldRpcEndpoint: existingRpcEndpointForReplaceWhenChainNotChanged,\n newRpcEndpoint,\n });\n } else {\n const newRpcEndpoint =\n newRpcEndpointFields.type === RpcEndpointType.Infura\n ? newRpcEndpointFields\n : { ...newRpcEndpointFields, networkClientId: uuidV4() };\n const networkClientOperation = {\n type: 'add' as const,\n rpcEndpoint: newRpcEndpoint,\n };\n networkClientOperations.push(networkClientOperation);\n }\n }\n\n for (const existingRpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {\n if (\n !networkClientOperations.some((networkClientOperation) => {\n const otherRpcEndpoint =\n networkClientOperation.type === 'replace'\n ? networkClientOperation.oldRpcEndpoint\n : networkClientOperation.rpcEndpoint;\n return (\n otherRpcEndpoint.type === existingRpcEndpoint.type &&\n otherRpcEndpoint.networkClientId ===\n existingRpcEndpoint.networkClientId &&\n otherRpcEndpoint.url === existingRpcEndpoint.url\n );\n })\n ) {\n const networkClientOperation = {\n type: 'remove' as const,\n rpcEndpoint: existingRpcEndpoint,\n };\n networkClientOperations.push(networkClientOperation);\n }\n }\n\n const updatedNetworkConfiguration =\n this.#determineNetworkConfigurationToPersist({\n networkFields: fields,\n networkClientOperations,\n });\n\n if (\n replacementSelectedRpcEndpointIndex === undefined &&\n networkClientOperations.some((networkClientOperation) => {\n return (\n networkClientOperation.type === 'remove' &&\n networkClientOperation.rpcEndpoint.networkClientId ===\n this.state.selectedNetworkClientId\n );\n }) &&\n !networkClientOperations.some((networkClientOperation) => {\n return (\n networkClientOperation.type === 'replace' &&\n networkClientOperation.oldRpcEndpoint.networkClientId ===\n this.state.selectedNetworkClientId\n );\n })\n ) {\n throw new Error(\n `Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \\`replacementSelectedRpcEndpointIndex\\` option.`,\n );\n }\n\n this.#registerNetworkClientsAsNeeded({\n networkFields: fields,\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n\n const replacementSelectedRpcEndpointWithIndex = networkClientOperations\n .map(\n (networkClientOperation, index) =>\n [networkClientOperation, index] as const,\n )\n .find(([networkClientOperation, _index]) => {\n return (\n networkClientOperation.type === 'replace' &&\n networkClientOperation.oldRpcEndpoint.networkClientId ===\n this.state.selectedNetworkClientId\n );\n });\n const correctedReplacementSelectedRpcEndpointIndex =\n replacementSelectedRpcEndpointIndex ??\n replacementSelectedRpcEndpointWithIndex?.[1];\n\n let rpcEndpointToSelect: RpcEndpoint | undefined;\n if (correctedReplacementSelectedRpcEndpointIndex !== undefined) {\n rpcEndpointToSelect =\n updatedNetworkConfiguration.rpcEndpoints[\n correctedReplacementSelectedRpcEndpointIndex\n ];\n\n if (rpcEndpointToSelect === undefined) {\n throw new Error(\n `Could not update network: \\`replacementSelectedRpcEndpointIndex\\` ${correctedReplacementSelectedRpcEndpointIndex} does not refer to an entry in \\`rpcEndpoints\\``,\n );\n }\n }\n\n if (\n rpcEndpointToSelect &&\n rpcEndpointToSelect.networkClientId !== this.state.selectedNetworkClientId\n ) {\n await this.setActiveNetwork(rpcEndpointToSelect.networkClientId, {\n updateState: (state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'update',\n networkFields: fields,\n networkConfigurationToPersist: updatedNetworkConfiguration,\n existingNetworkConfiguration,\n });\n },\n });\n } else {\n this.update((state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'update',\n networkFields: fields,\n networkConfigurationToPersist: updatedNetworkConfiguration,\n existingNetworkConfiguration,\n });\n });\n }\n\n this.#unregisterNetworkClientsAsNeeded({\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n\n return updatedNetworkConfiguration;\n }\n\n /**\n * Destroys and unregisters the network identified by the given chain ID, also\n * removing the associated network configuration from state.\n *\n * @param chainId - The chain ID associated with an existing network.\n * @throws if `chainId` does not refer to an existing network configuration,\n * or if the currently selected network is being removed.\n * @see {@link NetworkConfiguration}\n */\n removeNetwork(chainId: Hex) {\n const existingNetworkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n\n if (existingNetworkConfiguration === undefined) {\n throw new Error(\n `Cannot find network configuration for chain '${chainId}'`,\n );\n }\n\n if (\n existingNetworkConfiguration.rpcEndpoints.some(\n (rpcEndpoint) =>\n rpcEndpoint.networkClientId === this.state.selectedNetworkClientId,\n )\n ) {\n throw new Error(`Cannot remove the currently selected network`);\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n const networkClientOperations =\n existingNetworkConfiguration.rpcEndpoints.map((rpcEndpoint) => {\n return {\n type: 'remove' as const,\n rpcEndpoint,\n };\n });\n\n this.#unregisterNetworkClientsAsNeeded({\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n });\n this.update((state) => {\n this.#updateNetworkConfigurations({\n state,\n mode: 'remove',\n existingNetworkConfiguration,\n });\n\n for (const rpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {\n delete state.networksMetadata[rpcEndpoint.networkClientId];\n }\n });\n\n this.messenger.publish(\n 'NetworkController:networkRemoved',\n existingNetworkConfiguration,\n );\n }\n\n /**\n * Assuming that the network has been previously switched, switches to this\n * new network.\n *\n * If the network has not been previously switched, this method is equivalent\n * to {@link resetConnection}.\n */\n async rollbackToPreviousProvider() {\n await this.#refreshNetwork(this.#previouslySelectedNetworkClientId);\n }\n\n /**\n * Deactivates the controller, stopping any ongoing polling.\n *\n * In-progress requests will not be aborted.\n */\n // We're intentionally changing the signature of an extended method.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async destroy() {\n await this.#blockTrackerProxy?.destroy();\n }\n\n /**\n * Merges the given backup data into controller state.\n *\n * @param backup - The data that has been backed up.\n * @param backup.networkConfigurationsByChainId - Network configurations,\n * keyed by chain ID.\n */\n loadBackup({\n networkConfigurationsByChainId,\n }: Pick<NetworkState, 'networkConfigurationsByChainId'>): void {\n this.update((state) => {\n state.networkConfigurationsByChainId = {\n ...state.networkConfigurationsByChainId,\n ...networkConfigurationsByChainId,\n };\n });\n }\n\n /**\n * Searches for the default RPC endpoint configured for the given chain and\n * returns its network client ID. This can then be passed to\n * {@link getNetworkClientById} to retrieve the network client.\n *\n * @param chainId - Chain ID to search for.\n * @returns The ID of the network client created for the chain's default RPC\n * endpoint.\n */\n findNetworkClientIdByChainId(chainId: Hex): NetworkClientId {\n const networkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n\n if (!networkConfiguration) {\n throw new Error(`Invalid chain ID \"${chainId}\"`);\n }\n\n const { networkClientId } =\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ];\n return networkClientId;\n }\n\n /**\n * Ensure that the given fields which will be used to either add or update a\n * network are valid.\n *\n * @param args - The arguments.\n */\n #validateNetworkFields(\n args: {\n autoManagedNetworkClientRegistry: AutoManagedNetworkClientRegistry;\n } & (\n | {\n mode: 'add';\n networkFields: AddNetworkFields;\n }\n | {\n mode: 'update';\n existingNetworkConfiguration: NetworkConfiguration;\n networkFields: UpdateNetworkFields;\n }\n ),\n ) {\n const { mode, networkFields, autoManagedNetworkClientRegistry } = args;\n const existingNetworkConfiguration =\n 'existingNetworkConfiguration' in args\n ? args.existingNetworkConfiguration\n : null;\n\n const errorMessagePrefix =\n mode === 'update' ? 'Could not update network' : 'Could not add network';\n\n if (\n !isStrictHexString(networkFields.chainId) ||\n !isSafeChainId(networkFields.chainId)\n ) {\n throw new Error(\n `${errorMessagePrefix}: Invalid \\`chainId\\` '${networkFields.chainId}' (must start with \"0x\" and not exceed the maximum)`,\n );\n }\n\n if (\n existingNetworkConfiguration === null ||\n networkFields.chainId !== existingNetworkConfiguration.chainId\n ) {\n const existingNetworkConfigurationViaChainId =\n this.state.networkConfigurationsByChainId[networkFields.chainId];\n if (existingNetworkConfigurationViaChainId !== undefined) {\n if (existingNetworkConfiguration === null) {\n throw new Error(\n `Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`,\n );\n } else {\n throw new Error(\n `Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`,\n );\n }\n }\n }\n\n const isInvalidDefaultBlockExplorerUrlIndex =\n networkFields.blockExplorerUrls.length > 0\n ? networkFields.defaultBlockExplorerUrlIndex === undefined ||\n networkFields.blockExplorerUrls[\n networkFields.defaultBlockExplorerUrlIndex\n ] === undefined\n : networkFields.defaultBlockExplorerUrlIndex !== undefined;\n\n if (isInvalidDefaultBlockExplorerUrlIndex) {\n throw new Error(\n `${errorMessagePrefix}: \\`defaultBlockExplorerUrlIndex\\` must refer to an entry in \\`blockExplorerUrls\\``,\n );\n }\n\n if (networkFields.rpcEndpoints.length === 0) {\n throw new Error(\n `${errorMessagePrefix}: \\`rpcEndpoints\\` must be a non-empty array`,\n );\n }\n for (const rpcEndpointFields of networkFields.rpcEndpoints) {\n if (!isValidUrl(rpcEndpointFields.url)) {\n throw new Error(\n `${errorMessagePrefix}: An entry in \\`rpcEndpoints\\` has invalid URL '${rpcEndpointFields.url}'`,\n );\n }\n const networkClientId =\n 'networkClientId' in rpcEndpointFields\n ? rpcEndpointFields.networkClientId\n : undefined;\n\n if (\n rpcEndpointFields.type === RpcEndpointType.Custom &&\n networkClientId !== undefined &&\n isInfuraNetworkType(networkClientId)\n ) {\n throw new Error(\n `${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`,\n );\n }\n\n if (\n mode === 'update' &&\n networkClientId !== undefined &&\n rpcEndpointFields.type === RpcEndpointType.Custom &&\n !Object.values(autoManagedNetworkClientRegistry).some(\n (networkClientsById) => networkClientId in networkClientsById,\n )\n ) {\n throw new Error(\n `${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`,\n );\n }\n\n if (\n networkFields.rpcEndpoints.some(\n (otherRpcEndpointFields) =>\n otherRpcEndpointFields !== rpcEndpointFields &&\n URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url),\n )\n ) {\n throw new Error(\n `${errorMessagePrefix}: Each entry in rpcEndpoints must have a unique URL`,\n );\n }\n\n const networkConfigurationsForOtherChains = Object.values(\n this.state.networkConfigurationsByChainId,\n ).filter((networkConfiguration) =>\n existingNetworkConfiguration\n ? networkConfiguration.chainId !==\n existingNetworkConfiguration.chainId\n : true,\n );\n for (const networkConfiguration of networkConfigurationsForOtherChains) {\n const rpcEndpoint = networkConfiguration.rpcEndpoints.find(\n (existingRpcEndpoint) =>\n URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url),\n );\n if (rpcEndpoint) {\n if (mode === 'update') {\n throw new Error(\n `Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`,\n );\n } else {\n throw new Error(\n `Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`,\n );\n }\n }\n }\n }\n\n if (\n [...new Set(networkFields.rpcEndpoints)].length <\n networkFields.rpcEndpoints.length\n ) {\n throw new Error(\n `${errorMessagePrefix}: Each entry in rpcEndpoints must be unique`,\n );\n }\n\n const networkClientIds = networkFields.rpcEndpoints\n .map((rpcEndpoint) =>\n 'networkClientId' in rpcEndpoint\n ? rpcEndpoint.networkClientId\n : undefined,\n )\n .filter(\n (networkClientId): networkClientId is NetworkClientId =>\n networkClientId !== undefined,\n );\n if ([...new Set(networkClientIds)].length < networkClientIds.length) {\n throw new Error(\n `${errorMessagePrefix}: Each entry in rpcEndpoints must have a unique networkClientId`,\n );\n }\n\n const infuraRpcEndpoints = networkFields.rpcEndpoints.filter(\n (rpcEndpointFields): rpcEndpointFields is InfuraRpcEndpoint =>\n rpcEndpointFields.type === RpcEndpointType.Infura,\n );\n if (infuraRpcEndpoints.length > 1) {\n throw new Error(\n `${errorMessagePrefix}: There cannot be more than one Infura RPC endpoint`,\n );\n }\n\n const soleInfuraRpcEndpoint = infuraRpcEndpoints[0];\n if (soleInfuraRpcEndpoint) {\n const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(\n soleInfuraRpcEndpoint.url,\n );\n const infuraNetworkNickname = NetworkNickname[infuraNetworkName];\n const infuraChainId = ChainId[infuraNetworkName];\n if (networkFields.chainId !== infuraChainId) {\n throw new Error(\n mode === 'add'\n ? `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`\n : `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`,\n );\n }\n }\n\n if (\n networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===\n undefined\n ) {\n throw new Error(\n `${errorMessagePrefix}: \\`defaultRpcEndpointIndex\\` must refer to an entry in \\`rpcEndpoints\\``,\n );\n }\n }\n\n /**\n * Constructs a network configuration that will be persisted to state when\n * adding or updating a network.\n *\n * @param args - The arguments to this function.\n * @param args.networkFields - The fields used to add or update a network.\n * @param args.networkClientOperations - Operations which were calculated for\n * updating the network client registry but which also map back to RPC\n * endpoints (and so can be used to save those RPC endpoints).\n * @returns The network configuration to persist.\n */\n #determineNetworkConfigurationToPersist({\n networkFields,\n networkClientOperations,\n }: {\n networkFields: AddNetworkFields | UpdateNetworkFields;\n networkClientOperations: NetworkClientOperation[];\n }): NetworkConfiguration {\n const rpcEndpointsToPersist = networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is\n | AddNetworkClientOperation\n | NoopNetworkClientOperation => {\n return (\n networkClientOperation.type === 'add' ||\n networkClientOperation.type === 'noop'\n );\n },\n )\n .map((networkClientOperation) => networkClientOperation.rpcEndpoint)\n .concat(\n networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is ReplaceNetworkClientOperation => {\n return networkClientOperation.type === 'replace';\n },\n )\n .map(\n (networkClientOperation) => networkClientOperation.newRpcEndpoint,\n ),\n );\n\n return { ...networkFields, rpcEndpoints: rpcEndpointsToPersist };\n }\n\n /**\n * Creates and registers network clients using the given operations calculated\n * as a part of adding or updating a network.\n *\n * @param args - The arguments to this function.\n * @param args.networkFields - The fields used to add or update a network.\n * @param args.networkClientOperations - Dictate which network clients need to\n * be created.\n * @param args.autoManagedNetworkClientRegistry - The network client registry\n * to update.\n */\n #registerNetworkClientsAsNeeded({\n networkFields,\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n }: {\n networkFields: AddNetworkFields | UpdateNetworkFields;\n networkClientOperations: NetworkClientOperation[];\n autoManagedNetworkClientRegistry: AutoManagedNetworkClientRegistry;\n }) {\n const addedRpcEndpoints = networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is AddNetworkClientOperation => {\n return networkClientOperation.type === 'add';\n },\n )\n .map((networkClientOperation) => networkClientOperation.rpcEndpoint)\n .concat(\n networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is ReplaceNetworkClientOperation => {\n return networkClientOperation.type === 'replace';\n },\n )\n .map(\n (networkClientOperation) => networkClientOperation.newRpcEndpoint,\n ),\n );\n\n for (const addedRpcEndpoint of addedRpcEndpoints) {\n if (addedRpcEndpoint.type === RpcEndpointType.Infura) {\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n addedRpcEndpoint.networkClientId\n ] = createAutoManagedNetworkClient({\n networkClientId: addedRpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Infura,\n chainId: networkFields.chainId,\n network: addedRpcEndpoint.networkClientId,\n failoverRpcUrls: addedRpcEndpoint.failoverUrls,\n infuraProjectId: this.#infuraProjectId,\n ticker: networkFields.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n });\n } else {\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n addedRpcEndpoint.networkClientId\n ] = createAutoManagedNetworkClient({\n networkClientId: addedRpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Custom,\n chainId: networkFields.chainId,\n failoverRpcUrls: addedRpcEndpoint.failoverUrls,\n rpcUrl: addedRpcEndpoint.url,\n ticker: networkFields.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n });\n }\n }\n }\n\n /**\n * Destroys and removes network clients using the given operations calculated\n * as a part of updating or removing a network.\n *\n * @param args - The arguments to this function.\n * @param args.networkClientOperations - Dictate which network clients to\n * remove.\n * @param args.autoManagedNetworkClientRegistry - The network client registry\n * to update.\n */\n #unregisterNetworkClientsAsNeeded({\n networkClientOperations,\n autoManagedNetworkClientRegistry,\n }: {\n networkClientOperations: NetworkClientOperation[];\n autoManagedNetworkClientRegistry: AutoManagedNetworkClientRegistry;\n }) {\n const removedRpcEndpoints = networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is RemoveNetworkClientOperation => {\n return networkClientOperation.type === 'remove';\n },\n )\n .map((networkClientOperation) => networkClientOperation.rpcEndpoint)\n .concat(\n networkClientOperations\n .filter(\n (\n networkClientOperation,\n ): networkClientOperation is ReplaceNetworkClientOperation => {\n return networkClientOperation.type === 'replace';\n },\n )\n .map(\n (networkClientOperation) => networkClientOperation.oldRpcEndpoint,\n ),\n );\n\n for (const rpcEndpoint of removedRpcEndpoints) {\n const networkClient = this.getNetworkClientById(\n rpcEndpoint.networkClientId,\n );\n networkClient.destroy();\n delete autoManagedNetworkClientRegistry[networkClient.configuration.type][\n rpcEndpoint.networkClientId\n ];\n }\n }\n\n /**\n * Updates `networkConfigurationsByChainId` in state depending on whether a\n * network is being added, updated, or removed.\n *\n * - The existing network configuration will be removed when a network is\n * being filed under a different chain or removed.\n * - A network configuration will be stored when a network is being added or\n * when a network is being updated.\n *\n * @param args - The arguments to this function.\n */\n #updateNetworkConfigurations(\n args: { state: Draft<NetworkState> } & (\n | {\n mode: 'add';\n networkFields: AddNetworkFields;\n networkConfigurationToPersist: NetworkConfiguration;\n }\n | {\n mode: 'update';\n networkFields: UpdateNetworkFields;\n networkConfigurationToPersist: NetworkConfiguration;\n existingNetworkConfiguration: NetworkConfiguration;\n }\n | {\n mode: 'remove';\n existingNetworkConfiguration: NetworkConfiguration;\n }\n ),\n ) {\n const { state, mode } = args;\n\n if (\n mode === 'remove' ||\n (mode === 'update' &&\n args.networkFields.chainId !==\n args.existingNetworkConfiguration.chainId)\n ) {\n delete state.networkConfigurationsByChainId[\n args.existingNetworkConfiguration.chainId\n ];\n }\n\n if (mode === 'add' || mode === 'update') {\n if (\n !deepEqual(\n state.networkConfigurationsByChainId[args.networkFields.chainId],\n args.networkConfigurationToPersist,\n )\n ) {\n args.networkConfigurationToPersist.lastUpdatedAt = Date.now();\n }\n state.networkConfigurationsByChainId[args.networkFields.chainId] =\n args.networkConfigurationToPersist;\n }\n\n this.#networkConfigurationsByNetworkClientId =\n buildNetworkConfigurationsByNetworkClientId(\n cloneDeep(state.networkConfigurationsByChainId),\n );\n }\n\n /**\n * Before accessing or switching the network, the registry of network clients\n * needs to be populated. Otherwise, `#applyNetworkSelection` and\n * `getNetworkClientRegistry` will throw an error. This method checks to see if the\n * population step has happened yet, and if not, makes it happen.\n *\n * @returns The populated network client registry.\n */\n #ensureAutoManagedNetworkClientRegistryPopulated(): AutoManagedNetworkClientRegistry {\n return (this.#autoManagedNetworkClientRegistry ??=\n this.#createAutoManagedNetworkClientRegistry());\n }\n\n /**\n * Constructs the registry of network clients based on the set of default\n * and custom networks in state.\n *\n * @returns The network clients keyed by ID.\n */\n #createAutoManagedNetworkClientRegistry(): AutoManagedNetworkClientRegistry {\n const chainIds = knownKeysOf(this.state.networkConfigurationsByChainId);\n const networkClientsWithIds = chainIds.flatMap((chainId) => {\n const networkConfiguration =\n this.state.networkConfigurationsByChainId[chainId];\n return networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {\n if (rpcEndpoint.type === RpcEndpointType.Infura) {\n const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(\n rpcEndpoint.url,\n );\n return [\n rpcEndpoint.networkClientId,\n createAutoManagedNetworkClient({\n networkClientId: rpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Infura,\n network: infuraNetworkName,\n failoverRpcUrls: rpcEndpoint.failoverUrls,\n infuraProjectId: this.#infuraProjectId,\n chainId: networkConfiguration.chainId,\n ticker: networkConfiguration.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n }),\n ] as const;\n }\n return [\n rpcEndpoint.networkClientId,\n createAutoManagedNetworkClient({\n networkClientId: rpcEndpoint.networkClientId,\n networkClientConfiguration: {\n type: NetworkClientType.Custom,\n chainId: networkConfiguration.chainId,\n failoverRpcUrls: rpcEndpoint.failoverUrls,\n rpcUrl: rpcEndpoint.url,\n ticker: networkConfiguration.nativeCurrency,\n },\n getRpcServiceOptions: this.#getRpcServiceOptions,\n getBlockTrackerOptions: this.#getBlockTrackerOptions,\n messenger: this.messenger,\n isRpcFailoverEnabled: this.#isRpcFailoverEnabled,\n logger: this.#log,\n }),\n ] as const;\n });\n });\n\n return networkClientsWithIds.reduce(\n (\n obj: {\n [NetworkClientType.Custom]: Partial<AutoManagedCustomNetworkClientRegistry>;\n [NetworkClientType.Infura]: Partial<AutoManagedBuiltInNetworkClientRegistry>;\n },\n [networkClientId, networkClient],\n ) => {\n return {\n ...obj,\n [networkClient.configuration.type]: {\n ...obj[networkClient.configuration.type],\n [networkClientId]: networkClient,\n },\n };\n },\n {\n [NetworkClientType.Custom]: {},\n [NetworkClientType.Infura]: {},\n },\n ) as AutoManagedNetworkClientRegistry;\n }\n\n /**\n * Updates the global provider and block tracker proxies (accessible via\n * {@link getSelectedNetworkClient}) to point to the same ones within the\n * given network client, thereby magically switching any consumers using these\n * proxies to use the new network.\n *\n * Also refreshes the EthQuery instance accessible via the `getEthQuery`\n * action to wrap the provider from the new network client. Note that this is\n * not a proxy, so consumers will need to call `getEthQuery` again after the\n * network switch.\n *\n * @param networkClientId - The ID of a network client that requests will be\n * routed through (either the name of an Infura network or the ID of a custom\n * network configuration).\n * @param options - Options for this method.\n * @param options.updateState - Allows for updating state.\n * @throws if no network client could be found matching the given ID.\n */\n #applyNetworkSelection(\n networkClientId: string,\n {\n updateState,\n }: {\n updateState?: (state: Draft<NetworkState>) => void;\n } = {},\n ) {\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n let autoManagedNetworkClient:\n | AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n | AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n if (isInfuraNetworkType(networkClientId)) {\n const possibleAutoManagedNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n networkClientId\n ];\n\n // This is impossible to reach\n /* istanbul ignore if */\n if (!possibleAutoManagedNetworkClient) {\n throw new Error(\n `No Infura network client found with ID '${networkClientId}'`,\n );\n }\n\n autoManagedNetworkClient = possibleAutoManagedNetworkClient;\n } else {\n const possibleAutoManagedNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n networkClientId\n ];\n\n if (!possibleAutoManagedNetworkClient) {\n throw new Error(`No network client found with ID '${networkClientId}'`);\n }\n\n autoManagedNetworkClient = possibleAutoManagedNetworkClient;\n }\n\n this.#autoManagedNetworkClient = autoManagedNetworkClient;\n\n this.update((state) => {\n state.selectedNetworkClientId = networkClientId;\n if (state.networksMetadata[networkClientId] === undefined) {\n state.networksMetadata[networkClientId] = {\n status: NetworkStatus.Unknown,\n EIPS: {},\n };\n }\n updateState?.(state);\n });\n\n if (this.#providerProxy) {\n this.#providerProxy.setTarget(this.#autoManagedNetworkClient.provider);\n } else {\n this.#providerProxy = createSwappableProxy(\n this.#autoManagedNetworkClient.provider,\n );\n }\n\n if (this.#blockTrackerProxy) {\n this.#blockTrackerProxy.setTarget(\n this.#autoManagedNetworkClient.blockTracker,\n );\n } else {\n this.#blockTrackerProxy = createEventEmitterProxy(\n this.#autoManagedNetworkClient.blockTracker,\n {\n eventFilter: 'skipInternal',\n },\n );\n }\n\n this.#ethQuery = new EthQuery(this.#providerProxy);\n }\n}\n"]}
|