Bonding curve
Exact formulas and rounding rules.
Each launch uses a virtual constant-product curve. State: vT (virtual token reserves), vS (virtual SOL reserves), rT (real tokens left for sale), rS (real SOL held). The invariant is vT · vS ≥ k₀. All math is u128 integer arithmetic with explicit rounding; the web app uses an exact BigInt port of the same code and both are tested against shared vectors.
Buy
fee = ceil(g · f / 10 000) g = gross SOL in, f = fee bps
net = g − fee
out = floor(vT · net / (vS + net))
if out ≥ rT (the buy would empty the curve):
out = rT
net = ceil(vS · out / (vT − out))
g = ceil(net · 10 000 / (10 000 − f))
fee = g − net only g is charged; the curve completesSell
gross = min(floor(vS · t / (vT + t)), rS)
fee = ceil(gross · f / 10 000)
out = gross − feeFee split
sweep = floor(fee · s / 10 000)
creator = floor(fee · c / 10 000)
protocol = fee − sweep − creator (s + c + p = 10 000)Display values
- Spot price (lamports per base unit) =
vS / vT; market cap =vS · totalSupply / vT. - Price impact =
1 − (out / net) / (vT / vS), computed in bps. - Slippage:
minOut = floor(quoteOut · (10 000 − slippageBps) / 10 000). The program rejects the trade if the actual output is belowminOut.
Rounding always favours the curve and the vaults, never the trader: fees round up, outputs round down, required inputs round up.