Skip to content

lukman-amuda/Community-Funding-Platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Community Funding Platform Smart Contract

Overview

The Community Funding Platform is a decentralized smart contract built on the Stacks blockchain that enables community-driven funding for local initiatives. Community members can contribute to a shared funding pool, propose funding requests for verified initiatives, vote on proposals, and collectively distribute funds through a democratic process.

Features

  • Initiative Registration: Anyone can register a community initiative with details like name, category, and description
  • Verification System: Contract owner can verify legitimate initiatives before they become eligible for funding
  • Community Contributions: Members contribute STX tokens to build a collective funding pool
  • Democratic Proposals: Eligible contributors can create funding requests for verified initiatives
  • Voting Mechanism: Contributors vote on funding proposals with a time-limited voting period
  • Automated Execution: Approved proposals automatically transfer funds to initiatives
  • Initiative Management: Initiative owners can update information and deactivate their listings

Contract Architecture

Data Structures

Initiatives Map

{
  initiative-id: uint,
  owner: principal,
  name: string-ascii 50,
  category: string-ascii 30,
  description: string-ascii 200,
  wallet: principal,
  verified: bool,
  funding-received: uint,
  registration-block: uint,
  active: bool
}

Funding Requests Map

{
  request-id: uint,
  initiative-id: uint,
  amount: uint,
  proposer: principal,
  votes-for: uint,
  votes-against: uint,
  voting-ends: uint,
  executed: bool,
  description: string-ascii 150
}

Contributions Map

{
  contributor: principal,
  total-contributed: uint,
  last-contribution: uint
}

Core Functions

Public Functions

register-initiative

Register a new community initiative.

Parameters:

  • name: Initiative name (max 50 characters)
  • category: Initiative category (max 30 characters)
  • description: Detailed description (max 200 characters)
  • wallet: Principal address to receive funds

Returns: Initiative ID

Example:

(contract-call? .community-funding register-initiative 
  "Local Art Gallery" 
  "Arts & Culture" 
  "A community space for local artists to showcase their work"
  'SP2...WALLET)

verify-initiative

Verify an initiative as legitimate (contract owner only).

Parameters:

  • initiative-id: ID of the initiative to verify

Returns: true on success

contribute-to-pool

Add funds to the community funding pool.

Parameters:

  • amount: Amount in microSTX (1 STX = 1,000,000 microSTX)

Returns: Amount contributed

Example:

(contract-call? .community-funding contribute-to-pool u5000000) ;; 5 STX

create-funding-request

Create a proposal to fund an initiative.

Requirements:

  • Caller must have contributed at least the minimum amount (1 STX)
  • Initiative must be verified and active
  • Request amount must not exceed available pool balance

Parameters:

  • initiative-id: Target initiative ID
  • amount: Requested funding amount in microSTX
  • description: Proposal description (max 150 characters)

Returns: Request ID

vote-on-request

Vote on a funding request.

Requirements:

  • Caller must be an eligible voter (contributed minimum amount)
  • Must not have already voted on this request
  • Voting period must still be active

Parameters:

  • request-id: ID of the funding request
  • support: true to vote for, false to vote against

Returns: Vote value (true/false)

execute-request

Execute an approved funding request.

Requirements:

  • Voting period must have ended
  • Must have minimum required votes (default: 3)
  • Must have more votes for than against
  • Request must not have been executed already

Parameters:

  • request-id: ID of the request to execute

Returns: Amount transferred

update-initiative-info

Update initiative details (owner only).

Parameters:

  • initiative-id: ID of the initiative
  • name: New name
  • description: New description

Returns: true on success

deactivate-initiative

Deactivate an initiative (owner or contract owner).

Parameters:

  • initiative-id: ID of the initiative to deactivate

Returns: true on success

emergency-withdrawal

Emergency fund withdrawal (contract owner only).

Parameters:

  • amount: Amount to withdraw
  • recipient: Recipient address

Returns: Amount withdrawn

Read-Only Functions

  • get-initiative: Retrieve initiative details by ID
  • get-request: Retrieve funding request details by ID
  • get-vote: Check if an address voted on a specific request
  • get-contribution: Get contribution stats for an address
  • get-total-funding-pool: Get current pool balance
  • get-initiative-count: Get total number of registered initiatives
  • get-request-count: Get total number of funding requests
  • is-eligible-voter: Check if an address can vote

Configuration Variables

  • Minimum Funding Amount: 1 STX (1,000,000 microSTX) - minimum contribution to become eligible voter
  • Voting Period: 144 blocks (~24 hours) - duration of voting on proposals
  • Minimum Votes Required: 3 votes - minimum votes needed for proposal execution

Error Codes

Code Constant Description
u100 ERR-NOT-AUTHORIZED Unauthorized action
u101 ERR-INITIATIVE-NOT-FOUND Initiative doesn't exist
u102 ERR-INITIATIVE-ALREADY-EXISTS Initiative already registered
u103 ERR-INSUFFICIENT-FUNDS Not enough funds in pool
u104 ERR-INVALID-AMOUNT Invalid amount specified
u105 ERR-REQUEST-NOT-FOUND Funding request doesn't exist
u106 ERR-ALREADY-VOTED User already voted on this request
u107 ERR-VOTING-PERIOD-ENDED Voting period has ended/not ended
u108 ERR-NOT-ELIGIBLE User not eligible to perform action
u109 ERR-INVALID-INPUT Invalid input parameter

Workflow Example

  1. Setup

    • Deploy contract (deployer becomes contract owner)
    • Community members contribute to funding pool
  2. Initiative Registration

    • Initiative owner registers their project
    • Contract owner verifies the initiative
  3. Funding Request

    • Eligible contributor creates funding request
    • Community members vote during voting period
    • If approved, anyone executes the request to transfer funds
  4. Fund Distribution

    • Funds automatically transferred to initiative wallet
    • Initiative's funding-received counter updated
    • Pool balance reduced accordingly

Security Features

  • Input validation on all user-supplied data
  • Range checks on IDs to prevent invalid references
  • String validation to prevent empty inputs
  • Authorization checks for privileged operations
  • Vote tracking to prevent double-voting
  • Time-locked voting periods
  • Balance verification before transfers

Deployment

  1. Deploy the contract to Stacks blockchain
  2. Note the contract address for user interactions
  3. Configure minimum amounts and voting periods if needed
  4. Begin accepting initiative registrations

Testing Recommendations

  • Test initiative registration with valid/invalid inputs
  • Verify contribution and eligibility system
  • Test voting mechanics and time constraints
  • Confirm proposal execution logic
  • Test emergency withdrawal functionality
  • Verify authorization controls

About

This is a decentralized autonomous organization (DAO) smart contract that enables communities to collectively fund local initiatives through democratic governance. Built on the Stacks blockchain, it creates a transparent, trustless system where community members pool resources and vote on how to distribute funds to verified projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors