mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-16 18:38:05 +00:00
feat: enhance protocol event parsers and bump to v0.3.5
- Add creator_fee support to Bonk events - Improve PumpFun/PumpSwap event parsing - Update documentation and common types
This commit is contained in:
@@ -3,7 +3,9 @@ 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::{GlobalConfig, PlatformConfig, PoolState};
|
||||
use crate::streaming::event_parser::protocols::bonk::{
|
||||
AmmFeeOn, GlobalConfig, PlatformConfig, PoolState,
|
||||
};
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -25,9 +27,11 @@ pub struct BonkTradeEvent {
|
||||
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)]
|
||||
@@ -58,6 +62,15 @@ pub struct BonkTradeEvent {
|
||||
pub is_bot: bool,
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -73,9 +86,11 @@ impl_unified_event!(
|
||||
amount_out,
|
||||
protocol_fee,
|
||||
platform_fee,
|
||||
creator_fee,
|
||||
share_fee,
|
||||
trade_direction,
|
||||
pool_status
|
||||
pool_status,
|
||||
exact_in
|
||||
);
|
||||
|
||||
/// Create pool event
|
||||
@@ -89,6 +104,7 @@ pub struct BonkPoolCreateEvent {
|
||||
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)]
|
||||
@@ -105,6 +121,15 @@ pub struct BonkPoolCreateEvent {
|
||||
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,
|
||||
@@ -113,7 +138,8 @@ impl_unified_event!(
|
||||
config,
|
||||
base_mint_param,
|
||||
curve_param,
|
||||
vesting_param
|
||||
vesting_param,
|
||||
amm_fee_on
|
||||
);
|
||||
|
||||
/// Create pool event
|
||||
@@ -287,6 +313,7 @@ pub mod discriminators {
|
||||
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];
|
||||
|
||||
|
||||
@@ -8,9 +8,7 @@ use crate::streaming::event_parser::{
|
||||
common::{utils::*, EventMetadata, EventType, ProtocolType},
|
||||
core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent},
|
||||
protocols::bonk::{
|
||||
discriminators, BonkMigrateToAmmEvent, BonkMigrateToCpswapEvent, BonkPoolCreateEvent,
|
||||
BonkTradeEvent, ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams,
|
||||
TradeDirection, VestingParams,
|
||||
bonk_pool_create_event_log_decode, bonk_trade_event_log_decode, discriminators, AmmFeeOn, BonkMigrateToAmmEvent, BonkMigrateToCpswapEvent, BonkPoolCreateEvent, BonkTradeEvent, ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams, TradeDirection, VestingParams
|
||||
},
|
||||
};
|
||||
|
||||
@@ -78,6 +76,15 @@ impl BonkEventParser {
|
||||
inner_instruction_parser: Some(Self::parse_pool_create_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_initialize_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
protocol_type: ProtocolType::Bonk,
|
||||
inner_instruction_discriminator: discriminators::POOL_CREATE_EVENT,
|
||||
instruction_discriminator: discriminators::INITIALIZE_V2,
|
||||
event_type: EventType::BonkInitializeV2,
|
||||
inner_instruction_parser: Some(Self::parse_pool_create_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_initialize_v2_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
protocol_type: ProtocolType::Bonk,
|
||||
@@ -108,7 +115,7 @@ impl BonkEventParser {
|
||||
data: &[u8],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Ok(event) = borsh::from_slice::<BonkPoolCreateEvent>(data) {
|
||||
if let Some(event) = bonk_pool_create_event_log_decode(data) {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(metadata.signature.to_string());
|
||||
Some(Box::new(BonkPoolCreateEvent { metadata, ..event }))
|
||||
@@ -122,7 +129,7 @@ impl BonkEventParser {
|
||||
data: &[u8],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Ok(event) = borsh::from_slice::<BonkTradeEvent>(data) {
|
||||
if let Some(event) = bonk_trade_event_log_decode(data) {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}", metadata.signature, event.pool_state));
|
||||
if metadata.event_type == EventType::BonkBuyExactIn
|
||||
@@ -324,6 +331,48 @@ impl BonkEventParser {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Parse initialize event
|
||||
fn parse_initialize_v2_instruction(
|
||||
data: &[u8],
|
||||
accounts: &[Pubkey],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if data.len() < 24 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut offset = 0;
|
||||
let base_mint_param = Self::parse_mint_params(data, &mut offset)?;
|
||||
let curve_param = Self::parse_curve_params(data, &mut offset)?;
|
||||
let vesting_param = Self::parse_vesting_params(data, &mut offset)?;
|
||||
let amm_fee_on = data[offset];
|
||||
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(metadata.signature.to_string());
|
||||
|
||||
Some(Box::new(BonkPoolCreateEvent {
|
||||
metadata,
|
||||
payer: accounts[0],
|
||||
creator: accounts[1],
|
||||
global_config: accounts[2],
|
||||
platform_config: accounts[3],
|
||||
pool_state: accounts[5],
|
||||
base_mint: accounts[6],
|
||||
quote_mint: accounts[7],
|
||||
base_vault: accounts[8],
|
||||
quote_vault: accounts[9],
|
||||
base_mint_param,
|
||||
curve_param,
|
||||
vesting_param,
|
||||
amm_fee_on: if amm_fee_on == 0 {
|
||||
Some(AmmFeeOn::QuoteToken)
|
||||
} else {
|
||||
Some(AmmFeeOn::BothToken)
|
||||
},
|
||||
..Default::default()
|
||||
}))
|
||||
}
|
||||
|
||||
/// Parse MintParams structure
|
||||
fn parse_mint_params(data: &[u8], offset: &mut usize) -> Option<MintParams> {
|
||||
// Read decimals (1 byte)
|
||||
|
||||
@@ -5,7 +5,9 @@ use solana_sdk::pubkey::Pubkey;
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata,
|
||||
protocols::bonk::{BonkGlobalConfigAccountEvent, BonkPlatformConfigAccountEvent, BonkPoolStateAccountEvent},
|
||||
protocols::bonk::{
|
||||
BonkGlobalConfigAccountEvent, BonkPlatformConfigAccountEvent, BonkPoolStateAccountEvent,
|
||||
},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
@@ -41,6 +43,13 @@ pub struct VestingParams {
|
||||
pub unlock_period: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub enum AmmFeeOn {
|
||||
#[default]
|
||||
QuoteToken,
|
||||
BothToken,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct ConstantCurve {
|
||||
pub supply: u64,
|
||||
|
||||
Reference in New Issue
Block a user