Major changes: - Refactor event parsing system: migrate scattered logs_* modules to unified event_parser architecture - Add unified UnifiedEvent trait and EventParser trait for standardized event parsing interface - Introduce GenericEventParser and EventParserFactory for plugin-style protocol extension - Add match_event! macro to simplify event type matching and handling - Add Raydium Launchpad (Bonk.fun) protocol support: - Complete buy/sell trading functionality - Pool state management and querying - Event parsing and subscription - Update trading system to support new protocol architecture - Refactor constants organization, rename raydium to raydium_launchpad - Update documentation and example code Technical improvements: - Unified event interface design for better code maintainability - Factory pattern implementation for dynamic protocol loading - Generic event parser to reduce code duplication - Improved error handling and type safety Breaking Changes: - Remove old logs_* modules, use new event_parser system - Protocol constants path change: raydium -> raydium_launchpad - Event subscription API updated to unified interface
114 lines
2.9 KiB
Rust
114 lines
2.9 KiB
Rust
use borsh::BorshDeserialize;
|
|
use serde::{Deserialize, Serialize};
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
use crate::event_parser::{common::EventMetadata, core::traits::UnifiedEvent};
|
|
use crate::impl_unified_event;
|
|
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
|
pub struct PumpFunCreateTokenEvent {
|
|
#[borsh(skip)]
|
|
pub metadata: EventMetadata,
|
|
pub name: String,
|
|
pub symbol: String,
|
|
pub uri: String,
|
|
pub mint: Pubkey,
|
|
pub bonding_curve: Pubkey,
|
|
pub user: Pubkey,
|
|
pub creator: Pubkey,
|
|
pub timestamp: i64,
|
|
pub virtual_token_reserves: u64,
|
|
pub virtual_sol_reserves: u64,
|
|
pub real_token_reserves: u64,
|
|
pub token_total_supply: u64,
|
|
#[borsh(skip)]
|
|
pub mint_authority: Pubkey,
|
|
#[borsh(skip)]
|
|
pub associated_bonding_curve: Pubkey,
|
|
}
|
|
|
|
impl_unified_event!(
|
|
PumpFunCreateTokenEvent,
|
|
mint,
|
|
bonding_curve,
|
|
user,
|
|
creator,
|
|
timestamp,
|
|
virtual_token_reserves,
|
|
virtual_sol_reserves,
|
|
real_token_reserves,
|
|
token_total_supply
|
|
);
|
|
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
|
pub struct PumpFunTradeEvent {
|
|
#[borsh(skip)]
|
|
pub metadata: EventMetadata,
|
|
pub mint: Pubkey,
|
|
pub sol_amount: u64,
|
|
pub token_amount: u64,
|
|
pub is_buy: bool,
|
|
pub user: Pubkey,
|
|
pub timestamp: i64,
|
|
pub virtual_sol_reserves: u64,
|
|
pub virtual_token_reserves: u64,
|
|
pub real_sol_reserves: u64,
|
|
pub real_token_reserves: u64,
|
|
pub fee_recipient: Pubkey,
|
|
pub fee_basis_points: u64,
|
|
pub fee: u64,
|
|
pub creator: Pubkey,
|
|
pub creator_fee_basis_points: u64,
|
|
pub creator_fee: u64,
|
|
#[borsh(skip)]
|
|
pub bonding_curve: Pubkey,
|
|
#[borsh(skip)]
|
|
pub associated_bonding_curve: Pubkey,
|
|
#[borsh(skip)]
|
|
pub associated_user: Pubkey,
|
|
#[borsh(skip)]
|
|
pub creator_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub max_sol_cost: u64,
|
|
#[borsh(skip)]
|
|
pub min_sol_output: u64,
|
|
#[borsh(skip)]
|
|
pub amount: u64,
|
|
#[borsh(skip)]
|
|
pub is_bot: bool,
|
|
#[borsh(skip)]
|
|
pub is_dev_create_token_trade: bool, // 是否是dev创建token的交易
|
|
}
|
|
|
|
impl_unified_event!(
|
|
PumpFunTradeEvent,
|
|
mint,
|
|
sol_amount,
|
|
token_amount,
|
|
is_buy,
|
|
user,
|
|
timestamp,
|
|
virtual_sol_reserves,
|
|
virtual_token_reserves,
|
|
real_sol_reserves,
|
|
real_token_reserves,
|
|
fee_recipient,
|
|
fee_basis_points,
|
|
fee,
|
|
creator,
|
|
creator_fee_basis_points,
|
|
creator_fee
|
|
);
|
|
|
|
/// 事件鉴别器常量
|
|
pub mod discriminators {
|
|
// 事件鉴别器
|
|
pub const CREATE_TOKEN_EVENT: &str = "0xe445a52e51cb9a1d1b72a94ddeeb6376";
|
|
pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee";
|
|
|
|
// 指令鉴别器
|
|
pub const CREATE_TOKEN_IX: &[u8] = &[24, 30, 200, 40, 5, 28, 7, 119];
|
|
pub const BUY_IX: &[u8] = &[102, 6, 61, 18, 1, 218, 235, 234];
|
|
pub const SELL_IX: &[u8] = &[51, 230, 133, 164, 1, 127, 131, 173];
|
|
}
|