A decentralized lending protocol built on the Stacks blockchain that enables users to deposit Bitcoin as collateral and borrow against it. This smart contract implements core lending functionality with liquidation mechanisms and protocol governance features.
The BTC Lending Protocol allows users to:
- Deposit STX as collateral
- Borrow against their collateral
- Repay loans with interest
- Participate in liquidations of under-collateralized positions
- Track lending metrics and protocol health
- Minimum collateral ratio: 150%
- Liquidation threshold: 130%
- Liquidation penalty: 10%
- Real-time price feed integration with 1-hour validity period
- Default protocol fee: 1%
- Maximum fee cap: 10%
- Fixed interest rate: 5% APR
- Interest calculated based on blocks elapsed
- Price oracle validity checks
- Protocol pause mechanism
- Owner-only administrative functions
- Balance and authorization validations
MIN-COLLATERAL-RATIO: 150%
LIQUIDATION-THRESHOLD: 130%
LIQUIDATION-PENALTY: 10%
PRICE-VALIDITY-PERIOD: 3600 blocks (approximately 1 hour)
MAX-FEE-PERCENTAGE: 10%
ERR-NOT-AUTHORIZED (100)
: Unauthorized access attemptERR-INSUFFICIENT-BALANCE (101)
: Insufficient balance for operationERR-INVALID-AMOUNT (102)
: Invalid amount specifiedERR-BELOW-MIN-COLLATERAL (103)
: Collateral ratio below minimumERR-LOAN-NOT-FOUND (104)
: Loan doesn't existERR-LOAN-EXISTS (105)
: Loan already existsERR-INVALID-LIQUIDATION (106)
: Invalid liquidation attemptERR-PRICE-EXPIRED (107)
: Price feed data expiredERR-ZERO-AMOUNT (108)
: Zero amount specifiedERR-EXCEED-MAX-FEE (109)
: Fee exceeds maximum allowed
Deposits STX as collateral into the protocol.
(deposit-collateral (amount uint))
Creates a loan against deposited collateral.
(borrow (amount uint))
Repays an existing loan with interest.
(repay-loan (amount uint))
Liquidates an under-collateralized position.
(liquidate (user principal))
Retrieves loan details for a user.
(get-loan (user principal))
Calculates current collateral ratio for a user.
(get-current-collateral-ratio (user principal))
Returns protocol-wide statistics.
(get-protocol-stats)
Updates the BTC price oracle.
(update-btc-price (new-price-in-cents uint))
Updates the protocol fee percentage.
(update-protocol-fee (new-fee uint))
Toggles the protocol's pause state.
(toggle-protocol-pause)
;; Deposit 1000 STX as collateral
(contract-call? .btc-lending deposit-collateral u1000)
;; Borrow 500 STX against collateral
(contract-call? .btc-lending borrow u500)
;; Repay 100 STX of the loan
(contract-call? .btc-lending repay-loan u100)
;; Liquidate an under-collateralized position
(contract-call? .btc-lending liquidate 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)
-
Price Oracle Dependency: The protocol relies on accurate and timely price feeds. Ensure the price oracle is reliable and frequently updated.
-
Liquidation Risks: Users should maintain healthy collateral ratios to avoid liquidation. The protocol enforces a 130% liquidation threshold.
-
Interest Rate Risk: The fixed 5% APR interest rate may need adjustment based on market conditions (requires contract upgrade).
-
Administrative Controls: The contract owner has significant control through administrative functions. Proper governance should be implemented.
The BTC Lending Protocol is open for community review and improvement suggestions. Please follow these steps to contribute:
- Fork the repository
- Create a feature branch
- Submit a pull request with detailed description of changes
This project is licensed under the MIT License - see the LICENSE file for details.