# Bonding Curve - Solana

### Introduction

This is an implementation of a bonding curve mechanism for buying and selling Moonshot tokens based on virtual collateral and token reserves, also known as a Constant Product curve. The curve has an quadratic shape so that the price rises slowly at the start and fast towards the end. \
\
Once \~80% of the 1B token supply is sold on the curve, the market cap reaches \~431 SOL and all remaining tokens & collateral migrate to either Meteora or Raydium (as set by the creator at  launch).   Approximately \~88 SOL of collateral is collected on the curve.&#x20;

{% hint style="info" %}
The curve described here applies to all coins launched after 12 August, '24. Coins launched prior use a linear curve that collects \~250 SOL in collateral before migration.
{% endhint %}

### Definitions

#### Curve

vTOKEN \* vSOL = k&#x20;

Where,

1. vTOKEN = virtual reserve of the token&#x20;
2. vSOL = virtual reserve of the collateral (SOL)
3. k = constant that determines the shape of the curve

#### Setting initial values&#x20;

We set the value of the coefficient k based on the initial price of the token

k = vTOKEN \* vSOL  = iVTOKEN \* iVSOL        - (1)

Where, iVTOKEN is initial amount of vTOKEN = 1,073,000,000

Initial price is set at 27.95 lamports or 0.00000002795 SOL

So initial price = iVSOL/iVTOKEN = 27.95 lamports

Initial virtual and collateral reserves are set as follows :

* iVTOKEN = 1,073,000,000
* iVSOL = 30

#### Values&#x20;

* Total supply of tokens (T)  = 1,000,000,000
* Minimum price is set to 27.95 lamports or 27.95e^-9 SOL
* Mcap = price \* 1,000,000,000
* Allocation at Migration (A)  = \~80% of total supply
  * The minimal token amount is 799820983207404442 (tokens have 9 decimals). That's the exact point trading stops and the migration begins. Its close to 80% of token allocation but not exact since the smart contract derives this number from the the MarketCapThreshold
  * MarketCapThreshold is set to 345 SOL (A \* price). The equates to a fully diluted market cap of \~431 SOL&#x20;
  * If a buyer places a larger trade right before the \~80% threshold, a max allocation of 82% can be sold on the curve
  * Curve progress % = allocation / min token amount (799820983207404442)
* Fee to be deducted at the time of migration (F) = 6 SOL for Raydium or 3 SOL for Meteora
  * **Raydium:** 1 SOL is paid to Raydium and 3 SOL is paid to openbook
  * **Meteora**: 1 SOL for creating various token accounts for [Launch. Lock. Earn](https://docs.moonshot.cc/faq#whats-launch-lock-and-earn)
  * 2 SOL migration fees paid to Moonshot

#### Calculation on tokens to Migrate (M) :&#x20;

For calculating M, we will calculate, at the time of migration (when supply reaches the allocation A),

* SOL collected as collateral
* Reduce the fee to be charged from the collateral SOL
* Calculate the price at the time of migration (allocation reached)
* Determine the no of tokens (to be migrated) based on the collateral collected and price at allocation

M = (collateral collected - migration fees) / price of token

* Collateral Collected= current\_virtual\_collateral\_reserves - initial\_collateral\_reserves&#x20;
* Migration fees = Fee charged for creating a pool on Raydium/Meteora + Moonshot migration Fee = 6SOL
* Price of token = current\_virtual\_collateral\_reserve / current\_virtual\_token\_reserve

#### Calculating tokens to Burn (B)

Tokens to Burn (B) = T - A - M

&#x20;    \= Total Supply - allocation(tokens sold at migration) - tokens to migrate (M)

So the total tokens in circulation post migration would be = A + M

\
Example
-------

Token Address : 6ovpeZNwNbXJzUaXMs8zozh9JvnJPq5teUJTQtLhRDwg

Total Supply (T) = 1,000,000,000

[Allocation at Migration](https://solscan.io/account/4kG9mqhHYjKDMwWM1xq1EZZtNUrn9wxdvhbQGs651u9a#splTransfers) : 801,085,146

[Collateral Collected at Migration](https://solscan.io/account/4kG9mqhHYjKDMwWM1xq1EZZtNUrn9wxdvhbQGs651u9a#splTransfers) : 88.386383546

[Collateral as SOL shifted to Raydium](https://solscan.io/tx/2AfEMzvPScRP1BdAkfUsVqM517tx9kdnZHVaNmS9gFHhJMTwQZzgxyc6cAG4K8GGvtbXPm9czxVoUPeUyNL2MKhZ) = collateral collected - Fees

\= 88.386383546 - 6

\= 82.386383546

Price at migration = (Difference in virtual token reserves) / (Difference in virtual collateral reserves)

&#x20;     \= (1,073,000,000 -801085145) / (88.386383546 + 30)&#x20;

&#x20;     \= 4.35380346e-7

[Tokens to Migrate (M)](https://solscan.io/tx/2AfEMzvPScRP1BdAkfUsVqM517tx9kdnZHVaNmS9gFHhJMTwQZzgxyc6cAG4K8GGvtbXPm9czxVoUPeUyNL2MKhZ) = (collateral collected - Fees) / Price

\= 82.386383546 / 4.35380346e-7

\= 189,228,531

[Tokens to Burn](https://solscan.io/tx/xqJmLhHLENjS5zUVfH4FFD5v1FiZPRWhkcmRHGT4XAipLpipjdXaGaKK7yFw3yDX3HbeLwGFuYuaEQeKxARVVSn)(B) = T - A - M

&#x20; \= 1,000,000,000 - 801,085,146 - 189,228,531

\= 9,686,323

[Raydium LP tokens burnt](https://solscan.io/token/3BXCVLEKjcPz1UKKVMELSj6yTEKTXQt1zU1WiQyL7EBV)

\
Calculating prices for buy & sell
---------------------------------

Please us our [Bot SDK](https://docs.moonshot.cc/developers/bot-sdk-solana) or contact our team for support
