ModuleRegistry
The ModuleRegistry contract is used to register and track modules within the Story ecosystem. It serves as a central registry for all protocol modules, allowing for easy discovery and management of different module types and implementations.
State Variables
ModuleRegistryStorage
Storage structure for the ModuleRegistry containing:
modules
: Maps module names to their addressesmoduleTypes
: Maps module addresses to their typesallModuleTypes
: Maps module types to their interface IDs
ModuleRegistryStorageLocation
The storage location for the ModuleRegistry storage structure, following ERC-7201 for namespace storage pattern.
Functions
initialize
Initializes the ModuleRegistry contract.
Parameters:
accessManager
: The address of the governance contract.
registerModuleType
Registers a new module type in the registry associated with an interface.
Parameters:
name
: The name of the module type to be registered.interfaceId
: The interface ID associated with the module type.
removeModuleType
Removes a module type from the registry.
Parameters:
name
: The name of the module type to be removed.
registerModule (Default Type)
Registers a new module in the registry with the default module type.
Parameters:
name
: The name of the module.moduleAddress
: The address of the module.
registerModule (Specific Type)
Registers a new module in the registry with a specific module type.
Parameters:
name
: The name of the module to be registered.moduleAddress
: The address of the module.moduleType
: The type of the module being registered.
removeModule
Removes a module from the registry.
Parameters:
name
: The name of the module to be removed.
isRegistered
Checks if a module is registered in the protocol.
Parameters:
moduleAddress
: The address of the module.
Returns:
bool
: True if the module is registered, false otherwise.
getModule
Returns the address of a module.
Parameters:
name
: The name of the module.
Returns:
address
: The address of the module.
getModuleType
Returns the module type of a given module address.
Parameters:
moduleAddress
: The address of the module.
Returns:
string
: The type of the module as a string.
getModuleTypeInterfaceId
Returns the interface ID associated with a given module type.
Parameters:
moduleType
: The type of the module as a string.
Returns:
bytes4
: The interface ID of the module type.
Internal Functions
_registerModule
Internal function to register a new module in the registry.
Parameters:
name
: The name of the module.moduleAddress
: The address of the module.moduleType
: The type of the module being registered.
_getModuleRegistryStorage
Returns the storage struct of the ModuleRegistry.
Returns:
ModuleRegistryStorage
: The storage structure for the ModuleRegistry.
_authorizeUpgrade
Hook to authorize the upgrade according to UUPSUpgradeable.
Parameters:
newImplementation
: The address of the new implementation.
Events
ModuleAdded
Emitted when a new module is added to the registry.
Parameters:
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
Emitted when a module is removed from the registry.
Parameters:
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.