A production-grade Solana smart contract implementation of Pump.fun's bonding curve token launch mechanism, built with Anchor 0.30+ and SPL Token-2022.
- Overview
- Features
- Bonding Curve Mechanics
- Architecture
- Installation
- Building & Testing
- Deployment
- Contact
This project implements a complete bonding curve mechanism for launching memecoins on Solana. Users can create tokens with metadata, trade them instantly via a bonding curve (buys push price up, sells pull price down), and automatically graduate to a DEX liquidity pool when the curve reaches completion.
- Token Supply: 1,000,000,000 tokens with 6 decimals
- Bonding Curve Tokens: ~793 million tokens available for trading
- Reserved Tokens: ~207 million tokens reserved for DEX liquidity pool
- Token Standard: SPL Token-2022 with Metadata Pointer and Token Metadata extensions
- Graduation Target:
500 SOL virtual market cap ($75k at $150/SOL)
-
Token Creation
- Create Token-2022 mints with metadata (name, symbol, URI)
- Initialize bonding curve with virtual reserves
- Pay creation fee (0.02 SOL)
-
Instant Trading
- Buy tokens with SOL (mints tokens, increases price)
- Sell tokens for SOL (burns tokens, decreases price)
- Constant product bonding curve formula
- Slippage protection
-
Protocol Fees
- 0.5% fee on all buys and sells
- Fees sent to treasury PDA
- Creation fee for new tokens
-
Automatic Graduation
- Curve completes when virtual SOL reserve reaches ~500 SOL
- Anyone can call
completeinstruction - Prepares for DEX pool creation (stub implementation)
- β Anchor framework best practices
- β PDA-based account management
- β Slippage checks on all trades
- β Reentrancy protection via Anchor's account model
- β Authority checks on all privileged operations
- β Custom error types for clear failure cases
- β Math overflow protection with checked arithmetic
The bonding curve uses a constant product formula (similar to Uniswap's x * y = k):
k = virtual_sol_reserve * virtual_token_reserve
When Buying (SOL β Tokens):
- User sends
sol_inSOL - New virtual SOL reserve:
virtual_sol_reserve + sol_in - New virtual token reserve:
k / (virtual_sol_reserve + sol_in) - Tokens out:
virtual_token_reserve - new_virtual_token_reserve - Protocol fee (0.5%) deducted from tokens out
When Selling (Tokens β SOL):
- User burns
tokens_intokens - New virtual token reserve:
virtual_token_reserve + tokens_in - New virtual SOL reserve:
k / (virtual_token_reserve + tokens_in) - SOL out:
virtual_sol_reserve - new_virtual_sol_reserve - Protocol fee (0.5%) deducted from SOL out
k = virtual_sol_reserve * virtual_token_reserve
new_sol_reserve = virtual_sol_reserve + sol_in
new_token_reserve = k / new_sol_reserve
tokens_out = virtual_token_reserve - new_token_reserve
tokens_out_after_fee = tokens_out * (1 - protocol_fee_bps / 10000)
k = virtual_sol_reserve * virtual_token_reserve
new_token_reserve = virtual_token_reserve + tokens_in
new_sol_reserve = k / new_token_reserve
sol_out = virtual_sol_reserve - new_sol_reserve
sol_out_after_fee = sol_out * (1 - protocol_fee_bps / 10000)
- Starting Price: Very low (determined by initial virtual reserves: 30 SOL / 793M tokens)
- Price Increases: Each buy increases the virtual SOL reserve, decreasing available tokens
- Price Decreases: Each sell decreases the virtual SOL reserve, increasing available tokens
- Completion: When virtual SOL reserve reaches ~500 SOL, curve is complete
- Virtual Reserves: Used for price calculation (x * y = k formula)
- Real SOL Reserve: Accumulates actual SOL from buys (used for DEX liquidity)
- Virtual reserves start at 30 SOL and 793M tokens
- Real SOL accumulates from each buy and is used when graduating to DEX
pump-fun-clone/
βββ programs/
β βββ pump-fun-clone/
β βββ src/
β βββ lib.rs # Program entry point
β βββ state.rs # Account structs (GlobalConfig, BondingCurve)
β βββ errors.rs # Custom error types
β βββ constants.rs # Constants and bonding curve math
β βββ instructions/
β βββ mod.rs # Instruction module exports
β βββ initialize.rs # Initialize global config
β βββ create.rs # Create token + bonding curve
β βββ buy.rs # Buy tokens from curve
β βββ sell.rs # Sell tokens to curve
β βββ complete.rs # Complete/graduate curve
βββ tests/
βββ pump-fun-clone.ts # Integration tests
- PDA:
[b"global_config"] - Fields:
authority: Protocol authoritytreasury: Treasury PDA addressprotocol_fee_bps: Fee in basis points (50 = 0.5%)creation_fee: Token creation fee in lamportstotal_tokens_created: Countertreasury_bump: Bump seed for treasury PDA
- PDA:
[b"bonding_curve", mint] - Fields:
mint: Token mint addresscreator: Token creatorvirtual_sol_reserve: Virtual SOL reserve for pricingvirtual_token_reserve: Virtual token reserve for pricingreal_sol_reserve: Accumulated real SOLtokens_sold: Total tokens soldcompleted: Whether curve is completecreated_at: Creation timestampcompleted_at: Completion timestamp (optional)bump: PDA bump seed
- PDA:
[b"treasury", global_config] - Receives all protocol fees and creation fees
- Accumulates SOL for DEX liquidity pool creation
1. Initialize
ββ> Creates GlobalConfig and Treasury PDAs
2. Create Token
ββ> Creates Token-2022 mint with metadata
ββ> Initializes BondingCurve account
ββ> Pays creation fee to treasury
3. Buy Tokens
ββ> Transfers SOL from buyer
ββ> Calculates tokens using bonding curve
ββ> Mints tokens to buyer
ββ> Updates virtual reserves
ββ> Checks for completion
4. Sell Tokens
ββ> Burns tokens from seller
ββ> Calculates SOL using bonding curve
ββ> Transfers SOL to seller
ββ> Updates virtual reserves
5. Complete Curve
ββ> Verifies completion threshold
ββ> Marks curve as complete
ββ> Emits completion event
ββ> (In production: triggers DEX pool creation)
- Rust 1.70+
- Solana CLI 1.18+
- Anchor CLI 0.30+
- Node.js 18+ and Yarn/npm
-
Clone the repository
git clone <repository-url> cd Solana-Pumpfun-Smart-Contract-Clone
-
Install Anchor
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force avm install latest avm use latest
-
Install dependencies
anchor build
-
Install test dependencies
cd tests yarn install # or npm install
anchor buildThis will:
- Compile the Rust program
- Generate the IDL (Interface Definition Language)
- Create the program binary
anchor testOr run tests with verbose output:
anchor test --skip-local-validator-
Start local validator
solana-test-validator
-
Deploy program
anchor deploy
-
Run tests
anchor test --skip-local-validator
The test suite includes:
- β Global config initialization
- β Token creation with bonding curve
- β Multiple buy operations (price increase verification)
- β Sell operations (price decrease verification)
- β Curve completion
- β Slippage protection
- β Fee calculations
-
Set Solana CLI to devnet
solana config set --url devnet -
Airdrop SOL (if needed)
solana airdrop 2 <your-wallet-address>
-
Update program ID
- Generate new keypair:
solana-keygen new -o target/deploy/pump_fun_clone-keypair.json - Update
declare_id!inlib.rs - Update
Anchor.tomlwith new program ID
- Generate new keypair:
-
Build and deploy
anchor build anchor deploy
-
Set Solana CLI to mainnet
solana config set --url mainnet-beta -
Build for mainnet
anchor build
-
Deploy (requires sufficient SOL)
anchor deploy
-
Verify deployment
solana program show <program-id>
-
Initialize global config
- Call
initializeinstruction with protocol authority - This sets up the GlobalConfig and Treasury PDAs
- Call
-
Verify initialization
- Check GlobalConfig account exists
- Verify treasury PDA is funded
- Telegram: https://t.me/codiiman
- Twitter: https://x.com/codiiman_