OwnerFacet
Manages diamond contract ownership and transfers
- Provides external view function
owner()to check contract ownership. - Supports ownership transfer via
transferOwnership(address). - Allows ownership renouncement via
renounceOwnership(). - Utilizes diamond storage for owner state.
Overview
This facet implements ownership management for a diamond contract. It exposes functions to view the current owner, transfer ownership to a new address, and renounce ownership entirely. Developers integrate this facet to establish clear ownership and control over diamond upgradeability and configuration.
Storage
OwnerStorage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.owner")) |
Functions
owner
Get the address of the owner
Returns:
| Property | Type | Description |
|---|---|---|
- | address | The address of the owner. |
transferOwnership
Set the address of the new owner of the contract Set _newOwner to address(0) to renounce any ownership.
Parameters:
| Property | Type | Description |
|---|---|---|
_newOwner | address | The address of the new owner of the contract |
renounceOwnership
Events
Errors
Best Practices
- Initialize the owner address during diamond deployment.
- Enforce ownership checks on sensitive functions through the
owner()view function. - Use
transferOwnershipfor planned ownership changes andrenounceOwnershipwith extreme caution.
Security Considerations
The transferOwnership function allows setting the owner to address(0), effectively renouncing ownership. Ensure this action is intended before execution. All state-changing functions are implicitly protected by the owner role, as only the current owner can call transferOwnership and renounceOwnership through the diamond proxy.