Price Calculation
The SC Bonding Curve uses a constant product formula for its bonding curve, which determines the price of tokens during buying and selling operations.
Bonding Curve Formula
The core formula for the SC Bonding Curve bonding curve is:
k = (virtual_sol + real_sol) \* (virtual_token + real_token)
Where:
virtual_sol
andvirtual_token
are the initial virtual liquidity amounts taken from a configuration account.real_sol
andreal_token
are the actual SOL and token in the bonding curve
This constant product formula ensures that the product of the two sides remains constant, leading to a price curve that increases as more tokens are purchased and decreases as tokens are sold.
Platform Fee
SC Bonding Curve charges a 1% platform fee on all transactions. This fee is applied differently depending on whether the user is buying or selling:
For buying: Fee is deducted from input SOL before calculating token amount
For selling: Fee is deducted from output SOL after calculating SOL amount
Buy Price Calculation (With Fee)
When a user buys tokens with SOL, the process includes these steps:
Deduct 1% platform fee from input SOL
Calculate token amount using the remaining SOL
Transfer tokens to the user
The formula with the platform fee is:
fee_amount = sol_to_spend * 0.01
amount_without_fee = sol_to_spend - fee_amount
token_amount = pool_token_balance * amount_without_fee / (pool_sol_balance + amount_without_fee)
Where:
pool_token_balance
= virtual_token + real_tokenpool_sol_balance
= virtual_sol + real_solsol_to_spend
= total SOL amount the user is spending
Implementation in the Contract
// Platform fee in basis points (1% = 100 basis points)
let platform_fee_bps = 100;
// Calculate amount after fee deduction
let amount_without_fee = sol_to_spend * (10000u64 - platform_fee_bps) / 10000u64;
// Calculate expected tokens using amount after fee
let expected_token: u64 = u64::try_from(
(pool_token_balance as u128) * (amount_without_fee as u128) /
((pool_sol_balance + amount_without_fee) as u128)
).unwrap();
Example Calculation (Buy)
Let's say:
Virtual SOL = 1,000 SOL
Virtual Token = 1,000,000 tokens
Real SOL in pool = 500 SOL
Real Token in pool = 500,000 tokens
User wants to spend 10 SOL
The calculation would be:
fee_amount = 10 * 0.01 = 0.1 SOL
amount_without_fee = 10 - 0.1 = 9.9 SOL
pool_token_balance = 1,000,000 + 500,000 = 1,500,000 tokens
pool_sol_balance = 1,000 + 500 = 1,500 SOL
token_amount = 1,500,000 * 9.9 / (1,500 + 9.9)
token_amount = 14,850,000 / 1,509.9
token_amount ≈ 9,834.44 tokens
Sell Price Calculation (With Fee)
When a user sells tokens to receive SOL, the process includes these steps:
Calculate SOL amount using the constant product formula
Deduct 1% platform fee from the calculated SOL amount
Transfer the remaining SOL to the user
The formula with the platform fee is:
sol_amount_before_fee = pool_sol_balance * token_amount / (pool_token_balance + token_amount)
fee_amount = sol_amount_before_fee * 0.01
sol_amount_after_fee = sol_amount_before_fee - fee_amount
Where:
pool_token_balance
= virtual_token + real_tokenpool_sol_balance
= virtual_sol + real_soltoken_amount
= amount of tokens being sold
Implementation in the Contract
// Calculate SOL amount before fee
let sol_to_return: u64 = u64::try_from(
(pool_sol_balance as u128) * (token_to_spend as u128) /
((pool_token_balance + token_to_spend) as u128)
).unwrap();
// Platform fee in basis points (1% = 100 basis points)
let platform_fee_bps = 100;
// Calculate fee and final SOL amount
let sol_to_fee = sol_to_return * platform_fee_bps / 10000u64;
let sol_to_user = sol_to_return - sol_to_fee;
Example Calculation (Sell)
Using the same pool state as above, if a user wants to sell 10,000 tokens:
pool_token_balance = 1,000,000 + 500,000 = 1,500,000 tokens
pool_sol_balance = 1,000 + 500 = 1,500 SOL
sol_amount_before_fee = 1,500 * 10,000 / (1,500,000 + 10,000)
sol_amount_before_fee = 15,000,000 / 1,510,000
sol_amount_before_fee ≈ 9.93 SOL
fee_amount = 9.93 * 0.01 = 0.0993 SOL
sol_amount_after_fee = 9.93 - 0.0993 = 9.8307 SOL
Impact of Virtual Liquidity
The virtual liquidity parameters have a significant impact on the price curve:
Higher Virtual Liquidity = Lower Price Impact (more stable price)
Lower Virtual Liquidity = Higher Price Impact (more volatile price)
By adjusting the virtual liquidity, the platform can regulate how much SOL should be collected for migration and maintain appropriate market capitalization regardless of SOL price fluctuations.
Last updated