The Magic of AMM's

October 25, 2025

AMM : Automated Market Makers

Hello ! everyone ,

In this blog we gonna have a deep dive of AMM and the magic / math behind it.

Let’s start with What AMM’s actually are ??

Simply , An AMM is a system / protocol that uses a formula and a pool of tokens to automatically decide the price of assets instead of using a traditional order book.

Okay , what is Order book ?

The order book is the fundamental mechanism behind traditional financial markets and most centralized crypto exchanges (like Binance or Coinbase). It is a real-time, electronic list of buy and sell orders for a specific asset (like a stock, Bitcoin, or ETH), organized by price level.

Let’s go back in time when people ( investors / traders ) used to go to the market and shout like ,on one side “ I want to buy this asset at this price! “ and on the other side “ I want to sell this asset at that price! “ The order book is the list that collects all these intentions.

It has two main sides:

Bids (The Buy Side): These are orders from people who want to purchase the asset. They state the maximum price they are willing to pay.

Asks / Offers (The Sell Side): These are orders from people who want to sell the asset. They state the minimum price they are willing to accept.

The orders are always sorted, with the highest bid and the lowest ask at the top of their respective lists. This is because these are the most competitive and likely-to-execute orders.

Key Terminology:

Bid Price: The highest price a buyer is currently willing to pay.

Ask Price: The lowest price a seller is currently willing to accept.

Spread: The difference between the Ask Price and the Bid Price (Spread = Ask - Bid).

Market Order: An order to buy or sell immediately at the best available current price. It doesn’t specify a price, only an amount.

Limit Order: An order to buy or sell only at a specific price or better. It gets added to the order book and waits to be filled.

Depth: A measure of the volume of orders waiting at different price levels below and above the current price. A “deep” order book has large volumes of bids and asks.

How Does an Order Book Work? Let’s imagine the order book for Ultr⊘n Stock.

The Current Order Book:

«««< HEAD | Bids (Buyers) | ||| Asks (Sellers) | | |——————–|————–|||——————–|————–| | Quantity | Price ||| Price | Quantity | | 50 | $10.05 ||| $10.08 | 100 | | 25 | $10.04 ||| $10.09 | 75 | | 100 | $10.02 ||| $10.10 | 200 | ======= | Bid Quantity | Bid Price | Ask Price | Ask Quantity | |————–|———–|———–|————–| | 50 | $10.05 | $10.08 | 100 | | 25 | $10.04 | $10.09 | 75 | | 100 | $10.02 | $10.10 | 200 |

0716258 (pico ctf 2026 writeups and the projects are updated)

Best Bid: $10.05

Best Ask: $10.08

Spread: $10.08 - $10.05 = $0.03

Scenario 1: A New Limit Order to SELL

You: Place a limit order to sell 30 shares at $10.06.

What Happens: The exchange’s matching engine looks at the Bid side. Is anyone willing to buy at your price or higher?

Result: There is no bid at $10.06 or higher. Your order cannot be filled immediately. It gets added to the Ask side of the book, becoming the new “Best Ask” because it’s lower than the existing $10.08 ask.

The NEW Order Book:

«««< HEAD | Bids (Buyers) | ||| Asks (Sellers) | | |——————–|————–|||——————–|————–| | Quantity | Price ||| Price | Quantity | | 50 | $10.05 ||| $10.06 | 30 | | 25 | $10.04 ||| $10.08 | 100 | | 100 | $10.02 ||| $10.09 | 75 | ======= | Bid Quantity | Bid Price | Ask Price | Ask Quantity | |————–|———–|———–|————–| | 50 | $10.05 | $10.06 | 30 | | 25 | $10.04 | $10.08 | 100 | | 100 | $10.02 | $10.09 | 75 |

0716258 (pico ctf 2026 writeups and the projects are updated)

The Spread has now narrowed to $10.06 - $10.05 = $0.01.

Scenario 2: A New MARKET ORDER to BUY

A Trader: Places a market order to BUY 80 shares.

What Happens: A market order takes the best prices available immediately.

It buys the 30 shares from you at $10.06 (your limit order).

It still needs 50 more shares. It then moves to the next best seller and buys 50 shares at $10.08.

Result: The trader filled their order at two different prices. Your sell order is completely filled and removed from the book. The 100-share ask at $10.08 is reduced to 50 shares

Drawback of order book model

The main drawback of order book model is The Centralization Problem .

The process of matching thousands of orders per second requires a powerful , centralized server. This creates a single point of technical failure and control.

On most centralized exchanges , you don’t hold the private keys to your crypto . The exchange holds it for you (“not your keys , not your crypto”). This creates counterparty risk-if the exchange gets hacked or goes bankrupt , you could lose your funds.

The exchange operator can decide which tokens to list , often charging high listing fees and creating a barrier to entry.

ok , let’s get back to the AMM’s

An AMM is a system / protocol that uses a formula and a pool of tokens to automatically decide the price of assets instead of using a traditional order book.

core concepts of AMM :

  1. Liquidity Pools (LPs): Instead of trading with another person, you trade with a smart contract that holds reserves of two or more tokens. For example, an ETH/DAI pool holds both ETH and DAI.

  2. Liquidity Providers (LPs): Users who deposit their tokens into these pools to provide liquidity. In return, they earn fees from all trades that happen in their pool.

  3. The Magic Formula: A deterministic formula that defines the price based on the current ratio of tokens in the pool. The most famous one is the Constant Product Formula.