PumpFun Mechanics — Bonding Curves, Graduation & Instruction Parsing
PumpFun 机制解析 — Bonding Curve、毕业与指令解析
PumpFun is the dominant Solana token launchpad. Understanding its bonding curve math, graduation process, and instruction formats is essential for analyzing new token launches, building trading strategies around graduation events, and parsing on-chain PumpFun activity.
PumpFun 是 Solana 上最主流的代币发行平台。理解其 Bonding Curve 数学原理、毕业流程以及指令格式,对于分析新代币发行、围绕毕业事件构建交易策略,以及解析链上 PumpFun 活动至关重要。
Bonding Curve Math
Bonding Curve 数学原理
PumpFun uses a virtual constant-product (CPMM) bonding curve:
k = virtualSolReserves × virtualTokenReserves
PumpFun 采用虚拟常数乘积(CPMM) Bonding Curve:
k = virtualSolReserves × virtualTokenReserves
| Parameter | Value |
|---|
| Initial Virtual SOL | 30 SOL (30,000,000,000 lamports) |
| Initial Virtual Tokens | ~1.073B tokens (1,073,000,000,000,000 raw, 6 decimals) |
| Token Total Supply | 1B tokens (1,000,000,000,000,000 raw) |
| Real Token Reserves | ~793M tokens (793,000,000,000,000 raw) |
| Real SOL Reserves | 0 (no real SOL at launch) |
| Fee | 1% (applied externally by the program) |
Virtual vs Real: Virtual reserves define the curve shape. Real reserves track actual withdrawable funds. The difference (1.073B - 793M = 280M virtual tokens) shapes the initial price but can never be withdrawn.
| 参数 | 值 |
|---|
| 初始虚拟 SOL | 30 SOL(30,000,000,000 lamports) |
| 初始虚拟代币 | 约10.73亿枚(1,073,000,000,000,000 原始单位,6位小数) |
| 代币总供应量 | 10亿枚(1,000,000,000,000,000 原始单位) |
| 实际代币储备 | 约7.93亿枚(793,000,000,000,000 原始单位) |
| 实际 SOL 储备 | 0(发行时无实际 SOL) |
| 手续费 | 1%(由程序在外部收取) |
虚拟储备 vs 实际储备:虚拟储备决定曲线形状,实际储备追踪可提取的实际资金。两者的差值(10.73亿 - 7.93亿 = 2.8亿虚拟代币)决定了初始价格,但永远无法被提取。
python
price_sol_per_token = virtual_sol_reserves / virtual_token_reserves
python
price_sol_per_token = virtual_sol_reserves / virtual_token_reserves
In human-readable units:
In human-readable units:
price = (virtual_sol / 1e9) / (virtual_token / 1e6)
price = (virtual_sol / 1e9) / (virtual_token / 1e6)
At genesis: 30 / 1,073,000,000 ≈ 2.796e-8 SOL/token
At genesis: 30 / 1,073,000,000 ≈ 2.796e-8 SOL/token
At graduation: ~4.1e-7 SOL/token (~14.7x from launch)
At graduation: ~4.1e-7 SOL/token (~14.7x from launch)
Buy Tokens (SOL → Tokens)
买入代币(SOL → 代币)
python
def buy_tokens(v_sol: int, v_tok: int, real_tok: int, sol_in: int) -> int:
"""Calculate tokens received for a given SOL input.
Args:
v_sol: Virtual SOL reserves (lamports).
v_tok: Virtual token reserves (raw).
real_tok: Real token reserves (raw).
sol_in: SOL to spend (lamports, BEFORE 1% fee).
Returns:
Tokens received (raw units).
"""
k = v_sol * v_tok
new_v_sol = v_sol + sol_in
new_v_tok = k // new_v_sol + 1 # +1 matches on-chain rounding
tokens_out = v_tok - new_v_tok
return min(tokens_out, real_tok)
python
def buy_tokens(v_sol: int, v_tok: int, real_tok: int, sol_in: int) -> int:
"""Calculate tokens received for a given SOL input.
Args:
v_sol: Virtual SOL reserves (lamports).
v_tok: Virtual token reserves (raw).
real_tok: Real token reserves (raw).
sol_in: SOL to spend (lamports, BEFORE 1% fee).
Returns:
Tokens received (raw units).
"""
k = v_sol * v_tok
new_v_sol = v_sol + sol_in
new_v_tok = k // new_v_sol + 1 # +1 matches on-chain rounding
tokens_out = v_tok - new_v_tok
return min(tokens_out, real_tok)
Sell Tokens (Tokens → SOL)
卖出代币(代币 → SOL)
python
def sell_tokens(v_sol: int, v_tok: int, real_sol: int, tokens_in: int) -> int:
"""Calculate SOL received for selling tokens.
Args:
v_sol: Virtual SOL reserves (lamports).
v_tok: Virtual token reserves (raw).
real_sol: Real SOL reserves (lamports).
tokens_in: Tokens to sell (raw units).
Returns:
SOL received (lamports, BEFORE 1% fee).
"""
k = v_sol * v_tok
new_v_tok = v_tok + tokens_in
new_v_sol = k // new_v_tok
sol_out = v_sol - new_v_sol - 1 # -1 matches on-chain floor rounding
return min(sol_out, real_sol)
python
def sell_tokens(v_sol: int, v_tok: int, real_sol: int, tokens_in: int) -> int:
"""Calculate SOL received for selling tokens.
Args:
v_sol: Virtual SOL reserves (lamports).
v_tok: Virtual token reserves (raw).
real_sol: Real SOL reserves (lamports).
tokens_in: Tokens to sell (raw units).
Returns:
SOL received (lamports, BEFORE 1% fee).
"""
k = v_sol * v_tok
new_v_tok = v_tok + tokens_in
new_v_sol = k // new_v_tok
sol_out = v_sol - new_v_sol - 1 # -1 matches on-chain floor rounding
return min(sol_out, real_sol)
Buy Cost (Exact token amount → SOL needed)
买入成本(精确代币数量 → 所需 SOL)
python
def buy_cost(v_sol: int, v_tok: int, tokens_wanted: int) -> int:
"""Calculate SOL needed to buy exact token amount.
Returns:
SOL cost in lamports (before fee). Returns max int if impossible.
"""
if tokens_wanted >= v_tok:
return 2**64 - 1 # impossible
k = v_sol * v_tok
new_v_tok = v_tok - tokens_wanted
new_v_sol = k // new_v_tok + 1
return new_v_sol - v_sol
python
def buy_cost(v_sol: int, v_tok: int, tokens_wanted: int) -> int:
"""Calculate SOL needed to buy exact token amount.
Returns:
SOL cost in lamports (before fee). Returns max int if impossible.
"""
if tokens_wanted >= v_tok:
return 2**64 - 1 # impossible
k = v_sol * v_tok
new_v_tok = v_tok - tokens_wanted
new_v_sol = k // new_v_tok + 1
return new_v_sol - v_sol
The 1% fee is not part of the curve math. It's applied externally:
1% 的手续费不属于曲线数学的一部分,而是在外部收取:
Buying: fee deducted from SOL input before curve
Buying: fee deducted from SOL input before curve
actual_sol_to_curve = sol_input * 0.99
actual_sol_to_curve = sol_input * 0.99
Selling: fee deducted from SOL output after curve
Selling: fee deducted from SOL output after curve
actual_sol_received = sol_from_curve * 0.99
actual_sol_received = sol_from_curve * 0.99
Roundtrip minimum cost: ~2% from fees alone, plus price impact
Roundtrip minimum cost: ~2% from fees alone, plus price impact
python
market_cap_sol = (token_total_supply * virtual_sol_reserves) / virtual_token_reserves
python
market_cap_sol = (token_total_supply * virtual_sol_reserves) / virtual_token_reserves
Graduation occurs when
reaches
~85 SOL (~$12K-14K depending on SOL price). Only ~1.4% of PumpFun tokens ever graduate.
当
达到
约85 SOL(约12000-14000美元,取决于 SOL 价格)时,就会触发毕业。仅有约1.4% 的 PumpFun 代币能够成功毕业。
- flag set to on bonding curve account
- emitted (discriminator )
- Bonding curve stops accepting trades
- ~$12K liquidity deposited to the destination DEX
- Token becomes tradeable on PumpSwap (or Raydium for older tokens)
- Bonding Curve 账户的 标志被设置为
- 触发 事件(鉴别器为 )
- Bonding Curve 停止接受交易
- 约12000美元的流动性被存入目标 DEX
- 代币可在 PumpSwap 上交易(旧代币则迁移至 Raydium)
python
GRADUATION_THRESHOLD = 85_000_000_000 # 85 SOL in lamports
fill_pct = (real_sol_reserves / GRADUATION_THRESHOLD) * 100.0
python
GRADUATION_THRESHOLD = 85_000_000_000 # 85 SOL in lamports
fill_pct = (real_sol_reserves / GRADUATION_THRESHOLD) * 100.0
- March 2025+: PumpSwap (
pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
) — native AMM, no migration fee
- Before March 2025: Raydium V4 (
675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8
) — 6 SOL fee
- 2025年3月及以后:PumpSwap(地址
pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
)— 原生 AMM,无迁移手续费
- 2025年3月之前:Raydium V4(地址
675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8
)— 收取6 SOL 手续费
PumpSwap Post-Graduation
毕业后的 PumpSwap
PumpSwap is a constant-product AMM with 1% fee (same as bonding curve). Key differences:
- Base asset is always WSOL, quote is token
- Instruction semantics are inverted: "buy" instruction sells tokens, "sell" instruction buys tokens
- Supports creator revenue sharing (0.05% of volume to original creator)
PumpSwap 是一个常数乘积 AMM,手续费为1%(与 Bonding Curve 相同)。核心区别如下:
- 基础资产始终为 WSOL,报价资产为代币
- 指令语义相反:“buy” 指令用于卖出代币,“sell” 指令用于买入代币
- 支持创作者收益分成(交易量的0.05% 归原始创作者所有)
Program IDs & Addresses
程序 ID 与地址
| Program/Account | Address |
|---|
| PumpFun Program | 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
|
| PumpSwap Program | pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
|
| Fee Program | pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ
|
| Global Account | 4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf
|
| Fee Recipient | 62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV
|
| Event Authority | Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1
|
| 程序/账户 | 地址 |
|---|
| PumpFun 程序 | 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
|
| PumpSwap 程序 | pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
|
| 手续费程序 | pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ
|
| 全局账户 | 4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf
|
| 手续费接收方 | 62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV
|
| 事件权限账户 | Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1
|
Events are Anchor-style:
sha256("event:<EventName>")[0..8]
| Event | Discriminator (hex) |
|---|
| CreateEvent | |
| TradeEvent | |
| CompleteEvent | |
事件采用 Anchor 风格:
sha256("event:<EventName>")[0..8]
| 事件 | 鉴别器(十六进制) |
|---|
| CreateEvent | |
| TradeEvent | |
| CompleteEvent | |
TradeEvent Layout (after 8-byte discriminator)
TradeEvent 结构(8字节鉴别器之后)
mint: pubkey 32 bytes
solAmount: u64 8 bytes
tokenAmount: u64 8 bytes
isBuy: bool 1 byte
user: pubkey 32 bytes
timestamp: i64 8 bytes
virtualSolReserves: u64 8 bytes
virtualTokenReserves: u64 8 bytes
realSolReserves: u64 8 bytes
realTokenReserves: u64 8 bytes
Critical: Events are in CPI inner instructions. Search for discriminators anywhere in instruction data, not just at offset 0.
mint: pubkey 32 bytes
solAmount: u64 8 bytes
tokenAmount: u64 8 bytes
isBuy: bool 1 byte
user: pubkey 32 bytes
timestamp: i64 8 bytes
virtualSolReserves: u64 8 bytes
virtualTokenReserves: u64 8 bytes
realSolReserves: u64 8 bytes
realTokenReserves: u64 8 bytes
重要提示:事件位于 CPI 内部指令中。请在指令数据的任意位置搜索鉴别器,而非仅在偏移量0处。
Bonding Curve Account Layout
Bonding Curve 账户结构
Offset 0: discriminator 8 bytes
Offset 8: virtualTokenReserves u64
Offset 16: virtualSolReserves u64
Offset 24: realTokenReserves u64
Offset 32: realSolReserves u64
Offset 40: tokenTotalSupply u64
Offset 48: complete bool (1 byte)
Offset 49: creator pubkey (32 bytes)
Offset 0: discriminator 8 bytes
Offset 8: virtualTokenReserves u64
Offset 16: virtualSolReserves u64
Offset 24: realTokenReserves u64
Offset 32: realSolReserves u64
Offset 40: tokenTotalSupply u64
Offset 48: complete bool (1 byte)
Offset 49: creator pubkey (32 bytes)
| PDA | Seeds |
|---|
| Bonding Curve | |
| Bonding Curve V2 | ["bonding-curve-v2", mint]
|
| Creator Vault | ["creator-vault", creator]
|
| PDA | 种子 |
|---|
| Bonding Curve | |
| Bonding Curve V2 | ["bonding-curve-v2", mint]
|
| 创作者金库 | ["creator-vault", creator]
|
Instruction Discriminators
指令鉴别器
| Instruction | Hex | Notes |
|---|
| buy_exact_sol_in (V2) | | Current production buy |
| sell (V2) | | Current production sell |
| buy (V1/legacy) | | Legacy, still seen occasionally |
| create | | Token creation |
| 指令 | 十六进制值 | 说明 |
|---|
| buy_exact_sol_in (V2) | | 当前生产环境使用的买入指令 |
| sell (V2) | | 当前生产环境使用的卖出指令 |
| buy (V1/legacy) | | 遗留版本,偶尔仍会出现 |
| create | | 代币创建 |
Buy Instruction Data (24 bytes)
买入指令数据(24字节)
[0..8]: discriminator
[8..16]: spendable_sol_in u64 LE (total SOL budget, fees deducted internally)
[16..24]: min_tokens_out u64 LE (slippage floor)
[0..8]: discriminator
[8..16]: spendable_sol_in u64 LE (total SOL budget, fees deducted internally)
[16..24]: min_tokens_out u64 LE (slippage floor)
Sell Instruction Data (24 bytes)
卖出指令数据(24字节)
[0..8]: discriminator
[8..16]: amount_tokens u64 LE (tokens to sell, raw)
[16..24]: min_sol_output u64 LE (minimum SOL out, lamports)
[0..8]: discriminator
[8..16]: amount_tokens u64 LE (tokens to sell, raw)
[16..24]: min_sol_output u64 LE (minimum SOL out, lamports)
Price Impact & Sizing
价格影响与仓位计算
python
def price_impact(v_sol: int, v_tok: int, sol_in: int) -> float:
"""Calculate price impact for a buy as a percentage."""
spot = v_sol / v_tok
tokens = buy_tokens(v_sol, v_tok, v_tok, sol_in)
if tokens == 0:
return float('inf')
exec_price = sol_in / tokens
return (exec_price / spot - 1) * 100
python
def price_impact(v_sol: int, v_tok: int, sol_in: int) -> float:
"""Calculate price impact for a buy as a percentage."""
spot = v_sol / v_tok
tokens = buy_tokens(v_sol, v_tok, v_tok, sol_in)
if tokens == 0:
return float('inf')
exec_price = sol_in / tokens
return (exec_price / spot - 1) * 100
Example: 1 SOL buy at genesis
Example: 1 SOL buy at genesis
impact = price_impact(30_000_000_000, 1_073_000_000_000_000, 1_000_000_000)
impact = price_impact(30_000_000_000, 1_073_000_000_000_000, 1_000_000_000)
≈ 3.3% price impact
≈ 3.3% price impact
references/bonding_curve_math.md
— Complete mathematical derivations with worked examples
references/graduation_process.md
— Graduation threshold, migration, PumpSwap mechanics
references/instruction_reference.md
— Full instruction and event layouts for parsing
references/bonding_curve_math.md
— 包含完整数学推导与计算示例
references/graduation_process.md
— 毕业阈值、迁移与 PumpSwap 机制
references/instruction_reference.md
— 用于解析的完整指令与事件结构
scripts/curve_calculator.py
— Interactive bonding curve calculator: price, impact, fill %
- — Parse PumpFun events from transaction data
scripts/curve_calculator.py
— 交互式 Bonding Curve 计算器:可计算价格、价格影响、填充百分比
- — 从交易数据中解析 PumpFun 事件