DeFi (Decentralized Finance) is a financial services ecosystem built on blockchain, implementing lending, trading, wealth management and other financial services through smart contracts without intermediaries.
DeFi vs Traditional Finance
shellTraditional Finance (CeFi) DeFi (Decentralized Finance) ┌──────────────┐ ┌──────────────┐ │ Banks │ │ Smart Contracts│ │ Exchanges │ → │ Auto-execution │ │ Brokers │ │ Permissionless │ └──────────────┘ └──────────────┘ ↓ ↓ Trust institutions Trust code High barriers, censored Open, transparent
| Feature | Traditional Finance | DeFi |
|---|---|---|
| Entry Barrier | Identity verification required | Permissionless, wallet only |
| Operating Hours | Weekdays 9-17 | 7×24 hours |
| Transparency | Opaque | Fully on-chain transparent |
| Control | Institution controlled | User self-custody |
| Yield | Lower (0.5-3%) | Higher (5-20%+) |
| Risk | Institution credit risk | Smart contract risk |
DeFi Core Protocol Types
shellDeFi Ecosystem ├── DEX (Decentralized Exchanges) │ ├── AMM (Automated Market Maker) │ └── Order Book Model ├── Lending Protocols │ ├── Over-collateralized Lending │ └── Flash Loans ├── Stablecoins │ ├── Collateralized (DAI) │ └── Algorithmic (UST) ├── Derivatives │ ├── Perpetual Contracts │ └── Options └── Yield Aggregators └── Liquidity Mining
1. DEX (Decentralized Exchanges)
AMM (Automated Market Maker) Mechanism
Traditional Order Book vs AMM:
shellOrder Book Model: AMM Model: Buy Orders Sell Orders Liquidity Pool ┌──────┐ ┌──────┐ ┌─────────────┐ │ 100 │ │ 102 │ │ ETH │ USDC │ │ 99 │ │ 103 │ │ 100 │ 200K │ │ 98 │ │ 104 │ └─────────────┘ └──────┘ └──────┘ ↑ Needs counterparty Trade with pool
Constant Product Formula (Uniswap):
shellx × y = k Where: x = Token A amount y = Token B amount k = Constant (when liquidity unchanged) Example: Pool: 100 ETH + 200,000 USDC k = 100 × 200,000 = 20,000,000 How much USDC for 1 ETH? (100 + 1) × (200,000 - Δy) = 20,000,000 Δy ≈ 1,980 USDC
Impermanent Loss
shellRisk for liquidity providers: Initial: Deposit 1 ETH + 2000 USDC (ETH price $2000) Scenario 1: ETH rises to $4000 - Without providing liquidity: 1 ETH × $4000 + 2000 USDC = $6000 - After providing liquidity: Pool auto-balances √k = √(0.707 × 2828) ≈ $5656 - Impermanent Loss: $6000 - $5656 = $344 (5.7%)
2. Lending Protocols
Over-collateralized Lending
Aave/Compound Mechanism:
shellDeposit Process: Borrow Process: ┌─────────┐ ┌─────────┐ │Deposit │ │Collateral│ │ ETH │ │ ETH │ │Receive │ │Borrow │ │ aETH │ │ USDC │ │Earn │ │ │ │interest │ │LTV: 75% │ └─────────┘ │ │ │Interest │ │Model: │ │ • Util↑ │ │ • Rate↑ │ └─────────┘
Key Parameters:
- Collateral Factor: 75% (can borrow up to 75% of collateral value)
- Liquidation Threshold: 80%
- Health Factor: Triggers liquidation when < 1
Flash Loans
Principle: Borrow and repay within one block, no collateral needed.
shellFlash Loan Process: 1. Borrow 1000 ETH (no collateral) ↓ 2. Buy tokens on DEX A (undervalued) ↓ 3. Sell tokens on DEX B (overvalued) ↓ 4. Repay 1000 ETH + 0.09% fee ↓ 5. Arbitrage profit stays in contract ⚠️ All operations must complete in one atomic transaction
Use Cases:
- Arbitrage
- Collateral swapping
- Self-liquidation
3. Stablecoins
Type Comparison
| Type | Mechanism | Representative | Pros | Cons |
|---|---|---|---|---|
| Fiat-backed | 1:1 USD reserve | USDT, USDC | Price stable | Centralized |
| Crypto-backed | Over-collateralized crypto | DAI | Decentralized | Capital inefficient |
| Algorithmic | Algorithm adjusts supply/demand | UST (collapsed) | Capital efficient | Death spiral risk |
DAI Mechanism
shellDAI Generation Process: 1. Deposit 150 ETH (value $300,000) ↓ 2. Mint 100,000 DAI (150% collateral ratio) ↓ 3. Use DAI for trading/investment ↓ 4. Return 100,000 DAI + stability fee ↓ 5. Retrieve collateralized ETH Liquidation Mechanism: - Collateral ratio < 150%: Trigger liquidation - Keeper auctions collateral - Repay DAI debt
4. Liquidity Mining (Yield Farming)
Principle
Earn token rewards by providing liquidity.
shellLiquidity Mining Process: 1. Provide Liquidity ETH + USDC → Uniswap Pool ↓ 2. Receive LP Token ↓ 3. Stake LP Token to Farm Contract ↓ 4. Receive Rewards • Trading fees (0.3%) • Platform tokens (UNI, SUSHI)
Yield Calculation
shellAPY (Annual Percentage Yield) Calculation: Basic Formula: APY = (1 + r/n)^n - 1 Where: r = Period yield n = Compounding times per year Example: Daily yield 0.1%, compounding APY = (1 + 0.001)^365 - 1 ≈ 44% ⚠️ Note: APY fluctuates with price, not guaranteed
Risks
- Impermanent Loss: Price fluctuation causes LP loss
- Smart Contract Risk: Contract vulnerabilities exploited
- IL + Mining Rewards < 0: Token price crash
- Rug Pull: Project team runs away with funds
5. DeFi Composability
Lego Effect:
shellYield Maximization Strategy Example: 1. Deposit ETH in Aave receive aETH ↓ 2. Use aETH as collateral to borrow USDC on Compound ↓ 3. Provide USDC liquidity on Curve receive CRV ↓ 4. Stake CRV receive veCRV governance rights ↓ 5. Vote on pool reward allocation Risk: More combinations = More risk (risk contagion)
Interview Key Points
- Understand AMM constant product formula
- Master impermanent loss calculation and impact
- Understand over-collateralized lending liquidation mechanism
- Understand flash loan principles and use cases
- Familiar with pros and cons of different stablecoin types
- Master liquidity mining yield calculation
- Understand risks of DeFi composability
- Able to analyze DeFi protocol economic models