OwnerTwoStepsMod
Two-step ownership transfer for diamonds
- Implements ERC-173 two-step ownership transfer logic.
- Uses internal functions for seamless integration with facets.
- Leverages diamond storage for shared ownership state.
- Provides
owner(),pendingOwner(),transferOwnership(),acceptOwnership(), andrenounceOwnership()functions.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module facilitates a secure, two-step ownership transfer process for diamonds. By separating the initiation and finalization of ownership changes, it prevents accidental or malicious takeovers. Facets can import this module to manage ownership responsibilities within the diamond storage pattern.
Storage
OwnerStorage
storage-location: erc8042:compose.owner
PendingOwnerStorage
storage-location: erc8042:compose.owner.pending
State Variables
| Property | Type | Description |
|---|---|---|
OWNER_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.owner")) |
PENDING_OWNER_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.owner.pending")) |
Functions
acceptOwnership
Finalizes ownership transfer; must be called by the pending owner.
getOwnerStorage
Returns a pointer to the Owner storage struct. Uses inline assembly to access the storage slot defined by OWNER_STORAGE_POSITION.
Returns:
| Property | Type | Description |
|---|---|---|
s | OwnerStorage | The OwnerStorage struct in storage. |
getPendingOwnerStorage
Returns a pointer to the PendingOwner storage struct. Uses inline assembly to access the storage slot defined by PENDING_OWNER_STORAGE_POSITION.
Returns:
| Property | Type | Description |
|---|---|---|
s | PendingOwnerStorage | The PendingOwnerStorage struct in storage. |
owner
Returns the current owner.
pendingOwner
Returns the pending owner (if any).
renounceOwnership
Renounce ownership of the contract Sets the owner to address(0), disabling all functions restricted to the owner.
requireOwner
Reverts if the caller is not the owner.
transferOwnership
Initiates a two-step ownership transfer.
Parameters:
| Property | Type | Description |
|---|---|---|
_newOwner | address | The address of the new owner of the contract |
Events
Errors
Best Practices
- Call
transferOwnershiponly from the current owner. - Call
acceptOwnershiponly from the pending owner. - Use
requireOwner()within facets to enforce owner-only access to critical functions.
Integration Notes
This module manages ownership state within diamond storage. It utilizes specific storage slots (OWNER_STORAGE_POSITION and PENDING_OWNER_STORAGE_POSITION) to store the owner and pendingOwner values, respectively. All functions interact with these storage locations directly via inline assembly, ensuring that changes are immediately visible to any facet interacting with the same diamond storage pattern.