Skip to main content

OwnerMod

Manages contract ownership using diamond storage

Key Features
  • Provides internal functions for ERC-173 ownership management.
  • Uses diamond storage pattern (EIP-8042) for shared state.
  • requireOwner() enforces access control based on contract ownership.
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 managing contract ownership according to ERC-173. Facets can import this module to check ownership and transfer it using shared diamond storage. Ownership changes are immediately visible to all facets interacting with the same storage pattern.


Storage

OwnerStorage

storage-location: erc8042:compose.owner

Definition
struct OwnerStorage {
address owner;
}

State Variables

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

Functions

getStorage

Returns a pointer to the ERC-173 storage struct. Uses inline assembly to access the storage slot defined by STORAGE_POSITION.

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

Returns:

PropertyTypeDescription
sOwnerStorageThe OwnerStorage struct in storage.

owner

Get the address of the owner

function owner() view returns (address);

Returns:

PropertyTypeDescription
-addressThe address of the owner.

requireOwner

Reverts if the caller is not the owner.

function requireOwner() view;

setContractOwner

function setContractOwner(address _initialOwner) ;

Parameters:

PropertyTypeDescription
_initialOwneraddress-

transferOwnership

Set the address of the new owner of the contract Set _newOwner to address(0) to renounce any ownership.

function transferOwnership(address _newOwner) ;

Parameters:

PropertyTypeDescription
_newOwneraddressThe address of the new owner of the contract

Events

Errors

Best Practices

Best Practice
  • Call requireOwner() in facets before executing sensitive operations.
  • Use transferOwnership() to safely transfer ownership, setting to address(0) to renounce.
  • Ensure OwnerMod is initialized with the correct storage slot during diamond deployment.

Integration Notes

Shared Storage

This module utilizes diamond storage at the STORAGE_POSITION defined by keccak256("compose.owner"). The OwnerStorage struct, containing the owner field, is accessed via inline assembly. All functions are internal, ensuring they are called by other facets within the diamond. Changes to ownership are persistent and immediately reflected across all facets accessing this storage slot.

Was this helpful?
Last updated: