MODULE 05

DeFi Fundamentals

Open, permissionless financial protocols: how trading, lending and earning yield work without a bank or exchange in the middle.

Intermediate Difficulty
40 min Duration
Reading + Quiz Format
12 Sections
Pair ETH / USDC
Liquidity $4.2M
Type AMM
01. Introduction

Introduction

Every financial action covered so far assumed you were the only one involved: holding an asset, moving it across a network. Decentralized finance (DeFi) introduces other participants: traders, liquidity providers, borrowers and lenders, all interacting through code instead of an institution.

This lesson explains what DeFi actually replaces, how a decentralized exchange fills a trade without an order book, how liquidity pools and automated market makers set prices, and the real risks, like impermanent loss, that come with participating.

By the end of this lesson you will understand how a swap executes without a company matching orders, why liquidity providers earn fees, what yield farming and staking actually mean in DeFi, and how to weigh the risk of a protocol before using it.

02. Smart Contracts

Smart Contracts

A smart contract is self-executing code deployed on a blockchain. Once deployed, its logic runs exactly as written: no company can quietly change the rules, freeze a specific user's funds, or make an exception behind the scenes.

Every DeFi protocol (every exchange, lending market, or yield strategy) is ultimately a set of smart contracts. Calling a protocol "trustless" means you're trusting published, inspectable code instead of a company's internal promises.

Deterministic

Given the same inputs, a smart contract always produces the same outcome.

Public

Anyone can read a contract's code and verify what it actually does.

Immutable (usually)

Most deployed contracts can't be changed, though some include upgrade mechanisms worth checking for.

03. Decentralized Exchanges (DEXs)

Decentralized Exchanges (DEXs)

A decentralized exchange lets people trade assets directly from their own wallets, using smart contracts to execute trades instead of a company holding custody of funds and matching orders internally.

Traditional exchanges (CEXs) use an order book, matching buyers and sellers at agreed prices. Most DEXs use a different model entirely: liquidity pools priced algorithmically by an automated market maker, covered in the next two sections.

CEX

A company custodies your funds, matches orders on an internal order book, and requires an account.

DEX

Your wallet keeps custody of your funds. Trades execute against a smart contract, with no account required.

Both models coexist across the industry: a DEX simply removes the custodian from the trading process.

04. Liquidity Pools

Liquidity Pools

A liquidity pool is a smart contract holding two (or more) assets, deposited by liquidity providers (LPs), that traders swap against directly. Instead of matching a buyer with a seller, a trade adjusts the pool's own reserves.

In exchange for depositing assets, liquidity providers receive LP tokens representing their share of the pool, and earn a portion of the trading fees generated by every swap.

pool_reserves.json
Pool ETH / USDC
Reserve A 120 ETH
Reserve B 240,000 USDC
LP Fee 0.30% per swap

The relationship between the two reserves is exactly what an automated market maker uses to set price, covered next.

05. Automated Market Makers (AMMs)

Automated Market Makers (AMMs)

An automated market maker is the formula a liquidity pool uses to price trades, based only on the pool's own reserves: no order book, and no external price feed required for the trade itself.

The most common model keeps the product of both reserves constant: as a trade removes some of one asset, the pool automatically raises its price relative to the other, in proportion to how much was removed.

Price is reactive

A large trade moves the pool's price more than a small one: this is where slippage comes from.

No counterparty needed

You always trade against the pool itself, not another specific person.

Arbitrage keeps it honest

If a pool's price drifts from the wider market, traders are incentivized to correct it for profit.

This same mechanism is also what creates impermanent loss for liquidity providers, explained later in this lesson.

06. Yield Farming

Yield Farming

Yield farming means actively moving assets between DeFi protocols to capture the highest available return, which can come from more than one source at once.

  • Trading fees. A share of the fees generated by swaps in a pool you've provided liquidity to.
  • Lending interest. Interest paid by borrowers in a lending market, covered in Module 06.
  • Incentive rewards. Extra tokens a protocol distributes to attract liquidity, on top of its normal fees.

Advertised returns often combine several of these sources: and incentive rewards specifically tend to fade as a protocol matures.

07. Staking

Staking

In DeFi, "staking" is used in two related but distinct ways: locking a network's native coin to help secure that network, or depositing an asset into a protocol's own contract to earn rewards.

Protocol-level staking is common: depositing an LP token to earn extra incentive rewards, or locking a governance token for a period in exchange for a share of protocol fees.

Network Staking

Securing a proof-of-stake network directly, earning a share of newly issued coins.

Protocol Staking

Depositing an asset into a specific protocol's contract to earn that protocol's own rewards.

Read a staking contract's terms carefully: lock-up periods and reward sources vary significantly between protocols.

08. Impermanent Loss

Impermanent Loss

Impermanent loss is the gap between what a liquidity provider's deposited assets would be worth if simply held, versus what they're worth withdrawn from the pool, after the pool's prices have moved.

It happens because an AMM automatically rebalances a pool's reserves as prices shift: the pool ends up holding more of the asset that fell in relative price and less of the one that rose.

divergence_example.json
Deposited 1 ETH + 2,000 USDC
If Held Value unchanged from deposit
If Withdrawn Lower after price divergence
Impermanent? Only realized if you withdraw during the gap

The loss is called "impermanent" because it can shrink back to zero if prices return to their original ratio before you withdraw: but it becomes permanent the moment you do.

09. DeFi Risks

DeFi Risks

Removing a company from the process doesn't remove risk: it changes what kind of risk you're taking on.

  • Smart contract risk. A bug in a contract's code can be exploited, and losses are frequently irreversible.
  • Impermanent loss. Covered in the previous section: a real cost of providing liquidity, not just a hypothetical one.
  • Oracle risk. Protocols that rely on external price feeds can be manipulated if that feed is inaccurate or compromised.
  • Rug pulls. A project's creators abandon it and drain its liquidity, sometimes by design from the start.
  • Composability risk. Protocols building on top of each other means a failure in one can cascade into every protocol depending on it.
10. Summary

Summary

DeFi rebuilds trading, lending, and earning yield as open smart contracts instead of company-run services. Decentralized exchanges use liquidity pools priced by automated market makers, replacing a traditional order book.

Liquidity providers earn fees but take on impermanent loss when pool prices diverge. Yield farming and staking describe different ways of putting assets to work across protocols: and every one of these activities carries risk that doesn't disappear just because there's no company involved.

11. Glossary

Glossary

DeFi
Decentralized finance: financial services rebuilt as open smart contracts instead of company-run services.
Smart Contract
Self-executing code deployed on a blockchain that defines exactly how a protocol behaves.
DEX
Decentralized Exchange: a trading protocol that executes trades against smart contracts instead of a company's order book.
Liquidity Pool
A smart contract holding two or more assets that traders swap against directly.
AMM
Automated Market Maker: the formula a liquidity pool uses to price trades based on its own reserves.
LP Token
A token representing a liquidity provider's share of a pool, used to withdraw their deposit and earned fees.
Yield Farming
Actively moving assets between protocols to capture the highest available return.
Staking
Locking an asset in a network or protocol's contract in exchange for rewards.
Impermanent Loss
The gap between holding assets and providing them to a pool, caused by price divergence between reserves.
Rug Pull
When a project's creators abandon it and drain its liquidity, leaving other participants with worthless holdings.
12. Quiz

Quiz

Check your understanding of this lesson before moving on. Incorrect answers point you straight back to the relevant section.

1. What does a smart contract guarantee, compared to a company-run service?

2. How does a typical DEX differ from a centralized exchange?

3. What is a liquidity pool?

4. What determines the price of a trade in an AMM-based pool?

5. Which of these is a real source of yield farming returns?

6. What is "protocol staking," as distinct from network staking?

7. When does impermanent loss become permanent?

8. What is a "rug pull"?

9. Why doesn't removing a company from a financial service eliminate risk?