Cipherbase
BTC ETH XMR
DeFi Entry 07 of 20

Lending and Borrowing in DeFi: How Decentralized Credit Markets Work

DeFi has reimagined lending by removing banks from the equation entirely. Users interact directly with smart contracts that automate collateral, interest, and liquidations. The result is a permissionless credit market open to anyone, 24/7.

Animated diagram of deposits flowing into a lending pool, a borrower posting collateral and interest flowing back to lenders.
Animated diagram of deposits flowing into a lending pool, a borrower posting collateral and interest flowing back to lenders.
On this page
  1. How DeFi Lending Actually Works
  2. Key Protocols: Aave, Compound, and MakerDAO
  3. Collateral, Liquidation, and Health Factors
  4. Practical Use Cases for DeFi Borrowing
  5. Flash Loans: Uncollateralized Borrowing
  6. Governance and Protocol Risk

Decentralized finance has reimagined one of the oldest financial activities by removing banks from the equation entirely. No credit checks, no underwriting, no loan officer. Instead, you interact directly with smart contracts that handle collateral, interest, and liquidation automatically. The result is a permissionless credit market that runs 24/7 and is open to anyone with a crypto wallet.

Here's how DeFi lending actually works under the hood, what makes it different from traditional credit, and how to navigate the major protocols without getting burned.


How DeFi Lending Actually Works

In traditional finance, a bank takes deposits from savers and lends that money to borrowers, pocketing the spread between deposit and lending rates. DeFi replicates this using liquidity pools — smart contract-held reserves that anyone can deposit into or borrow from.

When you supply assets to a lending protocol, you get interest-bearing tokens in return. Compound gives you cTokens; Aave gives you aTokens. These tokens appreciate automatically as interest accrues. Redeem them later and the protocol returns your principal plus whatever yield built up while you waited.

Borrowers draw from those same pools. The catch is that you have to post collateral worth more than what you borrow — this is called overcollateralization. If your collateral value drops below a defined threshold, a liquidator can step in, repay part of your debt, and claim your collateral at a discount.

Interest Rate Models

Most protocols set interest rates algorithmically based on how much of the pool is being used at any given time.

When utilization is low, rates stay cheap to attract borrowers. When utilization gets high, rates spike sharply to push borrowers toward repayment and pull in more deposits. Compound's model follows a kinked curve: rates climb gradually up to an optimal utilization point, then jump hard beyond it to protect pool liquidity. It's a self-correcting system that doesn't need anyone managing it manually.


Key Protocols: Aave, Compound, and MakerDAO

Three protocols dominate DeFi lending, each with a distinct approach.

ProtocolCollateral ModelInterest TypeNotable Feature
AaveOvercollateralizedVariable + StableFlash loans, credit delegation
CompoundOvercollateralizedVariable (algorithmic)cToken model, COMP governance
MakerDAOOvercollateralizedStability feeGenerates DAI stablecoin
Euler FinanceRisk-tieredVariablePermissionless listing
MorphoP2P matching layerVariableBetter rates via Aave/Compound

Compound Protocol: A Closer Look

Compound is one of the most straightforward protocols to understand. Supply ETH, receive cETH. The exchange rate between cETH and ETH increases over time as interest accumulates — so the longer you hold cETH, the more ETH you get back when you redeem it.

Here's how you'd interact with Compound programmatically using ethers.js:

const { ethers } = require("ethers");

const cEthAbi = [
  "function mint() payable",
  "function redeem(uint256 redeemTokens) returns (uint256)",
  "function exchangeRateCurrent() returns (uint256)"
];

async function supplyEth(provider, cEthAddress, amountInEth) {
  const signer = provider.getSigner();
  const cEth = new ethers.Contract(cEthAddress, cEthAbi, signer);

  const tx = await cEth.mint({
    value: ethers.utils.parseEther(amountInEth)
  });

  await tx.wait();
  console.log(`Supplied ${amountInEth} ETH to Compound`);
}

This mints cETH proportional to the current exchange rate. Redeeming burns your cETH and returns ETH plus whatever interest accrued.


Collateral, Liquidation, and Health Factors

Before you borrow anything, you need to understand collateral mechanics. Every protocol defines two key parameters per asset.

The first is Loan-to-Value (LTV) — the maximum you can borrow against your collateral. An 80% LTV on ETH means you can borrow $800 against $1,000 worth of ETH.

The second is the Liquidation Threshold — the point where your position becomes eligible for liquidation. On Aave, ETH sits at 82.5%.

“Smart contracts will replace lawyers.”

— Andreas Antonopoulos

Your Health Factor on Aave combines these into a single number:

Health Factor = (Collateral Value × Liquidation Threshold) / Total Borrowed Value

A Health Factor above 1.0 means you're safe. Below 1.0 triggers liquidation. Say you deposit $10,000 of ETH with an 82.5% liquidation threshold and borrow $7,000. Your health factor works out to:

($10,000 × 0.825) / $7,000 = 1.178

ETH dropping just 15% pushes that to roughly 1.0 — right at the liquidation edge. That's why experienced borrowers typically keep their health factor at 1.5 or higher. It gives you breathing room when markets move fast.

What Happens During Liquidation

Liquidators are bots (and occasionally humans) that watch on-chain positions constantly. When a health factor falls below 1.0, they can repay up to 50% of the outstanding debt and claim the equivalent collateral plus a liquidation bonus — usually 5 to 10%. That bonus is what makes running a liquidation bot worthwhile, and it's also what makes being liquidated so costly when prices crash quickly.


Practical Use Cases for DeFi Borrowing

Why borrow less than you already own? It sounds circular, but there are real reasons people do it.

Leverage. Deposit ETH, borrow USDC, buy more ETH. You've now got leveraged long exposure without selling your original position. Protocols like Gearbox can automate this in a single transaction.

Liquidity without a tax bill. In most jurisdictions, borrowing against an asset isn't a taxable event — selling it is. An ETH holder who needs dollar liquidity can borrow USDC against their holdings without triggering capital gains. It's a meaningful difference if you've held for years.

Yield arbitrage. Supply an asset earning 3% APY on Compound, borrow a different asset at 2% APY, deploy that borrowed capital into a higher-yield strategy. This mechanic is at the core of most yield farming loops.

Short selling. Borrow an asset you think is going to fall, sell it immediately, wait for the price to drop, buy it back cheaper, repay the loan, and keep the difference. Clean and straightforward.


Flash Loans: Uncollateralized Borrowing

Flash loans have no equivalent in traditional finance. You can borrow any amount of any asset with zero collateral — as long as the entire loan is repaid within the same transaction block.

If repayment doesn't happen, the whole transaction reverts as if it never occurred. The blockchain enforces this atomicity, not a legal contract.

// Simplified Aave flash loan callback
function executeOperation(
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata premiums,
    address initiator,
    bytes calldata params
) external returns (bool) {
    // Your arbitrage, liquidation, or collateral swap logic here

    // Approve repayment: principal + 0.09% fee
    for (uint i = 0; i < assets.length; i++) {
        uint amountOwed = amounts[i] + premiums[i];
        IERC20(assets[i]).approve(address(POOL), amountOwed);
    }

    return true;
}

Legitimate uses include arbitrage between DEXs, liquidating undercollateralized positions, and collateral swaps. Flash loans have also been weaponized against protocols with weak price oracle designs, which is why robust oracles — like Chainlink's decentralized feeds or Uniswap's time-weighted average price — matter so much.


Governance and Protocol Risk

Lending protocols aren't static. Parameters like LTV ratios, supported assets, and interest rate curves are all controlled by governance. In Compound's case, COMP

Frequently Asked Questions

What is lending and borrowing in DeFi?

In DeFi, lending means depositing your crypto into a protocol so others can borrow it, and you earn interest in return. Borrowing means taking out a crypto loan by putting up your own crypto as collateral. Everything is handled by smart contracts, so there's no bank or credit check involved.

Why do I need collateral to borrow in DeFi?

DeFi protocols can't verify your identity or credit history, so they require you to deposit crypto worth more than what you want to borrow — this is called overcollateralization. If your collateral value drops too much, the protocol automatically liquidates it to cover the loan. This protects lenders from losing their funds.

What happens if I don't repay my DeFi loan?

There's no debt collector, but your collateral can be liquidated automatically if its value falls below the protocol's required threshold. You won't owe anything after liquidation, but you'll lose a portion of your collateral, often including a liquidation penalty fee. This is why it's important to monitor your collateral ratio closely.

Video Resources

Sources & Further Reading

  • Aave Docs — Lending protocol documentation, risk parameters and governance.
  • Compound Docs — Documentation for the Compound money market protocol.
  • DeFi Llama — Total value locked and protocol analytics across chains.
  • Ethereum.org: DeFi — Official introduction to decentralised finance on Ethereum.
  • Uniswap Docs — Protocol documentation for the leading automated market maker.
  • Finematics — Educational explainers on DeFi mechanisms with diagrams.
  • Lido Docs — Liquid staking protocol documentation.