A robust and flexible Decentralized Autonomous Organization (DAO) governance system, leveraging OpenZeppelin's smart contract libraries.
- On-chain Governance: Fully decentralized decision-making process
- Time-locked Execution: Enhanced security with delayed implementation of proposals
- Flexible Voting: Customizable voting periods and thresholds
- ERC20 Governance Token: Built-in token for voting power allocation
- Upgradeable Architecture: Prepared for future improvements and adaptations
-
Clone the repository:
git clone https://github.com/zeroaddresss/governance-dao.git cd governance-dao
-
Install dependencies:
forge install
-
Compile the contracts:
forge build
-
Run tests:
forge test
- MyGovernor.sol: The core governance contract that manages proposals, voting, and execution.
- TimeLock.sol: Implements a delay mechanism for executing approved proposals.
- GovToken.sol: ERC20 token with voting capabilities for governance participation.
- Box.sol: A simple contract demonstrating governance-controlled state changes.
- Proposal Creation: Any token holder can create a proposal.
- Voting: Token holders cast their votes during the voting period.
- Execution: If approved, proposals are queued and then executed after a time delay.
Key parameters in MyGovernor.sol
:
- Voting Delay: 1 block
- Voting Period: 50400 blocks (β1 week on Ethereum mainnet)
- Proposal Threshold: 0 tokens
- Quorum: 4% of total supply
These can be adjusted based on your DAO's specific needs.
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public returns (uint256)
Example:
address[] memory targets = new address[](1);
targets[0] = address(boxContract);
uint256[] memory values = new uint256[](1);
values[0] = 0;
bytes[] memory calldatas = new bytes[](1);
calldatas[0] = abi.encodeWithSignature("store(uint256)", newValue);
string memory description = "Set Box value to " + newValue;
uint256 proposalId = governor.propose(targets, values, calldatas, description);
function castVote(uint256 proposalId, uint8 support) public returns (uint256)
Example:
uint256 proposalId = /* ... */;
uint8 support = 1; // 0 = Against, 1 = For, 2 = Abstain
governor.castVote(proposalId, support);
governance-dao/
βββ src/
β βββ MyGovernor.sol
β βββ TimeLock.sol
β βββ GovToken.sol
β βββ Box.sol
βββ test/
β βββ MyGovernorTest.t.sol
βββ script/
βββ README.md
- OpenZeppelin Contracts ^5.0.0
- Foundry (for development and testing)
Run the test suite using Foundry:
forge test
For more detailed output:
forge test -vvvvv
This project is licensed under the MIT License - see the LICENSE file for details.