Something.cool
  • Getting started
    • Why Something.cool?
    • 1st stage - Bonding curve
    • 2nd stage - CoolDEX trading
  • Zero-fee coins
    • What is Zero-fee coin?
    • How to launch Zero-fee coin
  • Community coins
    • What is Community coin?
    • Community contribution / How it works?
      • Holders
      • Liquidity providers
      • Burning
    • How to launch Сommunity coin
  • Features
    • Coin Explore
      • New Pairs
      • Coin Vision
    • Spaces
    • Rewards
  • Community
    • Referral program
    • X
    • Media kit
  • Developer Resources
  • Platform Architecture
    • Technical Introduction
    • Overview
    • Components
  • SC Bonding Curve
    • Overview
    • Functions
      • Create Token
      • Buy Token
      • Sell Token
      • Migrate
      • Admin Set Properties
    • Price Calculation
    • Fees
  • CoolDEX
    • Overview
    • Functions
      • Initialize Pool
      • Swap Base In
      • Swap Base Out
      • Deposit
      • Withdraw
      • Withdraw PnL
    • Price Calculation
    • Fees
  • Token Types
    • Token Types
  • Migration Process
    • Migration Process
  • Rewards Claiming
    • Overview
    • Authentication
    • Endpoints
    • Errors
    • Example
  • Reference
    • SC Bonding Curve IDL
    • CoolDEX IDL
    • Log Structure
    • DEVNET EXAMPLES
  • INTERNAL API
    • Overview
    • Register
  • Example: Registering a User via Internal API (JavaScript)
Powered by GitBook
On this page
  • Bonding Curve Formula
  • Platform Fee
  • Buy Price Calculation (With Fee)
  • Implementation in the Contract
  • Example Calculation (Buy)
  • Sell Price Calculation (With Fee)
  • Implementation in the Contract
  • Example Calculation (Sell)
  • Impact of Virtual Liquidity
  1. SC Bonding Curve

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 and virtual_token are the initial virtual liquidity amounts taken from a configuration account.

  • real_sol and real_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:

  1. Deduct 1% platform fee from input SOL

  2. Calculate token amount using the remaining SOL

  3. 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_token

  • pool_sol_balance = virtual_sol + real_sol

  • sol_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:

  1. Calculate SOL amount using the constant product formula

  2. Deduct 1% platform fee from the calculated SOL amount

  3. 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_token

  • pool_sol_balance = virtual_sol + real_sol

  • token_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:

  1. Higher Virtual Liquidity = Lower Price Impact (more stable price)

  2. 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.

PreviousAdmin Set PropertiesNextFees

Last updated 2 months ago