1/37
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Defi Characteristics
Smart Contract Foundation - services executed by transparent auditable code rather than centralized institutions
Open Access - anyone can access through interest
Always Available - protocols operate continuously (unlike regular banks with banking hours, holidays, or geographic restrictions)
FTX
Collapsed in November 2022
$8 billion lost
opaque accounting and centralized control
users locked out
Defi Protocols
all transactions visible on-chain
users maintain full control over assets
zero downtime or fund freezes
cryptographic certainty instead of institutional trust
all transactions, collateral ratios, and protocol balances are publicly auditable in real-time
can only lend to anon using only on-chain verifiable assets
Centralized Exchanges
function as black boxes
users must trust management with custody of funds
Composability
all DeFi protocols can be combined to create sophiscated financial products
permissionless composability, so innovation does not require approval from any central authority
Main Protocols: stablecoins, AMMs, lending, perpetuals, governance
Example: acquire stablecoins, supply stablecoins to lending pool and receive interest-bearing tokens, use tokens as collateral to borrow and trade on Uniswap or GMX (tokens still earn yield)
Volatility Problem
native cryptos (ETH, BTC) experience dramatic price swings
unsuitable for predictable loan payments, merchant payment processing, denominating financial contracts (stating what currency to use in contract)
Stablecoin Solution
digital cash pegged to fiat currencies (typically USD) or crypto or algorithm
price anchor (stable reference for defi protocols)
safe haven (preserves value during crypto crashes)
programmable (smart contracts and blockchain capabilities)
enables other DeFi primitives
Fiat-Backed
backed by cash (typically USD) or short term U.S. treasury securities (loans to government) held in traditional bank accounts
1:1 to fiat
subject to off-chain aduitors
examples: USDC (Circle), USDT
risk: requires trusting centralized entity with reserves, issuers can freeze addresses and block transactions, subject to government intervention and compliance requirements
if price below $1, buy cheap tokens and redeem for USDC, demand increases → price rises
if price above $1, mint new tokens and sell them, supply increases → price drops
Crypto-Collaterized
over-collateralized with crypto assets
up to 150% ratio ($150 ETH backs $100 DAI)
if collateral value drops below threshold, automatically liquidate collateral
user returns stablecoin plus stability fee to reclaim collateral
all data on-chain
example: DAI (MakerDAO)
if above $1, mint more DAI by opening more vaults or swap USDC for DAI to increase supply
if below $1, repay loans (burn DAI) and retrieve collateral or swap DAI for USDC to reduce supply
pros: more transparent, more decentralized, and more censorship resisitant than fiat-backed
cons: more complex than fiat-backed, capital-inefficient, code vulnerabilities could drain collateral, heavy reliance on USDC for Peg Stability Module (PSM) so not that decentralized, liquidation can cascade
Algorithmic
incentive mechanism adjusts supply based on demand
mint/burn relationship with governance token (LUNA for UST)
example: UST (Terra) → failed
risk: death spiral if market confidence breaks (mass withdrawal)
if above $1, burn token to mint stablecoin
if below $1, burn stablecoin to mint token
Traditional Order Books
requires matching buyers to sellers
constant order placement and cancellation
high frequency updates
high gas costs
AMM Solution
liquidity always available
no need to match orders
algorithmic pricing
single transaction
passive liquid provision
AMMs
pool holds reserves of two tokens
liquidity providers deposit both in proportion to current price
invariant ensures some formula of reserves stays constant (sum, product, etc.)
price adjusts to maintain constant product
always available, no operator needed
example: Uniswap (general purpose), Balancer (multi-asset pools), Curve (stablecoin-optimized)
Over-Collateralized Lending
lock up collateral more than loan value
if collateral price drops, collateral ratio drops (less for collateral)
borrow to maintain ETH exposure while accessing liquidity, anonymous, tax efficient
global, permissionless access to liquidity without personal info or delays
automatic liquidation if collateral drops below threshold
less capital efficient than traditional loans
Lending in Action
lenders deposit liquidity into protocol and receive interest-bearing tokens
lock collateral and borrow against it (interest goes to lenders)
interest rates adjust based on utilization (high demand leads to higher rates which lead to more lenders)
borrowers repay principal plus interest to unlock collateral
Perps
no expiration (can hold positions indefinitely)
long positions (rise) and short positions (fall)
periodic payments between longs and short to keep price anchored to spot price
example platforms: dYdX (order book-based), GMX (pool-based leverage), Hyperliquid (high-performance L1=low latency)
Purpose of Perps
offset spot holdings with short positions
express market views with leverage
arbitrage funding rates and spot prices (exploit difference in price)
gain exposure without holding underlying assets
Governance via DAOs
create proposals for protocol changes (fee adjustments, parameter updates, treasury spending, or code upgrades)
governance token holders votes on-chain (voting power proportional to token holdings)
changes execute automatically when passed
maximal transparency
Maximal Extractable Value (MEV)
reorder, insert, or censor transactions to extract additional profit
example: user buys ETH, bot detects pending transaction, bot buys before transaction, bot sells post transaction, bot profits from price movement
DeFi Stack
stablecoins, AMMs, lending, perps, governance
each entry builds on primitives before it
Peg Stability Module (PSM)
DAI price stabilized through 1:1 swaps with USDC
DAI also backed by U.S. treasury bonds
45% backed by USDC, 30% backed by bonds, 25% backed by crypto
Hybrid Approaches for Stablecoin
backed by real-world assets and crypto collateral
integrated with fiat
community control through DAO governance
transparent with regular audits and proof-of-reserves
Constant-Sum Market Maker (CSMM)
linear invariant
x + y = k, delta x = delta y
1:1 exchange
vulnerable to arbitrage
unable to react to external market price changes (if market price shift to not 1 Y per 1 X, arbitrageurs can exploit)
one token can get completely drained
unsafe in practice (not used in real-life)
1mil USDC → 1mil DAI (1.0000 price, 0% price impact)
Constant-Product Market Maker (CPMM)
hyperbolic invariant
x y = k, delta y = (delta x * y)/(x + delta x)
trades cause slippage
larger trades causes more deviations between prices
when pool prices deviate from external markets, arbitrage trades profit until pool’s ratio aligns with global market
slippage prevents pool drainage
used for crypto since no assumption of fixed ratio
1mil USDC → 980392 DAI (0.9804 price, 1.96% price drop)
Slippage
difference between average execution price and marginal price at start of trade
Curve’s StableSwap
A(x+y) + D = AD + (D³)/(4xy)
A(x+y) provides flat pricing near equilibrium
(D³)/(4xy) ensures infinite liquidity at extremes
A is tuning parameter to control hybrid behavior (critical amplification coefficient)
D is total liquidity
low slippage when prices near 1:1
better capital efficiency (large trades have minimal price impact)
CPMM at extremes prevent pool drainage
used for stablecoin exchanges to allow for simple swaps
1mil USDC → 999990 DAI (0.99999 price, 0.001% price drop)
Amplification Coefficient (A)
tuning lever in stableswap
higher A value → flatter around equilibrium (closer to CSMM)
Loan-to-Value Ratio (LTV)
maximum borrowing against collateral
example: 80% LTV on ETH allows $800 loan against $1000 collateral
lower LTV for volatile assets
set by protocol governance
leveraged trading and accessing liquidity without selling assets → avoiding taxable events
Utilization Rate (U)
U = total borrowed / total available liquidity
low U → interest rates fall to encourage borrowing
high U → interest rates rise to incentivize repayment and attract liquidity
optimal rate ~80%
Kinked Interest Rate Model
balance capital efficiency with liquidity risk
below optimal U → interest rates rise slowly to encourage borrowing and maximize capital efficiency (gentle slope)
above optimal U → interest rates surge sharply to prevent pool drainage and attract new liquidity (steep slope)
Health Factor (HF)
HF = (total collateral value * weight avg liquidation threshold)/(total borrow value)
HF > 1 → safe
HF <= 1 → under-collateralized, eligible for liquidation
affected by collateral asset value decreasing, borrowed asset value increasing, taking on additional debt
improve HF by supplying more collateral or repaying debt
example: initial $10000 in ETH with threshold 80% for $6000 in GH, HF=10000×0.8/6000=1.33, ETH drops to $7000, HF=7000×0.8/6000=0.933, liquidate
Liquidation Process
triggered by borrower’s health factor falling below 1
automated liquidator bots monitor blockchain and identify vulnerable position
liquidator calls liquidate, repaying borrower’s debt for them
liquidator receives portion of borrower’s collateral at discount (liquidation bonus), usually 5-10%
previous example: HF=0.933 ($7000 ETH collateral, $6000 GHO debt), with 5% liquidation bonus
liquidator spends $6000 GHO, receives $6300 ETH, profits $300
protocol recovers $6000 GHO and remains solvent
borrower’s debt cleared, receives $700 ETH collateral, lost $6300 to liquidation
Blockchain Oracle
feeds external data to smart contracts
needed to trigger liquidation
has multiple independent sources
resistant to short-term manipulation
de-centralized with no single point of failure
Flash Loan
borrow with zero collateral
loan must be borrowed and repaid with same atomic transaction
reverts if lending contract did not get repaid
used for arbitrage, liquidations, collateral swaps
“money lego” for developers and traders
Atomic Transaction
all or nothing
if every step succeeds, transaction occurs
if any step fails, transaction reverts
Oracle Manipulation Attack
borrowing massive capital through flash loan
use funds to execute swap on low-liquidity DEX to artificially inflate price of token X
gives inflated token X to as collateral to lending protocol using manipulated DEX as oracle, borrows maximum ETH with falsely valued collateral
repays original flash loan, keeps stolen ETH, price of token X crashes, protocol no longer solvent
Oracle Security Strategies
Decentralized Oracle Networks (DONs) - aggregate price data from multiple independent sources
Time-Weighted Average Price (TWAP) - calculate average price over time window (30 minutes), resistant to short-term price spikes
Multi-Source Validation - price agreement across all sources needed before accepting value, detects and rejects outliers
Aave Protocol
liquidity protocol
choose between variable and stable interest rates
pioneered flash loans
supports diverse range of assets as collateral, including violate and niche tokens