# 11 — DeFi, Stablecoins, and Governance Consider three strange objects: an exchange with no order book and no operator, a bank with no banker, and a currency pegged to the dollar by a contract. Each one clearly needs *something* holding it together — but what could that something be, with no institution behind it? The answer, in each case, turns out to be an invariant guarded by incentives. DeFi protocols are financial state machines, and the fastest way to understand any of them is to find the invariant first. Let's do exactly that, three times. ## Decentralized exchanges Traditional exchanges match bids and asks in an **order book**. An **automated market maker (AMM)** replaces that matching engine with a formula and a pool: ```text x * y = k ``` A pool holds reserves of two assets, `x` and `y`, and accepts any trade that preserves the product `k`. That one rule does everything: the price is just the ratio of reserves, and buying enough of `y` makes it scarcer and therefore pricier along the curve — automatically, with no one quoting anything. **Liquidity providers (LPs)** deposit both assets into the pool and earn fees when others trade against it — essentially paid for standing still. Notice the substitution that happened here, because it's the recurring DeFi move: an order book needs a market maker actively quoting prices; an AMM needs only that arithmetic keeps working. Active intelligence, replaced by a passive invariant. The costs come from the same arithmetic. Large trades **walk the curve** — **slippage**, price movement caused by your own trade size against limited pool liquidity. LPs hold a changing mix of assets; if one asset rises sharply, they end up with less of it than if they'd simply held — that's **impermanent loss**, relative to holding. And since every AMM trade is a visible, deterministic price move, AMMs are structurally exposed to [[MEV]] — the sandwich attack's natural habitat. One more corollary worth filing: a pool's spot price can be shoved around within a single block, which is why naively using it as a price oracle ends in tears. ## Lending protocols Users deposit collateral and borrow against it. Two knobs matter before the invariant: - **Collateral factor** — how much you can borrow per dollar of collateral. - **Liquidation threshold** — the line where the protocol sells your collateral to repay debt. The invariant: > Every position remains overcollateralized, at all times, according to the oracle. Around it: collateral factors, liquidation thresholds, interest-rate curves that steepen as utilization rises, and liquidators — bounty hunters who repay underwater debt in exchange for discounted collateral. It's worth appreciating who keeps the system solvent at 3 a.m.: nobody on duty, just whoever finds it profitable to be awake. Incentives standing where an institution's risk desk would stand. Now reread the invariant and notice the fine print: *according to the oracle*. The protocol doesn't know what anything is worth — it believes a feed ([[08 Nodes, RPCs, and Indexers]]). Manipulate that feed for one block, and the protocol will "correctly" liquidate healthy positions or hand out unbacked loans, executing its rules flawlessly the entire time. And when prices move faster than liquidators can act, or collateral can't be sold fast enough, the result is bad debt — the risk engine colliding with [[Gas and Blockspace|the blockspace auction]], and losing. Derivatives protocols (perpetuals, options) are the same shape at higher voltage: more oracle dependence, **funding rates** (periodic payments that keep perpetual prices near spot), liquidation cascades. ## Stablecoins A stablecoin is a token that tracks an external value, usually the dollar. Four mechanisms, each with different fine print: | **Type** | **Mechanism** | |---|---| | Fiat-backed | Issuer holds bank/T-bill reserves | | Crypto-collateralized | Overcollateralized onchain positions | | Algorithmic | Supply mechanics attempt to hold the peg | | Synthetic | Derivative positions replicate the peg | Each is a different answer to "what stands behind the peg?" — and the differences matter. Fiat-backed coins quietly reintroduce the bank: mint/burn authority, freeze and blacklist functions, reserve attestations, redemption rights. The token lives on-chain; the promise lives in a legal document. Crypto-collateralized designs (MakerDAO's lineage) keep the collateral visible on-chain and pay for that transparency with capital inefficiency. Algorithmic designs promised stability with nothing behind it; the graveyard is instructive, and the lesson is simple — a peg backed by confidence holds exactly as long as confidence does. Why stablecoins matter so much: volatile assets are bad units of account, so stablecoins are what people actually transact in. They're the bridge between blockchain rails and payment-like UX. If your work touches payments, the practical questions are concrete: who can freeze, who can mint, what backs redemption, on which chains, across which [[10 Bridges and Interoperability|bridges]]. ## Governance Code gets deployed; the world changes; someone has to hold the pen. **Governance** is how protocols decide their own changes — often via **governance tokens** (votes weighted by token holdings), delegation, **multisigs** (m-of-n admin keys), **timelocks** (mandatory delay before upgrades execute), onchain proposals, and offchain signaling. The failure modes are the ones you'd predict from any voting system, sharpened by the fact that the votes are purchasable: voter apathy, whale control, malicious proposals. The purest form of the last one is worth spelling out: buy enough tokens, pass a proposal that transfers the treasury to yourself, exit. A governance token prices the right to rewrite the rules — and occasionally the treasury is worth more than that price. When it is, someone arbitrages. The underlying tension every governance design is negotiating: ```text speed vs safety decentralization vs competence immutability vs upgradeability ``` And a thread from [[05 Execution and Smart Contracts]] closes here: whoever can upgrade the contract is part of the trust model. Governance is that fact, given a constitution. ## Learning outcomes Questions worth trying on: - Could you derive slippage and impermanent loss from `x * y = k` at a whiteboard? - Could you explain to a risk engineer what keeps a lending protocol solvent — and enumerate the assumptions doing quiet work in your answer? - For each stablecoin type: what backs it, who can freeze it, and what does its failure actually look like? - Could you sketch a governance attack, and then the design features (timelocks, quorums, veto powers) that would have priced it out? - And the thread to pull forward: you've now seen oracles trusted, bridges robbed, and invariants gamed. What would it look like to assemble all of that into one coherent threat model? ## Checkpoint 1. Why does a large trade against an AMM move the price more than the same trade on a deep order book? *(Hint: you're walking the `x*y=k` curve alone — no other orders to absorb size. If unsure, revisit "Decentralized exchanges".)* 2. Walk the path from "oracle reports a wrong price for one block" to "protocol insolvent." *(If unsure, revisit "Lending protocols" — the full anatomy arrives in [[12 Security and Incentive Design]].)* 3. What's the difference between a stablecoin depeg and a stablecoin freeze, and which coin types are exposed to which? *(If unsure, revisit "Stablecoins".)* **Exercise.** Model `x * y = k` in a spreadsheet or notebook: seed a pool, run trades of increasing size, plot effective price against trade size. Then compute an LP's position value versus simply holding both assets, across a range of prices. In an hour you'll have *derived* slippage and impermanent loss — which beats memorizing them, and sticks. ## Resources - **DeFi MOOC** — the structured treatment: AMMs, lending, stablecoins, oracles, liquidations, MEV. The real value is watching financial invariants get encoded into adversarial state machines. - **Uniswap docs and whitepapers** — the cleanest canonical primitive; v2 for the core idea, v3 for concentrated liquidity. - **MakerDAO docs** — the canonical crypto-collateralized stablecoin: vaults, liquidation, redemption. --- Next: every module so far has hinted at its own failure mode. Time to assemble them into one threat model. How does all of this break? → [[12 Security and Incentive Design]]