Back to Blog
#DEX#AMM#Liquidity#Trading#Education

How DEX Prices Work: AMM Formulas, Liquidity Pools, and Price Calculations Explained

10 min read
By ScreenerBot Team

How DEX Prices Work: AMM Formulas, Liquidity Pools, and Price Calculations Explained

Have you ever wondered how decentralized exchanges determine the price when you swap tokens? Unlike traditional exchanges with order books, DEXs use mathematical formulas to calculate prices automatically.

This guide explains how these Automated Market Makers (AMMs) work, from basic concepts to the math behind them, all in terms anyone can understand.


๐ŸŽฏ What You'll Learn

  • What liquidity pools are and how they work
  • The famous x*y=k formula explained simply
  • How different AMM types calculate prices
  • Why slippage happens on DEXs
  • How Solana's major DEXs (Raydium, Orca, Meteora) differ

๐Ÿ“Š Traditional Exchanges vs DEXs

How Traditional Exchanges Work

On a traditional exchange (like the stock market or centralized crypto exchanges):

  1. Buyers place orders: "I want to buy 1 SOL at $100"
  2. Sellers place orders: "I want to sell 1 SOL at $101"
  3. When prices match, a trade happens
  4. This is called an order book

The price is determined by what buyers and sellers are willing to pay.

How DEXs Work

Decentralized exchanges don't have order books. Instead:

  1. Liquidity providers deposit tokens into a pool
  2. An algorithm calculates the price based on pool balances
  3. Traders swap directly with the pool
  4. The algorithm adjusts prices after each trade

This algorithm is called an Automated Market Maker (AMM).


๐ŸŠ What is a Liquidity Pool?

A liquidity pool is a smart contract that holds two (or more) tokens.

Example: SOL/USDC Pool

Imagine a pool containing:

  • 1,000 SOL
  • 200,000 USDC

This pool allows anyone to:

  • Swap SOL for USDC
  • Swap USDC for SOL

The ratio of tokens in the pool determines the price.

In this case:

  • 200,000 USDC รท 1,000 SOL = 200 USDC per SOL

Who Provides Liquidity?

Liquidity Providers (LPs) are people who:

  1. Deposit pairs of tokens into pools
  2. Earn fees from trades
  3. Take on the risk of impermanent loss

Without LPs, there would be no liquidity to trade with.


โšก The Constant Product Formula (x * y = k)

The most famous AMM formula is the constant product formula, invented by Uniswap.

The Formula

x * y = k

Where:

  • x = amount of Token A in the pool
  • y = amount of Token B in the pool
  • k = a constant number that never changes

How It Works

Let's use our SOL/USDC pool:

  • x = 1,000 SOL
  • y = 200,000 USDC
  • k = 1,000 ร— 200,000 = 200,000,000

This "k" value must stay constant before and after every trade.

Calculating a Swap

You want to buy 10 SOL from the pool. Here's how the math works:

Before the trade:

  • SOL: 1,000
  • USDC: 200,000
  • k: 200,000,000

After you take 10 SOL:

  • SOL: 990 (1,000 - 10)
  • The pool needs enough USDC to maintain k = 200,000,000
  • USDC needed: 200,000,000 รท 990 = 202,020.20

You pay:

  • 202,020.20 - 200,000 = 2,020.20 USDC for 10 SOL
  • Effective price: 202.02 USDC per SOL

Notice the price (202.02) is higher than the initial price (200.00). This is called price impact.


๐Ÿ“‰ Understanding Slippage and Price Impact

What is Price Impact?

Price impact is how much your trade moves the market price.

  • Small trades = small price impact
  • Large trades = large price impact

The bigger your trade relative to the pool size, the worse your price.

Example: Different Trade Sizes

Using our 1,000 SOL / 200,000 USDC pool:

Trade Size You Get Effective Price Price Impact
1 SOL 199.80 USDC $199.80 0.1%
10 SOL 1,980.20 USDC $198.02 1.0%
50 SOL 9,523.81 USDC $190.48 4.8%
100 SOL 18,181.82 USDC $181.82 9.1%

The more you buy, the worse your average price.

What is Slippage?

Slippage is the difference between:

  • The price you expect
  • The price you actually get

Slippage can occur because:

  1. Price impact from your trade size
  2. Other trades happening before yours
  3. Network delays changing pool state

Slippage Tolerance

When you set slippage tolerance to 1%, you're saying:

  • "I'm okay if the price is up to 1% worse than quoted"
  • If it's worse than that, cancel my transaction

๐ŸŽฏ Concentrated Liquidity (CLMM)

The Problem with x*y=k

The constant product formula spreads liquidity across all prices (from $0 to $โˆž).

But most trading happens in a narrow range:

  • SOL trades between $150-$250 most of the time
  • Liquidity at $0.01 or $10,000 is wasted

The Solution: Concentrated Liquidity

Concentrated Liquidity Market Makers (CLMMs) allow LPs to provide liquidity in specific price ranges.

How It Works

Instead of providing liquidity for all prices:

  1. You choose a minimum price (e.g., $150)
  2. You choose a maximum price (e.g., $250)
  3. Your liquidity is concentrated in this range
  4. You earn more fees when trades happen in your range

Benefits

For traders:

  • More liquidity at common prices
  • Better prices and less slippage
  • More efficient markets

For LPs:

  • Higher fee earnings per dollar deposited
  • Capital efficiency up to 4,000x better
  • Active management opportunities

Popular CLMMs on Solana

  • Orca Whirlpools - The original Solana CLMM
  • Raydium CLMM - High-volume concentrated pools
  • Meteora DLMM - Dynamic liquidity with price bins

๐Ÿ”ข Different AMM Formulas

1. Constant Product (x * y = k)

Used by: Raydium Legacy, early Uniswap

Best for: General-purpose trading

Formula: x * y = k

Characteristics:

  • Simple and reliable
  • Liquidity spread across all prices
  • Higher slippage for large trades

2. Constant Sum (x + y = k)

Used by: Some stablecoin pools

Best for: Assets that should be 1:1

Formula: x + y = k

Characteristics:

  • Zero slippage within range
  • Breaks if prices diverge
  • Not used alone in practice

3. StableSwap (Curve Formula)

Used by: Saber, Mercurial

Best for: Stablecoin-to-stablecoin swaps

Formula: Hybrid of constant product and constant sum

Characteristics:

  • Very low slippage for stable pairs
  • More complex math
  • Optimal for correlated assets

4. Concentrated Liquidity

Used by: Orca, Raydium CLMM, Meteora DLMM

Best for: Most trading pairs

Formula: Modified x*y=k within price ranges

Characteristics:

  • Capital efficient
  • Better prices for traders
  • Requires active LP management

๐ŸŒŠ How Solana DEXs Calculate Prices

Raydium

Raydium offers two pool types:

Legacy AMM Pools (CPMM):

  • Uses constant product formula
  • Liquidity spread across all prices
  • Simple for LPs

Concentrated Liquidity (CLMM):

  • LPs choose price ranges
  • Higher capital efficiency
  • Better prices for traders

Price Calculation Example (Legacy):

Price = Token B in pool / Token A in pool
Price of SOL = USDC in pool / SOL in pool

Orca

Orca uses Whirlpools (CLMM):

Key Features:

  • Price ticks define liquidity ranges
  • Liquidity concentrated where it matters
  • NFT represents LP positions

How Price Works:

  • Each tick represents a discrete price point
  • Liquidity is assigned to tick ranges
  • Swaps cross ticks as price moves

Example:

  • Current price: $200 per SOL
  • Your liquidity: $180 - $220 range
  • You earn fees only when price is in your range

Meteora

Meteora offers multiple AMM types:

DLMM (Dynamic Liquidity Market Maker):

  • Uses "bins" instead of ticks
  • Price changes in discrete steps
  • Dynamic fees based on volatility

DAMM (Dynamic AMM):

  • Traditional constant product pools
  • Optimized for stable pairs
  • Built-in fee management

DBC (Dynamic Bonding Curve):

  • For token launches
  • Price increases as supply decreases
  • Fair launch mechanism

Pumpfun AMM

Pumpfun uses a bonding curve:

How It Works:

  1. Token starts at a low price
  2. As people buy, price increases algorithmically
  3. Fixed supply released over the curve
  4. Price is determined by total amount bought

Formula (simplified):

Price = Base Price ร— (1 + Tokens Sold / Curve Constant)

๐Ÿ“ Calculating Price from Pool Reserves

For Constant Product AMMs

To calculate the current price of Token A in terms of Token B:

Price of A = Reserve of B / Reserve of A

Example

Pool contains:

  • 500 SOL
  • 125,000 USDC

Price of SOL:

125,000 USDC / 500 SOL = 250 USDC per SOL

For Concentrated Liquidity

The calculation is more complex:

  1. Find the current active tick
  2. Calculate virtual reserves within the range
  3. Apply the formula within that range

Most traders use DEX APIs rather than calculating manually.


๐Ÿ’ฑ How Aggregators Find Best Prices

What is a DEX Aggregator?

A DEX aggregator (like Jupiter) finds the best price across multiple DEXs.

How It Works

  1. You want to swap 100 SOL for USDC
  2. Jupiter checks prices on:
  3. Raydium pools
  4. Orca pools
  5. Meteora pools
  6. Many others
  7. It might split your trade:
  8. 60 SOL through Raydium
  9. 30 SOL through Orca
  10. 10 SOL through Meteora
  11. You get the best overall price

Why Aggregators Help

  • Better prices - finds the best rates
  • Lower slippage - splits large orders
  • One transaction - handles complexity

๐Ÿ“Š Price vs OHLCV Data

What is OHLCV?

OHLCV stands for:

  • Open - Price at start of period
  • High - Highest price in period
  • Low - Lowest price in period
  • Close - Price at end of period
  • Volume - Total traded in period

Where Does OHLCV Come From?

OHLCV data is aggregated from individual trades:

  1. Every swap has a price
  2. Data providers collect all swaps
  3. They organize into time periods (1m, 5m, 1h, etc.)
  4. Charts display this data

Data Sources

  • On-chain: Reading pool reserves directly
  • Aggregators: DexScreener, GeckoTerminal, Birdeye
  • APIs: Jupiter, Raydium, Orca APIs

๐ŸŽ“ Key Takeaways

  1. AMMs use formulas - Not order books, but math
  2. x*y=k is fundamental - Most AMMs derive from this
  3. Bigger trades = worse prices - Price impact matters
  4. Concentrated liquidity is more efficient - CLMM pools offer better prices
  5. Aggregators find best prices - Use Jupiter for optimal rates
  6. Pool reserves determine price - Simple ratio calculation

๐Ÿ”— Learn More

Solana DEXs

DEX Aggregators

Price Data


๐Ÿ“– Glossary

Term Definition
AMM Automated Market Maker - algorithm determining prices
Liquidity Pool Smart contract holding tokens for trading
Constant Product x*y=k formula for price calculation
CLMM Concentrated Liquidity Market Maker
Slippage Difference between expected and actual price
Price Impact How your trade moves the market price
LP Liquidity Provider - deposits tokens to pools
OHLCV Open/High/Low/Close/Volume price data
DEX Aggregator Service finding best prices across DEXs

Understanding how DEX prices work gives you an edge in trading. Now you know why big trades get worse prices and how to minimize slippage! ๐Ÿš€

Ready to Start Trading?

Download ScreenerBot and start automated DeFi trading on Solana.

Download Now