How to calculate impermanent loss (with examples)

Covalent TeamUpdated 14 min read

The impermanent loss formula, worked examples for a 2x move, a table of losses by price change, Uniswap V3 ranges, and code that computes it for a real pool.

Impermanent loss is how much less a liquidity pool position is worth than holding the same tokens, after their prices move apart. In a 50/50 constant product pool it depends on one number, how far the price ratio of the two tokens has moved, and it follows one formula. This guide explains where the loss comes from, works it through by hand, gives the loss for common price moves, covers Uniswap V3's concentrated liquidity, and computes it for a real pool with the GoldRush token price API.

This is not investment advice. The examples use hypothetical prices to show the math.

What is impermanent loss?

When you provide liquidity to an automated market maker (AMM) such as Uniswap, you deposit two tokens in a fixed value ratio, usually 50/50, and receive a share of the pool. Traders swap against the pool and pay a fee to its liquidity providers (LPs).

As the market price of one token moves against the other, traders and arbitrageurs rebalance the pool: they buy the token that got cheaper in the pool and sell the one that got dearer. Your share of the pool ends up holding more of the token that fell and less of the one that rose. Impermanent loss is the gap between what your share is worth and what the tokens you deposited would be worth if you had just held them:

Impermanent loss = value of the LP position ÷ value if held − 1

It is called impermanent because it shrinks back to zero if the price ratio returns to where it was when you deposited. It becomes a realized loss when you withdraw while the ratio is still different. Trading fees you earned are counted separately, and they can make up for it.

Why impermanent loss happens: the constant product formula

Uniswap V2 and its forks are constant product AMMs. A pool holding x of one token and y of the other keeps their product fixed through every swap (before fees):

x × y = kpool price of the first token = y ÷ x

A hypothetical ETH/USDC pool holds 100 ETH and 200,000 USDC, so k = 20,000,000 and the pool price is 2,000 USDC per ETH. A trader buys 10 ETH:

  • The pool's ETH falls to 90, so its USDC must rise to 20,000,000 ÷ 90 = 222,222.22.
  • The trader pays 22,222.22 USDC for 10 ETH, an average of 2,222.22 per ETH. The price slides as the trade eats into the pool.
  • The new pool price is 222,222.22 ÷ 90 = 2,469.14 USDC per ETH, and 90 × 222,222.22 is still 20,000,000.

Uniswap V2 also charges a 0.3% fee on each swap (Uniswap V2 whitepaper), which stays in the pool for its LPs, so in practice k grows slowly with every trade.

The pool has no price feed. When ETH's market price moves, the pool's price only follows because arbitrageurs trade against it until the two match, and every such trade moves the pool toward more of the token that fell. That rebalancing is the impermanent loss: the LP sells the rising token on the way up and buys the falling one on the way down.

The impermanent loss formula

Let r be the price ratio change: the pair's price when you value the position divided by its price when you deposited. For a 50/50 constant product pool, with fees left out:

IL = 2 × √r ÷ (1 + r) − 1

Why it works: at pool price P, a position with invariant k holds √(k ÷ P) of the first token and √(k × P) of the second, so it is worth 2√(k × P) in the second token. The deposit, held instead, is worth √(k ÷ P₀) × P + √(k × P₀). Dividing one by the other leaves 2√(P × P₀) ÷ (P + P₀), which is 2√r ÷ (1 + r).

Three things follow from it:

  • The loss depends only on r, not on which way the price moved or how big the pool is. A 2x rise and a 50% fall (r = 0.5) both cost 5.72%.
  • It is never positive. Any move away from the entry ratio leaves the position worth less than holding.
  • If both tokens move by the same percentage, r is 1 and there is no impermanent loss, however much their dollar prices changed.

Worked example: impermanent loss on a 2x price move

You deposit 1 ETH and 2,000 USDC into a hypothetical ETH/USDC pool when ETH is $2,000, so your deposit is worth $4,000 and your share's k is 1 × 2,000 = 2,000.

ETH doubles to $4,000, so r = 2. Arbitrage rebalances the pool until its price is 4,000 USDC per ETH. Your share now holds:

  • ETH: √(2,000 ÷ 4,000) = 0.7071 ETH
  • USDC: √(2,000 × 4,000) = 2,828.43 USDC
ETH USDC Value at ETH = $4,000
Held in your wallet 1 2,000 $6,000.00
In the pool 0.7071 2,828.43 $5,656.85

The position is $343.15 behind holding, and $5,656.85 ÷ $6,000 − 1 = −5.72%. The formula gives the same answer: 2 × √2 ÷ 3 − 1 = −0.0572. It is still a $1,656.85 gain on the $4,000 you put in; impermanent loss measures the shortfall against holding, not against your deposit.

If ETH had halved to $1,000 instead (r = 0.5), your share would hold 1.4142 ETH and 1,414.21 USDC, worth $2,828.43 against $3,000 held: the same −5.72%.

Impermanent loss by price change

From the formula, for a 50/50 constant product pool before fees:

Price ratio change (r) Impermanent loss
1.1x (or 0.91x) 0.11%
1.25x (or 0.8x) 0.62%
1.5x (or 0.67x) 2.02%
2x (or 0.5x) 5.72%
3x (or 0.33x) 13.40%
4x (or 0.25x) 20.00%
5x (or 0.2x) 25.46%
10x (or 0.1x) 42.50%

Small moves cost little, and the loss grows quickly with large ones. A move and its inverse (2x and 0.5x) cost the same.

Impermanent loss with trading fees

The formula leaves out fees. What you actually earned or lost against holding is:

Net result vs holding = (LP position value + fees earned) − value if held

Fees accrue with every swap, so a pool with high volume relative to its liquidity earns more per dollar deposited. A position comes out ahead of holding when the fees it earned exceed its impermanent loss. Pairs whose prices move together, such as two stablecoins or a token and its wrapped version, keep r close to 1 and have little impermanent loss to cover; volatile pairs need much more fee income to break even.

Impermanent loss in Uniswap V3

Uniswap V3 lets an LP choose a price range [pa, pb] and provide liquidity only inside it. The same capital acts like a much larger full-range position while the price stays in range, so it earns more fees per dollar. It also takes more impermanent loss, by the same leverage.

While the price stays inside the range, the loss of a V3 position opened at price p0 is the full-range loss multiplied by a factor that depends only on how wide the range is. The factor follows from the token amounts a range position holds at each price, as the Uniswap V3 whitepaper defines them (the amounts function in ilV3 below):

IL (V3) = IL (V2) ÷ (1 − (√(pa ÷ p0) + √(p0 ÷ pb)) ÷ 2)

For ranges centred on the entry price, the multiplier and the loss on a 1.1x move are:

Range around the entry price Multiplier Loss on a 1.1x move
Full range (Uniswap V2) 1x 0.11%
0.5x to 2x 3.41x 0.39%
0.8x to 1.25x 9.47x 1.07%
0.9x to 1.1x 20.4x 2.32%

So a position whose range only just covers a doubling or a halving loses 3.41 times as much as a full-range one, 19.53% instead of 5.72% on a 2x move. As the range widens toward every price, the multiplier falls to 1 and the loss approaches the V2 formula.

Outside the range the formula no longer applies. The position is then entirely the token that fell, it stops earning fees, and its shortfall against holding keeps growing as the price moves further away. The ilV3 function below handles both cases.

Calculate impermanent loss for a real pool with GoldRush

To compute impermanent loss for an actual position, you need the pair's price when the liquidity went in and its price now or when it came out. Two GoldRush Foundational API endpoints supply them:

  • DEX pool spot prices (spot_prices, 1 per call): a Uniswap V2 or V3 pool's (or fork's) two tokens and their current prices in the pool, on Ethereum, Polygon, Base, Optimism, BNB Smart Chain (BSC) and Gnosis.
  • Historical token prices (historical_by_addresses_v2, 1 per call): each token's daily USD price for a date range. One call takes a comma-separated list of tokens.

Prerequisites: Node.js 18 or later (for the built-in fetch), and a GoldRush API key in the GOLDRUSH_API_KEY environment variable. The three code blocks below make one script: save them, in order, in one file named il.mjs (the .mjs extension lets the last block use top-level await), then run node il.mjs.

The formulas first. They need nothing but prices:

// Impermanent loss of a full-range (Uniswap V2-style) position after the price ratio changes by r.function ilV2(r) {    return (2 * Math.sqrt(r)) / (1 + r) - 1;} // Impermanent loss of a concentrated (Uniswap V3-style) position with range [pa, pb], opened at price p0 and valued// at p1. Prices are token1 per token0. Works in and out of range: outside it, the position is all one token.function ilV3(p0, p1, pa, pb) {    const clamp = (p) => Math.min(Math.max(p, pa), pb);    // Token amounts per unit of liquidity at price p.    const amounts = (p) => ({        x: 1 / Math.sqrt(clamp(p)) - 1 / Math.sqrt(pb), // token0        y: Math.sqrt(clamp(p)) - Math.sqrt(pa), // token1    });    const start = amounts(p0);    const now = amounts(p1);    const lpValue = now.x * p1 + now.y; // what the position holds at p1, in token1    const holdValue = start.x * p1 + start.y; // what the deposit would be worth if held    return lpValue / holdValue - 1;}

Then the data. Add this to the same file:

const API = "https://api.covalenthq.com/v1";const headers = { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}` }; async function get(url) {    const res = await fetch(url, { headers });    if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);    return (await res.json()).data;} // The pool's two tokens and its current in-pool price, from the DEX pool spot price endpoint.async function getPool(chain, pool) {    const [p] = await get(`${API}/pricing/spot_prices/${chain}/pools/${pool}/?quote-currency=USD`);    return {        token0: { address: p.token_0_address.toLowerCase(), symbol: p.token_0_ticker },        token1: { address: p.token_1_address.toLowerCase(), symbol: p.token_1_ticker },        priceNow: Number(p.token_0_price), // token0 in units of token1, in the pool right now    };} // Each token's USD price on one day (YYYY-MM-DD), in one call for both tokens.async function getPricesOn(chain, addresses, day) {    const data = await get(        `${API}/pricing/historical_by_addresses_v2/${chain}/USD/${addresses.join(",")}/?from=${day}&to=${day}`    );    const prices = new Map();    for (const token of data) {        const price = token.prices?.[0]?.price;        if (price == null) throw new Error(`No price yet for ${token.contract_ticker_symbol} on ${day}`);        prices.set(token.contract_address.toLowerCase(), price);    }    return prices;} // Impermanent loss for a deposit made on `from` (YYYY-MM-DD) and valued on `to`, or at the pool's price right now// when `to` is left out. Pass `range` as [lower, upper] multiples of the entry price (for example [0.5, 2]) to model// a concentrated position; leave it out for a full-range one.async function impermanentLoss({ chain, pool, from, to, range }) {    const { token0, token1, priceNow } = await getPool(chain, pool);    const addresses = [token0.address, token1.address];    const ratio = (prices) => prices.get(token0.address) / prices.get(token1.address);     // The pair's price, token0 in units of token1, at entry and at the end.    const p0 = ratio(await getPricesOn(chain, addresses, from));    const p1 = to ? ratio(await getPricesOn(chain, addresses, to)) : priceNow;    const r = p1 / p0;    const il = range ? ilV3(p0, p1, p0 * range[0], p0 * range[1]) : ilV2(r);     return { pair: `${token0.symbol}/${token1.symbol}`, r, il };}

getPricesOn reads a list with one entry per token, each with its daily prices. This one is a historical_by_addresses_v2 response for WETH on 29 October 2026, recorded on 3 November 2026 and trimmed of its metadata:

{    "data": [        {            "contract_decimals": 18,            "contract_ticker_symbol": "WETH",            "contract_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",            "quote_currency": "USD",            "prices": [{ "date": "2026-10-29", "price": 2252.9236 }],            "items": null        }    ],    "error": false,    "error_message": null,    "error_code": null}

Run it for the Uniswap V2 USDC/WETH pool on Ethereum, as a full-range position, as a 0.5x–2x V3 range, and against the pool's price now. Add this at the end of il.mjs:

const pool = "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc"; // Uniswap V2 USDC/WETH on Ethereumconst show = ({ pair, r, il }) =>    console.log(`${pair}: ratio ×${r.toFixed(3)}, impermanent loss ${(il * 100).toFixed(2)}%`); show(await impermanentLoss({ chain: "eth-mainnet", pool, from: "2026-10-01", to: "2026-11-18" }));show(await impermanentLoss({ chain: "eth-mainnet", pool, from: "2026-10-01", to: "2026-11-18", range: [0.5, 2] }));show(await impermanentLoss({ chain: "eth-mainnet", pool, from: "2026-10-01" })); // valued at the pool price now

Run against responses recorded from those two endpoints on 21 November 2026, it printed:

USDC/WETH: ratio ×1.540, impermanent loss -2.29%USDC/WETH: ratio ×1.540, impermanent loss -7.82%USDC/WETH: ratio ×1.609, impermanent loss -2.77%

The 0.5x–2x range lost 3.41 times as much as full range, as the multiplier table predicts. A few things to know when you adapt it:

  • Daily prices. Historical prices are one per day, so from and to are days, not blocks. The most recent day can come back empty for a while; use a day at least two days back, or leave to out to use the pool's live price.
  • Which token is which. Prices are token0 in units of token1, the pool's own order. r and the loss don't depend on which way round you take them.
  • Not a position tracker. The code gives the loss for a deposit at a given date and price range. It doesn't read your LP position, the fees it earned, or deposits and withdrawals in between. Add earned fees on top to get the net result, as in the fees section above.
  • Other pool designs. The formulas are for 50/50 constant product pools and Uniswap V3 ranges. Weighted pools (such as 80/20) and stableswap curves follow different math.

For more on what GoldRush offers DeFi apps, see the DeFi API page.

Handle errors from the GoldRush pricing endpoints

When a request fails, the API answers with a non-2xx status and the same envelope as a success, with data set to null. The docs show this body for a chain name it doesn't recognize, with HTTP status 501:

{    "data": null,    "error": true,    "error_message": "Chain nosuchchain-mainnet not supported.",    "error_code": 501}

get() throws the status and the body, so the script stops with 501 {"data":null,"error":true,…} rather than computing a loss from a missing price. error_code always equals the HTTP status, and error_message says what went wrong:

  • 501: the chain name is misspelled, or the chain isn't one the pool spot price endpoint supports. Fix it; the same request keeps returning 501.
  • 401: the API key is missing or wrong. A request with no Authorization header at all gets an HTML 401 page instead of JSON, which is why get() reads the body as text before throwing.
  • 429 or a 5xx: rate limit or a busy backend. Retry after a pause, with backoff.

A day with no price yet is not an error: the request succeeds but the token comes back without a price for that day, which the No price yet check catches. Failed requests cost no credits. The error handling page lists every code and what to do about it.

Frequently asked questions

How do you calculate impermanent loss?

Divide the pair's price when you value the position by its price when you deposited to get the ratio change r, then compute 2 × √r ÷ (1 + r) − 1. The result is how much less the position is worth than holding the same tokens. A 2x move in either direction gives −5.72%.

What is the impermanent loss formula for Uniswap V3?

Inside the position's price range, the loss is the Uniswap V2 loss divided by 1 − (√(pa ÷ p0) + √(p0 ÷ pb)) ÷ 2, where pa and pb are the range bounds and p0 the entry price. The narrower the range, the larger the multiplier: 3.41x for a 0.5x to 2x range. Outside the range, value the position as all one token.

Does impermanent loss become permanent?

It becomes realized when you withdraw while the price ratio is different from when you deposited. If the ratio returns to where it started, the loss goes back to zero. Fees you earned in the meantime are yours either way.

Can trading fees cover impermanent loss?

Yes, if the fees a position earns are larger than its impermanent loss. That is more likely in pools with high trading volume relative to their liquidity, and in pairs whose prices move together, which keeps the loss small.

Do stablecoin pairs have impermanent loss?

In principle yes, but very little while both coins hold their peg, because the price ratio stays close to 1. If one of them loses its peg, the ratio moves and the pool leaves LPs holding more of the coin that fell.

Can I get the prices to calculate impermanent loss from an API?

Yes. The GoldRush historical token price endpoint returns each token's daily USD price, so you can get the pair's price on the day you deposited and on any later day. The DEX pool spot price endpoint returns a Uniswap V2 or V3 pool's tokens and its current price. The code above uses both.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.