Implement core staking, governance, and tier systems with enhanced security controls#1
Open
timileyin-create wants to merge 8 commits into
Open
Implement core staking, governance, and tier systems with enhanced security controls#1timileyin-create wants to merge 8 commits into
timileyin-create wants to merge 8 commits into
Conversation
… tracking fields The `UserPositions` map was updated to include new fields: `analytics-tokens`, `voting-power`, `tier-level`, and `rewards-multiplier`. These additions enable more granular tracking of user participation in governance and reward systems. Key changes: - Added `analytics-tokens` to track the number of ANALYTICS-TOKEN rewards earned by users. - Introduced `voting-power` to represent a user's influence in governance decisions. - Added `tier-level` to classify users into different staking tiers with escalating privileges. - Included `rewards-multiplier` to calculate dynamic reward rates based on user tier and staking behavior. Impact: - Enhances governance functionality by enabling weighted voting based on staking. - Improves reward distribution accuracy with tier-based multipliers. - Supports the protocol's tiered staking system, aligning with the platform's design goals.
The `initialize-contract` function now includes logic to set up the tier system configuration for staking. This feature defines three tiers with escalating privileges, minimum staking requirements, and reward multipliers. Key changes: - Added `TierLevels` map entries for three tiers: - Tier 1: Minimum stake of 1,000,000 STX, 1x reward multiplier, and limited features. - Tier 2: Minimum stake of 5,000,000 STX, 1.5x reward multiplier, and additional features. - Tier 3: Minimum stake of 10,000,000 STX, 2x reward multiplier, and full feature access. - Ensured only the contract owner can initialize the tiers using an authorization check. Impact: - Establishes a structured tier system for staking with clear privileges and rewards. - Enhances user incentives by offering higher rewards and features for larger stakes. - Lays the foundation for a scalable and configurable staking mechanism.
… multiplier The `stake-stx` function was introduced to allow users to stake STX tokens, update their staking positions, and calculate rewards dynamically based on tier levels and lock periods. Key changes: - Added validation for lock periods, contract pause state, and minimum stake requirements. - Implemented STX transfer to the contract for staking. - Updated `StakingPositions` map to track staking details such as amount, start block, lock period, and rewards. - Updated `UserPositions` map to reflect the user's total stake, tier level, and rewards multiplier. - Integrated tier-based reward calculation using `get-tier-info` and lock period multiplier. Impact: - Enables users to stake STX tokens securely and participate in the protocol. - Provides dynamic reward calculation based on staking tiers and lock periods. - Enhances user incentives by offering higher rewards for longer lock periods and larger stakes.
The `initiate-unstake` and `complete-unstake` functions were implemented to allow users to unstake their STX tokens while enforcing a cooldown period for security and protocol stability. Key changes: - **`initiate-unstake`**: - Validates that the user has sufficient staked tokens to unstake. - Ensures no active cooldown is in progress for the staking position. - Records the block height at which the cooldown period starts. - **`complete-unstake`**: - Validates that the cooldown period has elapsed before allowing the unstake to complete. - Transfers the staked amount back to the user. - Deletes the user's staking position from the `StakingPositions` map. Impact: - Introduces a secure and structured process for unstaking STX tokens. - Prevents immediate unstaking, mitigating risks during market volatility. - Enhances protocol stability by enforcing a cooldown mechanism.
The `create-proposal` and `vote-on-proposal` functions were added to enable decentralized governance within the protocol. These functions allow users to create proposals and cast votes based on their voting power. Key changes: - **`create-proposal`**: - Validates that the user has sufficient voting power to create a proposal. - Ensures the proposal description and voting period are valid. - Records the proposal details, including creator, description, start and end blocks, and vote counts. - **`vote-on-proposal`**: - Validates the proposal ID and ensures the voting period is still active. - Allows users to cast votes either in favor or against the proposal. - Updates the proposal's vote counts based on the user's voting power. Impact: - Enables decentralized governance by allowing users to propose and vote on protocol changes. - Ensures fair voting by weighting votes according to users' staking positions. - Strengthens the protocol's community-driven decision-making process.
…l management The `pause-contract`, `resume-contract`, and read-only utility functions were implemented to provide administrative control and access to key contract data. Key changes: - **`pause-contract`**: - Allows the contract owner to pause the protocol, preventing certain operations during emergencies. - Ensures only the contract owner can execute this function. - **`resume-contract`**: - Enables the contract owner to resume the protocol after it has been paused. - Includes authorization checks to restrict access. - **Read-only functions**: - `get-contract-owner`: Returns the contract owner's address. - `get-stx-pool`: Retrieves the current STX pool balance. - `get-proposal-count`: Provides the total number of proposals created. - **Private function**: - `get-tier-info`: Determines the user's tier level and reward multiplier based on their stake amount. Impact: - Improves protocol security by allowing the owner to pause and resume operations during critical situations. - Enhances transparency by providing read-only access to essential contract data. - Supports tier-based reward calculations with the `get-tier-info` function.
This update introduces private utility functions to enhance the protocol's functionality, including reward calculation, lock period multipliers, and input validation for descriptions, lock periods, and voting periods.
Key changes:
- **`calculate-lock-multiplier`**:
- Determines a multiplier based on the staking lock period:
- 2 months: 1.5x multiplier.
- 1 month: 1.25x multiplier.
- No lock: 1x multiplier.
- **`calculate-rewards`**:
- Computes staking rewards based on the user's stake amount, base reward rate, multiplier, and the number of blocks elapsed.
- **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.
Impact:
- Improves reward calculation accuracy with dynamic multipliers.
- Enhances protocol security by validating user inputs for proposals and staking.
- Supports flexible staking and governance configurations.
…rotocol The README file was updated to provide comprehensive documentation for the BitStride protocol, including its features, workflows, and technical specifications. Key changes: - **Overview**: - Introduced BitStride as an institutional-grade DeFi protocol combining Bitcoin security with Stacks Layer 2 capabilities. - Highlighted key features such as staking, governance, and tiered rewards. - **Key Features**: - Detailed the staking engine, governance module, and institutional tier system. - Included a table summarizing tier privileges and multipliers. - **Technical Specifications**: - Documented core components like ANALYTICS-TOKEN, staking parameters, and governance controls. - Provided reward calculation formulas and cooldown period details. - **System Workflows**: - Added a mermaid diagram for the staking process. - Outlined the governance lifecycle from proposal creation to execution. - **Security Architecture**: - Described multi-layer protection mechanisms, including Bitcoin finality, Stacks safeguards, and protocol-level controls. - **Code Examples**: - Included Clarity code snippets for staking, proposal creation, voting, and unstaking. Impact: - Enhances developer and user understanding of the protocol. - Provides clear instructions for interacting with the smart contract. - Improves transparency and accessibility for institutional participants.
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.
Overview
This PR introduces the foundational components for BitStride's institutional-grade DeFi protocol on Stacks L2, combining Bitcoin-secured transactions with advanced staking mechanics and decentralized governance.
Feature Additions
1. Tiered Staking Engine
2. Governance Module
3. Security Architecture
Technical Improvements
Documentation
This implementation establishes BitStride as enterprise-ready DeFi infrastructure, combining Bitcoin's security with institutional-grade staking features and community governance.