Skip to content

Conversation

@nathaniel-cmd
Copy link
Owner

Overview

This PR introduces critical upgrades to the BitVault protocol, enhancing its functionality, security, and transparency as a Bitcoin-collateralized stablecoin system on Stacks L2. The changes implement robust position management, real-time monitoring, and comprehensive documentation aligned with Bitcoin DeFi best practices.

Key Changes

1. Liquidation Tracking & Transparency

  • liquidation-history Map
    Records all liquidation events with:
    {
      timestamp: uint,
      collateral-liquidated: uint,
      debt-repaid: uint
    }
    • Enables historical auditing of protocol health
    • Provides immutable records for regulatory compliance

2. Position Health Monitoring

  • get-collateral-ratio Function
    (define-read-only (get-collateral-ratio (user principal))
    • Calculates real-time collateralization percentage
    • Integrates live BTC price data
    • Returns 0 for debt-free positions

3. Collateral Management

  • Enhanced Validation
    • check-min-collateral: Enforces 0.01 BTC minimum deposit
    • check-position-health: Blocks undercollateralized withdrawals
    • MAX-DEPOSIT enforcement (10,000 BTC ceiling)

4. Stablecoin Operations

Function Purpose Validation
mint-stablecoin Debt issuance Price freshness + collateral check
repay-stablecoin Debt reduction Amount ≤ current debt

5. Protocol Administration

  • Oracle Management
    • set-price: Oracle-restricted price updates
    • set-price-oracle: Owner-controlled oracle assignment
  • Block Height Consistency
    Standardized stacks-block-height usage for temporal logic

6. Comprehensive Documentation

  • Added technical specifications for all system parameters
  • Detailed workflow diagrams for liquidation process
  • Code examples for core interactions

Review Notes

  • All functions include error code standardization
  • Backwards compatibility maintained

The `liquidation-history` map was introduced to record details of liquidation events, including the timestamp, collateral liquidated, and debt repaid. This feature enhances transparency and provides historical data for auditing and monitoring purposes.

Key changes:
- Added a new `liquidation-history` map with fields: `timestamp`, `collateral-liquidated`, and `debt-repaid`.
- Ensures that all liquidation events are logged for future reference and analysis.

Impact:
- Improves protocol transparency by maintaining a historical record of liquidation events.
- Facilitates better monitoring and auditing of the system's liquidation processes.
- Enhances user trust by providing clear and accessible data on liquidation activities.
This update introduces the `get-collateral-ratio` read-only function, which calculates and returns the collateralization ratio for a user's position. The ratio is expressed as a percentage, providing users with a clear view of their position's health.

Key changes:
- Added `get-collateral-ratio` function to compute the ratio of collateral value to debt.
- Integrated price data (`btc-price`) and user position details (`collateral` and `debt`) for accurate calculations.
- Handles edge cases where the debt is zero, returning a ratio of `0`.

Impact:
- Improves user experience by enabling real-time monitoring of position health.
- Enhances transparency and usability of the protocol.
- Supports better decision-making for users managing their collateralized positions.
This update enhances the `deposit-collateral` function by integrating robust validation mechanisms to ensure user deposits meet protocol requirements. It includes checks for minimum deposit amounts and collateralization ratio compliance.

Key changes:
- Added `check-min-collateral` to validate deposit amounts against minimum thresholds.
- Integrated `check-position-health` to ensure positions maintain the required collateralization ratio.
- Updated `deposit-collateral` to enforce these validations before updating user positions.

Impact:
- Improves protocol security by preventing under-collateralized positions.
- Enhances user experience by providing clear error handling for invalid deposits.
- Ensures compliance with system parameters, maintaining protocol integrity.
This update introduces two key public functions, `mint-stablecoin` and `repay-stablecoin`, enabling users to mint new stablecoins against their collateral and repay their debt, respectively. These functions ensure proper validation and maintain the protocol's collateralization requirements.

Key changes:
- Added `mint-stablecoin` to allow users to mint stablecoins by increasing their debt, ensuring sufficient collateralization and compliance with system limits.
- Added `repay-stablecoin` to enable users to repay their stablecoin debt, reducing their outstanding liabilities and updating the total supply.
- Integrated validation checks for amount bounds, price freshness, and collateralization ratio.

Impact:
- Enhances user functionality by enabling stablecoin minting and debt repayment.
- Maintains protocol integrity by enforcing collateralization and system limits.
- Improves user experience with clear error handling and position updates.
…tions

This update introduces key functionalities for managing collateral, enforcing liquidation, and administering protocol parameters. These features enhance user interactions and ensure the protocol's stability and compliance.

Key changes:
- Added `withdraw-collateral` function to allow users to withdraw excess collateral while maintaining proper collateralization.
- Implemented `liquidate-position` function to enable liquidation of undercollateralized positions, ensuring protocol health.
- Added administrative functions:
  - `set-price` for updating BTC price, restricted to the authorized price oracle.
  - `set-price-oracle` for updating the price oracle address, restricted to the contract owner.

Impact:
- Improves user flexibility by enabling collateral withdrawals.
- Enhances protocol security by enforcing liquidation for undercollateralized positions.
- Provides robust administrative controls for maintaining protocol integrity.
… consistency

This update ensures that the `last-price-update` variable consistently uses `stacks-block-height` across the contract. This change improves clarity and aligns with the protocol's standard for tracking block heights.

Key changes:
- Updated the `last-price-update` variable to explicitly use `stacks-block-height` in relevant functions, such as `set-price`.

Impact:
- Enhances code consistency and readability.
- Reduces potential confusion regarding block height tracking.
…es, functionality, and usage examples

This update introduces a detailed README file for the BitVault protocol, providing an in-depth overview of its features, technical specifications, and usage examples. The README serves as a comprehensive guide for developers and users interacting with the protocol.

Key changes:
- Added sections for system parameters, error codes, and core functionality.
- Included detailed workflows for collateral management, stablecoin operations, and liquidation processes.
- Provided usage examples for key functions such as `deposit-collateral`, `mint-stablecoin`, `repay-stablecoin`, and `liquidate-position`.
- Documented oracle integration and security architecture, highlighting risk mitigation strategies.

Impact:
- Enhances developer and user understanding of the protocol.
- Improves accessibility by offering clear and structured documentation.
- Facilitates onboarding and interaction with the BitVault system.
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.

2 participants