ChainScore Labs
All Guides

What is DeFi Lending and How Does It Work?

LABS

What is DeFi Lending and How Does It Work?

An architectural and operational analysis of decentralized lending protocols, detailing the core mechanisms that enable permissionless credit markets.
Chainscore © 2025

Core Architectural Concepts

An overview of the fundamental technical and financial mechanisms that power decentralized lending protocols, enabling permissionless borrowing and lending of digital assets.

Overcollateralized Loans

Overcollateralization is a foundational risk-management mechanism where borrowers must deposit crypto assets worth more than the loan value. This creates a safety buffer for lenders against price volatility.

  • A user deposits $150 worth of ETH as collateral to borrow $100 in stablecoins.
  • If the collateral value falls too close to the loan value, it may be liquidated.
  • This system enables trustless lending without credit checks, but requires significant capital from borrowers.

Liquidity Pools & Money Markets

Liquidity pools are smart contract-based reservoirs where lenders deposit assets to earn interest. Protocols like Aave and Compound aggregate these into money markets with algorithmically set rates.

  • Lenders supply assets like USDC to a pool to earn a variable APY.
  • Borrowers draw from this pool, paying interest that is distributed to lenders.
  • This creates a dynamic, transparent marketplace for capital, replacing traditional intermediaries.

Algorithmic Interest Rates

Interest rates in DeFi are not set by a central entity but are determined algorithmically based on the supply and demand for each asset within a protocol's pool.

  • When borrowing demand for DAI is high, its interest rate increases automatically.
  • This incentivizes more lenders to supply DAI to capture higher yields.
  • This real-time price discovery creates efficient markets and competitive returns for users.

Liquidation Mechanisms

Liquidation is a critical process that protects the protocol and lenders. If a borrower's collateral value falls below a required threshold (the liquidation ratio), their position is automatically sold to repay the loan.

  • A "liquidation bot" can purchase the undercollateralized assets at a discount.
  • This process is enforced by smart contracts, ensuring solvency.
  • It maintains system health but poses a key risk for borrowers during market crashes.

Governance Tokens

Governance tokens like AAVE or COMP confer voting rights to holders, enabling decentralized community control over a lending protocol's key parameters and upgrades.

  • Token holders vote on proposals to adjust interest rate models or add new collateral assets.
  • They often also provide fee discounts or reward distributions.
  • This aligns protocol development with user interests, fostering a decentralized ecosystem.

Flash Loans

Flash loans are uncollateralized loans that must be borrowed and repaid within a single blockchain transaction. They are a unique innovation only possible in DeFi.

  • An arbitrageur borrows a large sum to exploit a price difference between two exchanges, repaying it instantly with profit.
  • If repayment fails, the entire transaction reverts, eliminating default risk.
  • This enables sophisticated trading strategies and capital efficiency without upfront capital.

The Lending Lifecycle: A Step-by-Step Breakdown

A detailed walkthrough of the decentralized finance lending process, from depositing collateral to repaying loans.

1

Step 1: Collateral Deposit & Smart Contract Interaction

The user locks crypto assets into a lending protocol's smart contract.

Detailed Instructions

To initiate a loan, a user must first deposit collateral assets like ETH, WBTC, or stablecoins into a protocol's smart contract. This action is secured by the blockchain and creates a collateralized debt position (CDP). The smart contract, such as Aave's LendingPool, calculates the Loan-to-Value (LTV) ratio to determine borrowing power. For example, depositing 10 ETH (worth $30,000) with a 75% LTV allows borrowing up to $22,500.

  • Sub-step 1: Connect Wallet: Use MetaMask or WalletConnect to link your wallet (e.g., address 0x742d35Cc6634C0532925a3b844Bc9e...) to the DeFi platform.
  • Sub-step 2: Approve Token: Sign a transaction to grant the protocol's contract permission to move your tokens. This is an ERC-20 approve function call.
  • Sub-step 3: Deposit Collateral: Execute the deposit function, which transfers your tokens to the protocol's pool and mints a receipt token (like aTokens in Aave) representing your share.

Tip: Always verify the contract address on the protocol's official website to avoid scams. Monitor gas fees to ensure cost-effective transactions.

2

Step 2: Borrowing Assets Against Collateral

The user takes out a loan in a different cryptocurrency, up to their approved limit.

Detailed Instructions

Once collateral is locked, users can borrow assets from the protocol's liquidity pool. The maximum borrowable amount is determined by the health factor, a safety metric that must stay above 1.0 to avoid liquidation. Borrowing involves interacting with the protocol's core borrowing function, which transfers the borrowed asset to the user's wallet and records the debt.

  • Sub-step 1: Select Asset: Choose the asset to borrow (e.g., DAI, USDC, or another token). Check the current interest rate model (stable or variable).
  • Sub-step 2: Specify Amount: Enter the amount to borrow, ensuring it doesn't exceed your borrowing limit based on your collateral's LTV. For instance, borrowing 5,000 DAI.
  • Sub-step 3: Execute Borrow: Call the borrow() function on the smart contract. This will increase your debt and decrease your health factor.
solidity
// Example borrow function call for Aave ILendingPool lendingPool = ILendingPool(0x7d2768dE...); lendingPool.borrow(DAI_ADDRESS, 5000000000000000000000, 2, 0, msg.sender); // 2 represents variable interest rate, 5000 DAI (with 18 decimals)

Tip: Borrowing at a variable rate can be cheaper initially but carries interest rate risk. Always leave a buffer in your health factor (e.g., >1.5) for market volatility.

3

Step 3: Accruing Interest & Managing Position

Interest accumulates on the borrowed amount, and the user monitors their position's health.

Detailed Instructions

After borrowing, interest accrues continuously on the debt, typically in real-time per block. The interest rate is determined by the pool's utilization rate and the chosen rate model. Users must actively manage their position by tracking the health factor, which fluctuates with collateral value and debt amount. If the health factor drops below 1.0, the position becomes eligible for liquidation.

  • Sub-step 1: Monitor Health Factor: Use the protocol's interface or a dashboard like DeBank to check your health factor. A value like 1.75 is considered safe.
  • Sub-step 2: Track Interest: View your accumulating debt, which compounds. For variable rates, the APY might change from 3% to 8% based on market conditions.
  • Sub-step 3: Optional Actions: To improve your health factor, you can:
    • Repay a portion of the debt.
    • Add more collateral to the position.
    • Switch from a variable to a stable interest rate (if supported).

Tip: Set up alerts for your health factor using services like Gelato Network to avoid unexpected liquidations during market crashes.

4

Step 4: Loan Repayment & Collateral Withdrawal

The user repays the loan plus interest to unlock their original collateral.

Detailed Instructions

The final step involves repaying the loan in full (or partially) to retrieve the locked collateral. The user must repay the borrowed asset plus all accrued interest. Upon full repayment, the debt is cleared, and the collateral becomes withdrawable. This requires two main transactions: approving the repayment and executing the repayment function.

  • Sub-step 1: Approve Repayment: Grant the protocol contract permission to spend the repayment token (e.g., DAI) from your wallet using the approve function.
  • Sub-step 2: Execute Repayment: Call the repay() function on the smart contract. Specify the amount to repay. Repaying the full debt will set your borrowed balance to zero.
  • Sub-step 3: Withdraw Collateral: Once debt is zero, call the withdraw() function to transfer your original collateral (e.g., ETH) back to your wallet.
solidity
// Example repay and withdraw calls IERC20(DAI_ADDRESS).approve(lendingPoolAddress, repayAmount); lendingPool.repay(DAI_ADDRESS, repayAmount, 2, msg.sender); // 2 for variable rate debt lendingPool.withdraw(ETH_ADDRESS, collateralAmount, msg.sender);

Tip: Always repay a slightly higher amount (e.g., 1% more) to account for interest accrued between transaction creation and confirmation. Verify the transaction on a block explorer like Etherscan.

Major Lending Protocols: A Feature Comparison

Comparison of key operational and economic features across leading DeFi lending platforms.

FeatureAave V3Compound V3MakerDAO

Primary Governance Token

AAVE

COMP

MKR

Native Stablecoin

GHO

None

DAI

Interest Rate Model

Variable & Stable Rates

Jump Rate Model

Stability Fee

Max Loan-to-Value (LTV) for ETH

80%

82.5%

90% (for ETH-A vault)

Unique Feature

Flash Loans, Rate Switching

Comet USDC Market

Overcollateralized Vaults

Primary Deployment Chain

Ethereum, 10+ others

Ethereum

Ethereum

Total Value Locked (TVL) ~

$12.5B

$2.1B

$8.3B

Liquidation Penalty (ETH)

5%

5%

13%

Protocol Roles and Incentives

Understanding the Ecosystem

At its core, DeFi lending allows you to be your own bank. You can deposit your crypto to earn interest or borrow assets by putting up other crypto as collateral. This system is powered by smart contracts on blockchains like Ethereum, which automate the entire process without a central company.

Key Roles You Can Play

  • Lenders/Suppliers: You deposit assets like USDC or ETH into a liquidity pool on a protocol like Aave. In return, you receive interest-bearing tokens (like aTokens) that accrue yield.
  • Borrowers: You can take out a loan by locking up more valuable crypto as collateral. For example, you might deposit $150 worth of ETH to borrow $100 worth of DAI, maintaining a collateral ratio for safety.
  • Liquidators: These are users who help keep the system solvent. If a borrower's collateral value falls too close to their loan value, anyone can liquidate their position, repaying the debt and seizing the collateral for a bonus.

Real-World Incentive

Why would you participate? As a lender, you earn passive income, often higher than traditional savings. As a borrower, you access liquidity without selling your assets, which is useful for trading or real-world expenses. The entire system is secured by transparent, mathematical rules.

Critical Risks and Failure Modes

While DeFi lending offers high yields and permissionless access, it operates without traditional safeguards. This grid details the primary vulnerabilities users and protocols face, from smart contract exploits to systemic market failures.

Smart Contract Risk

Smart contracts are immutable, self-executing code that powers all DeFi protocols. Any bug or vulnerability can be catastrophic.

  • Exploits: Hackers can drain funds by finding flaws, as seen in the $190M Euler Finance hack in 2023.
  • Upgradability Issues: Some protocols use proxy patterns for updates, introducing centralization and new bug risks.
  • Why this matters: Users entrust all collateral to this code; a single error can lead to total, irreversible loss of funds.

Liquidation Risk

Liquidation occurs when a borrower's collateral value falls below the required threshold, triggering an automatic sale at a discount.

  • Volatility Spikes: A sudden market crash can cause mass liquidations, as seen during the 2022 LUNA/UST collapse.
  • Slippage and Bad Debt: Liquidators may not cover the full loan, leaving the protocol with unrecoverable debt.
  • Why this matters: Borrowers can lose most of their collateral instantly, while protocols risk insolvency from bad debt accumulation.

Oracle Failure

Oracles are external data feeds that provide price information to smart contracts. They are a critical single point of failure.

  • Manipulation Attacks: 'Oracle manipulation' can be used to drain protocols, famously exploited in the $34M Harvest Finance attack.
  • Data Lag: Delayed price updates during high volatility can cause incorrect liquidations or allow undercollateralized borrowing.
  • Why this matters: If oracle data is wrong, the entire lending protocol's solvency calculations become invalid, leading to massive losses.

Protocol & Governance Risk

Governance tokens grant voting rights on protocol changes, but decision-making can be slow, contentious, or centralized.

  • Malicious Proposals: A token holder majority could vote to steal funds or alter critical parameters.
  • Voter Apathy: Low participation can lead to decisions by a small, potentially misaligned group.
  • Why this matters: Users are subject to the decisions of token holders, which may not align with their interests, risking arbitrary changes to the system's rules.

Systemic & Contagion Risk

Systemic risk refers to the interconnectedness of DeFi protocols, where the failure of one can cascade through the entire ecosystem.

  • Composability Dangers: Protocols are built like 'money legos'; a failure in a widely used oracle or lending pool can collapse many others.
  • Collateral Rehypothecation: The same asset (e.g., stETH) used as collateral across multiple protocols can create a domino effect of liquidations.
  • Why this matters: A crisis in one major protocol, like Aave or Compound, can trigger a widespread loss of confidence and liquidity across DeFi.
SECTION-TECHNICAL-FAQ

Technical Deep Dive: Frequently Asked Questions

Ready to Start Building?

Let's bring your Web3 vision to life.

From concept to deployment, ChainScore helps you architect, build, and scale secure blockchain solutions.