Skip to content

Conversation

@nicholas-source
Copy link
Owner

Overview

This PR implements the core functionality for the StacksFund smart contract, a decentralized fund management system built on the Stacks blockchain. The implementation includes deposit handling, proposal management, voting mechanisms, and fund execution capabilities.

Changes

Contract Structure

  • Added contract metadata and documentation
  • Implemented error constants and operational parameters
  • Set up data variables and maps for state management

Core Features

  1. Fund Management

    • Deposit functionality with minimum requirements
    • Time-locked withdrawal system
    • Token minting and burning mechanisms
  2. Proposal System

    • Proposal creation with validation
    • Voting mechanism with power calculation
    • Proposal execution with safety checks
  3. Access Control

    • Contract owner validation
    • Initialization controls
    • Balance and authorization checks

Technical Implementation

  • Added data maps for:

    • User balances
    • Deposit records
    • Proposal details
    • Vote tracking
  • Implemented private functions:

    • is-contract-owner
    • check-initialized
    • calculate-voting-power
    • transfer-tokens
    • mint-tokens
    • burn-tokens
    • validate-proposal-id
  • Added public functions:

    • initialize
    • deposit
    • withdraw
    • create-proposal
    • vote
    • execute-proposal
  • Implemented read-only functions:

    • get-balance
    • get-total-supply
    • get-proposal
    • get-deposit-info
    • get-vote

Testing

  • Unit tests added for all core functions
  • Integration tests for complete workflows
  • Edge case testing for security validation

Security Considerations

  • Time-locked deposits prevent instant withdrawals
  • Vote validation prevents double voting
  • Balance checks prevent overflow/underflow
  • Proper authorization checks throughout

Documentation

  • Added inline documentation for all functions
  • Updated contract description and usage guidelines
  • Included error code documentation

Implementation Details

Constants

(define-constant minimum-duration u144) ;; minimum 1 day
(define-constant maximum-duration u20160) ;; maximum 14 days
(define-constant minimum-deposit u1000000) ;; in microSTX

Key Functions

(define-public (deposit (amount uint))
(begin
    (try! (check-initialized))
    (asserts! (>= amount (var-get minimum-deposit)) err-below-minimum)
    ...
))

TODO

  • Add additional test coverage
  • Implement event logging
  • Add proposal description validation
  • Consider adding proposal categories

Deployment Plan

  1. Deploy to testnet
  2. Run integration tests
  3. Community review period
  4. Security audit
  5. Mainnet deployment

Checklist

  • Code follows project style guidelines
  • Documentation has been updated
  • Security considerations addressed
  • Breaking changes documented
  • Testnet deployment tested

Reviewers

@smart-contract-team @security-team

- Added contract title, summary, and description.
- Defined various error constants for contract operations.
- Set minimum and maximum duration constants for proposals.
- Defined data variables for total supply, minimum deposit, lock period, initialization status, last rebalance, and proposal count.
- Added data maps for tracking balances and deposits.
- Defined a data map for proposals with fields for proposer, description, amount, target, expiration, execution status, and vote counts.
- Added a data map for tracking votes by proposal ID and voter.
- Added `is-contract-owner` to check if the transaction sender is the contract owner.
- Added `check-initialized` to ensure the contract is initialized.
- Added `calculate-voting-power` to determine the voting power of a given voter.
- Added `transfer-tokens` function to handle token transfers between sender and recipient.
- Ensures sender has sufficient balance before transferring tokens.
- Updates balances of sender and recipient accordingly.
- Added `mint-tokens` function to mint new tokens for a specified account.
- Updates the account balance and total supply accordingly.
- Added `burn-tokens` function to burn tokens from a specified account.
- Ensures the account has sufficient balance before burning tokens.
- Updates the account balance and total supply accordingly.
- Added `initialize` function to set the contract as initialized by the contract owner.
- Added `deposit` function to allow users to deposit STX, update deposit records, and mint fund tokens.
- Added `withdraw` function to allow users to withdraw their deposited STX.
- Ensures the contract is initialized and the lock period has expired.
- Burns the corresponding fund tokens before transferring STX back to the user.
- Added `create-proposal` function to allow users to create new proposals.
- Validates input parameters including description, amount, target, and duration.
- Ensures the proposer has a positive balance and updates the proposal count.
- Added `vote` function to allow users to vote on proposals.
- Ensures the contract is initialized and the proposal exists.
- Validates the voter's power, proposal expiration, and if the user has already voted.
- Records the vote and updates the proposal's vote counts.
- Added `execute-proposal` function to execute approved proposals.
- Ensures the contract is initialized and the proposal exists.
- Validates the proposal's execution status, expiration, and vote counts.
- Transfers funds as specified in the proposal and marks it as executed.
- Added `get-balance` to retrieve the balance of a specified account.
- Added `get-total-supply` to get the total supply of tokens.
- Added `get-proposal` to fetch details of a specific proposal.
- Added `get-deposit-info` to get deposit information for a specified account.
- Added `validate-proposal-id` private function to ensure proposal ID is valid.
- Updated `vote` and `execute-proposal` functions to use `validate-proposal-id` for proposal ID validation.
- Added LICENSE file to specify the project's license.
- Added CONTRIBUTING file to guide contributors.
- Added README file to provide an overview and instructions for the project.
- Added SECURITY file to outline the security policy and contact information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants