Factory pattern
The system uses the factory pattern to create standardized DAO instances:- Factory contract (
AgoraDaoFactory) deploys new DAO instances - Product contract (
AgoraDao) represents individual DAOs - Registry tracks all deployed DAOs for discovery
Factory creates DAOs
Benefits of factory pattern
Consistency
Every DAO is deployed with the same code and proper initialization
Discovery
Factory maintains a registry of all DAOs for easy discovery
Upgradability
Future versions can deploy new DAO implementations while maintaining the registry
Gas efficiency
Users only deploy the lightweight DAO contract, not the full factory logic
Contract relationships
The system consists of four contracts with clear relationships:AgoraDaoFactory relationships
Inherits from:Ownable(OpenZeppelin) - Provides single owner with admin privilegesValidation- Provides input validation for DAO creation
AgoraDaoinstances via thenewkeyword
- Array of all DAOs (
allDaos) - Mapping of DAOs by creator (
daosByUser) - Mapping to verify DAO authenticity (
isDao)
From AgoraDaoFactory.sol:15
AgoraDao relationships
Inherits from:Rol- Provides complete role-based access control system
fabric- Stores parent factory address for callbacks- Calls
IAgoraDaoFactory.addUserCounter()when users join
- Creator automatically receives
DEFAULT_ADMIN_ROLE - Tracks member count via
userCounter
From AgoraDao.sol:17
Inheritance structure
Rol inheritance
TheRol contract (contracts/AgoraDao/Rol.sol:6) inherits from OpenZeppelin’s AccessControl:
hasRole(bytes32 role, address account)- Check if account has role_grantRole(bytes32 role, address account)- Grant role to account_revokeRole(bytes32 role, address account)- Revoke role from accountDEFAULT_ADMIN_ROLE- Built-in admin role
- Role enumeration via
roleUsersmapping - Batch role assignment via
registerRoleBatch() - Role deletion with array compaction
- Additional permission checks for role assignment
Validation inheritance
TheValidation contract (contracts/AgoraDaoFactory/Validation.sol:4) is a pure utility contract:
State variables and mappings
AgoraDaoFactory state
Counters
Counters
DAO registry
DAO registry
Categories
Categories
User tracking
User tracking
AgoraDao state
Factory reference
Factory reference
addUserCounter)DAO metadata
DAO metadata
Rol state
Role enumeration
Role enumeration
Role membership
Role membership
Position tracking
Position tracking
Events emitted
All contracts emit events for off-chain indexing and UI updates:Factory events
From AgoraDaoFactory.sol:41
DAO events
From AgoraDao.sol:25
joinDao().
Role events
From AgoraDao/Rol.sol:20-21
RoleRegistered- Emitted when a role is grantedRoleDeleted- Emitted when a role is revoked
executor parameter tracks who performed the action (admin or auditor).
Data flow diagram
Access control matrix
Role-based permissions in the system:| Action | Admin | Auditor | Task Manager | Proposal Manager | User |
|---|---|---|---|---|---|
| Assign AUDITOR_ROLE | ✓ | ✗ | ✗ | ✗ | ✗ |
| Assign other roles | ✓ | ✓ | ✗ | ✗ | ✗ |
| Revoke roles | ✓ | ✗ | ✗ | ✗ | ✗ |
| Join DAO | ✗* | ✓ | ✓ | ✓ | ✓ |
| Add categories (Factory) | Owner | ✗ | ✗ | ✗ | ✗ |
joinDao()
Next steps
Deployment
Learn how to deploy and configure the contracts
Overview
Return to smart contracts overview