diff --git a/packages/controller-utils/CHANGELOG.md b/packages/controller-utils/CHANGELOG.md index cbe4120560..b271c0cdfe 100644 --- a/packages/controller-utils/CHANGELOG.md +++ b/packages/controller-utils/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `DEFAULT_INFURA_NETWORKS` with Infura network names to be enabled by default ([#8767](https://github.com/MetaMask/core/pull/8767)) + ## [12.0.0] ### Changed diff --git a/packages/controller-utils/src/index.test.ts b/packages/controller-utils/src/index.test.ts index 4187876c27..ab32df1aa9 100644 --- a/packages/controller-utils/src/index.test.ts +++ b/packages/controller-utils/src/index.test.ts @@ -81,6 +81,7 @@ describe('@metamask/controller-utils', () => { "weiHexToGweiDec", "isEqualCaseInsensitive", "InfuraNetworkType", + "DEFAULT_INFURA_NETWORKS", "CustomNetworkType", "NetworkType", "isNetworkType", diff --git a/packages/controller-utils/src/types.ts b/packages/controller-utils/src/types.ts index 95ac170672..f23ebb1deb 100644 --- a/packages/controller-utils/src/types.ts +++ b/packages/controller-utils/src/types.ts @@ -23,6 +23,27 @@ export const InfuraNetworkType = { export type InfuraNetworkType = (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType]; +/** + * The default set of Infura networks to include in the wallet. + * + * This is a subset of the full list of {@link InfuraNetworkType}, and can be used to determine + * which Infura networks to enable by default. + */ +export const DEFAULT_INFURA_NETWORKS = [ + InfuraNetworkType.mainnet, + InfuraNetworkType.goerli, + InfuraNetworkType.sepolia, + InfuraNetworkType['linea-goerli'], + InfuraNetworkType['linea-sepolia'], + InfuraNetworkType['linea-mainnet'], + InfuraNetworkType['base-mainnet'], + InfuraNetworkType['arbitrum-mainnet'], + InfuraNetworkType['bsc-mainnet'], + InfuraNetworkType['optimism-mainnet'], + InfuraNetworkType['polygon-mainnet'], + InfuraNetworkType['monad-mainnet'], +] as const satisfies InfuraNetworkType[]; + /** * Custom network types that are not part of Infura. */ diff --git a/packages/network-controller/CHANGELOG.md b/packages/network-controller/CHANGELOG.md index 305e4b6002..fc10c79f9c 100644 --- a/packages/network-controller/CHANGELOG.md +++ b/packages/network-controller/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- **BREAKING:** Remove Sei, MegaETH, Avalanche, and ZKSync from list of default networks ([#8767](https://github.com/MetaMask/core/pull/8767)) + - You will need to add them as network configurations first before switching to them. + ## [31.1.0] ### Added diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index e77d72f98e..ebadfb9dff 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -16,6 +16,7 @@ import { NetworkNickname, BUILT_IN_CUSTOM_NETWORKS_RPC, BUILT_IN_NETWORKS, + DEFAULT_INFURA_NETWORKS, } from '@metamask/controller-utils'; import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker'; import EthQuery from '@metamask/eth-query'; @@ -807,37 +808,38 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record< Hex, NetworkConfiguration > { - return Object.values(InfuraNetworkType).reduce< - Record - >((obj, infuraNetworkType) => { - const chainId = ChainId[infuraNetworkType]; + return DEFAULT_INFURA_NETWORKS.reduce>( + (obj, infuraNetworkType) => { + const chainId = ChainId[infuraNetworkType]; - // Skip deprecated network as default network. - if (DEPRECATED_NETWORKS.has(chainId)) { - return obj; - } - - const rpcEndpointUrl = - `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const; + // Skip deprecated network as default network. + if (DEPRECATED_NETWORKS.has(chainId)) { + return obj; + } - const networkConfiguration: NetworkConfiguration = { - blockExplorerUrls: [], - chainId, - defaultRpcEndpointIndex: 0, - name: NetworkNickname[infuraNetworkType], - nativeCurrency: NetworksTicker[infuraNetworkType], - rpcEndpoints: [ - { - failoverUrls: [], - networkClientId: infuraNetworkType, - type: RpcEndpointType.Infura, - url: rpcEndpointUrl, - }, - ], - }; + const rpcEndpointUrl = + `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const; + + const networkConfiguration: NetworkConfiguration = { + blockExplorerUrls: [], + chainId, + defaultRpcEndpointIndex: 0, + name: NetworkNickname[infuraNetworkType], + nativeCurrency: NetworksTicker[infuraNetworkType], + rpcEndpoints: [ + { + failoverUrls: [], + networkClientId: infuraNetworkType, + type: RpcEndpointType.Infura, + url: rpcEndpointUrl, + }, + ], + }; - return { ...obj, [chainId]: networkConfiguration }; - }, {}); + return { ...obj, [chainId]: networkConfiguration }; + }, + {}, + ); } /** diff --git a/packages/network-controller/tests/NetworkController.test.ts b/packages/network-controller/tests/NetworkController.test.ts index c7bddcd60e..30f733598a 100644 --- a/packages/network-controller/tests/NetworkController.test.ts +++ b/packages/network-controller/tests/NetworkController.test.ts @@ -518,36 +518,6 @@ describe('NetworkController', () => { }, ], }, - "0x10e6": { - "blockExplorerUrls": [], - "chainId": "0x10e6", - "defaultRpcEndpointIndex": 0, - "name": "MegaETH Mainnet", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "megaeth-mainnet", - "type": "infura", - "url": "https://megaeth-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, - "0x144": { - "blockExplorerUrls": [], - "chainId": "0x144", - "defaultRpcEndpointIndex": 0, - "name": "ZKsync Era", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "zksync-mainnet", - "type": "infura", - "url": "https://zksync-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x2105": { "blockExplorerUrls": [], "chainId": "0x2105", @@ -578,21 +548,6 @@ describe('NetworkController', () => { }, ], }, - "0x531": { - "blockExplorerUrls": [], - "chainId": "0x531", - "defaultRpcEndpointIndex": 0, - "name": "Sei Mainnet", - "nativeCurrency": "SEI", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "sei-mainnet", - "type": "infura", - "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x89": { "blockExplorerUrls": [], "chainId": "0x89", @@ -653,21 +608,6 @@ describe('NetworkController', () => { }, ], }, - "0xa86a": { - "blockExplorerUrls": [], - "chainId": "0xa86a", - "defaultRpcEndpointIndex": 0, - "name": "Avalanche Mainnet", - "nativeCurrency": "AVAX", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "avalanche-mainnet", - "type": "infura", - "url": "https://avalanche-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0xaa36a7": { "blockExplorerUrls": [], "chainId": "0xaa36a7", @@ -747,36 +687,6 @@ describe('NetworkController', () => { }, ], }, - "0x10e6": { - "blockExplorerUrls": [], - "chainId": "0x10e6", - "defaultRpcEndpointIndex": 0, - "name": "MegaETH Mainnet", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "megaeth-mainnet", - "type": "infura", - "url": "https://megaeth-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, - "0x144": { - "blockExplorerUrls": [], - "chainId": "0x144", - "defaultRpcEndpointIndex": 0, - "name": "ZKsync Era", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "zksync-mainnet", - "type": "infura", - "url": "https://zksync-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x18c6": { "blockExplorerUrls": [ "https://megaexplorer.xyz", @@ -825,21 +735,6 @@ describe('NetworkController', () => { }, ], }, - "0x531": { - "blockExplorerUrls": [], - "chainId": "0x531", - "defaultRpcEndpointIndex": 0, - "name": "Sei Mainnet", - "nativeCurrency": "SEI", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "sei-mainnet", - "type": "infura", - "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x89": { "blockExplorerUrls": [], "chainId": "0x89", @@ -900,21 +795,6 @@ describe('NetworkController', () => { }, ], }, - "0xa86a": { - "blockExplorerUrls": [], - "chainId": "0xa86a", - "defaultRpcEndpointIndex": 0, - "name": "Avalanche Mainnet", - "nativeCurrency": "AVAX", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "avalanche-mainnet", - "type": "infura", - "url": "https://avalanche-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0xaa36a7": { "blockExplorerUrls": [], "chainId": "0xaa36a7", @@ -2071,21 +1951,6 @@ describe('NetworkController', () => { enableRpcFailover: expect.any(Function), disableRpcFailover: expect.any(Function), }, - 'avalanche-mainnet': { - blockTracker: expect.anything(), - configuration: { - type: NetworkClientType.Infura, - failoverRpcUrls: [], - infuraProjectId, - chainId: '0xa86a', - ticker: 'AVAX', - network: InfuraNetworkType['avalanche-mainnet'], - }, - provider: expect.anything(), - destroy: expect.any(Function), - enableRpcFailover: expect.any(Function), - disableRpcFailover: expect.any(Function), - }, 'base-mainnet': { blockTracker: expect.anything(), configuration: { @@ -2161,21 +2026,6 @@ describe('NetworkController', () => { enableRpcFailover: expect.any(Function), disableRpcFailover: expect.any(Function), }, - 'megaeth-mainnet': { - blockTracker: expect.anything(), - configuration: { - type: NetworkClientType.Infura, - failoverRpcUrls: [], - infuraProjectId, - chainId: '0x10e6', - ticker: 'ETH', - network: InfuraNetworkType['megaeth-mainnet'], - }, - provider: expect.anything(), - destroy: expect.any(Function), - enableRpcFailover: expect.any(Function), - disableRpcFailover: expect.any(Function), - }, 'monad-mainnet': { blockTracker: expect.anything(), configuration: { @@ -2221,21 +2071,6 @@ describe('NetworkController', () => { enableRpcFailover: expect.any(Function), disableRpcFailover: expect.any(Function), }, - 'sei-mainnet': { - blockTracker: expect.anything(), - configuration: { - type: NetworkClientType.Infura, - failoverRpcUrls: [], - infuraProjectId, - chainId: '0x531', - ticker: 'SEI', - network: InfuraNetworkType['sei-mainnet'], - }, - provider: expect.anything(), - destroy: expect.any(Function), - enableRpcFailover: expect.any(Function), - disableRpcFailover: expect.any(Function), - }, sepolia: { blockTracker: expect.anything(), configuration: { @@ -2251,21 +2086,6 @@ describe('NetworkController', () => { enableRpcFailover: expect.any(Function), disableRpcFailover: expect.any(Function), }, - 'zksync-mainnet': { - blockTracker: expect.anything(), - configuration: { - type: NetworkClientType.Infura, - failoverRpcUrls: [], - infuraProjectId, - chainId: '0x144', - ticker: 'ETH', - network: InfuraNetworkType['zksync-mainnet'], - }, - provider: expect.anything(), - destroy: expect.any(Function), - enableRpcFailover: expect.any(Function), - disableRpcFailover: expect.any(Function), - }, }); }, ); @@ -15090,36 +14910,6 @@ describe('NetworkController', () => { }, ], }, - "0x10e6": { - "blockExplorerUrls": [], - "chainId": "0x10e6", - "defaultRpcEndpointIndex": 0, - "name": "MegaETH Mainnet", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "megaeth-mainnet", - "type": "infura", - "url": "https://megaeth-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, - "0x144": { - "blockExplorerUrls": [], - "chainId": "0x144", - "defaultRpcEndpointIndex": 0, - "name": "ZKsync Era", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "zksync-mainnet", - "type": "infura", - "url": "https://zksync-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x2105": { "blockExplorerUrls": [], "chainId": "0x2105", @@ -15150,21 +14940,6 @@ describe('NetworkController', () => { }, ], }, - "0x531": { - "blockExplorerUrls": [], - "chainId": "0x531", - "defaultRpcEndpointIndex": 0, - "name": "Sei Mainnet", - "nativeCurrency": "SEI", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "sei-mainnet", - "type": "infura", - "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x89": { "blockExplorerUrls": [], "chainId": "0x89", @@ -15225,21 +15000,6 @@ describe('NetworkController', () => { }, ], }, - "0xa86a": { - "blockExplorerUrls": [], - "chainId": "0xa86a", - "defaultRpcEndpointIndex": 0, - "name": "Avalanche Mainnet", - "nativeCurrency": "AVAX", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "avalanche-mainnet", - "type": "infura", - "url": "https://avalanche-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0xaa36a7": { "blockExplorerUrls": [], "chainId": "0xaa36a7", @@ -15319,36 +15079,6 @@ describe('NetworkController', () => { }, ], }, - "0x10e6": { - "blockExplorerUrls": [], - "chainId": "0x10e6", - "defaultRpcEndpointIndex": 0, - "name": "MegaETH Mainnet", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "megaeth-mainnet", - "type": "infura", - "url": "https://megaeth-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, - "0x144": { - "blockExplorerUrls": [], - "chainId": "0x144", - "defaultRpcEndpointIndex": 0, - "name": "ZKsync Era", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "zksync-mainnet", - "type": "infura", - "url": "https://zksync-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x2105": { "blockExplorerUrls": [], "chainId": "0x2105", @@ -15379,21 +15109,6 @@ describe('NetworkController', () => { }, ], }, - "0x531": { - "blockExplorerUrls": [], - "chainId": "0x531", - "defaultRpcEndpointIndex": 0, - "name": "Sei Mainnet", - "nativeCurrency": "SEI", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "sei-mainnet", - "type": "infura", - "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x89": { "blockExplorerUrls": [], "chainId": "0x89", @@ -15454,21 +15169,6 @@ describe('NetworkController', () => { }, ], }, - "0xa86a": { - "blockExplorerUrls": [], - "chainId": "0xa86a", - "defaultRpcEndpointIndex": 0, - "name": "Avalanche Mainnet", - "nativeCurrency": "AVAX", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "avalanche-mainnet", - "type": "infura", - "url": "https://avalanche-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0xaa36a7": { "blockExplorerUrls": [], "chainId": "0xaa36a7", @@ -15548,36 +15248,6 @@ describe('NetworkController', () => { }, ], }, - "0x10e6": { - "blockExplorerUrls": [], - "chainId": "0x10e6", - "defaultRpcEndpointIndex": 0, - "name": "MegaETH Mainnet", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "megaeth-mainnet", - "type": "infura", - "url": "https://megaeth-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, - "0x144": { - "blockExplorerUrls": [], - "chainId": "0x144", - "defaultRpcEndpointIndex": 0, - "name": "ZKsync Era", - "nativeCurrency": "ETH", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "zksync-mainnet", - "type": "infura", - "url": "https://zksync-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x2105": { "blockExplorerUrls": [], "chainId": "0x2105", @@ -15608,21 +15278,6 @@ describe('NetworkController', () => { }, ], }, - "0x531": { - "blockExplorerUrls": [], - "chainId": "0x531", - "defaultRpcEndpointIndex": 0, - "name": "Sei Mainnet", - "nativeCurrency": "SEI", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "sei-mainnet", - "type": "infura", - "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0x89": { "blockExplorerUrls": [], "chainId": "0x89", @@ -15683,21 +15338,6 @@ describe('NetworkController', () => { }, ], }, - "0xa86a": { - "blockExplorerUrls": [], - "chainId": "0xa86a", - "defaultRpcEndpointIndex": 0, - "name": "Avalanche Mainnet", - "nativeCurrency": "AVAX", - "rpcEndpoints": [ - { - "failoverUrls": [], - "networkClientId": "avalanche-mainnet", - "type": "infura", - "url": "https://avalanche-mainnet.infura.io/v3/{infuraProjectId}", - }, - ], - }, "0xaa36a7": { "blockExplorerUrls": [], "chainId": "0xaa36a7",