Owner Two Step Transfer Module
Two-step ERC-173 ownership transfer logic
- Implements ERC-173 two-step ownership transfer logic.
- All functions are
internal, intended for use by other facets within a diamond. - Utilizes diamond storage pattern for ownership state management.
- Emits
OwnershipTransferStartedandOwnershipTransferredevents for off-chain monitoring.
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 initiating and accepting ERC-173 ownership transfers. Facets can integrate this module to manage ownership changes within the diamond. Ownership changes are finalized through a two-step process, ensuring that the new owner explicitly accepts the transfer.
Storage
OwnerStorage
storage-location: erc8042:erc173.owner
PendingOwnerStorage
storage-location: erc8042:erc173.owner.pending
State Variables
| Property | Type | Description |
|---|---|---|
OWNER_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc173.owner")) |
PENDING_OWNER_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc173.owner.pending")) |
Functions
acceptOwnership
Finalizes ownership transfer. Only the pending owner can call this function.
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. |
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
- Ensure the
transferOwnershipfunction is called only by the current owner to prevent unauthorized transfer initiation. - Verify that
acceptOwnershipis called by the correct pending owner before finalizing the transfer. - Handle the
OwnerUnauthorizedAccounterror, which is emitted when unauthorized accounts attempt to perform ownership-related actions.
Integration Notes
This module interacts with two primary storage slots within the diamond's shared storage: OWNER_STORAGE_POSITION for the current owner and PENDING_OWNER_STORAGE_POSITION for the pending owner. The getOwnerStorage and getPendingOwnerStorage functions provide direct access pointers to these storage locations using inline assembly. Changes made via transferOwnership and acceptOwnership modify these shared storage slots, making them immediately visible to any other facet that accesses the same storage positions.