Skip to content
sanskar717Public

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

DAO Governance System

A fully functional Decentralized Autonomous Organization (DAO) built with Hardhat, Solidity, and OpenZeppelin contracts. This project demonstrates on-chain governance with proposal creation, voting, and execution mechanisms.

🌟 Features

  • ERC20 Governance Token with vote delegation and checkpointing
  • TimeLock Controller for delayed execution of approved proposals
  • Governor Contract for complete proposal lifecycle management
  • Automated Scripts for proposal creation, voting, and execution
  • Local Development with Hardhat network for testing

🏗️ Architecture

The DAO consists of four main contracts:

  1. GovernanceToken.sol - ERC20Votes token that grants voting power
  2. TimeLock.sol - TimelockController that enforces execution delays
  3. GovernorContract.sol - Main governance contract for proposals
  4. Box.sol - Example contract controlled by the DAO

📋 Prerequisites

  • Node.js v16+
  • Yarn or npm
  • Basic understanding of Ethereum and Solidity

🚀 Getting Started

Installation

# Clone the repository
git clone https://github.com/sanskar717/DAO.git
cd DAO

# Install dependencies
yarn install

Local Development

# Start a local Hardhat node
yarn hardhat node

# In a new terminal, deploy contracts
yarn hardhat deploy --network localhost

📜 Usage

The DAO workflow involves three main steps: Propose, Vote, and Execute.

1. Create a Proposal

yarn hardhat run scripts/propose.ts --network localhost

This creates a proposal to change a value in the Box contract. The proposal ID is saved to proposals.json.

2. Vote on Proposal

yarn hardhat run scripts/vote.ts --network localhost

Cast your vote on the active proposal. Votes can be:

  • 0 = Against
  • 1 = For
  • 2 = Abstain

3. Queue and Execute

yarn hardhat run scripts/queue-and-execute.ts --network localhost

After voting period ends, queue the proposal in the TimeLock, wait for the delay, then execute it.

📁 Project Structure

DAO/
├── contracts/
│   ├── GovernanceToken.sol    # ERC20Votes token
│   ├── TimeLock.sol            # TimelockController
│   ├── GovernorContract.sol    # Governor
│   └── Box.sol                 # Example governed contract
├── deploy/
│   ├── 01-deploy-governance-token.ts
│   ├── 02-deploy-time-lock.ts
│   ├── 03-deploy-governor-contract.ts
│   ├── 04-setup-governance-contract.ts
│   └── 05-deploy-box.ts
├── scripts/
│   ├── propose.ts              # Create proposals
│   ├── vote.ts                 # Vote on proposals
│   └── queue-and-execute.ts    # Queue and execute
├── utils/
│   ├── move-block.ts           # Helper for local testing
│   └── move-time.ts            # Helper for local testing
└── helper-hardhat-config.ts    # Configuration constants

⚙️ Configuration

Key parameters can be modified in helper-hardhat-config.ts:

export const VOTING_DELAY = 1;          // Blocks before voting starts
export const VOTING_PERIOD = 5;         // Blocks for voting duration
export const MIN_DELAY = 3600;          // Seconds before execution
export const QUORUM_PERCENTAGE = 4;     // Minimum participation
export const NEW_STORE_VALUE = 77;      // Example proposal value

🔑 How It Works

Governance Flow

  1. Token Holders receive governance tokens and delegate voting power
  2. Proposers create proposals to execute actions
  3. Voters cast votes during the voting period
  4. TimeLock enforces a delay after proposal passes
  5. Executors can execute approved proposals after delay

Proposal States

  • Pending (0) - Waiting for voting delay
  • Active (1) - Currently accepting votes
  • Canceled (2) - Proposal was canceled
  • Defeated (3) - Did not reach quorum or majority
  • Succeeded (4) - Passed and ready to queue
  • Queued (5) - Queued in TimeLock
  • Expired (6) - Execution window expired
  • Executed (7) - Successfully executed

🧪 Testing

# Run tests (when implemented)
yarn hardhat test

# Check coverage
yarn hardhat coverage

🌐 Deployment to Testnet

  1. Create a .env file:
SEPOLIA_RPC_URL=your_rpc_url
PRIVATE_KEY=your_private_key
ETHERSCAN_API_KEY=your_api_key
  1. Deploy:
yarn hardhat deploy --network sepolia

🛠️ Built With

📝 License

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

🤝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

👨‍💻 Author

Sanskar

🙏 Acknowledgments

  • OpenZeppelin for secure contract implementations
  • Patrick Collins for Web3 education
  • Hardhat team for excellent developer tools

📚 Resources


⭐ Star this repo if you found it helpful!

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages