Skip to main content

What Is an Automated Market Maker (AMM)? How the Formula Sets Prices

An AMM is a smart contract that prices token swaps with a formula over a pool of reserves. How x·y=k works, worked examples, and the risks for LPs.

· By ZIPMEX · 22 min read

An automated market maker (AMM) is a smart contract that holds a pool of two or more tokens and quotes prices with a fixed formula. There is no order book. When you swap, you trade against the pool's reserves and not against another person. After each trade the formula moves the price. People called liquidity providers (LPs) fund the pool and earn the trading fees, and they carry the risk that the pool's mix of tokens shifts against them.

Vitalik Buterin described the idea in his June 2017 post "On Path Independence". There he called on-chain market makers "fully automated on-chain mechanisms that act as always-available counterparties" and named the constant-product design his favourite. He credited that design to Martin Köppelmann.

How an AMM swap works

  1. You send token A to the pool contract and name the minimum amount of token B you will accept. That minimum is your slippage tolerance.
  2. The contract reads both reserves and works out the output from its conservation function.
  3. If the output meets your minimum, token A goes into the pool and token B goes to your wallet in the same transaction. A fee stays in the pool for the LPs.
  4. The reserves are now different, so the next trader gets a different price.

On Ethereum, time is divided into 12-second slots. A swap settles when its transaction is included in a block.

The constant product formula: x · y = k

In a constant-product pool, x is the reserve of token A and y is the reserve of token B. A trade must leave their product k unchanged, not counting fees. The spot price is the ratio of the reserves, y/x.

Worked example (fees ignored)

StepValue
Pool10 ETH and 20,000 USDC
k10 × 20,000 = 200,000
Spot price2,000 USDC per ETH
Buy 1 ETH: ETH left9
USDC needed in pool200,000 ÷ 9 = 22,222.22
USDC paid2,222.22
Price impact11.1% above the pre-trade spot price

Price impact grows with the size of a trade relative to the pool. The same 1 ETH purchase from a pool 100 times deeper moves the price only a fraction of a percent. Before a large swap, check the pool's liquidity. DeFi Llama is one public tracker of DeFi liquidity.

Slippage and sandwich attacks

Slippage is the gap between the price you are quoted and the price you get. It has two causes: your own price impact, and other trades that land before yours. A wide slippage tolerance can be exploited. Ethereum.org's MEV documentation says a searcher may "watch the mempool for large DEX trades", buy just before the trade and sell right after it. It adds that "users who are sandwiched face increased slippage and worse execution." A tight tolerance limits that exposure. On thin pools, though, a tight tolerance means more failed swaps.

Main AMM designs

The academic survey "SoK: Decentralized Exchanges (DEX) with Automated Market Maker (AMM) Protocols" (Xu, Paruch, Cousaert, Feng; ACM Computing Surveys, 2023) compares the main designs:

DesignHow it pricesSuited toTrade-off
Constant productx · y = kVolatile pairsPrice impact rises quickly on large trades
Constant sumx + y = kAssets meant to trade 1:1Can be fully drained of one asset if the peg breaks
Hybrid (stableswap)Mixes constant-sum and constant-productAssets with the same peg, such as stablecoinsWeaker fit for assets that drift apart
Weighted poolsConstant product with custom weights, can hold more than two assetsIndex-style basketsMore complex to manage
Concentrated liquidityLPs place liquidity "on a fraction of the bonding curve"Using capital where trading happensLPs must manage price ranges; out-of-range liquidity earns no fees

A ledger-level AMM: the XRP Ledger

Not every AMM is a separate application. The XRP Ledger built one into the protocol, and its AMM amendment went live on mainnet on 22 March 2024. Its documentation says it "implements a geometric mean AMM with a weight parameter of 0.5," which behaves like a constant-product pool. Each pool holds two assets. LP token holders can "vote to set the fee from 0% to 1%, in increments of 0.001%."

How much does a price move cost an LP?

Enter how far one asset's price has moved against the other since you deposited to see the divergence loss against simply holding, before fees.

Worked examples (loss vs holding = 2√r ÷ (1 + r) − 1, where r is the price ratio between withdrawal and deposit)
Price ratio of one asset against the other, withdrawal vs deposit (×)Divergence loss versus holding the deposit, before fees
2 ×-5.72 %
1.25 ×-0.62 %
1.5 ×-2.02 %
0.5 ×-5.72 %
4 ×-20 %
  • The formula applies only to a 50/50 constant-product pool, as the article explains.
  • The price ratio is your own scenario, not a forecast from any source.
  • The result is measured against simply holding the original deposit and leaves out trading fees and any reward tokens.

This shows divergence loss for a 50/50 constant-product pool only: it ignores fees, rewards, gas, arbitrage losses and other pool designs such as concentrated liquidity, and says nothing about where prices will go.

Liquidity providers: fees, LP tokens and losses

LPs deposit both assets of a pool. In return they receive LP tokens, which represent their share of the reserves. Redeeming LP tokens returns that share of the pool at its current mix, with the fees it has collected. Some pools also pay reward tokens on top of fees. Those rewards depend on the price of the reward token, so they are a separate and less stable source of return than trading fees.

Impermanent (divergence) loss

When prices move, arbitrageurs trade against the pool until its price matches the wider market. This leaves LPs holding more of the asset that fell and less of the asset that rose. The SoK paper calls this divergence loss: the pool position's value divided by the value of simply holding the deposit, minus one.

Example: you deposit 1 ETH and 2,000 USDC at 2,000 USDC per ETH, a total of 4,000 USDC. ETH then rises to 4,000 USDC. The pool rebalances to about 0.7071 ETH and 2,828.43 USDC, worth about 5,656.85 USDC. Holding the original deposit would be worth 6,000 USDC. The gap is about 343 USDC, or 5.72%, before fees.

For a 50/50 constant-product pool, the loss depends only on the price ratio r between withdrawal and deposit. The formula is 2√r ÷ (1 + r) − 1:

Price change of one asset vs the otherLoss vs holding
×1.25−0.62%
×1.5−2.02%
×2 or ×0.5−5.72%
×4−20.0%

The loss is called "impermanent" because it shrinks if the price returns to where it started. Once you withdraw, it is fixed. Pools of pegged assets see little divergence while the peg holds.

Fees versus arbitrage losses

A 2022 paper, "Automated Market Making and Loss-Versus-Rebalancing" (Milionis, Moallemi, Roughgarden, Zhang), splits LP returns into two parts. One is market exposure. The other is "accrued fees minus losses to arbitrageurs." In one large constant-product ETH-USDC pool the authors studied, over 99.991% of the variance in LP returns came from market exposure. In other words, fee income can be eaten up by arbitrage, and most of an LP's outcome depends on where prices go.

Other risks

  • Smart contract risk. The pool is code. Bugs or flaws in how it connects to other contracts can lose funds. An audit lowers this risk but does not remove it.
  • Gas costs. The Ethereum documentation says fees rise when demand is high and users "must offer higher tip amounts" to get included. It also says Layer 2 scaling is "a primary initiative to greatly improve gas costs." On a small swap, gas can be a large share of the cost.
  • Fake tokens. Anyone can create a pool for any token, including copies of real ones. Check the contract address against the project's official sources before you swap.

Frequently asked questions

What is an AMM in simple terms?

A smart contract that holds token reserves and sets the swap price with a formula, so you trade against a pool instead of another person.

Why does a large trade get a worse price?

Every unit you take out of the pool changes the reserve ratio. That moves the price against you during your own trade.

Do liquidity providers always profit from fees?

No. Divergence loss and arbitrage can cost more than the fees earned, and price moves drive most of an LP's result.

Which AMM design has the lowest slippage?

For assets with the same peg, hybrid stableswap designs. For volatile pairs, slippage depends mostly on how deep the pool is and, in concentrated-liquidity pools, on how much liquidity sits near the current price.

Limitations: the fee figures and pool behaviour described here vary by protocol and chain, and nothing in this article is investment advice.

Updated on Oct 25, 2026