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
2 changes: 1 addition & 1 deletion eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@
"count": 2
},
"id-length": {
"count": 7
"count": 4
}
},
"packages/network-enablement-controller/src/selectors.ts": {
Expand Down
98 changes: 98 additions & 0 deletions packages/controller-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ export const BUILT_IN_CUSTOM_NETWORKS_RPC = {
'megaeth-testnet': 'https://carrot.megaeth.com/rpc',
'megaeth-testnet-v2': 'https://carrot.megaeth.com/rpc',
'monad-testnet': 'https://testnet-rpc.monad.xyz',
// New additions for 20+ network performance testing
'fantom-mainnet': 'https://rpc.ftm.tools',
'gnosis-mainnet': 'https://rpc.gnosischain.com',
'celo-mainnet': 'https://forno.celo.org',
'cronos-mainnet': 'https://evm.cronos.org',
aurora: 'https://mainnet.aurora.dev',
'moonbeam-mainnet': 'https://rpc.api.moonbeam.network',
'moonriver-mainnet': 'https://rpc.api.moonriver.moonbeam.network',
'klaytn-mainnet': 'https://public-en-cypress.klaytn.net',
'avalanche-mainnet': 'https://api.avax.network/ext/bc/C/rpc',
'zksync-era-mainnet': 'https://mainnet.era.zksync.io',
'palm-mainnet': 'https://palm-mainnet.public.blastapi.io',
'hypervm-mainnet': 'https://rpc.hyperliquid.xyz',
};

/**
Expand Down Expand Up @@ -178,6 +191,91 @@ export const BUILT_IN_NETWORKS = {
blockExplorerUrl: BlockExplorerUrl['sei-mainnet'],
},
},
// New additions for 20+ network performance testing
[NetworkType['fantom-mainnet']]: {
chainId: ChainId['fantom-mainnet'],
ticker: NetworksTicker['fantom-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['fantom-mainnet'],
},
},
[NetworkType['gnosis-mainnet']]: {
chainId: ChainId['gnosis-mainnet'],
ticker: NetworksTicker['gnosis-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['gnosis-mainnet'],
},
},
[NetworkType['celo-mainnet']]: {
chainId: ChainId['celo-mainnet'],
ticker: NetworksTicker['celo-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['celo-mainnet'],
},
},
[NetworkType['cronos-mainnet']]: {
chainId: ChainId['cronos-mainnet'],
ticker: NetworksTicker['cronos-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['cronos-mainnet'],
},
},
[NetworkType.aurora]: {
chainId: ChainId.aurora,
ticker: NetworksTicker.aurora,
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl.aurora,
},
},
[NetworkType['moonbeam-mainnet']]: {
chainId: ChainId['moonbeam-mainnet'],
ticker: NetworksTicker['moonbeam-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['moonbeam-mainnet'],
},
},
[NetworkType['moonriver-mainnet']]: {
chainId: ChainId['moonriver-mainnet'],
ticker: NetworksTicker['moonriver-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['moonriver-mainnet'],
},
},
[NetworkType['klaytn-mainnet']]: {
chainId: ChainId['klaytn-mainnet'],
ticker: NetworksTicker['klaytn-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['klaytn-mainnet'],
},
},
[NetworkType['avalanche-mainnet']]: {
chainId: ChainId['avalanche-mainnet'],
ticker: NetworksTicker['avalanche-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['avalanche-mainnet'],
},
},
[NetworkType['zksync-era-mainnet']]: {
chainId: ChainId['zksync-era-mainnet'],
ticker: NetworksTicker['zksync-era-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['zksync-era-mainnet'],
},
},
[NetworkType['palm-mainnet']]: {
chainId: ChainId['palm-mainnet'],
ticker: NetworksTicker['palm-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['palm-mainnet'],
},
},
[NetworkType['hypervm-mainnet']]: {
chainId: ChainId['hypervm-mainnet'],
ticker: NetworksTicker['hypervm-mainnet'],
rpcPrefs: {
blockExplorerUrl: BlockExplorerUrl['hypervm-mainnet'],
},
},
[NetworkType.rpc]: {
chainId: undefined,
blockExplorerUrl: undefined,
Expand Down
78 changes: 78 additions & 0 deletions packages/controller-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export const CustomNetworkType = {
'megaeth-testnet': 'megaeth-testnet',
'megaeth-testnet-v2': 'megaeth-testnet-v2',
'monad-testnet': 'monad-testnet',
// New additions for 20+ network performance testing
'fantom-mainnet': 'fantom-mainnet',
'gnosis-mainnet': 'gnosis-mainnet',
'celo-mainnet': 'celo-mainnet',
'cronos-mainnet': 'cronos-mainnet',
aurora: 'aurora',
'moonbeam-mainnet': 'moonbeam-mainnet',
'moonriver-mainnet': 'moonriver-mainnet',
'klaytn-mainnet': 'klaytn-mainnet',
'avalanche-mainnet': 'avalanche-mainnet',
'zksync-era-mainnet': 'zksync-era-mainnet',
'palm-mainnet': 'palm-mainnet',
'hypervm-mainnet': 'hypervm-mainnet',
} as const;
export type CustomNetworkType =
(typeof CustomNetworkType)[keyof typeof CustomNetworkType];
Expand Down Expand Up @@ -98,6 +111,18 @@ export enum BuiltInNetworkName {
OptimismMainnet = 'optimism-mainnet',
PolygonMainnet = 'polygon-mainnet',
SeiMainnet = 'sei-mainnet',
// New additions for 20+ network performance testing
FantomMainnet = 'fantom-mainnet',
GnosisMainnet = 'gnosis-mainnet',
CeloMainnet = 'celo-mainnet',
CronosMainnet = 'cronos-mainnet',
MoonbeamMainnet = 'moonbeam-mainnet',
MoonriverMainnet = 'moonriver-mainnet',
KlaytnMainnet = 'klaytn-mainnet',
AvalancheMainnet = 'avalanche-mainnet',
ZkSyncEraMainnet = 'zksync-era-mainnet',
PalmMainnet = 'palm-mainnet',
HyperEvmMainnet = 'hypervm-mainnet',
}

/**
Expand Down Expand Up @@ -125,6 +150,18 @@ export const ChainId = {
[BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)
// New additions for 20+ network performance testing
[BuiltInNetworkName.FantomMainnet]: '0xfa', // toHex(250)
[BuiltInNetworkName.GnosisMainnet]: '0x64', // toHex(100)
[BuiltInNetworkName.CeloMainnet]: '0xa4ec', // toHex(42220)
[BuiltInNetworkName.CronosMainnet]: '0x19', // toHex(25)
[BuiltInNetworkName.MoonbeamMainnet]: '0x504', // toHex(1284)
[BuiltInNetworkName.MoonriverMainnet]: '0x505', // toHex(1285)
[BuiltInNetworkName.KlaytnMainnet]: '0x2019', // toHex(8217)
[BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)
[BuiltInNetworkName.ZkSyncEraMainnet]: '0x144', // toHex(324)
[BuiltInNetworkName.PalmMainnet]: '0x2a15c308d', // toHex(11297108109)
[BuiltInNetworkName.HyperEvmMainnet]: '0x3e7', // toHex(999)
} as const;
export type ChainId = (typeof ChainId)[keyof typeof ChainId];

Expand Down Expand Up @@ -154,6 +191,21 @@ export enum NetworksTicker {
'optimism-mainnet' = 'ETH',
'polygon-mainnet' = 'POL',
'sei-mainnet' = 'SEI',
// New additions for 20+ network performance testing
'fantom-mainnet' = 'FTM',
'gnosis-mainnet' = 'XDAI',
'celo-mainnet' = 'CELO',
'cronos-mainnet' = 'CRO',
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
aurora = 'ETH',
'moonbeam-mainnet' = 'GLMR',
'moonriver-mainnet' = 'MOVR',
'klaytn-mainnet' = 'KLAY',
'avalanche-mainnet' = 'AVAX',
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
'zksync-era-mainnet' = 'ETH',
'palm-mainnet' = 'PALM',
'hypervm-mainnet' = 'HYPE',
rpc = '',
}
/* eslint-enable @typescript-eslint/naming-convention */
Expand All @@ -178,6 +230,19 @@ export const BlockExplorerUrl = {
[BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',
[BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',
[BuiltInNetworkName.SeiMainnet]: 'https://seitrace.com',
// New additions for 20+ network performance testing
[BuiltInNetworkName.FantomMainnet]: 'https://ftmscan.com',
[BuiltInNetworkName.GnosisMainnet]: 'https://gnosisscan.io',
[BuiltInNetworkName.CeloMainnet]: 'https://celoscan.io',
[BuiltInNetworkName.CronosMainnet]: 'https://cronoscan.com',
[BuiltInNetworkName.Aurora]: 'https://aurorascan.dev',
[BuiltInNetworkName.MoonbeamMainnet]: 'https://moonscan.io',
[BuiltInNetworkName.MoonriverMainnet]: 'https://moonriver.moonscan.io',
[BuiltInNetworkName.KlaytnMainnet]: 'https://scope.klaytn.com',
[BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',
[BuiltInNetworkName.ZkSyncEraMainnet]: 'https://explorer.zksync.io',
[BuiltInNetworkName.PalmMainnet]: 'https://explorer.palm.io',
[BuiltInNetworkName.HyperEvmMainnet]: 'https://explorer.hyperliquid.xyz',
} as const satisfies Record<BuiltInNetworkType, string>;
export type BlockExplorerUrl =
(typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];
Expand All @@ -201,6 +266,19 @@ export const NetworkNickname = {
[BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',
[BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',
[BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',
// New additions for 20+ network performance testing
[BuiltInNetworkName.FantomMainnet]: 'Fantom Opera',
[BuiltInNetworkName.GnosisMainnet]: 'Gnosis Chain',
[BuiltInNetworkName.CeloMainnet]: 'Celo',
[BuiltInNetworkName.CronosMainnet]: 'Cronos',
[BuiltInNetworkName.Aurora]: 'Aurora',
[BuiltInNetworkName.MoonbeamMainnet]: 'Moonbeam',
[BuiltInNetworkName.MoonriverMainnet]: 'Moonriver',
[BuiltInNetworkName.KlaytnMainnet]: 'Klaytn',
[BuiltInNetworkName.AvalancheMainnet]: 'Avalanche C-Chain',
[BuiltInNetworkName.ZkSyncEraMainnet]: 'zkSync Era',
[BuiltInNetworkName.PalmMainnet]: 'Palm',
[BuiltInNetworkName.HyperEvmMainnet]: 'HyperEVM',
} as const satisfies Record<BuiltInNetworkType, string>;
export type NetworkNickname =
(typeof NetworkNickname)[keyof typeof NetworkNickname];
Expand Down
47 changes: 46 additions & 1 deletion packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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';
Expand Down Expand Up @@ -868,7 +869,7 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record<
// Create the `networkConfigurationsByChainId` objects explicitly,
// Because it is not always guaranteed that the custom networks are included in the
// default networks.
return {
const configs = {
[ChainId['megaeth-testnet']]: getCustomNetworkConfiguration(
CustomNetworkType['megaeth-testnet'],
),
Expand All @@ -878,7 +879,51 @@ function getDefaultCustomNetworkConfigurationsByChainId(): Record<
[ChainId['monad-testnet']]: getCustomNetworkConfiguration(
CustomNetworkType['monad-testnet'],
),
// New additions for 20+ network performance testing
[ChainId[BuiltInNetworkName.FantomMainnet]]: getCustomNetworkConfiguration(
CustomNetworkType['fantom-mainnet'],
),
[ChainId[BuiltInNetworkName.GnosisMainnet]]: getCustomNetworkConfiguration(
CustomNetworkType['gnosis-mainnet'],
),
[ChainId[BuiltInNetworkName.CeloMainnet]]: getCustomNetworkConfiguration(
CustomNetworkType['celo-mainnet'],
),
[ChainId[BuiltInNetworkName.CronosMainnet]]: getCustomNetworkConfiguration(
CustomNetworkType['cronos-mainnet'],
),
[ChainId[BuiltInNetworkName.Aurora]]: getCustomNetworkConfiguration(
CustomNetworkType.aurora,
),
[ChainId[BuiltInNetworkName.MoonbeamMainnet]]:
getCustomNetworkConfiguration(CustomNetworkType['moonbeam-mainnet']),
[ChainId[BuiltInNetworkName.MoonriverMainnet]]:
getCustomNetworkConfiguration(CustomNetworkType['moonriver-mainnet']),
[ChainId[BuiltInNetworkName.KlaytnMainnet]]: getCustomNetworkConfiguration(
CustomNetworkType['klaytn-mainnet'],
),
[ChainId[BuiltInNetworkName.AvalancheMainnet]]:
getCustomNetworkConfiguration(CustomNetworkType['avalanche-mainnet']),
[ChainId[BuiltInNetworkName.ZkSyncEraMainnet]]:
getCustomNetworkConfiguration(CustomNetworkType['zksync-era-mainnet']),
[ChainId[BuiltInNetworkName.PalmMainnet]]: getCustomNetworkConfiguration(
CustomNetworkType['palm-mainnet'],
),
[ChainId[BuiltInNetworkName.HyperEvmMainnet]]:
getCustomNetworkConfiguration(CustomNetworkType['hypervm-mainnet']),
};

console.log(
'[NetworkController] getDefaultCustomNetworkConfigurationsByChainId - returning',
Object.keys(configs).length,
'custom network configurations',
);
console.log(
'[NetworkController] Custom network chain IDs:',
Object.keys(configs),
);

return configs;
}

/**
Expand Down
25 changes: 20 additions & 5 deletions packages/network-controller/src/create-network-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
InfuraNetworkType,
} from '@metamask/controller-utils';
import { ChainId } from '@metamask/controller-utils';

import { createThrottledFetchForChainId } from './throttled-fetch';

Check failure on line 7 in packages/network-controller/src/create-network-client.ts

View workflow job for this annotation

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

`./throttled-fetch` import should occur after import of `./rpc-service/rpc-service-chain`

import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker';
import { PollingBlockTracker } from '@metamask/eth-block-tracker';
import { createInfuraMiddleware } from '@metamask/eth-json-rpc-infura';
Expand Down Expand Up @@ -210,11 +213,23 @@
const availableEndpointUrls: [string, ...string[]] = isRpcFailoverEnabled
? [primaryEndpointUrl, ...(configuration.failoverRpcUrls ?? [])]
: [primaryEndpointUrl];
const rpcServiceConfigurations = availableEndpointUrls.map((endpointUrl) => ({
...getRpcServiceOptions(endpointUrl),
endpointUrl,
logger,
}));
const rpcServiceConfigurations = availableEndpointUrls.map((endpointUrl) => {
const options = getRpcServiceOptions(endpointUrl);

// Apply network throttling based on chain ID if configured
const throttledFetch = createThrottledFetchForChainId(
endpointUrl,
configuration.chainId,
options.fetch,
);

return {
...options,
fetch: throttledFetch,
endpointUrl,
logger,
};
});

/**
* Extracts the error from Cockatiel's `FailureReason` type received in
Expand Down
6 changes: 6 additions & 0 deletions packages/network-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ export type { NetworkClient } from './create-network-client';
export type { AbstractRpcService } from './rpc-service/abstract-rpc-service';
export type { RpcServiceRequestable } from './rpc-service/rpc-service-requestable';
export { isConnectionError } from './rpc-service/rpc-service';
export {
NETWORK_THROTTLE_CONFIG,
createThrottledFetch,
createThrottledFetchForChainId,
createThrottledGetRpcServiceOptions,
} from './throttled-fetch';
Loading
Loading