Skip to main content

OwnerTwoStepsMod

Two-step ownership transfer for diamonds

Key Features
  • 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(), and renounceOwnership() functions.
Module Usage

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

Definition
struct OwnerStorage {
address owner;
}

PendingOwnerStorage

storage-location: erc8042:compose.owner.pending

Definition
struct PendingOwnerStorage {
address pendingOwner;
}

State Variables

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

Functions

acceptOwnership

Finalizes ownership transfer; must be called by the pending owner.

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.

owner

Returns the current owner.

function owner() view returns (address);

pendingOwner

Returns the pending owner (if any).

function pendingOwner() view returns (address);

renounceOwnership

Renounce ownership of the contract Sets the owner to address(0), disabling all functions restricted to the owner.

function renounceOwnership() ;

requireOwner

Reverts if the caller is not the owner.

function requireOwner() view;

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
  • Call transferOwnership only from the current owner.
  • Call acceptOwnership only from the pending owner.
  • Use requireOwner() within facets to enforce owner-only access to critical functions.

Integration Notes

Shared Storage

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.

Was this helpful?
Last updated: