mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-16 18:38:05 +00:00
- Updated BonkTradeEvent struct with new fields: global_config, platform_config, system_program, platform_associated_account, and creator_associated_account - Modified account parsing logic in parser to support the new account fields - Updated account count check from 11 to 18 to accommodate the new protocol structure - Bumped version from 0.3.8 to 0.3.9
335 lines
9.6 KiB
Rust
Executable File
335 lines
9.6 KiB
Rust
Executable File
use crate::impl_unified_event;
|
|
use crate::streaming::event_parser::common::EventMetadata;
|
|
use crate::streaming::event_parser::protocols::bonk::types::{
|
|
CurveParams, MintParams, PoolStatus, TradeDirection, VestingParams,
|
|
};
|
|
use crate::streaming::event_parser::protocols::bonk::{
|
|
AmmFeeOn, GlobalConfig, PlatformConfig, PoolState,
|
|
};
|
|
use borsh::BorshDeserialize;
|
|
use serde::{Deserialize, Serialize};
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
/// Trade event
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
|
pub struct BonkTradeEvent {
|
|
#[borsh(skip)]
|
|
pub metadata: EventMetadata,
|
|
pub pool_state: Pubkey,
|
|
pub total_base_sell: u64,
|
|
pub virtual_base: u64,
|
|
pub virtual_quote: u64,
|
|
pub real_base_before: u64,
|
|
pub real_quote_before: u64,
|
|
pub real_base_after: u64,
|
|
pub real_quote_after: u64,
|
|
pub amount_in: u64,
|
|
pub amount_out: u64,
|
|
pub protocol_fee: u64,
|
|
pub platform_fee: u64,
|
|
pub creator_fee: u64,
|
|
pub share_fee: u64,
|
|
pub trade_direction: TradeDirection,
|
|
pub pool_status: PoolStatus,
|
|
pub exact_in: bool,
|
|
#[borsh(skip)]
|
|
pub minimum_amount_out: u64,
|
|
#[borsh(skip)]
|
|
pub maximum_amount_in: u64,
|
|
#[borsh(skip)]
|
|
pub share_fee_rate: u64,
|
|
#[borsh(skip)]
|
|
pub payer: Pubkey,
|
|
#[borsh(skip)]
|
|
pub global_config: Pubkey,
|
|
#[borsh(skip)]
|
|
pub platform_config: Pubkey,
|
|
#[borsh(skip)]
|
|
pub user_base_token: Pubkey,
|
|
#[borsh(skip)]
|
|
pub user_quote_token: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_token_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_token_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_token_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_token_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub is_dev_create_token_trade: bool,
|
|
#[borsh(skip)]
|
|
pub is_bot: bool,
|
|
#[borsh(skip)]
|
|
pub system_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub platform_associated_account: Pubkey,
|
|
#[borsh(skip)]
|
|
pub creator_associated_account: Pubkey,
|
|
}
|
|
|
|
pub const BONK_TRADE_EVENT_LOG_SIZE: usize = 32 + 8 * 13 + 1 + 1 + 1;
|
|
|
|
pub fn bonk_trade_event_log_decode(data: &[u8]) -> Option<BonkTradeEvent> {
|
|
if data.len() < BONK_TRADE_EVENT_LOG_SIZE {
|
|
return None;
|
|
}
|
|
borsh::from_slice::<BonkTradeEvent>(&data[..BONK_TRADE_EVENT_LOG_SIZE]).ok()
|
|
}
|
|
|
|
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
|
|
impl_unified_event!(
|
|
BonkTradeEvent,
|
|
pool_state,
|
|
total_base_sell,
|
|
virtual_base,
|
|
virtual_quote,
|
|
real_base_before,
|
|
real_quote_before,
|
|
real_base_after,
|
|
real_quote_after,
|
|
amount_in,
|
|
amount_out,
|
|
protocol_fee,
|
|
platform_fee,
|
|
creator_fee,
|
|
share_fee,
|
|
trade_direction,
|
|
pool_status,
|
|
exact_in
|
|
);
|
|
|
|
/// Create pool event
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
|
pub struct BonkPoolCreateEvent {
|
|
#[borsh(skip)]
|
|
pub metadata: EventMetadata,
|
|
pub pool_state: Pubkey,
|
|
pub creator: Pubkey,
|
|
pub config: Pubkey,
|
|
pub base_mint_param: MintParams,
|
|
pub curve_param: CurveParams,
|
|
pub vesting_param: VestingParams,
|
|
pub amm_fee_on: Option<AmmFeeOn>,
|
|
#[borsh(skip)]
|
|
pub payer: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub global_config: Pubkey,
|
|
#[borsh(skip)]
|
|
pub platform_config: Pubkey,
|
|
}
|
|
|
|
pub const BONK_POOL_CREATE_EVENT_LOG_SIZE: usize = 256;
|
|
|
|
pub fn bonk_pool_create_event_log_decode(data: &[u8]) -> Option<BonkPoolCreateEvent> {
|
|
if data.len() < BONK_POOL_CREATE_EVENT_LOG_SIZE {
|
|
return None;
|
|
}
|
|
borsh::from_slice::<BonkPoolCreateEvent>(&data[..BONK_POOL_CREATE_EVENT_LOG_SIZE]).ok()
|
|
}
|
|
|
|
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
|
|
impl_unified_event!(
|
|
BonkPoolCreateEvent,
|
|
pool_state,
|
|
creator,
|
|
config,
|
|
base_mint_param,
|
|
curve_param,
|
|
vesting_param,
|
|
amm_fee_on
|
|
);
|
|
|
|
/// Create pool event
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
|
pub struct BonkMigrateToAmmEvent {
|
|
#[borsh(skip)]
|
|
pub metadata: EventMetadata,
|
|
pub base_lot_size: u64,
|
|
pub quote_lot_size: u64,
|
|
pub market_vault_signer_nonce: u8,
|
|
#[borsh(skip)]
|
|
pub payer: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub openbook_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub market: Pubkey,
|
|
#[borsh(skip)]
|
|
pub request_queue: Pubkey,
|
|
#[borsh(skip)]
|
|
pub event_queue: Pubkey,
|
|
#[borsh(skip)]
|
|
pub bids: Pubkey,
|
|
#[borsh(skip)]
|
|
pub asks: Pubkey,
|
|
#[borsh(skip)]
|
|
pub market_vault_signer: Pubkey,
|
|
#[borsh(skip)]
|
|
pub market_base_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub market_quote_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_pool: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_authority: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_open_orders: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_lp_mint: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_base_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_quote_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_target_orders: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_config: Pubkey,
|
|
#[borsh(skip)]
|
|
pub amm_create_fee_destination: Pubkey,
|
|
#[borsh(skip)]
|
|
pub authority: Pubkey,
|
|
#[borsh(skip)]
|
|
pub pool_state: Pubkey,
|
|
#[borsh(skip)]
|
|
pub global_config: Pubkey,
|
|
#[borsh(skip)]
|
|
pub base_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub quote_vault: Pubkey,
|
|
#[borsh(skip)]
|
|
pub pool_lp_token: Pubkey,
|
|
#[borsh(skip)]
|
|
pub spl_token_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub associated_token_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub system_program: Pubkey,
|
|
#[borsh(skip)]
|
|
pub rent_program: Pubkey,
|
|
}
|
|
|
|
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
|
|
impl_unified_event!(
|
|
BonkMigrateToAmmEvent,
|
|
base_lot_size,
|
|
quote_lot_size,
|
|
market_vault_signer_nonce
|
|
);
|
|
|
|
// Migrate to CP Swap event
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
|
pub struct BonkMigrateToCpswapEvent {
|
|
pub metadata: EventMetadata,
|
|
pub payer: Pubkey,
|
|
pub base_mint: Pubkey,
|
|
pub quote_mint: Pubkey,
|
|
pub platform_config: Pubkey,
|
|
pub cpswap_program: Pubkey,
|
|
pub cpswap_pool: Pubkey,
|
|
pub cpswap_authority: Pubkey,
|
|
pub cpswap_lp_mint: Pubkey,
|
|
pub cpswap_base_vault: Pubkey,
|
|
pub cpswap_quote_vault: Pubkey,
|
|
pub cpswap_config: Pubkey,
|
|
pub cpswap_create_pool_fee: Pubkey,
|
|
pub cpswap_observation: Pubkey,
|
|
pub lock_program: Pubkey,
|
|
pub lock_authority: Pubkey,
|
|
pub lock_lp_vault: Pubkey,
|
|
pub authority: Pubkey,
|
|
pub pool_state: Pubkey,
|
|
pub global_config: Pubkey,
|
|
pub base_vault: Pubkey,
|
|
pub quote_vault: Pubkey,
|
|
pub pool_lp_token: Pubkey,
|
|
pub base_token_program: Pubkey,
|
|
pub quote_token_program: Pubkey,
|
|
pub associated_token_program: Pubkey,
|
|
pub system_program: Pubkey,
|
|
pub rent_program: Pubkey,
|
|
pub metadata_program: Pubkey,
|
|
pub remaining_accounts: Vec<Pubkey>,
|
|
}
|
|
|
|
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
|
|
impl_unified_event!(BonkMigrateToCpswapEvent,);
|
|
|
|
/// 池状态
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct BonkPoolStateAccountEvent {
|
|
pub metadata: EventMetadata,
|
|
pub pubkey: String,
|
|
pub executable: bool,
|
|
pub lamports: u64,
|
|
pub owner: String,
|
|
pub rent_epoch: u64,
|
|
pub pool_state: PoolState,
|
|
}
|
|
impl_unified_event!(BonkPoolStateAccountEvent,);
|
|
|
|
/// 全局配置
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct BonkGlobalConfigAccountEvent {
|
|
pub metadata: EventMetadata,
|
|
pub pubkey: String,
|
|
pub executable: bool,
|
|
pub lamports: u64,
|
|
pub owner: String,
|
|
pub rent_epoch: u64,
|
|
pub global_config: GlobalConfig,
|
|
}
|
|
impl_unified_event!(BonkGlobalConfigAccountEvent,);
|
|
|
|
/// 平台配置
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct BonkPlatformConfigAccountEvent {
|
|
pub metadata: EventMetadata,
|
|
pub pubkey: String,
|
|
pub executable: bool,
|
|
pub lamports: u64,
|
|
pub owner: String,
|
|
pub rent_epoch: u64,
|
|
pub platform_config: PlatformConfig,
|
|
}
|
|
impl_unified_event!(BonkPlatformConfigAccountEvent,);
|
|
|
|
/// Event discriminator constants
|
|
pub mod discriminators {
|
|
// Event discriminators
|
|
pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee";
|
|
pub const POOL_CREATE_EVENT: &str = "0xe445a52e51cb9a1d97d7e20976a173ae";
|
|
|
|
// Instruction discriminators
|
|
pub const BUY_EXACT_IN: &[u8] = &[250, 234, 13, 123, 213, 156, 19, 236];
|
|
pub const BUY_EXACT_OUT: &[u8] = &[24, 211, 116, 40, 105, 3, 153, 56];
|
|
pub const SELL_EXACT_IN: &[u8] = &[149, 39, 222, 155, 211, 124, 152, 26];
|
|
pub const SELL_EXACT_OUT: &[u8] = &[95, 200, 71, 34, 8, 9, 11, 166];
|
|
pub const INITIALIZE: &[u8] = &[175, 175, 109, 31, 13, 152, 155, 237];
|
|
pub const INITIALIZE_V2: &[u8] = &[67, 153, 175, 39, 218, 16, 38, 32];
|
|
pub const MIGRATE_TO_AMM: &[u8] = &[207, 82, 192, 145, 254, 207, 145, 223];
|
|
pub const MIGRATE_TO_CP_SWAP: &[u8] = &[136, 92, 200, 103, 28, 218, 144, 140];
|
|
|
|
// 账户鉴别器
|
|
pub const POOL_STATE_ACCOUNT: &[u8] = &[247, 237, 227, 245, 215, 195, 222, 70];
|
|
pub const GLOBAL_CONFIG_ACCOUNT: &[u8] = &[149, 8, 156, 202, 160, 252, 176, 217];
|
|
pub const PLATFORM_CONFIG_ACCOUNT: &[u8] = &[160, 78, 128, 0, 248, 83, 230, 160];
|
|
}
|