Sell Token
Sells tokens back to the bonding curve in exchange for SOL.
Instruction
Parameters
pda_token_nonce
u8
Nonce for the token owner PDA
token_to_spend
u64
Amount of tokens to sell
min_sol_to_receive
u64
Minimum acceptable SOL amount to receive (slippage protection)
logging_account_bump
u8
Bump for the logging authority PDA
Account Setup
1
Payer account
Transaction signer (User wallet)
-
2
Token program
SPL Token program
TOKEN_PROGRAM_ID
3
Token owner PDA
Bonding curve account
[Buffer.from("token_owner"), mint.toBuffer(), [nonce]]
4
Token mint
Token mint address
Provided by user
5
Owner token account
Token account for PDA
getAssociatedTokenAddress(mint, ownerPDA, true)
6
User token account
User's token account
getAssociatedTokenAddress(mint, userWallet, false)
7
Fee account
Platform fee account
Fixed address (see Reference section)
8
Program account
SC bonding curve program
SC bonding curve program ID
9
Properties account
Platform configuration
[Buffer.from("settings")]
10
Log authority account
For structured logs
[Buffer.from("logging_authority")]
Function Logic
Verifies the PDA token owner matches the expected PDA for the token mint
Retrieves platform fee from properties account (currently 1%)
Verifies the token is not finalized or mark as finalized if migration threshold is crossed
Checks if trading is closed for the token
Calculates expected SOL return amount using the bonding curve formula
Verifies expected SOL amount meets minimum specified (slippage check)
Updates pool balances in the bonding curve account
Transfers tokens from user to the bonding curve
Calculates fee amount and deducts from the SOL return
Transfers remaining SOL to the user
Transfers fee amount to the fee account
Records sell data in logs
Price Calculation
Where:
pool_token_balance
= virtual_token + real_tokenpool_sol_balance
= virtual_sol + real_soltoken_amount
= amount of tokens being sold
Notes
The platform fee is deducted from the SOL return amount
If the sale would leave less than POOL_MIGRATION_RESERVES tokens in the pool, the token is marked as finalized
Once finalized, a token can no longer be traded on the bonding curve
Example Usage
Last updated