events optimization

This commit is contained in:
wood
2025-08-03 05:37:04 +08:00
parent 2cbab93346
commit 4c90931e28
17 changed files with 1311 additions and 212 deletions
@@ -20,6 +20,12 @@ pub struct BonkEventParser {
inner: GenericEventParser,
}
impl Default for BonkEventParser {
fn default() -> Self {
Self::new()
}
}
impl BonkEventParser {
pub fn new() -> Self {
// 配置所有事件类型
@@ -73,9 +79,9 @@ impl BonkEventParser {
) -> Option<Box<dyn UnifiedEvent>> {
if let Ok(event) = borsh::from_slice::<BonkPoolCreateEvent>(data) {
let mut metadata = metadata;
metadata.set_id(format!("{}", metadata.signature,));
metadata.set_id(metadata.signature.to_string());
Some(Box::new(BonkPoolCreateEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -93,7 +99,7 @@ impl BonkEventParser {
metadata.set_id(format!(
"{}-{}",
metadata.signature,
event.pool_state.to_string()
event.pool_state
));
if metadata.event_type == EventType::BonkBuyExactIn
|| metadata.event_type == EventType::BonkBuyExactOut
@@ -101,15 +107,13 @@ impl BonkEventParser {
if event.trade_direction != TradeDirection::Buy {
return None;
}
} else if metadata.event_type == EventType::BonkSellExactIn
|| metadata.event_type == EventType::BonkSellExactOut
{
if event.trade_direction != TradeDirection::Sell {
} else if (metadata.event_type == EventType::BonkSellExactIn
|| metadata.event_type == EventType::BonkSellExactOut)
&& event.trade_direction != TradeDirection::Sell {
return None;
}
}
Some(Box::new(BonkTradeEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -270,7 +274,7 @@ impl BonkEventParser {
let vesting_param = Self::parse_vesting_params(data, &mut offset)?;
let mut metadata = metadata;
metadata.set_id(format!("{}", metadata.signature));
metadata.set_id(metadata.signature.to_string());
Some(Box::new(BonkPoolCreateEvent {
metadata,
@@ -17,6 +17,12 @@ pub struct PumpFunEventParser {
inner: GenericEventParser,
}
impl Default for PumpFunEventParser {
fn default() -> Self {
Self::new()
}
}
impl PumpFunEventParser {
pub fn new() -> Self {
// 配置所有事件类型
@@ -61,10 +67,10 @@ impl PumpFunEventParser {
metadata.signature,
event.name,
event.symbol,
event.mint.to_string()
event.mint
));
Some(Box::new(PumpFunCreateTokenEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -82,12 +88,12 @@ impl PumpFunEventParser {
metadata.set_id(format!(
"{}-{}-{}-{}",
metadata.signature,
event.mint.to_string(),
event.user.to_string(),
event.is_buy.to_string()
event.mint,
event.user,
event.is_buy
));
Some(Box::new(PumpFunTradeEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -129,7 +135,7 @@ impl PumpFunEventParser {
metadata.signature,
name,
symbol,
accounts[0].to_string()
accounts[0]
));
Some(Box::new(PumpFunCreateTokenEvent {
@@ -162,9 +168,9 @@ impl PumpFunEventParser {
metadata.set_id(format!(
"{}-{}-{}-{}",
metadata.signature,
accounts[2].to_string(),
accounts[6].to_string(),
true.to_string()
accounts[2],
accounts[6],
true
));
Some(Box::new(PumpFunTradeEvent {
metadata,
@@ -199,9 +205,9 @@ impl PumpFunEventParser {
metadata.set_id(format!(
"{}-{}-{}-{}",
metadata.signature,
accounts[2].to_string(),
accounts[6].to_string(),
false.to_string()
accounts[2],
accounts[6],
false
));
Some(Box::new(PumpFunTradeEvent {
metadata,
@@ -267,6 +273,6 @@ impl EventParser for PumpFunEventParser {
}
fn supported_program_ids(&self) -> Vec<Pubkey> {
self.inner.supported_program_ids()
vec![PUMPFUN_PROGRAM_ID]
}
}
@@ -20,6 +20,12 @@ pub struct PumpSwapEventParser {
inner: GenericEventParser,
}
impl Default for PumpSwapEventParser {
fn default() -> Self {
Self::new()
}
}
impl PumpSwapEventParser {
pub fn new() -> Self {
// 配置所有事件类型
@@ -78,7 +84,7 @@ impl PumpSwapEventParser {
metadata.signature, event.user, event.pool, event.base_amount_out
));
Some(Box::new(PumpSwapBuyEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -98,7 +104,7 @@ impl PumpSwapEventParser {
metadata.signature, event.user, event.pool, event.base_amount_in
));
Some(Box::new(PumpSwapSellEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -118,7 +124,7 @@ impl PumpSwapEventParser {
metadata.signature, event.pool, event.creator, event.base_amount_in
));
Some(Box::new(PumpSwapCreatePoolEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -138,7 +144,7 @@ impl PumpSwapEventParser {
metadata.signature, event.pool, event.user, event.lp_token_amount_out
));
Some(Box::new(PumpSwapDepositEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -158,7 +164,7 @@ impl PumpSwapEventParser {
metadata.signature, event.pool, event.user, event.lp_token_amount_in
));
Some(Box::new(PumpSwapWithdrawEvent {
metadata: metadata,
metadata,
..event
}))
} else {
@@ -413,6 +419,6 @@ impl EventParser for PumpSwapEventParser {
}
fn supported_program_ids(&self) -> Vec<Pubkey> {
self.inner.supported_program_ids()
vec![PUMPSWAP_PROGRAM_ID]
}
}
@@ -17,6 +17,12 @@ pub struct RaydiumClmmEventParser {
inner: GenericEventParser,
}
impl Default for RaydiumClmmEventParser {
fn default() -> Self {
Self::new()
}
}
impl RaydiumClmmEventParser {
pub fn new() -> Self {
// 配置所有事件类型
@@ -89,7 +95,6 @@ impl RaydiumClmmEventParser {
token_program: accounts[8],
tick_array: accounts[9],
remaining_accounts: accounts[10..].to_vec(),
..Default::default()
}))
}
@@ -133,7 +138,6 @@ impl RaydiumClmmEventParser {
input_vault_mint: accounts[11],
output_vault_mint: accounts[12],
remaining_accounts: accounts[13..].to_vec(),
..Default::default()
}))
}
}
@@ -17,6 +17,12 @@ pub struct RaydiumCpmmEventParser {
inner: GenericEventParser,
}
impl Default for RaydiumCpmmEventParser {
fn default() -> Self {
Self::new()
}
}
impl RaydiumCpmmEventParser {
pub fn new() -> Self {
// 配置所有事件类型