Skip to content

A comprehensive Solana smart contract implementation inspired by pump.fun, featuring bonding curve mechanics, token creation, and automated market making functionality.

Notifications You must be signed in to change notification settings

Vector-6/Solana_Pumpfun_SmartContract

Repository files navigation

Solana Pump.fun Smart Contract

A comprehensive Solana smart contract implementation inspired by pump.fun, featuring bonding curve mechanics, token creation, and automated market making functionality.

πŸš€ Overview

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

πŸ“ Project Structure

β”œβ”€β”€ 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

πŸ”§ Prerequisites

  • Rust (latest stable version)
  • Solana CLI (v1.17+)
  • Anchor Framework (v0.29.0)
  • Node.js (v18+)
  • pnpm (package manager)

βš™οΈ Installation

  1. Clone the repository

    git clone <repository-url>
    cd Solana-pumpfun-smart-contract
  2. Install dependencies

    pnpm install
  3. Install Solana CLI

    sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)"
  4. Install Anchor

    npm install -g @coral-xyz/anchor-cli@0.29.0

πŸš€ Deployment Instructions

1. Environment Setup

⚠️ IMPORTANT: Authentication Configuration Required

Before deployment, you must update the following authentication-related configurations:

Update Program ID

// In programs/pump-science/src/lib.rs
declare_id!("YOUR_PROGRAM_ID_HERE"); // Replace with your program ID

Update Authority Keys

// 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

Update Wallet Configuration

# 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

2. Generate New Program ID

# Generate a new program keypair
solana-keygen new -o pump_fun.json

# Get the program ID
solana-keygen pubkey pump_fun.json

3. Build the Program

# Build the program
anchor build

# Verify the build
anchor verify

4. Deploy to Devnet

# Set Solana cluster to devnet
solana config set --url devnet

# Airdrop SOL for deployment
solana airdrop 2

# Deploy the program
anchor deploy

5. Deploy to Mainnet (Production)

# Set Solana cluster to mainnet
solana config set --url mainnet-beta

# Deploy with proper authority
anchor deploy --provider.cluster mainnet-beta

πŸ” Key Configuration Points

Authority Management

The program uses a multi-authority system:

  1. Global Authority: Can update program settings, manage whitelist
  2. Migration Authority: Can migrate completed bonding curves to Meteora
  3. Fee Receiver: Receives platform fees from trades

Whitelist Configuration

// 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)

Fee Structure

// Configurable fee parameters
pub migrate_fee_amount: u64,  // Fee for migration (in lamports)
pub fee_receiver: Pubkey,     // Fee collection address

πŸ§ͺ Testing

Run Tests

# Run all tests
pnpm test

# Run specific test suites
pnpm test:anchor
pnpm test:bankrun

# Run with validator
pnpm validator && pnpm test:only

Test Coverage

The test suite covers:

  • Bonding curve creation and trading
  • Admin functions and authority management
  • Migration to Meteora pools
  • Whitelist management
  • Error handling and edge cases

πŸ“Š Bonding Curve Mechanics

Virtual Reserves Model

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 tokens

Price Calculation

Token price follows the constant product formula:

price = virtual_sol_reserves / virtual_token_reserves

Completion Threshold

Bonding curves complete when:

  • Virtual SOL reserves reach 30 SOL
  • Tokens migrate to Meteora liquidity pools

πŸ”„ Migration Process

Meteora Integration

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";

Migration Steps

  1. Create Pool: Initialize Meteora pool with bonding curve tokens
  2. Lock Pool: Lock the pool for trading
  3. Transfer Liquidity: Move SOL and tokens to Meteora

πŸ› οΈ Development

Code Generation

# Generate IDL and client libraries
pnpm generate

# Generate IDL only
pnpm generate:idls

# Generate clients only
pnpm generate:clients

Linting

# Check code formatting
pnpm lint

# Fix formatting issues
pnpm lint:fix

Building

# Build programs
pnpm programs:build

# Clean build artifacts
pnpm programs:clean

πŸ“ API Reference

Core Instructions

Initialize Program

pub fn initialize(ctx: Context<Initialize>, params: GlobalSettingsInput)

Create Bonding Curve

pub fn create_bonding_curve(ctx: Context<CreateBondingCurve>, params: CreateBondingCurveParams)

Swap Tokens

pub fn swap(ctx: Context<Swap>, params: SwapParams)

Admin Functions

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>)

Account Structures

Global Account

pub struct Global {
    pub status: ProgramStatus,
    pub global_authority: Pubkey,
    pub migration_authority: Pubkey,
    pub fee_receiver: Pubkey,
    pub whitelist_enabled: bool,
    // ... other fields
}

Bonding Curve Account

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
}

πŸ”’ Security Considerations

Access Control

  • 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 Management

  • 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

🚨 Important Notes

Pre-Deployment Checklist

  • 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

Production Considerations

  • 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

πŸ“ž Support

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

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


⚠️ Disclaimer: This is a reference implementation. Always conduct thorough testing and security audits before deploying to mainnet. The authors are not responsible for any financial losses.

About

A comprehensive Solana smart contract implementation inspired by pump.fun, featuring bonding curve mechanics, token creation, and automated market making functionality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published