@metamask/multichain-network-controller
Version:
Multichain network controller
1 lines • 5.8 kB
Source Map (JSON)
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2BA,MAAM,CAAC,MAAM,kCAAkC,GAAG,6BAA6B,CAAC","sourcesContent":["import type { AccountsControllerListMultichainAccountsAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type {\n BtcScope,\n CaipAssetType,\n CaipChainId,\n SolScope,\n TrxScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkStatus,\n NetworkControllerSetActiveNetworkAction,\n NetworkControllerGetStateAction,\n NetworkControllerRemoveNetworkAction,\n NetworkControllerGetSelectedChainIdAction,\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkClientId,\n} from '@metamask/network-controller';\n\nimport type { ActiveNetworksByAddress } from './api/accounts-api';\nimport type { MultichainNetworkControllerMethodActions } from './MultichainNetworkController/MultichainNetworkController-method-action-types';\n\nexport const MULTICHAIN_NETWORK_CONTROLLER_NAME = 'MultichainNetworkController';\n\nexport type MultichainNetworkMetadata = {\n features: string[];\n status: NetworkStatus;\n};\n\nexport type SupportedCaipChainId =\n | BtcScope.Mainnet\n | BtcScope.Testnet\n | BtcScope.Testnet4\n | BtcScope.Signet\n | BtcScope.Regtest\n | SolScope.Mainnet\n | SolScope.Testnet\n | SolScope.Devnet\n | TrxScope.Mainnet\n | TrxScope.Nile\n | TrxScope.Shasta;\n\nexport type CommonNetworkConfiguration = {\n /**\n * EVM network flag.\n */\n isEvm: boolean;\n /**\n * The chain ID of the network.\n */\n chainId: CaipChainId;\n /**\n * The name of the network.\n */\n name: string;\n};\n\nexport type NonEvmNetworkConfiguration = CommonNetworkConfiguration & {\n /**\n * EVM network flag.\n */\n isEvm: false;\n /**\n * The native asset type of the network.\n */\n nativeCurrency: CaipAssetType;\n};\n\n// TODO: The controller only supports non-EVM network configurations at the moment\n// Once we support Caip chain IDs for EVM networks, we can re-enable EVM network configurations\nexport type EvmNetworkConfiguration = CommonNetworkConfiguration & {\n /**\n * EVM network flag.\n */\n isEvm: true;\n /**\n * The native asset type of the network.\n * For EVM, this is the network ticker since there is no standard between\n * tickers and Caip IDs.\n */\n nativeCurrency: string;\n /**\n * The block explorers of the network.\n */\n blockExplorerUrls: string[];\n /**\n * The index of the default block explorer URL.\n */\n defaultBlockExplorerUrlIndex: number;\n};\n\nexport type MultichainNetworkConfiguration =\n | EvmNetworkConfiguration\n | NonEvmNetworkConfiguration;\n\n/**\n * State used by the {@link MultichainNetworkController} to cache network configurations.\n */\nexport type MultichainNetworkControllerState = {\n /**\n * The network configurations by chain ID.\n */\n multichainNetworkConfigurationsByChainId: Record<\n CaipChainId,\n MultichainNetworkConfiguration\n >;\n /**\n * The chain ID of the selected network.\n */\n selectedMultichainNetworkChainId: SupportedCaipChainId;\n /**\n * Whether EVM or non-EVM network is selected\n */\n isEvmSelected: boolean;\n /**\n * The active networks for the available EVM addresses (non-EVM networks will be supported in the future).\n */\n networksWithTransactionActivity: ActiveNetworksByAddress;\n};\n\n/**\n * Returns the state of the {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerGetStateAction =\n ControllerGetStateAction<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerState\n >;\n\n/**\n * Event emitted when the state of the {@link MultichainNetworkController} changes.\n */\nexport type MultichainNetworkControllerStateChange = ControllerStateChangeEvent<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerState\n>;\n\nexport type MultichainNetworkControllerNetworkDidChangeEvent = {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:networkDidChange`;\n payload: [NetworkClientId | SupportedCaipChainId];\n};\n\n/**\n * Actions exposed by the {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerActions =\n | MultichainNetworkControllerGetStateAction\n | MultichainNetworkControllerMethodActions;\n\n/**\n * Events emitted by {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerEvents =\n | MultichainNetworkControllerStateChange\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n */\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerSetActiveNetworkAction\n | AccountsControllerListMultichainAccountsAction\n | NetworkControllerRemoveNetworkAction\n | NetworkControllerGetSelectedChainIdAction\n | NetworkControllerFindNetworkClientIdByChainIdAction;\n\n// Re-define event here to avoid circular dependency with AccountsController\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `AccountsController:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents = AccountsControllerSelectedAccountChangeEvent;\n\n/**\n * Messenger type for the MultichainNetworkController.\n */\nexport type MultichainNetworkControllerMessenger = Messenger<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerActions | AllowedActions,\n MultichainNetworkControllerEvents | AllowedEvents\n>;\n"]}