Bonding Curve Formulas
Mathematical Foundation
The Dynamic Bonding Curve uses the following key parameters:
migration_quote_threshold: The minimum quote amount required for migrationl: Liquidity value for a curve segmentpa: Starting price (sqrt) for a curve segmentpb: Ending price (sqrt) for a curve segment
Example Configuration
sqrt_start_price = 1
curve = [
(sqrt_price = 2, liquidity = 100),
(sqrt_price = 4, liquidity = 500)
]This creates two curve segments:
(l = 100, pa = 1, pb = 2)(l = 500, pa = 2, pb = 4)
Each segment is defined by its sqrt_price and liquidity values.
Core Formulas
1. Bonding Curve Amount
The bonding curve amount determines how much of the base token is required for a given quote amount within a curve segment.
2. Migration Quote Threshold
The migration quote threshold is the minimum amount of quote tokens that must be in the pool before it can migrate to a DAMM pool.
3. Migration Price Calculation
When a pool reaches the migration threshold, the migration price is calculated based on:
Migration Fee Percentage: The percentage fee taken during migrationMigration Amount: The total amount being migrated
Fee Formulas
Pool Fee Interface
poolFees: {
baseFee: {
cliffFeeNumerator: BN // Initial fee numerator (base fee)
firstFactor: number // feeScheduler: numberOfPeriod, rateLimiter: feeIncrementBps
secondFactor: BN // feeScheduler: periodFrequency, rateLimiter: maxLimiterDuration
thirdFactor: BN // feeScheduler: reductionFactor, rateLimiter: referenceAmount
baseFeeMode: number // 0: FeeSchedulerLinear, 1: FeeSchedulerExponential, 2: RateLimiter
}
dynamicFee: {
// Optional dynamic fee
binStep: number // u16 value representing the bin step in bps
binStepU128: BN // u128 value for a more accurate bin step
filterPeriod: number // Minimum time that must pass between fee updates
decayPeriod: number // Period after the volatility starts decaying (must be > filterPeriod)
reductionFactor: number // Controls how quickly volatility decays over time
variableFeeControl: number // Multiplier that determines how much volatility affects fees
maxVolatilityAccumulator: number // Caps the maximum volatility that can be accumulated
} | null
}Migration Fee
The migration fee is calculated based on:
quote_min: Minimum quote amountmigration_quote_threshold: The threshold for migration
migrationFee: {
// Optional migration fee (set as 0 for feePercentage and 0 for creatorFeePercentage for no migration fee)
feePercentage: number // The percentage of fee taken from migration quote threshold (0-50)
creatorFeePercentage: number // The fee share percentage for the creator from the migration fee (0-100)
}When using buildCurveWithMarketCap, the initial_market_cap is calculated to ensure the desired market cap at migration.
Formula
let D = desiredMarketCap and M = migrationMarketCap and f = migrationFee and I = initialMarketCap
requiredRatio = sqrt(D / M)
percentageSupplyOnMigration = (requiredRatio * (1 - f) * 100) / (1 + requiredRatio * (1 - f))
x = percentageSupplyOnMigration / ((100 - V - L) - percentageSupplyOnMigration)
I = M * x²Example
let D = 10000 / SOL_PRICE
let M = 80000 / SOL_PRICE
let f = 0.5
let V = 0
let L = 1 / 1000000000 // leftover needs to be indicated to cover precision loss
let requiredRatio = Math.sqrt(D / M)
let percentageSupplyOnMigration =
(requiredRatio * (1 - f) * 100) / (1 + requiredRatio * (1 - f))
let x =
percentageSupplyOnMigration /
(100 - V - L - percentageSupplyOnMigration)
let I = M * x * x
const curveConfig = buildCurveWithMarketCap({
totalTokenSupply: 1000000000,
initialMarketCap: I,
migrationMarketCap: M,
migrationOption: MigrationOption.MET_DAMM_V2,
tokenBaseDecimal: TokenDecimal.SIX,
tokenQuoteDecimal: TokenDecimal.NINE,
lockedVestingParam: {
totalLockedVestingAmount: 0,
numberOfVestingPeriod: 0,
cliffUnlockAmount: 0,
totalVestingDuration: 0,
cliffDurationFromMigrationTime: 0,
},
baseFeeParams: {
baseFeeMode: BaseFeeMode.FeeSchedulerLinear,
feeSchedulerParam: {
startingFeeBps: 100,
endingFeeBps: 100,
numberOfPeriod: 0,
totalDuration: 0,
},
},
dynamicFeeEnabled: false,
activationType: ActivationType.Slot,
collectFeeMode: CollectFeeMode.QuoteToken,
migrationFeeOption: MigrationFeeOption.FixedBps100,
tokenType: TokenType.SPL,
partnerLpPercentage: 0,
creatorLpPercentage: 0,
partnerLockedLpPercentage: 100,
creatorLockedLpPercentage: 0,
creatorTradingFeePercentage: 0,
leftover: 1,
tokenUpdateAuthority: 0,
migrationFee: {
feePercentage: 50,
creatorFeePercentage: 0,
},
})Last updated on