RegistryStore Contract Documentation
Overview
The RegistryStore contract is responsible for managing a registry of addresses that can be associated with specific registry names. This contract allows governance to set, update, and remove addresses associated with various registries. It is initialized with a permissions registry, which controls access through governance roles.
Inherits
- Initializable: From OpenZeppelin, used to make the contract upgradeable and prevent re-initialization.
- Permissions: A custom modifier to control access based on roles like governance.
Errors
-
CantSetZeroAddress()
Thrown when attempting to set a registry address to the zero address (0x0).
Reason: Registry addresses cannot be set to the zero address as this would indicate an invalid entry. -
CantSetEmptyRegistry()
Thrown when attempting to set a registry entry with an empty registry name.
Reason: The registry name cannot be empty, as it must have a valid identifier. -
NotGovernance(address sender)
Thrown when a function that requires governance access is called by an address that does not hold the governance role.
Reason: This error ensures only authorized users with the governance role can perform restricted operations.
State Variables
-
mapping(string => address) registryAddresses
A mapping that stores the addresses for different registries by registry name. The key is the registry name (string), and the value is the associated address (address). -
IRegistryStore registryAddress
A state variable storing the contract’s own address, cast to theIRegistryStoreinterface.
Events
RegistryAddressUpdated(string indexed registryName, address indexed newAddress)
Emitted when a registry address is updated.
Parameters:registryName: The name of the registry that was updated.newAddress: The new address assigned to the registry.
Functions
initialize(address _permissionsRegistry) external initializer
Initializes the contract by setting the permissions registry address. It can only be called once, as per the upgradeable pattern, and is protected by the initializer modifier from OpenZeppelin.
- Parameters:
_permissionsRegistry: The address of the permissions registry, which controls access and governance roles.-
Reverts:
-
CantSetZeroAddress: If_permissionsRegistryis the zero address (0x0). -
Functionality:
- Sets the permissions registry address in
registryAddressesunder the keyRegistryStoreLibrary.PERMISSIONS_REGISTRY_KEY. - Stores the contract's own address in
registryAddresscast asIRegistryStore.
setRegistryAddress(string calldata _registryName, address _newAddress) public onlyGovernance
Allows the governance role to update the address associated with a specific registry name.
-
Parameters:
-
_registryName: The name of the registry to be updated. -
_newAddress: The new address to associate with the given registry. -
Reverts:
-
CantSetZeroAddress: If_newAddressis the zero address. -
CantSetEmptyRegistry: If_registryNameis an empty string. -
Emits:
RegistryAddressUpdated: When a registry address is successfully updated.
removeRegistry(string calldata _registryName) public onlyGovernance
Allows the governance role to remove an entry from the registry by setting its address to the zero address.
- Parameters:
_registryName: The name of the registry to be removed.
getRegistryAddress(string calldata _registryName) public view returns (address)
Returns the address associated with the given registry name.
-
Parameters:
-
_registryName: The name of the registry to look up. -
Returns:
- The address associated with the given registry name.