diff --git a/packages/controller-utils/CHANGELOG.md b/packages/controller-utils/CHANGELOG.md index 94c4b187905..c6c6f65bb3d 100644 --- a/packages/controller-utils/CHANGELOG.md +++ b/packages/controller-utils/CHANGELOG.md @@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `monad-testnet` to `InfuraNetworkType` ([#7067](https://github.com/MetaMask/core/pull/7067)) +### Changed + +- Update Monad Testnet Infura Network Client ID from `monad-testnet` to `monad-testnet-infura` ([#7333](https://github.com/MetaMask/core/pull/7333)) + - Change `monad-testnet` to `monad-testnet-infura` in `InfuraNetworkType` quasi-enum + - Add `monad-testnet-infura` to `BUILT_IN_NETWORKS` + - Add `MonadTestnetInfura` to `BuiltInNetworkName` enum + - Add `monad-testnet-infura` to `ChainId` type + - Add `MonadTestnetInfura` to `NetworksTicker` enum + - Add `MonadTestnetInfura` to `BlockExplorerUrl` quasi-enum + - Add `MonadTestnetInfura` to `NetworkNickname` quasi-enum + ## [11.16.0] ### Added diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index a7a2b5e80bc..9e3cd015c09 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -124,6 +124,13 @@ export const BUILT_IN_NETWORKS = { blockExplorerUrl: BlockExplorerUrl['monad-testnet'], }, }, + [NetworkType['monad-testnet-infura']]: { + chainId: ChainId['monad-testnet-infura'], + ticker: NetworksTicker['monad-testnet-infura'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['monad-testnet-infura'], + }, + }, [NetworkType['base-mainnet']]: { chainId: ChainId['base-mainnet'], ticker: NetworksTicker['base-mainnet'], diff --git a/packages/controller-utils/src/types.ts b/packages/controller-utils/src/types.ts index 71f905d51c6..a5db287e694 100644 --- a/packages/controller-utils/src/types.ts +++ b/packages/controller-utils/src/types.ts @@ -14,7 +14,7 @@ export const InfuraNetworkType = { 'optimism-mainnet': 'optimism-mainnet', 'polygon-mainnet': 'polygon-mainnet', 'sei-mainnet': 'sei-mainnet', - 'monad-testnet': 'monad-testnet', + 'monad-testnet-infura': 'monad-testnet-infura', } as const; export type InfuraNetworkType = @@ -88,6 +88,7 @@ export enum BuiltInNetworkName { Aurora = 'aurora', MegaETHTestnet = 'megaeth-testnet', MonadTestnet = 'monad-testnet', + MonadTestnetInfura = 'monad-testnet-infura', BaseMainnet = 'base-mainnet', ArbitrumOne = 'arbitrum-mainnet', BscMainnet = 'bsc-mainnet', @@ -111,6 +112,7 @@ export const ChainId = { [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144) [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342) [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143) + [BuiltInNetworkName.MonadTestnetInfura]: '0x279f', // toHex(10143) [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453) [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161) [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56) @@ -132,6 +134,8 @@ export enum NetworksTicker { 'megaeth-testnet' = 'MegaETH', 'monad-testnet' = 'MON', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values + 'monad-testnet-infura' = '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', @@ -152,6 +156,7 @@ export const BlockExplorerUrl = { [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build', [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz', [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com', + [BuiltInNetworkName.MonadTestnetInfura]: 'https://testnet.monadexplorer.com', [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org', [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io', [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com', @@ -171,6 +176,7 @@ export const NetworkNickname = { [BuiltInNetworkName.LineaMainnet]: 'Linea', [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet', [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet', + [BuiltInNetworkName.MonadTestnetInfura]: 'Monad Testnet', [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet', [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One', [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet', diff --git a/packages/network-controller/CHANGELOG.md b/packages/network-controller/CHANGELOG.md index b6c4b0b8767..dda2e49a3cb 100644 --- a/packages/network-controller/CHANGELOG.md +++ b/packages/network-controller/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update the default set of Infura networks to include Monad Testnet ([#7067](https://github.com/MetaMask/core/pull/7067)) +- Update Monad Testnet Network Client Id ([#7333](https://github.com/MetaMask/core/pull/7333)) ## [27.0.0] diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index 13acb49a41d..691ac599343 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -40,6 +40,7 @@ import { v4 as uuidV4 } from 'uuid'; import { DEPRECATED_NETWORKS, INFURA_BLOCKED_KEY, + FALLBACK_INFURA_NETWORK_TYPE_MAPPING, NetworkStatus, } from './constants'; import type { @@ -823,9 +824,28 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record< Hex, NetworkConfiguration > { + const reverseFallbackInfuraNetworkTypeMapping = Object.entries( + FALLBACK_INFURA_NETWORK_TYPE_MAPPING, + ).reduce>( + (reversed, [key, value]) => { + reversed[value] = key; + return reversed; + }, + {} as Record, + ); + return Object.values(InfuraNetworkType).reduce< Record - >((obj, infuraNetworkType) => { + >((obj, _infuraNetworkType) => { + let infuraNetworkType = _infuraNetworkType; + if ( + hasProperty(reverseFallbackInfuraNetworkTypeMapping, infuraNetworkType) + ) { + infuraNetworkType = reverseFallbackInfuraNetworkTypeMapping[ + infuraNetworkType + ] as InfuraNetworkType; + } + const chainId = ChainId[infuraNetworkType]; // Skip deprecated network as default network. @@ -845,7 +865,7 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record< rpcEndpoints: [ { failoverUrls: [], - networkClientId: infuraNetworkType, + networkClientId: _infuraNetworkType, type: RpcEndpointType.Infura, url: rpcEndpointUrl, }, @@ -1118,6 +1138,18 @@ function deriveInfuraNetworkNameFromRpcEndpointUrl( return match.groups.networkName; } + // Infura URL can be inserted by user manually, + // in case the network name extra from URL is not mapped to InfuraNetworkType, + // we should add a fallback mapping here. + if ( + hasProperty( + FALLBACK_INFURA_NETWORK_TYPE_MAPPING, + match.groups.networkName, + ) + ) { + return FALLBACK_INFURA_NETWORK_TYPE_MAPPING[match.groups.networkName]; + } + throw new Error(`Unknown Infura network '${match.groups.networkName}'`); } diff --git a/packages/network-controller/src/constants.ts b/packages/network-controller/src/constants.ts index 1708cc2ebf6..f6ef82a83c9 100644 --- a/packages/network-controller/src/constants.ts +++ b/packages/network-controller/src/constants.ts @@ -1,3 +1,5 @@ +import { InfuraNetworkType } from "@metamask/controller-utils"; + /** * Represents the availability status of an RPC endpoint. (Regrettably, the * name of this type is a misnomer.) @@ -41,3 +43,13 @@ export const INFURA_BLOCKED_KEY = 'countryBlocked'; * without the need to remove the network from constant list of controller-utils. */ export const DEPRECATED_NETWORKS = new Set(['0xe704', '0x5']); + +/** + * A mapping of network keys to their corresponding InfuraNetworkType keys. + * This is used to map the network keys to the InfuraNetworkType keys. + * For example, `monad-testnet` is mapped to `monad-testnet-infura`. + * This is used to map the network keys to the InfuraNetworkType keys. + */ +export const FALLBACK_INFURA_NETWORK_TYPE_MAPPING: Record = { + 'monad-testnet': 'monad-testnet-infura', +}