Updates
3 Nov

Indexing millions of token prices based on liquidity

Zora has millions of tokens and computing fresh quotes for every token in every wallet on every page load is a complex engineering problem. Our engineering team has recently made further improvements to ensure your wallet accurately displays Estimated Value of Holdings, the total value if you sold everything right now. This number reflects what you'd actually receive if you executed sales across all your positions.

Previously, we calculated this as: number of coins × price.

The new method shows what you'll actually get by simulating real trades through Uniswap V3 and V4 pools.

Price calculation under liquidity constraints

For each token position, we need to know: "If I sold this right now, what would I actually get, and how much of it can I sell?"

Step 1: Identify the liquidity path

Different tokens have different paths to value: each token on Zora has a route to $USDC through various pairs ($WETH, $ZORA, $CREATOR, $CONTENT, etc.) and Uniswap versions (v3, v4). We calculate the full path to get the actual USD value.

Step 2: Simulate the swap

For each path, we simulate swaps through all available pools at each hop, and always carry forward the highest output value to the next hop:

  • Loading current pool state (price ticks, available liquidity)
  • Walking through ticks and consuming liquidity at each price level
  • Applying the pool's fee tier
  • For V4 pools, accounting for custom hook behavior
  • For multi-hop routes, executing each swap sequentially through intermediate tokens

Step 3: Return actual value

The final number accounts for:

  • Price impact from your trade size
  • Slippage through multiple ticks
  • Fees
  • Multi-hop routing inefficiencies

This is what you'll actually receive.

Understanding Automated Market Makers (AMMs)

The technical infrastructure:

  • Uniswap v3 for $ZORA tokens
  • Uniswap v4 for $CREATOR and $CONTENT tokens
  • Aggressive caching: scale to millions of tokens without sacrificing accuracy

When calculating prices, it's important to understand how tokens actually trade onchain.

Constant product formula

Traditional exchanges use order books: lists of buy and sell orders. AMMs replace this with a mathematical formula and a pool of tokens.

The simplest AMM uses the constant product formula:

x × y = k

Where:

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

When you swap token A for token B:

  1. You add token A to the pool (x increases)
  2. The formula must maintain k constant
  3. So token B must decrease (y decreases)
  4. You receive that token B

Example:

  • Pool has 1,000,000 $CREATOR and 100,000 USDC
  • Let x = $CREATOR amount, y = USDC amount
  • So: x = 1,000,000 and y = 100,000
  • k = 1,000,000 × 100,000 = 100,000,000,000
  • You want to buy $CREATOR with 10,000 USDC
  • New USDC amount: y = 100,000 + 10,000 = 110,000 (you added USDC to pool)
  • To keep k constant: x × y = k, so x × 110,000 = 100,000,000,000
  • Solving for x: x = 100,000,000,000 ÷ 110,000 = 909,090.91 $CREATOR
  • Pool gives you: 1,000,000 - 909,090.91 = 90,909.09 $CREATOR
  • Price per $CREATOR: 10,000 ÷ 90,909.09 = ~$0.11

But if you bought a smaller amount with just 100 USDC, you'd pay ~$0.10 per $CREATOR. The bigger your trade relative to pool size, the worse your price gets.

Slippage and price impact

Price impact is how much your trade moves the price. Large trades relative to pool liquidity cause significant price movement.

Slippage is the difference between expected price and execution price:

slippage = |(execution_price - spot_price) / spot_price|

A $1 spot price that executes at $0.95 means 5% slippage.

Liquidity depth

Liquidity is the total value of tokens available in a pool. Deeper pools handle larger trades with less slippage.

Two pools might show the same spot price ($1), but dramatically different execution:

Deep Pool (1M tokens):

  • Sell 10K tokens → 2% slippage → $9,800 received

Thin Pool (50K tokens):

  • Sell 10K tokens → 60% slippage → $4,000 received

This is why we calculate actual quotes instead of using spot price × balance.

In summary

Indexing millions of token prices based on liquidity requires simulating actual swaps through liquidity pools, not multiplying balances by spot prices. In this post we’ve walked through Uniswap v3 and v4 tick ranges, consumed available liquidity, applied fees, and handled multi-hop routes to calculate what you'd actually receive from a sale.

Zora caches pool states at the tick level and processes quotes in parallel. This approach scales to millions of tokens while maintaining low latency for wallet loads, giving users real execution prices instead of theoretical values.