Skip to content

Commit b2b6d21

Browse files
feat: add Monad Testnet to network-controller and controller-utils (#5724)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR is to add Monad Testnet as default network on `network-controller` default state - `networkConfigurationsByChainId` with the constants and type from the latest `controller-utils` ### Changes: - Refactor `network-controller` methods`getDefaultCustomNetworkConfigurationsByChainId` to build the configuration from `CustomNetworkType` instead of hardcode network 1 by 1 - Add `Monad Testnet` info into `controller-utils` - Include `Monad Testnet` into `network-controller` method `getDefaultCustomNetworkConfigurationsByChainId` Integration PR in mobile: MetaMask/metamask-mobile#14963 <img width="300" alt="image" src="https://github.com/user-attachments/assets/5f4b5bd7-d4f2-4edb-9e03-43b08206276a" /> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Changelog <!-- THIS SECTION IS NO LONGER NEEDED. The process for updating changelogs has changed. Please consult the "Updating changelogs" section of the Contributing doc for more. --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent f0742fa commit b2b6d21

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

packages/controller-utils/CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add Monad Testnet to various constants, enums, and types ([#5724](https://github.com/MetaMask/core/pull/5724))
13+
- Add `monad-testnet` to `BUILT_IN_NETWORKS`
14+
- Add `monad-testnet` and `megaeth-testnet` to `BUILT_IN_CUSTOM_NETWORKS_RPC`
15+
- Add `MonadTestnet` to `BuiltInNetworkName` enum
16+
- Add `monad-testnet` to `ChainId` type
17+
- Add `MonadTestnet` to `NetworksTicker` enum
18+
- Add `MonadTestnet` to `BlockExplorerUrl` quasi-enum
19+
- Add `MonadTestnet` to `NetworkNickname` quasi-enum
20+
1021
## [11.7.0]
1122

1223
### Added

packages/controller-utils/src/constants.ts

+12
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ export const TESTNET_TICKER_SYMBOLS = {
5656
* Map of all built-in custom networks to their RPC endpoints.
5757
*/
5858
export const BUILT_IN_CUSTOM_NETWORKS_RPC = {
59+
/**
60+
* @deprecated Please use `megaeth-testnet` instead.
61+
*/
5962
MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc',
63+
'megaeth-testnet': 'https://carrot.megaeth.com/rpc',
64+
'monad-testnet': 'https://testnet-rpc.monad.xyz',
6065
};
6166

6267
/**
@@ -112,6 +117,13 @@ export const BUILT_IN_NETWORKS = {
112117
blockExplorerUrl: BlockExplorerUrl['megaeth-testnet'],
113118
},
114119
},
120+
[NetworkType['monad-testnet']]: {
121+
chainId: ChainId['monad-testnet'],
122+
ticker: NetworksTicker['monad-testnet'],
123+
rpcPrefs: {
124+
blockExplorerUrl: BlockExplorerUrl['monad-testnet'],
125+
},
126+
},
115127
[NetworkType.rpc]: {
116128
chainId: undefined,
117129
blockExplorerUrl: undefined,

packages/controller-utils/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type InfuraNetworkType =
1818
*/
1919
export const CustomNetworkType = {
2020
'megaeth-testnet': 'megaeth-testnet',
21+
'monad-testnet': 'monad-testnet',
2122
} as const;
2223
export type CustomNetworkType =
2324
(typeof CustomNetworkType)[keyof typeof CustomNetworkType];
@@ -76,6 +77,7 @@ export enum BuiltInNetworkName {
7677
LineaMainnet = 'linea-mainnet',
7778
Aurora = 'aurora',
7879
MegaETHTestnet = 'megaeth-testnet',
80+
MonadTestnet = 'monad-testnet',
7981
}
8082

8183
/**
@@ -92,6 +94,7 @@ export const ChainId = {
9294
[BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)
9395
[BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)
9496
[BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)
97+
[BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)
9598
} as const;
9699
export type ChainId = (typeof ChainId)[keyof typeof ChainId];
97100

@@ -109,6 +112,7 @@ export enum NetworksTicker {
109112
'linea-sepolia' = 'LineaETH',
110113
'linea-mainnet' = 'ETH',
111114
'megaeth-testnet' = 'MegaETH',
115+
'monad-testnet' = 'MON',
112116
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
113117
// eslint-disable-next-line @typescript-eslint/naming-convention
114118
rpc = '',
@@ -122,6 +126,7 @@ export const BlockExplorerUrl = {
122126
[BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',
123127
[BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',
124128
[BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',
129+
[BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',
125130
} as const satisfies Record<BuiltInNetworkType, string>;
126131
export type BlockExplorerUrl =
127132
(typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];
@@ -134,6 +139,7 @@ export const NetworkNickname = {
134139
[BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',
135140
[BuiltInNetworkName.LineaMainnet]: 'Linea',
136141
[BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',
142+
[BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',
137143
} as const satisfies Record<BuiltInNetworkType, string>;
138144
export type NetworkNickname =
139145
(typeof NetworkNickname)[keyof typeof NetworkNickname];

packages/network-controller/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add Monad Testnet as default network ([#5724](https://github.com/MetaMask/core/pull/5724))
13+
1014
## [23.3.0]
1115

1216
### Added

packages/network-controller/src/NetworkController.ts

+40-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BaseController } from '@metamask/base-controller';
77
import type { Partialize } from '@metamask/controller-utils';
88
import {
99
InfuraNetworkType,
10+
CustomNetworkType,
1011
NetworkType,
1112
isSafeChainId,
1213
isInfuraNetworkType,
@@ -15,7 +16,6 @@ import {
1516
NetworkNickname,
1617
BUILT_IN_CUSTOM_NETWORKS_RPC,
1718
BUILT_IN_NETWORKS,
18-
BuiltInNetworkName,
1919
} from '@metamask/controller-utils';
2020
import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker';
2121
import EthQuery from '@metamask/eth-query';
@@ -728,25 +728,46 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record<
728728
Hex,
729729
NetworkConfiguration
730730
> {
731-
const { ticker, rpcPrefs } =
732-
BUILT_IN_NETWORKS[BuiltInNetworkName.MegaETHTestnet];
731+
// Create the `networkConfigurationsByChainId` objects explicitly,
732+
// Because it is not always guaranteed that the custom networks are included in the
733+
// default networks.
733734
return {
734-
[ChainId[BuiltInNetworkName.MegaETHTestnet]]: {
735-
blockExplorerUrls: [rpcPrefs.blockExplorerUrl],
736-
chainId: ChainId[BuiltInNetworkName.MegaETHTestnet],
737-
defaultRpcEndpointIndex: 0,
738-
defaultBlockExplorerUrlIndex: 0,
739-
name: NetworkNickname[BuiltInNetworkName.MegaETHTestnet],
740-
nativeCurrency: ticker,
741-
rpcEndpoints: [
742-
{
743-
failoverUrls: [],
744-
networkClientId: BuiltInNetworkName.MegaETHTestnet,
745-
type: RpcEndpointType.Custom,
746-
url: BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET,
747-
},
748-
],
749-
},
735+
[ChainId['megaeth-testnet']]: getCustomNetworkConfiguration(
736+
CustomNetworkType['megaeth-testnet'],
737+
),
738+
[ChainId['monad-testnet']]: getCustomNetworkConfiguration(
739+
CustomNetworkType['monad-testnet'],
740+
),
741+
};
742+
}
743+
744+
/**
745+
* Constructs a `NetworkConfiguration` object by `CustomNetworkType`.
746+
*
747+
* @param customNetworkType - The type of the custom network.
748+
* @returns The `NetworkConfiguration` object.
749+
*/
750+
function getCustomNetworkConfiguration(
751+
customNetworkType: CustomNetworkType,
752+
): NetworkConfiguration {
753+
const { ticker, rpcPrefs } = BUILT_IN_NETWORKS[customNetworkType];
754+
const rpcEndpointUrl = BUILT_IN_CUSTOM_NETWORKS_RPC[customNetworkType];
755+
756+
return {
757+
blockExplorerUrls: [rpcPrefs.blockExplorerUrl],
758+
chainId: ChainId[customNetworkType],
759+
defaultRpcEndpointIndex: 0,
760+
defaultBlockExplorerUrlIndex: 0,
761+
name: NetworkNickname[customNetworkType],
762+
nativeCurrency: ticker,
763+
rpcEndpoints: [
764+
{
765+
failoverUrls: [],
766+
networkClientId: customNetworkType,
767+
type: RpcEndpointType.Custom,
768+
url: rpcEndpointUrl,
769+
},
770+
],
750771
};
751772
}
752773

packages/network-controller/src/types.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ChainId, InfuraNetworkType } from '@metamask/controller-utils';
1+
import type { InfuraNetworkType, ChainId } from '@metamask/controller-utils';
22
import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker';
33
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
44
import type { Hex } from '@metamask/utils';
@@ -57,4 +57,6 @@ export type NetworkClientConfiguration =
5757
/**
5858
* The Chain ID representing the additional networks to be included as default.
5959
*/
60-
export type AdditionalDefaultNetwork = (typeof ChainId)['megaeth-testnet'];
60+
export type AdditionalDefaultNetwork = (typeof ChainId)[
61+
| 'megaeth-testnet'
62+
| 'monad-testnet'];

0 commit comments

Comments
 (0)