UNPKG

@metamask/multichain-network-controller

Version:
1 lines 6.6 kB
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA0Ba,QAAA,kCAAkC,GAAG,6BAA6B,CAAC","sourcesContent":["import type { AccountsControllerListMultichainAccountsAction } from '@metamask/accounts-controller';\nimport {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n BtcScope,\n CaipAssetType,\n CaipChainId,\n SolScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\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 { MultichainNetworkController } from './MultichainNetworkController/MultichainNetworkController';\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.Signet\n | SolScope.Mainnet\n | SolScope.Testnet\n | SolScope.Devnet;\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\nexport type SetActiveNetworkMethod = (\n id: SupportedCaipChainId | NetworkClientId,\n) => Promise<void>;\n\nexport type MultichainNetworkControllerSetActiveNetworkAction = {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:setActiveNetwork`;\n handler: SetActiveNetworkMethod;\n};\n\nexport type MultichainNetworkControllerGetNetworksWithTransactionActivityByAccountsAction =\n {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:getNetworksWithTransactionActivityByAccounts`;\n handler: MultichainNetworkController['getNetworksWithTransactionActivityByAccounts'];\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 | MultichainNetworkControllerSetActiveNetworkAction\n | MultichainNetworkControllerGetNetworksWithTransactionActivityByAccountsAction;\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 */\nexport type 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 */\nexport type AllowedEvents = AccountsControllerSelectedAccountChangeEvent;\n\nexport type MultichainNetworkControllerAllowedActions =\n | MultichainNetworkControllerActions\n | AllowedActions;\n\nexport type MultichainNetworkControllerAllowedEvents =\n | MultichainNetworkControllerEvents\n | AllowedEvents;\n\n/**\n * Messenger type for the MultichainNetworkController.\n */\nexport type MultichainNetworkControllerMessenger = RestrictedMessenger<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerAllowedActions,\n MultichainNetworkControllerAllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}