MSTR Cat

Blockchain/Level VI · After bitcoin/6.3 Ethereum and smart contracts/Lesson 4

DeFi: AMMs, lending, and what broke

The code that replaced the bank, and the keys it forgot to lock

MaterialsA spreadsheet for tracking collateral ratiosAccess to a block explorer (e.g., Etherscan)The Uniswap v2 white paperA block explorer for Ethereum or Solana

Wonder

  1. How can two static numbers in a smart contract determine the price of an asset?
  2. Why does lending against over-collateralized crypto require a stablecoin to function as a unit of account?
  3. How can a user borrow millions of dollars and repay them within a single transaction?

Explore

    Part IDeFi summer: AMMs, lending and MakerDAO

  1. MakerDAO, founded by Rune Christensen in 2014, launched DAI in December 2017. It is a dollar-pegged stablecoin backed by over-collateralized crypto loans. Users lock assets like ether into smart contracts to borrow DAI. The protocol maintains the peg through redemption mechanisms and liquidations if collateral value drops below required thresholds. This created the first decentralized credit system on Ethereum, operating without banks or central intermediaries.
  2. Uniswap, launched by Hayden Adams in November 2018, replaced order books with automated market makers (AMMs). A pool holds two tokens and prices trades using the constant-product rule x · y = k. Anyone can trade against the pool reserves or supply liquidity to earn fees. This eliminated the need for a counterparty at every moment. Users trade against the pool rather than another person, and prices are kept in line by arbitrageurs maintaining equilibrium with external markets rather than matching bids and asks.
  3. In June 2020, Compound began distributing its COMP token to users who supplied liquidity or borrowed assets. This practice, known as ‘liquidity mining,’ incentivized capital accumulation in protocols. It ignited ‘DeFi summer.’ Yearn Finance, which began as iEarn earlier in 2020 and launched its YFI token in July, automated yield-seeking. Uniswap airdropped UNI tokens to early users in September 2020. Total value locked across these systems surged as users farmed yields, creating a dense, composable financial stack where protocols built upon one another.
  4. Warning signs had already appeared before DeFi summer began. Smart contracts are public and auditable, but bugs can be exploited. In February 2020, bZx suffered a flash-loan attack, in which an attacker borrowed funds to manipulate prices within a single transaction. MakerDAO faced cascading liquidations on 12 March 2020 during market volatility; network congestion and failing bidder bots left auctions nearly empty, and about $8 million of ether went for zero DAI; Maker covered the shortfall by minting and auctioning new MKR, diluting its holders. DeFi inherits market risk and adds technical failure modes of its own.
  5. DeFi protocols rely on price oracles to determine the fiat value of collateral assets like ether. Oracles such as Chainlink Price Feeds or Uniswap’s time-weighted average prices (TWAPs), computed on-chain, feed prices into smart contracts for collateralization calculations. Manipulating these feeds is a primary attack vector. The trust model shifts from a single institution to code, oracle data, and governance. When the logic fails at an edge case, losses fall on users or token holders rather than a central backstop.
  6. The composability of DeFi allows protocols to stack, creating complex financial instruments like leveraged yield farming. This efficiency comes with systemic risk; a failure in one layer can cascade through others. For example, a price oracle manipulation can trigger liquidations across multiple lending platforms simultaneously. The trade-off is between the transparency and permissionless access of smart contracts and the fragility inherent in interconnected code, softened only partly by emergency mechanisms such as Maker’s shutdown and Compound’s pause controls.
  7. Part IIDeFi: markets without middlemen, and what broke

  8. DeFi replaced intermediaries with smart contracts that apply identical rules to all participants. Automated market makers (AMMs) like Uniswap v2, launched in May 2020, allowed trading via liquidity pools rather than order books. Lending protocols enabled overcollateralised borrowing where users deposited assets as collateral to borrow stablecoins or other tokens. These systems operated without central administrators approving individual transactions.
  9. The primary vulnerability emerged from external price feeds, known as oracles. Protocols required accurate asset prices to calculate collateral values and trigger liquidations. In March 2020, MakerDAO experienced cascading liquidations during a market crash; network congestion and lagging price feeds let bots win collateral auctions with bids of zero DAI, leaving millions of dollars of bad debt. Transparent rules still failed when the plumbing around them clogged.
  10. Oracle manipulation proved more devastating than simple volatility. In October 2022 a trader pushed up the price of the thinly traded MNGO token on the markets Mango’s oracle read, inflating the value of his collateral, and borrowed about $110 million against it. The protocol was left with bad debt exceeding its liquid reserves, demonstrating that code cannot protect against manipulated input data.
  11. Bridges and administrative keys introduced additional points of failure. Bridges move assets between blockchains, concentrating risk in a single custodial entity or smart contract. Several major hacks involved attackers exploiting retained admin privileges or buggy bridge logic to drain funds. Unlike Bitcoin’s immutable consensus rules, these upgradeable contracts allowed for social consensus changes but also exposed users to the discretion of governance teams who held authority over protocol parameters.
  12. Bitcoin-compatible designs can reduce these risks. Discreet Log Contracts allow parties to settle on external outcomes using signed commitments from trusted oracles, removing the need for on-chain price feeds, though an oracle can still attest to a manipulated price. Escrowed lending can be implemented with explicit, verifiable scripts where collateral is locked until conditions are met. Batch-cleared markets, a market design rather than a Bitcoin feature, would process multiple orders together, reducing ordering advantages.
  13. The lesson for Bitcoin is not to avoid markets but to build them from rules anyone can check: collateral held in visible scripts, outcomes settled by accountable signatures, ordering made irrelevant by batch clearing, and no party able to change the rules after users commit. What DeFi got right (open access, transparent positions, settlement without a clearing house) is worth carrying home; its admin keys and unaccountable price feeds are not.

Key facts

  • MakerDAO launched DAI, a dollar-pegged stablecoin backed by over-collateralized crypto loans, in December 2017.
  • Uniswap popularised the automated market maker using the constant-product rule x · y = k to price trades without an order book.
  • Compound initiated ‘liquidity mining’ in June 2020 by distributing COMP tokens, igniting DeFi summer.
  • The bZx protocol suffered a flash-loan attack in February 2020, exploiting smart contract logic within a single transaction.
  • On 12 March 2020, congested liquidation auctions let about $8 million of MakerDAO collateral sell for zero DAI.
  • DeFi protocols use price oracles like Chainlink and Uniswap TWAPs to determine the fiat value of collateral assets.
  • Uniswap v2 (May 2020) extended the AMM design, which trades against pools rather than order books, with token-to-token pairs and price oracles.
  • In March 2020 congestion let MakerDAO collateral auctions clear at zero bids, leaving millions in bad debt.
  • In October 2022 a trader manipulated the price Mango Markets’ oracle read, inflated his collateral and borrowed about $110 million.
  • Bridges concentrate risk by moving assets between chains, exposing users to custodial entities or smart contract vulnerabilities.
  • Discreet Log Contracts enable settlement on external outcomes using signed commitments from trusted oracles without on-chain price feeds.
  • Batch-cleared markets process multiple orders in a single block, reducing ordering advantages and minimizing exposure to real-time manipulation.

Exercise nine, six, three, one

9CollectList 9 DeFi protocols active in 2020. Note their primary function (lending, exchange, stablecoin) and their token symbol.
6ClusterGroup the 9 into 6 by risk profile: price manipulation exposure, smart contract complexity, liquidity dependency, oracle reliance, governance centralization, or other.
3DistillReduce the 6 to 3 core technical vulnerabilities that define DeFi systemic risk.
1CrystallizeWrite 1 sentence on how composability amplifies both yield and contagion in decentralized finance.

Fact check

Dates, figures and claims checked against the published sources listed below.

Open in the interactive academy →

PT ES ZH JA KO RU DE FR MS