In our last Coinverse tutorial, we explored how Decentralized Exchanges (DEXs) use smart contracts to let users trade cryptocurrency directly from their private wallets without a middleman. But this brings up a massive, glaring question that confuses almost every beginner in Web3:

If there is no central company matching buyers and sellers, and no traditional "order book" keeping track of bids and asks, where do the actual tokens come from when you want to buy? Who are you trading against?

Conceptual illustration explaining Liquidity Pools and Automated Market Makers (AMMs) functioning as the core engine of decentralized cryptocurrency trading.
The Engine of Decentralized Trading: How Liquidity Pools and AMMs Power Web3 Exchanges

The answer is the most brilliant innovation in all of Decentralized Finance: Liquidity Pools and Automated Market Makers (AMMs). Together, they create a financial system where anyone can act as a bank, and algorithms dictate the fair market price of an asset instantly.

1. Why the Traditional Order Book Fails on the Blockchain

To understand why AMMs were invented, we have to look at why we could not just copy Wall Street's homework. The traditional stock market and Centralized Exchanges (like Binance) use an Order Book. Buyers list the maximum price they are willing to pay, sellers list the minimum price they are willing to accept, and a central server matches them up.

This requires thousands of updates per second as people constantly cancel and replace orders. In the early days of DeFi, developers tried to put order books on the Ethereum blockchain. It was a disaster. Blockchains process transactions in "blocks" every few seconds, and every transaction costs a network fee (gas). Updating an order book on-chain was impossibly slow and wildly expensive.

The industry needed a way to trade that did not require constant, high-speed updates from active market makers. They needed a passive system.

2. What is a Liquidity Pool?

A liquidity pool is exactly what it sounds like: a giant digital pot of funds locked inside a smart contract. Instead of matching buyers with specific sellers, a DEX matches buyers against this communal pool of assets.

But who puts the money into the pool? Everyday users like you and me, known as Liquidity Providers (LPs).

If a DEX wants to allow people to trade between Ethereum (ETH) and USD Coin (USDC), it creates an ETH/USDC liquidity pool. To participate, a Liquidity Provider must deposit an equal fiat value of both tokens into the smart contract. For example, if ETH is $3,000, an LP might deposit 1 ETH and 3,000 USDC into the pool.

Why would anyone lock their money in a pool? Because of the fees. Every time a trader uses that pool to swap tokens, they pay a small trading fee (typically 0.3 percent). The smart contract automatically distributes that fee to the LPs based on their share of the pool. In DeFi, you do not just use the exchange; you can literally be the exchange and earn the passive income that Wall Street banks normally keep for themselves.

3. The AMM: Trading Against an Algorithm

Now that we have a pool full of tokens, how does the exchange know what price to charge? If there is no order book, who decides what Ethereum is worth at any given millisecond?

This is where the Automated Market Maker (AMM) comes in. The AMM is the mathematical algorithm embedded in the smart contract that dictates the price based purely on supply and demand within that specific pool.

When you go to Uniswap to buy ETH using your USDC, you are not waiting for a seller to agree to your price. You are depositing your USDC directly into the pool and withdrawing ETH from the pool. Because you took ETH out, there is now less ETH in the pool than there was a second ago. Because Ethereum is now scarcer in that pool, the AMM automatically raises the price of the remaining ETH.

4. The Magic Formula: x * y = k

The most common AMM algorithm, pioneered by Uniswap, is incredibly elegant in its simplicity. It relies on a "Constant Product Formula" represented as: x * y = k.

  • x = The total amount of Token A in the pool (e.g., ETH)
  • y = The total amount of Token B in the pool (e.g., USDC)
  • k = The total constant liquidity

The golden rule of the smart contract is that "k" must always remain constant. If a trader comes in and buys a massive amount of ETH (removing "x" from the pool), they must deposit a massive amount of USDC (adding "y" to the pool) to keep "k" the same.

As the supply of ETH approaches zero in the pool, the mathematical curve forces the price of ETH to approach infinity. This mechanism guarantees that the pool can never actually run out of tokens; it just makes them exponentially more expensive to buy as they become scarce.

5. Slippage and the Reality of Decentralized Markets

Because the price of an asset in a pool changes based on the ratio of the two tokens, large trades can cause problems. This introduces a concept you must understand before trading in DeFi: Slippage.

Slippage is the difference between the price you expect to pay and the price you actually pay when the trade executes.

Imagine a very small liquidity pool that only holds 10 ETH and 30,000 USDC. If you try to buy 5 ETH all at once, you are removing 50 percent of the pool's entire Ethereum supply in a single transaction. The AMM algorithm will react violently, spiking the price of ETH mid-trade. You might expect to pay $3,000 per ETH, but due to slippage, your average cost might be $4,500.

To avoid high slippage, traders must ensure they are trading in pools with massive amounts of "Deep Liquidity" (millions of dollars in deposits), where their individual trade is just a tiny drop in the ocean and barely moves the mathematical ratio.

Liquidity pools and AMMs solved the trading problem for DeFi, but trading is only half of the financial system. In the next pillar of our Coinverse series, we will explore how smart contracts handle credit, diving into the mechanics of Borrowing and Lending on the Blockchain.