OwnerMod
Manages contract ownership using diamond storage
- Provides internal functions for ERC-173 ownership management.
- Uses diamond storage pattern (EIP-8042) for shared state.
requireOwner()enforces access control based on contract ownership.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions for managing contract ownership according to ERC-173. Facets can import this module to check ownership and transfer it using shared diamond storage. Ownership changes are immediately visible to all facets interacting with the same storage pattern.
Storage
OwnerStorage
storage-location: erc8042:compose.owner
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.owner")) |
Functions
getStorage
Returns a pointer to the ERC-173 storage struct. Uses inline assembly to access the storage slot defined by STORAGE_POSITION.
Returns:
| Property | Type | Description |
|---|---|---|
s | OwnerStorage | The OwnerStorage struct in storage. |
owner
Get the address of the owner
Returns:
| Property | Type | Description |
|---|---|---|
- | address | The address of the owner. |
requireOwner
Reverts if the caller is not the owner.
setContractOwner
Parameters:
| Property | Type | Description |
|---|---|---|
_initialOwner | address | - |
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 |
Events
Errors
Best Practices
- Call
requireOwner()in facets before executing sensitive operations. - Use
transferOwnership()to safely transfer ownership, setting toaddress(0)to renounce. - Ensure
OwnerModis initialized with the correct storage slot during diamond deployment.
Integration Notes
This module utilizes diamond storage at the STORAGE_POSITION defined by keccak256("compose.owner"). The OwnerStorage struct, containing the owner field, is accessed via inline assembly. All functions are internal, ensuring they are called by other facets within the diamond. Changes to ownership are persistent and immediately reflected across all facets accessing this storage slot.