State Variables
ModuleRegistryStorage
modules
: Maps module names to their addressesmoduleTypes
: Maps module addresses to their typesallModuleTypes
: Maps module types to their interface IDs
ModuleRegistryStorageLocation
Functions
initialize
accessManager
: The address of the governance contract.
registerModuleType
name
: The name of the module type to be registered.interfaceId
: The interface ID associated with the module type.
removeModuleType
name
: The name of the module type to be removed.
registerModule (Default Type)
name
: The name of the module.moduleAddress
: The address of the module.
registerModule (Specific Type)
name
: The name of the module to be registered.moduleAddress
: The address of the module.moduleType
: The type of the module being registered.
removeModule
name
: The name of the module to be removed.
isRegistered
moduleAddress
: The address of the module.
bool
: True if the module is registered, false otherwise.
getModule
name
: The name of the module.
address
: The address of the module.
getModuleType
moduleAddress
: The address of the module.
string
: The type of the module as a string.
getModuleTypeInterfaceId
moduleType
: The type of the module as a string.
bytes4
: The interface ID of the module type.
Internal Functions
_registerModule
name
: The name of the module.moduleAddress
: The address of the module.moduleType
: The type of the module being registered.
_getModuleRegistryStorage
ModuleRegistryStorage
: The storage structure for the ModuleRegistry.
_authorizeUpgrade
newImplementation
: The address of the new implementation.
Events
ModuleAdded
name
: The name of the module.moduleAddress
: The address of the module.moduleTypeInterfaceId
: The interface ID of the module type.moduleType
: The type of the module.
ModuleRemoved
name
: The name of the module.moduleAddress
: The address of the module.
Security Considerations
The ModuleRegistry contract implements several security measures:-
Access Control: Most functions are restricted to be called only by the protocol admin through the
restricted
modifier. -
Input Validation: The contract validates all inputs to ensure they meet the required criteria:
- Module addresses must be non-zero and must be contracts
- Names and module types cannot be empty strings
- Module types must be registered before modules of that type can be registered
- Modules must support the expected interface for their type
-
Duplicate Prevention: The contract prevents duplicate registrations:
- A module type cannot be registered twice with the same name
- A module cannot be registered twice with different names
- A name cannot be used for multiple modules
- Upgradability: The contract is upgradable using the UUPS pattern, with upgrade authorization restricted to the protocol admin.