Chapter 3 Automated Market Making

This chapter presents several thought experiments to demonstrate the mechanism that powers Uniswap and most other decentralized exchanges (DEXs). Liquidity providers (LPs1) on Uniswap (or other DEXs) earn real yield, and this chapter also explains where the yield comes from.

3.1 The mechanism

In Quickstart, I had you send $25 of ETH and $25 of USDC to a Uniswap V3 smart contract. That made you a liquidity provider. The smart contract acts as a liquidity pool of ETH and USDC deposits from all liquidity providers. For example, take the 0.05% fee tier ETH-USDC pool on Arbitrum, its contract address is 0xc6962004f452be9203591991d15f6b388e09e8d0. At the moment of this writing, it holds 5,009 ETH and 17,925,757 USDC, which is worth ~$37 million US dollars2. That’s a lot of liquidity, and had you deposited $50 in this pool, you would’ve only shared a tiny %, nonetheless, you would’ve helped reduce slippage3 and got paid 0.05% of the trading volume for each swap your liquidity supported.

You can remove your liquidity at any time. But if liquidity leaves in large amounts, swap price will become volatile and deviate from market price, leading to bad user experience. That’s because the price of ETH in the pool4 depends on the ratio of the ETH and USDC in the pool, and the pool is designed to ‘buy low’ and ‘sell high’5. Let’s walk through how trading, external price movement, and liquidity removal would impact the ETH-USDC pool:

What happens after a swap?

  1. Swap: A user buys ETH with USDC on Uniswap, and Uniswap routes the transaction through the 0.05% fee tier pool (only when it offers the best rate).

  2. Balance change: The swap sends USDC to the pool and removes ETH from the pool. Now the pool has more USDC and less ETH than before.

  3. Price adjustment: Uniswap’s smart contract automatically lifts the price of ETH. Now ETH price in the pool is higher, encouraging others to either sell ETH into it for USDC or add ETH liquidity.

Exercise: What happens after a user sells ETH for USDC?

What happens after a big movement in ETH market price?

  1. Market pump: ETH market price jumps by 20%.

  2. Price disparity: But within the pool, ETH price increases more slowly because the ratio of ETH and USDC in the pool doesn’t just change by itself in an instant.

  3. Arbitrage: Now the market price of ETH is higher than its price in the pool, bots will buy ETH from the ETH-USDC pool and sell it in the external market for profit. This in turn will deplete ETH in the pool and lift its internal price.

  4. Impact on LPs: Your LP position is now unbalanced with less ETH and more USDC. If you chose to remove liquidity at this point, you would end up with less ETH than you initially deposited, resulting in a loss compared to just holding ETH in wallet because of the price increase. This loss is impermanent and only becomes realized when you remove liquidity. It would be erased if the internal ETH price were to revert back to its original state before you withdraw.

  5. Impermanent loss: This is the first time the term “Impermanent Loss (IL)” appears in this book, although you already encountered it in section 2.4 of Quickstart. We’ll discuss IL again and again in this book. For now, just know that IL happens because bots are constantly scanning for and arbitraging away the disparities between the pool’s internal prices and external market prices. And the profits these bots earn come from you the liquidity providers.

Exercise: What happens after a big dump in ETH market price?

What happens if you remove liquidity as ETH price pumps?

  1. Pull liquidity: The price of ETH in the pool rose above the upper limit of the price range of your LP position. Your position is 100% USDC now and it has earned enough fees to make up for IL. You decide to withdraw the 100% USDC and close the position.

  2. Balance change: Now the pool has a bit less USDC. This reduces a little bit of the upward price pressure caused by the depletion of ETH. In general, as the external market price increases, arbitrage bots will dump USDC into the pool to buy ETH (i.e. remove ETH from the pool) and sell them in the market for a profit. Some LPs will take profit by removing liquidity, effectively removing (more) USDC (than ETH) from the pool, which puts a break on the growth of USDC in the pool. Others will either sell ETH into the pool or add ETH liquidity since the price is higher, which puts a break on the depletion of ETH by the bots.

  3. Extreme case: What if ETH price pumps 10x, and you want to sell your 10 ETH into the pool for some nice profit but only to discover the pool has only $1000 of liquidity left? You dig deeper and find that most of the liquidity left immediately after the pump and that most of those positions started with a large proportion of ETH and ended with 100% USDC. It seems that they anticipated the pump and prepared in advance to unload their ETH via LP. This extreme case is unlikely for ETH, but has happened to shitcoins.

Exercise: What happens if you add liquidity as ETH price dumps?

Summary

Your ETH-USDC LP position will hold more ETH when ETH price drops and more USDC when ETH price jumps. That’s because Automated Market Makers (AMMs) always buy low and sell high and automatically adjust your LP balance as price moves between your position’s lower and upper price limits. Therefore, we can use LP to dollar-cost average in and out of a coin. A topic we’ll discuss in later chapters.

3.2 Where does the yield come from

There are five ways for us non-VCs to make money with money in decentralized finance (DeFi). The following tables summarize it all.

DeFi Activity Difficulty Enjoyable? 1-Year (Bear + Bull) Return
Trading Hard Yes Negative for most people
Providing liquidity to DEXs Medium Yes 30% ~ 100%+
Providing liquidity to Perp DEXs6 Easy Yes 5% ~ 40%+
Lend-borrow looping Easy No < 10%
Airdrop farming Easy No 2 ~ 5-figure USD
DeFi Activity Risks
Trading Buy high and sell low. Leverage.
Providing liquidity to DEXs Impermanent loss.
Providing liquidity to Perp DEXs Traders big wins.
Lend-borrow looping Liquidation. More money markets got exploited than DEXs.
Airdrop farming Wasted effort. Sybil detection. Dilution. Team rug. Scam links.
DeFi Activity Yield Source
Trading Traders’ wins are paid by LPs.
Providing liquidity to DEXs Swap fees.
Providing liquidity to Perp DEXs Leverage trading and liquidation fees + LP entry and exit fees.
Lend-borrow looping Supply rate - Borrow rate.
Airdrop farming Money raised.

When you provide liquidity to a DEX like Uniswap, your yield comes from the swap fees, which are commissions paid by DEX users every time they make a swap. It’s usually 0.01%, 0.05%, 0.3%, or 1% of the trading volume, paid out in the token of the trading pair. The higher the volume, the tighter your price range, the longer the price stays in your range, the more fees you will earn.

Some DEXs (for example, Uniswap) pass all swap fees to LPs. Other DEXs not only pass all swap fees to LPs but also reward LPs with their governance tokens. For example, on Trader Joe, pools with a green “REWARDS” tag reward LPs with JOE token in addition to trading fees. Yet some other DEXs reward LPs with only their governance tokens and give all trading fees to holders of the vote escrow version of their governance tokens. Examples include Ramses on Arbitrum, Cleopatra on Mantle, Cellana on Aptos, and Velodrome. In a bull market, governance tokens of newer DEXs with growing TVL can pump a lot, so it may make sense to farm them with LP. In a bear market, I only7 do concentrated liquidity on Uniswap, and I only deposit to these pools: ETH-USDC, ETH-USDT, and ETH-BTC. It’s comforting to know my capital is parked in battle-tested smart contracts to earn high quality assets.


  1. Throughout the book, I use the term LP to mean Liquidity Provider sometimes and Liquidity Provision at other times. The context should make it clear which one is which.↩︎

  2. You can see how many tokens are held in the contract by visiting its arbiscan url: https://arbiscan.io/address/0xc6962004f452be9203591991d15f6b388e09e8d0.↩︎

  3. Slippage is the difference between the expected price and the execution price. It occurs every time you trade on a DEX because price changes so fast between the start and finish of the transaction. Its effect can be positive or negative.↩︎

  4. The price of ETH in the pool, i.e., the internal price, is rarely the same as the price of ETH in the market, i.e., the external price.↩︎

  5. When trading on DEXs that rely on automated market making, you don’t trade against other traders, instead, you trade against the liquidity pool.↩︎

  6. Perp DEXs, short for Perpetual Decentralized Exchanges, are platforms powered by smart contracts that allow people to trade perpetual swaps against liquidity providers.↩︎

  7. I’m also pretty heavy in Orca and Meteora SOL-USDC pairs on Solana since the beginning of 2024.↩︎