Intermediate · 10 min read

How Automated Market Makers (AMMs) Work Under the Hood

No order book, no market makers standing by — just a formula and a pool of reserves. Here's the mechanics behind the constant-product curve that prices most of DeFi.

Dario FennDario FennDeFi & Markets Lead · DeFi protocols, yield, market structure and on-chain data
How Automated Market Makers (AMMs) Work Under the Hood
The short answer

An automated market maker replaces the order book with a formula over pooled reserves. Under the constant-product rule the product of the two balances stays fixed, so buying pushes the price up as your order consumes liquidity — which is why large trades cost more and why the price impact depends on pool depth rather than on the token's market capitalisation. Arbitrageurs keep the pool aligned with the wider market, and their profit comes out of liquidity providers' returns.

Automated market makers replaced the order book with a formula, and that single design choice is what made permissionless, always-on trading possible in DeFi. There's no buyer waiting to match your sell order on a Uniswap pool — there's a pot of two assets and a piece of maths that decides the price on the spot, every time, for anyone who shows up. Understanding that formula is the fastest way to understand why AMMs behave the way they do: why big trades move price more than small ones, why liquidity providers get paid, and why arbitrageurs are quietly doing useful work in the background the whole time.

The Problem AMMs Solve

A traditional exchange needs buyers and sellers actively placing orders at every moment, plus market makers willing to quote both sides continuously to keep the book liquid — infrastructure that's expensive to run and hard to bootstrap for a brand-new asset with no existing trading interest. An automated market maker sidesteps all of that. Anyone can deposit two assets into a pool, and the pool itself becomes the counterparty to every trade, quoting a price algorithmically based on nothing but its own reserves. No order matching engine, no market maker desk, no minimum trading volume required to function.

The Constant-Product Formula

The formula behind Uniswap and most of its imitators is deceptively simple: x × y = k, where x and y are the quantities of the two tokens held in the pool, and k is a constant that the formula holds fixed across every trade. When someone buys token Y with token X, they're adding to the X side of the pool and removing from the Y side — and because x × y must stay equal to k, removing some Y forces the price of the remaining Y to rise. The pool literally cannot run out of an asset entirely, because the formula makes each additional unit exponentially more expensive to buy as the reserve thins out.

Worked Example: Pricing a Trade

Say a pool holds 10 ETH and 20,000 USDC, giving k = 200,000 and an implied ETH price of 2,000 USDC. A trader wants to buy 1 ETH. After the trade, the pool must hold 9 ETH, so y must satisfy 9 × y = 200,000, meaning y = 22,222.2 USDC — an increase of 2,222.2 USDC from the starting 20,000. That trader effectively paid 2,222.2 USDC for 1 ETH, not 2,000, because removing ETH from a pool with only 10 ETH to begin with moves the price meaningfully. Buy another ETH straight after and the price for that second unit is higher still, since the pool now holds only 9 ETH rather than 10.

Slippage and Why Big Trades Cost More

That gap between the quoted starting price and the actual average price paid is slippage, and it's baked directly into the curve rather than being some separate fee. The smaller the pool relative to the trade size, the steeper the curve and the worse the slippage — which is exactly why large trades get routed across multiple pools or executed through aggregators that split an order to minimise the average price impact, and why a token with thin liquidity can see wild price swings on comparatively modest buy or sell orders.

Liquidity Providers and the Pool's Other Side

None of this works without liquidity providers willing to deposit both assets into the pool in the first place. In return, they earn a cut of every trade that passes through — typically 0.05% to 1% of the trade size, depending on the pool and platform — proportional to their share of the total reserves. This is the mechanism that turns idle token holdings into yield, and it's also the exact mechanism behind impermanent loss: the pool automatically rebalances LPs' holdings as prices move, which is what makes it function as a market maker at all.

Arbitrage: How the Pool Stays Priced Correctly

An AMM pool has no independent way of knowing the 'real' market price of an asset — it only knows its own reserves. If ETH moves on centralised exchanges but a given pool hasn't seen a trade yet, its price will lag behind, and that gap is closed by arbitrageurs who buy the cheaper asset from the pool and sell it elsewhere, or vice versa, until the pool's implied price matches the wider market. This constant arbitrage activity is what keeps AMM prices honest, and it's also a quiet, continuous tax on liquidity providers, since every arbitrage trade that corrects the pool's price is, by definition, profitable for the arbitrageur and a small loss for the LPs on the other side.

Beyond Constant Product: Other Curve Designs

The plain x × y = k formula isn't the only curve in use. Curve Finance uses a modified formula, sometimes called stableswap, that flattens the curve near a 1:1 price ratio — ideal for stablecoin pairs or pegged assets, where trades near parity should barely move the price at all, while still falling back to a constant-product-style curve further from parity to prevent the pool being drained. Uniswap v3 took a different approach with concentrated liquidity, letting LPs choose to deploy their capital only within a specific price range rather than across the entire curve from zero to infinity, which dramatically increases capital efficiency for pairs that trade within a predictable band but requires active management as prices move outside that range.

The Trade-offs Baked Into the Design

Every AMM design is a trade-off between simplicity, capital efficiency and risk. Constant-product pools are simple and always liquid at any price, but capital-inefficient, since much of the pool's depth sits at prices that will realistically never trade. Concentrated liquidity fixes the capital efficiency problem but pushes more of the pricing risk and active management burden onto LPs. Stableswap curves are excellent for pegged assets and terrible for volatile ones. None of this is a flaw to be engineered away — it's the underlying tension every AMM design has to resolve, and the reason the space keeps producing new curve shapes rather than settling on one.

Reading a Pool's Depth Before You Trade

Most trading interfaces built on top of AMMs will show an estimated price impact before a trade is confirmed, calculated directly from the curve formula and the pool's current reserves — it's worth actually looking at that number rather than clicking straight through, since a 3% price impact on a routine trade is a clear signal that the pool is thin relative to the size being traded, and that either splitting the order or routing through an aggregator that sources liquidity across several pools would get a meaningfully better fill. The same reserves data that determines price impact is public on-chain information, which is why on-chain analytics tools can show, in real time, exactly how much a given trade size would move a given pool, well before it happens.

Why This Matters Beyond Trading

The constant-product formula isn't just a trading mechanism — it's become a building block used well outside simple swaps. Lending protocols reference AMM prices as oracle inputs, options and perpetuals platforms build on top of AMM-style pricing curves for their own instruments, and new token launches routinely use an AMM pool as the very first price discovery mechanism a token ever has, before any centralised exchange lists it. Understanding the curve mechanics, in other words, isn't just useful for the specific act of swapping one token for another; it's close to a prerequisite for understanding how a large share of on-chain finance actually prices anything at all.

Once the formula clicks, most of what looks strange about DeFi trading stops looking strange: why a token can be listed and tradeable within minutes of a pool being created, why prices on thin pools jump around so much more than on centralised exchanges, and why providing liquidity is a genuinely different activity from simply holding an asset, with its own separate risk and reward profile attached.

FAQ

How does an automated market maker set prices?
From the ratio of assets in the pool. The constant-product formula keeps the product of the two reserves fixed, so buying one asset raises its price as reserves shift.
Why do large trades cost more on an AMM?
Because your own order moves the reserve ratio as it executes. The bigger the trade relative to pool depth, the further the price moves against you.
Who keeps AMM prices in line with the market?
Arbitrageurs. When a pool drifts from the wider market, trading it back to parity is profitable, and that profit comes out of liquidity providers' returns.
Are all AMMs constant-product?
No. Stable-swap curves concentrate liquidity near parity for correlated assets, and concentrated liquidity lets providers choose a price range, which changes the economics considerably.