Skip to content

Implement Analytics Token Staking & Governance Core Functionality #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

david-cmd-byte
Copy link
Owner

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

  1. 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.
  2. Staking/Unstaking

    • stake-stx: Securely locks STX with optional lock-up bonuses.
    • initiate-unstake/complete-unstake: Enforces 24-hour cooldown for withdrawals.
  3. Governance Engine

    • create-proposal: Submit actions (e.g., reward adjustments) with ≥1M STX staked.
    • vote-on-proposal: Voting power scales with staked STX.
  4. Security & Controls

    • pause-contract/resume-contract: Owner-controlled emergency stops.
    • Validations for lock periods, descriptions, and voting windows.
  5. Reward System

    • Dynamic rewards via calculate-rewards, combining tier and lock multipliers.
    • Base 5% APY, adjustable through governance.
  6. Documentation

    • Detailed README with integration examples, error codes, and governance workflow.

Documentation

  • README includes:
    • Contract architecture and formulas.
    • Step-by-step integration guide.
    • Governance proposal lifecycle.
    • Error code reference table.

Notes for Reviewers

  1. Security Focus:
    • Cooldown periods prevent instant withdrawals.
    • All STX transfers use as-contract for atomic safety.
  2. Governance Limits:
    • Minimum 1M STX stake to submit proposals.
    • Voting power tied to staked balance.
  3. Extensibility:
    • TierLevels map allows future reward adjustments.
    • features-enabled supports protocol upgrades.

Impact: Establishes foundation for decentralized analytics governance.

- 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.
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