Skip to main content

Overview

The AgoraDaoFactory contract is the main factory responsible for creating new DAO instances in the Agora ecosystem. It manages DAO creation, categorization, and tracking of all DAOs and users across the platform. The contract inherits from OpenZeppelin’s Ownable and the custom Validation contract. Contract: AgoraDaoFactory.sol
Inherits: Ownable, Validation
Author: NightmareFox12

State Variables

Core Counters

uint256 public userCounter;
uint256 public daoCounter;
  • userCounter: Tracks the total number of unique users across all DAOs
  • daoCounter: Tracks the total number of DAOs created

Storage

string[] internal daoCategories;
Dao[] public allDaos;
  • daoCategories: Array storing available DAO category names
  • allDaos: Array containing all created DAOs

Mappings

mapping(address => Dao[]) public daosByUser;
mapping(address => bool) internal isUser;
mapping(address => bool) internal isDao;
  • daosByUser: Maps creator addresses to their created DAOs
  • isUser: Tracks whether an address has been counted as a user
  • isDao: Verifies if an address is a canonical DAO contract

Structs

Dao

Represents a DAO instance with its metadata.
struct Dao {
    uint256 daoID;
    address creator;
    address daoAddress;
    string name;
    string description;
    string category;
    string imageURI;
    uint256 creationTimestamp;
}
daoID
uint256
Unique identifier for the DAO
creator
address
Address of the DAO creator
daoAddress
address
Deployed contract address of the DAO
name
string
Name of the DAO
description
string
Description of the DAO’s purpose
category
string
Category classification (e.g., “SERVICE”, “GOVERNANCE”)
imageURI
string
URI pointing to the DAO’s image/logo
creationTimestamp
uint256
Block timestamp when the DAO was created

Functions

createDao

Creates a new DAO instance with the specified parameters.
function createDao(
    string memory _name,
    string memory _description,
    uint256 _categoryID,
    string memory _imageURI
) external
_name
string
required
Name of the DAO (1-50 characters)
_description
string
required
Description of the DAO (1-500 characters)
_categoryID
uint256
required
Index of the category in the daoCategories array
_imageURI
string
required
URI for the DAO’s image/logo
Process:
  1. Validates input parameters through _createDao validation
  2. Deploys a new AgoraDao contract instance
  3. Creates a Dao struct with metadata
  4. Stores the DAO in daosByUser and allDaos
  5. Marks the address as a canonical DAO
  6. Increments daoCounter
  7. Updates user counter for the creator
  8. Emits DaoCreated event
Example:
factory.createDao(
    "Climate Action DAO",
    "A DAO focused on funding climate change initiatives",
    2, // SOCIAL IMPACT category
    "ipfs://QmExample..."
);

addDaoCategory

Adds a new category to the available DAO categories. Only callable by the contract owner.
function addDaoCategory(string memory newCategory) external onlyOwner
newCategory
string
required
Name of the new category to add
Requirements:
  • Category name must not be empty
  • Category must not already exist (prevents duplicates)
  • Only callable by contract owner
Example:
factory.addDaoCategory("EDUCATION");

addUserCounter

Increments the user counter if the address is a new user.
function addUserCounter(address _newUser) public
_newUser
address
required
Address to check and potentially add to user count
Logic:
  • Only increments if address is not already counted
  • Excludes zero address and contract address
  • Can be called by child DAO contracts

withdraw

Withdraws all Ether from the contract to the owner. Only callable by the contract owner.
function withdraw() external onlyOwner
Requirements:
  • Only callable by contract owner
  • Transfers entire contract balance to owner

getAllDaoCategories

Returns all available DAO categories.
function getAllDaoCategories() external view returns (string[] memory)
categories
string[]
Array of all available DAO category names
Default categories:
  • SERVICE
  • GOVERNANCE
  • SOCIAL IMPACT
  • ENERGY

getAllDaos

Returns all created DAOs.
function getAllDaos() external view returns (Dao[] memory)
daos
Dao[]
Array of all DAO structs created through the factory

getTotalDaoCount

Returns the total number of DAOs created.
function getTotalDaoCount() external view returns (uint256)
count
uint256
Total number of DAOs in the allDaos array

Events

DaoCreated

Emitted when a new DAO is successfully created.
event DaoCreated(uint256 indexed daoID, address indexed creator, string indexed name);
daoID
uint256
The ID assigned to the newly created DAO
creator
address
Address of the DAO creator
name
string
Name of the created DAO

Constructor

constructor(address initialOwner) Ownable(initialOwner)
Initializes the factory with default categories:
  • SERVICE
  • GOVERNANCE
  • SOCIAL IMPACT
  • ENERGY
initialOwner
address
required
Address that will own the factory contract

Usage Example

// Deploy factory
AgoraDaoFactory factory = new AgoraDaoFactory(msg.sender);

// Create a new DAO
factory.createDao(
    "Developer DAO",
    "A DAO for coordinating open-source development",
    0, // SERVICE category
    "ipfs://QmDevDao..."
);

// Get all DAOs
AgoraDaoFactory.Dao[] memory allDaos = factory.getAllDaos();

// Get categories
string[] memory categories = factory.getAllDaoCategories();

// Get total count
uint256 totalDaos = factory.getTotalDaoCount();

Build docs developers (and LLMs) love