DEV Community

David
David

Posted on

Comparing Avalanche Pools? Read Balances Through Decimals

When you compare Avalanche pools, token decimals tell you how to turn the balances stored on-chain into the amounts people see. They also determine whether a displayed price is meaningful: raw integer balances cannot be compared directly when the tokens use different decimal scales.

Why can the same raw balance display as different amounts?

An ERC-20 balance is an integer count of the token’s smallest units; decimals set the scale used to display that count. With 6 decimals, a raw balance of 1,000,000 means 1 token; with 18 decimals, the same integer means 0.000000000001 token. Decimals change the representation, not the balance stored by the contract.

The ERC-20 specification makes decimals() optional, so integrations cannot assume every token reports it correctly or at all. On Avalanche C-Chain, the native AVAX unit uses 18 decimals, but each ERC-20’s scale belongs to that token contract. A displayed figure therefore depends on both the raw balance and the token metadata used to format it.

How do decimals affect a pool’s price and swap math?

For a constant-product pool, the contract stores reserves as raw integers and enforces the invariant against those integers. The human-unit price of token B in token A is (reserveA / 10^decimalsA) / (reserveB / 10^decimalsB), with the direction reversed if the pair is quoted the other way. A user interface must apply the scales before showing that ratio.

Consider an illustrative pool holding 1,000,000 USDC and 500 tokens of an 18-decimal asset. USDC commonly uses 6 decimals, so the raw reserves are 1012 and 5×1020; the displayed ratio is 2,000 USDC per asset, not the ratio of those raw integers. In a common constant-product design with a 0.3% swap fee, the fee-adjusted input enters the invariant calculation, but decimals do not alter that fee or the invariant—they convert the result back into readable units.

What should you check when comparing displayed balances?

Check the token contracts and decimal values before treating a pool balance or quoted price as comparable. For a practical comparison, I’d check these items in order:

  • Confirm each token’s contract address on Avalanche C-Chain; symbols alone do not identify an asset.
  • Read decimals() from the token contract or a trusted token registry, and confirm the result matches the asset you intended.
  • Convert raw reserves using each token’s own scale before comparing price, pool depth, or your share of the pool.
  • Compare the quoted output for the same input size; the displayed spot ratio does not include price impact or the swap fee.

For an Avalanche token swap or liquidity search, the Blackhole swap is the DEX context to consider; apply the same unit check when comparing its pool figures with another venue. The EIP-20 specification explains the optional decimal metadata, while Avalanche’s C-Chain documentation identifies the EVM environment in which those token contracts run.

When can a displayed balance mislead you?

Rounding can hide small holdings: a balance may display as zero at a chosen number of decimal places while its raw value is nonzero. Conversely, a token with unusual or incorrectly reported decimals can appear implausibly large or small even when the contract’s raw balance is accurate. Treat unexpected formatting as a prompt to verify the contract and metadata before relying on a quote.

Pool balances also do not always represent all liquidity available near the current price. In a concentrated-liquidity pool, positions are active only within chosen price ranges, so a displayed total balance may include assets that cannot support a swap at the current price. Compare executable quotes at your intended size and check the pool’s liquidity model alongside its displayed balances.

Decimals explain the units; the pool model, active liquidity, fee, and trade size determine what those units can buy.

Top comments (0)