├── README.md └── DAO.sol /README.md: -------------------------------------------------------------------------------- 1 | # DAO Governance 🏛️ 2 | A decentralized governance system that allows token holders to create and vote on proposals, influencing the decision-making of a community-driven treasury. 3 | 4 | ## 📌 Features 5 | - **Proposal Creation** – Token holders can submit proposals for the community 6 | - **Voting Mechanism** – Users vote based on the number of governance tokens they hold 7 | - **Automated Execution** – Approved proposals trigger on-chain actions 8 | - **Treasury Management** – Community votes on fund allocation 9 | - **Web3 wallet integration** (MetaMask, WalletConnect) 10 | 11 | ## 🔗 Project Structure 12 | # DAO Governance 🏛️ 13 | A decentralized governance system that allows token holders to create and vote on proposals, influencing the decision-making of a community-driven treasury. 14 | 15 | ## 📌 Features 16 | - **Proposal Creation** – Token holders can submit proposals for the community 17 | - **Voting Mechanism** – Users vote based on the number of governance tokens they hold 18 | - **Automated Execution** – Approved proposals trigger on-chain actions 19 | - **Treasury Management** – Community votes on fund allocation 20 | - **Web3 wallet integration** (MetaMask, WalletConnect) 21 | 22 | ## 🔗 Project Structure 23 | -------------------------------------------------------------------------------- /DAO.sol: -------------------------------------------------------------------------------- 1 | 2 | --- 3 | 4 | ### **Example Solidity Contract (`contracts/DAO.sol`)** 5 | ```solidity 6 | // SPDX-License-Identifier: MIT 7 | pragma solidity ^0.8.19; 8 | 9 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 10 | import "@openzeppelin/contracts/access/Ownable.sol"; 11 | 12 | contract DAO { 13 | struct Proposal { 14 | string description; 15 | uint256 votesFor; 16 | uint256 votesAgainst; 17 | bool executed; 18 | mapping(address => bool) voted; 19 | } 20 | 21 | mapping(uint256 => Proposal) public proposals; 22 | uint256 public proposalCount; 23 | IERC20 public governanceToken; 24 | 25 | event ProposalCreated(uint256 proposalId, string description); 26 | event Voted(uint256 proposalId, bool support, address voter); 27 | event ProposalExecuted(uint256 proposalId); 28 | 29 | constructor(address _governanceToken) { 30 | governanceToken = IERC20(_governanceToken); 31 | } 32 | 33 | function createProposal(string memory _description) public { 34 | proposals[proposalCount] = Proposal(_description, 0, 0, false); 35 | emit ProposalCreated(proposalCount, _description); 36 | proposalCount++; 37 | } 38 | 39 | function vote(uint256 _proposalId, bool _support) public { 40 | Proposal storage proposal = proposals[_proposalId]; 41 | require(!proposal.voted[msg.sender], "Already voted"); 42 | 43 | uint256 votingPower = governanceToken.balanceOf(msg.sender); 44 | require(votingPower > 0, "No governance tokens"); 45 | 46 | if (_support) { 47 | proposal.votesFor += votingPower; 48 | } else { 49 | proposal.votesAgainst += votingPower; 50 | } 51 | 52 | proposal.voted[msg.sender] = true; 53 | emit Voted(_proposalId, _support, msg.sender); 54 | } 55 | 56 | function executeProposal(uint256 _proposalId) public onlyOwner { 57 | Proposal storage proposal = proposals[_proposalId]; 58 | require(!proposal.executed, "Proposal already executed"); 59 | require(proposal.votesFor > proposal.votesAgainst, "Not enough support"); 60 | 61 | proposal.executed = true; 62 | emit ProposalExecuted(_proposalId); 63 | } 64 | } 65 | --------------------------------------------------------------------------------