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
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.
FairdaoManagement Events
Triggered when a new manager is added.
Parameters:
manager- The address of the added managerisOwner- Whether the manager is an owneroperator- The address that performed the add operation
Triggered when a manager is removed.
Parameters:
manager- The address of the removed managerwasOwner- Whether the manager was an owneroperator- The address that performed the remove operation
Triggered when a key manager is added.
Parameters:
key- The key being managedmanager- The address of the key manageroperator- The address that performed the add operation
Triggered when key management permissions are transferred.
Parameters:
key- The key being managedoldManager- The previous manager addressnewManager- The new manager addressoperator- The address that performed the transfer operation
Triggered when emergency stop is enabled.
Parameters:
operator- The address that triggered emergency stop
Triggered when emergency stop is disabled.
Parameters:
operator- The address that resumed operations
UserDataStorage Events
Triggered when user data is updated.
Parameters:
user- User addresskey- Key used to store the datadataLength- Length of the stored dataoperator- Address that performed the update operation
Triggered when FairdaoManager address is set or updated.
Parameters:
managerAddress- New FairdaoManager addressoperator- Address that performed the update operation
Checks if the caller is a contract owner.
Requirement: Caller must be a contract owner
Failure message: "Not owner"
Checks if the caller is a contract manager.
Requirement: Caller must be a contract manager
Failure message: "Not manager"
Checks if the contract is in emergency stop state.
Requirement: Contract must not be in emergency stop state
Failure message: "Emergency stop active"
FairdaoManagement Functions
Constructor function, initializes the contract and sets the deployer address as the first owner.
Checks if an address is a manager.
Parameters:
user- The address to check
Return value: bool - Whether the address is a manager
Checks if an address has owner privileges.
Parameters:
user- The address to check
Return value: bool - Whether the address has owner privileges
Adds a new manager.
Parameters:
manager- New manager addresswithOwnerPermission- Whether to grant owner permission
Return value: bool - Whether the operation succeeded
Event: ManagerAdded(manager, withOwnerPermission, msg.sender)
Gets the number of managers.
Return value: uint256 - Number of managers
Removes a manager.
Parameters:
index- Index of the manager in the arraymanager- 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)
Gets the manager address at the specified index.
Parameters:
index- Index in the array
Return value: address - Manager address
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
Checks if an address is the manager of the specified key.
Parameters:
key- The key to checkuser- The address to check
Return value: bool - Whether the address is a key 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
Adds a manager for a single key.
Parameters:
key- The key to add a manager formanager- Manager address
Return value: bool - Whether the operation succeeded
Event: AddKeyManager(key, manager, msg.sender)
Transfers key management permissions to another address.
Parameters:
key- The key to transfer management fornewManager- New manager address
Return value: bool - Whether the operation succeeded
Event: TransferKeyManager(key, oldManager, newManager, msg.sender)
Checks if the contract is in emergency stop state.
Return value: bool - Whether the contract is in emergency stop state
Enables emergency stop (owner only).
Return value: bool - Whether the operation succeeded
Event: EmergencyStopped(msg.sender)
Disables emergency stop (owner only).
Return value: bool - Whether the operation succeeded
Event: EmergencyResumed(msg.sender)
UserDataStorage Functions
Constructor function, sets the contract owner to the deployer.
Parameters: None
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)
Stores user data.
Parameters:
user- User addresskey- Key to store the datadata- 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)
Gets stored user data.
Parameters:
user- User addresskey- 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 datatimestamp- Last update timestamp
Gets the address of the FairdaoManager contract.
Parameters: None
Return value: address - The address of the FairdaoManager contract