Learning Objectives:

  • Master yield farming mechanics and strategies

  • Understand liquidity mining economics and token incentives

  • Learn yield optimization and compounding strategies

  • Analyze farming risks, APY calculations, and real-world examples

5.5.1: What is Yield Farming? – The Complete Picture

Definition and Core Concept

Yield farming is the practice of generating returns by strategically moving assets between DeFi protocols to maximize yield. It’s essentially “interest farming” where users deploy capital to earn rewards from protocols.

text
Yield Farming Definition:

Yield Farming = Earning yield + Farming protocol tokens

┌─────────────────────────────────────────────────────────────────────┐
│                    Yield Farming Components                        │
│                                                                   │
│  Step 1: Deposit Assets                                          │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  User deposits ETH, USDC, or other tokens                  │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                    │
│  Step 2: Earn Base Yield                                         │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  • Lending interest (Aave: 3-5% APY)                      │   │
│  │  • Trading fees (Uniswap: 0.3% per trade)                │   │
│  │  • Staking rewards (Lido: 4-6% APR)                      │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                    │
│  Step 3: Earn Bonus Rewards                                      │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  • Liquidity mining tokens (UNI, CRV, etc.)              │   │
│  │  • Governance tokens                                     │   │
│  │  • Protocol incentives                                   │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                    │
│  Step 4: Compound or Harvest                                    │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  • Reinvest rewards (auto-compounding)                    │   │
│  │  • Sell rewards for stablecoins                          │   │
│  │  • Move to next farm                                    │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                                                                   │
│  Total Yield = Base Yield + Bonus Rewards + Compounding         │
└─────────────────────────────────────────────────────────────────────┘

Why Yield Farming Exists:

The concept emerged from the need to incentivize liquidity providers and bootstrap DeFi protocols.

text
The Incentive Problem:

"Chicken and Egg" Problem:
- Protocols need liquidity to function
- Users won't provide liquidity without incentives
- Protocols distribute tokens to attract liquidity

Solution: Liquidity Mining
- Protocol distributes native tokens
- Users provide liquidity and earn tokens
- Win-win: Protocol gets liquidity, users get rewards

Historical Context:
- First major farm: Compound (June 2020)
- "DeFi Summer" 2020: Explosion of yield farming
- Yearn Vaults: Automated yield optimization
- Yields reached 1000%+ APY (early days)

5.5.2: Liquidity Mining – The Economic Engine

How Liquidity Mining Works:

Liquidity mining is a specific type of yield farming where protocols distribute native tokens to users who provide liquidity.

text
Liquidity Mining Mechanics:

1. User Provides Liquidity:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Deposits token pair (ETH/USDC) to Uniswap              │
   │  • Receives LP tokens (liquidity provider tokens)         │
   │  • Stakes LP tokens in farm                               │
   └─────────────────────────────────────────────────────────────┘

2. Protocol Distributes Rewards:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Rewards allocated per block                            │
   │  • Distributed proportionally to stake                    │
   │  • Example: 100 UNI rewards per block                    │
   └─────────────────────────────────────────────────────────────┘

3. User Earns Rewards:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Earns trading fees (base yield)                       │
   │  • Earns UNI tokens (bonus rewards)                      │
   │  • Total APR = 30-100%+                                  │
   └─────────────────────────────────────────────────────────────┘

Reward Distribution Mathematics:

text
Reward Calculation:

User_Reward = (User_Stake / Total_Stake) × Total_Rewards

Example:
- User Stake: 100,000 USDC
- Total Stake: 10,000,000 USDC
- Total Rewards: 1,000 UNI/day

User_Reward = (100,000 / 10,000,000) × 1,000 = 10 UNI/day

Value of Reward:
- UNI Price: $10
- Daily Reward: $100
- Annual Reward: $36,500
- APR: (36,500 / 100,000) × 100 = 36.5%

Additional Yield:
- Trading Fees: 0.3% × Volume
- Fee APR: 10-20% depending on volume
- Total APR: 46.5-56.5%

Token Emission Schedules:

text
Emission Types:

1. Linear Emissions:
   ┌─────────────────────────────────────────────────────────────┐
   │  Fixed number of tokens per block                         │
   │  Example: 100 UNI per block                              │
   │  Total supply increases linearly                          │
   │  Inflation rate decreases over time                      │
   └─────────────────────────────────────────────────────────────┘

2. Halving Emissions:
   ┌─────────────────────────────────────────────────────────────┐
   │  Rewards halve at set intervals                           │
   │  Example: 50% reduction every 4 years                    │
   │  Similar to Bitcoin halving                               │
   └─────────────────────────────────────────────────────────────┘

3. Dynamic Emissions:
   ┌─────────────────────────────────────────────────────────────┐
   │  Rewards adjust based on metrics                         │
   │  Example: Based on TVL, volume, or utilization           │
   │  More responsive to protocol needs                       │
   └─────────────────────────────────────────────────────────────┘

4. Time-Locked Emissions:
   ┌─────────────────────────────────────────────────────────────┐
   │  Rewards vest over time                                   │
   │  Example: 25% unlocked, 75% vesting                      │
   │  Reduces sell pressure                                    │
   └─────────────────────────────────────────────────────────────┘

5.5.3: Types of Yield Farming Strategies

Strategy 1: Single Asset Staking

text
Single Asset Staking:

Description:
- Deposit one asset only
- Earn rewards in native token
- Lower risk (no impermanent loss)

Examples:
1. Stake ETH on Lido → earn stETH
2. Stake USDC on Aave → earn aUSDC
3. Stake UNI on Uniswap → earn UNI

APR: 3-15% (lower than LP farming)

Pros:
- No impermanent loss
- Simpler to manage
- Lower risk

Cons:
- Lower yield
- Limited upside
- Less flexible

Strategy 2: Liquidity Pool (LP) Farming

text
LP Farming:

Description:
- Provide liquidity to DEX pool
- Earn trading fees + protocol rewards
- Higher risk (impermanent loss)

Examples:
1. ETH/USDC on Uniswap → earn UNI
2. USDC/DAI on Curve → earn CRV
3. WBTC/ETH on Balancer → earn BAL

APR: 20-100%+ (higher than staking)

Pros:
- Higher yield potential
- Multiple rewards sources
- Contributes to protocol

Cons:
- Impermanent loss risk
- More complex
- Higher gas costs

Strategy 3: Yield Aggregation (Vaults)

text
Yield Aggregation (Vaults):

Description:
- Automated yield strategies
- Auto-compounding
- Professional management

Examples:
1. Yearn Vaults: yvUSDC, yvETH
2. Convex: vlCVX, cvxCRV
3. Beefy: Auto-compounding LPs

APR: Varies (25-50%+)

Pros:
- Hands-off approach
- Auto-compounding
- Professional strategy

Cons:
- Higher fees (10-20% performance)
- Less control
- Smart contract risk

Strategy 4: Leveraged Farming

text
Leveraged Farming:

Description:
- Borrow assets to amplify position
- Higher returns, higher risk
- Requires margin

Example:
1. Deposit 100 ETH
2. Borrow 100 ETH on Aave
3. Deposit 200 ETH in farm
4. 2× leverage on yields

APR: Leveraged APR (50-200%+)

Pros:
- Amplified returns
- Capital efficiency
- Higher yields

Cons:
- Liquidation risk
- Higher complexity
- Higher fees
- More gas costs

Strategy 5: Arbitrage Farming

text
Arbitrage Farming:

Description:
- Profit from price differences
- Low risk if done correctly
- Requires speed and efficiency

Examples:
1. DEX arbitrage: Buy low, sell high
2. Yield arbitrage: Farm higher yield
3. Flash loan arbitrage: Zero capital

APR: Variable (10-50%+)

Pros:
- Lower risk
- Consistent returns
- Market-making profit

Cons:
- Requires capital
- Competitive (bots)
- Complexity

5.5.4: Impermanent Loss – Complete Explanation

What is Impermanent Loss?

Impermanent loss is the temporary loss experienced by liquidity providers when the price ratio of deposited tokens changes.

text
Impermanent Loss - The Math:

Initial Deposit:
- Token A: 100 tokens
- Token B: 200 tokens
- Price: 1 Token A = 2 Token B

Pool Value: 100 × 2 = 200 (in terms of Token B)

After Price Change (Token A doubles to 4 Token B):
- Pool must rebalance to maintain k
- New Reserve: 70.71 Token A + 282.84 Token B
- Value: 70.71 × 4 + 282.84 = 565.68

If You Had HODL:
- Token A: 100 × 4 + 200 = 600

Impermanent Loss = 600 - 565.68 = 34.32 (5.72%)

IL by Price Change:

text
Impermanent Loss Table:

Price Change   |   Impermanent Loss
1.25x          |   0.6%
1.5x           |   2.0%
2x             |   5.7%
3x             |   13.4%
4x             |   20.0%
5x             |   25.5%
10x            |   42.5%

Formula:
IL = 2 × √r / (1 + r) - 1

Where r = New_Price / Old_Price

Example (r=2):
IL = 2 × √2 / (1 + 2) - 1
IL = 2 × 1.414 / 3 - 1
IL = 2.828 / 3 - 1
IL = 0.9427 - 1 = -5.73%

When Impermanent Loss is Permanent:

text
IL Becomes Permanent When:

1. Withdrawing:
   - IL realized at withdrawal
   - If prices haven't returned
   - Loss is locked in

2. Price Changes:
   - If price changes permanently
   - IL becomes permanent
   - Can't recover

3. Pair Divergence:
   - Assets diverge significantly
   - IL grows larger
   - May never recover

Mitigation:
- Choose stable pairs (USDC/DAI)
- Monitor prices
- Use impermanent loss insurance
- Diversify pools

5.5.5: Yield Aggregators – Yearn Finance Deep-Dive

Yearn Architecture:

text
Yearn Finance Structure:

┌─────────────────────────────────────────────────────────────────────┐
│                    Yearn Finance                                   │
│                                                                   │
│  Depositors:                                                      │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  Users deposit assets into vaults                         │   │
│  │  Receive yTokens (yvUSDC, yvETH, etc.)                    │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                    │
│  Vaults:                                                         │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  • Automated strategies                                    │   │
│  │  • Multiple yield sources                                  │   │
│  │  • Auto-compounding                                       │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                    │
│  Strategies:                                                     │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  1. Lend on Aave/Compound                                 │   │
│  │  2. Provide liquidity on Curve                            │   │
│  │  3. Stake on Convex                                       │   │
│  │  4. Flash loan arbitrage                                  │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                    │
│  Rewards:                                                        │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  • yTokens appreciate                                      │   │
│  │  • Performance fee: 10-20%                                │   │
│  │  • Depositors earn returns                                │   │
│  └─────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────┘

Yearn Vault Math:

text
Vault Economics:

Share Price = Total_Assets / Total_Shares

Example:
- Total Assets: $1,000,000
- Total Shares: 1,000,000
- Share Price: $1.00

After Yield:
- Total Assets: $1,100,000
- Total Shares: 1,000,000 (unchanged)
- Share Price: $1.10

User Deposit: $10,000
Shares Received = 10,000 / $1.00 = 10,000 shares

After Yield (1 year):
- Share Price: $1.10
- User Value: 10,000 × $1.10 = $11,000
- Return: 10%

Compound Effect:
- Daily yield: 0.026%
- Daily compounding
- APY: 10.5% (vs 10% simple)

5.5.6: APY vs APR – Understanding the Difference

The Math Behind Returns:

text
APR (Annual Percentage Rate):
Simple interest without compounding

APY (Annual Percentage Yield):
Interest with compounding

Formula:
APY = (1 + APR/n)^n - 1

Where n = Number of compounding periods

Example:
APR = 10%
Daily Compounding (n=365):
APY = (1 + 0.10/365)^365 - 1
APY = (1.00027397)^365 - 1
APY = 1.1051 - 1 = 10.51%

Monthly Compounding (n=12):
APY = (1 + 0.10/12)^12 - 1
APY = (1.00833)^12 - 1
APY = 1.1047 - 1 = 10.47%

Important:
- DeFi often quotes APY (compounding included)
- Traditional finance often quotes APR (simple interest)
- Always check compounding frequency

5.5.7: Yield Farming Risks – Complete Analysis

Risk Matrix:

 
 
Risk Severity Description Mitigation
Impermanent Loss Medium Loss from price divergence Choose stable pairs
Smart Contract Risk High Protocol bugs or hacks Audits, diversification
Rug Pulls High Malicious exit scam Verify contracts
APY Volatility Low Variable returns Monitor regularly
Liquidity Risk Medium Cannot withdraw Check pool depth
Gas Costs Low High transaction fees Optimize timing
Slippage Low Price impact Use slippage limits
Front-Running Medium MEV exploits Use privacy options

Detailed Risk Analysis:

text
1. Smart Contract Risk:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Protocol bug exploited                                 │
   │  • Funds drained                                          │
   │  • Historical: $1B+ lost to hacks                        │
   │  • Mitigation: Only use audited protocols                │
   └─────────────────────────────────────────────────────────────┘

2. Impermanent Loss:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Loss from price changes                                │
   │  • Can be 0.6-42.5%+                                     │
   │  • Worse with volatile pairs                             │
   │  • Mitigation: Use stable pairs or short duration        │
   └─────────────────────────────────────────────────────────────┘

3. APY Volatility:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Yields can drop rapidly                                │
   │  • From 100% to 10% overnight                           │
   │  • Dependent on TVL and volume                           │
   │  • Mitigation: Monitor regularly                        │
   └─────────────────────────────────────────────────────────────┘

4. Token Price Risk:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Farm token value drops                                 │
   │  • Rewards worth less                                     │
   │  • Can cause IL                                           │
   │  • Mitigation: Sell rewards for stablecoins              │
   └─────────────────────────────────────────────────────────────┘

5.5.8: Historical Yield Farming Examples

DeFi Summer 2020 – The Beginning:

text
Compound Liquidity Mining (June 2020):

- Launch: COMP token distribution
- Market: $10M TVL → $100M+
- APY: 100-500%+ in early days
- Impact: Sparked DeFi explosion

Yearn Finance Growth (2020-2021):

- Launch: yVaults
- TVL: $0 → $5B+ in months
- APY: 50-200%+
- Impact: Yield optimization popularized

Curve Wars (2021):

- Launch: CRV token
- Economics: 59% emissions to LPs
- Strategy: veCRV voting
- Impact: Fee wars and yield optimization

Real-World Yield Farming Calculation:

text
Example: Curve USDC-DAI Farm

Pool: USDC-DAI (Stablecoin)
TVL: $100M
Volume: $50M/day
Trading Fee: 0.04% (LP share)
CRV Rewards: 5,000 CRV/day

Base Yield (Trading Fees):
Daily Fees = $50M × 0.04% = $20,000
Fee APR = ($20,000 × 365) / $100M = 7.3%

Bonus Yield (CRV Rewards):
CRV Price: $0.50
Daily CRV Value = 5,000 × $0.50 = $2,500
CRV APR = ($2,500 × 365) / $100M = 0.9%

Total APR = 7.3% + 0.9% = 8.2%
APY (with compounding) = 8.5%

5.5.9: Popular Yield Farming Platforms

Major Platforms:

 
 
Platform Focus TVL APY Range Key Features
Yearn Aggregator $5B+ 5-50% Auto-compounding
Convex Curve + CRV $4B+ 10-50% CRV boosting
Aave Lending $10B+ 2-15% aTokens
Uniswap DEX $6B+ 10-100% LP tokens
Curve Stable DEX $4B+ 5-30% Low slippage
Lido Staking $30B+ 3-6% stETH

How to Evaluate a Farm:

text
Evaluation Checklist:

☐ Protocol Audits:
   ☐ Multiple audits done
   ☐ Reputable firms
   ☐ No critical issues

☐ Smart Contract:
   ☐ Verified on Etherscan
   ☐ Open source
   ☐ Well-documented

☐ Liquidity:
   ☐ Sufficient depth
   ☐ Low slippage
   ☐ High volume

☐ Tokenomics:
   ☐ Fair distribution
   ☐ Reasonable vesting
   ☐ Utility beyond farming

☐ APY:
   ☐ Sustainable (30-100%)
   ☐ Not too high (risk of scam)
   ☐ Verified real yield

☐ Risks:
   ☐ IL acceptable
   ☐ Volatility acceptable
   ☐ Gas costs reasonable

☐ Community:
   ☐ Active development
   ☐ Engaged community
   ☐ Good reputation

5.5.10: Current State of Yield Farming (2024)

Market Evolution:

text
Yield Farming Trends:

1. Yields Have Normalized:
   ┌─────────────────────────────────────────────────────────────┐
   │  • 2020: 100-1000% APY                                   │
   │  • 2022: 10-50% APY                                     │
   │  • 2024: 5-30% APY                                      │
   │  • More sustainable yields                              │
   └─────────────────────────────────────────────────────────────┘

2. Shift to Real Yield:
   ┌─────────────────────────────────────────────────────────────┐
   │  • Protocol revenue (fees)                               │
   │  • Sustainable returns                                   │
   │  • Less inflationary                                     │
   └─────────────────────────────────────────────────────────────┘

3. Focus on LSTs (Liquid Staking Tokens):
   ┌─────────────────────────────────────────────────────────────┐
   │  • stETH, rETH, cbETH                                   │
   │  • 4-6% base yield                                      │
   │  • Plus DeFi yields                                     │
   │  • Combined yield: 10-20%                              │
   └─────────────────────────────────────────────────────────────┘

4. Restaking (EigenLayer):
   ┌─────────────────────────────────────────────────────────────┐
   │  • Additional yield on staked ETH                       │
   │  • Shared security                                      │
   │  • New yield source                                     │
   └─────────────────────────────────────────────────────────────┘

1. Yield Farming Math – Complete Formulas

 
APR to APY Conversion:
APY = (1 + APR/n)^n - 1

APR = (APY + 1)^(1/n) × n - 1

Compound Interest:
A = P × (1 + r/n)^(n × t)

Where:
- A = Final amount
- P = Principal
- r = Annual interest rate
- n = Compounding frequency
- t = Time in years

Continuous Compounding:
A = P × e^(r × t)

Daily Compounding Example:
P = $10,000
r = 20%
t = 1 year

A = 10,000 × (1 + 0.20/365)^365
A = 10,000 × 1.2213
A = $12,213

2. Advanced Farming Strategy

text
Multi-Step Farming Example:

Initial Position:
- ETH: 10 ETH ($30,000)
- USDC: $30,000

Step 1: Provide LP
- Deposit in ETH/USDC Uniswap pool
- Earn trading fees + UNI rewards

Step 2: Stake LP Tokens
- Stake LP tokens in farm
- Earn additional rewards

Step 3: Lend Rewards
- Lend earned tokens
- Earn interest on rewards

Step 4: Reinvest
- Compound yields
- Increase position

Total Yield:
- LP Fees: 15% APY
- UNI Rewards: 20% APY
- Interest on Rewards: 5% APY
- Total: 40%+ APY (with compounding)

  •