ProtocolCore release 0.1.0

Constant-product AMM

The Core CPMM quote uses integer fee arithmetic, effective input, floor division, and an LP-claim reserve floor.

For an ideal constant-product pool with reserves x and y, a swap of input dx for output dy follows:

xy=k,dy=y dxx+dxxy = k, \qquad dy = \frac{y\,dx}{x+dx}

The Core implementation applies fees before pricing and uses integer arithmetic. It also enforces a remaining-reserve floor so both the locked and redeemable LP portions retain a positive proportional claim.

Core quote arithmetic

Let A be the input amount and f the pool fee tier in basis points. The integer fee is floored:

F=⌊Af10,000⌋,P=A−FF = \left\lfloor\frac{A f}{10{,}000}\right\rfloor, \qquad P = A-F

P is the pricing input. For input reserve X and output reserve Y, Core evaluates the equivalent scaled expression:

E=10,000P,O=⌊YE10,000X+E⌋E = 10{,}000P, \qquad O = \left\lfloor\frac{YE}{10{,}000X+E}\right\rfloor

This is the integer form of the fee-adjusted quote. Multiplying numerator and denominator by the fee denominator avoids a fractional fee-adjusted input. The implementation uses checked arithmetic and a 256-bit intermediate for the output numerator.

Reserve and direction mapping

The selected direction determines which LP vault is reserve_in and which is reserve_out. For A→B, X is vault A and Y is vault B; B→A reverses them. The fee and public input amount are denominated in the input asset.

LP-claim reserve floor

The LP mint has 9 decimals and keeps 1,000 base units permanently locked. With total LP supply L and locked supply L₀, Core derives:

Rmin⁡=max⁡ ⁣(⌈LL0⌉,⌈LL−L0⌉)R_{\min}=\max\!\left(\left\lceil\frac{L}{L_0}\right\rceil,\left\lceil\frac{L}{L-L_0}\right\rceil\right)

An output is rejected if the depleted reserve would fall below Rmin. This protects positive integer-proportional claims for both the locked amount and provider LP tokens.

For the fee split and exact fee tiers, see Fees. The same quote function is used by the SDK's quote and privateSwap flows.

PreviousCurrent releaseNext Fees
Source baseline: frozen Core v0.1.0 / SDK v0.1.1.