StackLend is a decentralized lending protocol built on the Stacks blockchain that enables secure, transparent, and efficient lending operations using STX tokens as collateral.
StackLend allows users to:
- Deposit STX tokens as collateral
- Borrow against their collateral
- Repay loans
- Withdraw collateral
- Participate in liquidations
The protocol implements dynamic interest rates, collateralization ratios, and liquidation mechanisms to maintain system stability and protect users.
- Minimum collateralization ratio: 150%
- Maximum collateralization ratio: 500%
- Liquidation threshold: 130%
- Protocol fee: 1% (configurable up to 10%)
-
Deposit (
deposit)- Allows users to deposit STX tokens as collateral
- Updates total deposits and user position
- Returns the deposited amount
-
Borrow (
borrow)- Enables borrowing against deposited collateral
- Requires maintaining minimum collateralization ratio
- Updates total borrows and user position
- Returns borrowed amount
-
Repay (
repay)- Allows users to repay borrowed amounts
- Updates total borrows and user position
- Returns repaid amount
-
Withdraw (
withdraw)- Enables withdrawal of collateral
- Ensures remaining position maintains minimum collateralization
- Updates total deposits and user position
- Returns withdrawn amount
Liquidate (liquidate)
- Allows liquidation of under-collateralized positions
- Triggers when position falls below liquidation threshold (130%)
- Transfers collateral to liquidator
- Clears user position
-
Get User Position (
get-user-position){ total-collateral: uint, total-borrowed: uint, loan-count: uint } -
Get Protocol Stats (
get-protocol-stats){ total-deposits: uint, total-borrows: uint, minimum-collateral-ratio: uint, liquidation-threshold: uint, protocol-fee: uint }
Contract owner can adjust key parameters within defined bounds:
-
Set Minimum Collateral Ratio (
set-minimum-collateral-ratio)- Range: 110% to 500%
- Must be higher than liquidation threshold
-
Set Liquidation Threshold (
set-liquidation-threshold)- Must be between minimum collateral ratio (110%) and current minimum collateral ratio
- Default: 130%
-
Set Protocol Fee (
set-protocol-fee)- Maximum: 10%
- Default: 1%
| Code | Description |
|---|---|
| u100 | Not authorized |
| u101 | Insufficient collateral |
| u102 | Invalid amount |
| u103 | Loan not found |
| u104 | Loan active |
| u105 | Insufficient balance |
| u106 | Liquidation failed |
| u107 | Invalid parameter |
-
Access Control
- Administrative functions restricted to contract owner
- Self-liquidation prevention
- Secure parameter bounds
-
Position Management
- Dynamic collateral ratio tracking
- Safe position updates
- Protected withdrawal conditions
-
System Stability
- Minimum collateralization requirements
- Liquidation mechanisms
- Fee structure for sustainability
Interest is calculated using the following formula:
interest-per-block = (principal * rate) / 10000
total-interest = interest-per-block * blocks;; Deposit STX tokens
(contract-call? .stacklend deposit);; Borrow 100 STX
(contract-call? .stacklend borrow u100);; Repay 50 STX
(contract-call? .stacklend repay u50);; Withdraw 75 STX
(contract-call? .stacklend withdraw u75)-
For Users
- Maintain healthy collateralization ratios (>150%)
- Monitor market conditions
- Repay loans promptly to avoid liquidation
-
For Liquidators
- Monitor positions near liquidation threshold
- Ensure sufficient STX balance for liquidation
- Understand liquidation penalties and rewards
-
For Administrators
- Regular monitoring of system parameters
- Gradual parameter adjustments
- Emergency response planning
-
Block Height
- Used for interest calculations
- Timestamp approximation
- Loan duration tracking
-
Position Updates
- Atomic operations
- Safe state transitions
- Balance verification
-
Error Handling
- Comprehensive error codes
- Clear error messages
- Safe state rollback
We welcome contributions to StackLend! Please ensure:
- Comprehensive testing of changes
- Clear documentation updates
- Adherence to Clarity best practices
- Security-first approach