Skip to main content

Owner Two Step Transfer Module

Two-step ERC-173 ownership transfer logic

Key Features
  • 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 OwnershipTransferStarted and OwnershipTransferred events for off-chain monitoring.
Module Usage

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

Definition
struct OwnerStorage {
address owner;
}

PendingOwnerStorage

storage-location: erc8042:erc173.owner.pending

Definition
struct PendingOwnerStorage {
address pendingOwner;
}

State Variables

PropertyTypeDescription
OWNER_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc173.owner"))
PENDING_OWNER_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc173.owner.pending"))

Functions

acceptOwnership

Finalizes ownership transfer. Only the pending owner can call this function.

function acceptOwnership() ;

getOwnerStorage

Returns a pointer to the Owner storage struct. Uses inline assembly to access the storage slot defined by OWNER_STORAGE_POSITION.

function getOwnerStorage() pure returns (OwnerStorage storage s);

Returns:

PropertyTypeDescription
sOwnerStorageThe 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.

function getPendingOwnerStorage() pure returns (PendingOwnerStorage storage s);

Returns:

PropertyTypeDescription
sPendingOwnerStorageThe PendingOwnerStorage struct in storage.

transferOwnership

Initiates a two-step ownership transfer.

function transferOwnership(address _newOwner) ;

Parameters:

PropertyTypeDescription
_newOwneraddressThe address of the new owner of the contract.

Events

Errors

Best Practices

Best Practice
  • Ensure the transferOwnership function is called only by the current owner to prevent unauthorized transfer initiation.
  • Verify that acceptOwnership is called by the correct pending owner before finalizing the transfer.
  • Handle the OwnerUnauthorizedAccount error, which is emitted when unauthorized accounts attempt to perform ownership-related actions.

Integration Notes

Shared Storage

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.