Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/controller-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions packages/controller-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
8 changes: 7 additions & 1 deletion packages/controller-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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',
Expand All @@ -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)
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/network-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
36 changes: 34 additions & 2 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -823,9 +824,28 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record<
Hex,
NetworkConfiguration
> {
const reverseFallbackInfuraNetworkTypeMapping = Object.entries(
FALLBACK_INFURA_NETWORK_TYPE_MAPPING,
).reduce<Record<InfuraNetworkType, string>>(
(reversed, [key, value]) => {
reversed[value] = key;
return reversed;
},
{} as Record<InfuraNetworkType, string>,
);

return Object.values(InfuraNetworkType).reduce<
Record<Hex, NetworkConfiguration>
>((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.
Expand All @@ -845,7 +865,7 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record<
rpcEndpoints: [
{
failoverUrls: [],
networkClientId: infuraNetworkType,
networkClientId: _infuraNetworkType,
type: RpcEndpointType.Infura,
url: rpcEndpointUrl,
},
Expand Down Expand Up @@ -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}'`);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/network-controller/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InfuraNetworkType } from "@metamask/controller-utils";

Check failure on line 1 in packages/network-controller/src/constants.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Replace `"@metamask/controller-utils"` with `'@metamask/controller-utils'`

/**
* Represents the availability status of an RPC endpoint. (Regrettably, the
* name of this type is a misnomer.)
Expand Down Expand Up @@ -41,3 +43,13 @@
* without the need to remove the network from constant list of controller-utils.
*/
export const DEPRECATED_NETWORKS = new Set<string>(['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<string, InfuraNetworkType> = {

Check failure on line 53 in packages/network-controller/src/constants.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Replace `string,·InfuraNetworkType` with `⏎··string,⏎··InfuraNetworkType⏎`
'monad-testnet': 'monad-testnet-infura',
}

Check failure on line 55 in packages/network-controller/src/constants.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Insert `;`
Loading