Pump SDK Core — Instruction Building & On-Chain Interaction
Build, extend, and maintain the core Pump SDK — an offline-first TypeScript SDK that constructs Solana TransactionInstructions for token creation, buying, selling, migration, and creator fee collection across three on-chain programs (Pump, PumpAMM, PumpFees) plus the Mayhem program.
Context
The SDK is published as @pump-fun/pump-sdk (npm) and powers the Pump protocol — a Solana-based token launchpad with bonding curve pricing, automatic AMM migration after graduation, tiered fees, and creator fee sharing. The codebase uses Anchor for IDL-based instruction building and supports both Token (SPL) and Token-2022 token programs.
Key Files
- -
src/sdk.ts — PumpSdk class with all instruction builders and account decoders - INLINECODE4 —
OnlinePumpSdk class extending offline SDK with live RPC fetches - INLINECODE6 — barrel re-export module defining the public API surface
- INLINECODE7 — TypeScript interfaces for all on-chain account state
- INLINECODE8 — Program Derived Address derivation for all programs
- INLINECODE9 ,
src/idl/pump_amm.ts, src/idl/pump_fees.ts — Anchor IDL definitions
Architecture
- - Offline SDK (
PumpSdk): Builds instructions without a live connection. Uses Anchor Program instances initialized with a dummy keypair and connection. Exported as a singleton PUMP_SDK. - Online SDK (
OnlinePumpSdk): Wraps PumpSdk with a real Connection for fetching account state via getMultipleAccountsInfo. Provides "BothPrograms" methods that aggregate data across bonding curve (Pump) and AMM (PumpAMM) programs. - Three program IDs:
PUMP_PROGRAM_ID, PUMP_AMM_PROGRAM_ID, PUMP_FEE_PROGRAM_ID, plus MAYHEM_PROGRAM_ID for mayhem-mode tokens.
Instruction Builder Pattern
Every instruction method returns TransactionInstruction[] (not transactions), allowing callers to compose them into transactions freely. Methods follow a naming convention:
- -
*Instruction — single instruction - INLINECODE25 — multiple instructions (e.g., ATA creation + buy)
Account Decoders
The SDK decodes raw AccountInfo<Buffer> into typed interfaces using the Anchor coder:
- -
decodeGlobal, decodeBondingCurve, decodeFeeConfig, decodeSharingConfig, etc. - Nullable variants (e.g.,
decodeBondingCurveNullable) handle missing or undersized accounts gracefully.
Slippage Calculation
CODEBLOCK0
Patterns to Follow
- - Always return
TransactionInstruction[] from instruction builders, never full Transaction objects - Use
getMultipleAccountsInfo to batch RPC calls (2–3 accounts per call) - Support both Token (SPL) and Token-2022 programs via
tokenProgram parameter - Handle account extension (
extendAccountInstruction) for bonding curves that need more space - Validate shareholder arrays: max 10 shareholders, shares must total 10,000 bps, no duplicates, no zero shares
- Use typed error classes from
src/errors.ts for validation failures - Keep the offline SDK connection-free; all RPC calls belong in INLINECODE38
Common Pitfalls
- - Circular dependency between
sdk.ts and INLINECODE40 - Buy instruction passes
{ 0: true } as a flags argument — this is intentional, not a bug - INLINECODE42 — accounts may need extension before certain operations
- INLINECODE43 means the token has graduated to AMM — bonding curve operations will fail
- The
createInstruction (v1) is deprecated in favor of createV2Instruction (Token-2022)
Pump SDK Core — 指令构建与链上交互
构建、扩展并维护核心Pump SDK——一个离线优先的TypeScript SDK,用于在三个链上程序(Pump、PumpAMM、PumpFees)以及Mayhem程序中构建代币创建、买入、卖出、迁移和创建者费用收取的Solana TransactionInstruction。
上下文
该SDK以@pump-fun/pump-sdk(npm)发布,为Pump协议提供支持——一个基于Solana的代币启动平台,具有联合曲线定价、毕业后的自动AMM迁移、分层费用和创建者费用共享功能。代码库使用Anchor进行基于IDL的指令构建,并同时支持Token(SPL)和Token-2022代币程序。
关键文件
- - src/sdk.ts — PumpSdk类,包含所有指令构建器和账户解码器
- src/onlineSdk.ts — OnlinePumpSdk类,扩展离线SDK并支持实时RPC获取
- src/index.ts — 桶状重新导出模块,定义公共API接口
- src/state.ts — 所有链上账户状态的TypeScript接口
- src/pda.ts — 所有程序的程序派生地址推导
- src/idl/pump.ts、src/idl/pumpamm.ts、src/idl/pumpfees.ts — Anchor IDL定义
架构
- - 离线SDK(PumpSdk):无需实时连接即可构建指令。使用使用虚拟密钥对和连接初始化的Anchor Program实例。作为单例PUMPSDK导出。
- 在线SDK(OnlinePumpSdk):使用真实的Connection包装PumpSdk,通过getMultipleAccountsInfo获取账户状态。提供BothPrograms方法,聚合联合曲线(Pump)和AMM(PumpAMM)程序的数据。
- 三个程序ID:PUMPPROGRAMID、PUMPAMMPROGRAMID、PUMPFEEPROGRAMID,以及用于混乱模式代币的MAYHEMPROGRAM_ID。
指令构建器模式
每个指令方法返回TransactionInstruction[](而非交易),允许调用者自由组合成交易。方法遵循命名约定:
- - Instruction — 单条指令
- Instructions — 多条指令(例如,ATA创建+买入)
账户解码器
SDK使用Anchor编码器将原始AccountInfo解码为类型化接口:
- - decodeGlobal、decodeBondingCurve、decodeFeeConfig、decodeSharingConfig等
- 可空变体(例如,decodeBondingCurveNullable)优雅处理缺失或大小不足的账户
滑点计算
maxSolCost = solAmount + (solAmount × slippage × 10 / 1000)
minSolReceived = solAmount - (solAmount × slippage × 10 / 1000)
需遵循的模式
- - 始终从指令构建器返回TransactionInstruction[],而非完整的Transaction对象
- 使用getMultipleAccountsInfo批量处理RPC调用(每次调用2-3个账户)
- 通过tokenProgram参数同时支持Token(SPL)和Token-2022程序
- 处理需要更多空间的联合曲线的账户扩展(extendAccountInstruction)
- 验证股东数组:最多10个股东,股份必须总计10,000基点,无重复,无零股份
- 使用src/errors.ts中的类型化错误类进行验证失败处理
- 保持离线SDK无连接;所有RPC调用属于OnlinePumpSdk
常见陷阱
- - sdk.ts和onlineSdk.ts之间的循环依赖
- 买入指令将{ 0: true }作为标志参数传递——这是有意为之,而非错误
- BONDINGCURVENEW_SIZE = 151 — 在某些操作前账户可能需要扩展
- BondingCurve.complete === true表示代币已毕业到AMM——联合曲线操作将失败
- createInstruction(v1)已弃用,推荐使用createV2Instruction(Token-2022)