diff --git a/packages/assets-controllers/src/TokenDetectionController.test.ts b/packages/assets-controllers/src/TokenDetectionController.test.ts index b94d1da4ffa..1db2d4e6e37 100644 --- a/packages/assets-controllers/src/TokenDetectionController.test.ts +++ b/packages/assets-controllers/src/TokenDetectionController.test.ts @@ -1181,7 +1181,18 @@ describe('TokenDetectionController', () => { await advanceTime({ clock, duration: 1 }); expect(mockTokens).toHaveBeenNthCalledWith(1, { - chainIds: ['0x1', '0xaa36a7', '0xe705', '0xe708', '0x2105'], + chainIds: [ + '0x1', + '0xaa36a7', + '0xe705', + '0xe708', + '0x2105', + '0xa4b1', + '0x38', + '0xa', + '0x89', + '0x531', + ], selectedAddress: secondSelectedAccount.address, }); }, diff --git a/packages/controller-utils/CHANGELOG.md b/packages/controller-utils/CHANGELOG.md index 10631aea328..880f045e1a3 100644 --- a/packages/controller-utils/CHANGELOG.md +++ b/packages/controller-utils/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Arbitrum, BSC, Optimism, Polygon, and Sei networks to Infura networks ([#6972](https://github.com/MetaMask/core/pull/6972)) + - Add `arbitrum-one`, `bsc-mainnet`, `optimism-mainnet`, `polygon-mainnet`, `sei-mainnet` to `BUILT_IN_NETWORKS` + - Add `arbitrum-one`, `bsc-mainnet`, `optimism-mainnet`, `polygon-mainnet`, `sei-mainnet` to `InfuraNetworkType` + - Add `ArbitrumOne`, `BscMainnet`, `OptimismMainnet`, `PolygonMainnet`, `SeiMainnet` to `BuiltInNetworkName` enum + - Add corresponding chain IDs to `ChainId` type (0xa4b1, 0x38, 0xa, 0x89, 0x531) + - Add `ETG`, `BNB`, `ETH`, `POL`, `SEI` tickers to `NetworksTicker` enum + - Add block explorer URLs to `BlockExplorerUrl` quasi-enum + - Add network nicknames to `NetworkNickname` quasi-enum + ## [11.14.1] ### Changed diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index 4d352555527..a7a2b5e80bc 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -131,6 +131,41 @@ export const BUILT_IN_NETWORKS = { blockExplorerUrl: BlockExplorerUrl['base-mainnet'], }, }, + [NetworkType['arbitrum-mainnet']]: { + chainId: ChainId['arbitrum-mainnet'], + ticker: NetworksTicker['arbitrum-mainnet'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['arbitrum-mainnet'], + }, + }, + [NetworkType['bsc-mainnet']]: { + chainId: ChainId['bsc-mainnet'], + ticker: NetworksTicker['bsc-mainnet'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['bsc-mainnet'], + }, + }, + [NetworkType['optimism-mainnet']]: { + chainId: ChainId['optimism-mainnet'], + ticker: NetworksTicker['optimism-mainnet'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['optimism-mainnet'], + }, + }, + [NetworkType['polygon-mainnet']]: { + chainId: ChainId['polygon-mainnet'], + ticker: NetworksTicker['polygon-mainnet'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['polygon-mainnet'], + }, + }, + [NetworkType['sei-mainnet']]: { + chainId: ChainId['sei-mainnet'], + ticker: NetworksTicker['sei-mainnet'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['sei-mainnet'], + }, + }, [NetworkType.rpc]: { chainId: undefined, blockExplorerUrl: undefined, diff --git a/packages/controller-utils/src/types.ts b/packages/controller-utils/src/types.ts index b0f66676a6e..bb7c2e3d1bf 100644 --- a/packages/controller-utils/src/types.ts +++ b/packages/controller-utils/src/types.ts @@ -9,6 +9,11 @@ export const InfuraNetworkType = { 'linea-sepolia': 'linea-sepolia', 'linea-mainnet': 'linea-mainnet', 'base-mainnet': 'base-mainnet', + 'arbitrum-mainnet': 'arbitrum-mainnet', + 'bsc-mainnet': 'bsc-mainnet', + 'optimism-mainnet': 'optimism-mainnet', + 'polygon-mainnet': 'polygon-mainnet', + 'sei-mainnet': 'sei-mainnet', } as const; export type InfuraNetworkType = @@ -80,6 +85,11 @@ export enum BuiltInNetworkName { MegaETHTestnet = 'megaeth-testnet', MonadTestnet = 'monad-testnet', BaseMainnet = 'base-mainnet', + ArbitrumOne = 'arbitrum-mainnet', + BscMainnet = 'bsc-mainnet', + OptimismMainnet = 'optimism-mainnet', + PolygonMainnet = 'polygon-mainnet', + SeiMainnet = 'sei-mainnet', } /** @@ -98,6 +108,11 @@ export const ChainId = { [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342) [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143) [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453) + [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161) + [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56) + [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10) + [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137) + [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329) } as const; export type ChainId = (typeof ChainId)[keyof typeof ChainId]; @@ -114,6 +129,13 @@ export enum NetworksTicker { 'monad-testnet' = 'MON', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values 'base-mainnet' = 'ETH', + // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values + 'arbitrum-mainnet' = 'ETH', + 'bsc-mainnet' = 'BNB', + // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values + 'optimism-mainnet' = 'ETH', + 'polygon-mainnet' = 'POL', + 'sei-mainnet' = 'SEI', rpc = '', } @@ -127,6 +149,11 @@ export const BlockExplorerUrl = { [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz', [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com', [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org', + [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io', + [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com', + [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io', + [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com', + [BuiltInNetworkName.SeiMainnet]: 'https://seitrace.com', } as const satisfies Record; export type BlockExplorerUrl = (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl]; @@ -141,6 +168,11 @@ export const NetworkNickname = { [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet', [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet', [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet', + [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One', + [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet', + [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet', + [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet', + [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet', } as const satisfies Record; export type NetworkNickname = (typeof NetworkNickname)[keyof typeof NetworkNickname]; diff --git a/packages/network-controller/tests/NetworkController.test.ts b/packages/network-controller/tests/NetworkController.test.ts index f30adcdaf15..1da2cffcbce 100644 --- a/packages/network-controller/tests/NetworkController.test.ts +++ b/packages/network-controller/tests/NetworkController.test.ts @@ -490,6 +490,81 @@ describe('NetworkController', () => { }, ], }, + "0x38": Object { + "blockExplorerUrls": Array [], + "chainId": "0x38", + "defaultRpcEndpointIndex": 0, + "name": "BSC Mainnet", + "nativeCurrency": "BNB", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "bsc-mainnet", + "type": "infura", + "url": "https://bsc-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x531": Object { + "blockExplorerUrls": Array [], + "chainId": "0x531", + "defaultRpcEndpointIndex": 0, + "name": "Sei Mainnet", + "nativeCurrency": "SEI", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "sei-mainnet", + "type": "infura", + "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x89": Object { + "blockExplorerUrls": Array [], + "chainId": "0x89", + "defaultRpcEndpointIndex": 0, + "name": "Polygon Mainnet", + "nativeCurrency": "POL", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "polygon-mainnet", + "type": "infura", + "url": "https://polygon-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa", + "defaultRpcEndpointIndex": 0, + "name": "Optimism Mainnet", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "optimism-mainnet", + "type": "infura", + "url": "https://optimism-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa4b1": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa4b1", + "defaultRpcEndpointIndex": 0, + "name": "Arbitrum One", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "arbitrum-mainnet", + "type": "infura", + "url": "https://arbitrum-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, "0xaa36a7": Object { "blockExplorerUrls": Array [], "chainId": "0xaa36a7", @@ -602,6 +677,81 @@ describe('NetworkController', () => { }, ], }, + "0x38": Object { + "blockExplorerUrls": Array [], + "chainId": "0x38", + "defaultRpcEndpointIndex": 0, + "name": "BSC Mainnet", + "nativeCurrency": "BNB", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "bsc-mainnet", + "type": "infura", + "url": "https://bsc-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x531": Object { + "blockExplorerUrls": Array [], + "chainId": "0x531", + "defaultRpcEndpointIndex": 0, + "name": "Sei Mainnet", + "nativeCurrency": "SEI", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "sei-mainnet", + "type": "infura", + "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x89": Object { + "blockExplorerUrls": Array [], + "chainId": "0x89", + "defaultRpcEndpointIndex": 0, + "name": "Polygon Mainnet", + "nativeCurrency": "POL", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "polygon-mainnet", + "type": "infura", + "url": "https://polygon-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa", + "defaultRpcEndpointIndex": 0, + "name": "Optimism Mainnet", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "optimism-mainnet", + "type": "infura", + "url": "https://optimism-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa4b1": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa4b1", + "defaultRpcEndpointIndex": 0, + "name": "Arbitrum One", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "arbitrum-mainnet", + "type": "infura", + "url": "https://arbitrum-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, "0xaa36a7": Object { "blockExplorerUrls": Array [], "chainId": "0xaa36a7", @@ -1747,6 +1897,51 @@ describe('NetworkController', () => { mockCreateNetworkClient().mockReturnValue(buildFakeClient()); expect(controller.getNetworkClientRegistry()).toStrictEqual({ + 'arbitrum-mainnet': { + blockTracker: expect.anything(), + configuration: { + type: NetworkClientType.Infura, + failoverRpcUrls: [], + infuraProjectId, + chainId: '0xa4b1', + ticker: 'ETH', + network: InfuraNetworkType['arbitrum-mainnet'], + }, + provider: expect.anything(), + destroy: expect.any(Function), + enableRpcFailover: expect.any(Function), + disableRpcFailover: expect.any(Function), + }, + 'base-mainnet': { + blockTracker: expect.anything(), + configuration: { + type: NetworkClientType.Infura, + failoverRpcUrls: [], + infuraProjectId, + chainId: '0x2105', + ticker: 'ETH', + network: InfuraNetworkType['base-mainnet'], + }, + provider: expect.anything(), + destroy: expect.any(Function), + enableRpcFailover: expect.any(Function), + disableRpcFailover: expect.any(Function), + }, + 'bsc-mainnet': { + blockTracker: expect.anything(), + configuration: { + type: NetworkClientType.Infura, + failoverRpcUrls: [], + infuraProjectId, + chainId: '0x38', + ticker: 'BNB', + network: InfuraNetworkType['bsc-mainnet'], + }, + provider: expect.anything(), + destroy: expect.any(Function), + enableRpcFailover: expect.any(Function), + disableRpcFailover: expect.any(Function), + }, 'linea-mainnet': { blockTracker: expect.anything(), configuration: { @@ -1792,30 +1987,60 @@ describe('NetworkController', () => { enableRpcFailover: expect.any(Function), disableRpcFailover: expect.any(Function), }, - sepolia: { + 'optimism-mainnet': { blockTracker: expect.anything(), configuration: { type: NetworkClientType.Infura, failoverRpcUrls: [], infuraProjectId, - chainId: '0xaa36a7', - ticker: 'SepoliaETH', - network: InfuraNetworkType.sepolia, + chainId: '0xa', + ticker: 'ETH', + network: InfuraNetworkType['optimism-mainnet'], }, provider: expect.anything(), destroy: expect.any(Function), enableRpcFailover: expect.any(Function), disableRpcFailover: expect.any(Function), }, - 'base-mainnet': { + 'polygon-mainnet': { blockTracker: expect.anything(), configuration: { type: NetworkClientType.Infura, failoverRpcUrls: [], infuraProjectId, - chainId: '0x2105', - ticker: 'ETH', - network: InfuraNetworkType['base-mainnet'], + chainId: '0x89', + ticker: 'POL', + network: InfuraNetworkType['polygon-mainnet'], + }, + provider: expect.anything(), + destroy: expect.any(Function), + 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: { + type: NetworkClientType.Infura, + failoverRpcUrls: [], + infuraProjectId, + chainId: '0xaa36a7', + ticker: 'SepoliaETH', + network: InfuraNetworkType.sepolia, }, provider: expect.anything(), destroy: expect.any(Function), @@ -14554,6 +14779,81 @@ describe('NetworkController', () => { }, ], }, + "0x38": Object { + "blockExplorerUrls": Array [], + "chainId": "0x38", + "defaultRpcEndpointIndex": 0, + "name": "BSC Mainnet", + "nativeCurrency": "BNB", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "bsc-mainnet", + "type": "infura", + "url": "https://bsc-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x531": Object { + "blockExplorerUrls": Array [], + "chainId": "0x531", + "defaultRpcEndpointIndex": 0, + "name": "Sei Mainnet", + "nativeCurrency": "SEI", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "sei-mainnet", + "type": "infura", + "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x89": Object { + "blockExplorerUrls": Array [], + "chainId": "0x89", + "defaultRpcEndpointIndex": 0, + "name": "Polygon Mainnet", + "nativeCurrency": "POL", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "polygon-mainnet", + "type": "infura", + "url": "https://polygon-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa", + "defaultRpcEndpointIndex": 0, + "name": "Optimism Mainnet", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "optimism-mainnet", + "type": "infura", + "url": "https://optimism-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa4b1": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa4b1", + "defaultRpcEndpointIndex": 0, + "name": "Arbitrum One", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "arbitrum-mainnet", + "type": "infura", + "url": "https://arbitrum-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, "0xaa36a7": Object { "blockExplorerUrls": Array [], "chainId": "0xaa36a7", @@ -14648,6 +14948,81 @@ describe('NetworkController', () => { }, ], }, + "0x38": Object { + "blockExplorerUrls": Array [], + "chainId": "0x38", + "defaultRpcEndpointIndex": 0, + "name": "BSC Mainnet", + "nativeCurrency": "BNB", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "bsc-mainnet", + "type": "infura", + "url": "https://bsc-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x531": Object { + "blockExplorerUrls": Array [], + "chainId": "0x531", + "defaultRpcEndpointIndex": 0, + "name": "Sei Mainnet", + "nativeCurrency": "SEI", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "sei-mainnet", + "type": "infura", + "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x89": Object { + "blockExplorerUrls": Array [], + "chainId": "0x89", + "defaultRpcEndpointIndex": 0, + "name": "Polygon Mainnet", + "nativeCurrency": "POL", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "polygon-mainnet", + "type": "infura", + "url": "https://polygon-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa", + "defaultRpcEndpointIndex": 0, + "name": "Optimism Mainnet", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "optimism-mainnet", + "type": "infura", + "url": "https://optimism-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa4b1": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa4b1", + "defaultRpcEndpointIndex": 0, + "name": "Arbitrum One", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "arbitrum-mainnet", + "type": "infura", + "url": "https://arbitrum-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, "0xaa36a7": Object { "blockExplorerUrls": Array [], "chainId": "0xaa36a7", @@ -14742,6 +15117,81 @@ describe('NetworkController', () => { }, ], }, + "0x38": Object { + "blockExplorerUrls": Array [], + "chainId": "0x38", + "defaultRpcEndpointIndex": 0, + "name": "BSC Mainnet", + "nativeCurrency": "BNB", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "bsc-mainnet", + "type": "infura", + "url": "https://bsc-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x531": Object { + "blockExplorerUrls": Array [], + "chainId": "0x531", + "defaultRpcEndpointIndex": 0, + "name": "Sei Mainnet", + "nativeCurrency": "SEI", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "sei-mainnet", + "type": "infura", + "url": "https://sei-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0x89": Object { + "blockExplorerUrls": Array [], + "chainId": "0x89", + "defaultRpcEndpointIndex": 0, + "name": "Polygon Mainnet", + "nativeCurrency": "POL", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "polygon-mainnet", + "type": "infura", + "url": "https://polygon-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa", + "defaultRpcEndpointIndex": 0, + "name": "Optimism Mainnet", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "optimism-mainnet", + "type": "infura", + "url": "https://optimism-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, + "0xa4b1": Object { + "blockExplorerUrls": Array [], + "chainId": "0xa4b1", + "defaultRpcEndpointIndex": 0, + "name": "Arbitrum One", + "nativeCurrency": "ETH", + "rpcEndpoints": Array [ + Object { + "failoverUrls": Array [], + "networkClientId": "arbitrum-mainnet", + "type": "infura", + "url": "https://arbitrum-mainnet.infura.io/v3/{infuraProjectId}", + }, + ], + }, "0xaa36a7": Object { "blockExplorerUrls": Array [], "chainId": "0xaa36a7",