Implement BitAnalytics Protocol with Tiered Staking & Governance#1
Open
opuelatei wants to merge 9 commits into
Open
Implement BitAnalytics Protocol with Tiered Staking & Governance#1opuelatei wants to merge 9 commits into
opuelatei wants to merge 9 commits into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces the core functionality for the BitAnalytics protocol, enabling decentralized analytics governance on Bitcoin via Stacks. Key additions include:
Changes Overview
1. Core Architecture & Data Structures
Proposalsmap to track governance proposals (creator, votes, status)UserPositionsandStakingPositionsmaps for staking managementminimum-stake,cooldown-period, reward rates)2. Tiered Staking System
TierLevelsmap (T1-T3)3. Staking/Unstaking Workflows
stake-stx: Enforces minimum stake, updates positions, calculates rewardsinitiate-unstake/complete-unstake: Implements 24h cooldown security4. Governance Engine
create-proposal: Requires Tier 2+ status and 1M µSTX voting powervote-on-proposal: Weighted voting based on staked amount5. Security & Controls
pause-contract,resume-contract)6. Documentation
stacks-block-heightImpact
Reviewer Checklist
initialize-contractTesting Notes
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."