Skip to content

Research notes

Curve NG Raw Balances vs Normalized xp

Trace a two-coin ledger from raw token amounts to equal xp, then check vault-share decimals, admin balances, rate changes and integer rounding.

An ivory paper stack and ceramic blocks support a level lime beam on black, with a lime wedge beside them.
Illustration for research notes; examples in this article are educational.

In Curve StableSwap-NG, raw balances are token integers, while xp is the rate-normalized balance vector used by the invariant. For each coin, multiply the pool’s balance excluding accrued admin fees by its effective stored rate, then divide by 10^18 with integer truncation. The rate incorporates decimal scaling and, where configured, a token conversion rate. Equal xp values can therefore represent different displayed token quantities.

A pool holding 1,250 units of one token and 1,000 shares of another need not be imbalanced. The answer depends on what a share represents and which balances the pool actually includes. Conversely, matching displayed quantities can conceal a difference in normalized amounts.

This guide follows the plain-pool reference at Curve’s repository commit 3332cd4. It is a code snapshot, not evidence that every deployed NG pool uses that implementation. Curve’s current documentation identifies an earlier documentation scope, so confirm the implementation of any pool you inspect. Curve’s NG overview and source scope.

Keep three quantities in separate columns

Start with the asset’s raw integer, its displayed quantity and its contribution to xp. They answer different questions.

QuantityWhat it measuresWhat it cannot establish
Raw token amountInteger units of a particular token contractA comparable amount of another token
Displayed token quantityRaw amount divided by that token’s decimal scaleUnderlying assets represented by a share
Normalized xpPool balance multiplied by its effective rate, with integer scalingAn independent market price or redemption guarantee

The ERC-20 decimals guide explains the first conversion. NG adds another conversion before applying its invariant. The common unit is the configured reference denomination, not necessarily dollars. Do not feed human-readable quantities into a function expecting raw integers, or treat xp as another wallet token balance.

In the pinned pool, the normalization is xp[i] = floor(balance[i] × rate[i] / 10^18). Its _xp_mem function performs the multiplication before the division. get_balances() returns the balances selected for this accounting, while stored_rates() returns the effective rates. Pinned NG pool source.

The name “stored rates” can mislead: the public getter invokes the internal rate calculation. Curve’s integration documentation describes externally queried rate oracles for configured oracle assets and a separate ERC-4626 asset type. Preserve the returned rate with the observation state rather than assuming its name means an old cached value. Curve’s token-handling documentation.

Reconcile a two-coin ledger

Consider a hypothetical, non-rebasing plain pool. Coin A is an ordinary six-decimal token. Coin B is an eighteen-decimal vault share. Assume one B share represents 1.25 units of an underlying asset comparable to one A. This relationship is a constructed normalization premise, not a market-price claim.

Suppose cached balances match actual token holdings at the chosen state. Some holdings represent accrued admin fees:

Ledger entryCoin ACoin B
Displayed holdings1,260 tokens1,002 shares
Accrued admin amount10 tokens2 shares
Displayed amount used for normalization1,250 tokens1,000 shares
Raw amount used for normalization1,250,000,0001,000 × 10^18
Effective rate10^301.25 × 10^18
Resulting xp1,250 × 10^181,250 × 10^18

For A, multiply 1,250,000,000 by 10^30, then divide by 10^18. The result is exactly 1,250 × 10^18.

For B, multiply 1,000 × 10^18 by 1.25 × 10^18, then divide by 10^18. It gives the same result. Both calculations have zero remainder.

The displayed quantities differ by 250, yet each coin supplies half of this example’s normalized total. Adding raw balances together would mix six-decimal A units with eighteen-decimal B units. Adding displayed quantities would mix tokens with shares. Neither sum reconstructs the input vector.

The 10^30 rate for A is intentional. The pinned NG factory’s plain-pool deployment path constructs a base multiplier of 10^(36 − decimals). Six decimals therefore produce 10^30; eighteen produce 10^18. The extra division by 10^18 in normalization leaves the desired eighteen-decimal common scale. Pinned NG factory source.

A shortcut that assigns every ordinary token a full effective rate of 10^18 would fail here. For A, it would leave xp at 1,250,000,000, one trillion times smaller than the intended normalized amount. “No additional exchange-rate adjustment” does not mean “no decimal adjustment.”

Why the admin amount comes out first

Accrued admin fees are a separate claim. Curve documents admin_balances as accumulated claimable fees and excludes them when constructing pool balances. Its documented balance paths distinguish cached accounting from reading token balances for rebasing pools. Curve’s balance-accounting overview.

Using the hypothetical gross holdings above would produce 1,260 × 10^18 for A and 1,252.5 × 10^18 for B. That introduces an apparent 7.5-unit normalized difference into a ledger whose included balances are equal. The discrepancy comes from mixing accounting scopes, not from a change in the assets’ conversion relationship.

In the pinned snapshot, the flag pool_contains_rebasing_tokens selects live balanceOf(pool) reads instead of cached stored_balances; both paths subtract admin_balances. Its public balances(i) getter already returns that net figure. Subtracting admin fees again would undercount. Pinned balance-selection implementation.

For a deployed pool, use its own getter and verified implementation to establish the accounting boundary. An explorer’s token-holdings panel is useful evidence of custody, but substituting it for the pool’s included balance requires reconciliation.

Build the vault rate without assuming equal decimals

Now reconstruct B’s effective rate in the illustrative ledger. Let its underlying asset have six decimals even though B shares have eighteen.

The NG ERC-4626 path uses call_amount, representing one whole share in raw units, and a scale_factor that brings the underlying amount to eighteen decimals. It combines that conversion with the base decimal multiplier. Curve’s ERC-4626 rate calculation.

For this constructed vault:

Rate componentIllustrative valueMeaning
Base multiplier10^18B’s eighteen share decimals
call_amount10^18One whole B share
convertToAssets result1,250,0001.25 underlying tokens at six decimals
scale_factor10^12Underlying six-decimal units to eighteen
Effective rate1.25 × 10^18Base multiplier × conversion × scale, divided by 10^18

This is why calling convertToAssets(10^18) blindly is unsafe when reconstructing another vault’s rate. The requested amount must use that vault’s share scale.

As a separate hypothetical check, change B to eight share decimals while keeping the same economic conversion and six-decimal underlying. One share now means 10^8 raw share units, so call_amount becomes 10^8. The base multiplier becomes 10^28. The returned underlying amount remains 1,250,000.

The effective rate is then 1.25 × 10^28. A balance of 1,000 shares is 10^11 raw units. Multiplying that balance by the effective rate and dividing by 10^18 again yields 1,250 × 10^18. Changing the share denomination has changed two accounting inputs while preserving the represented quantity.

The ERC-4626 standard describes convertToAssets as an ideal conversion that rounds down and excludes fees and actual-exchange slippage. It does not promise exact live redemption proceeds. For that separate distinction, read ERC-4626 shares versus assets.

A new rate can change xp without a transfer

Keep the original illustrative 1,000-share included balance, but change its effective rate from 1.25 × 10^18 to 1.26 × 10^18. Its xp becomes 1,260 × 10^18. A stays at 1,250 × 10^18.

B’s normalized amount increased by 10, or 0.8%, while its raw share balance stayed fixed. That is an arithmetic consequence of the stipulated rate change. It is not evidence of realized investment returns or an independently verified rise in market value.

This also exposes a snapshot failure. Combining an old balance with a new rate creates a hybrid state. The resulting integer may be precise but fail to describe any state the pool used. Keep balances, rates and the block reference together; RPC batching versus one-block snapshots explains why sending requests together is insufficient on its own.

Integer order matters too. For A, dividing its raw balance by 10^18 first truncates it to zero. Multiplying afterward cannot restore the lost amount.

For a tiny, separate illustrative B balance of three raw share units at the 1.25 × 10^18 rate, normalization yields three normalized base units, discarding a fractional 0.75 unit. Retain the integer operations when reproducing code. A floating-point display of 3.75 has not reproduced the contract’s result.

Use xp to check inputs, then finish the quote

Normalized equality identifies the reference balance in this constructed ledger. It does not turn a finite swap into a guaranteed one-for-one exchange. The constant-product versus StableSwap comparison explains the invariant’s shape; the present calculation establishes the units supplied to it.

A usable reconstruction record should contain:

RecordCheck before proceeding
Chain, pool and implementationDoes the verified code match the accounting being reproduced?
Block reference and coin orderAre all balance and rate observations aligned?
Included raw balancesWere admin fees already excluded by the getter?
Token decimals and asset typesIs the token standard, oracle-based, rebasing or ERC-4626?
Effective rates and provenanceWere decimal and conversion adjustments each applied once?
Integer xp resultsDoes multiplication precede division, with remainders understood?

After those checks, current amplification and fees still belong to the quote. Current A versus a ramp target explains which amplification observation applies. Base fee versus off-peg fee addresses the fee input.

Before blaming invariant math for a mismatched reconstruction, compare the included raw balances and effective rates coin by coin. Keep that ledger with the block reference. A correct xp vector is a reproducible starting point for the calculation that follows.

Keep the context with the example.

Each worked example is illustrative, with its sources and assumptions in the article. Read our editorial standards for authorship, verification and corrections.