Skip to content

Bitcoin Native DAO Smart Contract Implementation - #1

Open
esthercodez1 wants to merge 19 commits into
mainfrom
feature/add-contract
Open

esthercodez1 wants to merge 19 commits into
mainfrom
feature/add-contract

Conversation

@esthercodez1

Copy link
Copy Markdown
Owner

Description

This pull request introduces a comprehensive implementation of a Bitcoin Native DAO (Decentralized Autonomous Organization) smart contract on the Stacks blockchain. The contract provides a robust framework for decentralized governance, enabling Bitcoin holders to participate in collective decision-making through staking, proposal creation, and voting mechanisms.

Key Features Implemented

  • Staking Mechanism

    • Users can stake Bitcoin tokens
    • Minimum stake requirements
    • Time-locked staking periods
  • Governance Functionality

    • Proposal creation and voting
    • Stake-weighted voting system
    • Quorum-based proposal execution
  • Treasury Management

    • Secure fund transfers
    • Whitelisted recipient validation
    • Proposal-based fund allocation

Notable Improvements

  • Comprehensive error handling
  • Owner-only administrative functions
  • Flexible governance parameters
  • Enhanced security checks
  • Whitelisted recipient management

Changes Detailed

Contract Components

  • Added constants for error handling and contract management
  • Implemented data maps for:
    • Proposals
    • Stakes
    • Votes
    • Whitelisted Recipients

Core Functions

  • stake(): Token staking with lock periods
  • unstake(): Token withdrawal mechanism
  • create-proposal(): Proposal submission with validation
  • vote(): Stake-weighted voting
  • execute-proposal(): Proposal execution with quorum checks

Administrative Functions

  • update-minimum-stake()
  • update-quorum-percentage()
  • update-voting-period()
  • set-whitelisted-recipient()

Testing Considerations

  • Verify staking and unstaking mechanics
  • Test proposal creation and voting workflows
  • Validate quorum and execution logic
  • Check administrative function access controls

Potential Future Enhancements

  • More granular voting mechanisms
  • Advanced proposal types
  • Enhanced recipient validation
  • Time-locked governance tokens

Documentation

A comprehensive README has been added, providing:

  • Detailed contract overview
  • Usage instructions
  • Deployment guidelines
  • Contribution framework

Checklist

  • Implemented core DAO functionality
  • Added comprehensive error handling
  • Created detailed documentation
  • Implemented security best practices
  • Complete unit testing
  • Conduct security audit

Reviewer Guidance

Please review:

  • Staking and voting mechanics
  • Security checks and access controls
  • Error handling robustness
  • Overall contract architecture

Approval Status

Pending comprehensive review and testing.

- Define contract owner constant
- Add error constants for various contract conditions:
  - Owner-only actions
  - Insufficient balance
  - Proposal not found
  - Already voted
  - Proposal expired
  - Invalid amount
  - Not a stakeholder
  - Proposal not active
  - Invalid quorum
  - Proposal not expired
- Define minimum stake (1 BTC in sats)
- Initialize proposal count to 0
- Set quorum percentage to 51%
- Set voting period to approximately 1 day in Bitcoin blocks
- Define proposals map with the following fields:
  - title: ASCII string (max 100 characters)
  - description: ASCII string (max 500 characters)
  - proposer: principal
  - amount: uint
  - recipient: principal
  - start-block: uint
  - end-block: uint
  - yes-votes: uint
  - no-votes: uint
  - status: ASCII string (max 20 characters)
  - executed: bool
- Define stakes map with the following fields:
  - amount: uint
  - lock-until: uint
- Define votes map with the following fields:
  - proposal-id: uint
  - voter: principal
  - voted: bool
  - vote: bool
- get-proposal: Retrieve proposal details by proposal ID
- get-stake: Retrieve stake details by staker principal
- get-vote: Retrieve vote details by proposal ID and voter principal
- calculate-voting-power: Calculate voting power based on staker's amount
- is-proposal-active: Determine if a proposal is active based on block height and status
- stake: Allows users to stake a specified amount of tokens
  - Transfers tokens to the contract
  - Updates the staker's amount and lock period
  - Ensures the amount is above the minimum stake
- unstake: Allows users to unstake a specified amount of tokens
  - Transfers tokens back to the user
  - Updates the staker's amount and lock period
  - Ensures the amount is available and the lock period has expired
- create-proposal: Allows users to create a new proposal
  - Requires a title, description, amount, and recipient
  - Checks if the proposer has the minimum stake
  - Sets proposal details including start and end blocks, and initializes votes and status
  - Increments the proposal count
- vote: Allows users to vote on a proposal
  - Checks if the proposal is active and the user has not voted before
  - Records the user's vote
  - Updates the proposal's yes-votes or no-votes based on the user's stake
- execute-proposal: Allows users to execute a proposal
  - Checks if the proposal is not already executed and has expired
  - Verifies if the proposal meets the quorum requirements
  - Transfers the proposal amount to the recipient if approved
  - Updates the proposal status to executed or rejected
- update-minimum-stake: Allows the contract owner to update the minimum stake amount
  - Ensures the caller is the contract owner
  - Sets the new minimum stake value
- update-quorum-percentage: Allows the contract owner to update the quorum percentage
  - Ensures the caller is the contract owner
  - Validates the new percentage is between 1 and 100
  - Sets the new quorum percentage value
- update-voting-period: Allows the contract owner to update the voting period
  - Ensures the caller is the contract owner
  - Sets the new voting period value
- Renamed private is-valid-recipient function to is-valid-recipient-private
- Resolved runtime error: NameAlreadyUsed("is-valid-recipient")
- Improved code clarity and removed function duplication
…main branch

This commit introduces a comprehensive README for the Bitcoin Native DAO smart contract. The README includes the following sections:

- Overview of the DAO and its purpose
- Key functionalities such as staking, proposal creation, voting, and treasury management
- Detailed explanation of contract components, including constants, data variables, and main functions
- Security measures implemented in the contract
- Usage examples to guide users in interacting with the smart contract
- Deployment requirements and initial configuration guidelines
- Limitations, considerations, and recommended improvements for future development
- Contribution guidelines for the community

This README serves as a foundational guide for developers, users, and contributors.
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.

1 participant