A comprehensive decentralized autonomous organization (DAO) governance system built with ink! v6. This contract enables community-driven decision making through proposal creation, voting, and execution mechanisms.
This governance contract implements a complete DAO system with:
- Proposal Management: Create, vote on, and execute governance proposals
- Voting System: Multi-option voting with customizable parameters
- Quorum Requirements: Configurable participation thresholds
- Execution Delays: Time-locked execution for security
- Voter Registration: Permission-based voting participation
- Treasury Management: Fund allocation and spending controls
lib.rs- Main contract module and exportsgovernance.rs- Core governance logic and state managementtypes.rs- Data structures and enumserrors.rs- Custom error definitionsevents.rs- Event definitions for loggingtests.rs- Comprehensive test suite
pub struct Proposal {
pub id: u32,
pub title: String,
pub description: String,
pub proposal_type: ProposalType, // Treasury, Governance, Technical, Other
pub governance_params: GovernanceParameters,
pub voting_options: VotingOptions, // Custom voting choices
pub proposer: H160,
pub created_at: u32, // Block number
pub voting_end: u32, // Block number
pub execution_time: u32, // Block number
pub status: ProposalStatus, // Active, Passed, Rejected, Executed, Expired
pub vote_counts: Vec<u128>, // Votes per option
pub total_voters: u32,
}- Create proposals with custom titles and descriptions
- Support for different proposal types (Treasury, Governance, Technical, Other)
- Configurable governance parameters (voting period, quorum, execution delay)
- Custom voting options for each proposal
- Multi-option voting support
- One vote per registered voter per proposal
- Real-time vote counting and tracking
- Vote weight system (currently 1:1, extensible)
- Voter registration requirement
- Quorum-based decision making
- Time-locked execution delays
- Comprehensive error handling
- Event logging for transparency
- Voting Periods: 3, 7, 14, or 30 days
- Quorum Thresholds: 5%, 10%, 20%, or 25%
- Execution Delays: Immediate, 1, 2, or 7 days
# Development build
cargo contract build
# Production build
cargo contract build --release# Deploy to local node
cargo contract instantiate --constructor new --suri //Alice --skip-confirm
# Deploy to testnet
cargo contract instantiate --constructor new --suri <your-seed> --url wss://rococo-contracts-rpc.polkadot.io// Create a new proposal
create_proposal(
title: String,
description: String,
proposal_type: ProposalType,
governance_parameters: GovernanceParameters,
voting_options: VotingOptions
) -> Result<u32>
// Get proposal details
get_proposal(proposal_id: u32) -> Option<Proposal>
// Get all proposal IDs
get_all_proposal_ids() -> Vec<u32>// Vote on a proposal
vote(proposal_id: u32, option_index: u32) -> Result<()>
// Get user's vote
get_user_vote(proposal_id: u32, user: H160) -> Option<Vote>
// Check quorum status
has_reached_quorum(proposal_id: u32) -> Option<bool>
// Get detailed results
get_detailed_results(proposal_id: u32) -> Option<Vec<(String, u128)>>// Register as voter
register_voter() -> Result<()>
// Check voter status
is_voter(account: H160) -> bool
// Get total voters
get_total_voters() -> u32// Update proposal status (when voting ends)
update_proposal_status(proposal_id: u32) -> Result<()>
// Execute passed proposal
execute_proposal(proposal_id: u32) -> Result<()>cargo testcargo test --features e2e-testsThe contract includes comprehensive tests covering:
- Proposal creation and management
- Voting mechanisms
- Voter registration
- Status transitions
- Error conditions
- Edge cases
The contract emits events for all major operations:
// Proposal lifecycle
ProposalCreated { proposal_id, proposer, title, proposal_type }
ProposalStatusUpdated { proposal_id, old_status, new_status }
ProposalExecuted { proposal_id, status }
// Voting
VoteCast { proposal_id, voter, option_index, option_text, weight }
// Voter management
VoterRegistered { voter }[dependencies]
ink = { git = "https://github.com/use-ink/ink", tag = "v6.0.0-alpha.4", version = "6.0.0-alpha.4", default-features = false, features = ["unstable-hostfn"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }This contract is designed to work with the Governance DApp, which provides:
- Real-time proposal viewing
- Interactive voting interface
- Voter registration
- Status tracking
- Results visualization
- Access Control: Voter registration requirement
- Input Validation: Comprehensive parameter checking
- Safe Arithmetic: Overflow/underflow protection
- Time Locks: Execution delays for security
- Quorum Requirements: Prevents minority rule
- Event Logging: Full transparency
- All state changes are logged via events
- Comprehensive error handling
- Input validation on all public functions
- Safe arithmetic operations
- Clear separation of concerns
- Efficient mapping-based storage
- Minimal data duplication
- Optimized struct packing
- Batch operations where possible
- Minimal storage writes
- Efficient data structures
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is provided as-is for educational purposes. Check the main repository for licensing information.
For issues and questions:
- Create an issue in the repository
- Check the main README for troubleshooting
- Review the ink! documentation
🦀 Built with Rust + ink! v6.0.0-alpha.4
This governance contract demonstrates advanced ink! smart contract development patterns and serves as a foundation for building decentralized autonomous organizations.

