* ,,, ,, ,,, ,,, ,, ,,, ,,, ,,, ,,, ,,, ,,, ,,,
* ██▌ ███▀▀▀███▄ ███▄ ██ ██▄██▀▀██▄ ███▀▀▀███▄ ██▄██▀▀██▄ ▄██╟
* ██▌ ██▌ █████, ██ ██▌ └██▌ ██▌ ██▌ ██
* ╟█l ███▀▄███ ██ └███ ██ l██ ██╟ ███▀▄███ ██▌└██╟██ ╟█i
* ██▌ ██▌ ██ ╙████ ██▌ ,██▀ ██▌ ██▌ ██
* █████▀▄██▀ █████▀▀▄██▀ ██ ╙██ ██▌██▌╙███▀` █████▀▀▄██▀ ╙██ ╙██
* ¬─ ¬─ ¬─¬─ ¬─¬─' ¬─¬─ ¬─' ¬─¬─ '¬─ '─¬ ¬─ ¬─' ¬─'
The Lendefi smart contract represents a sophisticated lending protocol with several noteworthy innovations compared to existing solutions like Compound III, Aave, and MakerDAO. This review assesses the contract's architecture, security features, economic model, and overall viability. For more information visit Nebula Labs.
The contract implements a monolithic design pattern that combines all core lending functionality within a single upgradeable contract. This approach offers several advantages:
- Comprehensive Integration: All lending, borrowing, and liquidation functionality is tightly integrated
- Simplified User Experience: Single entry point for protocol interactions
- Efficient State Management: Cross-functional optimizations possible within contract scope
The architecture follows sound design principles with clear separation of concerns through distinct functional areas and well-defined interfaces.
The contract demonstrates strong security practices:
- Access Control: Robust role-based permissions (DEFAULT_ADMIN_ROLE, PAUSER_ROLE, MANAGER_ROLE, UPGRADER_ROLE)
- Modern Error Handling: Custom errors replace require statements for better gas efficiency and debugging
- Reentrancy Protection: All state-modifying functions implement nonReentrant guards
- Oracle Safeguards: Multiple validation layers including:
- Price positivity checks
- Round completion verification
- Timestamp freshness (8-hour maximum age)
- Volatility monitoring (special handling for >20% price movements)
- Emergency Controls: Pausable functionality for crisis management
- Upgradeable Pattern: UUPS proxy implementation with proper version tracking
One of the contract's standout features is its sophisticated risk management framework:
-
Multi-tier Collateral Classification:
- STABLE: Lowest risk assets (1% liquidation bonus)
- CROSS_A: Low risk assets (2% liquidation bonus)
- CROSS_B: Medium risk assets (3% liquidation bonus)
- ISOLATED: High risk assets (4% liquidation bonus)
-
Asset-Specific Parameters:
- Individual borrow thresholds
- Custom liquidation thresholds
- Supply caps to prevent overconcentration
- Isolation debt caps for higher risk assets
-
Position Management:
- Support for both isolated and cross-collateral positions
- Granular health factor calculations
- Dynamic interest rate model based on utilization and risk tier
- Allows transfer of assets between positions to help mitigate risk
The protocol implements a sustainable economic model with multiple components:
-
Interest Rate Mechanism:
- Base rates vary by collateral tier (higher risk = higher rates)
- Dynamic scaling based on utilization
- Protocol profit margin built into calculations
-
Fee Structure:
- Flash loan fees (configurable, default 9 basis points)
- Protocol fees based on profit target (typically 1%)
-
Liquidation Incentives:
- Tier-based liquidation bonuses (1-4%)
- Governance token staking requirement (20,000 tokens minimum)
-
Liquidity Provider Rewards:
- Time-based reward accrual
- Minimum supply threshold for eligibility
- Ecosystem integration for additional incentives
The contract demonstrates high-quality implementation practices:
- Gas Optimization: Efficient storage design, custom errors, and optimized calculations
- Modular Components: Well-structured internal functions for reusable logic
- Comprehensive Events: Detailed event emissions for off-chain tracking
- Rich View Functions: Extensive read-only functions for position monitoring
- Thorough Documentation: Detailed NatSpec comments explaining functionality
The Lendefi protocol represents a technically sophisticated and feature-rich lending solution that addresses known limitations in existing protocols. Its multi-tier collateral system, advanced risk management, and flexible position options position it as a potentially viable addition to the DeFi ecosystem.
The contract demonstrates the technical maturity expected in a production-grade DeFi protocol while introducing innovative features that address existing market gaps.
- Supports more than 200 collateral assets.
- Allows multiple independent user positions.
- Up to 20 collateral assets per user postion.
- Compounds interest.
- Gas Efficient.
- Issues ERC20 yield token to lenders.
- Completely upgradeable.
- DAO Managed.
- Reward Ecosystem.
- Flash loan functionality.
The protocol offers flash loans with:
- Configurable fees (default: 9 basis points)
- Support for callbacks to borrower contracts
- Validation of return funds plus fees
- Fee accrual to protocol treasury
A gas-optimized feature allowing users to move collateral between their positions:
- No token transfers occur (purely accounting changes)
- Subject to the same risk checks as withdrawals/deposits
- Enforces maximum asset limits per position
The protocol integrates with Chainlink price oracles:
- Support for multiple oracles per asset
- Median price calculation for robust pricing
- Freshness thresholds for price data
- Special handling for volatile assets
- Tiered oracle fallback system
Several security mechanisms are implemented:
- Comprehensive input validation
- Reentrancy guards on all state-modifying functions
- Circuit breaker (pause) functionality
- Supply caps per asset
- Debt caps for isolated assets
- Maximum asset limit per position
- Minimum/maximum parameter constraints
The protocol provides extensive on-chain metrics:
- Current utilization rate
- Total borrow and supply amounts
- Interest accrual tracking
- Position health factors
- Asset TVL (Total Value Locked)
- Individual position summaries
- Collateral valuations
The Lendefi protocol is built with security and flexibility as core principles. The main contract implements:
-
Multi-tier Collateral System:
- STABLE: Lowest risk assets with 5% liquidation bonus
- CROSS_A: Low risk assets with 8% liquidation bonus
- CROSS_B: Medium risk assets with 10% liquidation bonus
- ISOLATED: High risk assets with 15% liquidation bonus
-
Risk Management:
- Dynamic health factor calculations based on collateral value and debt
- Position-specific credit limits
- Asset-specific borrowing and liquidation thresholds
- Price oracle safety mechanisms with volatility checks
-
Position Management:
- Cross-collateralization across multiple assets
- Isolated positions for higher risk assets
- Custom liquidation parameters per risk tier
- Interpositional asset transfers
-
Economic Model:
- Utilization-based interest rates
- Compound interest mechanism
- Protocol fees based on profit targets
- Flash loan functionality with configurable fees
- Liquidity provider incentives via yield tokens
-
Security Features:
- Role-based access control (RBAC)
- UUPS upgradeable pattern
- Non-reentrant function protection
- Emergency pause mechanism
- Oracle price validation with multiple safety checks
The protocol consists of several integrated components:
- Core Lending Contract: Manages borrowing, collateralization, and liquidations
- Liquidity Tokenization: ERC20-compatible yield token representing supplied liquidity
- Ecosystem Contract: Handles rewards and protocol incentives
- Governance Integration: Protocol parameters controlled via DAO
Positions become liquidatable when their health factor falls below 1.0. Liquidators:
- Must hold at least 20,000 governance tokens to perform liquidations
- Receive all collateral assets from the liquidated position
- Pay the full debt amount plus a tier-based liquidation fee
- Help maintain protocol solvency by managing undercollateralized positions
The protocol utilizes Chainlink price feeds with multiple safeguards:
- Price freshness verification
- Volatility monitoring for large price movements
- Round completion validation
- Minimum price checks
This software is provided as is with a Business Source License 1.1 without warranties of any kind. Some libraries included with this software are licenced under the MIT license, while others require GPL-v3.0. The smart contracts are labeled accordingly.
You need to hold 20_000 governance tokens to be able to run liquidations on the Lendefi Protocol.
This is a foundry repository. To get more information visit Foundry. You must have foundry installed.
curl -L https://foundry.paradigm.xyz | bash
foundryup
then
git clone https://github.com/nebula-labs-xyz/lendefi-protocol.git
cd lendefi-protocol
echo "ALCHEMY_API_KEY=your_api_key_here" >> .env
npm install
forge clean && forge build && forge test -vvv --ffi --gas-report