A comprehensive Solana smart contract implementation inspired by pump.fun, featuring bonding curve mechanics, token creation, and automated market making functionality.
This project implements a decentralized token launch platform on Solana with the following key features:
- Bonding Curve Mechanics: Automated price discovery using virtual reserves
- Token Creation: Mint new tokens with metadata support
- Automated Market Making: Buy/sell tokens through bonding curves
- Migration Support: Integration with Meteora for liquidity pool migration
- Whitelist System: Controlled token creation with admin-managed whitelist
- Fee Management: Configurable fee structure with platform revenue
βββ programs/pump-science/ # Main Solana program
β βββ src/
β β βββ instructions/ # Program instructions
β β β βββ admin/ # Admin functions (initialize, set_params, whitelist)
β β β βββ curve/ # Bonding curve operations (create, swap)
β β β βββ migration/ # Migration to Meteora pools
β β βββ state/ # Account structures
β β β βββ bonding_curve/ # Bonding curve state and logic
β β β βββ global.rs # Global program settings
β β β βββ whitelist.rs # Whitelist management
β β βββ constants.rs # Program constants
β β βββ errors.rs # Custom error definitions
β β βββ events.rs # Event definitions
βββ tests/ # Test files
βββ clients/ # Generated client libraries
βββ configs/ # Configuration files
- Rust (latest stable version)
- Solana CLI (v1.17+)
- Anchor Framework (v0.29.0)
- Node.js (v18+)
- pnpm (package manager)
-
Clone the repository
git clone <repository-url> cd Solana-pumpfun-smart-contract
-
Install dependencies
pnpm install
-
Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)" -
Install Anchor
npm install -g @coral-xyz/anchor-cli@0.29.0
Before deployment, you must update the following authentication-related configurations:
// In programs/pump-science/src/lib.rs
declare_id!("YOUR_PROGRAM_ID_HERE"); // Replace with your program ID// In programs/pump-science/src/state/global.rs
// Update these default values with your authority keys:
pub global_authority: Pubkey, // Your admin wallet
pub migration_authority: Pubkey, // Your migration authority wallet
pub fee_receiver: Pubkey, // Your fee collection wallet# In Anchor.toml
[provider]
wallet = "./your-wallet.json" # Replace with your wallet file path
[programs.devnet]
pump_science = "YOUR_PROGRAM_ID_HERE" # Replace with your program ID# Generate a new program keypair
solana-keygen new -o pump_fun.json
# Get the program ID
solana-keygen pubkey pump_fun.json# Build the program
anchor build
# Verify the build
anchor verify# Set Solana cluster to devnet
solana config set --url devnet
# Airdrop SOL for deployment
solana airdrop 2
# Deploy the program
anchor deploy# Set Solana cluster to mainnet
solana config set --url mainnet-beta
# Deploy with proper authority
anchor deploy --provider.cluster mainnet-betaThe program uses a multi-authority system:
- Global Authority: Can update program settings, manage whitelist
- Migration Authority: Can migrate completed bonding curves to Meteora
- Fee Receiver: Receives platform fees from trades
// Enable/disable whitelist in global settings
pub whitelist_enabled: bool,
// Add creators to whitelist (admin only)
pub fn add_wl(ctx: Context<AddWl>, new_creator: Pubkey)// Configurable fee parameters
pub migrate_fee_amount: u64, // Fee for migration (in lamports)
pub fee_receiver: Pubkey, // Fee collection address# Run all tests
pnpm test
# Run specific test suites
pnpm test:anchor
pnpm test:bankrun
# Run with validator
pnpm validator && pnpm test:onlyThe test suite covers:
- Bonding curve creation and trading
- Admin functions and authority management
- Migration to Meteora pools
- Whitelist management
- Error handling and edge cases
The bonding curve uses virtual reserves for price discovery:
// Initial virtual reserves (configurable)
initial_virtual_token_reserves: 1073000000000000, // ~1.073B tokens
initial_virtual_sol_reserves: 30000000000, // 30 SOL
initial_real_token_reserves: 793100000000000, // ~793M tokensToken price follows the constant product formula:
price = virtual_sol_reserves / virtual_token_reserves
Bonding curves complete when:
- Virtual SOL reserves reach 30 SOL
- Tokens migrate to Meteora liquidity pools
The program integrates with Meteora for liquidity pool migration:
// Meteora program constants
pub const METEORA_PROGRAM_KEY: &str = "Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB";
pub const METEORA_VAULT_PROGRAM_KEY: &str = "24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi";- Create Pool: Initialize Meteora pool with bonding curve tokens
- Lock Pool: Lock the pool for trading
- Transfer Liquidity: Move SOL and tokens to Meteora
# Generate IDL and client libraries
pnpm generate
# Generate IDL only
pnpm generate:idls
# Generate clients only
pnpm generate:clients# Check code formatting
pnpm lint
# Fix formatting issues
pnpm lint:fix# Build programs
pnpm programs:build
# Clean build artifacts
pnpm programs:cleanpub fn initialize(ctx: Context<Initialize>, params: GlobalSettingsInput)pub fn create_bonding_curve(ctx: Context<CreateBondingCurve>, params: CreateBondingCurveParams)pub fn swap(ctx: Context<Swap>, params: SwapParams)pub fn set_params(ctx: Context<SetParams>, params: GlobalSettingsInput)
pub fn add_wl(ctx: Context<AddWl>, new_creator: Pubkey)
pub fn remove_wl(ctx: Context<RemoveWl>)pub struct Global {
pub status: ProgramStatus,
pub global_authority: Pubkey,
pub migration_authority: Pubkey,
pub fee_receiver: Pubkey,
pub whitelist_enabled: bool,
// ... other fields
}pub struct BondingCurve {
pub mint: Pubkey,
pub creator: Pubkey,
pub virtual_sol_reserves: u64,
pub virtual_token_reserves: u64,
pub real_sol_reserves: u64,
pub real_token_reserves: u64,
pub complete: bool,
// ... other fields
}- Multi-signature: Use multi-sig wallets for authority accounts
- Timelock: Consider implementing timelock for critical parameter changes
- Audit: Conduct thorough security audits before mainnet deployment
- Fee Validation: All fee transfers are validated against global settings
- Slippage Protection: Built-in slippage protection for trades
- Authority Checks: Strict authority validation for admin functions
- Update program ID in
lib.rs - Configure authority wallets in global settings
- Set up fee receiver wallet
- Configure whitelist settings
- Update Meteora integration addresses
- Test thoroughly on devnet
- Conduct security audit
- Set up monitoring and alerting
- Monitoring: Implement comprehensive monitoring for all program interactions
- Backup: Maintain secure backups of authority keys
- Upgrades: Plan for program upgrades and migrations
- Compliance: Ensure compliance with local regulations
For questions and support:
- Create an issue in the repository
- Review the test files for usage examples
- Check the generated IDL for complete API reference
This project is licensed under the MIT License - see the LICENSE file for details.