Secret terminal

How Automated Market Makers Work in Crypto

19 min
How Automated Market Makers Work in Crypto

An AMM (automated market maker) is a smart contract, meaning a program on a blockchain that holds a supply of tokens (usually two) and calculates the exchange price with a formula. There is no order book inside. There is no second trader on the other side of the trade either. You send one token to the contract, the contract recalculates its reserves and hands you the other.

The price here is set by the arithmetic of reserves. Nearly everything that makes an AMM in crypto different from a regular exchange grows out of that fact.

Next, in order: the formula, what a trade costs in a pool, impermanent loss, and the reasons why the usual order book reading can't be applied to an AMM.

What Is an AMM

On a centralized exchange (CEX), trades are matched by the order book, a list of limit orders to buy and sell. One participant posts an order, another hits it with a market order.

An automated market maker removes the second side. Its role is taken over by a liquidity pool, a contract holding a supply of two assets. The trader trades against the pool, and the pool is filled by liquidity providers (LPs), who deposit tokens and earn a share of the fees.

Why make it so complicated? On Ethereum, an order book turned out too expensive: every order placed and canceled there is a separate transaction that costs gas (the network fee for computation). A formula removes the problem: a quote exists as long as the pool has reserves, and nobody pays gas to update it.

That's why liquidity in an AMM is passive: it sits in the pool, ready to trade at any price the formula produces. And the pool price itself has no idea what's happening on the rest of the market until arbitrageurs pull it into line. The whole category of such protocols is covered in the article "What Is DeFi in Simple Terms", and the comparison of venues is in a separate piece, "CEX vs DEX: Where to Trade Crypto".

The x*y=k Formula

The basic model is called constant product. A pool has two reserves: x tokens of the first asset and y tokens of the second. Their product has to stay the same after every trade, that is, x*y=k. The price of token X in tokens of Y at any moment equals the ratio of reserves: P = y / x.

Take a hypothetical ETH/USDT pool holding 10 ETH and 20,000 USDT. Then k = 200,000, and the price inside the pool is 2000 USDT per ETH. The numbers are illustrative and rounded.

A trader wants to buy 1 ETH. After the trade, 9 ETH will remain in the reserve, so the USDT reserve must grow to 200,000 / 9, that is, to 22,222.22. The trader pays the difference: 2222.22 USDT for one ETH against a quote of 2000. That 11.1% premium is called price impact, and the trade itself creates it.

In a pool a hundred times deeper, the picture is different.

Pool sizeBuying 1 ETH costsPremium over the 2000 quote
10 ETH + 20,000 USDT2222.22 USDT11.1%
1000 ETH + 2,000,000 USDT2002.00 USDT0.1%

Same trade, yet the premium differs by a factor of 111. The rule for constant product is simple: buying 1% of a pool's reserve costs about 1% more than the quote, and buying 10% of the reserve already costs 11% more. Before a swap (an exchange of tokens in a pool), I compare the trade with the reserves, and if I go beyond 1%, I look for a deeper pool or hand the swap to an aggregator that will split it across several pools. That's my personal threshold, not a standard. Depth and spread have their own breakdown: "Liquidity in Crypto".

The calculation leaves out the fee. In a real pool, the fee is first deducted from the incoming amount, and the remainder goes into the formula.

The x*y=k curve has a weak spot: liquidity is smeared across all prices from zero to infinity. That suits a new token, but in a USDT/USDC pair, where the price has stayed near one for years, almost all the capital sits idle. So the AMM family has long been wider than one formula: constant sum (x + y = k), curves for stablecoins (tokens pegged to the dollar), pools with weights other than 50/50. And newer protocol versions let a provider pick a narrow price range (that's how concentrated liquidity works).

Difference from the Classic Order Book

For someone who reads order flow, the main difference is in what you can see before the trade. A density level in the order book, meaning a large limit order or a stack of orders at one price, doesn't exist in an AMM, because there are no orders at all. The tape (the stream of executed trades with size and side) arrives in batches, block by block. Clusters (volume by price inside a candle) can be calculated, but there's nothing to check them against. And spoofing and absorption have nowhere to come from: there's no one to post orders for show and no one to take market orders onto themselves, so the price just slides along the curve.

ParameterOrder book on a CEXAMM pool
Price sourceParticipants' limit ordersFormula and reserves
Visible before entryDensity levels, tape, clustersReserves and the estimated execution price
Order cancellationFree, within exchange limitsNo orders
Front-runningHigh-frequency algorithms, servers next to the exchangeMEV (profit from transaction ordering in a block)
Who takes the riskMarket maker, chooses the quoteLiquidity provider, doesn't choose the quote

In return, the pool's state is public, and the cost of entry is calculated before the transaction is sent.

The order book itself (limit orders, liquidity, and entry points) is covered in the free lesson on the Secret Terminal YouTube channel. The lesson is part of a full five-part crypto trading course for beginners.

How Liquidity Pools Work

A provider deposits both assets into the pool in a proportion that matches the current price. For an ETH/USDT pool at a price of 2000, that's, for example, 1 ETH and 2000 USDT. In return, the contract issues an LP token that records a share of the whole pool, not the specific coins deposited. In protocols with price ranges, an NFT (a unique token) with the position's parameters is issued instead.

From there, simple bookkeeping takes over.

  • Every trade leaves a fee in the pool. In old-style pools (like Uniswap v2), it goes into the reserves, and the provider's share grows in value on its own. In pools with ranges, fees accumulate separately and are collected manually.
  • The asset ratio is always drifting. Did the price of ETH go up? There's now less ETH and more USDT in the pool, because traders were buying up ETH specifically.
  • Arbitrageurs keep the pool price close to the market price. As soon as the gap with the exchange gets bigger than the pool fee plus gas, a bot evens out the reserves and takes the difference. The provider pays for it: the difference comes out of their reserves.

A 10,000 USDT swap in a pool of 1000 ETH + 2,000,000 USDT at a 0.30% fee: 30 USDT go to the fee, and the trader receives 4.96027 ETH. That works out to 2016.02 USDT per ETH, 0.80% above the quote. Of that, 0.30% is the fee and about 0.50% is price impact.

The nominal size of a pool says little about income. What to look at is the ratio of daily volume to TVL (total value locked, the sum of assets in the pool), because the fee is charged on volume. At a hypothetical fee of 0.30%, a 50 million USDT pool with volume of 200 thousand a day collects 600 USDT a day, or 0.0012% of the capital put in. A 2 million pool with volume of 10 million collects 30,000 USDT, that is, 1.5% a day. Then again, that kind of volume in a small pool usually comes together with a sharp price move.

Stablecoin pools have a different curve: near parity it's almost flat, and in a deep pool, swapping a million USDC for USDT goes through with minimal price impact. The payback comes when the peg breaks. The flat section then works against the provider, and the pool quickly fills up with the asset that lost value. Venues with such pools are compared in the overview "What Is a DEX: Decentralized Exchanges".

Impermanent Loss: The Main Risk

Impermanent loss (IL) is how far the value of a pool position lags behind the value of the same assets simply held in a wallet. It's measured against holding, not against the entry point: a position can be in profit relative to what was put in and still lose to the wallet.

The cause is mechanical: the pool has to trade by the formula, and the formula forces it to sell the asset that's rising and buy the one that's falling.

The word "impermanent" is misleading. While the position is in the pool, the divergence can shrink if the price returns to the entry level. On withdrawal, the shortfall is locked in for good. The second term, divergence loss, is more accurate.

In a constant product pool, the size of IL depends only on how many times the price ratio of the two assets has changed, and direction plays no part. The formula: IL = 2 × √r / (1 + r) - 1, where r is the ratio of the new price to the old one, and the absolute value of the result is the shortfall.

Price changerShortfall vs holding
+50%1.52.02%
2x25.72%
3x313.40%
4x420.00%
10x1042.50%

The formula is symmetric: a price drop by half gives the same 5.72%, and a drop to a quarter gives the same 20%. A pair of two stablecoins creates almost no IL as long as the peg holds and r stays near one. In a "stablecoin plus volatile altcoin" pair, the altcoin's entire move turns into divergence.

What this formula doesn't show. Concentrated liquidity and contract risk. A range gives more fees on the same capital, but when the price moves past its boundary, the position turns entirely into one asset and stops earning. The divergence mechanism is the same, only the curve is steeper. And contract risk has nothing to do with pool arithmetic at all. A bug in the code, a compromised admin key, manipulation of an oracle (a service that feeds external prices to the contract), a malicious hook (third-party code attached to the pool), and what's at stake is no longer 5.72% relative to holding but the entire position.

A Worked Example

All numbers are hypothetical and rounded, and there's no yield forecast in them.

An ETH/USDT pool, price 2000. You deposited 10 ETH and 20,000 USDT (40,000 USDT at the current price) and, for simplicity, own the entire pool. The product k equals 200,000. The price of ETH rose to 4000, and the reserves were recalculated so that the product was preserved and their ratio gave the new price.

  • ETH in the pool: √(200,000 / 4000) = 7.0711
  • USDT in the pool: √(200,000 × 4000) = 28,284.27
What we calculateCalculationResult
Pool position28,284.27 × 2 (the ETH in the pool is worth the same as the USDT)56,568.54
Simple holding10 × 4000 + 20,00060,000
Difference60,000 - 56,568.543431.46
In percent3431.46 / 60,0005.72%

The same 5.72% as in the "2x" row. As the price climbed, the pool sold 2.9289 ETH at an average of 2828 USDT, while ETH on the market already costs 4000.

The second half of the calculation is fees, and we'll take a more modest entry. A hypothetical pool: TVL of 1,000,000 USDT, daily volume of 500,000 USDT, a 0.30% fee that goes entirely to providers. The pool collects 1500 USDT a day. Your 1% share (a 10,000 USDT entry) brings in 15 USDT a day. Over 30 days without reinvestment, and with the share and volume unchanged, that comes to 450 USDT.

Now IL on the same entry. You went in 50/50, that is, 5000 USDT and 5000 worth of ETH. Over the month, ETH doubled. Simple holding would have given 15,000 USDT, while the pool position is worth 15,000 × (1 - 0.0572) ≈ 14,142. The shortfall is 858 USDT, fees covered 450 of that, and what's left is minus 408 USDT versus holding.

Change the volume to 2,000,000 a day, and fees give 1800, which covers IL with room to spare. At 100,000 you get 90. At volume of around 950,000, the position would break even against holding. I'd judge a pool by exactly these two numbers: the expected price divergence and the ratio of volume to TVL. The headline APR figure (the annual rate without reinvestment) says less. Neither volume nor divergence is known in advance, so a calculation like this doesn't become a promise of returns.

Uniswap, PancakeSwap, Raydium

Three protocols people usually start with when getting to know AMMs in crypto. The parameters were checked against the official documentation on October 1, 2026, but versions and fees change, so reread the primary source before entering a pool.

Uniswap. The protocol that turned the x*y=k formula into an industry standard. In v2 there's one fee for all pools, and since December 2025, after the UNIfication vote, the protocol takes 0.05% out of the 0.30%. The third version brought concentrated liquidity and fee tiers, and new tiers are switched on by a vote of UNI holders. In v4, all pools live inside a single PoolManager contract, hooks appeared, and the pool creator sets the fee, with a hook able to change it on the fly.

PancakeSwap. In v3 on EVM chains (Ethereum-compatible ones), providers get from 66% to 68% of the fee, and the rest is split between CAKE burns and the treasury. On Solana, v3 is built differently: there are 18 tiers, and the split is the same for all of them, 84% to providers and 8% each to burns and the treasury. The Infinity architecture added CLAMM pools (constant product, positions as NFTs) and LBAMM, made of price bins with a constant sum (x + y = k), where a trade inside a bin goes through with no price impact.

Raydium. On Solana, Raydium runs three programs at once. CPMM is a plain constant product with support for Token-2022 (Solana's new token standard). The documentation sends new pairs right here. Concentrated liquidity in the spirit of Uniswap v3 is split out into the CLMM program. In both types, providers get 84% of the fee, 12% goes to RAY buybacks, and 4% to the treasury. AMM v4 is an old hybrid of constant product with the OpenBook order book. It's no longer offered by default: the program was kept for long-standing pairs that need the OpenBook integration.

ProtocolModelSwap fee
Uniswap v2x*y=k0.30%, of which 0.05% to the protocol
Uniswap v3x*y=k in a range0.05 / 0.30 / 1% plus extra tiers
Uniswap v4x*y=k in a range, hooksany from 0% to 100%, step 0.0001%
PancakeSwap v2x*y=k0.25%, 0.17% to providers
PancakeSwap v3 (EVM)x*y=k in a range0.01 / 0.05 / 0.25 / 1%
PancakeSwap v3 (Solana)x*y=k in a range18 tiers from 0.01% to 4%
PancakeSwap Infinity LBAMMx + y = k across price binsstatic or dynamic, up to 10%
Raydium CPMMx*y=k0.01 / 0.25 / 1%
Raydium CLMMx*y=k in a rangemost often 0.01 / 0.05 / 0.25 / 1%
Raydium AMM v4x*y=k plus the OpenBook order book0.25%

One protocol often has several versions of its code running, so pools with the same pair name can differ in both depth and fee. You have to check the specific pool: the pair name alone isn't enough.

AMM vs CEX: Which Is Better for Trading

There's no single answer, and the table shows why. This is specifically about pools: DEXs (decentralized exchanges) with an order book work differently.

CriterionAMM poolCEX
Custody of fundsYour own wallet and keysExchange account
Trade speedBlock timeMilliseconds
Cost of entryPool fee, price impact, gas, MEVExchange fee and spread
New tokensAnyone can create a pool in minutesThe exchange's listing decision
Main riskCode, oracle, admin key, the token itselfSolvency and the venue's rules

For intraday trading and scalping, speed and visibility of the flow decide everything. If you have a second to get into a move, the "sign the transaction and wait for a block" mode doesn't fit, and strategies built on density levels and absorption need an order book, which a pool doesn't have.

Fresh and illiquid tokens are the opposite case. A pool is created without permission, and a token's first weeks of life often play out only on DEXs.

A sensible setup for an active trader: execute trades and read the flow on centralized venues, and keep early tokens and the part of the portfolio under your own keys on DEXs. The first part takes a terminal with an exchange order book. In Secret Terminal, for example, the order book, tape, and clusters are open in one window, and it doesn't show AMM pools.

[Placeholder: terminal mockup with the order book, tape, and clusters (image: terminal mockup)]

When the pre-trade calculation doesn't work. On March 12, 2025, a trader swapped 220,764 USDC in the USDC/USDT pool on Uniswap v3 and received 5271 USDT. Cointelegraph described it as a sandwich attack: right before the trade, an MEV bot bought the liquidity out of the pool and returned it right after. The whole thing took eight seconds. The transaction didn't go through the Uniswap interface, which has MEV protection and a default slippage tolerance (the limit on how far the execution price can move from the estimated one before the trade is canceled). The trade executed against a pool state that was no longer the one the price had been calculated on.

Typical mistakes. Nearly all of them come down to one thing: a person looks at the rate and doesn't look at the pool.

  • Checking only the rate and not dividing the trade size by the pool's reserve.
  • Slippage tolerance "with a margin." Set 5-10% so the transaction would go through for sure? That margin is exactly what a bot can take. I check the minimum amount to be received before every signature myself, even on stablecoins.
  • Counting a pool's yield by fees and not counting impermanent loss.
  • Entering a narrow range and forgetting about the position. The price moved past the boundary, and you're sitting entirely in the asset that turned out weaker.
  • Not telling apart pools with the same pair name. They have different versions, depth, and fees, and sometimes a fake token with the same ticker.

Reading the order book together with clusters is shown in the free lesson of the same course.

This material is educational and does not contain investment recommendations.

FAQ

  • AMM: what is it in simple terms?

    An automated market maker is a smart contract that holds a supply of tokens and swaps them by a formula, with no order book and no second trader. The price is set by the ratio of reserves in the pool, and it changes after every swap. The pool is filled by liquidity providers, who earn a share of the fees for it.

  • What does the x*y=k formula mean?

    The product of the two assets' reserves in the pool stays constant after a swap. That's why a large trade moves the price by itself: buying 10% of the reserve costs about 11% more than the quote. This is the basic model without fees, and it describes some of the existing AMMs, but not all of them.

  • Can you lose money providing liquidity?

    Yes. Tokens in a pool can drop in price just like in a wallet, and impermanent loss adds a shortfall versus simple holding: with a 2x price divergence that's 5.72%, with 4x it's 20%. Fees work in the opposite direction and may cover it, or may not. Separately, there's the risk of the contract itself, where you can lose the entire position.

  • Will impermanent loss disappear if the price comes back?

    If the price ratio returns to the entry level, the shortfall shrinks to zero. On withdrawal, it's locked in at whatever size it is at that moment. So the wording "impermanent loss" is accurate only until you exit the pool.

  • Why is there so much slippage on a DEX?

    The trade itself moves the price. In a 10 ETH pool, buying one ETH costs 11% more than the quote, while in a 1000 ETH pool the same purchase gives a premium of 0.1%. The precise name for this effect is price impact, and slippage is the difference between the estimated and the actual price if the pool changed while the transaction was waiting for a block.

  • How is concentrated liquidity different from a regular pool?

    The provider sets a price range within which their capital works, and earns more fees there on the same amount. Outside the range, the position turns entirely into one asset and stops collecting fees. From the outside it looks like a limit order, but if the price comes back into the range, the swap reverses: the position has to be closed with a separate transaction.

  • Is an AMM suitable for scalping?

    In its classic form, no. Scalping needs millisecond execution, free order cancellation, and an order book in front of your eyes. In a pool, a trade waits for a block, there are no orders at all, and the flow of trades is visible only in batches. Add gas and MEV, which eat up small profits, so reading the order book and the tape stays on centralized venues.

In a pool, the price is calculated by a formula, while on an exchange it's formed from the orders in the order book. Secret Terminal shows this part of the market: the order book with a density map, the tape, cluster analysis, and a trade journal. You can trade through it on Binance, Bybit, OKX, MEXC, WhiteBIT, Kraken, and BloFin. The terminal is free and runs on Windows. Download it from the official website, connect your exchange, and see how much is visible before you enter a trade.

Was helpful

Your rating will help us improve the quality of published materials and increase their usefulness.