mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-12 16:38:04 +00:00
feat: Add Raydium AMM V4 support and enhance protocol parsers
- Add complete Raydium AMM V4 protocol integration - Enhance PumpFun, CLMM, CPMM event parsing - Refactor parser architecture for better extensibility - Update documentation and examples
This commit is contained in:
@@ -104,14 +104,84 @@ impl_unified_event!(
|
||||
creator_fee
|
||||
);
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpFunMigrateEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
|
||||
pub user: Pubkey,
|
||||
pub mint: Pubkey,
|
||||
pub mint_amount: u64,
|
||||
pub sol_amount: u64,
|
||||
pub pool_migration_fee: u64,
|
||||
pub bonding_curve: Pubkey,
|
||||
pub timestamp: i64,
|
||||
pub pool: Pubkey,
|
||||
|
||||
#[borsh(skip)]
|
||||
pub global: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub withdraw_authority: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub associated_bonding_curve: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub system_program: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub token_program: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pump_amm: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pool_authority: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pool_authority_mint_account: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pool_authority_wsol_account: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub amm_global_config: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub wsol_mint: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub lp_mint: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub user_pool_token_account: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pool_base_token_account: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pool_quote_token_account: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub token_2022_program: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub associated_token_program: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub pump_amm_event_authority: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub event_authority: Pubkey,
|
||||
#[borsh(skip)]
|
||||
pub program: Pubkey,
|
||||
}
|
||||
|
||||
impl_unified_event!(
|
||||
PumpFunMigrateEvent,
|
||||
user,
|
||||
mint,
|
||||
mint_amount,
|
||||
sol_amount,
|
||||
pool_migration_fee,
|
||||
bonding_curve,
|
||||
timestamp,
|
||||
pool
|
||||
);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 事件鉴别器
|
||||
pub const CREATE_TOKEN_EVENT: &str = "0xe445a52e51cb9a1d1b72a94ddeeb6376";
|
||||
pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee";
|
||||
pub const COMPLETE_PUMP_AMM_MIGRATION_EVENT: &str = "0xe445a52e51cb9a1dbde95db95c94ea94";
|
||||
|
||||
// 指令鉴别器
|
||||
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];
|
||||
pub const MIGRATE_IX: &[u8] = &[155, 234, 231, 146, 236, 158, 162, 30];
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ use solana_transaction_status::UiCompiledInstruction;
|
||||
use crate::streaming::event_parser::{
|
||||
common::{EventMetadata, EventType, ProtocolType},
|
||||
core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent},
|
||||
protocols::pumpfun::{discriminators, PumpFunCreateTokenEvent, PumpFunTradeEvent},
|
||||
protocols::pumpfun::{
|
||||
discriminators, PumpFunCreateTokenEvent, PumpFunMigrateEvent, PumpFunTradeEvent,
|
||||
},
|
||||
};
|
||||
|
||||
/// PumpFun程序ID
|
||||
@@ -56,6 +58,15 @@ impl PumpFunEventParser {
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_instruction,
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPFUN_PROGRAM_ID,
|
||||
protocol_type: ProtocolType::PumpFun,
|
||||
inner_instruction_discriminator: discriminators::COMPLETE_PUMP_AMM_MIGRATION_EVENT,
|
||||
instruction_discriminator: discriminators::MIGRATE_IX,
|
||||
event_type: EventType::PumpFunMigrate,
|
||||
inner_instruction_parser: Self::parse_migrate_inner_instruction,
|
||||
instruction_parser: Self::parse_migrate_instruction,
|
||||
},
|
||||
];
|
||||
|
||||
let inner = GenericEventParser::new(vec![PUMPFUN_PROGRAM_ID], configs);
|
||||
@@ -63,6 +74,20 @@ impl PumpFunEventParser {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
/// 解析迁移事件
|
||||
fn parse_migrate_inner_instruction(
|
||||
data: &[u8],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Ok(event) = borsh::from_slice::<PumpFunMigrateEvent>(data) {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}-{}", metadata.signature, event.user, event.mint));
|
||||
Some(Box::new(PumpFunMigrateEvent { metadata, ..event }))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// 解析创建代币日志事件
|
||||
fn parse_create_token_inner_instruction(
|
||||
data: &[u8],
|
||||
@@ -72,15 +97,9 @@ impl PumpFunEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!(
|
||||
"{}-{}-{}-{}",
|
||||
metadata.signature,
|
||||
event.name,
|
||||
event.symbol,
|
||||
event.mint
|
||||
metadata.signature, event.name, event.symbol, event.mint
|
||||
));
|
||||
Some(Box::new(PumpFunCreateTokenEvent {
|
||||
metadata,
|
||||
..event
|
||||
}))
|
||||
Some(Box::new(PumpFunCreateTokenEvent { metadata, ..event }))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -95,15 +114,9 @@ impl PumpFunEventParser {
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!(
|
||||
"{}-{}-{}-{}",
|
||||
metadata.signature,
|
||||
event.mint,
|
||||
event.user,
|
||||
event.is_buy
|
||||
metadata.signature, event.mint, event.user, event.is_buy
|
||||
));
|
||||
Some(Box::new(PumpFunTradeEvent {
|
||||
metadata,
|
||||
..event
|
||||
}))
|
||||
Some(Box::new(PumpFunTradeEvent { metadata, ..event }))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -138,13 +151,7 @@ impl PumpFunEventParser {
|
||||
};
|
||||
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!(
|
||||
"{}-{}-{}-{}",
|
||||
metadata.signature,
|
||||
name,
|
||||
symbol,
|
||||
accounts[0]
|
||||
));
|
||||
metadata.set_id(format!("{}-{}-{}-{}", metadata.signature, name, symbol, accounts[0]));
|
||||
|
||||
Some(Box::new(PumpFunCreateTokenEvent {
|
||||
metadata,
|
||||
@@ -173,13 +180,7 @@ impl PumpFunEventParser {
|
||||
let amount = u64::from_le_bytes(data[0..8].try_into().unwrap());
|
||||
let max_sol_cost = u64::from_le_bytes(data[8..16].try_into().unwrap());
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!(
|
||||
"{}-{}-{}-{}",
|
||||
metadata.signature,
|
||||
accounts[2],
|
||||
accounts[6],
|
||||
true
|
||||
));
|
||||
metadata.set_id(format!("{}-{}-{}-{}", metadata.signature, accounts[2], accounts[6], true));
|
||||
Some(Box::new(PumpFunTradeEvent {
|
||||
metadata,
|
||||
fee_recipient: accounts[1],
|
||||
@@ -210,13 +211,8 @@ impl PumpFunEventParser {
|
||||
let amount = u64::from_le_bytes(data[0..8].try_into().unwrap());
|
||||
let min_sol_output = u64::from_le_bytes(data[8..16].try_into().unwrap());
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!(
|
||||
"{}-{}-{}-{}",
|
||||
metadata.signature,
|
||||
accounts[2],
|
||||
accounts[6],
|
||||
false
|
||||
));
|
||||
metadata
|
||||
.set_id(format!("{}-{}-{}-{}", metadata.signature, accounts[2], accounts[6], false));
|
||||
Some(Box::new(PumpFunTradeEvent {
|
||||
metadata,
|
||||
fee_recipient: accounts[1],
|
||||
@@ -232,6 +228,47 @@ impl PumpFunEventParser {
|
||||
..Default::default()
|
||||
}))
|
||||
}
|
||||
|
||||
/// 解析迁移指令事件
|
||||
fn parse_migrate_instruction(
|
||||
_data: &[u8],
|
||||
accounts: &[Pubkey],
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if accounts.len() < 24 {
|
||||
return None;
|
||||
}
|
||||
let mut metadata = metadata;
|
||||
metadata.set_id(format!("{}-{}-{}", metadata.signature, accounts[5], accounts[2]));
|
||||
Some(Box::new(PumpFunMigrateEvent {
|
||||
metadata,
|
||||
global: accounts[0],
|
||||
withdraw_authority: accounts[1],
|
||||
mint: accounts[2],
|
||||
bonding_curve: accounts[3],
|
||||
associated_bonding_curve: accounts[4],
|
||||
user: accounts[5],
|
||||
system_program: accounts[6],
|
||||
token_program: accounts[7],
|
||||
pump_amm: accounts[8],
|
||||
pool: accounts[9],
|
||||
pool_authority: accounts[10],
|
||||
pool_authority_mint_account: accounts[11],
|
||||
pool_authority_wsol_account: accounts[12],
|
||||
amm_global_config: accounts[13],
|
||||
wsol_mint: accounts[14],
|
||||
lp_mint: accounts[15],
|
||||
user_pool_token_account: accounts[16],
|
||||
pool_base_token_account: accounts[17],
|
||||
pool_quote_token_account: accounts[18],
|
||||
token_2022_program: accounts[19],
|
||||
associated_token_program: accounts[20],
|
||||
pump_amm_event_authority: accounts[21],
|
||||
event_authority: accounts[22],
|
||||
program: accounts[23],
|
||||
..Default::default()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
||||
Reference in New Issue
Block a user