pumpfun

安装量: 76
排名: #10205

安装

npx skills add https://github.com/sendaifun/skills --skill pumpfun

A comprehensive guide for building applications with PumpFun - Solana's leading token launch and AMM protocol enabling instant trading without initial liquidity.

Overview

PumpFun is a token launch and trading protocol on Solana offering:

  • Pump Program - Create SPL tokens with instant trading on bonding curves

  • PumpSwap (AMM) - Constant-product automated market maker for graduated tokens

  • Creator Fees - Automatic fee distribution to token creators

  • Token2022 Support - Modern token standard via create_v2 instruction

  • Mayhem Mode - Special mode for enhanced token launches

Program IDs

| Pump Program | 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P

| PumpSwap AMM | pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA

| Pump Fees | pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ

| Mayhem Program | MAyhSmzXzV1pTf7LsNkrNwkWKTo4ougAJ1PPg47MD4e

Quick Start

Installation

# Install PumpFun SDKs
npm install @pump-fun/pump-sdk @pump-fun/pump-swap-sdk

# Or with pnpm
pnpm add @pump-fun/pump-sdk @pump-fun/pump-swap-sdk

Basic Setup

import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import bs58 from 'bs58';

// Setup connection
const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.fromSecretKey(bs58.decode('YOUR_SECRET_KEY'));

// Program addresses
const PUMP_PROGRAM_ID = new PublicKey('6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P');
const PUMP_AMM_PROGRAM_ID = new PublicKey('pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA');
const PUMP_FEES_PROGRAM_ID = new PublicKey('pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ');

Pump Program (Bonding Curves)

The Pump program enables creation of SPL tokens with instant trading on a bonding curve without requiring initial liquidity.

How Bonding Curves Work

  • Token Creation - Create a token with initial virtual reserves

  • Trading - Users buy/sell on the bonding curve using Uniswap V2 formula

  • Graduation - When market cap threshold is reached, liquidity migrates to PumpSwap

  • LP Burn - LP tokens are burned, making liquidity permanent

Global Configuration

interface Global {
  initialized: boolean;
  authority: PublicKey;
  feeRecipient: PublicKey;
  initialVirtualTokenReserves: bigint;  // Default: 1,073,000,000,000,000
  initialVirtualSolReserves: bigint;    // Default: 30,000,000,000 (30 SOL)
  initialRealTokenReserves: bigint;     // Default: 793,100,000,000,000
  tokenTotalSupply: bigint;             // Default: 1,000,000,000,000,000
  feeBasisPoints: bigint;               // Default: 100 (1%)
  creatorFeeBasisPoints: bigint;        // Creator fee percentage
}

Bonding Curve Account

interface BondingCurve {
  virtualTokenReserves: bigint;
  virtualSolReserves: bigint;
  realTokenReserves: bigint;
  realSolReserves: bigint;
  tokenTotalSupply: bigint;
  complete: boolean;
  creator: PublicKey;        // Token creator address
  isMayhemMode: boolean;     // Mayhem mode flag
}

Deriving PDAs

import { PublicKey } from '@solana/web3.js';

const PUMP_PROGRAM_ID = new PublicKey('6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P');

// Derive bonding curve PDA
function getBondingCurvePDA(mint: PublicKey): [PublicKey, number] {
  return PublicKey.findProgramAddressSync(
    [Buffer.from('bonding-curve'), mint.toBuffer()],
    PUMP_PROGRAM_ID
  );
}

// Derive associated bonding curve (token account)
function getAssociatedBondingCurve(mint: PublicKey): [PublicKey, number] {
  return PublicKey.findProgramAddressSync(
    [
      Buffer.from('associated-bonding-curve'),
      mint.toBuffer()
    ],
    PUMP_PROGRAM_ID
  );
}

// Derive creator vault PDA
function getCreatorVaultPDA(creator: PublicKey): [PublicKey, number] {
  return PublicKey.findProgramAddressSync(
    [Buffer.from('creator-vault'), creator.toBuffer()],
    PUMP_PROGRAM_ID
  );
}

// Derive global account PDA
function getGlobalPDA(): [PublicKey, number] {
  return PublicKey.findProgramAddressSync(
    [Buffer.from('global')],
    PUMP_PROGRAM_ID
  );
}

Create Token (Legacy SPL)

import {
  Connection,
  Keypair,
  PublicKey,
  Transaction,
  TransactionInstruction,
  SystemProgram,
  SYSVAR_RENT_PUBKEY,
} from '@solana/web3.js';
import {
  TOKEN_PROGRAM_ID,
  ASSOCIATED_TOKEN_PROGRAM_ID,
  getAssociatedTokenAddressSync,
} from '@solana/spl-token';

async function createToken(
  connection: Connection,
  payer: Keypair,
  name: string,
  symbol: string,
  uri: string
): Promise<string> {
  const mint = Keypair.generate();

  const [bondingCurve] = getBondingCurvePDA(mint.publicKey);
  const [associatedBondingCurve] = getAssociatedBondingCurve(mint.publicKey);
  const [global] = getGlobalPDA();

  // Metaplex metadata PDA
  const METADATA_PROGRAM_ID = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
  const [metadata] = PublicKey.findProgramAddressSync(
    [
      Buffer.from('metadata'),
      METADATA_PROGRAM_ID.toBuffer(),
      mint.publicKey.toBuffer(),
    ],
    METADATA_PROGRAM_ID
  );

  // Build create instruction data
  const nameBuffer = Buffer.from(name);
  const symbolBuffer = Buffer.from(symbol);
  const uriBuffer = Buffer.from(uri);

  const data = Buffer.alloc(
    8 + 4 + nameBuffer.length + 4 + symbolBuffer.length + 4 + uriBuffer.length
  );

  // Write discriminator for 'create' instruction
  const discriminator = Buffer.from([0x18, 0x1e, 0xc8, 0x28, 0x05, 0x1c, 0x07, 0x77]);
  discriminator.copy(data, 0);

  let offset = 8;
  data.writeUInt32LE(nameBuffer.length, offset);
  offset += 4;
  nameBuffer.copy(data, offset);
  offset += nameBuffer.length;

  data.writeUInt32LE(symbolBuffer.length, offset);
  offset += 4;
  symbolBuffer.copy(data, offset);
  offset += symbolBuffer.length;

  data.writeUInt32LE(uriBuffer.length, offset);
  offset += 4;
  uriBuffer.copy(data, offset);

  const instruction = new TransactionInstruction({
    programId: PUMP_PROGRAM_ID,
    keys: [
      { pubkey: mint.publicKey, isSigner: true, isWritable: true },
      { pubkey: payer.publicKey, isSigner: false, isWritable: true },
      { pubkey: bondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedBondingCurve, isSigner: false, isWritable: true },
      { pubkey: global, isSigner: false, isWritable: false },
      { pubkey: METADATA_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: metadata, isSigner: false, isWritable: true },
      { pubkey: payer.publicKey, isSigner: true, isWritable: true },
      { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
    ],
    data,
  });

  const tx = new Transaction().add(instruction);
  tx.feePayer = payer.publicKey;
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
  tx.sign(payer, mint);

  const signature = await connection.sendRawTransaction(tx.serialize());
  await connection.confirmTransaction(signature);

  return mint.publicKey.toBase58();
}

Create Token V2 (Token2022)

// create_v2 uses Token2022 program instead of legacy Metaplex
// Account structure (14 accounts):
const createV2Accounts = [
  'mint',                    // 0: New token mint (signer, writable)
  'mintAuthority',           // 1: Mint authority PDA
  'bondingCurve',            // 2: Bonding curve PDA (writable)
  'associatedBondingCurve',  // 3: Token account for bonding curve (writable)
  'global',                  // 4: Global config
  'user',                    // 5: Creator/payer (signer, writable)
  'systemProgram',           // 6: System program
  'token2022Program',        // 7: Token2022 program
  'associatedTokenProgram',  // 8: Associated token program
  'rent',                    // 9: Rent sysvar
  'mayhemProgram',           // 10: Mayhem program ID (for mayhem mode)
  'mayhemFeeRecipient',      // 11: Mayhem fee recipient
  'eventAuthority',          // 12: Event authority
  'program',                 // 13: Pump program
];

Buy Tokens on Bonding Curve

interface BuyArgs {
  amount: bigint;        // Token amount to buy
  maxSolCost: bigint;    // Maximum SOL to spend (slippage protection)
}

async function buyTokens(
  connection: Connection,
  payer: Keypair,
  mint: PublicKey,
  amount: bigint,
  maxSolCost: bigint
): Promise<string> {
  const [bondingCurve] = getBondingCurvePDA(mint);
  const [associatedBondingCurve] = getAssociatedBondingCurve(mint);
  const [global] = getGlobalPDA();

  // Get bonding curve data to find creator
  const bondingCurveData = await connection.getAccountInfo(bondingCurve);
  // Parse to get creator address...
  const creator = parseCreatorFromBondingCurve(bondingCurveData);
  const [creatorVault] = getCreatorVaultPDA(creator);

  // User's associated token account
  const userAta = getAssociatedTokenAddressSync(mint, payer.publicKey);

  // Fee recipient (from global config)
  const feeRecipient = new PublicKey('FEE_RECIPIENT_ADDRESS');

  // Build buy instruction
  const data = Buffer.alloc(8 + 8 + 8);
  const discriminator = Buffer.from([0x66, 0x06, 0x3d, 0x12, 0x01, 0xda, 0xeb, 0xea]);
  discriminator.copy(data, 0);
  data.writeBigUInt64LE(amount, 8);
  data.writeBigUInt64LE(maxSolCost, 16);

  const instruction = new TransactionInstruction({
    programId: PUMP_PROGRAM_ID,
    keys: [
      { pubkey: global, isSigner: false, isWritable: false },
      { pubkey: feeRecipient, isSigner: false, isWritable: true },
      { pubkey: mint, isSigner: false, isWritable: false },
      { pubkey: bondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedBondingCurve, isSigner: false, isWritable: true },
      { pubkey: userAta, isSigner: false, isWritable: true },
      { pubkey: payer.publicKey, isSigner: true, isWritable: true },
      { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
      { pubkey: creatorVault, isSigner: false, isWritable: true },
      // Fee config accounts (required since September 2025)
      { pubkey: PUMP_FEES_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: feeConfigPDA, isSigner: false, isWritable: false },
    ],
    data,
  });

  // Check if account extension needed (account size < 150 bytes)
  const accountInfo = await connection.getAccountInfo(bondingCurve);
  if (accountInfo && accountInfo.data.length < 150) {
    // Prepend extendAccount instruction
    const extendIx = createExtendAccountInstruction(bondingCurve);
    const tx = new Transaction().add(extendIx, instruction);
  } else {
    const tx = new Transaction().add(instruction);
  }

  tx.feePayer = payer.publicKey;
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
  tx.sign(payer);

  const signature = await connection.sendRawTransaction(tx.serialize());
  await connection.confirmTransaction(signature);

  return signature;
}

Sell Tokens on Bonding Curve

interface SellArgs {
  amount: bigint;        // Token amount to sell
  minSolOutput: bigint;  // Minimum SOL to receive (slippage protection)
}

async function sellTokens(
  connection: Connection,
  payer: Keypair,
  mint: PublicKey,
  amount: bigint,
  minSolOutput: bigint
): Promise<string> {
  const [bondingCurve] = getBondingCurvePDA(mint);
  const [associatedBondingCurve] = getAssociatedBondingCurve(mint);
  const [global] = getGlobalPDA();

  const bondingCurveData = await connection.getAccountInfo(bondingCurve);
  const creator = parseCreatorFromBondingCurve(bondingCurveData);
  const [creatorVault] = getCreatorVaultPDA(creator);

  const userAta = getAssociatedTokenAddressSync(mint, payer.publicKey);
  const feeRecipient = new PublicKey('FEE_RECIPIENT_ADDRESS');

  const data = Buffer.alloc(8 + 8 + 8);
  const discriminator = Buffer.from([0x33, 0xe6, 0x85, 0xa4, 0x01, 0x7f, 0x83, 0xad]);
  discriminator.copy(data, 0);
  data.writeBigUInt64LE(amount, 8);
  data.writeBigUInt64LE(minSolOutput, 16);

  const instruction = new TransactionInstruction({
    programId: PUMP_PROGRAM_ID,
    keys: [
      { pubkey: global, isSigner: false, isWritable: false },
      { pubkey: feeRecipient, isSigner: false, isWritable: true },
      { pubkey: mint, isSigner: false, isWritable: false },
      { pubkey: bondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedBondingCurve, isSigner: false, isWritable: true },
      { pubkey: userAta, isSigner: false, isWritable: true },
      { pubkey: payer.publicKey, isSigner: true, isWritable: true },
      { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
      { pubkey: creatorVault, isSigner: false, isWritable: true },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
      // Fee config accounts
      { pubkey: PUMP_FEES_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: feeConfigPDA, isSigner: false, isWritable: false },
    ],
    data,
  });

  const tx = new Transaction().add(instruction);
  tx.feePayer = payer.publicKey;
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
  tx.sign(payer);

  const signature = await connection.sendRawTransaction(tx.serialize());
  return signature;
}

Calculate Price (Bonding Curve Math)

// Uniswap V2 constant product formula: x * y = k
// Quote: SOL -> Tokens

interface BondingCurveState {
  virtualTokenReserves: bigint;
  virtualSolReserves: bigint;
  realTokenReserves: bigint;
  realSolReserves: bigint;
}

function calculateBuyQuote(
  state: BondingCurveState,
  solAmountIn: bigint,
  feeBasisPoints: bigint = 100n
): bigint {
  // Calculate net SOL after fees
  const netSol = (solAmountIn * 10000n) / (10000n + feeBasisPoints);

  // Calculate tokens out using constant product formula
  // tokensOut = (netSol * virtualTokenReserves) / (virtualSolReserves + netSol)
  const tokensOut = (netSol * state.virtualTokenReserves) /
                   (state.virtualSolReserves + netSol);

  // Cap at real token reserves
  return tokensOut > state.realTokenReserves ? state.realTokenReserves : tokensOut;
}

function calculateSellQuote(
  state: BondingCurveState,
  tokenAmountIn: bigint,
  feeBasisPoints: bigint = 100n
): bigint {
  // Calculate SOL out using constant product formula
  // solOut = (tokenAmountIn * virtualSolReserves) / (virtualTokenReserves + tokenAmountIn)
  const grossSol = (tokenAmountIn * state.virtualSolReserves) /
                  (state.virtualTokenReserves + tokenAmountIn);

  // Deduct fees
  const netSol = (grossSol * (10000n - feeBasisPoints)) / 10000n;

  // Cap at real SOL reserves
  return netSol > state.realSolReserves ? state.realSolReserves : netSol;
}

function calculateMarketCap(state: BondingCurveState, tokenSupply: bigint): bigint {
  // marketCap = virtualSolReserves * mintSupply / virtualTokenReserves
  return (state.virtualSolReserves * tokenSupply) / state.virtualTokenReserves;
}

Migration to PumpSwap

When a bonding curve completes (real tokens exhausted), liquidity can be migrated to PumpSwap:

async function migrateToAMM(
  connection: Connection,
  payer: Keypair,
  mint: PublicKey
): Promise<string> {
  const [bondingCurve] = getBondingCurvePDA(mint);

  // Migrate instruction is permissionless - anyone can call it
  // after bonding curve is complete
  const discriminator = Buffer.from([0x9d, 0xaf, 0x1e, 0x65, 0xe8, 0x69, 0x9b, 0x26]);

  const instruction = new TransactionInstruction({
    programId: PUMP_PROGRAM_ID,
    keys: [
      // ... migration accounts including PumpSwap pool creation
    ],
    data: discriminator,
  });

  const tx = new Transaction().add(instruction);
  tx.feePayer = payer.publicKey;
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
  tx.sign(payer);

  return await connection.sendRawTransaction(tx.serialize());
}

PumpSwap (AMM)

PumpSwap is a constant-product AMM for tokens that have graduated from the bonding curve.

Global Config

// GlobalConfig address
const GLOBAL_CONFIG = new PublicKey('ADyA8hdefvWN2dbGGWFotbzWxrAvLW83WG6QCVXvJKqw');

interface GlobalConfig {
  admin: PublicKey;
  lpFeeBasisPoints: number;          // 20 bps (0.2%)
  protocolFeeBasisPoints: number;    // 5 bps (0.05%)
  coinCreatorFeeBasisPoints: number; // Creator fee
  disableFlags: number;              // Operation disable flags
  protocolFeeRecipients: PublicKey[]; // 8 fee recipients for load balancing
  tokenIncentivesEnabled: boolean;
}

Pool Account

interface Pool {
  bump: number;
  poolCreator: PublicKey;
  baseMint: PublicKey;          // Token mint
  quoteMint: PublicKey;         // Usually WSOL
  lpMint: PublicKey;            // LP token mint
  poolBaseTokenAccount: PublicKey;
  poolQuoteTokenAccount: PublicKey;
  lpSupply: bigint;             // Tracks original LP supply (independent of burns)
  coinCreator: PublicKey;       // Creator for fee distribution
  isMayhemMode: boolean;        // Mayhem mode flag
}

Deriving Pool PDAs

返回排行榜