Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions Clarinet.toml
Original file line number Diff line number Diff line change
@@ -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
124 changes: 124 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
}
)
```
Loading