Skip to main content

OwnerTwoStepsFacet

Manage diamond ownership and transfers

Key Features
  • Manages diamond ownership via a two-step transfer process.
  • Exposes owner() and pendingOwner() view functions.
  • Provides transferOwnership(), acceptOwnership(), and renounceOwnership() external functions.
  • Utilizes dedicated storage slots for owner and pending owner state.

Overview

This facet provides ownership management for a diamond, enabling secure transfers and renouncements. It exposes external functions to view current and pending owners, initiate ownership transfers, and accept or renounce ownership, all integrated within the diamond proxy pattern.


Storage

OwnerStorage

Definition
struct OwnerStorage {
address owner;
}

PendingOwnerStorage

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

owner

Get the address of the owner

function owner() external view returns (address);

Returns:

PropertyTypeDescription
-addressThe address of the owner.

pendingOwner

Get the address of the pending owner

function pendingOwner() external view returns (address);

Returns:

PropertyTypeDescription
-addressThe address of the pending owner.

transferOwnership

Set the address of the new owner of the contract

function transferOwnership(address _newOwner) external;

Parameters:

PropertyTypeDescription
_newOwneraddressThe address of the new owner of the contract

acceptOwnership

function acceptOwnership() external;

renounceOwnership

function renounceOwnership() external;

Events

Errors

Best Practices

Best Practice
  • Initialize ownership during diamond deployment using transferOwnership.
  • Ensure the current owner calls transferOwnership to initiate a transfer.
  • The new owner must call acceptOwnership to finalize the transfer.
  • Use renounceOwnership with caution to remove ownership permanently.

Security Considerations

Security

The transferOwnership function can only be called by the current owner. The acceptOwnership function can only be called by the pending owner. The renounceOwnership function can only be called by the current owner. All state-changing functions enforce these access controls to prevent unauthorized actions. Follow standard Solidity security practices for input validation.

Was this helpful?
Last updated: