Chapter 6 of 9
DeFi Primitives: Lending, Trading, and Yield
Explore the main building blocks of decentralized finance and how they replicate or extend traditional financial services.
1. From TradFi to DeFi Primitives
In traditional finance (TradFi), core services are:
- Trading: Stock exchanges and brokers match buyers and sellers.
- Lending/Borrowing: Banks take deposits and issue loans.
- Yield: Savings accounts, bonds, and other products pay interest.
In decentralized finance (DeFi), these functions are re-created using smart contracts instead of banks or brokers. The key primitives (building blocks) you’ll see repeatedly are:
- Decentralized exchanges (DEXs)
- AMMs (Automated Market Makers) like Uniswap
- On-chain order books like dYdX (v3 on Ethereum/L2, later Cosmos app-chain)
- Lending and borrowing protocols like Aave and Compound
- Liquidity pools and yield farming (earning fees or token rewards)
- Composability ("money legos"): protocols can stack on top of each other
By the end of this module, you should be able to:
- Describe how DEXs enable peer-to-peer trading without centralized intermediaries.
- Explain how DeFi lending/borrowing works and how on-chain interest rates are set.
- Understand liquidity provision, yield farming, and how composability ties it all together.
> Context (relative to today – early 2026):
> - AMM-style DEXs (Uniswap, Curve, Balancer) still dominate spot DeFi trading.
> - Major lending protocols (Aave, Compound, Spark, Morpho) continue to use overcollateralized loans.
> - Yield strategies often combine multiple protocols (e.g., deposit → borrow → LP → farm).
2. AMM DEXs: Trading Without an Order Book
Most DeFi trading volume still happens on AMM (Automated Market Maker) DEXs.
2.1 Core idea
Instead of an order book with bids and asks, an AMM holds a pool of two (or more) tokens and uses a pricing formula to determine the exchange rate.
The classic Uniswap v2 model for a 2-token pool (Token A and Token B):
- Let `x` = amount of Token A in the pool
- Let `y` = amount of Token B in the pool
- The pool maintains:
`x * y = k` (a constant)
When you trade:
- You send in Token A, receive Token B.
- `x` increases, `y` decreases.
- The product `x * y` stays (approximately) constant.
- The price is implied by the ratio `y / x`.
2.2 How a swap works (simplified)
You want to swap 100 USDC → ETH in a USDC/ETH pool:
- Before your trade:
- Pool has `x = 100,000 USDC`, `y = 50 ETH`
- `k = 100,000 * 50 = 5,000,000`
- You send `Δx = 100 USDC` to the pool → new `x' = 100,100`.
- To keep `x' * y' ≈ k`, solve for `y'`:
- `100,100 * y' = 5,000,000` → `y' ≈ 49.95 ETH`
- You receive `y - y' = 0.05 ETH` (minus a small fee, e.g., 0.3%).
> Key point: You trade against the pool, not against a specific counterparty. Liquidity providers (LPs) collectively are the counterparty.
2.3 Variants you should know
- Uniswap v3 (2021) → concentrated liquidity:
- LPs choose specific price ranges to provide liquidity.
- More efficient capital use but more complex and riskier for LPs.
- Curve → specialized for stablecoins and correlated assets:
- Uses formulas that reduce slippage when prices are expected to be similar (e.g., USDC/USDT/DAI).
- Balancer → multi-asset pools (e.g., 80/20 or 50/25/25 baskets).
These designs are still standard in 2026, with many forks and improvements across chains (Ethereum, L2s, Solana, etc.).
3. Thought Exercise: Slippage on an AMM
Imagine two trades on the same Uniswap v2-style ETH/USDC pool:
- Pool state before any trade:
- `x = 200,000 USDC`
- `y = 100 ETH`
- Implied price ≈ 2,000 USDC/ETH
Trade A: Swap 200 USDC → ETH
Trade B: Swap 20,000 USDC → ETH
Your task
- Qualitatively (no exact math needed):
- Which trade experiences more price impact (slippage), A or B? Why?
- Think about these guiding questions:
- How does trade size compare to pool size?
- What happens to the `x` and `y` balances after each trade?
- How does the price (ratio `y/x`) change after a small vs. large trade?
- Optional quick estimate (if you like math):
- For a small trade (Trade A), the price after the trade will be close to 2,000 USDC/ETH.
- For a large trade (Trade B), the price after the trade will move noticeably.
Write down a 2–3 sentence explanation of why larger trades in AMMs cause more slippage, then compare your reasoning to this intuition:
> As the trade size becomes larger relative to the pool, it pushes the token balances further away from their starting ratio, so the pricing formula adjusts the price more aggressively, causing higher slippage.
4. On-Chain Order Book DEXs
Not all DEXs are AMMs. Some use order books, similar to centralized exchanges (CEXs).
4.1 How order book DEXs work
- Traders place limit orders (e.g., "Sell 1 ETH at 2,100 USDC").
- Orders are matched with market orders or other limit orders.
- Matching can happen:
- Fully on-chain (less common due to gas costs).
- Hybrid: off-chain order book + on-chain settlement.
Examples and evolutions (up to early 2026):
- dYdX:
- v3: ran as a Layer 2 on Ethereum with an off-chain order book and on-chain settlement.
- Later migrated to a Cosmos-based app chain, still using an order book model.
- Injective, Sei, Vertex, GMX v2 (and others):
- Use order books or hybrid designs on specialized chains or L2s.
4.2 AMMs vs. order books (conceptual comparison)
- Capital efficiency:
- Order books can be more efficient for very liquid markets.
- AMMs guarantee continuous liquidity but may require more capital.
- User experience:
- AMMs: simple swaps, no need to think about order types.
- Order books: more control (limit orders, stop orders), familiar to traders.
- On-chain constraints:
- AMMs: fewer transactions (just swaps), simpler on-chain logic.
- Order books: many order updates/cancellations can be expensive on general-purpose L1s, so they often use L2s or app-chains.
Both models coexist in DeFi. As an undergraduate learner, you should recognize which type of DEX a protocol uses and how that affects fees, slippage, and UX.
5. Lending & Borrowing Protocols: Overcollateralized Loans
Now we move from trading to lending and borrowing.
5.1 What lending protocols do
Protocols like Aave, Compound, Spark, Morpho allow:
- Lenders to deposit assets into pools and earn interest.
- Borrowers to take loans against collateral they deposit.
- All logic is governed by smart contracts, not banks.
5.2 Overcollateralization
Because loans are largely pseudonymous (addresses, not real-world IDs), protocols manage risk via overcollateralization:
- You might need to deposit $150 worth of ETH to borrow $100 of USDC.
- This is expressed as a Loan-to-Value (LTV) ratio.
- Example: LTV = 70% → to borrow $70, you must deposit $100 of eligible collateral.
5.3 Liquidation
If the value of your collateral falls, your health factor may drop below a safe threshold.
- When your position becomes undercollateralized, liquidators can repay part of your debt and receive your collateral at a discount.
- This mechanism keeps the protocol solvent.
> Key risk insight: You can be liquidated even if you intend to repay, simply because of price movements. This is a central risk in DeFi borrowing.
5.4 Collateral types and risk parameters
Protocols define, for each asset:
- Collateral factor / LTV (how much you can borrow against it).
- Liquidation threshold (when liquidation is triggered).
- Liquidation bonus (discount given to liquidators).
- Reserve factor (portion of interest kept by the protocol/DAO).
These parameters are updated via governance (token-holder voting or multisig councils). In 2024–2025, many protocols tightened risk parameters after market volatility and some high-profile liquidations.
6. Quiz: Lending Basics
Check your understanding of overcollateralized lending.
You deposit $1,000 worth of ETH into a lending protocol where ETH has a maximum LTV of 70%. What is the **maximum** you can safely borrow in USDC before hitting the LTV limit (ignoring price changes and fees)?
- $500
- $700
- $1,000
- $1,300
Show Answer
Answer: B) $700
With a 70% LTV, you can borrow up to 70% of the collateral value. 70% of $1,000 is $700. Borrowing more than this would exceed the allowed LTV and put you at immediate risk of liquidation.
7. How On-Chain Interest Rates Are Determined
In DeFi lending, interest rates are algorithmic and update automatically based on utilization.
7.1 Utilization ratio
For a given asset (e.g., USDC):
- `Total deposits = D`
- `Total borrowed = B`
- Utilization `U = B / D`
7.2 Interest rate curves
Protocols define interest rate models (often piecewise linear):
- At low utilization (e.g., U < 50%):
- Borrow rate is relatively low.
- Lend rate is lower (borrow rate minus reserve factor).
- As utilization increases, borrow rates rise:
- Encourages more deposits (to earn higher yields).
- Discourages additional borrowing.
- Above a kink point (e.g., U > 80%):
- Borrow rates can rise sharply to prevent the pool from running out of liquidity.
7.3 Example (simplified)
Assume a USDC market with:
- `D = 10,000,000 USDC` deposited
- `B = 7,000,000 USDC` borrowed
- Utilization: `U = 70%`
Suppose the interest rate model says:
- For `U = 70%`, borrow rate = 6% APR.
- Protocol keeps 10% of interest as a reserve.
Then:
- Lenders earn ≈ 5.4% APR (because 90% of interest goes to them).
- Borrowers pay 6% APR.
> Observation: Rates are market-driven but encoded in smart contracts. If demand to borrow increases, utilization rises → rates increase automatically, without a central bank or credit officer.
8. Liquidity Provision & Impermanent Loss
Providing liquidity (LPing) is how users supply assets to AMMs and earn fees.
8.1 What LPs do
In a simple 50/50 ETH/USDC pool:
- You deposit equal value of both tokens, e.g.,
- 1 ETH at $2,000
- 2,000 USDC
- Total deposit value: $4,000.
- You receive LP tokens representing your share of the pool.
- You earn a share of trading fees (e.g., 0.3% of each swap) proportional to your share of the pool.
8.2 Impermanent loss (IL) intuition
If the price of ETH changes relative to USDC, the pool rebalances to maintain the AMM formula. This can make your position underperform simply holding the assets.
Scenario:
- Initial price: 1 ETH = 2,000 USDC.
- Later price: 1 ETH = 3,000 USDC.
If you had just held 1 ETH + 2,000 USDC:
- New value = 1 ETH ($3,000) + 2,000 USDC = $5,000.
As an LP, the pool automatically sold some ETH as its price rose, so you end up with less ETH and more USDC. Your LP position might be worth, say, $4,800 instead of $5,000.
- The $200 difference is called impermanent loss (relative to HODLing).
- It can be offset or exceeded by trading fees and other incentives.
> Key takeaway: LPing is not risk-free. You earn fees but take on price risk and impermanent loss. This is central to understanding DeFi yields.
9. Design a Simple Yield Strategy (Thought Exercise)
You have $1,000 in USDC and want to earn yield using DeFi primitives. Using what you’ve learned, sketch a simple, realistic strategy.
Constraints
- Use at least two different primitives (e.g., lending + AMM, or lending + staking).
- Avoid leverage for now (no borrowing to re-deposit).
- Focus on mechanics, not maximizing APY.
Example structure (fill in the blanks for yourself)
- Deposit USDC into a lending protocol (e.g., Aave) to earn base interest.
- Receive aUSDC (interest-bearing token) that grows in value over time.
- (Optional) Use aUSDC in another protocol that accepts it as collateral or LP asset.
- Track three risk dimensions:
- Smart contract risk (bugs, exploits).
- Market risk (USDC depeg, protocol-specific token price moves).
- Liquidity risk (can you withdraw when you want?).
Your task
Write a short plan (4–6 bullet points) answering:
- Which protocol(s) would you use for lending or LPing?
- What token(s) do you end up holding?
- Where does your yield come from (fees, interest, token incentives)?
- What is the main risk that would make you lose money?
Compare your plan to this pattern:
> Deposit stablecoins → receive interest-bearing tokens → optionally stake or LP them elsewhere → yield sources = interest + fees + incentives → risks = contract risk + depeg risk + protocol governance risk.
10. Yield Farming & Incentives
Yield farming refers to strategies that optimize returns by combining multiple protocols and incentives.
10.1 Common yield sources
- Trading fees from DEX liquidity pools.
- Borrow interest paid to lenders on lending protocols.
- Token incentives (liquidity mining):
- Protocols distribute their governance tokens (e.g., UNI, AAVE, CRV) to users who supply liquidity or borrow/lend.
- Restaking / reusing yield-bearing tokens:
- Example: deposit staked ETH (e.g., Lido’s stETH, Rocket Pool’s rETH) into lending or LP pools.
10.2 Example of a multi-step yield farm (conceptual)
- Stake ETH with a liquid staking protocol → receive staked ETH token (e.g., stETH).
- Deposit stETH into a lending protocol as collateral → earn staking yield + lending yield.
- Optionally borrow stablecoins against stETH and deposit those into another yield source (this introduces leverage and liquidation risk).
> In 2023–2025, such strategies became very common, especially around LSTs (Liquid Staking Tokens) and later LRTs (Liquid Restaking Tokens) after protocols like EigenLayer grew.
10.3 Risk layering
Each additional protocol layer adds:
- More smart contract risk.
- More governance/parameter risk.
- Potential correlated failures (e.g., if a widely used LST depegs, many strategies unwind simultaneously).
As yields rose in some periods (e.g., during liquidity mining campaigns), several high-profile incidents showed that chasing high APY without understanding risk can lead to losses. Your goal as a learner is to understand exactly where yield comes from and what risk compensates it.
11. Composability: “Money Legos” in Practice
DeFi protocols are designed to be composable: one protocol’s tokens and contracts can be used inside another. This is often called "money legos".
11.1 Simple composability chain
- Base asset: ETH on Ethereum.
- Liquid staking: Stake ETH → get stETH (a yield-bearing token).
- Lending protocol: Deposit stETH → get a-stETH (Aave’s interest-bearing token).
- DEX/LP: Provide a-stETH + another token as liquidity on a DEX.
- Yield aggregator: Deposit LP tokens into a vault that auto-compounds rewards.
At each step, you are stacking:
- New yield sources (staking rewards, borrow interest, trading fees, token incentives).
- New risks (contract bugs, oracle failures, governance attacks, liquidity crunches).
11.2 Composability risks (real-world context)
From 2020–2025, several incidents showed:
- Oracle manipulation could drain lending pools that accepted thinly traded tokens as collateral.
- Bridge hacks on cross-chain assets could break assumptions in multiple protocols that relied on those wrapped tokens.
- Governance attacks (e.g., borrowing governance tokens to pass malicious proposals) could change protocol parameters unexpectedly.
> Key concept: Composability is powerful but fragile. When you analyze any DeFi position, always ask:
> “What other protocols does this depend on, directly or indirectly?”
12. Flashcards: Core DeFi Primitives
Flip the cards to review key terms from this module.
- Automated Market Maker (AMM)
- A type of decentralized exchange that uses a liquidity pool and a pricing formula (e.g., x*y=k) instead of an order book to determine asset prices and enable trading.
- Liquidity Pool
- A smart contract that holds reserves of one or more tokens. Traders swap against the pool, and liquidity providers earn a share of trading fees proportional to their share of the pool.
- Liquidity Provider (LP)
- A user who deposits tokens into a liquidity pool on a DEX or other protocol, receiving LP tokens and earning fees (and sometimes token incentives) in return.
- Impermanent Loss
- The loss in value an LP experiences compared to simply holding the underlying tokens, caused by price changes between the assets in an AMM pool. It may be offset by trading fees.
- Overcollateralized Loan
- A loan where the borrower must deposit collateral worth more than the loan amount (e.g., $150 collateral for a $100 loan) to protect the protocol against default and price volatility.
- Utilization Ratio
- In a lending pool, the fraction of deposited assets that are currently borrowed: U = total borrowed / total supplied. It is a key input to on-chain interest rate models.
- Yield Farming
- The practice of maximizing returns by allocating capital across DeFi protocols to earn interest, trading fees, and token incentives, often by combining multiple primitives.
- Composability (Money Legos)
- The ability of DeFi protocols and tokens to be combined like building blocks, where the output of one protocol (e.g., a yield-bearing token) can be used as input in another.
- Liquid Staking Token (LST)
- A token representing staked assets (like staked ETH) that continues to earn staking rewards while remaining liquid and usable in other DeFi protocols.
- Order Book DEX
- A decentralized exchange that uses a traditional order book of bids and asks (often with off-chain matching and on-chain settlement) instead of an AMM pricing formula.
Key Terms
- Composability
- The property that allows DeFi protocols and tokens to interoperate and be combined, so that one protocol’s outputs can seamlessly become another’s inputs.
- Yield Farming
- Allocating and re-allocating capital across DeFi protocols to earn yield from interest, fees, and token incentives, often using complex multi-step strategies.
- Liquidity Pool
- A smart contract that holds reserves of tokens and facilitates trades, lending, or other operations. Users who deposit tokens into the pool are liquidity providers.
- Order Book DEX
- A decentralized exchange that maintains a list of buy and sell orders (order book) and matches them, often using off-chain infrastructure with on-chain settlement.
- Impermanent Loss
- The relative loss incurred by an LP compared to simply holding the underlying tokens, due to price divergence between assets in an AMM pool.
- Utilization Ratio
- The proportion of assets in a lending pool that are currently borrowed (borrowed / supplied). It influences algorithmic interest rates.
- Liquidity Provider (LP)
- A user who supplies assets to a liquidity pool and receives LP tokens plus a share of the fees or rewards generated by the pool.
- Overcollateralized Loan
- A loan where the borrower posts collateral worth more than the loan, commonly used in DeFi to manage credit risk without identity-based underwriting.
- Liquid Staking Token (LST)
- A token that represents staked assets (e.g., ETH) and accrues staking rewards while remaining transferable and usable in DeFi.
- Automated Market Maker (AMM)
- A DEX design where prices are set by a formula based on pool balances, rather than by matching buy and sell orders in an order book.