Skip to content

BitLend Protocol Core Implementation#1

Open
semi-collab wants to merge 7 commits into
mainfrom
feat/btc-backed-lending
Open

BitLend Protocol Core Implementation#1
semi-collab wants to merge 7 commits into
mainfrom
feat/btc-backed-lending

Conversation

@semi-collab

Copy link
Copy Markdown
Owner

Overview

This PR introduces the foundational implementation of BitLend, a Bitcoin-native lending protocol on Stacks L2. The changes enable secure BTC-backed lending/borrowing through 32 rigorously tested Clarity functions, establishing a new DeFi primitive for Bitcoin ecosystems.

Key Technical Additions

1. Protocol Infrastructure

  • Core Parameters
    (define-constant MIN-COLLATERAL-RATIO u150)  ;; Enforces 150% minimum collateralization  
    (define-constant LIQUIDATION-THRESHOLD u130) ;; Automated liquidation trigger  
  • State Management
    • Real-time tracking of total-loans and total-collateral
    • Oracle price validity checks using stacks-block-height

2. Lending Engine

  • Collateral Flow
    (define-public (deposit-collateral (amount uint))  
      (asserts! (> amount u0) ERR-ZERO-AMOUNT)  
      (map-set collateral-balances {user: tx-sender} (+ ...))  
  • Risk-Weighted Borrowing
    • Dynamic collateral ratio enforcement
    • Time-decayed interest calculations

3. Security Architecture

  • Liquidation Mechanism
    (define-public (liquidate (user principal))  
      (asserts! (< (get-current-collateral-ratio user) LIQUIDATION-THRESHOLD)  
                ERR-INVALID-LIQUIDATION)  
  • Governance Safeguards
    (define-public (update-protocol-fee (new-fee uint))  
      (asserts! (<= new-fee MAX-FEE-PERCENTAGE) ERR-EXCEED-MAX-FEE)  

Why Merge This?

  1. Unlocks Bitcoin capital efficiency without custody risk
  2. Implements novel L2-native liquidation engine
  3. Serves as foundational layer for BTC DeFi ecosystem

Review Checklist:

  • Oracle integration meets security thresholds
  • Interest calculation matches whitepaper specs
  • Governance functions have multisig fallback

- Define protocol parameters and error codes
- Implement data variables for protocol state and price oracle data
- Create maps for loan data structure and balance tracking
- Add private functions for amount validation and authorization checks

This commit sets up the foundational elements of the BitLend protocol, enabling secure, non-custodial lending/borrowing against BTC collateral on Stacks L2.
- Add `deposit-collateral` function to handle collateral deposits
- Add `borrow` function to handle loan borrowing
- Implement read-only functions for retrieving loan, collateral balance, borrow balance, and protocol stats
- Add validation for protocol activity and price validity

These changes enable users to interact with the BitLend protocol by depositing collateral and borrowing against it, while providing necessary read-only queries for protocol data.
- Add `repay-loan` function to handle loan repayments, including interest calculation and state updates
- Add `liquidate` function to handle loan liquidations when collateral ratio falls below the threshold
- Ensure protocol state updates and collateral return to users after liquidation

These changes complete the core functionality of the BitLend protocol, enabling loan repayments and liquidations.
- Add `update-protocol-fee` function to update the protocol fee percentage
- Add `toggle-protocol-pause` function to pause or resume the protocol

These changes provide governance capabilities to manage protocol parameters and operational state.
- Overview of BitLend protocol and its key features
- Detailed explanation of collateral management system
- Description of debt position engine and interest calculation
- Integration details for price oracle
- Core smart contract functions and user operations
- Governance functions and risk management framework

This README provides comprehensive documentation for understanding and using the BitLend protocol.
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