Skip to content

Implement BitAnalytics Protocol with Tiered Staking & Governance#1

Open
opuelatei wants to merge 9 commits into
mainfrom
feat/develop
Open

Implement BitAnalytics Protocol with Tiered Staking & Governance#1
opuelatei wants to merge 9 commits into
mainfrom
feat/develop

Conversation

@opuelatei

Copy link
Copy Markdown
Owner

Summary

This PR introduces the core functionality for the BitAnalytics protocol, enabling decentralized analytics governance on Bitcoin via Stacks. Key additions include:

  • Tiered staking system with rewards multipliers
  • On-chain governance with proposal creation and voting
  • Secure unstaking mechanics with cooldown periods
  • Comprehensive contract administration controls

Changes Overview

1. Core Architecture & Data Structures

  • Added Proposals map to track governance proposals (creator, votes, status)
  • Implemented UserPositions and StakingPositions maps for staking management
  • Defined protocol parameters (minimum-stake, cooldown-period, reward rates)

2. Tiered Staking System

  • Configured 3-tier structure via TierLevels map (T1-T3)
    • T1: 1 STX (1x rewards)
    • T3: 10 STX (2x rewards + full governance rights)
  • Integrated lock period multipliers (up to 1.5x for 60-day commitments)

3. Staking/Unstaking Workflows

  • stake-stx: Enforces minimum stake, updates positions, calculates rewards
  • initiate-unstake/complete-unstake: Implements 24h cooldown security

4. Governance Engine

  • create-proposal: Requires Tier 2+ status and 1M µSTX voting power
  • vote-on-proposal: Weighted voting based on staked amount

5. Security & Controls

  • Contract pausing/resuming (pause-contract, resume-contract)
  • Input validation for proposals, lock periods, and voting windows

6. Documentation

  • Added comprehensive README with protocol specs, workflows, and audit checklist
  • Standardized block height references using stacks-block-height

Impact

  • ✅ Enables decentralized governance of Bitcoin analytics infrastructure
  • ✅ Incentivizes long-term participation via tiered rewards
  • ✅ Provides enterprise-grade security through cooldowns and admin controls
  • ✅ Creates foundation for STX-based analytics economy

Reviewer Checklist

  • Verify tier configuration in initialize-contract
  • Test end-to-end staking/unstaking flow
  • Validate proposal creation/voting thresholds
  • Confirm reward calculations match specs
  • Review emergency control functionality

Testing Notes

  1. Stake STX with different lock periods to test multipliers
  2. Create proposals with insufficient voting power (should fail)
  3. Attempt unstaking during cooldown period (should revert)
  4. Simulate contract pause during active operations

Ready for Review
This implementation establishes BitAnalytics as a leader in Bitcoin-native decentralized analytics. Thank you for your detailed review! Let me know if you need clarifications or additional testing scenarios.

"Building trustless analytics for Bitcoin's future."

… contract

- Define `Proposals` map to manage governance proposals with details such as creator, description, voting data, and execution status.
- Define `UserPositions` map to track user-specific staking data, including collateral, debt, staking amounts, voting power, and rewards.
- Introduce key staking parameters such as `minimum-stake` and `cooldown-period` for protocol security and governance.
- Enhance contract architecture to support tiered staking, voting, and rewards distribution.
- Define `TierLevels` map to configure staking tiers with minimum stake, reward multipliers, and feature enablement.
- Implement `initialize-contract` public function to set up initial tier levels with predefined configurations.
- Ensure only the contract owner can initialize the contract using authorization checks.
…riods

- Add `stake-stx` public function to allow users to stake STX tokens.
- Validate staking conditions, including lock period, contract state, and minimum stake amount.
- Update `StakingPositions` map with staking details such as amount, start block, lock period, and rewards.
- Update `UserPositions` map to reflect new staking totals, tier level, and rewards multiplier based on tier and lock period.
- Increment the `stx-pool` variable to track the total staked STX in the contract.
- Implement `initiate-unstake` public function to allow users to start the unstaking process.
  - Validate sufficient staked amount and ensure no active cooldown period.
  - Update `StakingPositions` map to record the cooldown start block.
- Implement `complete-unstake` public function to finalize the unstaking process.
  - Validate that the cooldown period has elapsed before transferring staked tokens back to the user.
  - Remove the user's staking position from the `StakingPositions` map upon completion.
- Implement `create-proposal` public function to allow users to create governance proposals.
  - Validate user voting power and proposal parameters such as description and voting period.
  - Store proposal details in the `Proposals` map, including creator, description, voting data, and execution status.
  - Increment the `proposal-count` variable to track the total number of proposals.

- Implement `vote-on-proposal` public function to enable users to vote on proposals.
  - Validate the proposal's existence, voting eligibility, and that the voting period is still active.
  - Update the `Proposals` map with votes for or against based on the user's voting power.
- Implement `pause-contract` and `resume-contract` public functions to allow the contract owner to pause or resume contract operations.
  - Ensure only the contract owner can perform these actions using authorization checks.
  - Update the `contract-paused` variable to reflect the current state.

- Add read-only functions:
  - `get-contract-owner`: Returns the contract owner.
  - `get-stx-pool`: Returns the total STX pool in the contract.
  - `get-proposal-count`: Returns the total number of proposals created.

- Add `get-tier-info` private function to determine the tier level and reward multiplier based on the stake amount.
- Implement `calculate-lock-multiplier` private function to determine the rewards multiplier based on the lock period:
  - 1.5x multiplier for a 2-month lock period.
  - 1.25x multiplier for a 1-month lock period.
  - 1x multiplier for no lock.

- Implement `calculate-rewards` private function to compute staking rewards:
  - Rewards are calculated based on the stake amount, base rate, user multiplier, and the number of blocks.

- Add validation functions:
  - `is-valid-description`: Ensures proposal descriptions are between 10 and 256 characters.
  - `is-valid-lock-period`: Validates lock periods (0, 1 month, or 2 months).
  - `is-valid-voting-period`: Ensures voting periods are between 100 and 2880 blocks.
- Updated all instances of block height references to use `stacks-block-height` for consistency and clarity.
- Ensures uniformity across the contract and aligns with Stacks blockchain standards.
- Documented protocol overview, key features, and architecture.
- Added instructions for staking, unstaking, and governance operations.
- Included reward calculation formula and tier structure details.
- Highlighted security features, error handling, and audit checklist.
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