Skip to content

Research notes

Curve NG Base Fee vs Off-Peg Fee: A Worked Example

A checked fee-state table and a complete illustrative swap separate the stored base fee, the current pair fee and the fee actually used in output math.

Ivory ceramic jaws with unequal counterweights reveal a lime seam beside a small fixed ceramic spacer.
Illustration for research notes; examples in this article are educational.

Curve StableSwap-NG’s base fee is the stored starting rate. Its off-peg multiplier can raise the effective fee when the exchanged coins’ normalized balances become more unequal. A current fee getter evaluates the present state, while a finite swap uses averages of the pre-swap and calculated post-swap balances. The base fee alone therefore cannot reproduce the swap output.

A pool showing a base fee of 0.04% does not necessarily charge 0.04% on the output of your intended swap. You need the multiplier, the relevant normalized balances and the amount being exchanged. Those inputs answer different questions, even when the interface places them beside one another.

This explanation follows the plain-pool StableSwap-NG implementation at commit 3332cd44656ec64b3c048885e1dd71955254b262, checked on 28 October 2026. Every numerical scenario below is hypothetical. A repository version establishes a calculation to inspect; a deployed pool still needs its own implementation and state checks.

Decode the two fields before doing arithmetic

Curve documents both fee() and offpeg_fee_multiplier() with a precision denominator of ten billion, or 1e10. The fee integer represents a fractional charge. The multiplier integer represents a factor after division by the same denominator. Curve’s plain-pool fee methods.

For this illustrative example, choose a base fee integer of 4,000,000 and a multiplier integer of 50,000,000,000. These are assumptions, rather than a current pool’s configuration.

Hypothetical fieldStored integerInterpreted value
Fee denominator Q10,000,000,000One whole fraction
Base fee f4,000,0000.0004 = 0.04% = 4 basis points
Off-peg multiplier M50,000,000,000A factor of 5
Limiting fee with this multiplier20,000,0000.20% = 20 basis points

The fivefold setting does not mean every swap pays five times the base fee. It sets the upper end of the formula’s range. With equal positive normalized balances, the result is the base fee. As one balance becomes very small relative to the other, the result approaches that upper end. Curve’s integration guide describes this base-to-multiplied-fee range. StableSwap-NG integration guide.

Keep the units visible when discussing a change. A move from 0.04% to 0.08% adds four basis points and doubles the fee rate. Describing it as “a 0.04% increase” leaves the reader guessing whether you mean percentage points or a relative change.

Build a fee table without pretending it is a swap

Let a and b be the two normalized balances supplied to the fee function. In the pinned implementation, first check M: when it is no greater than Q, the function returns f directly. Otherwise, multiply M − Q by 4 × a × b, divide by the square of a + b, and round down to obtain an intermediate integer t. Then divide M × f by t + Q and round down to obtain the fee integer F. Pinned StableSwap-NG fee calculation.

Convert F to a percentage by dividing by Q and multiplying by 100. For the following constructed table, each displayed normalized unit contains 1e18 integer units. Each row is a separate state; the rows are not successive trades.

Normalized a:bFee integer FEffective feeMultiple of base fee
5:54,000,0000.04000000%1.0000
6:44,132,2310.04132231%1.0331
8:25,617,9770.05617977%1.4045
9:18,196,7210.08196721%2.0492
99:117,265,1930.17265193%4.3163

Rebuild the 9:1 row to check the scale. The balance term 4 × a × b divided by the square of their sum is 0.36 before integer scaling. Multiplying 0.36 by M − Q gives t = 14,400,000,000. Add Q to obtain a denominator of 24,400,000,000. The numerator M × f is 200,000,000,000,000,000. Integer division returns 8,196,721.

The fivefold parameter has produced about 2.0492 times the base fee in this state. Applying the full fivefold factor immediately would overstate this fixed-state result. Applying only the base fee would understate it.

Notice that reversing a and b leaves every multiplication and sum unchanged. A fixed-state fee calculation is symmetric. It does not yet tell you whether a specified trade moves the pool toward or away from equal normalized balances.

Normalization is essential to that conclusion. Two tokens with different decimals or conversion rates can have unequal raw counts but equal normalized balances. The separate raw balances versus normalized xp example shows how to construct those inputs. Comparing wallet-style token counts can send the fee calculation to the wrong row before rounding even matters.

The getter and the finite swap use different states

In the pinned Views helper, dynamic_fee(i, j, pool) constructs current normalized balances and applies the fee function to the selected pair. It has no input-amount argument. Its result is useful evidence about that state, rather than a complete quote for a finite input. By contrast, get_dy calculates the trade’s endpoints before determining the fee. Pinned StableSwap-NG Views helper.

Curve’s conceptual explanation states that swaps use average balances before and after the exchange. This is how two trades starting in the same pool can face different fee rates when one restores balance and the other increases imbalance. Curve’s explanation of off-peg fees.

The averages here are the arithmetic means of two endpoints. In integer math, each endpoint sum is divided by two with truncation. They are not a time-weighted observation, and the calculation does not continuously integrate a fee over every intermediate reserve position. Nor does it simply take the fee computed at the final state.

Follow one finite swap through the midpoint

Consider another explicitly illustrative scenario: an ordinary two-coin pool with five normalized units of X and five of Y. Both tokens have 18 decimals, both rate multipliers are 1e18, and neither changes during the calculation. Fix internal amplification at 20,000 with A_PRECISION equal to 100; there is no amplification ramp. Retain f = 4,000,000 and M = 50,000,000,000.

Send four units of X and receive Y. Applying the pinned invariant routines gives D = ten normalized units. The new pre-fee X endpoint is nine, and the calculated Y endpoint is approximately 1.041666666667. The table retains sufficient decimal places for reading; the underlying check uses integer arithmetic throughout.

Stage in the hypothetical swapX normalized unitsY normalized unitsFee at that pair
Starting state550.04000000%
Calculated pre-fee endpoint91.0416666666670.08039949%
Endpoint averages used for the swap fee73.0208333333330.04577413%

The middle row describes the invariant’s calculated endpoint before fee retention. It is not a report of final accounting balances after the exchange. The fee calculation uses seven for X because that is the mean of five and nine. For Y, it uses the mean of five and the calculated remaining balance.

The pinned execution routine obtains gross normalized output by subtracting the calculated Y endpoint from the starting Y balance, then subtracting one integer unit for rounding. It applies the dynamic fee to that output, rounds the fee amount down and converts the remainder to raw output units. Pinned exchange calculation.

Here, gross output after the one-unit adjustment is 3.958333333333333333 Y. The midpoint fee integer is 4,577,413. The fee amount is 0.001811892645833333 Y, leaving exactly 3.9565214406875 Y under the assumptions.

Using only the starting base fee on that same gross output would instead produce 3.95675 Y. It overstates the constructed output by 0.0002285593125 Y. Using the ending-state rate would overcharge relative to the specified midpoint method. Neither shortcut reproduces this example.

The invariant’s curvature and the fee deduction are separate parts of the output calculation. A fee percentage alone cannot explain the entire difference between four X sent and Y received. The constant-product versus StableSwap comparison isolates the invariant effect before adding NG’s state-dependent fees.

Catch the errors that a percentage hides

An “off-peg” fee is not an external certification of a depeg. In these calculations, the changing inputs are normalized pool balances. A high result does not identify a redemption failure, an issuer’s solvency or an external dollar price. Those require separate evidence.

Keep allocation separate from charging, too. An admin share determines where part of an assessed trading fee goes; it is not another fee to add to F. The protocol fees versus revenue ledger explains how successive allocations can otherwise be counted twice. For LP valuation, virtual price versus token redemption examines another distinct measure; a higher trading fee does not establish the redemption value of the pool’s assets.

Record the resolved Views helper when a deployed pool delegates its quote methods through the factory. A pinned exchange implementation alone does not identify the helper answering a quote. Curve’s plain-pool documentation shows this delegation for dynamic_fee. Curve’s fee getter implementation.

Rounding shortcuts also matter. Preserve integer division at the intermediate balance term, at the final fee rate, at the fee amount and at conversion to raw tokens. Rounding only the final decimal display follows a different method. The single-unit output adjustment must be made in normalized integer units, rather than subtracting one whole token.

Keep a reproducible fee worksheet

For a real quote review, retain the following fields together. Record unavailable evidence explicitly rather than inserting an assumed default.

Evidence to retainWhat it resolves
Chain, pool address, implementation and resolved Views helperWhich fee, quote and exchange routines apply
Block reference and observation timeWhether parameters, balances and rates describe one state
Coin indices, token decimals and rate multipliersThe exact normalization and trade direction
Base fee integer and multiplier integerThe two fields’ scales and permitted dynamic range
Gross input and current amplificationThe calculated trade endpoints
Current pair fee and amount-specific outputThe difference between a state observation and a finite quote
Minimum acceptable output and separate network costsThe transaction’s delivery requirement and total cost boundary

Use the pool’s amount-specific quoting route for the intended input, then retain the result with its state reference. Curve documents get_dy for output quotes and _min_dy for the minimum output accepted by an exchange. An earlier quote does not freeze the pool until execution. Curve’s quoting and swap interfaces.

Finish the review with three labeled numbers: the stored base fee, the current pair-state fee and the net output for the intended amount. If they were calculated from different blocks, different rate conventions or different implementations, reconcile those inputs before treating the comparison as an execution check.

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.