Overview

FairdaoStorage Non-Interface Contracts

This documentation covers three non-interface contracts in the FairdaoStorage project: FairdaoManagement, UserDataStorage, and SharedDataStorage.

These contracts provide core DAO functionality including admin management, key management, user-specific data storage, and shared data storage.

License

SPDX-License-Identifier: GPL-3.0

Solidity Version

^0.8.24

Contracts

FairdaoManagement

FAIR DAO management contract that provides management functions for admins, owners, and key managers.

Implements the IFairdaoManager interface, handling access control, emergency stop mechanism, and key management operations.

UserDataStorage

User data storage contract responsible for managing user-specific data.

Allows key managers to store and retrieve data for specific users.

SharedDataStorage

Shared data storage contract responsible for managing data shared among all users.

Allows key managers to store and retrieve data accessible by all users.

Data Structures

Storage Structure (UserDataStorage and SharedDataStorage)

struct Storage {
    uint64 timestamp; // Timestamp
    bytes data;       // Data content
}

Structure used to store data and its timestamp.

ManagerInfo Structure (FairdaoManagement)

struct ManagerInfo {
    uint64 timestamp; // Timestamp
    bool isOwner;     // Whether the manager is an owner
}

Structure for storing manager information, including creation timestamp and owner permission flag.

Events

FairdaoManagement Events

event ManagerAdded( address indexed manager, bool isOwner, address indexed operator )
Add
indexed

Triggered when a new manager is added.

Parameters:

  • manager - The address of the added manager
  • isOwner - Whether the manager is an owner
  • operator - The address that performed the add operation
event ManagerRemoved( address indexed manager, bool wasOwner, address indexed operator )
Remove
indexed

Triggered when a manager is removed.

Parameters:

  • manager - The address of the removed manager
  • wasOwner - Whether the manager was an owner
  • operator - The address that performed the remove operation
event AddKeyManager( bytes32 indexed key, address manager, address indexed operator )
Add
indexed

Triggered when a key manager is added.

Parameters:

  • key - The key being managed
  • manager - The address of the key manager
  • operator - The address that performed the add operation
event TransferKeyManager( bytes32 indexed key, address oldManager, address newManager, address indexed operator )
Transfer
indexed

Triggered when key management permissions are transferred.

Parameters:

  • key - The key being managed
  • oldManager - The previous manager address
  • newManager - The new manager address
  • operator - The address that performed the transfer operation
event EmergencyStopped(address indexed operator)
Emergency
indexed

Triggered when emergency stop is enabled.

Parameters:

  • operator - The address that triggered emergency stop
event EmergencyResumed(address indexed operator)
Resume
indexed

Triggered when emergency stop is disabled.

Parameters:

  • operator - The address that resumed operations

UserDataStorage Events

event UserDataUpdated( address indexed user, bytes32 indexed key, uint256 dataLength, address indexed operator )
Update
indexed

Triggered when user data is updated.

Parameters:

  • user - User address
  • key - Key used to store the data
  • dataLength - Length of the stored data
  • operator - Address that performed the update operation
event FairdaoManagerSet( address indexed managerAddress, address indexed operator )
Update
indexed

Triggered when FairdaoManager address is set or updated.

Parameters:

  • managerAddress - New FairdaoManager address
  • operator - Address that performed the update operation

SharedDataStorage Events

event SharedDataUpdated( bytes32 indexed key, bytes32 indexed valueId, uint256 dataLength, address indexed operator )
Update
indexed

Triggered when shared data is updated.

Parameters:

  • key - Key used to store the data
  • valueId - Unique identifier for the value
  • dataLength - Length of the stored data
  • operator - Address that performed the update operation
event FairdaoManagerSet( address indexed managerAddress, address indexed operator )
Update
indexed

Triggered when FairdaoManager address is set or updated.

Parameters:

  • managerAddress - New FairdaoManager address
  • operator - Address that performed the update operation
Modifiers
modifier isOwner()

Checks if the caller is a contract owner.

Requirement: Caller must be a contract owner

Failure message: "Not owner"

modifier onlyManager()

Checks if the caller is a contract manager.

Requirement: Caller must be a contract manager

Failure message: "Not manager"

modifier notEmergency()

Checks if the contract is in emergency stop state.

Requirement: Contract must not be in emergency stop state

Failure message: "Emergency stop active"

Functions

FairdaoManagement Functions

constructor()

Constructor function, initializes the contract and sets the deployer address as the first owner.

function isManager(address user) external view returns (bool)

Checks if an address is a manager.

Parameters:

  • user - The address to check

Return value: bool - Whether the address is a manager

function isOwner(address user) external view returns (bool)

Checks if an address has owner privileges.

Parameters:

  • user - The address to check

Return value: bool - Whether the address has owner privileges

function addManager(address manager, bool withOwnerPermission) external isOwner notEmergency returns (bool)

Adds a new manager.

Parameters:

  • manager - New manager address
  • withOwnerPermission - Whether to grant owner permission

Return value: bool - Whether the operation succeeded

Event: ManagerAdded(manager, withOwnerPermission, msg.sender)

function getManagerCount() external view returns (uint256)

Gets the number of managers.

Return value: uint256 - Number of managers

function removeManager(uint256 index, address manager) external isOwner notEmergency returns (bool)

Removes a manager.

Parameters:

  • index - Index of the manager in the array
  • manager - Address of the manager to remove

Requirements:

  • index must be valid
  • manager must be at the specified index

Failure messages:

  • "Bad index"

Return value: bool - Whether the operation succeeded

Event: ManagerRemoved(manager, wasOwner, msg.sender)

function getManagerAtIndex(uint256 index) external view returns (address)

Gets the manager address at the specified index.

Parameters:

  • index - Index in the array

Return value: address - Manager address

function getManagerInfo(address user) external view returns (uint256 timestamp, bool isOwner)

Gets manager information for the specified address.

Parameters:

  • user - Address to get information for

Return values:

  • timestamp - Manager addition timestamp (0 if not a manager)
  • isOwner - Whether the manager has owner permissions
function isKeyManager(bytes32 key, address user) external view returns (bool)

Checks if an address is the manager of the specified key.

Parameters:

  • key - The key to check
  • user - The address to check

Return value: bool - Whether the address is a key manager

function getKeyManager(bytes32 key) external view returns (address manager)

Gets the manager address of a specific key.

Parameters:

  • key - The key to query

Return value: address - Key manager address, or address(0) if none

function addKeyManager(bytes32 key, address manager) external onlyManager notEmergency returns (bool)

Adds a manager for a single key.

Parameters:

  • key - The key to add a manager for
  • manager - Manager address

Return value: bool - Whether the operation succeeded

Event: AddKeyManager(key, manager, msg.sender)

function transferKeyManager(bytes32 key, address newManager) external notEmergency isOwner returns (bool)

Transfers key management permissions to another address.

Parameters:

  • key - The key to transfer management for
  • newManager - New manager address

Return value: bool - Whether the operation succeeded

Event: TransferKeyManager(key, oldManager, newManager, msg.sender)

function isEmergencyStopped() external view returns (bool)

Checks if the contract is in emergency stop state.

Return value: bool - Whether the contract is in emergency stop state

function enableEmergencyStop() external isOwner returns (bool)

Enables emergency stop (owner only).

Return value: bool - Whether the operation succeeded

Event: EmergencyStopped(msg.sender)

function disableEmergencyStop() external isOwner returns (bool)

Disables emergency stop (owner only).

Return value: bool - Whether the operation succeeded

Event: EmergencyResumed(msg.sender)

UserDataStorage Functions

constructor()

Constructor function, sets the contract owner to the deployer.

Parameters: None

function setFairdaoManager(address fairdaoManagerAddress) external returns (bool)

Sets the FairdaoManager contract address. The caller must be the contract owner when setting for the first time, and the specified fairdaoManagerAddress must be an owner of the FairdaoManager contract.

Parameters:

  • fairdaoManagerAddress - Address of the FairdaoManager contract

Requirements:

  • If FairdaoManager is not set, caller must be the contract owner
  • The caller must be an owner according to fairdaoManager.isOwner
  • fairdaoManagerAddress cannot be address(0)

Failure messages:

  • "Not owner"
  • "Invalid manager addr"

Return value: bool - Whether the operation succeeded

Event: FairdaoManagerSet(fairdaoManagerAddress, msg.sender)

function setUserData(address user, bytes32 key, bytes calldata data) external returns (bool)

Stores user data.

Parameters:

  • user - User address
  • key - Key to store the data
  • data - Data to be stored

Requirements:

  • FairdaoManager must be set
  • user cannot be address(0)
  • key cannot be bytes32(0)
  • Caller must be the key manager for the specified key

Failure messages:

  • "Manager not set"
  • "Zero user"
  • "Zero key"
  • "Not key manager"

Return value: bool - Whether the operation succeeded

Event: UserDataUpdated(user, key, data.length, msg.sender)

function getUserData(address user, bytes32 key) external view returns (bytes memory data, uint64 timestamp)

Gets stored user data.

Parameters:

  • user - User address
  • key - Key to retrieve data

Requirements:

  • FairdaoManager must be set
  • user cannot be address(0)
  • key cannot be bytes32(0)

Failure messages:

  • "Manager not set"
  • "Zero user"
  • "Zero key"

Return values:

  • data - Stored data
  • timestamp - Last update timestamp
function getFairdaoManager() external view returns (address)

Gets the address of the FairdaoManager contract.

Parameters: None

Return value: address - The address of the FairdaoManager contract

SharedDataStorage Functions

constructor()

Constructor function, sets the contract owner to the deployer.

Parameters: None

function setFairdaoManager(address fairdaoManagerAddress) external returns (bool)

Sets the FairdaoManager contract address. The caller must be the contract owner when setting for the first time, and the specified fairdaoManagerAddress must be an owner of the FairdaoManager contract.

Parameters:

  • fairdaoManagerAddress - Address of the FairdaoManager contract

Requirements:

  • If FairdaoManager is not set, caller must be the contract owner
  • The caller must be an owner according to fairdaoManager.isOwner
  • fairdaoManagerAddress cannot be address(0)

Failure messages:

  • "Not owner"
  • "Invalid manager addr"

Return value: bool - Whether the operation succeeded

Event: FairdaoManagerSet(fairdaoManagerAddress, msg.sender)

function setSharedData(bytes32 key, bytes32 sharedValueId, bytes calldata data) external returns (bool)

Stores shared data.

Parameters:

  • key - Key to store the data
  • sharedValueId - Unique identifier for the value
  • data - Data to be stored

Requirements:

  • FairdaoManager must be set
  • key cannot be bytes32(0)
  • sharedValueId cannot be bytes32(0)
  • Caller must be the key manager for the specified key

Failure messages:

  • "Manager not set"
  • "Zero key"
  • "Zero value ID"
  • "Not key manager"
function getSharedData(bytes32 key, bytes32 sharedValueId) external view returns (bytes memory data, uint64 timestamp)

Gets shared data.

Parameters:

  • key - Key to retrieve data
  • sharedValueId - Unique identifier for the value

Requirements:

  • FairdaoManager must be set
  • key cannot be bytes32(0)
  • sharedValueId cannot be bytes32(0)

Failure messages:

  • "Manager not set"
  • "Zero key"
  • "Zero value ID"

Return values:

  • data - Stored shared data
  • timestamp - Last update timestamp
function getFairdaoManager() external view returns (address)

Gets the address of the FairdaoManager contract.

Parameters: None

Return value: address - The address of the FairdaoManager contract