Skip to content

tundekomolafe/Proposal-Submission-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 

Repository files navigation

Proposal Submission System Smart Contract

A comprehensive Clarity smart contract for decentralized proposal creation, voting, and execution on the Stacks blockchain.

Overview

This smart contract enables a democratic governance system where users can create proposals, vote on them using weighted voting power, and execute approved proposals. The system includes robust security measures, input validation, and proper stake management.

Key Features

πŸ—³οΈ Proposal Management

  • Create proposals with title, description, and custom duration
  • Automatic unique proposal ID generation
  • Stake requirement (1 STX) to prevent spam submissions
  • Duration validation (1-100 days)

πŸ”’ Weighted Voting System

  • User-based voting power allocation
  • Prevention of double voting
  • Real-time vote counting (yes/no)
  • 51% threshold for proposal approval

πŸ“Š Proposal Lifecycle

  • Active: Open for voting within time limit
  • Passed/Rejected: Based on 51% threshold
  • Executed: Finalized proposals with stake return

πŸ” Security & Access Control

  • Contract owner administrative privileges
  • Comprehensive input validation
  • Emergency proposal cancellation
  • Protection against common attack vectors

Smart Contract Functions

Public Functions

create-proposal(title, description, duration)

Creates a new proposal with the specified parameters.

  • Requirements: Valid voting power, 1 STX stake
  • Returns: Proposal ID
  • Validation: Title/description length, duration bounds

vote(proposal-id, support)

Cast a vote on an active proposal.

  • Parameters:
    • proposal-id: Target proposal ID
    • support: true (yes) or false (no)
  • Requirements: Active proposal, no previous vote, voting power > 0

execute-proposal(proposal-id)

Finalize and execute a proposal after voting period.

  • Action: Determines pass/fail based on votes
  • Stake Return: Returns stake for passed proposals

set-voting-power(user, power)

Owner only - Set voting power for users.

  • Range: 1 to 1,000,000
  • Access: Contract owner only

emergency-cancel(proposal-id)

Owner only - Emergency cancellation of active proposals.

Read-Only Functions

  • get-proposal(proposal-id) - Get proposal details
  • get-proposal-count() - Total proposals created
  • has-voted(proposal-id, voter) - Check voting status
  • get-vote(proposal-id, voter) - Get user's vote details
  • get-voting-power(user) - Get user's voting power
  • get-user-proposals(user) - Get proposals created by user
  • is-proposal-active(proposal-id) - Check if proposal is active

Constants & Limits

Parameter Value Description
MIN_PROPOSAL_DURATION 144 blocks ~1 day minimum
MAX_PROPOSAL_DURATION 14,400 blocks ~100 days maximum
MIN_STAKE 1,000,000 microSTX 1 STX stake requirement
VOTING_THRESHOLD 51% Approval threshold
MAX_VOTING_POWER 1,000,000 Maximum user voting power

Error Codes

Code Constant Description
u100 ERR-NOT-AUTHORIZED Insufficient permissions
u101 ERR-PROPOSAL-NOT-FOUND Invalid proposal ID
u102 ERR-ALREADY-VOTED User already voted
u103 ERR-PROPOSAL-EXPIRED Proposal voting ended
u104 ERR-INVALID-DURATION Duration out of bounds
u105 ERR-INSUFFICIENT-STAKE Stake amount too low
u106 ERR-PROPOSAL-ACTIVE Proposal still active
u107 ERR-INVALID-STATUS Invalid proposal status
u108 ERR-INVALID-INPUT Invalid input parameters

Usage Example

;; Create a proposal (requires 1 STX stake)
(contract-call? .proposal-system create-proposal 
  "Increase block rewards" 
  "Proposal to increase mining rewards by 10%" 
  u1440) ;; 10 days

;; Vote on proposal ID 1
(contract-call? .proposal-system vote u1 true) ;; Vote yes

;; Execute proposal after voting period
(contract-call? .proposal-system execute-proposal u1)

Security Features

  • Input Validation: All user inputs validated before processing
  • Stake Protection: Economic incentive against spam
  • Access Control: Owner-only administrative functions
  • Double Vote Prevention: Users can only vote once per proposal
  • Time-based Expiration: Automatic proposal expiration

Deployment Requirements

  1. Deploy contract to Stacks blockchain
  2. Set initial voting power for users via set-voting-power
  3. Users must have STX for proposal stakes
  4. Contract owner maintains administrative privileges

Gas Optimization

  • Efficient data structures with minimal storage operations
  • Read-only functions for gas-free queries
  • Optimized for under 300 lines of code
  • Strategic use of Clarity built-ins for performance

About

The Proposal Submission System is a production-ready Clarity smart contract that implements a comprehensive decentralized governance framework on the Stacks blockchain. This contract enables stakeholders to democratically propose, vote on, and execute community decisions through a secure, transparent, and economically incentivized system.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors