Buy Token
Purchases tokens from the bonding curve using SOL.
Instruction INDEX
2
Instruction
Parameters
pda_token_nonce
u8
Nonce for the token owner PDA
sol_to_spend
u64
Amount of SOL to spend in lamports
min_token_to_receive
u64
Minimum acceptable token 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
System program
System program
SystemProgram.programId
3
Token program
SPL Token program
TOKEN_PROGRAM_ID
4
Token owner PDA
Bonding curve account
[Buffer.from("token_owner"), mint.toBuffer(), [nonce]]
5
Token mint
Token mint address
Provided by user
6
Owner token account
Token account for PDA
getAssociatedTokenAddress(mint, ownerPDA, true)
7
User token account
User's token account
getAssociatedTokenAddress(mint, userWallet, false)
8
Fee account
Platform fee account
Fixed address (see Reference section)
9
Properties account
Platform configuration
[Buffer.from("settings")]
10
Program account
SC Bonding Curve program
SC Bonding Curve program ID
11
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%)
Calculates amount without fee (99% of sol_to_spend)
Retrieves current pool balances (virtual + real SOL and tokens)
Calculates expected token amount using the bonding curve formula
Verifies expected token amount meets minimum specified (slippage check)
Checks if purchase would finalize the token sale
If finalizing, adjusts amounts accordingly and marks the token as finalized
Transfers SOL to the bonding curve and fee account
Transfers tokens to the user
Updates pool balances in the bonding curve account
Records buy data in logs
Price Calculation
Where:
pool_token_balance
= virtual_token + real_tokenpool_sol_balance
= virtual_sol + real_solsol_amount
= amount of SOL after fee deduction
Notes
The platform fee is deducted from the SOL amount before calculating token amount
If the purchase would leave less than POOL_MIGRATION_RESERVES tokens in the pool, the token sale is finalized
A finalized token can no longer be traded on the bonding curve and is ready for migration
Example Usage
Last updated