4 Checks for Reading AMM Pool Ratios Correctly
Token decimals change how pool reserves should be read, not how the AMM stores or trades them. For treasury teams comparing liquidity or checking an execution price, the key step is to convert each reserve from raw integer units before forming a ratio; this is the mechanism behind a base swap as well as other AMMs on Base.
- On-chain reserves are integers in each token’s smallest unit.
- Normalize each reserve by its own token’s decimal scale before comparing quantities.
- Check token order, rounding and metadata before using a displayed ratio in treasury accounting.
1. Pool reserves use raw token units
An ERC-20 balance and a pair’s reserves are integers: a token’s decimals value tells software how to format those integers for people. If a token has d decimals, its human-readable quantity is its raw amount divided by 10d; 18 is common, while stablecoins often use 6, and the value can differ by token.
A constant-product AMM pair stores reserve0 and reserve1 as raw amounts, alongside a fixed token0/token1 order. Its invariant is commonly expressed as x × y = k; the decimals do not enter that integer arithmetic. A displayed reserve ratio, however, must be calculated from normalized quantities, because dividing raw reserve integers alone mixes units when the tokens have different decimal scales.
For example, suppose a pool holds 2,500 USDC with 6 decimals and 1.25 WETH with 18 decimals. The raw reserves are 2,500,000,000 and 1,250,000,000,000,000,000; the pool contains 0.0005 WETH per USDC, or 2,000 USDC per WETH. The raw ratio is 500 million, which is not an economic price.
2. Normalize before calculating price or trade impact
For token1 priced in token0, calculate (reserve1 ÷ 10d1) ÷ (reserve0 ÷ 10d0), equivalently (reserve1 ÷ reserve0) × 10d0−d1. Confirm token0 and token1 from the pair contract or trusted pool data first: reversing the order inverts the quoted price, while omitting the decimal adjustment can shift it by powers of ten.
To estimate a swap in a constant-product pool, the same units matter in the quote calculation. In a common V2-style formula, amountOut = (amountIn × feeFactor × reserveOut) ÷ (reserveIn × denominator + amountIn × feeFactor); one illustrative configuration uses a 997/1000 fee factor. All amounts and reserves in that formula are raw units of their respective tokens, so the returned integer output must be normalized with the output token’s decimals before it is compared with a treasury payout or market quote.
That calculation gives a spot or estimated execution price, not a guaranteed fill: larger trades move the reserves and therefore incur more price impact. For recurring transfers, compare the normalized output for the actual transfer size, and account separately for the pool’s configured fee and transaction costs. A reserve ratio alone says nothing about available depth at your size.
3. Verify metadata before using a displayed ratio
For a team reconciling a base swap pool against treasury records, fetch each token’s decimals and the pair’s reserves at the same block, then normalize with integer arithmetic or a decimal-safe library. Avoid binary floating-point for raw values: large integers can lose precision before the decimal adjustment, creating discrepancies in quotes, reports or minimum-output checks.
ERC-20 decimals are optional metadata, and a token may implement them incorrectly, return an unexpected value or fail to answer the query. If metadata is absent or untrusted, verify the token contract and use a reviewed source for its scale; treating an unknown token as 18 decimals can make a displayed reserve ratio—and any downstream valuation—wrong by an enormous factor.
BaseSwap is an AMM on Base, Coinbase’s Ethereum Layer 2, where the same raw-unit distinction applies. For an operating team, the practical criterion is whether the reserve ratio has been normalized with the verified decimals and correct token order before it enters pricing, settlement or liquidity decisions.
Comments
Post a Comment