The Physics of Yield Farming: Leverage & Loops

How to turn $1 into $10 of TVL. Recursive Lending (Looping), Risk Stacking, and the dangerous physics of 'Money Legos'.

Beginner 45 min read Expert Version →

🎯 What You'll Learn

  • Deconstruct Recursive Lending (The Folding Strategy)
  • Analyze Risk Stacking ($Risk_{total} = \prod Risk_i$)
  • Trace a Transaction through the 'Money Lego' stack
  • Calculate Impermanent Loss ($IL = 2 \\sqrt{P} / (1+P) - 1$)
  • Simulate a Liquidation Cascade

Introduction

Yield Farming is rarely about “Planting seeds and waiting.” It is usually about Financial Engineering.

The highest yields come from Leverage. By depositing Collateral, borrowing against it, and depositing again, you can multiply your exposure (and your yield) by 5x or 10x. But Leverage cuts both ways. One price dip, and the “Farmer” gets liquidated.

This lesson analyzes the physics of Recursive Yield.


The Physics: Recursive Lending (Looping)

How do you get 20% APY on a stablecoin that pays 4%? You Loop It.

The Algorithm:

  1. Deposit $100 USDC (Earn 4%).
  2. Borrow $80 DAI (Pay 2%).
  3. Swap DAI -> USDC.
  4. Deposit $80 USDC (Earn 4%).
  5. Repeat until LTV limit (Limit=11LTVLimit = \frac{1}{1 - LTV}).

The Math: If LTV is 80% (0.8), the Multiplier is 110.8=5x\frac{1}{1-0.8} = 5x.

  • Total Deposit: $500.
  • Total Borrow: $400.
  • Net Equity: $100.
  • Net Yield: (500×4%)(400×2%)=208=12%(500 \times 4\%) - (400 \times 2\%) = 20 - 8 = 12\%.
  • Result: You turned 4% into 12% (3x Boost).

Deep Dive: Money Legos (Stacking Risk)

DeFi is composable. This allows for Risk Stacking.

The Stack:

  1. Layer 1: Ethereum Blockchain.
  2. Layer 2: Curve Pool (USDC/DAI/USDT). Risk: Stablecoin De-peg.
  3. Layer 3: Convex Finance (Stakes Curve LP tokens). Risk: Convex Contract Bug.
  4. Layer 4: Liquid Wrapper (badgerWBTC). Risk: Bridge Hack.

Physics of Failure: If any layer breaks, the entire stack collapses. P(Survival)=P(L1)×P(L2)×P(L3)×P(L4)P(\text{Survival}) = P(L1) \times P(L2) \times P(L3) \times P(L4). If each layer is 99% safe, the stack is only 0.994=96%0.99^4 = 96\% safe.


Strategy: Delta Neutral Farming

How to farm volatile tokens without price risk.

The Setup:

  1. Spot Long: Buy $1000 ETH.
  2. Perp Short: Short $1000 ETH (1x Leverage).
  3. Net Exposure: $0. (Price moves don’t affect you).

The Yield:

  • Funding Rates: If Shorts are paid by Longs.
  • Liquidity Mining: Stake the Spot ETH in a pool.
  • Result: Pure Yield with near-zero Price Risk.

Code: Calculating Net APY (Looping)

def calculate_loop_yield(principal, supply_apy, borrow_apy, ltv):
    # Geometric Series Sum: a / (1 - r)
    # Total Supplied = principal / (1 - ltv)
    total_supplied = principal / (1.0 - ltv)
    total_borrowed = total_supplied - principal
    
    gross_yield = total_supplied * supply_apy
    borrow_cost = total_borrowed * borrow_apy
    
    net_profit = gross_yield - borrow_cost
    net_apy = net_profit / principal
    
    leverage_ratio = total_supplied / principal
    
    return {
        "net_apy": net_apy,
        "leverage": leverage_ratio,
        "liquidation_risk": "High" if ltv > 0.75 else "Medium"
    }

# Example:
# Supply 4%, Borrow 2%, LTV 80%
# Leverage 5x.
# Net APY = (5 * 0.04) - (4 * 0.02) = 0.20 - 0.08 = 12%

Practice Exercises

Exercise 1: The Loop (Beginner)

Scenario: Supply APY 10%. Borrow APY 12%. Task: Should you loop? (Answer: No! You lose 2% on every loop. Leverage multiplies losses too).

Exercise 2: Liquidation Point (Intermediate)

Scenario: You have 5x Leverage on ETH. Task: How much does ETH need to drop for you to be liquidated? (Hint: At 5x, a 20% drop wipes out your equity. Liquidation threshold might be even higher, e.g., 15%).

Exercise 3: Peg Risk (Advanced)

Scenario: You are looping USDT/USDC. Event: USDT de-pegs to 0.90.Task:WhathappenstoyourUSDCloan?(Itstaysat0.90. **Task:** What happens to your USDC loan? (It stays at 1.00. You are underwater. You get liquidated).


Knowledge Check

  1. What is the maximum theoretical leverage with 90% LTV?
  2. Why is Delta Neutral farming safer than simple LPing?
  3. What is “Composability Risk”?
  4. How does “Folding” increase yield?
  5. What happens to borrowers when APY spikes?
Answers
  1. 10x. Formula: 110.9=10\frac{1}{1-0.9} = 10.
  2. No Price Risk. You are hedged against market movements.
  3. Dependencies. If one protocol in the stack fails, your assets are lost.
  4. Multiplier. You earn yield on borrowed money, which earns yield on borrowed money…
  5. Squeeze. Borrow costs exceed supply earnings. Loop becomes unprofitable.

Summary

  • Yield: Is created by Leverage.
  • Risk: Multiplies with every layer.
  • Math: Defines the liquidation horizon.

Questions about this lesson? Working on related infrastructure?

Let's discuss