Skip to content

ukamakafaith/Chronos-Fortress-Smart-Contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Chronos Fortress Smart Contract

A secure, time-locked Bitcoin vault system built on Stacks blockchain with multi-signature support, daily withdrawal limits, and emergency controls.

Overview

Chronos Fortress provides a sophisticated asset protection mechanism where users can create fortresses (vaults) with temporal barriers (time-locks), extraction limits (withdrawal caps), and sentinel authorization (multi-sig guardians). Perfect for securing long-term holdings, implementing corporate treasury controls, or establishing trustless inheritance mechanisms.

Core Features

🏰 Fortress Management

  • Create Fortresses: Establish secure vaults with customizable parameters
  • Temporal Barriers: Set time-locks preventing early withdrawals
  • Cycle Thresholds: Implement daily/periodic withdrawal limits
  • Operational Controls: Activate/deactivate fortresses as needed

🛡️ Security Features

  • Multi-Signature Support: Require consensus from multiple sentinels for withdrawals
  • Sentinel System: Authorize trusted guardians to approve extraction mandates
  • Emergency Lockdown: Global protocol to freeze all fortress operations
  • Input Validation: Comprehensive checks against malicious or malformed data

💰 Asset Operations

  • Provision: Deposit STX tokens into your fortress
  • Extract: Withdraw funds after temporal barrier expires (within cycle limits)
  • Mandate System: Propose, endorse, and execute multi-sig withdrawals

Architecture

Data Structures

Fortresses Map

{
  architect: principal,          // Fortress owner
  reserves: uint,                // Current STX balance
  temporal-barrier: uint,        // Block height when withdrawals unlock
  cycle-threshold: uint,         // Maximum extraction per cycle (daily)
  extracted-this-cycle: uint,    // Amount withdrawn in current cycle
  last-extraction: uint,         // Last extraction cycle timestamp
  operational: bool,             // Active/inactive status
  sentinel-consensus: uint       // Required sentinel approvals
}

Extraction Mandates

{
  quantity: uint,                // Withdrawal amount
  beneficiary: principal,        // Recipient address
  endorsements: uint,            // Current approval count
  executed: bool,                // Execution status
  initiated-at: uint            // Creation block height
}

Usage Guide

1. Create a Fortress

(contract-call? .chronos-fortress construct-fortress 
  u14400        ;; temporal-lock (approx 100 days)
  u1000000      ;; cycle-threshold (1 STX per day)
  u2)           ;; sentinel-consensus (2 approvals required)

2. Deposit Funds

(contract-call? .chronos-fortress provision 
  u1            ;; fortress-id
  u10000000)    ;; quantity (10 STX)

3. Add Sentinels

(contract-call? .chronos-fortress commission-sentinel
  u1                                    ;; fortress-id
  'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7) ;; sentinel principal

4. Simple Withdrawal (After Timelock)

(contract-call? .chronos-fortress extract
  u1            ;; fortress-id
  u500000)      ;; quantity (0.5 STX)

5. Multi-Sig Withdrawal Process

Step 1: Initiate Mandate

(contract-call? .chronos-fortress initiate-extraction-mandate
  u1                                    ;; fortress-id
  u1                                    ;; mandate-id
  u2000000                              ;; quantity
  'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7) ;; beneficiary

Step 2: Sentinels Endorse

(contract-call? .chronos-fortress endorse-extraction-mandate
  u1            ;; fortress-id
  u1)           ;; mandate-id

Step 3: Execute (After Required Endorsements)

(contract-call? .chronos-fortress execute-extraction-mandate
  u1            ;; fortress-id
  u1)           ;; mandate-id

Configuration Functions

Adjust Temporal Barrier

(contract-call? .chronos-fortress adjust-temporal-barrier
  u1            ;; fortress-id
  u28800)       ;; new-temporal-lock (approx 200 days)

Adjust Cycle Threshold

(contract-call? .chronos-fortress adjust-cycle-threshold
  u1            ;; fortress-id
  u2000000)     ;; new-threshold (2 STX per day)

Toggle Operational Status

(contract-call? .chronos-fortress toggle-fortress-operational-status
  u1)           ;; fortress-id

Read-Only Functions

Query Fortress Details

(contract-call? .chronos-fortress get-fortress-details u1)

Check Reserves

(contract-call? .chronos-fortress get-fortress-reserves u1)

Check Accessibility

(contract-call? .chronos-fortress is-fortress-accessible u1)

Get Remaining Daily Limit

(contract-call? .chronos-fortress get-remaining-cycle-threshold u1)

List Architect's Fortresses

(contract-call? .chronos-fortress get-architect-fortresses 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)

Error Codes

Code Constant Description
u100 err-architect-only Only contract architect can perform this action
u101 err-access-denied Caller not authorized for this fortress
u102 err-fortress-sealed Fortress locked or inactive
u103 err-insufficient-reserves Not enough balance in fortress
u104 err-invalid-quantity Invalid amount specified
u105 err-fortress-exists Maximum fortresses reached
u106 err-fortress-not-found Fortress ID doesn't exist
u107 err-extraction-limit Daily withdrawal limit exceeded
u108 err-cooldown-active Cooldown period still active
u109 err-invalid-temporal-lock Invalid timelock value
u110 err-sentinel-exists Sentinel already commissioned
u111 err-not-sentinel Caller is not an authorized sentinel
u112 err-invalid-input Invalid input parameter

Security Considerations

⚠️ Important Notes

  1. Temporal Barriers Are Immutable Once Passed: While you can extend a timelock, you cannot shorten it
  2. Cycle Limits Reset Daily: Approximately every 144 blocks (~24 hours)
  3. Sentinel Trust: Choose sentinels carefully - they have significant authority
  4. Emergency Lockdown: Contract architect can freeze all operations globally
  5. No Recovery Mechanism: Lost private keys mean lost access to fortresses
  6. Input Validation: All user inputs are validated before processing

Best Practices

  • Use Multi-Sig for Large Amounts: Don't rely on single-key control for significant holdings
  • Test with Small Amounts First: Verify timelock and limit configurations work as expected
  • Document Sentinel List: Keep secure records of authorized sentinels
  • Regular Security Audits: Review fortress configurations and sentinel permissions periodically
  • Backup Configuration: Store fortress IDs and configuration parameters securely

Use Cases

1. Personal Savings Vault

Lock away savings with a time barrier to prevent impulsive spending, with daily withdrawal limits for controlled access.

2. Corporate Treasury

Implement multi-signature requirements for company funds with department-level spending limits and executive oversight.

3. Inheritance Planning

Create time-locked vaults with trusted family members as sentinels, ensuring smooth asset transfer.

4. Escrow Services

Hold funds in neutral fortresses requiring multi-party approval for release.

5. DCA Protection

Prevent emotional trading by time-locking investment capital with gradual extraction limits.

Technical Specifications

  • Blockchain: Stacks (Bitcoin L2)
  • Language: Clarity
  • Token: STX (Stacks native token)
  • Block Time: ~10 minutes (Bitcoin-anchored)
  • Cycle Duration: ~144 blocks (~24 hours)
  • Max Fortresses per Architect: 50

Development & Testing

Prerequisites

  • Stacks CLI (clarinet)
  • Stacks wallet
  • Testnet STX tokens

Deployment

clarinet deploy chronos-fortress

Local Testing

clarinet test

About

Chronos Fortress is a Clarity contract that enables users to create secure, programmable vaults for storing STX tokens with advanced access controls. The contract implements a fortress-based architecture where each vault operates as an independent secure unit governed by temporal restrictions, extraction limits, and multi-signature authorization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors