refactor: rename protocol from RaydiumLaunchpad to Bonk
Comprehensive renaming of RaydiumLaunchpad-related modules, structs, event types and constants to Bonk while maintaining functional logic
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
# Sol Trade SDK
|
||||
|
||||
A comprehensive Rust SDK for seamless interaction with Solana DEX trading programs. This SDK provides a robust set of tools and interfaces to integrate PumpFun, PumpSwap, and Raydium Launchpad (Bonk.fun) functionality into your applications.
|
||||
A comprehensive Rust SDK for seamless interaction with Solana DEX trading programs. This SDK provides a robust set of tools and interfaces to integrate PumpFun, PumpSwap, and Bonk functionality into your applications.
|
||||
|
||||
## Project Features
|
||||
|
||||
1. **PumpFun Trading**: Support for `buy` and `sell` operations
|
||||
2. **PumpSwap Trading**: Support for PumpSwap pool trading operations
|
||||
3. **Raydium Trading**: Support for Raydium Launchpad (Bonk.fun) trading operations
|
||||
4. **Event Subscription**: Subscribe to PumpFun, PumpSwap, and Raydium Launchpad (Bonk.fun) program trading events
|
||||
3. **Bonk Trading**: Support for Bonk trading operations
|
||||
4. **Event Subscription**: Subscribe to PumpFun, PumpSwap, and Bonk program trading events
|
||||
5. **Yellowstone gRPC**: Subscribe to program events using Yellowstone gRPC
|
||||
6. **ShredStream Support**: Subscribe to program events using ShredStream
|
||||
7. **Multiple MEV Protection**: Support for Jito, Nextblock, ZeroSlot, Temporal, Bloxroute, and other services
|
||||
@@ -45,7 +45,7 @@ use sol_trade_sdk::{
|
||||
PumpSwapBuyEvent, PumpSwapCreatePoolEvent, PumpSwapDepositEvent,
|
||||
PumpSwapSellEvent, PumpSwapWithdrawEvent,
|
||||
},
|
||||
raydium_launchpad::{RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent},
|
||||
bonk::{BonkPoolCreateEvent, BonkTradeEvent},
|
||||
},
|
||||
Protocol, UnifiedEvent,
|
||||
},
|
||||
@@ -65,11 +65,11 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Define callback function to handle events
|
||||
let callback = |event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumLaunchpadPoolCreateEvent => |e: RaydiumLaunchpadPoolCreateEvent| {
|
||||
println!("RaydiumLaunchpadPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
RaydiumLaunchpadTradeEvent => |e: RaydiumLaunchpadTradeEvent| {
|
||||
println!("RaydiumLaunchpadTradeEvent: {:?}", e);
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {:?}", e);
|
||||
},
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {:?}", e);
|
||||
@@ -100,7 +100,7 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let protocols = vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
];
|
||||
grpc.subscribe_events(protocols, None, None, None, callback)
|
||||
.await?;
|
||||
@@ -123,11 +123,11 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Define callback function to handle events (same as above)
|
||||
let callback = |event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumLaunchpadPoolCreateEvent => |e: RaydiumLaunchpadPoolCreateEvent| {
|
||||
println!("RaydiumLaunchpadPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
RaydiumLaunchpadTradeEvent => |e: RaydiumLaunchpadTradeEvent| {
|
||||
println!("RaydiumLaunchpadTradeEvent: {:?}", e);
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {:?}", e);
|
||||
},
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {:?}", e);
|
||||
@@ -158,7 +158,7 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let protocols = vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
];
|
||||
shred_stream
|
||||
.shredstream_subscribe(protocols, None, callback)
|
||||
@@ -376,19 +376,19 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Raydium Launchpad Trading Operations
|
||||
### 5. Bonk Trading Operations
|
||||
|
||||
```rust
|
||||
use sol_trade_sdk::trading::core::params::RaydiumLaunchpadParams;
|
||||
use sol_trade_sdk::trading::core::params::BonkParams;
|
||||
|
||||
async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Basic parameter setup
|
||||
let amount = 100_000; // 0.0001 SOL
|
||||
let mint = Pubkey::from_str("xxxxxxx")?;
|
||||
let recent_blockhash = solana_trade_client.rpc.get_latest_blockhash().await?;
|
||||
|
||||
// Raydium Launchpad parameter configuration
|
||||
let raydium_launchpad_params = RaydiumLaunchpadParams {
|
||||
// Bonk parameter configuration
|
||||
let bonk_params = BonkParams {
|
||||
virtual_base: None,
|
||||
virtual_quote: None,
|
||||
real_base_before: None,
|
||||
@@ -396,7 +396,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
auto_handle_wsol: true,
|
||||
};
|
||||
|
||||
println!("Buying tokens from Raydium Launchpad...");
|
||||
println!("Buying tokens from letsbonk.fun...");
|
||||
|
||||
// Buy operation
|
||||
let buy_params = BuyParams {
|
||||
@@ -410,7 +410,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
lookup_table_key: solana_trade_client.trade_config.clone().lookup_table_key,
|
||||
recent_blockhash,
|
||||
data_size_limit: 0,
|
||||
protocol_params: Box::new(raydium_launchpad_params.clone()),
|
||||
protocol_params: Box::new(bonk_params.clone()),
|
||||
};
|
||||
|
||||
let buy_with_tip_params = buy_params
|
||||
@@ -422,7 +422,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.await?;
|
||||
|
||||
// Sell operation
|
||||
println!("Selling tokens from Raydium Launchpad...");
|
||||
println!("Selling tokens from letsbonk.fun...");
|
||||
|
||||
let sell_params = SellParams {
|
||||
rpc: Some(solana_trade_client.rpc.clone()),
|
||||
@@ -434,7 +434,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
priority_fee: solana_trade_client.trade_config.clone().priority_fee,
|
||||
lookup_table_key: solana_trade_client.trade_config.clone().lookup_table_key,
|
||||
recent_blockhash,
|
||||
protocol_params: Box::new(raydium_launchpad_params.clone()),
|
||||
protocol_params: Box::new(bonk_params.clone()),
|
||||
};
|
||||
|
||||
solana_trade_client
|
||||
@@ -475,7 +475,7 @@ let trade_config = TradeConfig {
|
||||
|
||||
- **PumpFun**: Primary meme coin trading platform
|
||||
- **PumpSwap**: PumpFun's swap protocol
|
||||
- **Raydium Launchpad**: Raydium's token launch platform (Bonk.fun)
|
||||
- **Bonk**: token launch platform (letsbonk.fun)
|
||||
|
||||
## MEV Protection Services
|
||||
|
||||
@@ -491,7 +491,7 @@ let trade_config = TradeConfig {
|
||||
|
||||
- **BuyParams**: Unified buy parameter structure
|
||||
- **SellParams**: Unified sell parameter structure
|
||||
- **Protocol-specific Parameters**: Each protocol has its own parameter structure (PumpFunParams, PumpSwapParams, RaydiumLaunchpadParams)
|
||||
- **Protocol-specific Parameters**: Each protocol has its own parameter structure (PumpFunParams, PumpSwapParams, BonkParams)
|
||||
|
||||
### Event Parsing System
|
||||
|
||||
@@ -519,14 +519,14 @@ src/
|
||||
│ ├── protocols/ # Protocol-specific parsers
|
||||
│ │ ├── pumpfun/ # PumpFun event parsing
|
||||
│ │ ├── pumpswap/ # PumpSwap event parsing
|
||||
│ │ └── raydium_launchpad/ # Raydium Launchpad event parsing
|
||||
│ │ └── bonk/ # Bonk event parsing
|
||||
│ └── factory.rs # Parser factory
|
||||
├── grpc/ # gRPC clients
|
||||
├── instruction/ # Instruction building
|
||||
├── protos/ # Protocol buffer definitions
|
||||
├── pumpfun/ # PumpFun trading functionality
|
||||
├── pumpswap/ # PumpSwap trading functionality
|
||||
├── raydium_launchpad/ # Raydium Launchpad trading functionality
|
||||
├── bonk/ # Bonk trading functionality
|
||||
├── swqos/ # MEV service clients
|
||||
├── trading/ # Unified trading engine
|
||||
│ ├── common/ # Common trading tools
|
||||
|
||||
+27
-27
@@ -1,13 +1,13 @@
|
||||
# Sol Trade SDK
|
||||
|
||||
一个全面的 Rust SDK,用于与 Solana DEX 交易程序进行无缝交互。此 SDK 提供强大的工具和接口集,将 PumpFun、PumpSwap 和 Raydium Launchpad(Bonk.fun)功能集成到您的应用程序中。
|
||||
一个全面的 Rust SDK,用于与 Solana DEX 交易程序进行无缝交互。此 SDK 提供强大的工具和接口集,将 PumpFun、PumpSwap 和 Bonk 功能集成到您的应用程序中。
|
||||
|
||||
## 项目特性
|
||||
|
||||
1. **PumpFun 交易**: 支持`购买`、`卖出`功能
|
||||
2. **PumpSwap 交易**: 支持 PumpSwap 池的交易操作
|
||||
3. **Raydium 交易**: 支持 Raydium Launchpad(Bonk.fun)的交易操作
|
||||
4. **事件订阅**: 订阅 PumpFun、PumpSwap 和 Raydium Launchpad(Bonk.fun)程序的交易事件
|
||||
3. **Bonk 交易**: 支持 Bonk 的交易操作
|
||||
4. **事件订阅**: 订阅 PumpFun、PumpSwap 和 Bonk 程序的交易事件
|
||||
5. **Yellowstone gRPC**: 使用 Yellowstone gRPC 订阅程序事件
|
||||
6. **ShredStream 支持**: 使用 ShredStream 订阅程序事件
|
||||
7. **多种 MEV 保护**: 支持 Jito、Nextblock、ZeroSlot、Temporal、Bloxroute 等服务
|
||||
@@ -45,7 +45,7 @@ use sol_trade_sdk::{
|
||||
PumpSwapBuyEvent, PumpSwapCreatePoolEvent, PumpSwapDepositEvent,
|
||||
PumpSwapSellEvent, PumpSwapWithdrawEvent,
|
||||
},
|
||||
raydium_launchpad::{RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent},
|
||||
bonk::{BonkPoolCreateEvent, BonkTradeEvent},
|
||||
},
|
||||
Protocol, UnifiedEvent,
|
||||
},
|
||||
@@ -65,11 +65,11 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 定义回调函数处理事件
|
||||
let callback = |event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumLaunchpadPoolCreateEvent => |e: RaydiumLaunchpadPoolCreateEvent| {
|
||||
println!("RaydiumLaunchpadPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
RaydiumLaunchpadTradeEvent => |e: RaydiumLaunchpadTradeEvent| {
|
||||
println!("RaydiumLaunchpadTradeEvent: {:?}", e);
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {:?}", e);
|
||||
},
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {:?}", e);
|
||||
@@ -100,7 +100,7 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let protocols = vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
];
|
||||
grpc.subscribe_events(protocols, None, None, None, callback)
|
||||
.await?;
|
||||
@@ -123,11 +123,11 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 定义回调函数处理事件(与上面相同)
|
||||
let callback = |event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumLaunchpadPoolCreateEvent => |e: RaydiumLaunchpadPoolCreateEvent| {
|
||||
println!("RaydiumLaunchpadPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
RaydiumLaunchpadTradeEvent => |e: RaydiumLaunchpadTradeEvent| {
|
||||
println!("RaydiumLaunchpadTradeEvent: {:?}", e);
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {:?}", e);
|
||||
},
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {:?}", e);
|
||||
@@ -158,7 +158,7 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let protocols = vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
];
|
||||
shred_stream
|
||||
.shredstream_subscribe(protocols, None, callback)
|
||||
@@ -376,19 +376,19 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Raydium Launchpad 交易操作
|
||||
### 5. Bonk 交易操作
|
||||
|
||||
```rust
|
||||
use sol_trade_sdk::trading::core::params::RaydiumLaunchpadParams;
|
||||
use sol_trade_sdk::trading::core::params::BonkParams;
|
||||
|
||||
async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 基本参数设置
|
||||
let amount = 100_000; // 0.0001 SOL
|
||||
let mint = Pubkey::from_str("xxxxxxx")?;
|
||||
let recent_blockhash = solana_trade_client.rpc.get_latest_blockhash().await?;
|
||||
|
||||
// Raydium Launchpad参数配置
|
||||
let raydium_launchpad_params = RaydiumLaunchpadParams {
|
||||
// Bonk参数配置
|
||||
let bonk_params = BonkParams {
|
||||
virtual_base: None,
|
||||
virtual_quote: None,
|
||||
real_base_before: None,
|
||||
@@ -396,7 +396,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
auto_handle_wsol: true,
|
||||
};
|
||||
|
||||
println!("Buying tokens from Raydium Launchpad...");
|
||||
println!("Buying tokens from letsbonk.fun...");
|
||||
|
||||
// 购买操作
|
||||
let buy_params = BuyParams {
|
||||
@@ -410,7 +410,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
lookup_table_key: solana_trade_client.trade_config.clone().lookup_table_key,
|
||||
recent_blockhash,
|
||||
data_size_limit: 0,
|
||||
protocol_params: Box::new(raydium_launchpad_params.clone()),
|
||||
protocol_params: Box::new(bonk_params.clone()),
|
||||
};
|
||||
|
||||
let buy_with_tip_params = buy_params
|
||||
@@ -422,7 +422,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.await?;
|
||||
|
||||
// 卖出操作
|
||||
println!("Selling tokens from Raydium Launchpad...");
|
||||
println!("Selling tokens from letsbonk.fun...");
|
||||
|
||||
let sell_params = SellParams {
|
||||
rpc: Some(solana_trade_client.rpc.clone()),
|
||||
@@ -434,7 +434,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
priority_fee: solana_trade_client.trade_config.clone().priority_fee,
|
||||
lookup_table_key: solana_trade_client.trade_config.clone().lookup_table_key,
|
||||
recent_blockhash,
|
||||
protocol_params: Box::new(raydium_launchpad_params.clone()),
|
||||
protocol_params: Box::new(bonk_params.clone()),
|
||||
};
|
||||
|
||||
solana_trade_client
|
||||
@@ -475,7 +475,7 @@ let trade_config = TradeConfig {
|
||||
|
||||
- **PumpFun**: 主要的 meme 币交易平台
|
||||
- **PumpSwap**: PumpFun 的交换协议
|
||||
- **Raydium Launchpad**: Raydium 的代币发行平台(Bonk.fun)
|
||||
- **Bonk**: 代币发行平台(letsbonk.fun)
|
||||
|
||||
## MEV 保护服务
|
||||
|
||||
@@ -491,7 +491,7 @@ let trade_config = TradeConfig {
|
||||
|
||||
- **BuyParams**: 统一的购买参数结构
|
||||
- **SellParams**: 统一的卖出参数结构
|
||||
- **协议特定参数**: 每个协议都有自己的参数结构(PumpFunParams、PumpSwapParams、RaydiumLaunchpadParams)
|
||||
- **协议特定参数**: 每个协议都有自己的参数结构(PumpFunParams、PumpSwapParams、BonkParams)
|
||||
|
||||
### 事件解析系统
|
||||
|
||||
@@ -519,14 +519,14 @@ src/
|
||||
│ ├── protocols/ # 协议特定解析器
|
||||
│ │ ├── pumpfun/ # PumpFun事件解析
|
||||
│ │ ├── pumpswap/ # PumpSwap事件解析
|
||||
│ │ └── raydium_launchpad/ # Raydium Launchpad事件解析
|
||||
│ │ └── bonk/ # Bonk事件解析
|
||||
│ └── factory.rs # 解析器工厂
|
||||
├── grpc/ # gRPC客户端
|
||||
├── instruction/ # 指令构建
|
||||
├── protos/ # 协议缓冲区定义
|
||||
├── pumpfun/ # PumpFun交易功能
|
||||
├── pumpswap/ # PumpSwap交易功能
|
||||
├── raydium_launchpad/ # Raydium Launchpad交易功能
|
||||
├── bonk/ # Bonk交易功能
|
||||
├── swqos/ # MEV服务客户端
|
||||
├── trading/ # 统一交易引擎
|
||||
│ ├── common/ # 通用交易工具
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use crate::swqos::SwqosClient;
|
||||
use crate::trading::{
|
||||
core::params::{PumpSwapParams, RaydiumLaunchpadParams},
|
||||
core::params::{PumpSwapParams, BonkParams},
|
||||
factory::Protocol,
|
||||
BuyParams, TradeFactory,
|
||||
};
|
||||
@@ -31,9 +31,9 @@ pub async fn buy(
|
||||
auto_handle_wsol: bool,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
// 创建执行器
|
||||
let executor = TradeFactory::create_executor(Protocol::RaydiumLaunchpad);
|
||||
let executor = TradeFactory::create_executor(Protocol::Bonk);
|
||||
// 创建协议特定参数
|
||||
let protocol_params = Box::new(RaydiumLaunchpadParams {
|
||||
let protocol_params = Box::new(BonkParams {
|
||||
auto_handle_wsol: auto_handle_wsol,
|
||||
virtual_base: Some(virtual_base),
|
||||
virtual_quote: Some(virtual_quote),
|
||||
@@ -77,9 +77,9 @@ pub async fn buy_with_tip(
|
||||
auto_handle_wsol: bool,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
// 创建执行器
|
||||
let executor = TradeFactory::create_executor(Protocol::RaydiumLaunchpad);
|
||||
let executor = TradeFactory::create_executor(Protocol::Bonk);
|
||||
// 创建协议特定参数
|
||||
let protocol_params = Box::new(RaydiumLaunchpadParams {
|
||||
let protocol_params = Box::new(BonkParams {
|
||||
auto_handle_wsol: auto_handle_wsol,
|
||||
virtual_base: Some(virtual_base),
|
||||
virtual_quote: Some(virtual_quote),
|
||||
@@ -38,22 +38,22 @@ pub fn get_amount_out(
|
||||
|
||||
pub fn get_pool_pda(base_mint: &Pubkey, quote_mint: &Pubkey) -> Option<Pubkey> {
|
||||
let seeds: &[&[u8]; 3] = &[
|
||||
constants::raydium_launchpad::seeds::POOL_SEED,
|
||||
constants::bonk::seeds::POOL_SEED,
|
||||
base_mint.as_ref(),
|
||||
quote_mint.as_ref(),
|
||||
];
|
||||
let program_id: &Pubkey = &constants::raydium_launchpad::accounts::LAUNCHPAD_PROGRAM;
|
||||
let program_id: &Pubkey = &constants::bonk::accounts::BONK;
|
||||
let pda: Option<(Pubkey, u8)> = Pubkey::try_find_program_address(seeds, program_id);
|
||||
pda.map(|pubkey| pubkey.0)
|
||||
}
|
||||
|
||||
pub fn get_vault_pda(pool_state: &Pubkey, mint: &Pubkey) -> Option<Pubkey> {
|
||||
let seeds: &[&[u8]; 3] = &[
|
||||
constants::raydium_launchpad::seeds::POOL_VAULT_SEED,
|
||||
constants::bonk::seeds::POOL_VAULT_SEED,
|
||||
pool_state.as_ref(),
|
||||
mint.as_ref(),
|
||||
];
|
||||
let program_id: &Pubkey = &constants::raydium_launchpad::accounts::LAUNCHPAD_PROGRAM;
|
||||
let program_id: &Pubkey = &constants::bonk::accounts::BONK;
|
||||
let pda: Option<(Pubkey, u8)> = Pubkey::try_find_program_address(seeds, program_id);
|
||||
pda.map(|pubkey| pubkey.0)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{common::SolanaRpcClient, constants::raydium_launchpad::accounts};
|
||||
use crate::{common::SolanaRpcClient, constants::bonk::accounts};
|
||||
use anyhow::anyhow;
|
||||
use borsh::BorshDeserialize;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -53,8 +53,8 @@ impl Pool {
|
||||
) -> Result<Self, anyhow::Error> {
|
||||
let account = rpc.get_account(pool_address).await?;
|
||||
|
||||
if account.owner != accounts::LAUNCHPAD_PROGRAM {
|
||||
return Err(anyhow!("Account is not owned by RaydiumLaunchpad program"));
|
||||
if account.owner != accounts::BONK {
|
||||
return Err(anyhow!("Account is not owned by Bonk program"));
|
||||
}
|
||||
|
||||
Self::from_bytes(&account.data)
|
||||
@@ -7,7 +7,7 @@ use crate::common::{PriorityFee, SolanaRpcClient};
|
||||
use crate::pumpswap::common::get_token_balance;
|
||||
use crate::swqos::SwqosClient;
|
||||
use crate::trading::{
|
||||
core::params::RaydiumLaunchpadParams, factory::Protocol, SellParams, TradeFactory,
|
||||
core::params::BonkParams, factory::Protocol, SellParams, TradeFactory,
|
||||
};
|
||||
|
||||
// Sell tokens to a Pumpswap pool
|
||||
@@ -25,9 +25,9 @@ pub async fn sell(
|
||||
lookup_table_key: Option<Pubkey>,
|
||||
recent_blockhash: Hash,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let executor = TradeFactory::create_executor(Protocol::RaydiumLaunchpad);
|
||||
let executor = TradeFactory::create_executor(Protocol::Bonk);
|
||||
// 创建PumpFun协议参数
|
||||
let protocol_params = Box::new(RaydiumLaunchpadParams {
|
||||
let protocol_params = Box::new(BonkParams {
|
||||
virtual_base: Some(virtual_base),
|
||||
virtual_quote: Some(virtual_quote),
|
||||
real_base_before: Some(real_base_before),
|
||||
@@ -137,9 +137,9 @@ pub async fn sell_with_tip(
|
||||
lookup_table_key: Option<Pubkey>,
|
||||
recent_blockhash: Hash,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let executor = TradeFactory::create_executor(Protocol::RaydiumLaunchpad);
|
||||
let executor = TradeFactory::create_executor(Protocol::Bonk);
|
||||
// 创建PumpFun协议参数
|
||||
let protocol_params = Box::new(RaydiumLaunchpadParams {
|
||||
let protocol_params = Box::new(BonkParams {
|
||||
virtual_base: Some(virtual_base),
|
||||
virtual_quote: Some(virtual_quote),
|
||||
real_base_before: Some(real_base_before),
|
||||
@@ -26,7 +26,7 @@ pub mod accounts {
|
||||
pub const TOKEN_PROGRAM: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
||||
pub const EVENT_AUTHORITY: Pubkey = pubkey!("2DPAtwB8L12vrMRExbLuyGnC7n2J5LNoZQSejeQGpwkr");
|
||||
pub const WSOL_TOKEN_ACCOUNT: Pubkey = pubkey!("So11111111111111111111111111111111111111112");
|
||||
pub const LAUNCHPAD_PROGRAM: Pubkey = pubkey!("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj");
|
||||
pub const BONK: Pubkey = pubkey!("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj");
|
||||
|
||||
pub const PLATFORM_FEE_RATE: u128 = 100; // 1%
|
||||
pub const PROTOCOL_FEE_RATE: u128 = 25; // 0.25%
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod raydium_launchpad;
|
||||
pub mod bonk;
|
||||
pub mod swqos;
|
||||
|
||||
pub mod trade_type {
|
||||
@@ -13,5 +13,5 @@ pub mod trade_type {
|
||||
pub mod trade_platform {
|
||||
pub const PUMPFUN: &'static str = "pumpfun";
|
||||
pub const PUMPFUN_SWAP: &'static str = "pumpswap";
|
||||
pub const RAYDIUM_LAUNCHPAD: &'static str = "raydium_launchpad";
|
||||
pub const BONK: &'static str = "bonk";
|
||||
}
|
||||
@@ -11,8 +11,7 @@ pub enum ProtocolType {
|
||||
#[default]
|
||||
PumpSwap,
|
||||
PumpFun,
|
||||
RaydiumLaunchpad,
|
||||
Raydium,
|
||||
Bonk,
|
||||
}
|
||||
|
||||
/// 事件类型枚举
|
||||
@@ -33,12 +32,12 @@ pub enum EventType {
|
||||
PumpFunBuy,
|
||||
PumpFunSell,
|
||||
|
||||
// RaydiumLaunchpad 事件
|
||||
RaydiumLaunchpadBuyExactIn,
|
||||
RaydiumLaunchpadBuyExactOut,
|
||||
RaydiumLaunchpadSellExactIn,
|
||||
RaydiumLaunchpadSellExactOut,
|
||||
RaydiumLaunchpadInitialize,
|
||||
// Bonk 事件
|
||||
BonkBuyExactIn,
|
||||
BonkBuyExactOut,
|
||||
BonkSellExactIn,
|
||||
BonkSellExactOut,
|
||||
BonkInitialize,
|
||||
|
||||
// 通用事件
|
||||
Unknown,
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::fmt::Debug;
|
||||
|
||||
use crate::{
|
||||
error,
|
||||
event_parser::{common::{utils::*, EventMetadata, EventType, ProtocolType}, protocols::{pumpfun::{PumpFunCreateTokenEvent, PumpFunTradeEvent}, raydium_launchpad::{RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent}}},
|
||||
event_parser::{common::{utils::*, EventMetadata, EventType, ProtocolType}, protocols::{pumpfun::{PumpFunCreateTokenEvent, PumpFunTradeEvent}, bonk::{BonkPoolCreateEvent, BonkTradeEvent}}},
|
||||
};
|
||||
|
||||
/// 统一事件接口 - 所有协议的事件都需要实现此trait
|
||||
@@ -178,7 +178,7 @@ pub trait EventParser: Send + Sync {
|
||||
|
||||
fn process_events(&self, mut events: Vec<Box<dyn UnifiedEvent>>, bot_wallet: Option<Pubkey>) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
let mut dev_address = None;
|
||||
let mut raydium_dev_address = None;
|
||||
let mut bonk_dev_address = None;
|
||||
for event in &mut events {
|
||||
if let Some(token_info) = event.as_any().downcast_ref::<PumpFunCreateTokenEvent>() {
|
||||
dev_address = Some(token_info.user);
|
||||
@@ -195,14 +195,14 @@ pub trait EventParser: Send + Sync {
|
||||
}
|
||||
if let Some(pool_info) = event
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadPoolCreateEvent>()
|
||||
.downcast_ref::<BonkPoolCreateEvent>()
|
||||
{
|
||||
raydium_dev_address = Some(pool_info.creator);
|
||||
bonk_dev_address = Some(pool_info.creator);
|
||||
} else if let Some(trade_info) = event
|
||||
.as_any_mut()
|
||||
.downcast_mut::<RaydiumLaunchpadTradeEvent>()
|
||||
.downcast_mut::<BonkTradeEvent>()
|
||||
{
|
||||
if Some(trade_info.payer) == raydium_dev_address {
|
||||
if Some(trade_info.payer) == bonk_dev_address {
|
||||
trade_info.is_dev_create_token_trade = true;
|
||||
} else if Some(trade_info.payer) == bot_wallet {
|
||||
trade_info.is_bot = true;
|
||||
|
||||
@@ -3,7 +3,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::event_parser::protocols::{
|
||||
pumpfun::parser::PUMPFUN_PROGRAM_ID, pumpswap::parser::PUMPSWAP_PROGRAM_ID, raydium_launchpad::parser::RAYDIUM_LAUNCHPAD_PROGRAM_ID, RaydiumLaunchpadEventParser,
|
||||
pumpfun::parser::PUMPFUN_PROGRAM_ID, pumpswap::parser::PUMPSWAP_PROGRAM_ID, bonk::parser::BONK_PROGRAM_ID, BonkEventParser,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -16,7 +16,7 @@ use super::{
|
||||
pub enum Protocol {
|
||||
PumpSwap,
|
||||
PumpFun,
|
||||
RaydiumLaunchpad,
|
||||
Bonk,
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
@@ -24,7 +24,7 @@ impl Protocol {
|
||||
match self {
|
||||
Protocol::PumpSwap => vec![PUMPSWAP_PROGRAM_ID],
|
||||
Protocol::PumpFun => vec![PUMPFUN_PROGRAM_ID],
|
||||
Protocol::RaydiumLaunchpad => vec![RAYDIUM_LAUNCHPAD_PROGRAM_ID],
|
||||
Protocol::Bonk => vec![BONK_PROGRAM_ID],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ impl std::fmt::Display for Protocol {
|
||||
match self {
|
||||
Protocol::PumpSwap => write!(f, "PumpSwap"),
|
||||
Protocol::PumpFun => write!(f, "PumpFun"),
|
||||
Protocol::RaydiumLaunchpad => write!(f, "RaydiumLaunchpad"),
|
||||
Protocol::Bonk => write!(f, "Bonk"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ impl std::str::FromStr for Protocol {
|
||||
match s.to_lowercase().as_str() {
|
||||
"pumpswap" => Ok(Protocol::PumpSwap),
|
||||
"pumpfun" => Ok(Protocol::PumpFun),
|
||||
"raydiumlaunchpad" => Ok(Protocol::RaydiumLaunchpad),
|
||||
"bonk" => Ok(Protocol::Bonk),
|
||||
_ => Err(anyhow!("Unsupported protocol: {}", s)),
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ impl EventParserFactory {
|
||||
match protocol {
|
||||
Protocol::PumpSwap => Arc::new(PumpSwapEventParser::new()),
|
||||
Protocol::PumpFun => Arc::new(PumpFunEventParser::new()),
|
||||
Protocol::RaydiumLaunchpad => Arc::new(RaydiumLaunchpadEventParser::new()),
|
||||
Protocol::Bonk => Arc::new(BonkEventParser::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
use crate::event_parser::protocols::raydium_launchpad::types::{
|
||||
use crate::event_parser::protocols::bonk::types::{
|
||||
CurveParams, MintParams, PoolStatus, TradeDirection, VestingParams,
|
||||
};
|
||||
use crate::event_parser::{common::EventMetadata, core::traits::UnifiedEvent};
|
||||
@@ -9,7 +9,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
/// 买入事件
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumLaunchpadTradeEvent {
|
||||
pub struct BonkTradeEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pool_state: Pubkey,
|
||||
@@ -55,7 +55,7 @@ pub struct RaydiumLaunchpadTradeEvent {
|
||||
|
||||
// 使用宏生成UnifiedEvent实现,指定需要合并的字段
|
||||
impl_unified_event!(
|
||||
RaydiumLaunchpadTradeEvent,
|
||||
BonkTradeEvent,
|
||||
pool_state,
|
||||
total_base_sell,
|
||||
virtual_base,
|
||||
@@ -75,7 +75,7 @@ impl_unified_event!(
|
||||
|
||||
/// 创建池事件
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumLaunchpadPoolCreateEvent {
|
||||
pub struct BonkPoolCreateEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pool_state: Pubkey,
|
||||
@@ -102,7 +102,7 @@ pub struct RaydiumLaunchpadPoolCreateEvent {
|
||||
|
||||
// 使用宏生成UnifiedEvent实现,指定需要合并的字段
|
||||
impl_unified_event!(
|
||||
RaydiumLaunchpadPoolCreateEvent,
|
||||
BonkPoolCreateEvent,
|
||||
pool_state,
|
||||
creator,
|
||||
config,
|
||||
+1
-1
@@ -3,5 +3,5 @@ pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::RaydiumLaunchpadEventParser;
|
||||
pub use parser::BonkEventParser;
|
||||
pub use types::*;
|
||||
+24
-24
@@ -4,65 +4,65 @@ use solana_transaction_status::UiCompiledInstruction;
|
||||
use crate::event_parser::{
|
||||
common::{utils::*, EventMetadata, EventType, ProtocolType},
|
||||
core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent},
|
||||
protocols::raydium_launchpad::{
|
||||
protocols::bonk::{
|
||||
discriminators, ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams,
|
||||
RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent, TradeDirection, VestingParams,
|
||||
BonkPoolCreateEvent, BonkTradeEvent, TradeDirection, VestingParams,
|
||||
},
|
||||
};
|
||||
|
||||
/// RaydiumLaunchpad程序ID
|
||||
pub const RAYDIUM_LAUNCHPAD_PROGRAM_ID: Pubkey =
|
||||
/// Bonk程序ID
|
||||
pub const BONK_PROGRAM_ID: Pubkey =
|
||||
solana_sdk::pubkey!("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj");
|
||||
|
||||
/// RaydiumLaunchpad事件解析器
|
||||
pub struct RaydiumLaunchpadEventParser {
|
||||
/// Bonk事件解析器
|
||||
pub struct BonkEventParser {
|
||||
inner: GenericEventParser,
|
||||
}
|
||||
|
||||
impl RaydiumLaunchpadEventParser {
|
||||
impl BonkEventParser {
|
||||
pub fn new() -> Self {
|
||||
// 配置所有事件类型
|
||||
let configs = vec![
|
||||
GenericEventParseConfig {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::BUY_EXACT_IN,
|
||||
event_type: EventType::RaydiumLaunchpadBuyExactIn,
|
||||
event_type: EventType::BonkBuyExactIn,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_buy_exact_in_instruction,
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::BUY_EXACT_OUT,
|
||||
event_type: EventType::RaydiumLaunchpadBuyExactOut,
|
||||
event_type: EventType::BonkBuyExactOut,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_buy_exact_out_instruction,
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::SELL_EXACT_IN,
|
||||
event_type: EventType::RaydiumLaunchpadSellExactIn,
|
||||
event_type: EventType::BonkSellExactIn,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_exact_in_instruction,
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::SELL_EXACT_OUT,
|
||||
event_type: EventType::RaydiumLaunchpadSellExactOut,
|
||||
event_type: EventType::BonkSellExactOut,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_exact_out_instruction,
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
inner_instruction_discriminator: discriminators::POOL_CREATE_EVENT,
|
||||
instruction_discriminator: discriminators::INITIALIZE,
|
||||
event_type: EventType::RaydiumLaunchpadInitialize,
|
||||
event_type: EventType::BonkInitialize,
|
||||
inner_instruction_parser: Self::parse_pool_create_inner_instruction,
|
||||
instruction_parser: Self::parse_initialize_instruction,
|
||||
},
|
||||
];
|
||||
|
||||
let inner = GenericEventParser::new(
|
||||
RAYDIUM_LAUNCHPAD_PROGRAM_ID,
|
||||
ProtocolType::RaydiumLaunchpad,
|
||||
BONK_PROGRAM_ID,
|
||||
ProtocolType::Bonk,
|
||||
configs,
|
||||
);
|
||||
|
||||
@@ -74,10 +74,10 @@ impl RaydiumLaunchpadEventParser {
|
||||
data: &[u8],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Ok(event) = borsh::from_slice::<RaydiumLaunchpadPoolCreateEvent>(data) {
|
||||
if let Ok(event) = borsh::from_slice::<BonkPoolCreateEvent>(data) {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}", metadata.signature,));
|
||||
Some(Box::new(RaydiumLaunchpadPoolCreateEvent {
|
||||
Some(Box::new(BonkPoolCreateEvent {
|
||||
metadata: metadata,
|
||||
..event
|
||||
}))
|
||||
@@ -91,14 +91,14 @@ impl RaydiumLaunchpadEventParser {
|
||||
data: &[u8],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Ok(event) = borsh::from_slice::<RaydiumLaunchpadTradeEvent>(data) {
|
||||
if let Ok(event) = borsh::from_slice::<BonkTradeEvent>(data) {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!(
|
||||
"{}-{}",
|
||||
metadata.signature,
|
||||
event.pool_state.to_string()
|
||||
));
|
||||
Some(Box::new(RaydiumLaunchpadTradeEvent {
|
||||
Some(Box::new(BonkTradeEvent {
|
||||
metadata: metadata,
|
||||
..event
|
||||
}))
|
||||
@@ -124,7 +124,7 @@ impl RaydiumLaunchpadEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}", metadata.signature, accounts[4]));
|
||||
|
||||
Some(Box::new(RaydiumLaunchpadTradeEvent {
|
||||
Some(Box::new(BonkTradeEvent {
|
||||
metadata,
|
||||
amount_in,
|
||||
minimum_amount_out,
|
||||
@@ -158,7 +158,7 @@ impl RaydiumLaunchpadEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}", metadata.signature, accounts[4]));
|
||||
|
||||
Some(Box::new(RaydiumLaunchpadTradeEvent {
|
||||
Some(Box::new(BonkTradeEvent {
|
||||
metadata,
|
||||
amount_out,
|
||||
maximum_amount_in,
|
||||
@@ -192,7 +192,7 @@ impl RaydiumLaunchpadEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}", metadata.signature, accounts[4]));
|
||||
|
||||
Some(Box::new(RaydiumLaunchpadTradeEvent {
|
||||
Some(Box::new(BonkTradeEvent {
|
||||
metadata,
|
||||
amount_in,
|
||||
minimum_amount_out,
|
||||
@@ -226,7 +226,7 @@ impl RaydiumLaunchpadEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}", metadata.signature, accounts[4]));
|
||||
|
||||
Some(Box::new(RaydiumLaunchpadTradeEvent {
|
||||
Some(Box::new(BonkTradeEvent {
|
||||
metadata,
|
||||
amount_out,
|
||||
maximum_amount_in,
|
||||
@@ -262,7 +262,7 @@ impl RaydiumLaunchpadEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}", metadata.signature));
|
||||
|
||||
Some(Box::new(RaydiumLaunchpadPoolCreateEvent {
|
||||
Some(Box::new(BonkPoolCreateEvent {
|
||||
metadata,
|
||||
payer: accounts[0],
|
||||
creator: accounts[1],
|
||||
@@ -404,7 +404,7 @@ impl RaydiumLaunchpadEventParser {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EventParser for RaydiumLaunchpadEventParser {
|
||||
impl EventParser for BonkEventParser {
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod raydium_launchpad;
|
||||
pub mod bonk;
|
||||
|
||||
pub use pumpfun::PumpFunEventParser;
|
||||
pub use pumpswap::PumpSwapEventParser;
|
||||
pub use raydium_launchpad::RaydiumLaunchpadEventParser;
|
||||
pub use bonk::BonkEventParser;
|
||||
@@ -9,8 +9,8 @@ use solana_sdk::transaction::VersionedTransaction;
|
||||
|
||||
use crate::common::AnyResult;
|
||||
use crate::event_parser::protocols::pumpfun::{PumpFunCreateTokenEvent, PumpFunTradeEvent};
|
||||
use crate::event_parser::protocols::raydium_launchpad::{
|
||||
RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent,
|
||||
use crate::event_parser::protocols::bonk::{
|
||||
BonkPoolCreateEvent, BonkTradeEvent,
|
||||
};
|
||||
use crate::event_parser::{EventParserFactory, Protocol, UnifiedEvent};
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ use yellowstone_grpc_proto::geyser::{
|
||||
use crate::common::AnyResult;
|
||||
use crate::constants::pumpfun::trade;
|
||||
use crate::event_parser::protocols::pumpfun::{PumpFunCreateTokenEvent, PumpFunTradeEvent};
|
||||
use crate::event_parser::protocols::raydium_launchpad::{
|
||||
RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent,
|
||||
use crate::event_parser::protocols::bonk::{
|
||||
BonkPoolCreateEvent, BonkTradeEvent,
|
||||
};
|
||||
use crate::event_parser::{EventParserFactory, Protocol, UnifiedEvent};
|
||||
|
||||
|
||||
+15
-15
@@ -8,7 +8,7 @@ pub mod instruction;
|
||||
pub mod protos;
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod raydium_launchpad;
|
||||
pub mod bonk;
|
||||
pub mod swqos;
|
||||
pub mod trading;
|
||||
|
||||
@@ -26,7 +26,7 @@ use swqos::SwqosClient;
|
||||
use common::{PriorityFee, SolanaRpcClient, TradeConfig};
|
||||
|
||||
use accounts::BondingCurveAccount;
|
||||
use constants::trade_platform::{PUMPFUN, PUMPFUN_SWAP, RAYDIUM_LAUNCHPAD};
|
||||
use constants::trade_platform::{PUMPFUN, PUMPFUN_SWAP, BONK};
|
||||
use constants::trade_type::{COPY_BUY, SNIPER_BUY};
|
||||
|
||||
use crate::event_parser::protocols::pumpfun::PumpFunTradeEvent;
|
||||
@@ -34,7 +34,7 @@ use crate::swqos::SwqosConfig;
|
||||
use crate::trading::core::params::PumpFunParams;
|
||||
use crate::trading::core::params::PumpFunSellParams;
|
||||
use crate::trading::core::params::PumpSwapParams;
|
||||
use crate::trading::core::params::RaydiumLaunchpadParams;
|
||||
use crate::trading::core::params::BonkParams;
|
||||
use crate::trading::BuyWithTipParams;
|
||||
use crate::trading::SellParams;
|
||||
use crate::trading::SellWithTipParams;
|
||||
@@ -181,9 +181,9 @@ impl SolanaTrade {
|
||||
} else if let Some(protocol_params) = buy_params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.downcast_ref::<BonkParams>()
|
||||
{
|
||||
raydium_launchpad::buy::buy(
|
||||
bonk::buy::buy(
|
||||
self.rpc.clone(),
|
||||
self.payer.clone(),
|
||||
mint,
|
||||
@@ -270,9 +270,9 @@ impl SolanaTrade {
|
||||
} else if let Some(protocol_params) = buy_params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.downcast_ref::<BonkParams>()
|
||||
{
|
||||
raydium_launchpad::buy::buy(
|
||||
bonk::buy::buy(
|
||||
self.rpc.clone(),
|
||||
self.payer.clone(),
|
||||
mint,
|
||||
@@ -345,9 +345,9 @@ impl SolanaTrade {
|
||||
} else if let Some(protocol_params) = sell_params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.downcast_ref::<BonkParams>()
|
||||
{
|
||||
raydium_launchpad::sell::sell_by_percent(
|
||||
bonk::sell::sell_by_percent(
|
||||
self.rpc.clone(),
|
||||
self.payer.clone(),
|
||||
mint.clone(),
|
||||
@@ -417,9 +417,9 @@ impl SolanaTrade {
|
||||
} else if let Some(protocol_params) = sell_params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.downcast_ref::<BonkParams>()
|
||||
{
|
||||
raydium_launchpad::sell::sell_by_amount(
|
||||
bonk::sell::sell_by_amount(
|
||||
self.rpc.clone(),
|
||||
self.payer.clone(),
|
||||
mint.clone(),
|
||||
@@ -492,9 +492,9 @@ impl SolanaTrade {
|
||||
} else if let Some(protocol_params) = sell_params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.downcast_ref::<BonkParams>()
|
||||
{
|
||||
raydium_launchpad::sell::sell_by_percent_with_tip(
|
||||
bonk::sell::sell_by_percent_with_tip(
|
||||
self.rpc.clone(),
|
||||
self.swqos_clients.clone(),
|
||||
self.payer.clone(),
|
||||
@@ -566,9 +566,9 @@ impl SolanaTrade {
|
||||
} else if let Some(protocol_params) = sell_params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.downcast_ref::<BonkParams>()
|
||||
{
|
||||
raydium_launchpad::sell::sell_by_amount_with_tip(
|
||||
bonk::sell::sell_by_amount_with_tip(
|
||||
self.rpc.clone(),
|
||||
self.swqos_clients.clone(),
|
||||
self.payer.clone(),
|
||||
|
||||
+19
-19
@@ -11,7 +11,7 @@ use sol_trade_sdk::{
|
||||
PumpSwapBuyEvent, PumpSwapCreatePoolEvent, PumpSwapDepositEvent, PumpSwapSellEvent,
|
||||
PumpSwapWithdrawEvent,
|
||||
},
|
||||
raydium_launchpad::{RaydiumLaunchpadPoolCreateEvent, RaydiumLaunchpadTradeEvent},
|
||||
bonk::{BonkPoolCreateEvent, BonkTradeEvent},
|
||||
},
|
||||
Protocol, UnifiedEvent,
|
||||
},
|
||||
@@ -20,7 +20,7 @@ use sol_trade_sdk::{
|
||||
pumpfun::common::get_bonding_curve_account_v2,
|
||||
swqos::{SwqosConfig, SwqosRegion},
|
||||
trading::{
|
||||
core::params::{PumpFunParams, PumpFunSellParams, PumpSwapParams, RaydiumLaunchpadParams},
|
||||
core::params::{PumpFunParams, PumpFunSellParams, PumpSwapParams, BonkParams},
|
||||
BuyParams, SellParams,
|
||||
},
|
||||
SolanaTrade,
|
||||
@@ -32,7 +32,7 @@ use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signature:
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
test_pumpfun().await?;
|
||||
// test_pumpswap().await?;
|
||||
// test_raydium_launchpad().await?;
|
||||
// test_bonk().await?;
|
||||
// test_grpc().await?;
|
||||
// test_shreds().await?;
|
||||
Ok(())
|
||||
@@ -208,7 +208,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 创建一个随机账户作为交易者
|
||||
let payer = Keypair::new();
|
||||
let rpc_url = "https://mainnet.helius-rpc.com/?api-key=xxxxxx".to_string();
|
||||
@@ -232,14 +232,14 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let amount = 100_000; // 0.0001 SOL
|
||||
let recent_blockhash = solana_trade_client.rpc.get_latest_blockhash().await?;
|
||||
let mint = Pubkey::from_str("xxxxxxx")?;
|
||||
let raydium_launchpad_params = RaydiumLaunchpadParams {
|
||||
let bonk_params = BonkParams {
|
||||
virtual_base: None,
|
||||
virtual_quote: None,
|
||||
real_base_before: None,
|
||||
real_quote_before: None,
|
||||
auto_handle_wsol: true,
|
||||
};
|
||||
println!("Buying tokens from Raydium Launchpad...");
|
||||
println!("Buying tokens from letsbonk.fun...");
|
||||
// buy
|
||||
let buy_params = BuyParams {
|
||||
rpc: Some(solana_trade_client.rpc.clone()),
|
||||
@@ -252,7 +252,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
lookup_table_key: solana_trade_client.trade_config.clone().lookup_table_key,
|
||||
recent_blockhash,
|
||||
data_size_limit: 0,
|
||||
protocol_params: Box::new(raydium_launchpad_params.clone()),
|
||||
protocol_params: Box::new(bonk_params.clone()),
|
||||
};
|
||||
let buy_with_tip_params = buy_params
|
||||
.clone()
|
||||
@@ -261,7 +261,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.buy_use_buy_params(buy_with_tip_params, None)
|
||||
.await?;
|
||||
// sell
|
||||
println!("Selling tokens from Raydium Launchpad...");
|
||||
println!("Selling tokens from letsbonk.fun...");
|
||||
let sell_params = SellParams {
|
||||
rpc: Some(solana_trade_client.rpc.clone()),
|
||||
payer: solana_trade_client.payer.clone(),
|
||||
@@ -272,7 +272,7 @@ async fn test_raydium_launchpad() -> Result<(), Box<dyn std::error::Error>> {
|
||||
priority_fee: solana_trade_client.trade_config.clone().priority_fee,
|
||||
lookup_table_key: solana_trade_client.trade_config.clone().lookup_table_key,
|
||||
recent_blockhash,
|
||||
protocol_params: Box::new(raydium_launchpad_params.clone()),
|
||||
protocol_params: Box::new(bonk_params.clone()),
|
||||
};
|
||||
solana_trade_client
|
||||
.sell_by_amount_use_sell_params(sell_params)
|
||||
@@ -292,11 +292,11 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 定义回调函数处理 PumpSwap 事件
|
||||
let callback = |event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumLaunchpadPoolCreateEvent => |e: RaydiumLaunchpadPoolCreateEvent| {
|
||||
println!("RaydiumLaunchpadPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
RaydiumLaunchpadTradeEvent => |e: RaydiumLaunchpadTradeEvent| {
|
||||
println!("RaydiumLaunchpadTradeEvent: {:?}", e);
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {:?}", e);
|
||||
},
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {:?}", e);
|
||||
@@ -327,7 +327,7 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let protocols = vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
];
|
||||
grpc.subscribe_events(protocols, None, None, None, callback)
|
||||
.await?;
|
||||
@@ -344,11 +344,11 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 定义回调函数处理 PumpSwap 事件
|
||||
let callback = |event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumLaunchpadPoolCreateEvent => |e: RaydiumLaunchpadPoolCreateEvent| {
|
||||
println!("RaydiumLaunchpadPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
RaydiumLaunchpadTradeEvent => |e: RaydiumLaunchpadTradeEvent| {
|
||||
println!("RaydiumLaunchpadTradeEvent: {:?}", e);
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {:?}", e);
|
||||
},
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {:?}", e);
|
||||
@@ -379,7 +379,7 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let protocols = vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
];
|
||||
shred_stream
|
||||
.shredstream_subscribe(protocols, None, callback)
|
||||
|
||||
@@ -122,9 +122,9 @@ impl ProtocolParams for PumpSwapParams {
|
||||
}
|
||||
}
|
||||
|
||||
/// RaydiumLaunchpad协议特定参数
|
||||
/// Bonk协议特定参数
|
||||
#[derive(Clone)]
|
||||
pub struct RaydiumLaunchpadParams {
|
||||
pub struct BonkParams {
|
||||
pub virtual_base: Option<u128>,
|
||||
pub virtual_quote: Option<u128>,
|
||||
pub real_base_before: Option<u128>,
|
||||
@@ -132,7 +132,7 @@ pub struct RaydiumLaunchpadParams {
|
||||
pub auto_handle_wsol: bool,
|
||||
}
|
||||
|
||||
impl ProtocolParams for RaydiumLaunchpadParams {
|
||||
impl ProtocolParams for BonkParams {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::trading::protocols::raydium_launchpad::RaydiumLaunchpadInstructionBuilder;
|
||||
use crate::trading::protocols::bonk::BonkInstructionBuilder;
|
||||
|
||||
use super::{
|
||||
core::{executor::GenericTradeExecutor, traits::TradeExecutor},
|
||||
@@ -13,7 +13,7 @@ use super::{
|
||||
pub enum Protocol {
|
||||
PumpFun,
|
||||
PumpSwap,
|
||||
RaydiumLaunchpad,
|
||||
Bonk,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Protocol {
|
||||
@@ -21,7 +21,7 @@ impl std::fmt::Display for Protocol {
|
||||
match self {
|
||||
Protocol::PumpFun => write!(f, "PumpFun"),
|
||||
Protocol::PumpSwap => write!(f, "PumpSwap"),
|
||||
Protocol::RaydiumLaunchpad => write!(f, "RaydiumLaunchpad"),
|
||||
Protocol::Bonk => write!(f, "Bonk"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ impl std::str::FromStr for Protocol {
|
||||
match s.to_lowercase().as_str() {
|
||||
"pumpfun" => Ok(Protocol::PumpFun),
|
||||
"pumpswap" => Ok(Protocol::PumpSwap),
|
||||
"raydiumlaunchpad" => Ok(Protocol::RaydiumLaunchpad),
|
||||
"bonk" => Ok(Protocol::Bonk),
|
||||
_ => Err(anyhow!("Unsupported protocol: {}", s)),
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,11 @@ impl TradeFactory {
|
||||
let instruction_builder = Arc::new(PumpSwapInstructionBuilder);
|
||||
Arc::new(GenericTradeExecutor::new(instruction_builder, "PumpSwap"))
|
||||
}
|
||||
Protocol::RaydiumLaunchpad => {
|
||||
let instruction_builder = Arc::new(RaydiumLaunchpadInstructionBuilder);
|
||||
Protocol::Bonk => {
|
||||
let instruction_builder = Arc::new(BonkInstructionBuilder);
|
||||
Arc::new(GenericTradeExecutor::new(
|
||||
instruction_builder,
|
||||
"RaydiumLaunchpad",
|
||||
"Bonk",
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl TradeFactory {
|
||||
vec![
|
||||
Protocol::PumpFun,
|
||||
Protocol::PumpSwap,
|
||||
Protocol::RaydiumLaunchpad,
|
||||
Protocol::Bonk,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,24 @@ use solana_sdk::{instruction::Instruction, pubkey::Pubkey, signer::Signer};
|
||||
use spl_associated_token_account::instruction::create_associated_token_account_idempotent;
|
||||
|
||||
use crate::{
|
||||
constants::raydium_launchpad::{
|
||||
constants::bonk::{
|
||||
accounts, trade::DEFAULT_SLIPPAGE, BUY_EXECT_IN_DISCRIMINATOR, SELL_EXECT_IN_DISCRIMINATOR,
|
||||
},
|
||||
raydium_launchpad::{
|
||||
bonk::{
|
||||
common::{get_amount_out, get_pool_pda, get_token_balance, get_vault_pda},
|
||||
pool::Pool,
|
||||
},
|
||||
trading::core::{
|
||||
params::{BuyParams, RaydiumLaunchpadParams, SellParams},
|
||||
params::{BuyParams, BonkParams, SellParams},
|
||||
traits::InstructionBuilder,
|
||||
},
|
||||
};
|
||||
|
||||
/// RaydiumLaunchpad协议的指令构建器
|
||||
pub struct RaydiumLaunchpadInstructionBuilder;
|
||||
/// Bonk协议的指令构建器
|
||||
pub struct BonkInstructionBuilder;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl InstructionBuilder for RaydiumLaunchpadInstructionBuilder {
|
||||
impl InstructionBuilder for BonkInstructionBuilder {
|
||||
async fn build_buy_instructions(&self, params: &BuyParams) -> Result<Vec<Instruction>> {
|
||||
if params.amount_sol == 0 {
|
||||
return Err(anyhow!("Amount cannot be zero"));
|
||||
@@ -33,7 +33,7 @@ impl InstructionBuilder for RaydiumLaunchpadInstructionBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl RaydiumLaunchpadInstructionBuilder {
|
||||
impl BonkInstructionBuilder {
|
||||
/// 使用提供的账户信息构建买入指令
|
||||
async fn build_buy_instructions_with_accounts(
|
||||
&self,
|
||||
@@ -42,8 +42,8 @@ impl RaydiumLaunchpadInstructionBuilder {
|
||||
let protocol_params = params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
.downcast_ref::<RaydiumLaunchpadParams>()
|
||||
.ok_or_else(|| anyhow!("Invalid protocol params for RaydiumLaunchpad"))?;
|
||||
.downcast_ref::<BonkParams>()
|
||||
.ok_or_else(|| anyhow!("Invalid protocol params for Bonk"))?;
|
||||
|
||||
let pool_state = get_pool_pda(¶ms.mint, &accounts::WSOL_TOKEN_ACCOUNT).unwrap();
|
||||
|
||||
@@ -149,7 +149,7 @@ impl RaydiumLaunchpadInstructionBuilder {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Base Token Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Quote Token Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::EVENT_AUTHORITY, false), // Event Authority (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::LAUNCHPAD_PROGRAM, false), // Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::BONK, false), // Program (readonly)
|
||||
];
|
||||
// 创建指令数据
|
||||
let mut data = vec![];
|
||||
@@ -159,7 +159,7 @@ impl RaydiumLaunchpadInstructionBuilder {
|
||||
data.extend_from_slice(&share_fee_rate.to_le_bytes());
|
||||
|
||||
instructions.push(Instruction {
|
||||
program_id: accounts::LAUNCHPAD_PROGRAM,
|
||||
program_id: accounts::BONK,
|
||||
accounts,
|
||||
data,
|
||||
});
|
||||
@@ -263,7 +263,7 @@ impl RaydiumLaunchpadInstructionBuilder {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Base Token Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Quote Token Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::EVENT_AUTHORITY, false), // Event Authority (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::LAUNCHPAD_PROGRAM, false), // Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::BONK, false), // Program (readonly)
|
||||
];
|
||||
|
||||
// 创建指令数据
|
||||
@@ -274,7 +274,7 @@ impl RaydiumLaunchpadInstructionBuilder {
|
||||
data.extend_from_slice(&share_fee_rate.to_le_bytes());
|
||||
|
||||
instructions.push(Instruction {
|
||||
program_id: accounts::LAUNCHPAD_PROGRAM,
|
||||
program_id: accounts::BONK,
|
||||
accounts,
|
||||
data,
|
||||
});
|
||||
@@ -1,3 +1,3 @@
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod raydium_launchpad;
|
||||
pub mod bonk;
|
||||
Reference in New Issue
Block a user