Skip to content

zenbitETH/microDAO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroDAO Implementation

A comprehensive implementation of the microDAO system using Solidity and Foundry, featuring multichain multisig functionality, ENS integration, EAS attestations, and ERC20 tokenization.

Overview

The microDAO system consists of three core smart contracts:

  • MicroDAOFactory: Handles DAO creation, ENS setup, and initial configuration
  • MicroDAOManager: Manages ongoing operations, transactions, and member management
  • MicroDAOBadges: Handles achievement system and EAS attestations

Features

Core Functionality

  • Multichain multisig wallet creation
  • Configurable consensus threshold
  • Dynamic member management
  • ENS domain integration
  • Achievement badge system
  • EAS attestation support
  • ERC20 token deployment

Security Features

  • Role-based access control
  • Reentrancy protection
  • Multi-signature transaction approval
  • CREATE2 deterministic addresses

Architecture

MicroDAOFactory
├── Creates new DAOs using CREATE2
├── Manages ENS domain registration
├── Coordinates with badges contract
└── Tracks all created DAOs

MicroDAOManager (per DAO)
├── Multisig transaction management
├── Member add/remove functionality
├── ERC20 token deployment
├── Threshold management
└── Treasury management

MicroDAOBadges
├── Achievement tracking
├── EAS attestation creation
├── Badge requirement verification
└── Custom achievement support

Prerequisites

Installation

  1. Clone the repository:
git clone <repository-url>
cd microDAO_implementation
  1. Install dependencies:
forge install
  1. Build the contracts:
forge build

Testing

Run the comprehensive test suite:

# Run all tests
forge test

# Run tests with verbose output
forge test -vv

# Run specific test file
forge test --match-contract MicroDAOFactoryTest

# Run with gas reporting
forge test --gas-report

Test Coverage

The test suite covers:

  • DAO creation and configuration
  • Multisig transaction workflows
  • Member management operations
  • Badge granting and verification
  • Access control mechanisms
  • Edge cases and error conditions

Deployment

Local Development

  1. Start a local Anvil node:
anvil
  1. Deploy contracts:
forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --private-key <PRIVATE_KEY> --broadcast

Testnet Deployment

  1. Set environment variables:
export PRIVATE_KEY=<your-private-key>
export ALCHEMY_API_KEY=<your-alchemy-key>
export ETHERSCAN_API_KEY=<your-etherscan-key>
  1. Deploy to Sepolia:
forge script script/Deploy.s.sol --rpc-url sepolia --private-key $PRIVATE_KEY --broadcast --verify

Mainnet Deployment

⚠️ Warning: Ensure thorough testing before mainnet deployment.

forge script script/Deploy.s.sol --rpc-url mainnet --private-key $PRIVATE_KEY --broadcast --verify

Usage

Creating a DAO

  1. Use the deployment script:
export FACTORY_ADDRESS=<deployed-factory-address>
forge script script/CreateDAO.s.sol --rpc-url <network> --private-key $PRIVATE_KEY --broadcast
  1. Or interact directly with the factory:
IMicroDAOFactory.DAOConfig memory config = IMicroDAOFactory.DAOConfig({
    members: [address1, address2, address3],
    threshold: 2,
    ensName: "my-dao",
    easSchemas: new bytes32[](0)
});

address daoAddress = factory.createMicroDAO(config);

Managing DAO Operations

// Submit a transaction
uint256 txIndex = dao.submitTransaction(target, value, data);

// Confirm transaction (requires threshold confirmations)
dao.confirmTransaction(txIndex);

// Add new member (requires DAO approval)
bytes memory addMemberData = abi.encodeWithSignature("addMember(address)", newMember);
dao.submitTransaction(address(dao), 0, addMemberData);

Badge Management

// Grant creation badge (automatic on DAO creation)
badges.grantCreationBadge(daoAddress, members);

// Grant Mirror badge
badges.grantMirrorBadge(daoAddress, "https://mirror.xyz/article-url");

// Check achievements
bool hasCreationBadge = badges.hasAchievement(daoAddress, badges.CREATION_BADGE());

Configuration

Environment Variables

Create a .env file:

PRIVATE_KEY=<your-private-key>
ALCHEMY_API_KEY=<your-alchemy-api-key>
ETHERSCAN_API_KEY=<your-etherscan-api-key>
POLYGONSCAN_API_KEY=<your-polygonscan-api-key>
ARBISCAN_API_KEY=<your-arbiscan-api-key>

Network Configuration

The foundry.toml file includes configurations for:

  • Mainnet
  • Sepolia (testnet)
  • Polygon
  • Arbitrum

Smart Contract Interfaces

IMicroDAOFactory

  • createMicroDAO(DAOConfig) - Create a new DAO
  • setupENSForDAO(address, string) - Configure ENS domain
  • isValidDAO(address) - Check if address is a valid DAO

IMicroDAOManager

  • submitTransaction(address, uint256, bytes) - Submit multisig transaction
  • confirmTransaction(uint256) - Confirm pending transaction
  • addMember(address) - Add new member (requires DAO approval)
  • deployDAOToken(TokenConfig) - Deploy ERC20 governance token

IMicroDAOBadges

  • grantCreationBadge(address, address[]) - Grant creation achievement
  • grantMirrorBadge(address, string) - Grant Mirror publication badge
  • addNewAchievement(bytes32, string, string, BadgeRequirements) - Add custom achievement

Security Considerations

Access Control

  • Factory owner can update system contracts
  • DAO members control DAO operations
  • Badge contract owner manages achievement system

Multisig Security

  • Configurable threshold requirements
  • Transaction confirmation tracking
  • Reentrancy protection on execution

Upgrade Safety

  • Contracts use OpenZeppelin's battle-tested libraries
  • Role-based permissions prevent unauthorized access
  • Emergency pause functionality (can be added)

Gas Optimization

The contracts are optimized for gas efficiency:

  • Packed structs where possible
  • Efficient storage patterns
  • Minimal external calls
  • Batch operations support

Troubleshooting

Common Issues

  1. "forge: command not found"

    • Install Foundry: curl -L https://foundry.paradigm.xyz | bash && foundryup
  2. "Invalid threshold" error

    • Ensure threshold ≤ number of members and > 0
  3. "ENS name already taken"

    • Choose a unique ENS name for your DAO
  4. Transaction execution fails

    • Check that enough members have confirmed the transaction
    • Verify the target contract and data are correct

Debug Commands

# Check contract size
forge build --sizes

# Analyze gas usage
forge test --gas-report

# Debug specific transaction
forge debug <tx-hash> --rpc-url <network>

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors