Implement Analytics Token Staking & Governance Core Functionality#1
Open
david-cmd-byte wants to merge 7 commits intomainfrom
Open
Implement Analytics Token Staking & Governance Core Functionality#1david-cmd-byte wants to merge 7 commits intomainfrom
david-cmd-byte wants to merge 7 commits intomainfrom
Conversation
- Define `Proposals` map to store governance proposal details including creator, description, start/end blocks, execution status, votes for/against, and minimum votes. - Define `UserPositions` map to store user account data including total collateral, total debt, health factor, last updated timestamp, stx staked, analytics tokens, voting power, tier level, and rewards multiplier.
- Define `StakingPositions` map to store staking details including amount, start block, last claim, lock period, cooldown start, and accumulated rewards. - Define `TierLevels` map to configure tier levels with minimum stake, reward multiplier, and enabled features. - Implement `initialize-contract` public function to set up initial tier levels with respective configurations.
- Add `stake-stx` public function to allow users to stake STX tokens with a specified lock period. - Validate lock period, contract status, and minimum stake amount. - Transfer STX tokens from user to contract. - Update `StakingPositions` and `UserPositions` maps with new staking details. - Adjust user's tier level and rewards multiplier based on the new total stake and lock period. - Update the STX pool with the staked amount.
- Implement `initiate-unstake` public function to start the unstaking process by setting the cooldown start block. - Implement `complete-unstake` public function to complete the unstaking process after the cooldown period and transfer STX back to the user. - Implement `create-proposal` public function to allow users to create governance proposals with a description and voting period. - Validate user authorization, description, and voting period for proposals. - Update `Proposals` map and increment proposal count.
- Implement `vote-on-proposal` public function to allow users to vote on governance proposals. - Validate proposal existence, voting period, and user authorization. - Update proposal votes based on user input. - Implement `pause-contract` and `resume-contract` public functions to allow the contract owner to pause and resume the contract. - Implement read-only functions `get-contract-owner`, `get-stx-pool`, and `get-proposal-count` to retrieve contract owner, STX pool balance, and proposal count. - Add private functions `get-tier-info` and `calculate-lock-multiplier` to determine tier level and reward multiplier based on stake amount and lock period.
- Implement `calculate-rewards` private function to calculate rewards based on user's stake amount, base rate, multiplier, and number of blocks. - Implement `is-valid-description` private function to validate proposal descriptions ensuring they meet length requirements. - Implement `is-valid-lock-period` private function to validate lock periods ensuring they match predefined durations. - Implement `is-valid-voting-period` private function to validate voting periods ensuring they fall within acceptable range.
- Provide an overview of the contract's purpose and key features. - Include instructions for deploying and interacting with the contract. - Document public functions, data maps, and error codes.
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.
Description
This PR introduces a comprehensive staking and governance system for the Analytics Protocol, enabling users to stake STX tokens, earn rewards, and participate in decentralized decision-making. The implementation includes tiered rewards, governance proposals/voting, cooldown-protected withdrawals, and robust administrative controls.
Key Changes
Core Data Structures
Proposals: Governance proposals with metadata, votes, and execution status.UserPositions: Tracks staking balances, tiers, voting power, and rewards.StakingPositions: Manages lock periods, cooldowns, and accrued rewards.TierLevels: Configures reward multipliers and features per staking tier.Staking/Unstaking
stake-stx: Securely locks STX with optional lock-up bonuses.initiate-unstake/complete-unstake: Enforces 24-hour cooldown for withdrawals.Governance Engine
create-proposal: Submit actions (e.g., reward adjustments) with ≥1M STX staked.vote-on-proposal: Voting power scales with staked STX.Security & Controls
pause-contract/resume-contract: Owner-controlled emergency stops.Reward System
calculate-rewards, combining tier and lock multipliers.Documentation
Documentation
Notes for Reviewers
as-contractfor atomic safety.TierLevelsmap allows future reward adjustments.features-enabledsupports protocol upgrades.Impact: Establishes foundation for decentralized analytics governance.