Skip to content

Conversation

@ud-cmd
Copy link
Owner

@ud-cmd ud-cmd commented Mar 26, 2025

Overview

This PR introduces the core functionality for StakeStream - a Bitcoin-native DeFi protocol combining tiered staking with on-chain governance. The implementation establishes secure STX staking mechanics, decentralized decision-making, and adaptive reward systems while maintaining compliance with Stacks L2 standards.

Key Features

Tiered Staking Architecture

  • Bronze/Silver/Gold tiers with 1M/5M/10M uSTX requirements
  • Time-lock multipliers (1-1.5x) for extended commitments
  • Dynamic reward calculation:
    Rewards = (Stake × Base Rate × Tier Multiplier × Lock Multiplier × Blocks) / 14,400,000

On-Chain Governance Engine

  • Proposal system with description/period validation
  • Voting power derived from staked positions
  • Quadratic voting weights with minimum quorum enforcement

Enterprise-Grade Security

  • 24-hour unstaking cooldown period
  • Emergency protocol freeze capability
  • Block height-anchored time locks
  • 17 validation checks across operations

Technical Implementation

Core Components

Component Purpose Key Data
Proposals Governance tracking Creator, votes, execution status
UserPositions Stake management Tier level, voting power, rewards
TierLevels Reward configuration Multipliers, feature flags

Validation Framework

  • Proposal descriptions: 10-256 characters
  • Lock periods: 0/4320/8640 blocks
  • Voting periods: 100-2880 blocks
  • Minimum stake enforcement (1M uSTX)

Documentation

  • Comprehensive README with:
    • Protocol architecture diagrams
    • Fee structure breakdown
    • Risk management policies
    • Deployment guidelines

Review Notes

Please pay special attention to:

  • Reward calculation precision (uSTX handling)
  • Voting power accumulation logic
  • Cooldown period block math
  • Tier threshold validation

This implementation establishes StakeStream as a foundational DeFi primitive for Bitcoin ecosystem, combining yield generation with decentralized governance. Looking forward to community feedback to strengthen protocol security and functionality.

ud-cmd added 8 commits March 26, 2025 13:46
- Define `Proposals` map to store proposal details, including:
  - `creator`, `description`, `start-block`, and `end-block`.
  - Voting-related fields: `executed`, `votes-for`, `votes-against`, and `minimum-votes`.
- Enables on-chain governance functionality with proposal management.

This commit lays the groundwork for decentralized governance within the StakeStream protocol.
- Define `UserPositions` map to track user-specific staking and governance data.
- Define `StakingPositions` map to manage individual staking details.
- Define `TierLevels` map to configure tier-based staking rewards and features.
- Implement `initialize-contract` function to set up initial tier levels:
  - Bronze (1M uSTX, 1x multiplier).
  - Silver (5M uSTX, 1.5x multiplier).
  - Gold (10M uSTX, 2x multiplier).

This commit establishes the core data structures and initialization logic for the StakeStream protocol.
- Add `stake-stx` public function to enable users to stake STX tokens.
- Validate lock period, contract state, and minimum stake amount.
- Transfer staked STX to the contract securely.
- Calculate and update user tier level and rewards multiplier based on total stake and lock period.
- Update `StakingPositions` and `UserPositions` maps with staking details.
- Increment the STX pool variable to reflect the new stake.

This commit introduces the core staking mechanism for the StakeStream protocol.
- Implement `initiate-unstake` function:
  - Validates staking position and ensures no active cooldown.
  - Sets a cooldown period for unstaking.

- Implement `complete-unstake` function:
  - Validates cooldown completion before transferring STX back to the user.
  - Clears the user's staking position after successful unstaking.

- Implement `create-proposal` function:
  - Allows users with sufficient voting power to create governance proposals.
  - Validates proposal description and voting period.
  - Tracks proposals in the `Proposals` map and increments the proposal count.

This commit enhances the protocol with unstaking operations and governance proposal creation.
- Implement `vote-on-proposal` function:
  - Allows users to cast votes on governance proposals.
  - Updates `votes-for` or `votes-against` based on the user's choice and voting power.
  - Validates proposal existence, voting period, and user's voting power.

- Add administrative functions:
  - `pause-contract`: Enables the contract owner to pause the protocol.
  - `resume-contract`: Allows the contract owner to resume the protocol.

- Add read-only functions:
  - `get-contract-owner`: Returns the contract owner.
  - `get-stx-pool`: Retrieves the current STX pool balance.

This commit finalizes governance voting, administrative controls, and essential read-only queries for the StakeStream protocol.
…tions

- Implement `get-tier-info`:
  - Determines the user's tier level and reward multiplier based on their stake amount.

- Implement `calculate-lock-multiplier`:
  - Calculates a multiplier based on the lock period (1x for no lock, 1.25x for 1 month, 1.5x for 2 months).

- Implement `calculate-rewards`:
  - Computes staking rewards based on stake amount, base rate, multiplier, and elapsed blocks.

- Add validation functions:
  - `is-valid-description`: Ensures proposal descriptions meet length requirements.
  - `is-valid-lock-period`: Validates lock periods (no lock, 1 month, or 2 months).
  - `is-valid-voting-period`: Validates voting periods (minimum 100 blocks, maximum 2880 blocks).

- Add `get-proposal-count` read-only function:
  - Returns the current proposal count for governance tracking.

This commit introduces essential utility and validation functions to support staking, rewards, and governance operations.
…r block references

- Updated `stake-stx` function to use `stacks-block-height` for `start-block` and `last-claim` fields in `StakingPositions`.
- Modified `initiate-unstake` to set `cooldown-start` using `stacks-block-height`.
- Adjusted `complete-unstake` to calculate cooldown duration using `stacks-block-height`.
- Updated `create-proposal` and `vote-on-proposal` functions to reference `stacks-block-height` for proposal start and end blocks.

This ensures consistent and accurate block height references across staking and governance operations.
- Documented key features:
  - Tiered staking system with multipliers and lock periods.
  - Governance engine with proposal creation and voting.
  - Adaptive reward calculation formula.

- Added technical architecture:
  - Core data structures for tiers, user positions, and staking positions.

- Detailed staking operations:
  - `stake-stx`, `initiate-unstake`, and `complete-unstake` workflows.

- Explained governance functionality:
  - Proposal creation and voting mechanics with validation rules.

- Highlighted security model:
  - Cooldown enforcement, emergency toggle, and input validation.

- Included installation and usage instructions:
  - Deployment steps and sample contract interactions.

This README provides a complete overview of the StakeStream protocol for developers and users.
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