Skip to content
Education

How Does the x·y=k Formula Work in Uniswap, and Why Should Investors Understand It?

Main takeaways

  • In a constant-product pool, larger trades relative to the reserves get a worse average price.
  • When prices move, the pool rebalances an LP's tokens, which can underperform simply holding them.
  • Fees may offset divergence loss, but the formula does not predict prices, volume, or net returns.
A green glass sphere resting on a pearl-silver block with a curved hyperbolic top, beside a second sphere on the floor
On this page

A small formula helps explain something that often surprises people using Uniswap: the price you see is not always the price you receive. It also explains why liquidity providers can end up holding different amounts of tokens even when they have not made a single trade themselves.

The formula is x·y=k. It powered the original Uniswap market maker and remains a useful starting point for understanding decentralized exchanges. You do not need advanced mathematics to use it. A few numbers can show what happens during a swap, why liquidity matters, and how market movements affect an investor's position.

We will use one imaginary ETH/USDC pool and two separate scenarios. One is a token swap; the other is a rise in ETH's market price. Both start from the same reserves. To make the mechanism visible, we initially ignore trading fees. Real trades and real LP returns include fees and other costs.

1. What Does x·y=k Mean in Uniswap?

On a traditional exchange, buyers and sellers place orders. In Uniswap, a trader can instead exchange tokens with a pool: a smart contract that holds two tokens supplied by other users. This mechanism is called an automated market maker (AMM). The amounts held by the pool are its reserves.

Uniswap V1 and V2 use the constant-product rule to link those reserves:

x × y = k

Here, x and y are the two token reserves. Their product, k, stays unchanged during a swap in our simplified example without fees.

Imagine a pool containing 10 ETH and 20,000 USDC. Its constant product is:

10 × 20,000 = 200,000

When someone adds ETH to the pool and takes USDC out, the USDC reserve falls. The formula determines how much can be withdrawn. Taking out more USDC becomes progressively more expensive.

The starting reserves imply a current pool price of 2,000 USDC per ETH. That is the rate for a very small trade. A larger trade changes the balance and therefore gets a different average price.

Let's see what that means in practice.

2. How Does the Formula Determine Swap Prices?

Scenario A: selling 1 ETH

Scenario A begins with 10 ETH and 20,000 USDC, with fees excluded. A trader sells 1 ETH into the pool. Its ETH reserve rises to 11, so the formula gives the new USDC reserve:

200,000 ÷ 11 ≈ 18,181.82 USDC

The trader receives the difference:

20,000 − 18,181.82 ≈ 1,818.18 USDC

The initial pool price was 2,000 USDC per ETH, but the trader received about 1,818.18 USDC per ETH on average—9.09% less than the starting price, before fees. Selling 1 ETH is a large trade relative to this pool's 10 ETH reserve, so the price changes during execution.

After the swap, the pool's current price is lower still, about 1,652.89 USDC per ETH. The important comparison is between the starting price and what the trader actually receives.

This difference reflects price impact: the effect of a trade on its own execution price. Generally, the same trade has less impact in a deeper pool.

Diagram: the x·y = 200,000 curve; selling 1 ETH moves the pool from 10 ETH and 20,000 USDC to 11 ETH and about 18,181.82 USDC, an average price of 1,818.18 USDC per ETH versus 2,000 at the start

What about market prices?

The formula follows the reserves, not an external price feed. When ETH is cheaper in this pool than elsewhere, arbitrage traders may buy it here and sell it at the higher price. These trades move the pool price toward the wider market.

The prices need not match exactly: fees and execution costs can make small differences unprofitable to correct.

Real swaps also have fees, so the output is lower than in this fee-free example. One more distinction matters: price impact comes from the trade itself, while slippage is the difference between an expected quote and the actual execution. The pool can move between quoting and execution.

A quoted pool price alone is not enough to evaluate a trade. The expected token output matters more.

3. What Happens to Liquidity Providers When Prices Change?

Every swap changes the pool's reserves. But what does that mean for the people who supplied those tokens?

For Scenario B, we return to the original 10 ETH and 20,000 USDC. This is a separate example, not a continuation of the 1 ETH sale.

A liquidity provider (LP) deposits tokens and owns a share of the pool. That share gives the LP a changing mix of ETH and USDC rather than fixed token amounts.

Suppose ETH starts at a market price of 2,000 USDC and later rises to 4,000 USDC. Arbitrage traders can buy ETH from a pool that still prices it too cheaply, paying USDC into the pool. As they trade, the pool holds less ETH and more USDC.

With no fees and no added or withdrawn liquidity, the reserve product stays 200,000. At a new pool price of 4,000 USDC per ETH, the reserves satisfy y = 4,000x and x × y = 200,000. So x² = 50, giving approximately:

7.071 ETH and 28,284 USDC

The new reserves imply roughly 4,000 USDC per ETH, matching the assumed market price.

When ETH rises relative to USDC, arbitrage trades tend to leave the pool with less ETH and more USDC.

The LP did not place a sell order. Other traders changed the reserves. Someone who consistently owns 10% of this pool owns 10% of the new amounts.

Holding a share of a pool is therefore different from holding fixed amounts in a wallet.

4. How Does x·y=k Affect LP Returns and Risks?

Now we can measure the financial effect of that change.

In Scenario B, ETH has doubled to 4,000 USDC. The pool holds about 7.071 ETH and 28,284 USDC.

At 4,000 USDC per ETH, the value of the pool's ETH is about 28,284 USDC. Together with the USDC reserve, the total is approximately 56,569 USDC.

Compare this with someone who simply held the initial 10 ETH and 20,000 USDC in a wallet:

10 ETH × 4,000 USDC + 20,000 USDC = 60,000 USDC

In this fee-free illustration:

  • Liquidity pool value: approximately 56,569 USDC.
  • Value from holding the starting assets: 60,000 USDC.
  • Difference: approximately 3,431 USDC, or 5.72% less than holding.

This shortfall relative to holding the initial tokens is called impermanent loss (or divergence loss).

The pool still gained in dollar value—from 40,000 to about 56,569 USDC. Impermanent loss means underperforming the hold benchmark, not necessarily losing dollars.

If ETH had moved in the opposite direction, the pool's composition would have shifted toward ETH instead, and divergence loss could also arise. The more the relative price moves away from the starting ratio, the more pronounced the effect becomes in the simplified full-range model.

Diagram: after ETH doubles to 4,000 USDC, the fee-free LP position is worth about 56,569 USDC versus 60,000 USDC from holding, a divergence loss of about 3,431 USDC or 5.72%

Where do fees fit in?

Liquidity providers can earn fees when traders swap. Fees may offset part or all of the divergence loss. They can also be insufficient. The answer depends on trade volume, pool fees, how long the position is held, market movements, and other costs.

The formula explains the change in token balances, but not future prices, trading volume, or net LP returns.

The word “impermanent” can mislead. The shortfall exists while the position is still in the pool and may shrink if the price ratio moves back. Withdrawing liquidity ends the pool exposure at the then-current token amounts; it does not create the shortfall for the first time.

5. How Can Investors Use This Knowledge?

Use the formula as a decision aid, not a market forecast. The following questions help apply what the examples showed.

If you are swapping tokens

How does the quoted output compare with the pool's current price? A large trade relative to available liquidity may receive a much worse average price.

What will you receive after fees, and how much slippage will you permit? Increasing the slippage tolerance does not fix shallow liquidity.

Could another pool or route offer a better net execution? Splitting an order may sometimes help, but extra transactions bring fees and execution risks.

If you are providing liquidity

Would you be comfortable holding more of the token that falls in relative price? Your LP position can shift in that direction without a manual trade.

How would the position change if ETH rose or fell sharply? Consider both possibilities, without pretending to predict the market.

Could expected trading fees reasonably compensate for divergence loss, transaction costs, and other risks? Fee income is not the same as net return.

How will you monitor the position? Track its asset mix, earned fees, and performance against holding the tokens. In concentrated liquidity pools, also watch the chosen price range.

A simple rule: compare the whole outcome—tokens received for a swap, or position value plus fees for an LP—rather than focusing on a quoted price or fee rate alone.

None of these checks reveals the best time to trade or guarantees a profitable position.

6. Does x·y=k Still Matter in Modern Uniswap?

Yes, although modern pools require more than the basic formula.

Uniswap V1 and V2 are the clearest examples of full-range constant-product pools. They make the basic relationship between reserves, swaps, and price changes easy to see.

Uniswap V3 introduced concentrated liquidity, also used in V4. Instead of supplying liquidity across the full price spectrum, LPs can choose specific ranges. The constant-product idea still helps explain trading mechanics, but position behavior is more complex.

If the market price leaves an LP's chosen range, the position can become entirely one token and stop earning swap fees while out of range. Understanding x·y=k is therefore a foundation, not a complete manual for V3 or V4 position management.

The practical takeaway: check the expected swap output before trading, and compare an LP position's total value plus fees with simply holding the starting tokens. The formula helps explain the trade-offs; it does not forecast profits.

Technical references

← More in Education

Read the Everstrat Journal.

Learn how liquidity providers earn trading fees and what gives EVE its value.