From 9e7cc2985d7aca79a08f5a1baa3731af120a6442 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Tue, 29 Apr 2025 18:57:11 +0800 Subject: [PATCH 01/10] feat: add monad testnet --- packages/controller-utils/src/constants.ts | 9 +++++ packages/controller-utils/src/types.ts | 6 ++++ .../src/NetworkController.ts | 34 +++++++++++++------ packages/network-controller/src/types.ts | 5 +-- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index 4bcb6fbe4cc..1547e32e937 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -50,6 +50,7 @@ export const TESTNET_TICKER_SYMBOLS = { LINEA_GOERLI: 'LineaETH', LINEA_SEPOLIA: 'LineaETH', MEGAETH_TESTNET: 'MegaETH', + MONAD_TESTNET: 'MON', }; /** @@ -57,6 +58,7 @@ export const TESTNET_TICKER_SYMBOLS = { */ export const BUILT_IN_CUSTOM_NETWORKS_RPC = { MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc', + MONAD_TESTNET: 'https://testnet-rpc.monad.xyz', }; /** @@ -112,6 +114,13 @@ export const BUILT_IN_NETWORKS = { blockExplorerUrl: BlockExplorerUrl['megaeth-testnet'], }, }, + [NetworkType['monad-testnet']]: { + chainId: ChainId['monad-testnet'], + ticker: NetworksTicker['monad-testnet'], + rpcPrefs: { + blockExplorerUrl: BlockExplorerUrl['monad-testnet'], + }, + }, [NetworkType.rpc]: { chainId: undefined, blockExplorerUrl: undefined, diff --git a/packages/controller-utils/src/types.ts b/packages/controller-utils/src/types.ts index 00ac2b0ccb4..970d7e7d5d1 100644 --- a/packages/controller-utils/src/types.ts +++ b/packages/controller-utils/src/types.ts @@ -18,6 +18,7 @@ export type InfuraNetworkType = */ export const CustomNetworkType = { 'megaeth-testnet': 'megaeth-testnet', + 'monad-testnet': 'monad-testnet', } as const; export type CustomNetworkType = (typeof CustomNetworkType)[keyof typeof CustomNetworkType]; @@ -76,6 +77,7 @@ export enum BuiltInNetworkName { LineaMainnet = 'linea-mainnet', Aurora = 'aurora', MegaETHTestnet = 'megaeth-testnet', + MonadTestnet = 'monad-testnet', } /** @@ -92,6 +94,7 @@ export const ChainId = { [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141) [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144) [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342) + [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143) } as const; export type ChainId = (typeof ChainId)[keyof typeof ChainId]; @@ -109,6 +112,7 @@ export enum NetworksTicker { 'linea-sepolia' = 'LineaETH', 'linea-mainnet' = 'ETH', 'megaeth-testnet' = 'MegaETH', + 'monad-testnet' = 'MON', // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/naming-convention rpc = '', @@ -122,6 +126,7 @@ export const BlockExplorerUrl = { [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build', [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build', [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz', + [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com', } as const satisfies Record; export type BlockExplorerUrl = (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl]; @@ -134,6 +139,7 @@ export const NetworkNickname = { [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia', [BuiltInNetworkName.LineaMainnet]: 'Linea', [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet', + [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet', } as const satisfies Record; export type NetworkNickname = (typeof NetworkNickname)[keyof typeof NetworkNickname]; diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index f151d9e6c62..2df9f281c2e 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -7,6 +7,7 @@ import { BaseController } from '@metamask/base-controller'; import type { Partialize } from '@metamask/controller-utils'; import { InfuraNetworkType, + CustomNetworkType, NetworkType, isSafeChainId, isInfuraNetworkType, @@ -15,7 +16,6 @@ import { NetworkNickname, BUILT_IN_CUSTOM_NETWORKS_RPC, BUILT_IN_NETWORKS, - BuiltInNetworkName, } from '@metamask/controller-utils'; import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker'; import EthQuery from '@metamask/eth-query'; @@ -723,26 +723,38 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record< Hex, NetworkConfiguration > { - const { ticker, rpcPrefs } = - BUILT_IN_NETWORKS[BuiltInNetworkName.MegaETHTestnet]; - return { - [ChainId[BuiltInNetworkName.MegaETHTestnet]]: { + return Object.values(CustomNetworkType).reduce< + Record + >((obj, customNetworkType) => { + const chainId = ChainId[customNetworkType]; + const { ticker, rpcPrefs } = + BUILT_IN_NETWORKS[customNetworkType]; + // It converts client id to upper case and replace '-' with '_' + // to match the key in BUILT_IN_CUSTOM_NETWORKS_RPC + // e.g. 'megaeth-testnet' to 'MEGAETH_TESTNET' + // e.g. 'monad-testnet' to 'MONAD_TESTNET' + // TODO: Refactor controller-utils to use the same format as others + const rpcEndpointUrlKey = customNetworkType.toUpperCase().replace('-','_') as keyof typeof BUILT_IN_CUSTOM_NETWORKS_RPC; + + const networkConfiguration: NetworkConfiguration = { blockExplorerUrls: [rpcPrefs.blockExplorerUrl], - chainId: ChainId[BuiltInNetworkName.MegaETHTestnet], + chainId: ChainId[customNetworkType], defaultRpcEndpointIndex: 0, defaultBlockExplorerUrlIndex: 0, - name: NetworkNickname[BuiltInNetworkName.MegaETHTestnet], + name: NetworkNickname[customNetworkType], nativeCurrency: ticker, rpcEndpoints: [ { failoverUrls: [], - networkClientId: BuiltInNetworkName.MegaETHTestnet, + networkClientId: customNetworkType, type: RpcEndpointType.Custom, - url: BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET, + url: BUILT_IN_CUSTOM_NETWORKS_RPC[rpcEndpointUrlKey], }, ], - }, - }; + }; + + return { ...obj, [chainId]: networkConfiguration }; + }, {}); } /** diff --git a/packages/network-controller/src/types.ts b/packages/network-controller/src/types.ts index ba243b04993..cac64e6ef22 100644 --- a/packages/network-controller/src/types.ts +++ b/packages/network-controller/src/types.ts @@ -1,4 +1,5 @@ -import type { ChainId, InfuraNetworkType } from '@metamask/controller-utils'; +import { ChainId } from '@metamask/controller-utils'; +import type { InfuraNetworkType } from '@metamask/controller-utils'; import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker'; import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; import type { Hex } from '@metamask/utils'; @@ -57,4 +58,4 @@ export type NetworkClientConfiguration = /** * The Chain ID representing the additional networks to be included as default. */ -export type AdditionalDefaultNetwork = (typeof ChainId)['megaeth-testnet']; +export type AdditionalDefaultNetwork = typeof ChainId['megaeth-testnet'] | typeof ChainId['monad-testnet']; From cabccf73ee3b4d45897edef41fb6c8893bf661b9 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:12:19 +0800 Subject: [PATCH 02/10] chore: lint & change log --- packages/controller-utils/CHANGELOG.md | 11 +++++++++++ packages/network-controller/CHANGELOG.md | 1 + packages/network-controller/src/NetworkController.ts | 9 +++++---- packages/network-controller/src/types.ts | 7 ++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/controller-utils/CHANGELOG.md b/packages/controller-utils/CHANGELOG.md index b7330ba994c..81e9752e703 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 + +- Add Monad Testnet to various constants, enums, and types ([#5724](https://github.com/MetaMask/core/pull/5724)) + - Add `MONAD_TESTNET` to `TESTNET_TICKER_SYMBOLS` + - Add `monad-testnet` to `BUILT_IN_NETWORKS` + - Add `MonadTestnet` to `BuiltInNetworkName` enum + - Add `monad-testnet` to `ChainId` type + - Add `MonadTestnet` to `NetworksTicker` enum + - Add `MonadTestnet` to `BlockExplorerUrl` quasi-enum + - Add `MonadTestnet` to `NetworkNickname` quasi-enum + ## [11.7.0] ### Added diff --git a/packages/network-controller/CHANGELOG.md b/packages/network-controller/CHANGELOG.md index 9c72afa847f..03857210942 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 ### Added - Add optional `getBlockTrackerOptions` argument to NetworkController constructor ([#5702](https://github.com/MetaMask/core/pull/5702)) +- Add Monad Testnet as default network ([#5724](https://github.com/MetaMask/core/pull/5724)) ### Changed diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index 2df9f281c2e..a4ac8cf74bf 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -727,15 +727,16 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record< Record >((obj, customNetworkType) => { const chainId = ChainId[customNetworkType]; - const { ticker, rpcPrefs } = - BUILT_IN_NETWORKS[customNetworkType]; + const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType]; // It converts client id to upper case and replace '-' with '_' // to match the key in BUILT_IN_CUSTOM_NETWORKS_RPC // e.g. 'megaeth-testnet' to 'MEGAETH_TESTNET' // e.g. 'monad-testnet' to 'MONAD_TESTNET' // TODO: Refactor controller-utils to use the same format as others - const rpcEndpointUrlKey = customNetworkType.toUpperCase().replace('-','_') as keyof typeof BUILT_IN_CUSTOM_NETWORKS_RPC; - + const rpcEndpointUrlKey = customNetworkType + .toUpperCase() + .replace('-', '_') as keyof typeof BUILT_IN_CUSTOM_NETWORKS_RPC; + const networkConfiguration: NetworkConfiguration = { blockExplorerUrls: [rpcPrefs.blockExplorerUrl], chainId: ChainId[customNetworkType], diff --git a/packages/network-controller/src/types.ts b/packages/network-controller/src/types.ts index cac64e6ef22..e656b579a78 100644 --- a/packages/network-controller/src/types.ts +++ b/packages/network-controller/src/types.ts @@ -1,5 +1,4 @@ -import { ChainId } from '@metamask/controller-utils'; -import type { InfuraNetworkType } from '@metamask/controller-utils'; +import type { InfuraNetworkType, ChainId } from '@metamask/controller-utils'; import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker'; import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; import type { Hex } from '@metamask/utils'; @@ -58,4 +57,6 @@ export type NetworkClientConfiguration = /** * The Chain ID representing the additional networks to be included as default. */ -export type AdditionalDefaultNetwork = typeof ChainId['megaeth-testnet'] | typeof ChainId['monad-testnet']; +export type AdditionalDefaultNetwork = + | (typeof ChainId)['megaeth-testnet'] + | (typeof ChainId)['monad-testnet']; From 28cd3de3c91881565893ff1d745b8908cbf0f344 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:47:00 +0800 Subject: [PATCH 03/10] chore: remove testnet ticket --- packages/controller-utils/src/constants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index 1547e32e937..66ef878345a 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -50,7 +50,6 @@ export const TESTNET_TICKER_SYMBOLS = { LINEA_GOERLI: 'LineaETH', LINEA_SEPOLIA: 'LineaETH', MEGAETH_TESTNET: 'MegaETH', - MONAD_TESTNET: 'MON', }; /** From 83db5a288dc9e29201e80ccbedb1252f44ebede5 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Fri, 2 May 2025 23:17:05 +0800 Subject: [PATCH 04/10] chore: update type --- packages/network-controller/src/types.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/network-controller/src/types.ts b/packages/network-controller/src/types.ts index e656b579a78..712312a4482 100644 --- a/packages/network-controller/src/types.ts +++ b/packages/network-controller/src/types.ts @@ -1,4 +1,8 @@ -import type { InfuraNetworkType, ChainId } from '@metamask/controller-utils'; +import type { + InfuraNetworkType, + CustomNetworkType, + ChainId +} from '@metamask/controller-utils'; import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker'; import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; import type { Hex } from '@metamask/utils'; @@ -57,6 +61,4 @@ export type NetworkClientConfiguration = /** * The Chain ID representing the additional networks to be included as default. */ -export type AdditionalDefaultNetwork = - | (typeof ChainId)['megaeth-testnet'] - | (typeof ChainId)['monad-testnet']; +export type AdditionalDefaultNetwork = (typeof ChainId)[keyof typeof CustomNetworkType]; From eeba78262f97caae490a4367c447124115ad8501 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Fri, 2 May 2025 23:22:38 +0800 Subject: [PATCH 05/10] chore: lint --- packages/network-controller/src/types.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/network-controller/src/types.ts b/packages/network-controller/src/types.ts index 712312a4482..0ec80815333 100644 --- a/packages/network-controller/src/types.ts +++ b/packages/network-controller/src/types.ts @@ -1,7 +1,7 @@ -import type { +import type { InfuraNetworkType, CustomNetworkType, - ChainId + ChainId, } from '@metamask/controller-utils'; import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker'; import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; @@ -61,4 +61,5 @@ export type NetworkClientConfiguration = /** * The Chain ID representing the additional networks to be included as default. */ -export type AdditionalDefaultNetwork = (typeof ChainId)[keyof typeof CustomNetworkType]; +export type AdditionalDefaultNetwork = + (typeof ChainId)[keyof typeof CustomNetworkType]; From d9ad84d8fc4fcf71a233f7390f38cf6a00fe7ff7 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Fri, 2 May 2025 23:48:03 +0800 Subject: [PATCH 06/10] fix: define custom network explicitly --- .../src/NetworkController.ts | 86 ++++++++++++------- packages/network-controller/src/types.ts | 2 +- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index 33207c354ba..8bf41163fdf 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -728,39 +728,63 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record< Hex, NetworkConfiguration > { - return Object.values(CustomNetworkType).reduce< - Record - >((obj, customNetworkType) => { - const chainId = ChainId[customNetworkType]; - const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType]; - // It converts client id to upper case and replace '-' with '_' - // to match the key in BUILT_IN_CUSTOM_NETWORKS_RPC - // e.g. 'megaeth-testnet' to 'MEGAETH_TESTNET' - // e.g. 'monad-testnet' to 'MONAD_TESTNET' - // TODO: Refactor controller-utils to use the same format as others - const rpcEndpointUrlKey = customNetworkType - .toUpperCase() - .replace('-', '_') as keyof typeof BUILT_IN_CUSTOM_NETWORKS_RPC; + // Create the `networkConfigurationsByChainId` objects explicitly, + // Because it is not always guaranteed that the custom networks are included in the + // default networks. + return { + [ChainId['megaeth-testnet']]: getCustomNetworkConfiguration( + CustomNetworkType['megaeth-testnet'], + ), + [ChainId['monad-testnet']]: getCustomNetworkConfiguration( + CustomNetworkType['monad-testnet'], + ), + } +} - const networkConfiguration: NetworkConfiguration = { - blockExplorerUrls: [rpcPrefs.blockExplorerUrl], - chainId: ChainId[customNetworkType], - defaultRpcEndpointIndex: 0, - defaultBlockExplorerUrlIndex: 0, - name: NetworkNickname[customNetworkType], - nativeCurrency: ticker, - rpcEndpoints: [ - { - failoverUrls: [], - networkClientId: customNetworkType, - type: RpcEndpointType.Custom, - url: BUILT_IN_CUSTOM_NETWORKS_RPC[rpcEndpointUrlKey], - }, - ], - }; +/** + * Constructs a `NetworkConfiguration` object by `CustomNetworkType`. + * + * @param customNetworkType - The type of the custom network. + * @returns The `NetworkConfiguration` object. + */ +function getCustomNetworkConfiguration(customNetworkType:CustomNetworkType): NetworkConfiguration { + const chainId = ChainId[customNetworkType]; + const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType]; + const rpcEndpointUrl = getCustomNetworkRpcEndpointUrl(chainId); + + return { + blockExplorerUrls: [rpcPrefs.blockExplorerUrl], + chainId: ChainId[customNetworkType], + defaultRpcEndpointIndex: 0, + defaultBlockExplorerUrlIndex: 0, + name: NetworkNickname[customNetworkType], + nativeCurrency: ticker, + rpcEndpoints: [ + { + failoverUrls: [], + networkClientId: customNetworkType, + type: RpcEndpointType.Custom, + url: rpcEndpointUrl, + }, + ], + }; +} - return { ...obj, [chainId]: networkConfiguration }; - }, {}); +/** + * Get the RPC endpoint URL for a custom network by supported chain ID. + * + * @param chainId - The chain ID of the custom network. + * @returns The RPC endpoint URL. + */ +function getCustomNetworkRpcEndpointUrl(chainId: AdditionalDefaultNetwork): string { + switch (chainId) { + case ChainId['megaeth-testnet']: + return BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET; + case ChainId['monad-testnet']: + return BUILT_IN_CUSTOM_NETWORKS_RPC.MONAD_TESTNET; + default: + throw new Error(`Unsupported chain ID: ${chainId}`); + } } /** diff --git a/packages/network-controller/src/types.ts b/packages/network-controller/src/types.ts index 0ec80815333..4cdfd3e0a48 100644 --- a/packages/network-controller/src/types.ts +++ b/packages/network-controller/src/types.ts @@ -62,4 +62,4 @@ export type NetworkClientConfiguration = * The Chain ID representing the additional networks to be included as default. */ export type AdditionalDefaultNetwork = - (typeof ChainId)[keyof typeof CustomNetworkType]; + (typeof ChainId)['megaeth-testnet' | 'monad-testnet']; From c1f6e4903b5001913b93e19603588af2913ba834 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Fri, 2 May 2025 23:54:32 +0800 Subject: [PATCH 07/10] fix: lint --- .../network-controller/src/NetworkController.ts | 14 +++++++++----- packages/network-controller/src/types.ts | 11 ++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index 8bf41163fdf..dce13e9199d 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -738,7 +738,7 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record< [ChainId['monad-testnet']]: getCustomNetworkConfiguration( CustomNetworkType['monad-testnet'], ), - } + }; } /** @@ -747,12 +747,14 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record< * @param customNetworkType - The type of the custom network. * @returns The `NetworkConfiguration` object. */ -function getCustomNetworkConfiguration(customNetworkType:CustomNetworkType): NetworkConfiguration { +function getCustomNetworkConfiguration( + customNetworkType: CustomNetworkType, +): NetworkConfiguration { const chainId = ChainId[customNetworkType]; const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType]; const rpcEndpointUrl = getCustomNetworkRpcEndpointUrl(chainId); - return { + return { blockExplorerUrls: [rpcPrefs.blockExplorerUrl], chainId: ChainId[customNetworkType], defaultRpcEndpointIndex: 0, @@ -772,11 +774,13 @@ function getCustomNetworkConfiguration(customNetworkType:CustomNetworkType): Net /** * Get the RPC endpoint URL for a custom network by supported chain ID. - * + * * @param chainId - The chain ID of the custom network. * @returns The RPC endpoint URL. */ -function getCustomNetworkRpcEndpointUrl(chainId: AdditionalDefaultNetwork): string { +function getCustomNetworkRpcEndpointUrl( + chainId: AdditionalDefaultNetwork, +): string { switch (chainId) { case ChainId['megaeth-testnet']: return BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET; diff --git a/packages/network-controller/src/types.ts b/packages/network-controller/src/types.ts index 4cdfd3e0a48..adffecf160a 100644 --- a/packages/network-controller/src/types.ts +++ b/packages/network-controller/src/types.ts @@ -1,8 +1,4 @@ -import type { - InfuraNetworkType, - CustomNetworkType, - ChainId, -} from '@metamask/controller-utils'; +import type { InfuraNetworkType, ChainId } from '@metamask/controller-utils'; import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker'; import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; import type { Hex } from '@metamask/utils'; @@ -61,5 +57,6 @@ export type NetworkClientConfiguration = /** * The Chain ID representing the additional networks to be included as default. */ -export type AdditionalDefaultNetwork = - (typeof ChainId)['megaeth-testnet' | 'monad-testnet']; +export type AdditionalDefaultNetwork = (typeof ChainId)[ + | 'megaeth-testnet' + | 'monad-testnet']; From a77d247d18f25f5ca51a9c4bac35babb35bc9aef Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Sat, 3 May 2025 00:04:52 +0800 Subject: [PATCH 08/10] chore: lint --- packages/controller-utils/src/constants.ts | 8 +++++-- .../src/NetworkController.ts | 22 +------------------ 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index 66ef878345a..e7141d62de3 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -56,9 +56,13 @@ export const TESTNET_TICKER_SYMBOLS = { * Map of all built-in custom networks to their RPC endpoints. */ export const BUILT_IN_CUSTOM_NETWORKS_RPC = { + /** + * @deprecated Please use `megaeth-testnet` instead. + */ MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc', - MONAD_TESTNET: 'https://testnet-rpc.monad.xyz', -}; + 'megaeth-testnet': 'https://carrot.megaeth.com/rpc', + 'monad-testnet': 'https://testnet-rpc.monad.xyz', +} /** * Map of all build-in Infura networks to their network, ticker and chain IDs. diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index dce13e9199d..b7ddd36f0ee 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -750,9 +750,8 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record< function getCustomNetworkConfiguration( customNetworkType: CustomNetworkType, ): NetworkConfiguration { - const chainId = ChainId[customNetworkType]; const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType]; - const rpcEndpointUrl = getCustomNetworkRpcEndpointUrl(chainId); + const rpcEndpointUrl = BUILT_IN_CUSTOM_NETWORKS_RPC[customNetworkType]; return { blockExplorerUrls: [rpcPrefs.blockExplorerUrl], @@ -772,25 +771,6 @@ function getCustomNetworkConfiguration( }; } -/** - * Get the RPC endpoint URL for a custom network by supported chain ID. - * - * @param chainId - The chain ID of the custom network. - * @returns The RPC endpoint URL. - */ -function getCustomNetworkRpcEndpointUrl( - chainId: AdditionalDefaultNetwork, -): string { - switch (chainId) { - case ChainId['megaeth-testnet']: - return BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET; - case ChainId['monad-testnet']: - return BUILT_IN_CUSTOM_NETWORKS_RPC.MONAD_TESTNET; - default: - throw new Error(`Unsupported chain ID: ${chainId}`); - } -} - /** * Constructs properties for the NetworkController state whose values will be * used if not provided to the constructor. From a34db78a1be9c4642fdc4cb4044fbe1f3a4f18f9 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Sat, 3 May 2025 00:06:01 +0800 Subject: [PATCH 09/10] fix: lint --- packages/controller-utils/src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index e7141d62de3..977c15d7b0f 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -62,7 +62,7 @@ export const BUILT_IN_CUSTOM_NETWORKS_RPC = { MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc', 'megaeth-testnet': 'https://carrot.megaeth.com/rpc', 'monad-testnet': 'https://testnet-rpc.monad.xyz', -} +}; /** * Map of all build-in Infura networks to their network, ticker and chain IDs. From 7aab865a2a6e6578c4a983dc9ef763d7fa0e955b Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Tue, 6 May 2025 14:27:27 +0800 Subject: [PATCH 10/10] chore: update change log --- packages/controller-utils/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/controller-utils/CHANGELOG.md b/packages/controller-utils/CHANGELOG.md index 81e9752e703..fea476a9a66 100644 --- a/packages/controller-utils/CHANGELOG.md +++ b/packages/controller-utils/CHANGELOG.md @@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add Monad Testnet to various constants, enums, and types ([#5724](https://github.com/MetaMask/core/pull/5724)) - - Add `MONAD_TESTNET` to `TESTNET_TICKER_SYMBOLS` - Add `monad-testnet` to `BUILT_IN_NETWORKS` + - Add `monad-testnet` and `megaeth-testnet` to `BUILT_IN_CUSTOM_NETWORKS_RPC` - Add `MonadTestnet` to `BuiltInNetworkName` enum - Add `monad-testnet` to `ChainId` type - Add `MonadTestnet` to `NetworksTicker` enum