sourcebridge_42-contract-lab/docs/GovernanceContract.md
sourcebridge_42 fe42c6005d
Some checks are pending
CI / build-and-test (push) Waiting to run
CI / slither (push) Waiting to run
docs: add documentation for GovernanceContract.sol
2026-04-19 09:10:09 +00:00

2.7 KiB

Overview

The GovernanceContract is a decentralized governance mechanism for managing community proposals and voting processes on the ChunkNet blockchain. It provides a transparent, secure method for community members to create, vote on, and finalize governance proposals.

Interface

Function Parameters Returns Description
createProposal string _description uint256 Create a new governance proposal
vote uint256 _proposalId, bool _support void Cast a vote on an active proposal
finalizeProposal uint256 _proposalId void Conclude voting and determine proposal status
getProposalDetails uint256 _proposalId Proposal Retrieve detailed information about a specific proposal

Events

  • ProposalCreated: Emitted when a new proposal is created
  • ProposalVoted: Triggered when a community member votes
  • ProposalStatusChanged: Signals changes in proposal status

Storage Layout

  • proposals: Mapping of proposal IDs to Proposal structs
  • proposalCount: Total number of proposals created
  • votingContract: Reference to the VotingContract for voting power calculations
  • Constant parameters:
    • VOTING_PERIOD: 7 days
    • QUORUM_PERCENTAGE: 30%
    • PASS_THRESHOLD_PERCENTAGE: 50%

Access Control

  • Proposal creation: Open to all registered community members
  • Voting: Restricted to members with valid voting power
  • Proposal finalization: Can be called by any participant after voting period ends

Security Considerations

  • Prevents double voting through hasVoted mapping
  • Uses voting power from external VotingContract
  • Implements time-based voting restrictions
  • Requires quorum and pass threshold for proposal validation
  • Prevents proposal manipulation through cryptographic hashing

Deployment

Blockchain Environment:

Deployment Steps:

  1. Deploy VotingContract first
  2. Pass VotingContract address to GovernanceContract constructor
  3. Verify contract parameters
  4. Set appropriate access controls

Recommended Deployment Configuration: bash forge create GovernanceContract
--rpc-url https://rpc.chunknet.org
--private-key $DEPLOYER_PRIVATE_KEY
--constructor-args $VOTING_CONTRACT_ADDRESS

Testing

Test cases should cover:

  • Proposal creation validation
  • Voting mechanism
  • Quorum and threshold calculations
  • Proposal status transitions
  • Edge cases and potential attack vectors

Recommended test scenarios:

  • Create proposal with empty description
  • Vote before and after voting period
  • Test voting power calculations
  • Validate proposal finalization logic
  • Check event emissions