A decentralized lending and borrowing platform where users can supply assets as collateral, earn interest, and borrow against their holdings using smart contracts on Ethereum.
DeFi Lending Protocol is a trustless money market that allows users to supply crypto assets to earn interest or use them as collateral to borrow other assets. Using smart contracts on Ethereum, the platform ensures transparent, automated interest accrual and fair liquidation based on real-time market conditions.
- Deposit USDC, ETH, or other supported assets
- Receive lTokens representing your share of the pool
- Earn interest automatically as borrowers pay fees
- Redeem your lTokens anytime for underlying assets + accrued interest
- Use supplied assets as collateral to borrow other tokens
- Flexible collateral factors (75-80% depending on asset)
- No fixed loan terms - repay whenever you want
- Only pay interest on what you borrow
- Rates adjust automatically based on supply and demand
- Higher utilization = higher rates for suppliers and borrowers
- Kinked interest rate model optimizes capital efficiency
- Target utilization of 80% for optimal market health
- Real-time health factor monitoring
- Automated liquidation when positions become undercollateralized
- 8% liquidation penalty protects lenders
- 50% close factor limits liquidation impact
- All logic executed on-chain via audited smart contracts
- 10% reserve factor supports protocol sustainability
- Reentrancy protection and access controls
- Emergency pause functionality
- Connect Wallet: Connect your Web3 wallet to the platform
- Supply Assets: Deposit USDC, ETH, or other supported tokens to earn interest
- Enable as Collateral: Authorize your supplied assets to be used as collateral
- Borrow: Take out loans up to your collateral limit
- Monitor Health: Keep your health factor above 1.0 to avoid liquidation
- Repay & Redeem: Repay loans anytime and withdraw your supply + interest
The protocol uses a kinked interest rate model to balance supply and demand:
| Parameter | Value | Description |
|---|---|---|
| Base Rate | 2% | Minimum interest rate when utilization = 0% |
| Multiplier | 20% | Rate increase per utilization point up to kink |
| Jump Multiplier | 109% | Steep rate increase after kink point |
| Kink | 80% | Optimal utilization rate target |
Formula:
If utilization ≤ 80%:
Borrow Rate = 2% + (utilization × 20%)
If utilization > 80%:
Borrow Rate = 2% + (80% × 20%) + ((utilization - 80%) × 109%)
| Parameter | USDC | ETH | Description |
|---|---|---|---|
| Collateral Factor | 80% | 75% | Maximum borrowing power per $1 of collateral |
| Liquidation Threshold | 85% | 82% | When positions become liquidatable |
| Liquidation Penalty | 8% | 8% | Bonus given to liquidators |
| Reserve Factor | 10% | 10% | Protocol fee taken from interest |
| Close Factor | 50% | 50% | Maximum % of debt liquidatable per transaction |
Supply: $1,000 USDC
Borrow Limit: $800 (80% collateral factor)
Safe Borrow: $600 (75% utilization)
Health Factor: 1.33
Liquidation Risk: Low ✅
Supply: $1,000 USDC
Borrow: $790 (98.75% utilization)
Health Factor: 1.01
Liquidation Risk: HIGH ⚠️ (close to liquidation)
defi-lending-protocol/
├── contracts/ # Solidity smart contracts
│ ├── LToken.sol # Individual lending markets
│ ├── Comptroller.sol # Risk management & governance
│ └── InterestRateModel.sol # Interest rate calculations
├── src/ # Next.js frontend application
│ ├── components/ # React components
│ ├── config/ # Contract ABIs and addresses
│ └── hooks/ # Wagmi hooks for blockchain interaction
├── script/ # Foundry deployment scripts
└── test/ # Comprehensive test suite
- Smart Contracts: Solidity 0.8.20, OpenZeppelin, Foundry
- Frontend: Next.js 14, TypeScript, Tailwind CSS
- Web3 Integration: Wagmi, Viem, RainbowKit
- Blockchain: Ethereum (Sepolia testnet ready)
- Testing: Foundry (Forge)
- Comptroller:
0x0b1c31213d3181fd9b9fd159288f84adb2825e97 - Interest Rate Model:
0xa7bc577f2e1ff05bc79eaaed8c907a548b9d70b6 - Price Oracle:
0x313ed33288c24768db927cfb7af0304149f426ff
- USDC (Sepolia):
0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8 - WETH (Sepolia):
0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14
- Node.js 18+
- Foundry (installation guide)
- Git
# Clone the repository
git clone https://github.com/RobinOppenstam/defi-lending-protocol
cd defi-lending-protocol
# Install dependencies
npm install
# Install Foundry dependencies
forge install# Compile contracts
forge build
# Run tests
forge test
# Run tests with detailed output
forge test -vvv
# Generate coverage report
forge coverage
# Deploy to Sepolia testnet
forge script script/Deploy.s.sol --rpc-url sepolia --broadcast --verify# Set up environment variables
cp .env.example .env
# Add your WALLETCONNECT_PROJECT_ID to .env
# Update contract addresses in src/config/contracts.ts after deployment
# Start development server
npm run dev
# Visit http://localhost:3000Individual lending market for each supported asset. Handles supply, borrow, repay, and redeem operations.
Central risk management contract that tracks collateral, calculates borrow limits, and enforces liquidation rules.
Implements the kinked interest rate curve that adjusts rates based on market utilization.
The protocol includes comprehensive test coverage:
- ✅ Supply assets and receive lTokens
- ✅ Redeem lTokens for underlying assets
- ✅ Borrow against collateral
- ✅ Repay borrowed assets
- ✅ Interest rate calculations
- ✅ Exchange rate updates over time
- ✅ Liquidation mechanics
- ✅ Access controls and permissions
- ✅ Edge cases and failure modes
# Run all tests
forge test
# Run specific test file
forge test --match-path test/LToken.t.sol
# Run specific test function
forge test --match-test testSupplyAndRedeem- ✅ Reentrancy guards on all external calls
- ✅ Integer overflow protection (Solidity 0.8+)
- ✅ Access controls for admin functions
- ✅ Emergency pause functionality
- ✅ Liquidation safeguards
⚠️ Price Oracle: Requires Chainlink integration for production use⚠️ Governance: Single owner instead of decentralized governance⚠️ Audits: Not professionally audited - testnet only
- ✅ Core lending and borrowing functionality
- ✅ Kinked interest rate model
- ✅ Frontend interface with Web3 integration
- ✅ Comprehensive test suite
- 🔲 Chainlink price oracle integration
- 🔲 Liquidation bot implementation
- 🔲 Gas optimization
- 🔲 Additional token markets
- 🔲 Governance token and DAO
- 🔲 Flash loan functionality
- 🔲 Cross-chain deployment
- 🔲 Advanced analytics dashboard
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This is a testnet implementation for educational purposes only.
Do NOT use with real funds without:
- Professional security audits
- Proper price oracle integration
- Comprehensive testing on mainnet conditions
- Legal and regulatory compliance review
- 📖 Documentation (Coming soon)
- 🐛 Report Issues
- 💬 Join Discord (Coming soon)
Built with ❤️ using Foundry, Next.js, and Wagmi