5: Bonding curve mathematics
Constant Product Formula
LaunchLab uses a constant product bonding curve similar to Uniswap V2. However, LaunchLab uses virtual reserves and real reserves to control the curve shape and fundraising goals.
Reserve System
Each pool has 4 reserve values:
Virtual Base
VA
Virtual token reserves (controls initial price)
Virtual Quote
VB
Virtual SOL reserves (controls initial price)
Real Base
RA
Actual tokens in the pool
Real Quote
RB
Actual SOL raised
Initial Price: P_initial = VB / VA
Buy (Buying tokens with SOL)
Formulas:
Input Reserves (inR) = VB + RB
Output Reserves (outR) = VA - RA
Effective Quote (after fee) = amountIn * (10000 - feeBps) / 10000
Tokens Out = (outR * effectiveQuote) / (inR + effectiveQuote)Example:
Given:
Virtual Quote (VB) = 30,000,000,000 lamports (30 SOL)
Virtual Base (VA) = 793,100,000,000,000 (793,100 tokens, 6 decimals)
Real Quote (RB) = 0 (no purchases yet)
Real Base (RA) = 0
Fee = 1.05% (105 bps)
Amount In = 1,000,000,000 lamports (1 SOL)
Calculation:
inR = 30,000,000,000 + 0 = 30,000,000,000
outR = 793,100,000,000,000 - 0 = 793,100,000,000,000
effectiveQuote = 1,000,000,000 * (10000 - 105) / 10000 = 989,500,000
tokensOut = (793,100,000,000,000 * 989,500,000) / (30,000,000,000 + 989,500,000)
= 784,481,793,530,905 / 30,989,500,000
= 25,312,138,728 (≈ 25,312 tokens)Price Impact
Price impact measures how much your trade affects the price:
Price Before = outR / inR
Price After = (outR - amountOut) / (inR + effectiveIn)
Impact % = ((Price Before - Price After) / Price Before) * 100Fees are applied to the input amount (SOL or tokens) and the effective amount after fee is used in the bonding curve formulas above.
Last updated
