# DeFi Basics

> Lending, swapping, and yield without a bank.

Module: Crypto — Deep Dive — Finotaur Academy (free lesson)
Source: https://www.finotaur.com/academy/crypto/defi-basics

## You'll be able to

Explain how DeFi lending, swapping and liquidity provision work, calculate a loan's health factor, its liquidation distance and a liquidity provider's impermanent loss, and tell real yield from subsidised yield.

## In plain words

Decentralized finance (DeFi) is the set of financial services, mainly lending, borrowing, trading and earning yield, built from smart contracts on public blockchains, so users interact with code from their own wallets instead of with a bank or broker. Rules such as interest rates, collateral requirements and liquidations are enforced automatically and transparently. That removes the intermediary but not the risk: you now carry smart-contract risk, oracle risk and liquidation risk yourself, with no one to call when something goes wrong.

```takeaways
- **Lending markets** require over-collateralized loans; the **health factor** tells you how close you are to liquidation.
- **AMMs** let anyone provide liquidity and earn fees, but LPs suffer **impermanent loss** when prices diverge.
- **APY** includes compounding; **APR** does not. 10% APR compounded daily is about 10.52% APY.
- Ask where every yield comes from: borrower interest and trading fees are real; token emissions are a subsidy.
```

## Quick demo

**1. A DeFi loan (hypothetical parameters).** You deposit ETH worth **$10,000** in a lending market with an 82.5% liquidation threshold and borrow **$5,000** of stablecoins.

- Health factor = (collateral × liquidation threshold) ÷ debt = (10,000 × 0.825) ÷ 5,000 = **1.65**.
- Liquidation starts when the health factor falls below 1. With the debt fixed, that happens when collateral value falls by 1 − 1 ÷ 1.65 = **39.4%**, to about $6,061.
- Borrowing $6,500 instead gives 8,250 ÷ 6,500 = 1.27, and only about a **21%** drop is needed. Small changes in borrowing move your liquidation price a lot.

**2. Providing liquidity.** You deposit equal values of ETH and USDC into a constant-product pool. If ETH's price later doubles, the pool's arbitrage rebalancing leaves you with less ETH and more USDC than you started with. Compared with simply holding the two tokens, your position is worth:

- 2√r ÷ (1 + r) − 1, where r is the price ratio. For r = 2: 2 × 1.414 ÷ 3 − 1 = **−5.7%**.
- For r = 4 (price quadruples): 2 × 2 ÷ 5 − 1 = **−20%**. A halving (r = 0.5) also gives **−5.7%**.

That gap is **impermanent loss**. Fees earned may cover it, or may not.

**3. APR vs. APY.** A 10% APR compounded daily gives (1 + 0.10 ÷ 365)^365 − 1 = **10.52%** APY. Always compare like with like.

```chart
{
  "type": "bar",
  "title": "Impermanent loss vs. holding, by price change of one asset",
  "data": [["0.5x", -5.72], ["1.5x", -2.02], ["2x", -5.72], ["4x", -20.0]],
  "unit": "%",
  "unitPosition": "suffix",
  "caption": "Exact formula 2√r ÷ (1 + r) − 1 for a 50/50 constant-product pool, before trading fees.",
  "source": "Constant-product AMM arithmetic"
}
```

## Full explanation

### The building blocks

- **Swapping (DEXs).** Automated market makers price trades from pool balances. See the exchanges chapter for the x × y = k arithmetic.
- **Lending and borrowing.** Depositors supply assets to a pool and earn interest; borrowers post collateral and pay interest. Rates usually float with **utilisation**: the more of a pool that is borrowed, the higher both rates go, which attracts new deposits and discourages borrowing.
- **Stablecoins.** The main asset borrowed and lent; covered in their own chapter.
- **Staking and liquid staking.** Locking a proof-of-stake asset for rewards, often via tokens that can themselves be used as collateral elsewhere.
- **Derivatives and structured vaults.** On-chain perpetuals, options and automated strategies built on the pieces above.

Because these contracts can call one another, developers combine them like building blocks. This **composability** is DeFi's main innovation and its main systemic risk.

### Why loans are over-collateralized

A DeFi protocol cannot check your credit or sue you. Instead it holds more collateral than you borrow and sells it if its value falls too close to the debt. **Liquidators** (often bots) repay part of your debt and receive your collateral at a discount, the **liquidation bonus**, which is your penalty. Professionals treat the health factor like a margin level: they set alerts well above 1, add collateral or repay early, and avoid borrowing volatile assets against other volatile assets that may fall together.

### Where yield comes from

Every DeFi yield has a source:

- **Borrower interest**: real demand, usually for leverage.
- **Trading fees** paid to liquidity providers.
- **Staking rewards** from a blockchain's issuance and fees.
- **Token emissions**: the protocol paying you in its own token to attract deposits. This is a subsidy; its value depends on that token's price, and selling pressure from all recipients often pushes it down.

If you cannot name the source, assume the yield compensates you for a risk you have not identified.

### Impermanent loss in more depth

An AMM pool always rebalances toward the external price, because arbitrageurs buy whichever token is cheap in the pool. A liquidity provider therefore systematically sells the rising asset and buys the falling one. The loss is called "impermanent" because it disappears if prices return to the starting ratio, but it becomes permanent when you withdraw. **Concentrated liquidity** pools amplify both fee income and impermanent loss, because your capital is active only inside a chosen range; if price leaves the range, you hold 100% of the weaker asset and earn no fees.

### The risk map

- **Smart-contract risk**: bugs or exploits that drain funds. Audits help; long track records with large deposits help more; neither guarantees safety.
- **Oracle risk**: protocols rely on price feeds. Manipulated or delayed prices can trigger unfair liquidations or let attackers borrow against inflated collateral.
- **Governance and admin risk**: token holders or a multisig can change parameters or upgrade contracts.
- **Liquidity risk**: during stress, withdrawals may be impossible because most of a pool is lent out.
- **Bridge risk**: assets moved between chains are often held by bridge contracts, which have been among the largest hacking targets.
- **De-peg risk**: a stablecoin or liquid-staking token trading below its expected value can cascade through protocols that accept it as collateral.

### Advanced nuance

**Leverage loops** (deposit, borrow, re-deposit, repeat) multiply both yield and liquidation risk, and a small rate change can turn the loop unprofitable. **Correlated collateral** feels safe until a crash moves everything together. And on public chains your position, health factor and liquidation price are visible to everyone, including bots waiting to liquidate it.

### Common mistakes

- **Borrowing close to the maximum** and leaving no buffer for volatility.
- **Comparing APR with APY**, or quoting emissions yield as if it were cash.
- **Providing liquidity to volatile pairs** without modelling impermanent loss.
- **Depositing in a new protocol** because its yield is the highest on the dashboard.

```tip
Before you borrow, calculate the price drop that would liquidate you and compare it with the asset's moves on its worst days. If one bad day can reach your liquidation price, you are borrowing too much.
```

```checklist
title: Before you deposit into a DeFi protocol
- Name the source of the yield: interest, fees, staking or emissions.
- Check audits, time live and total value deposited, then size accordingly.
- Find out who can upgrade the contracts and whether changes are time-locked.
- For loans, compute your health factor and the price drop to liquidation.
- For LP positions, estimate impermanent loss for a 2x move either way.
- Use a dedicated wallet and limit token approvals.
```

```quiz
[
  {
    "q": "Collateral $12,000, liquidation threshold 0.80, debt $6,000. What is the health factor?",
    "options": ["1.25", "1.60", "2.00", "0.80"],
    "answer": 1,
    "why": "(12,000 × 0.80) ÷ 6,000 = 9,600 ÷ 6,000 = 1.60."
  },
  {
    "q": "In a 50/50 constant-product pool, one asset's price doubles relative to the other. Impermanent loss vs. holding is about:",
    "options": ["−2.0%", "−5.7%", "−20%", "−50%"],
    "answer": 1,
    "why": "2√2 ÷ 3 − 1 ≈ −5.7%, before fees."
  },
  {
    "q": "Which yield source is a subsidy rather than organic income?",
    "options": ["Borrower interest", "Trading fees", "Token emissions paid in the protocol's own token", "None of these"],
    "answer": 2,
    "why": "Emissions are newly issued tokens used to attract deposits; their value depends on the token's price."
  },
  {
    "q": "A pool quotes 12% APR compounded daily. Its APY is closest to:",
    "options": ["12.00%", "12.75%", "13.50%", "11.50%"],
    "answer": 1,
    "why": "(1 + 0.12 ÷ 365)^365 − 1 ≈ 12.75%."
  }
]
```
