From 88e848291f30a319363281fb53732d312c3f0105 Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:15:46 +0100 Subject: [PATCH 1/7] feat: Initialize BitStack Protocol with core functionalities - Define ANALYTICS-TOKEN fungible token - Set up constants for contract owner and error handling - Initialize data variables for contract state management - Create data maps for proposals and user positions - Implement staking, governance, and reward distribution mechanisms --- contracts/bitstack.clar | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 contracts/bitstack.clar diff --git a/contracts/bitstack.clar b/contracts/bitstack.clar new file mode 100644 index 0000000..b6e88f9 --- /dev/null +++ b/contracts/bitstack.clar @@ -0,0 +1,72 @@ +;; Title: BitStack Protocol - Bitcoin-Aligned DeFi Analytics & Governance Engine +;; Summary: Secure Layer 2 analytics platform combining multi-tier Bitcoin staking, decentralized governance, and institutional-grade risk controls +;; Description: +;; BitStack Protocol is a Stacks Layer 2 solution offering Bitcoin-native financial analytics through an innovative staking architecture. The protocol enables: +;; - Tiered STX staking with time-lock bonuses and health factor monitoring +;; - On-chain governance powered by Bitcoin's security model +;; - Real-time debt position tracking with automatic collateralization checks +;; - Emergency circuit breakers compliant with Bitcoin finality requirements +;; Designed for seamless Bitcoin interoperability, BitStack implements: +;; - Stacks-aware reward distribution cycles aligned with Bitcoin blocks +;; - Non-custodial staking with CLARITY-safe asset management +;; - Governance proposals enforceable through Bitcoin-anchored transactions +;; - Compliance with Bitcoin's UTXO model for transparent accounting +;; Built for institutional DeFi participants, BitStack combines Layer 2 efficiency with Bitcoin's settlement guarantees through: +;; - 24-block cooldown periods mirroring Bitcoin's confirmation standards +;; - Multi-sig compatible emergency recovery modes +;; - STX/BTC exchange rate aware collateral calculations +;; - Miner-extractable value (MEV) resistant reward distribution + +;; token definitions +(define-fungible-token ANALYTICS-TOKEN u0) + +;; constants +(define-constant CONTRACT-OWNER tx-sender) +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-INVALID-PROTOCOL (err u1001)) +(define-constant ERR-INVALID-AMOUNT (err u1002)) +(define-constant ERR-INSUFFICIENT-STX (err u1003)) +(define-constant ERR-COOLDOWN-ACTIVE (err u1004)) +(define-constant ERR-NO-STAKE (err u1005)) +(define-constant ERR-BELOW-MINIMUM (err u1006)) +(define-constant ERR-PAUSED (err u1007)) + +;; data vars +(define-data-var contract-paused bool false) +(define-data-var emergency-mode bool false) +(define-data-var stx-pool uint u0) +(define-data-var base-reward-rate uint u500) ;; 5% base rate (100 = 1%) +(define-data-var bonus-rate uint u100) ;; 1% bonus for longer staking +(define-data-var minimum-stake uint u1000000) ;; Minimum stake amount +(define-data-var cooldown-period uint u1440) ;; 24 hour cooldown in blocks +(define-data-var proposal-count uint u0) + +;; data maps +(define-map Proposals + { proposal-id: uint } + { + creator: principal, + description: (string-utf8 256), + start-block: uint, + end-block: uint, + executed: bool, + votes-for: uint, + votes-against: uint, + minimum-votes: uint + } +) + +(define-map UserPositions + principal + { + total-collateral: uint, + total-debt: uint, + health-factor: uint, + last-updated: uint, + stx-staked: uint, + analytics-tokens: uint, + voting-power: uint, + tier-level: uint, + rewards-multiplier: uint + } +) From 014d4fa901625fe5cc6166bfddd9b8d82b5ab7f1 Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:17:34 +0100 Subject: [PATCH 2/7] feat: Add staking and tier level initialization functions - Define `StakingPositions` and `TierLevels` data maps - Implement `initialize-contract` function to set up tier levels - Add `stake-stx` function to allow users to stake STX tokens with optional lock periods - Update user positions and STX pool accordingly --- Clarinet.toml | 30 +++++------ contracts/bitstack.clar | 116 ++++++++++++++++++++++++++++++++++++++++ tests/bitstack.test.ts | 21 ++++++++ 3 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 tests/bitstack.test.ts diff --git a/Clarinet.toml b/Clarinet.toml index d767c45..3209bbb 100644 --- a/Clarinet.toml +++ b/Clarinet.toml @@ -1,21 +1,19 @@ [project] -name = "BitStack" -description = "" +name = 'BitStack' +description = '' authors = [] telemetry = true -cache_dir = "./.cache" - -# [contracts.counter] -# path = "contracts/counter.clar" - +cache_dir = './.cache' +requirements = [] +[contracts.bitstack] +path = 'contracts/bitstack.clar' +clarity_version = 3 +epoch = 3.1 [repl.analysis] -passes = ["check_checker"] -check_checker = { trusted_sender = false, trusted_caller = false, callee_filter = false } +passes = ['check_checker'] -# Check-checker settings: -# trusted_sender: if true, inputs are trusted after tx_sender has been checked. -# trusted_caller: if true, inputs are trusted after contract-caller has been checked. -# callee_filter: if true, untrusted data may be passed into a private function without a -# warning, if it gets checked inside. This check will also propagate up to the -# caller. -# More informations: https://www.hiro.so/blog/new-safety-checks-in-clarinet +[repl.analysis.check_checker] +strict = false +trusted_sender = false +trusted_caller = false +callee_filter = false diff --git a/contracts/bitstack.clar b/contracts/bitstack.clar index b6e88f9..6995981 100644 --- a/contracts/bitstack.clar +++ b/contracts/bitstack.clar @@ -70,3 +70,119 @@ rewards-multiplier: uint } ) + +(define-map StakingPositions + principal + { + amount: uint, + start-block: uint, + last-claim: uint, + lock-period: uint, + cooldown-start: (optional uint), + accumulated-rewards: uint + } +) + +(define-map TierLevels + uint + { + minimum-stake: uint, + reward-multiplier: uint, + features-enabled: (list 10 bool) + } +) + +;; public functions + +;; Initializes the contract and sets up the tier levels +(define-public (initialize-contract) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED) + + ;; Set up tier levels + (map-set TierLevels u1 + { + minimum-stake: u1000000, ;; 1M uSTX + reward-multiplier: u100, ;; 1x + features-enabled: (list true false false false false false false false false false) + }) + (map-set TierLevels u2 + { + minimum-stake: u5000000, ;; 5M uSTX + reward-multiplier: u150, ;; 1.5x + features-enabled: (list true true true false false false false false false false) + }) + (map-set TierLevels u3 + { + minimum-stake: u10000000, ;; 10M uSTX + reward-multiplier: u200, ;; 2x + features-enabled: (list true true true true true false false false false false) + }) + (ok true) + ) +) + +;; Allows users to stake STX tokens with an optional lock period +(define-public (stake-stx (amount uint) (lock-period uint)) + (let + ( + (current-position (default-to + { + total-collateral: u0, + total-debt: u0, + health-factor: u0, + last-updated: u0, + stx-staked: u0, + analytics-tokens: u0, + voting-power: u0, + tier-level: u0, + rewards-multiplier: u100 + } + (map-get? UserPositions tx-sender))) + ) + (asserts! (is-valid-lock-period lock-period) ERR-INVALID-PROTOCOL) + (asserts! (not (var-get contract-paused)) ERR-PAUSED) + (asserts! (>= amount (var-get minimum-stake)) ERR-BELOW-MINIMUM) + + ;; Transfer STX to contract + (try! (stx-transfer? amount tx-sender (as-contract tx-sender))) + + ;; Calculate tier level and multiplier + (let + ( + (new-total-stake (+ (get stx-staked current-position) amount)) + (tier-info (get-tier-info new-total-stake)) + (lock-multiplier (calculate-lock-multiplier lock-period)) + ) + + ;; Update staking position + (map-set StakingPositions + tx-sender + { + amount: amount, + start-block: block-height, + last-claim: block-height, + lock-period: lock-period, + cooldown-start: none, + accumulated-rewards: u0 + } + ) + + ;; Update user position with new tier info + (map-set UserPositions + tx-sender + (merge current-position + { + stx-staked: new-total-stake, + tier-level: (get tier-level tier-info), + rewards-multiplier: (* (get reward-multiplier tier-info) lock-multiplier) + } + ) + ) + + ;; Update STX pool + (var-set stx-pool (+ (var-get stx-pool) amount)) + (ok true) + ) + ) +) \ No newline at end of file diff --git a/tests/bitstack.test.ts b/tests/bitstack.test.ts new file mode 100644 index 0000000..4bb9cf3 --- /dev/null +++ b/tests/bitstack.test.ts @@ -0,0 +1,21 @@ + +import { describe, expect, it } from "vitest"; + +const accounts = simnet.getAccounts(); +const address1 = accounts.get("wallet_1")!; + +/* + The test below is an example. To learn more, read the testing documentation here: + https://docs.hiro.so/stacks/clarinet-js-sdk +*/ + +describe("example tests", () => { + it("ensures simnet is well initalised", () => { + expect(simnet.blockHeight).toBeDefined(); + }); + + // it("shows an example", () => { + // const { result } = simnet.callReadOnlyFn("counter", "get-counter", [], address1); + // expect(result).toBeUint(0); + // }); +}); From 5e0583882931914a129b4e890e9936e08c44cecd Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:18:43 +0100 Subject: [PATCH 3/7] feat: Add unstaking and governance proposal functions - Implement `initiate-unstake` function to start the unstaking process with a cooldown period - Add `complete-unstake` function to finalize the unstaking process after the cooldown - Implement `create-proposal` function to allow users to create governance proposals --- contracts/bitstack.clar | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/contracts/bitstack.clar b/contracts/bitstack.clar index 6995981..a9b2923 100644 --- a/contracts/bitstack.clar +++ b/contracts/bitstack.clar @@ -185,4 +185,75 @@ (ok true) ) ) +) + +;; Initiates the unstaking process by setting a cooldown period +(define-public (initiate-unstake (amount uint)) + (let + ( + (staking-position (unwrap! (map-get? StakingPositions tx-sender) ERR-NO-STAKE)) + (current-amount (get amount staking-position)) + ) + (asserts! (>= current-amount amount) ERR-INSUFFICIENT-STX) + (asserts! (is-none (get cooldown-start staking-position)) ERR-COOLDOWN-ACTIVE) + + ;; Update staking position with cooldown + (map-set StakingPositions + tx-sender + (merge staking-position + { + cooldown-start: (some block-height) + } + ) + ) + (ok true) + ) +) + +;; Completes the unstaking process after the cooldown period +(define-public (complete-unstake) + (let + ( + (staking-position (unwrap! (map-get? StakingPositions tx-sender) ERR-NO-STAKE)) + (cooldown-start (unwrap! (get cooldown-start staking-position) ERR-NOT-AUTHORIZED)) + ) + (asserts! (>= (- block-height cooldown-start) (var-get cooldown-period)) ERR-COOLDOWN-ACTIVE) + + ;; Transfer STX back to user + (try! (as-contract (stx-transfer? (get amount staking-position) tx-sender tx-sender))) + + ;; Clear staking position + (map-delete StakingPositions tx-sender) + + (ok true) + ) +) + +;; Allows users to create a governance proposal +(define-public (create-proposal (description (string-utf8 256)) (voting-period uint)) + (let + ( + (user-position (unwrap! (map-get? UserPositions tx-sender) ERR-NOT-AUTHORIZED)) + (proposal-id (+ (var-get proposal-count) u1)) + ) + (asserts! (>= (get voting-power user-position) u1000000) ERR-NOT-AUTHORIZED) + (asserts! (is-valid-description description) ERR-INVALID-PROTOCOL) + (asserts! (is-valid-voting-period voting-period) ERR-INVALID-PROTOCOL) + + (map-set Proposals { proposal-id: proposal-id } + { + creator: tx-sender, + description: description, + start-block: block-height, + end-block: (+ block-height voting-period), + executed: false, + votes-for: u0, + votes-against: u0, + minimum-votes: u1000000 + } + ) + + (var-set proposal-count proposal-id) + (ok proposal-id) + ) ) \ No newline at end of file From bb95b6329f8c1f14f8e9f50625fb3ab469edace2 Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:19:07 +0100 Subject: [PATCH 4/7] feat: Add voting, contract pause/resume, and read-only functions - Implement `vote-on-proposal` function to allow users to vote on governance proposals - Add `pause-contract` and `resume-contract` functions to manage contract state - Implement read-only functions `get-contract-owner`, `get-stx-pool`, and `get-proposal-count` - Add private function `get-tier-info` to retrieve tier information based on stake amount --- contracts/bitstack.clar | 74 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/contracts/bitstack.clar b/contracts/bitstack.clar index a9b2923..db8f8d8 100644 --- a/contracts/bitstack.clar +++ b/contracts/bitstack.clar @@ -256,4 +256,76 @@ (var-set proposal-count proposal-id) (ok proposal-id) ) -) \ No newline at end of file +) + +;; Allows users to vote on a governance proposal +(define-public (vote-on-proposal (proposal-id uint) (vote-for bool)) + (let + ( + (proposal (unwrap! (map-get? Proposals { proposal-id: proposal-id }) ERR-INVALID-PROTOCOL)) + (user-position (unwrap! (map-get? UserPositions tx-sender) ERR-NOT-AUTHORIZED)) + (voting-power (get voting-power user-position)) + (max-proposal-id (var-get proposal-count)) + ) + (asserts! (< block-height (get end-block proposal)) ERR-NOT-AUTHORIZED) + (asserts! (and (> proposal-id u0) (<= proposal-id max-proposal-id)) ERR-INVALID-PROTOCOL) + + (map-set Proposals { proposal-id: proposal-id } + (merge proposal + { + votes-for: (if vote-for (+ (get votes-for proposal) voting-power) (get votes-for proposal)), + votes-against: (if vote-for (get votes-against proposal) (+ (get votes-against proposal) voting-power)) + } + ) + ) + (ok true) + ) +) + +;; Pauses the contract, disabling certain functions +(define-public (pause-contract) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED) + (var-set contract-paused true) + (ok true) + ) +) + +;; Resumes the contract, re-enabling certain functions +(define-public (resume-contract) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED) + (var-set contract-paused false) + (ok true) + ) +) + +;; read only functions + +;; Returns the contract owner +(define-read-only (get-contract-owner) + (ok CONTRACT-OWNER) +) + +;; Returns the current STX pool balance +(define-read-only (get-stx-pool) + (ok (var-get stx-pool)) +) + +;; Returns the current proposal count +(define-read-only (get-proposal-count) + (ok (var-get proposal-count)) +) + +;; private functions + +;; Retrieves tier information based on the stake amount +(define-private (get-tier-info (stake-amount uint)) + (if (>= stake-amount u10000000) + {tier-level: u3, reward-multiplier: u200} + (if (>= stake-amount u5000000) + {tier-level: u2, reward-multiplier: u150} + {tier-level: u1, reward-multiplier: u100} + ) + ) +) From 222aa51eb3846cb73aa590b6d6899a319a9f239b Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:21:21 +0100 Subject: [PATCH 5/7] feat: Add private utility functions for lock multiplier, rewards calculation, and validations - Implement `calculate-lock-multiplier` to determine reward multipliers based on lock periods - Add `calculate-rewards` to compute user rewards based on stake and block duration - Implement `is-valid-description` to validate proposal description length - Add `is-valid-lock-period` to validate staking lock periods - Implement `is-valid-voting-period` to validate governance voting periods --- contracts/bitstack.clar | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/contracts/bitstack.clar b/contracts/bitstack.clar index db8f8d8..205b827 100644 --- a/contracts/bitstack.clar +++ b/contracts/bitstack.clar @@ -329,3 +329,53 @@ ) ) ) + + +(define-private (calculate-lock-multiplier (lock-period uint)) + (if (>= lock-period u8640) ;; 2 months + u150 ;; 1.5x multiplier + (if (>= lock-period u4320) ;; 1 month + u125 ;; 1.25x multiplier + u100 ;; 1x multiplier (no lock) + ) + ) +) + +;; Calculates the rewards for a user based on their stake and the number of blocks +(define-private (calculate-rewards (user principal) (blocks uint)) + (let + ( + (staking-position (unwrap! (map-get? StakingPositions user) u0)) + (user-position (unwrap! (map-get? UserPositions user) u0)) + (stake-amount (get amount staking-position)) + (base-rate (var-get base-reward-rate)) + (multiplier (get rewards-multiplier user-position)) + ) + (/ (* (* (* stake-amount base-rate) multiplier) blocks) u14400000) + ) +) + +;; Validates the proposal description length +(define-private (is-valid-description (desc (string-utf8 256))) + (and + (>= (len desc) u10) ;; Minimum description length + (<= (len desc) u256) ;; Maximum description length + ) +) + +;; Validates the lock period +(define-private (is-valid-lock-period (lock-period uint)) + (or + (is-eq lock-period u0) ;; No lock + (is-eq lock-period u4320) ;; 1 month + (is-eq lock-period u8640) ;; 2 months + ) +) + +;; Validates the voting period +(define-private (is-valid-voting-period (period uint)) + (and + (>= period u100) ;; Minimum voting blocks + (<= period u2880) ;; Maximum voting blocks (approximately 1 day) + ) +) \ No newline at end of file From 53b8074b1a4f75623110b3a5ac01ce8dc0513bee Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:24:14 +0100 Subject: [PATCH 6/7] refactor: Update `block-height` to `stacks-block-height` - Replace all instances of `block-height` with `stacks-block-height` for consistency --- contracts/bitstack.clar | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/bitstack.clar b/contracts/bitstack.clar index 205b827..d5cca12 100644 --- a/contracts/bitstack.clar +++ b/contracts/bitstack.clar @@ -160,8 +160,8 @@ tx-sender { amount: amount, - start-block: block-height, - last-claim: block-height, + start-block: stacks-block-height, + last-claim: stacks-block-height, lock-period: lock-period, cooldown-start: none, accumulated-rewards: u0 @@ -202,7 +202,7 @@ tx-sender (merge staking-position { - cooldown-start: (some block-height) + cooldown-start: (some stacks-block-height) } ) ) @@ -217,7 +217,7 @@ (staking-position (unwrap! (map-get? StakingPositions tx-sender) ERR-NO-STAKE)) (cooldown-start (unwrap! (get cooldown-start staking-position) ERR-NOT-AUTHORIZED)) ) - (asserts! (>= (- block-height cooldown-start) (var-get cooldown-period)) ERR-COOLDOWN-ACTIVE) + (asserts! (>= (- stacks-block-height cooldown-start) (var-get cooldown-period)) ERR-COOLDOWN-ACTIVE) ;; Transfer STX back to user (try! (as-contract (stx-transfer? (get amount staking-position) tx-sender tx-sender))) @@ -244,8 +244,8 @@ { creator: tx-sender, description: description, - start-block: block-height, - end-block: (+ block-height voting-period), + start-block: stacks-block-height, + end-block: (+ stacks-block-height voting-period), executed: false, votes-for: u0, votes-against: u0, @@ -267,7 +267,7 @@ (voting-power (get voting-power user-position)) (max-proposal-id (var-get proposal-count)) ) - (asserts! (< block-height (get end-block proposal)) ERR-NOT-AUTHORIZED) + (asserts! (< stacks-block-height (get end-block proposal)) ERR-NOT-AUTHORIZED) (asserts! (and (> proposal-id u0) (<= proposal-id max-proposal-id)) ERR-INVALID-PROTOCOL) (map-set Proposals { proposal-id: proposal-id } From fc854c601f2fb1f0996d655119bb0a6f336bb5f3 Mon Sep 17 00:00:00 2001 From: ud-cmd Date: Thu, 27 Feb 2025 22:31:39 +0100 Subject: [PATCH 7/7] docs: Add README.md for StackSense Protocol overview and guidelines - Include architecture overview with protocol components - Detail core financial mechanics including staking formula and tier multipliers - Describe governance framework with proposal lifecycle and voting power calculation - Outline risk management system with health factor triggers and cooldown periods - Provide developer guidelines for contribution standards and audit trail --- README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc231d5 --- /dev/null +++ b/README.md @@ -0,0 +1,124 @@ +# StackSense Protocol - Layer 2 DeFi Analytics Engine + +Enterprise-grade DeFi analytics protocol combining Bitcoin-aligned staking mechanics with on-chain governance, built on Stacks L2. + +## Table of Contents + +- [StackSense Protocol - Layer 2 DeFi Analytics Engine](#stacksense-protocol---layer-2-defi-analytics-engine) + - [Table of Contents](#table-of-contents) + - [Architecture Overview](#architecture-overview) + - [Protocol Components](#protocol-components) + - [Core Financial Mechanics](#core-financial-mechanics) + - [Staking Formula](#staking-formula) + - [Tier Multipliers](#tier-multipliers) + - [Emergency Protocols](#emergency-protocols) + - [Governance Framework](#governance-framework) + - [Proposal Lifecycle](#proposal-lifecycle) + - [Voting Power Calculation](#voting-power-calculation) + - [Risk Management System](#risk-management-system) + - [Health Factor Triggers](#health-factor-triggers) + - [Cooldown Periods](#cooldown-periods) + - [Developer Guidelines](#developer-guidelines) + - [Contribution Standards](#contribution-standards) + - [Audit Trail](#audit-trail) + +## Architecture Overview + +### Protocol Components + +1. **Collateral Engine** + + - STX staking with time-lock multipliers + - Dynamic reward calculation: `(base_rate × stake × blocks × multiplier) / 14,400,000` + - Tiered thresholds: Bronze (1M STX), Silver (5M STX), Gold (10M STX) + +2. **Governance Module** + + - Proposal lifecycle management + - Voting power = `min(staked_STX × tier_multiplier, protocol_cap)` + - Quadratic voting implementation for critical parameters + +3. **Surveillance System** + + - Health factor monitoring: `total_collateral / (total_debt × liquidation_threshold)` + - Block-height based cooldowns (1440 blocks ≈ 24h) + +4. **Compliance Layer** + - UTXO-model aware accounting + - Bitcoin block confirmation mirroring + - MEV-resistant reward distribution + +## Core Financial Mechanics + +### Staking Formula + +```clarity +(/ (* (* (* stake_amount base_rate) multiplier) blocks_staked) 14400000) +``` + +### Tier Multipliers + +| Tier | Minimum STX | Reward Boost | Governance Power | +| ------ | ----------- | ------------ | ------------------ | +| Bronze | 1,000,000 | 1.0x | 1 vote/1000 STX | +| Silver | 5,000,000 | 1.5x | 1.5 votes/1000 STX | +| Gold | 10,000,000 | 2.0x | 2 votes/1000 STX | + +### Emergency Protocols + +- **Circuit Breaker**: Immediate contract pause preserving UTXO states +- **Debt Liquidation**: Automated at health factor < 1.0 +- **Multi-sig Recovery**: 3/5 signer requirement for emergency withdrawals + +## Governance Framework + +### Proposal Lifecycle + +1. Creation: 1M STX voting power minimum +2. Voting: 100-2880 blocks duration +3. Execution: >50% approval with 1M vote quorum +4. Enforcement: Bitcoin-anchored transaction batches + +### Voting Power Calculation + +```clarity +voting_power = (staked_stx * tier_multiplier) / 1000 +``` + +## Risk Management System + +### Health Factor Triggers + +| Factor Range | Protocol Response | +| ------------- | -------------------------- | +| HF ≥ 1.5 | Normal operations | +| 1.0 ≤ HF <1.5 | Reduced borrowing capacity | +| HF <1.0 | Liquidation enabled | + +### Cooldown Periods + +- Unstaking: 1440 blocks (24h) +- Governance veto: 10080 blocks (7d) +- Parameter changes: 2016 blocks (BTC epoch aligned) + +## Developer Guidelines + +### Contribution Standards + +- All financial operations must maintain UTXO isolation +- Governance changes require accompanying SIP documentation +- Test coverage minimum 85% for financial modules + +### Audit Trail + +```clarity +(define-data-var protocol-version uint u201) +(define-map version-history + uint + { + timestamp: uint, + hash: (buff 32), + author: principal + } +) +```