Pump.fun 协议的 Solana 智能合约 Fork 版本。该项目实现了一套完整的代币发行、Bonding Curve 交易和 AMM 流动性池管理系统。
本项目包含三个核心 Solana 程序:
| 程序 | Program ID | 描述 |
|---|---|---|
pump |
EnGZVNjHxuCYwYhGkuarfPewZ3HV9y6Jbc5fWB2tPpe7 |
主程序 - 代币创建与 Bonding Curve 交易 |
pump_amm |
FtZncevBWVYgkLZcSq5a93FQVRVLK8wd3B7M9hrha3th |
AMM 程序 - 流动性池管理 |
pump_fees |
9bFMgzuv2ZubxN2ATsDvFZcJrErUNuR3gg6bHd7C4o2C |
费用程序 - 动态费率管理 |
- 代币创建 (
create,create_v2): 创建新代币和对应的 Bonding Curve- 支持 SPL Token 和 Token2022 标准
- 支持 Mayhem 模式
- 交易功能:
buy/buy_exact_sol_in: 使用 SOL 购买代币sell: 卖出代币换取 SOL
- 流动性迁移 (
migrate): 当 Bonding Curve 完成后,将流动性迁移到 Pump AMM - 创作者费用 (
collect_creator_fee): 收取代币创作者费用 - 激励系统: 用户交易量追踪和代币激励领取
- 配置管理: 全局配置、费用设置、管理员权限
- 池子管理:
create_pool: 创建流动性池deposit: 添加流动性withdraw: 移除流动性
- 交易功能:
buy/buy_exact_quote_in: 买入基础代币sell: 卖出基础代币
- 费用分配: LP 费用、协议费用、创作者费用
- 分层费率: 基于市值动态调整交易费用
- 费用类型:
- LP 费用 (流动性提供者)
- 协议费用
- 创作者费用
采用恒定乘积做市商 (AMM) 算法:
virtual_token_reserves * virtual_sol_reserves = k
virtual_token_reserves: 虚拟代币储备virtual_sol_reserves: 虚拟 SOL 储备real_token_reserves: 实际代币储备real_sol_reserves: 实际 SOL 储备
- authority: 管理员地址
- fee_recipient: 费用接收地址
- initial_virtual_token_reserves: 初始虚拟代币储备
- initial_virtual_sol_reserves: 初始虚拟 SOL 储备
- fee_basis_points: 费率 (基点)
- creator_fee_basis_points: 创作者费率- virtual_token_reserves: 虚拟代币储备
- virtual_sol_reserves: 虚拟 SOL 储备
- real_token_reserves: 实际代币储备
- real_sol_reserves: 实际 SOL 储备
- token_total_supply: 代币总供应量
- complete: 是否已完成 (准备迁移)
- creator: 创作者地址
- is_mayhem_mode: 是否为 Mayhem 模式- base_mint: 基础代币地址
- quote_mint: 报价代币地址
- lp_mint: LP 代币地址
- lp_supply: LP 供应量
- coin_creator: 代币创作者
- is_mayhem_mode: 是否为 Mayhem 模式- Rust 1.75+
- Solana CLI 1.18+
- Anchor 0.32.1
- Node.js 18+ (用于测试)
- Yarn
# 构建所有程序
anchor build
# 仅构建特定程序
anchor build -p pump
anchor build -p pump_amm
anchor build -p pump_fees# TypeScript 测试
anchor test
# Rust 测试
cargo test
# 或
anchor run test-rs使用 Surfpool 进行本地开发和部署:
# 启动本地环境 (自动监听文件变化并重新部署)
surfpool start --watch或使用传统方式:
# 启动本地验证器
solana-test-validator
# 部署到本地网络
anchor deploypump-fun/
├── programs/
│ ├── pump/ # 主程序
│ │ └── src/
│ │ ├── instructions/ # 指令实现
│ │ ├── state/ # 账户状态
│ │ ├── events.rs # 事件定义
│ │ ├── errors.rs # 错误定义
│ │ ├── constants.rs # 常量定义
│ │ └── utils.rs # 工具函数
│ ├── pump-amm/ # AMM 程序
│ │ └── src/
│ │ ├── instructions/
│ │ ├── state.rs
│ │ ├── events.rs
│ │ └── errors.rs
│ └── pump-fees/ # 费用程序
│ └── src/
│ ├── instructions/
│ └── state.rs
├── tests/ # Rust 集成测试
├── Anchor.toml # Anchor 配置
└── Cargo.toml # Workspace 配置
- 调用
pump::create或pump::create_v2创建代币 - 用户通过
buy/sell在 Bonding Curve 上交易 - 当条件满足时,调用
migrate迁移到 AMM 池
用户 -> buy (SOL -> Token) -> Bonding Curve
用户 <- sell (Token -> SOL) <- Bonding Curve
Bonding Curve (complete=true) -> migrate -> Pump AMM Pool
费用按基点 (basis points) 计算,1 基点 = 0.01%
- 协议费用: 分配给协议方
- LP 费用: 分配给流动性提供者
- 创作者费用: 分配给代币创作者
支持基于市值的分层费率,市值越高费率可能越低。
- 所有交易支持滑点保护 (
max_sol_cost,min_sol_output) - 管理员权限分离 (authority, set_creator_authority, admin_set_creator_authority)
- 溢出检查已启用 (
overflow-checks = true)
本项目 Fork 自 pump-fun,感谢原作者的开源贡献。
MIT