Automated Market Makers Explained: The Math Behind x*y=k

DeFi & On-chain
Cập nhật2026-11-09
2,4K

An AMM (Automated Market Maker) is an on-chain trading mechanism that does not rely on a traditional order book: users swap tokens directly against a liquidity pool. Its most classic model is the x*y=k constant product formula, which adjusts prices automatically as the amounts of the two assets in the pool change, so buyers and sellers can trade without ever being matched with each other.

1. What exactly is an AMM?

Traditional centralized exchanges usually run on an order book.

Say ETH is trading at 3,000 USDT and you want to buy ETH. Someone in the market has to be willing to sell ETH at that price, and the exchange's matching engine finds the two sides and fills the order.

An AMM works on completely different logic.

It never asks you to find a matching seller. Instead, the two assets sit in a liquidity pool (Liquidity Pool), and when you trade you are effectively swapping against that pool.

For example, an ETH/USDC liquidity pool holds both ETH and USDC:

ETH + USDC → Liquidity Pool → Trader Swap

When you buy ETH with USDC, the pool's USDC grows and its ETH shrinks; selling ETH does the opposite.

The price is not set by hand by some trader. It changes automatically according to the amounts of assets in the pool and the AMM formula.

That is the core of automated market making.

Uniswap is one of the most representative AMM applications. To go deeper into its most important real-world use, continue with Uniswap Explained: The Evolution of a DEX Leader.

2. What does x*y=k mean?

The single most important formula for understanding a classic AMM is:

x × y = k

Where:

  • x = the amount of Token A in the liquidity pool

  • y = the amount of Token B in the liquidity pool

  • k = the constant product

For example, an ETH/USDC pool holds:

  • 10 ETH

  • 30,000 USDC

Therefore:

10 × 30,000 = 300,000

So:

k = 300,000

When a user buys ETH, the pool's ETH drops and its USDC rises. After the trade, the two new amounts must still satisfy the same constant product relationship.

That is the basis on which an AMM adjusts prices automatically.

Keep in mind that real trades also involve fees, so on-chain math does not simply plug the input amount straight into x*y=k. The classic Uniswap v2 model accounts for the swap fee first, and then calculates how many tokens the user receives.

Lark document - image

3. How does an AMM price assets automatically with a formula?

This is the most interesting part of an AMM:

Nobody has to tell the pool what ETH "should" cost right now — the pool's asset ratio itself forms the price.

Let's continue with the earlier example.

The pool holds:

10 ETH + 30,000 USDC

Before any trade, the simple in-pool price can be read as:

30,000 ÷ 10 = 3,000 USDC/ETH

Now suppose someone buys ETH with USDC, so the pool's ETH drops.

If only 9 ETH remain after the trade, then to maintain:

x × y = 300,000

the USDC amount has to reach:

300,000 ÷ 9 ≈ 33,333 USDC

In other words, as ETH is bought out, ETH in the pool shrinks while USDC grows, so the in-pool price of ETH keeps rising.

Conversely, if many users sell ETH, the pool's ETH grows and USDC shrinks, and the in-pool price of ETH falls.

So the price movement in an AMM can be summarized simply:

More buying → the token becomes scarcer in the pool → in-pool price rises

More selling → the token becomes more abundant in the pool → in-pool price falls

This is also the biggest difference between an AMM and a fixed-rate exchange.

4. Understanding x*y=k with a concrete example

Suppose we have a simulated pool made up entirely of two assets:

  • 10 ETH

  • 30,000 USDC

  • k = 300,000

Now a user wants to buy ETH with 3,000 USDC.

To keep it simple, ignore fees for now.

After the trade, the pool's USDC becomes:

30,000 + 3,000 = 33,000 USDC

From:

x × 33,000 = 300,000

we get:

x ≈ 9.09 ETH

The pool originally held 10 ETH, so the user receives roughly:

10 - 9.09 = 0.91 ETH

The user pays 3,000 USDC and gets about 0.91 ETH.

So the average execution price of this trade is roughly:

3,000 ÷ 0.91 ≈ 3,297 USDC/ETH

Notice that the in-pool price before the trade was 3,000 USDC/ETH, yet the user's average execution price already reached about 3,297 USDC/ETH.

This is a very important concept in AMMs:

A trade itself changes the pool's price.

And the larger the trade relative to the pool's liquidity, the more visible the price impact usually is. Uniswap's own documentation defines this change, caused by trade size relative to liquidity depth, as Price Impact.

The calculations above are simplified examples for illustration and do not represent any actual market quote.

5. Why do large trades usually fill more easily in deeper liquidity?

Think of an AMM as a pool of water.

A small pool holds only 10 ETH and 30,000 USDC, so if someone suddenly spends 10,000 USDC buying ETH, the effect on the pool is very obvious.

But if another pool holds:

1,000 ETH + 3,000,000 USDC

the same 10,000 USDC trade is a tiny share of the whole pool, and the price impact is usually far smaller.

So a very important relationship holds in AMMs:

Deeper liquidity → the same trade size usually causes less price impact

Shallower liquidity → the same trade size usually causes more price impact

That is why professional traders do not look only at a token's "current price" — they also watch the liquidity depth of the relevant trading pool.

6. Why does the price in an AMM keep changing?

Because every trade changes the pool's asset ratio.

Suppose:

10 ETH + 30,000 USDC

After someone buys ETH:

ETH ↓

USDC ↑

The pool's ETH/USDC ratio has changed, and a new price follows from it.

If many users buy ETH in a row:

ETH ↓↓↓

USDC ↑↑↑

the in-pool price of ETH keeps climbing.

Conversely, if many users sell ETH:

ETH ↑↑↑

USDC ↓↓↓

the in-pool price of ETH keeps falling.

So an AMM never has a price that stays fixed forever.

More precisely:

The price is a real-time result of the pool's state.

This is another key difference between an AMM and a traditional fixed-quote system.

7. Why can an AMM's price differ from the outside market?

This is a common question the first time newcomers meet an AMM.

Suppose a token trades at 100 USDT on the outside market, but trading activity has pushed the implied price in a particular AMM pool to 103 USDT.

Such a gap usually does not last.

If arbitrageurs spot that:

DEX: 103 USDT

Other markets: 100 USDT

they can buy in the cheaper market and sell in the more expensive one.

A large volume of arbitrage trades changes the pool's asset ratio, gradually pulling the in-pool price back toward the outside market price.

Therefore:

Arbitrage is not an anomaly in AMMs — it is an essential part of on-chain price discovery.

Of course, whether arbitrage is actually worth executing also depends on costs such as gas, trading fees, slippage and trade size.

8. Where do AMM fees come from?

An AMM has to solve not only "how do people trade" but also another question:

Why would anyone put their assets into a liquidity pool?

One answer is trading fees.

Liquidity providers — LPs (Liquidity Provider) — supply assets to the pool so that other users can trade against it.

Whenever a trade happens, the protocol charges a Swap Fee according to that pool's rules, and part or all of it goes to active liquidity providers under those rules. Fee mechanics are not identical across Uniswap versions and individual pools.

In the classic Uniswap v2, a pool's base Swap Fee was 0.30%. The protocol's fee mechanics have since changed, so it is no longer accurate to treat "0.30% entirely as LP income" as the actual distribution for every v2 pool today.

So when thinking about AMM returns, keep these three steps distinct:

Traders pay fees

↓

The protocol handles fees according to its rules

↓

Eligible LPs receive their share

Higher fee income does not automatically mean an LP profits, because LPs also carry risks such as price volatility.

9. Why can providing liquidity lead to impermanent loss?

This is one of the most easily overlooked issues in AMMs.

Suppose you provide to an ETH/USDC pool:

1 ETH + 3,000 USDC

At that moment ETH = 3,000 USDC.

If ETH then rallies sharply, the AMM automatically rebalances the pool's ETH and USDC through trading.

As the ETH price rises, arbitrageurs keep buying ETH out of the pool.

In the end, your share of the pool may become:

less ETH + more USDC

In other words, once you provide liquidity, your asset mix adjusts automatically as market prices move.

If you withdraw at that point and compare with simply holding the original ETH + USDC, a value difference may appear.

This is impermanent loss (Impermanent Loss).

Therefore:

Receiving fees ≠ a guaranteed net profit.

The final result has to account for:

Fee income + token price changes + impermanent loss + costs such as gas

This is one of the biggest differences between an AMM and simply holding assets.

10. Why is Uniswap v3 no longer simply "x*y=k for the whole pool"?

Many articles reduce AMMs to:

x*y=k

That understanding is essential for learning about classic AMMs, but applying it directly to every AMM today is not accurate enough.

Uniswap v2 uses the classic constant product model, while Uniswap v3 introduced concentrated liquidity (Concentrated Liquidity).

Put simply:

v2:

Liquidity is spread across the entire price range

v3:

LPs can concentrate liquidity into a price range of their choosing

For example, an LP can pick a specific price range and provide denser liquidity inside it.

The benefit is better capital efficiency: the same amount of capital can provide deeper liquidity within the effective price range.

The cost is equally clear:

LPs have to manage their price ranges.

If the market price leaves the range an LP set, that portion of liquidity may no longer be in the active trading range, so it stops earning swap fees in the normal way until the price returns to that range.

So modern AMMs have evolved from simply "putting two tokens into a pool" into far more complex liquidity management systems.

11. Why is an AMM more than just one formula?

x*y=k matters, but it is only the entry point to understanding a classic AMM.

A complete AMM actually contains at least:

Liquidity Pool

Determines how many tradable assets exist in the market.

Pricing Formula

Determines how assets are priced from the pool's state.

Swap Fee

Determines what traders pay and how LPs earn income.

Liquidity Provider

Supplies liquidity for trading.

Arbitrage

Helps prices across different markets converge again.

Smart Contract

Executes trades according to preset rules.

So a single AMM trade actually goes through:

User submits a swap

↓

The smart contract reads the pool state

↓

The pricing mechanism computes the output amount

↓

The relevant fee is deducted

↓

The pool's asset ratio is updated

↓

A new in-pool price is formed

This mechanism can run entirely automatically on-chain, with no manual matching by a traditional exchange.

12. How does an AMM differ from an order book model?

Embedded document table

There is no absolute answer to which model is "more advanced".

The AMM's strengths are an open mechanism, a high degree of automation, and letting users interact directly with on-chain liquidity; an order book offers finer control over prices and order management.

For different assets and different market conditions, each mechanism has its own appropriate use.

Lark document - image

13. The 5 most common beginner mistakes about AMMs

1. Believing x*y=k means the price never changes

In fact the opposite is true.

k is the constant product, while the token's price moves as the ratio of x to y changes.

2. Believing the pool's price is the true price of the whole market

An AMM is just one market.

Price differences can appear across different DEXs, different pools and centralized platforms.

3. Believing more liquidity means there is no risk

Deep liquidity can reduce the price impact of certain trades, but it cannot eliminate risks such as smart contract issues, price volatility and impermanent loss.

4. Believing an LP that collects fees is necessarily profitable

An LP's final outcome depends on both fee income and changes in asset prices.

5. Believing all AMMs use exactly the same x*y=k

The classic Uniswap v2 uses the constant product model, but modern AMMs have developed designs such as concentrated liquidity, stablecoin curves and weighted pools.

14. How can regular users judge whether an AMM pool is worth trading in?

If you are only doing a token swap, check these indicators first:

First, look at liquidity.

The shallower the pool, the more likely a large trade will move the price noticeably.

Second, look at your trade size.

Do not look only at the token's current quote — look at what share of the pool's liquidity your trade amount represents.

Third, look at Price Impact.

If an ordinary-sized trade already produces a very high Price Impact, be careful about whether the pool is deep enough.

Fourth, look at the fees.

Different AMMs and different pools may have different fee structures.

Fifth, look at the token itself.

A liquidity pool does not automatically guarantee that a token is safe or valuable. You still need to verify the token contract, the project's origin and any trading restrictions.

Sixth, look at the final trade conditions.

Before submitting, confirm the expected amount received, the minimum amount received, gas and other trade parameters.

FAQ: Common questions about AMMs

What does AMM mean?

AMM stands for Automated Market Maker. It uses smart contracts and liquidity pools to price and trade assets automatically, instead of relying on traditional order book matching.

Why can x*y=k be used for trading?

Because when a user takes one token out of the pool, they must add the other token, keeping the pool's constant product relationship satisfied. As the amounts of the two tokens change, the in-pool price changes automatically as well.

What does k mean in an AMM?

k is the invariant in the constant product model. In the most basic model, x and y are the amounts of the two assets in the pool and their product forms k. Real protocols also factor in rules such as fees when calculating.

Why can larger trades mean higher slippage or price impact?

Because a trade itself changes the pool's asset ratio. When the trade amount is large relative to the pool's depth, the effect on the in-pool price is usually more pronounced.

Is providing AMM liquidity guaranteed to be profitable?

No. An LP can earn swap fees under the pool's rules, but also takes on risks such as asset price changes, impermanent loss, smart contract risk and liquidity risk.

Is Uniswap v3 still an AMM?

Yes. Uniswap v3 is still an AMM, but compared with the classic v2 it uses concentrated liquidity, letting LPs choose specific price ranges. That makes capital use more flexible — and also more complex.

Summary: x*y=k is the starting point for understanding AMMs, not the finish line

The most classic expression of an AMM is:

x × y = k

It solves a complex problem with a simple mathematical relationship:

Without a traditional order book or manual matching, how do on-chain users trade assets?

The answer is:

Liquidity pool + pricing formula + smart contract + LP

User trades change the pool's asset ratio, and the changing ratio changes the price; arbitrageurs help prices converge across markets; LPs earn their share of fees by providing liquidity.

From Uniswap v2's classic constant product model, to v3's concentrated liquidity, to newer AMM architectures, the AMM has grown from a simple mathematical formula into complex on-chain trading infrastructure.

So truly understanding AMMs should not come down to remembering a single phrase, "x*y=k".

What matters more is understanding the full relationship:

Liquidity → pricing → trading → price impact → fees → arbitrage → LP returns and risks

Once you grasp this chain of logic, you can genuinely see why a trade in a DEX produces the price it does, and go on to understand how mainstream DEXs such as Uniswap operate.

Risk notice: AMM and DeFi activities may involve risks such as crypto asset price volatility, insufficient liquidity, smart contract vulnerabilities, token contract risk, impermanent loss, trade execution deviation and network fees. This article is for learning about blockchain technology and DeFi only and does not constitute any investment or trading advice.

The calculations above are simplified examples for illustration and do not represent any actual market quote.

Mục lục

Đề xuất đọc

Xem thêm
Top GameFi Projects to Watch in 2025
Top GameFi Projects to Watch in 2025
DeFi & On-chain
Slippage and MEV: The Hidden Costs of DEX Trading
Slippage and MEV: The Hidden Costs of DEX Trading
DeFi & On-chain
Restaking: EigenLayer and Shared Security
Restaking: EigenLayer and Shared Security
DeFi & On-chain