DEV Community

Anna Botsford
Anna Botsford

Posted on

5 Checks for Comparing Token Prices Across Pairs

When you integrate prices from separate liquidity pairs, compare their marginal prices in the same quote asset first, then compare executable quotes for the trade size you care about. A pair’s displayed price is a local rate implied by that pool’s state; it is neither a universal token price nor a promise that a trade can execute at that rate.

Normalize each pair before comparing its price

For a constant-product pair, the marginal price of token A in token B is the B reserve divided by the A reserve, adjusted for each token’s decimals. If a pair holds 20,000 USDT and 100,000 units of a token with 18 decimals, its marginal price is 0.20 USDT per token. Reversing the pair direction gives the reciprocal, 5 tokens per USDT.

Do not compare that figure directly with a price quoted in WBNB. Convert both rates into a shared numeraire using a separately identified WBNB/USDT market or another chosen reference. Keep the chain, contract addresses, block number, and timestamp attached to each observation; matching symbols do not establish that two token contracts represent the same asset.

A chart can make this comparison easier to inspect across markets: PooCoin token chart is a concrete example of tracking token activity in its pair context. For an integration, retain the pair address and quote-token identity alongside any chart-facing price so a downstream consumer can tell which market produced the number.

Read reserves, decimals, and pool type together

For a V2-style pool, read both reserves from the same block and compute the ratio after applying decimal scaling. If token A has 18 decimals and token B has 6, raw integer reserve division is wrong by a factor of 1012 unless the scale is applied. Store normalized human-unit reserves or use a fixed-point representation with the scale recorded.

Pool type changes what “price” means. A V2 constant-product pool derives its spot rate from reserves; a V3 concentrated-liquidity pool derives it from the current square-root price and token ordering, while active liquidity determines how much volume can trade near that price. V3 pools may also have multiple fee tiers for the same token pair, so the pool address and fee tier are part of the market identity.

For a robust pair record, key or validate at least these fields:

  • Chain ID and pool contract address
  • Token0 and token1 contract addresses, in canonical order
  • Decimals for both tokens, preferably read from token contracts and cached with a refresh policy
  • Pool version or type, including fee tier where applicable
  • Block number and timestamp for the observed state

Compare executable quotes, not just spot ratios

A worked comparison shows why reserve ratios alone can mislead. Suppose pool A holds 100,000 tokens and 20,000 USDT, giving a marginal rate of 0.20 USDT. Pool B holds 50,000 tokens and 40 WBNB; at an illustrative WBNB reference of 300 USDT, its marginal rate is 0.0008 WBNB, or 0.24 USDT. The 20% gap is a signal to investigate, not proof of a risk-free arbitrage.

For a V2-style swap that sends quote asset into the pool, the output is approximately y × (a × (1 − f)) / (x + a × (1 − f)), where x is the quote reserve, y the token reserve, a the input amount, and f the pool fee. With a 2,000 USDT input into pool A and an illustrative 0.25% fee, output is about 9,066 tokens, so the average execution price is about 0.221 USDT per token before gas and any token-level transfer effects. That is materially above its 0.20 marginal rate.

Quote the same notional against each candidate pool using the pool’s actual swap math, fees, and route. PancakeSwap V2 documentation describes a 0.25% fee per hop; V3 fee tiers vary by pool. A route through two pools pays two pool fees and compounds price impact, so comparing one pool’s spot rate with another route’s final quote mixes different costs.

Choose an observation method that fits the decision

Use a same-block snapshot for cross-pair monitoring, and state whether the reported value is a spot ratio, a route quote, or a time-weighted average. A subgraph or analytics API may lag chain state; pairing its reserve data with a newer reference price can manufacture a spread. For execution, obtain a fresh quote close to submission and include slippage tolerance, gas, and the transaction’s deadline or block-age limit.

Use a TWAP when the purpose is valuation or alerting that should resist a single swap’s transient price move. A reserve ratio is cheaper and immediate but can be manipulated in a thin pool; a TWAP smooths noise but reacts slowly when a genuine price change occurs. V3 TWAPs depend on observations and their window, while inactive out-of-range liquidity does not support execution at the current price.

One short safety check matters: tokens with transfer taxes, rebasing behavior, blacklists, or unusual balance accounting can make reserve-based quotes diverge from received amounts or even revert. Validate the specific token and pool behavior before treating a quote as executable, and exclude stale or illiquid markets from automated reference prices.

Why can two pairs show different prices for the same token?

Each pair has its own reserves, fee structure, and liquidity providers, so each produces a local marginal rate. Differences can persist when one market is thin, stale, costly to arbitrage, or isolated by bridge and settlement friction. Compare normalized prices at aligned block times, then test whether the discrepancy survives a realistic route quote.

Should I use the deepest pair as the reference?

Often, but “deepest” should mean the pool that provides the lowest expected execution cost at the relevant trade size, not simply the largest displayed TVL. Concentrated liquidity can offer strong depth within a narrow range and little outside it. Compare price impact, fees, token behavior, and freshness for the intended notional.

What should I ask before acting on a spread?

Ask whether both prices refer to the same contracts, chain, quote asset, and block, and whether the net executable difference remains after pool fees, route impact, gas, and transfer taxes. If the answer depends on stale indexer data or a thin reference pool, treat the apparent spread as an observation to verify, not a price you can necessarily trade.

Top comments (0)