Skip to main content

sol_parser_sdk/core/
events.rs

1//! 所有具体的事件类型定义
2//!
3//! 基于您提供的回调事件列表,定义所有需要的具体事件类型
4
5// use prost_types::Timestamp;
6use borsh::BorshDeserialize;
7use serde::{Deserialize, Serialize};
8use solana_sdk::{pubkey::Pubkey, signature::Signature};
9
10/// 基础元数据 - 所有事件共享的字段
11#[derive(Debug, Clone, Serialize, Deserialize, Default)]
12pub struct EventMetadata {
13    pub signature: Signature,
14    pub slot: u64,
15    pub tx_index: u64, // 交易在slot中的索引,参考solana-streamer
16    pub block_time_us: i64,
17    pub grpc_recv_us: i64,
18}
19
20/// Block Meta Event
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct BlockMetaEvent {
23    pub metadata: EventMetadata,
24}
25
26/// Bonk Pool Create Event
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct BonkPoolCreateEvent {
29    pub metadata: EventMetadata,
30    pub base_mint_param: BaseMintParam,
31    pub pool_state: Pubkey,
32    pub creator: Pubkey,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct BaseMintParam {
37    pub symbol: String,
38    pub name: String,
39    pub uri: String,
40    pub decimals: u8,
41}
42
43/// Bonk Trade Event
44#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct BonkTradeEvent {
47    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
48    pub metadata: EventMetadata,
49
50    // === Borsh 序列化字段(从 inner instruction data 读取)===
51    pub pool_state: Pubkey,      // 32 bytes
52    pub user: Pubkey,             // 32 bytes
53    pub amount_in: u64,           // 8 bytes
54    pub amount_out: u64,          // 8 bytes
55    pub is_buy: bool,             // 1 byte
56
57    // === 非 Borsh 字段(派生字段)===
58    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
59    pub trade_direction: TradeDirection,
60    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
61    pub exact_in: bool,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize, Default)]
65pub enum TradeDirection {
66    #[default]
67    Buy,
68    Sell,
69}
70
71/// Bonk Migrate AMM Event
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct BonkMigrateAmmEvent {
74    pub metadata: EventMetadata,
75    pub old_pool: Pubkey,
76    pub new_pool: Pubkey,
77    pub user: Pubkey,
78    pub liquidity_amount: u64,
79}
80
81/// PumpFun Trade Event - 基于官方IDL定义
82///
83/// 字段来源标记:
84/// - [EVENT]: 来自原始IDL事件定义,由程序日志直接解析获得
85/// - [INSTRUCTION]: 来自指令解析,用于补充事件缺失的上下文信息
86#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
87pub struct PumpFunTradeEvent {
88    #[borsh(skip)]
89    pub metadata: EventMetadata,
90
91    // === IDL TradeEvent 事件字段(Borsh 序列化字段,按顺序)===
92    pub mint: Pubkey,
93    pub sol_amount: u64,
94    pub token_amount: u64,
95    pub is_buy: bool,
96    #[borsh(skip)]
97    pub is_created_buy: bool,  // 由外层逻辑设置,不在 Borsh 数据中
98    pub user: Pubkey,
99    pub timestamp: i64,
100    pub virtual_sol_reserves: u64,
101    pub virtual_token_reserves: u64,
102    pub real_sol_reserves: u64,
103    pub real_token_reserves: u64,
104    pub fee_recipient: Pubkey,
105    pub fee_basis_points: u64,
106    pub fee: u64,
107    pub creator: Pubkey,
108    pub creator_fee_basis_points: u64,
109    pub creator_fee: u64,
110    pub track_volume: bool,
111    pub total_unclaimed_tokens: u64,
112    pub total_claimed_tokens: u64,
113    pub current_sol_volume: u64,
114    pub last_update_timestamp: i64,
115    /// Instruction name: "buy" | "sell" | "buy_exact_sol_in"
116    pub ix_name: String,
117    /// Mayhem mode flag (new field from IDL update)
118    pub mayhem_mode: bool,
119    /// Cashback fee basis points (PUMP_CASHBACK_README)
120    pub cashback_fee_basis_points: u64,
121    /// Cashback amount (PUMP_CASHBACK_README)
122    pub cashback: u64,
123    /// 是否返现代币(由 cashback_fee_basis_points > 0 推导,供 sol-trade-sdk 等构造 sell 指令用)
124    #[borsh(skip)]
125    pub is_cashback_coin: bool,
126
127    // === Instruction parameter fields (reserved for future use, DO NOT delete) ===
128    // pub amount: u64,                     // buy/sell.args.amount
129    // pub max_sol_cost: u64,               // buy.args.maxSolCost
130    // pub min_sol_output: u64,             // sell.args.minSolOutput
131
132    // === 指令账户字段 (从指令账户填充,不在 Borsh 数据中) ===
133    // pub global: Pubkey,                  // 0
134    #[borsh(skip)]
135    pub bonding_curve: Pubkey,            // 3
136    #[borsh(skip)]
137    pub associated_bonding_curve: Pubkey, // 4
138    // pub associated_user: Pubkey,         // 5
139    #[borsh(skip)]
140    pub token_program: Pubkey, // sell - 9 / buy - 8
141    #[borsh(skip)]
142    pub creator_vault: Pubkey, // sell - 8 / buy - 9
143}
144
145/// PumpFun Migrate Event
146#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
147pub struct PumpFunMigrateEvent {
148    #[borsh(skip)]
149    pub metadata: EventMetadata,
150    // Borsh 序列化字段(按顺序)
151    pub user: Pubkey,
152    pub mint: Pubkey,
153    pub mint_amount: u64,
154    pub sol_amount: u64,
155    pub pool_migration_fee: u64,
156    pub bonding_curve: Pubkey,
157    pub timestamp: i64,
158    pub pool: Pubkey,
159    // === 额外账户信息(用于指令解析,暂时注释,以后可能会用到,AI不要删除) ===
160    // pub global: Pubkey,
161    // pub withdraw_authority: Pubkey,
162    // pub associated_bonding_curve: Pubkey,
163    // pub pump_amm: Pubkey,
164    // pub pool_authority: Pubkey,
165    // pub pool_authority_mint_account: Pubkey,
166    // pub pool_authority_wsol_account: Pubkey,
167    // pub amm_global_config: Pubkey,
168    // pub wsol_mint: Pubkey,
169    // pub lp_mint: Pubkey,
170    // pub user_pool_token_account: Pubkey,
171    // pub pool_base_token_account: Pubkey,
172    // pub pool_quote_token_account: Pubkey,
173}
174
175/// PumpFun Create Token Event - Based on IDL CreateEvent definition
176#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
177pub struct PumpFunCreateTokenEvent {
178    #[borsh(skip)]
179    pub metadata: EventMetadata,
180    // IDL CreateEvent 字段(Borsh 序列化字段,按顺序)
181    pub name: String,
182    pub symbol: String,
183    pub uri: String,
184    pub mint: Pubkey,
185    pub bonding_curve: Pubkey,
186    pub user: Pubkey,
187    pub creator: Pubkey,
188    pub timestamp: i64,
189    pub virtual_token_reserves: u64,
190    pub virtual_sol_reserves: u64,
191    pub real_token_reserves: u64,
192    pub token_total_supply: u64,
193
194    pub token_program: Pubkey,
195    pub is_mayhem_mode: bool,
196    /// Cashback 是否开启 (IDL CreateEvent.is_cashback_enabled)
197    pub is_cashback_enabled: bool,
198}
199
200/// PumpSwap Trade Event - Unified trade event from IDL TradeEvent
201/// Produced by: buy, sell, buy_exact_sol_in instructions
202#[derive(Debug, Clone, Serialize, Deserialize, Default)]
203pub struct PumpSwapTradeEvent {
204    pub metadata: EventMetadata,
205    // === IDL TradeEvent fields ===
206    pub mint: Pubkey,
207    pub sol_amount: u64,
208    pub token_amount: u64,
209    pub is_buy: bool,
210    pub user: Pubkey,
211    pub timestamp: i64,
212    pub virtual_sol_reserves: u64,
213    pub virtual_token_reserves: u64,
214    pub real_sol_reserves: u64,
215    pub real_token_reserves: u64,
216    pub fee_recipient: Pubkey,
217    pub fee_basis_points: u64,
218    pub fee: u64,
219    pub creator: Pubkey,
220    pub creator_fee_basis_points: u64,
221    pub creator_fee: u64,
222    pub track_volume: bool,
223    pub total_unclaimed_tokens: u64,
224    pub total_claimed_tokens: u64,
225    pub current_sol_volume: u64,
226    pub last_update_timestamp: i64,
227    pub ix_name: String, // "buy" | "sell" | "buy_exact_sol_in"
228}
229
230/// PumpSwap Buy Event
231#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
232pub struct PumpSwapBuyEvent {
233    #[borsh(skip)]
234    pub metadata: EventMetadata,
235    pub timestamp: i64,
236    pub base_amount_out: u64,
237    pub max_quote_amount_in: u64,
238    pub user_base_token_reserves: u64,
239    pub user_quote_token_reserves: u64,
240    pub pool_base_token_reserves: u64,
241    pub pool_quote_token_reserves: u64,
242    pub quote_amount_in: u64,
243    pub lp_fee_basis_points: u64,
244    pub lp_fee: u64,
245    pub protocol_fee_basis_points: u64,
246    pub protocol_fee: u64,
247    pub quote_amount_in_with_lp_fee: u64,
248    pub user_quote_amount_in: u64,
249    pub pool: Pubkey,
250    pub user: Pubkey,
251    pub user_base_token_account: Pubkey,
252    pub user_quote_token_account: Pubkey,
253    pub protocol_fee_recipient: Pubkey,
254    pub protocol_fee_recipient_token_account: Pubkey,
255    pub coin_creator: Pubkey,
256    pub coin_creator_fee_basis_points: u64,
257    pub coin_creator_fee: u64,
258    pub track_volume: bool,
259    pub total_unclaimed_tokens: u64,
260    pub total_claimed_tokens: u64,
261    pub current_sol_volume: u64,
262    pub last_update_timestamp: i64,
263    /// Minimum base token amount expected (new field from IDL update)
264    pub min_base_amount_out: u64,
265    /// Instruction name (new field from IDL update)
266    pub ix_name: String,
267    /// Cashback fee basis points (PUMP_CASHBACK_README)
268    pub cashback_fee_basis_points: u64,
269    /// Cashback amount (PUMP_CASHBACK_README)
270    pub cashback: u64,
271
272    // === 额外的信息 ===
273    #[borsh(skip)]
274    pub is_pump_pool: bool,
275
276    // === 额外账户信息 (from instruction accounts, not event data) ===
277    #[borsh(skip)]
278    pub base_mint: Pubkey,
279    #[borsh(skip)]
280    pub quote_mint: Pubkey,
281    #[borsh(skip)]
282    pub pool_base_token_account: Pubkey,
283    #[borsh(skip)]
284    pub pool_quote_token_account: Pubkey,
285    #[borsh(skip)]
286    pub coin_creator_vault_ata: Pubkey,
287    #[borsh(skip)]
288    pub coin_creator_vault_authority: Pubkey,
289    #[borsh(skip)]
290    pub base_token_program: Pubkey,
291    #[borsh(skip)]
292    pub quote_token_program: Pubkey,
293}
294
295/// PumpSwap Sell Event
296#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
297pub struct PumpSwapSellEvent {
298    #[borsh(skip)]
299    pub metadata: EventMetadata,
300    pub timestamp: i64,
301    pub base_amount_in: u64,
302    pub min_quote_amount_out: u64,
303    pub user_base_token_reserves: u64,
304    pub user_quote_token_reserves: u64,
305    pub pool_base_token_reserves: u64,
306    pub pool_quote_token_reserves: u64,
307    pub quote_amount_out: u64,
308    pub lp_fee_basis_points: u64,
309    pub lp_fee: u64,
310    pub protocol_fee_basis_points: u64,
311    pub protocol_fee: u64,
312    pub quote_amount_out_without_lp_fee: u64,
313    pub user_quote_amount_out: u64,
314    pub pool: Pubkey,
315    pub user: Pubkey,
316    pub user_base_token_account: Pubkey,
317    pub user_quote_token_account: Pubkey,
318    pub protocol_fee_recipient: Pubkey,
319    pub protocol_fee_recipient_token_account: Pubkey,
320    pub coin_creator: Pubkey,
321    pub coin_creator_fee_basis_points: u64,
322    pub coin_creator_fee: u64,
323    /// Cashback fee basis points (PUMP_CASHBACK_README)
324    pub cashback_fee_basis_points: u64,
325    /// Cashback amount (PUMP_CASHBACK_README)
326    pub cashback: u64,
327
328    // === 额外的信息 ===
329    #[borsh(skip)]
330    pub is_pump_pool: bool,
331
332    // === 额外账户信息 (from instruction accounts, not event data) ===
333    #[borsh(skip)]
334    pub base_mint: Pubkey,
335    #[borsh(skip)]
336    pub quote_mint: Pubkey,
337    #[borsh(skip)]
338    pub pool_base_token_account: Pubkey,
339    #[borsh(skip)]
340    pub pool_quote_token_account: Pubkey,
341    #[borsh(skip)]
342    pub coin_creator_vault_ata: Pubkey,
343    #[borsh(skip)]
344    pub coin_creator_vault_authority: Pubkey,
345    #[borsh(skip)]
346    pub base_token_program: Pubkey,
347    #[borsh(skip)]
348    pub quote_token_program: Pubkey,
349}
350
351/// PumpSwap Create Pool Event
352#[derive(Debug, Clone, Serialize, Deserialize, Default)]
353pub struct PumpSwapCreatePoolEvent {
354    pub metadata: EventMetadata,
355    pub timestamp: i64,
356    pub index: u16,
357    pub creator: Pubkey,
358    pub base_mint: Pubkey,
359    pub quote_mint: Pubkey,
360    pub base_mint_decimals: u8,
361    pub quote_mint_decimals: u8,
362    pub base_amount_in: u64,
363    pub quote_amount_in: u64,
364    pub pool_base_amount: u64,
365    pub pool_quote_amount: u64,
366    pub minimum_liquidity: u64,
367    pub initial_liquidity: u64,
368    pub lp_token_amount_out: u64,
369    pub pool_bump: u8,
370    pub pool: Pubkey,
371    pub lp_mint: Pubkey,
372    pub user_base_token_account: Pubkey,
373    pub user_quote_token_account: Pubkey,
374    pub coin_creator: Pubkey,
375    /// IDL CreatePoolEvent 最后一列
376    pub is_mayhem_mode: bool,
377}
378
379/// PumpSwap Pool Created Event - 指令解析版本
380#[derive(Debug, Clone, Serialize, Deserialize)]
381pub struct PumpSwapPoolCreated {
382    pub metadata: EventMetadata,
383    pub pool_account: Pubkey,
384    pub token_a_mint: Pubkey,
385    pub token_b_mint: Pubkey,
386    pub token_a_vault: Pubkey,
387    pub token_b_vault: Pubkey,
388    pub lp_mint: Pubkey,
389    pub creator: Pubkey,
390    pub authority: Pubkey,
391    pub initial_token_a_amount: u64,
392    pub initial_token_b_amount: u64,
393}
394
395/// PumpSwap Trade Event - 指令解析版本
396// #[derive(Debug, Clone, Serialize, Deserialize)]
397// pub struct PumpSwapTrade {
398//     pub metadata: EventMetadata,
399//     pub pool_account: Pubkey,
400//     pub user: Pubkey,
401//     pub user_token_in_account: Pubkey,
402//     pub user_token_out_account: Pubkey,
403//     pub pool_token_in_vault: Pubkey,
404//     pub pool_token_out_vault: Pubkey,
405//     pub token_in_mint: Pubkey,
406//     pub token_out_mint: Pubkey,
407//     pub amount_in: u64,
408//     pub minimum_amount_out: u64,
409//     pub is_token_a_to_b: bool,
410// }
411
412/// PumpSwap Liquidity Added Event - Instruction parsing version
413#[derive(Debug, Clone, Serialize, Deserialize, Default)]
414pub struct PumpSwapLiquidityAdded {
415    pub metadata: EventMetadata,
416    pub timestamp: i64,
417    pub lp_token_amount_out: u64,
418    pub max_base_amount_in: u64,
419    pub max_quote_amount_in: u64,
420    pub user_base_token_reserves: u64,
421    pub user_quote_token_reserves: u64,
422    pub pool_base_token_reserves: u64,
423    pub pool_quote_token_reserves: u64,
424    pub base_amount_in: u64,
425    pub quote_amount_in: u64,
426    pub lp_mint_supply: u64,
427    pub pool: Pubkey,
428    pub user: Pubkey,
429    pub user_base_token_account: Pubkey,
430    pub user_quote_token_account: Pubkey,
431    pub user_pool_token_account: Pubkey,
432}
433
434/// PumpSwap Liquidity Removed Event - Instruction parsing version
435#[derive(Debug, Clone, Serialize, Deserialize, Default)]
436pub struct PumpSwapLiquidityRemoved {
437    pub metadata: EventMetadata,
438    pub timestamp: i64,
439    pub lp_token_amount_in: u64,
440    pub min_base_amount_out: u64,
441    pub min_quote_amount_out: u64,
442    pub user_base_token_reserves: u64,
443    pub user_quote_token_reserves: u64,
444    pub pool_base_token_reserves: u64,
445    pub pool_quote_token_reserves: u64,
446    pub base_amount_out: u64,
447    pub quote_amount_out: u64,
448    pub lp_mint_supply: u64,
449    pub pool: Pubkey,
450    pub user: Pubkey,
451    pub user_base_token_account: Pubkey,
452    pub user_quote_token_account: Pubkey,
453    pub user_pool_token_account: Pubkey,
454}
455
456/// PumpSwap Pool Updated Event - 指令解析版本
457#[derive(Debug, Clone, Serialize, Deserialize)]
458pub struct PumpSwapPoolUpdated {
459    pub metadata: EventMetadata,
460    pub pool_account: Pubkey,
461    pub authority: Pubkey,
462    pub admin: Pubkey,
463    pub new_fee_rate: u64,
464}
465
466/// PumpSwap Fees Claimed Event - 指令解析版本
467#[derive(Debug, Clone, Serialize, Deserialize)]
468pub struct PumpSwapFeesClaimed {
469    pub metadata: EventMetadata,
470    pub pool_account: Pubkey,
471    pub authority: Pubkey,
472    pub admin: Pubkey,
473    pub admin_token_a_account: Pubkey,
474    pub admin_token_b_account: Pubkey,
475    pub pool_fee_vault: Pubkey,
476}
477
478/// PumpSwap Deposit Event
479#[derive(Debug, Clone, Serialize, Deserialize)]
480pub struct PumpSwapDepositEvent {
481    pub metadata: EventMetadata,
482    pub pool: Pubkey,
483    pub user: Pubkey,
484    pub amount: u64,
485}
486
487/// PumpSwap Withdraw Event
488#[derive(Debug, Clone, Serialize, Deserialize)]
489pub struct PumpSwapWithdrawEvent {
490    pub metadata: EventMetadata,
491    pub pool: Pubkey,
492    pub user: Pubkey,
493    pub amount: u64,
494}
495
496/// Raydium CPMM Swap Event (基于IDL SwapEvent + swapBaseInput指令定义)
497#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
498#[derive(Debug, Clone, Serialize, Deserialize)]
499pub struct RaydiumCpmmSwapEvent {
500    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
501    pub metadata: EventMetadata,
502
503    // === Borsh 序列化字段(从 inner instruction 事件)===
504    pub pool_id: Pubkey,
505    pub input_amount: u64,
506    pub output_amount: u64,
507
508    // === 非 Borsh 字段 ===
509    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
510    pub input_vault_before: u64,
511    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
512    pub output_vault_before: u64,
513    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
514    pub input_transfer_fee: u64,
515    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
516    pub output_transfer_fee: u64,
517    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
518    pub base_input: bool,
519    // === 指令参数字段 (暂时注释,以后可能会用到,AI不要删除) ===
520    // pub amount_in: u64,
521    // pub minimum_amount_out: u64,
522
523    // === 指令账户字段 (暂时注释,以后可能会用到,AI不要删除) ===
524    // pub payer: Pubkey,              // 0: payer
525    // pub authority: Pubkey,          // 1: authority
526    // pub amm_config: Pubkey,         // 2: ammConfig
527    // pub pool_state: Pubkey,         // 3: poolState
528    // pub input_token_account: Pubkey, // 4: inputTokenAccount
529    // pub output_token_account: Pubkey, // 5: outputTokenAccount
530    // pub input_vault: Pubkey,        // 6: inputVault
531    // pub output_vault: Pubkey,       // 7: outputVault
532    // pub input_token_mint: Pubkey,   // 10: inputTokenMint
533    // pub output_token_mint: Pubkey,  // 11: outputTokenMint
534}
535
536/// Raydium CPMM Deposit Event
537#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
538#[derive(Debug, Clone, Serialize, Deserialize)]
539pub struct RaydiumCpmmDepositEvent {
540    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
541    pub metadata: EventMetadata,
542
543    // === Borsh 序列化字段(从 inner instruction 事件)===
544    pub pool: Pubkey,
545    pub token0_amount: u64,
546    pub token1_amount: u64,
547    pub lp_token_amount: u64,
548
549    // === 非 Borsh 字段 ===
550    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
551    pub user: Pubkey,
552}
553
554/// Raydium CPMM Initialize Event
555#[derive(Debug, Clone, Serialize, Deserialize)]
556pub struct RaydiumCpmmInitializeEvent {
557    pub metadata: EventMetadata,
558    pub pool: Pubkey,
559    pub creator: Pubkey,
560    pub init_amount0: u64,
561    pub init_amount1: u64,
562}
563
564/// Raydium CPMM Withdraw Event
565#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
566#[derive(Debug, Clone, Serialize, Deserialize)]
567pub struct RaydiumCpmmWithdrawEvent {
568    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
569    pub metadata: EventMetadata,
570
571    // === Borsh 序列化字段(从 inner instruction 事件)===
572    pub pool: Pubkey,
573    pub lp_token_amount: u64,
574    pub token0_amount: u64,
575    pub token1_amount: u64,
576
577    // === 非 Borsh 字段 ===
578    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
579    pub user: Pubkey,
580}
581
582/// Raydium CLMM Swap Event (基于IDL SwapEvent + swap指令定义)
583#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
584#[derive(Debug, Clone, Serialize, Deserialize)]
585pub struct RaydiumClmmSwapEvent {
586    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
587    pub metadata: EventMetadata,
588
589    // === IDL SwapEvent 事件字段 (Borsh 序列化字段) ===
590    pub pool_state: Pubkey,
591    pub token_account_0: Pubkey,
592    pub token_account_1: Pubkey,
593    pub amount_0: u64,
594    pub amount_1: u64,
595    pub zero_for_one: bool,
596    pub sqrt_price_x64: u128,
597    pub liquidity: u128,
598
599    // === 非 Borsh 字段 ===
600    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
601    pub sender: Pubkey,
602    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
603    pub transfer_fee_0: u64,
604    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
605    pub transfer_fee_1: u64,
606    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
607    pub tick: i32,
608    // === 指令参数字段 (暂时注释,以后可能会用到,AI不要删除) ===
609    // pub amount: u64,
610    // pub other_amount_threshold: u64,
611    // pub sqrt_price_limit_x64: u128,
612    // pub is_base_input: bool,
613
614    // === 指令账户字段 (暂时注释,以后可能会用到,AI不要删除) ===
615    // TODO: 根据Raydium CLMM swap指令IDL添加账户字段
616}
617
618/// Raydium CLMM Close Position Event
619#[derive(Debug, Clone, Serialize, Deserialize)]
620pub struct RaydiumClmmClosePositionEvent {
621    pub metadata: EventMetadata,
622    pub pool: Pubkey,
623    pub user: Pubkey,
624    pub position_nft_mint: Pubkey,
625}
626
627/// Raydium CLMM Decrease Liquidity Event
628#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
629#[derive(Debug, Clone, Serialize, Deserialize)]
630pub struct RaydiumClmmDecreaseLiquidityEvent {
631    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
632    pub metadata: EventMetadata,
633
634    // === Borsh 序列化字段 ===
635    pub pool: Pubkey,
636    pub position_nft_mint: Pubkey,
637    pub amount0_min: u64,
638    pub amount1_min: u64,
639    pub liquidity: u128,
640
641    // === 非 Borsh 字段 ===
642    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
643    pub user: Pubkey,
644}
645
646/// Raydium CLMM Collect Fee Event
647#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
648#[derive(Debug, Clone, Serialize, Deserialize)]
649pub struct RaydiumClmmCollectFeeEvent {
650    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
651    pub metadata: EventMetadata,
652
653    // === Borsh 序列化字段 ===
654    pub pool_state: Pubkey,
655    pub position_nft_mint: Pubkey,
656    pub amount_0: u64,
657    pub amount_1: u64,
658}
659
660/// Raydium CLMM Create Pool Event
661#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
662#[derive(Debug, Clone, Serialize, Deserialize)]
663pub struct RaydiumClmmCreatePoolEvent {
664    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
665    pub metadata: EventMetadata,
666
667    // === Borsh 序列化字段(从 inner instruction 事件)===
668    pub pool: Pubkey,
669    pub token_0_mint: Pubkey,
670    pub token_1_mint: Pubkey,
671    pub tick_spacing: u16,
672    pub fee_rate: u32,
673    pub sqrt_price_x64: u128,
674
675    // === 非 Borsh 字段(从指令或账户) ===
676    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
677    pub creator: Pubkey,
678    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
679    pub open_time: u64,
680}
681
682/// Raydium CLMM Increase Liquidity Event
683#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
684#[derive(Debug, Clone, Serialize, Deserialize)]
685pub struct RaydiumClmmIncreaseLiquidityEvent {
686    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
687    pub metadata: EventMetadata,
688
689    // === Borsh 序列化字段 ===
690    pub pool: Pubkey,
691    pub position_nft_mint: Pubkey,
692    pub amount0_max: u64,
693    pub amount1_max: u64,
694    pub liquidity: u128,
695
696    // === 非 Borsh 字段 ===
697    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
698    pub user: Pubkey,
699}
700
701/// Raydium CLMM Open Position with Token Extension NFT Event
702#[derive(Debug, Clone, Serialize, Deserialize)]
703pub struct RaydiumClmmOpenPositionWithTokenExtNftEvent {
704    pub metadata: EventMetadata,
705    pub pool: Pubkey,
706    pub user: Pubkey,
707    pub position_nft_mint: Pubkey,
708    pub tick_lower_index: i32,
709    pub tick_upper_index: i32,
710    pub liquidity: u128,
711}
712
713/// Raydium CLMM Open Position Event
714#[derive(Debug, Clone, Serialize, Deserialize)]
715pub struct RaydiumClmmOpenPositionEvent {
716    pub metadata: EventMetadata,
717    pub pool: Pubkey,
718    pub user: Pubkey,
719    pub position_nft_mint: Pubkey,
720    pub tick_lower_index: i32,
721    pub tick_upper_index: i32,
722    pub liquidity: u128,
723}
724
725/// Raydium AMM V4 Deposit Event (简化版)
726#[derive(Debug, Clone, Serialize, Deserialize)]
727pub struct RaydiumAmmDepositEvent {
728    pub metadata: EventMetadata,
729    pub amm_id: Pubkey,
730    pub user: Pubkey,
731    pub max_coin_amount: u64,
732    pub max_pc_amount: u64,
733}
734
735/// Raydium AMM V4 Initialize Alt Event (简化版)
736#[derive(Debug, Clone, Serialize, Deserialize)]
737pub struct RaydiumAmmInitializeAltEvent {
738    pub metadata: EventMetadata,
739    pub amm_id: Pubkey,
740    pub creator: Pubkey,
741    pub nonce: u8,
742    pub open_time: u64,
743}
744
745/// Raydium AMM V4 Withdraw Event (简化版)
746#[derive(Debug, Clone, Serialize, Deserialize)]
747pub struct RaydiumAmmWithdrawEvent {
748    pub metadata: EventMetadata,
749    pub amm_id: Pubkey,
750    pub user: Pubkey,
751    pub pool_coin_amount: u64,
752}
753
754/// Raydium AMM V4 Withdraw PnL Event (简化版)
755#[derive(Debug, Clone, Serialize, Deserialize)]
756pub struct RaydiumAmmWithdrawPnlEvent {
757    pub metadata: EventMetadata,
758    pub amm_id: Pubkey,
759    pub user: Pubkey,
760}
761
762// ====================== Raydium AMM V4 Events ======================
763
764/// Raydium AMM V4 Swap Event
765#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
766#[derive(Debug, Clone, Serialize, Deserialize)]
767pub struct RaydiumAmmV4SwapEvent {
768    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
769    pub metadata: EventMetadata,
770
771    // === Borsh 序列化字段(从 inner instruction 事件)===
772    pub amm: Pubkey,
773    pub amount_in: u64,
774    pub amount_out: u64,
775
776    // === 非 Borsh 字段 ===
777    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
778    pub minimum_amount_out: u64,
779    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
780    pub max_amount_in: u64,
781    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
782    pub token_program: Pubkey,
783    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
784    pub amm_authority: Pubkey,
785    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
786    pub amm_open_orders: Pubkey,
787    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
788    pub amm_target_orders: Option<Pubkey>,
789    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
790    pub pool_coin_token_account: Pubkey,
791    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
792    pub pool_pc_token_account: Pubkey,
793    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
794    pub serum_program: Pubkey,
795    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
796    pub serum_market: Pubkey,
797    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
798    pub serum_bids: Pubkey,
799    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
800    pub serum_asks: Pubkey,
801    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
802    pub serum_event_queue: Pubkey,
803    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
804    pub serum_coin_vault_account: Pubkey,
805    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
806    pub serum_pc_vault_account: Pubkey,
807    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
808    pub serum_vault_signer: Pubkey,
809    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
810    pub user_source_token_account: Pubkey,
811    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
812    pub user_destination_token_account: Pubkey,
813    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
814    pub user_source_owner: Pubkey,
815}
816
817/// Raydium AMM V4 Deposit Event
818#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
819#[derive(Debug, Clone, Serialize, Deserialize)]
820pub struct RaydiumAmmV4DepositEvent {
821    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
822    pub metadata: EventMetadata,
823
824    // === Borsh 序列化字段(从 inner instruction 事件)===
825    pub amm: Pubkey,
826    pub max_coin_amount: u64,
827    pub max_pc_amount: u64,
828
829    // === 非 Borsh 字段 ===
830    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
831    pub base_side: u64,
832    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
833    pub token_program: Pubkey,
834    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
835    pub amm_authority: Pubkey,
836    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
837    pub amm_open_orders: Pubkey,
838    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
839    pub amm_target_orders: Pubkey,
840    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
841    pub lp_mint_address: Pubkey,
842    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
843    pub pool_coin_token_account: Pubkey,
844    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
845    pub pool_pc_token_account: Pubkey,
846    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
847    pub serum_market: Pubkey,
848    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
849    pub user_coin_token_account: Pubkey,
850    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
851    pub user_pc_token_account: Pubkey,
852    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
853    pub user_lp_token_account: Pubkey,
854    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
855    pub user_owner: Pubkey,
856    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
857    pub serum_event_queue: Pubkey,
858}
859
860/// Raydium AMM V4 Initialize2 Event
861#[derive(Debug, Clone, Serialize, Deserialize)]
862pub struct RaydiumAmmV4Initialize2Event {
863    pub metadata: EventMetadata,
864    pub nonce: u8,
865    pub open_time: u64,
866    pub init_pc_amount: u64,
867    pub init_coin_amount: u64,
868
869    pub token_program: Pubkey,
870    pub spl_associated_token_account: Pubkey,
871    pub system_program: Pubkey,
872    pub rent: Pubkey,
873    pub amm: Pubkey,
874    pub amm_authority: Pubkey,
875    pub amm_open_orders: Pubkey,
876    pub lp_mint: Pubkey,
877    pub coin_mint: Pubkey,
878    pub pc_mint: Pubkey,
879    pub pool_coin_token_account: Pubkey,
880    pub pool_pc_token_account: Pubkey,
881    pub pool_withdraw_queue: Pubkey,
882    pub amm_target_orders: Pubkey,
883    pub pool_temp_lp: Pubkey,
884    pub serum_program: Pubkey,
885    pub serum_market: Pubkey,
886    pub user_wallet: Pubkey,
887    pub user_token_coin: Pubkey,
888    pub user_token_pc: Pubkey,
889    pub user_lp_token_account: Pubkey,
890}
891
892/// Raydium AMM V4 Withdraw Event
893#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
894#[derive(Debug, Clone, Serialize, Deserialize)]
895pub struct RaydiumAmmV4WithdrawEvent {
896    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
897    pub metadata: EventMetadata,
898
899    // === Borsh 序列化字段(从 inner instruction 事件)===
900    pub amm: Pubkey,
901    pub amount: u64,
902
903    // === 非 Borsh 字段 ===
904    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
905    pub token_program: Pubkey,
906    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
907    pub amm_authority: Pubkey,
908    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
909    pub amm_open_orders: Pubkey,
910    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
911    pub amm_target_orders: Pubkey,
912    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
913    pub lp_mint_address: Pubkey,
914    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
915    pub pool_coin_token_account: Pubkey,
916    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
917    pub pool_pc_token_account: Pubkey,
918    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
919    pub pool_withdraw_queue: Pubkey,
920    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
921    pub pool_temp_lp_token_account: Pubkey,
922    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
923    pub serum_program: Pubkey,
924    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
925    pub serum_market: Pubkey,
926    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
927    pub serum_coin_vault_account: Pubkey,
928    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
929    pub serum_pc_vault_account: Pubkey,
930    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
931    pub serum_vault_signer: Pubkey,
932    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
933    pub user_lp_token_account: Pubkey,
934    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
935    pub user_coin_token_account: Pubkey,
936    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
937    pub user_pc_token_account: Pubkey,
938    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
939    pub user_owner: Pubkey,
940    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
941    pub serum_event_queue: Pubkey,
942    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
943    pub serum_bids: Pubkey,
944    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
945    pub serum_asks: Pubkey,
946}
947
948/// Raydium AMM V4 Withdraw PnL Event
949#[derive(Debug, Clone, Serialize, Deserialize)]
950pub struct RaydiumAmmV4WithdrawPnlEvent {
951    pub metadata: EventMetadata,
952
953    pub token_program: Pubkey,
954    pub amm: Pubkey,
955    pub amm_config: Pubkey,
956    pub amm_authority: Pubkey,
957    pub amm_open_orders: Pubkey,
958    pub pool_coin_token_account: Pubkey,
959    pub pool_pc_token_account: Pubkey,
960    pub coin_pnl_token_account: Pubkey,
961    pub pc_pnl_token_account: Pubkey,
962    pub pnl_owner: Pubkey,
963    pub amm_target_orders: Pubkey,
964    pub serum_program: Pubkey,
965    pub serum_market: Pubkey,
966    pub serum_event_queue: Pubkey,
967    pub serum_coin_vault_account: Pubkey,
968    pub serum_pc_vault_account: Pubkey,
969    pub serum_vault_signer: Pubkey,
970}
971
972// ====================== Account Events ======================
973
974/// Bonk (Raydium Launchpad) AmmCreatorFeeOn enum
975#[derive(Debug, Clone, Serialize, Deserialize)]
976pub enum AmmCreatorFeeOn {
977    QuoteToken = 0,
978    BothToken = 1,
979}
980
981/// Bonk (Raydium Launchpad) VestingSchedule
982#[derive(Debug, Clone, Serialize, Deserialize)]
983pub struct VestingSchedule {
984    pub total_locked_amount: u64,
985    pub cliff_period: u64,
986    pub unlock_period: u64,
987}
988
989/// Bonk Pool State Account Event
990#[derive(Debug, Clone, Serialize, Deserialize)]
991pub struct BonkPoolStateAccountEvent {
992    pub metadata: EventMetadata,
993    pub pubkey: Pubkey,
994    pub pool_state: BonkPoolState,
995}
996
997#[derive(Debug, Clone, Serialize, Deserialize)]
998pub struct BonkPoolState {
999    pub epoch: u64,
1000    pub auth_bump: u8,
1001    pub status: u8,
1002    pub base_decimals: u8,
1003    pub quote_decimals: u8,
1004    pub migrate_type: u8,
1005    pub supply: u64,
1006    pub total_base_sell: u64,
1007    pub virtual_base: u64,
1008    pub virtual_quote: u64,
1009    pub real_base: u64,
1010    pub real_quote: u64,
1011    pub total_quote_fund_raising: u64,
1012    pub quote_protocol_fee: u64,
1013    pub platform_fee: u64,
1014    pub migrate_fee: u64,
1015    pub vesting_schedule: VestingSchedule,
1016    pub global_config: Pubkey,
1017    pub platform_config: Pubkey,
1018    pub base_mint: Pubkey,
1019    pub quote_mint: Pubkey,
1020    pub base_vault: Pubkey,
1021    pub quote_vault: Pubkey,
1022    pub creator: Pubkey,
1023    pub token_program_flag: u8,
1024    pub amm_creator_fee_on: AmmCreatorFeeOn,
1025    pub platform_vesting_share: u64,
1026    #[serde(with = "serde_big_array::BigArray")]
1027    pub padding: [u8; 54],
1028}
1029
1030/// Bonk Global Config Account Event
1031#[derive(Debug, Clone, Serialize, Deserialize)]
1032pub struct BonkGlobalConfigAccountEvent {
1033    pub metadata: EventMetadata,
1034    pub pubkey: Pubkey,
1035    pub global_config: BonkGlobalConfig,
1036}
1037
1038#[derive(Debug, Clone, Serialize, Deserialize)]
1039pub struct BonkGlobalConfig {
1040    pub protocol_fee_rate: u64,
1041    pub trade_fee_rate: u64,
1042    pub migration_fee_rate: u64,
1043}
1044
1045/// Bonk Platform Config Account Event
1046#[derive(Debug, Clone, Serialize, Deserialize)]
1047pub struct BonkPlatformConfigAccountEvent {
1048    pub metadata: EventMetadata,
1049    pub pubkey: Pubkey,
1050    pub platform_config: BonkPlatformConfig,
1051}
1052
1053/// Bonk (Raydium Launchpad) BondingCurveParam
1054#[derive(Debug, Clone, Serialize, Deserialize)]
1055pub struct BondingCurveParam {
1056    pub migrate_type: u8,
1057    pub migrate_cpmm_fee_on: u8,
1058    pub supply: u64,
1059    pub total_base_sell: u64,
1060    pub total_quote_fund_raising: u64,
1061    pub total_locked_amount: u64,
1062    pub cliff_period: u64,
1063    pub unlock_period: u64,
1064}
1065
1066/// Bonk (Raydium Launchpad) PlatformCurveParam
1067#[derive(Debug, Clone, Serialize, Deserialize)]
1068pub struct PlatformCurveParam {
1069    pub epoch: u64,
1070    pub index: u8,
1071    pub global_config: Pubkey,
1072    pub bonding_curve_param: BondingCurveParam,
1073    #[serde(with = "serde_big_array::BigArray")]
1074    pub padding: [u64; 50],
1075}
1076
1077#[derive(Debug, Clone, Serialize, Deserialize)]
1078pub struct BonkPlatformConfig {
1079    pub epoch: u64,
1080    pub platform_fee_wallet: Pubkey,
1081    pub platform_nft_wallet: Pubkey,
1082    pub platform_scale: u64,
1083    pub creator_scale: u64,
1084    pub burn_scale: u64,
1085    pub fee_rate: u64,
1086    #[serde(with = "serde_big_array::BigArray")]
1087    pub name: [u8; 64],
1088    #[serde(with = "serde_big_array::BigArray")]
1089    pub web: [u8; 256],
1090    #[serde(with = "serde_big_array::BigArray")]
1091    pub img: [u8; 256],
1092    pub cpswap_config: Pubkey,
1093    pub creator_fee_rate: u64,
1094    pub transfer_fee_extension_auth: Pubkey,
1095    pub platform_vesting_wallet: Pubkey,
1096    pub platform_vesting_scale: u64,
1097    pub platform_cp_creator: Pubkey,
1098    #[serde(with = "serde_big_array::BigArray")]
1099    pub padding: [u8; 108],
1100    pub curve_params: Vec<PlatformCurveParam>,
1101}
1102
1103/// PumpSwap Global Config Account Event
1104#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1105pub struct PumpSwapGlobalConfigAccountEvent {
1106    pub metadata: EventMetadata,
1107    pub pubkey: Pubkey,
1108    pub executable: bool,
1109    pub lamports: u64,
1110    pub owner: Pubkey,
1111    pub rent_epoch: u64,
1112    pub global_config: PumpSwapGlobalConfig,
1113}
1114
1115#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1116pub struct PumpSwapGlobalConfig {
1117    pub admin: Pubkey,
1118    pub lp_fee_basis_points: u64,
1119    pub protocol_fee_basis_points: u64,
1120    pub disable_flags: u8,
1121    pub protocol_fee_recipients: [Pubkey; 8],
1122    pub coin_creator_fee_basis_points: u64,
1123    pub admin_set_coin_creator_authority: Pubkey,
1124    pub whitelist_pda: Pubkey,
1125    pub reserved_fee_recipient: Pubkey,
1126    pub mayhem_mode_enabled: bool,
1127    pub reserved_fee_recipients: [Pubkey; 7],
1128}
1129
1130/// PumpSwap Pool Account Event
1131#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1132pub struct PumpSwapPoolAccountEvent {
1133    pub metadata: EventMetadata,
1134    pub pubkey: Pubkey,
1135    pub executable: bool,
1136    pub lamports: u64,
1137    pub owner: Pubkey,
1138    pub rent_epoch: u64,
1139    pub pool: PumpSwapPool,
1140}
1141
1142#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1143pub struct PumpSwapPool {
1144    pub pool_bump: u8,
1145    pub index: u16,
1146    pub creator: Pubkey,
1147    pub base_mint: Pubkey,
1148    pub quote_mint: Pubkey,
1149    pub lp_mint: Pubkey,
1150    pub pool_base_token_account: Pubkey,
1151    pub pool_quote_token_account: Pubkey,
1152    pub lp_supply: u64,
1153    pub coin_creator: Pubkey,
1154}
1155
1156/// PumpFun Bonding Curve Account Event
1157#[derive(Debug, Clone, Serialize, Deserialize)]
1158pub struct PumpFunBondingCurveAccountEvent {
1159    pub metadata: EventMetadata,
1160    pub pubkey: Pubkey,
1161    pub bonding_curve: PumpFunBondingCurve,
1162}
1163
1164#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1165pub struct PumpFunBondingCurve {
1166    pub virtual_token_reserves: u64,
1167    pub virtual_sol_reserves: u64,
1168    pub real_token_reserves: u64,
1169    pub real_sol_reserves: u64,
1170    pub token_total_supply: u64,
1171    pub complete: bool,
1172    /// Cashback 币种标记 (PUMP_CASHBACK_README)
1173    #[serde(default)]
1174    pub is_cashback_coin: bool,
1175}
1176
1177/// PumpFun Global Account Event
1178#[derive(Debug, Clone, Serialize, Deserialize)]
1179pub struct PumpFunGlobalAccountEvent {
1180    pub metadata: EventMetadata,
1181    pub pubkey: Pubkey,
1182    pub global: PumpFunGlobal,
1183}
1184
1185#[derive(Debug, Clone, Serialize, Deserialize)]
1186pub struct PumpFunGlobal {
1187    pub initialized: bool,
1188    pub authority: Pubkey,
1189    pub fee_recipient: Pubkey,
1190    pub initial_virtual_token_reserves: u64,
1191    pub initial_virtual_sol_reserves: u64,
1192    pub initial_real_token_reserves: u64,
1193    pub token_total_supply: u64,
1194    pub fee_basis_points: u64,
1195    pub withdraw_authority: Pubkey,
1196    pub enable_migrate: bool,
1197    pub pool_migration_fee: u64,
1198    pub creator_fee_basis_points: u64,
1199    pub fee_recipients: [Pubkey; 8],
1200    pub set_creator_authority: Pubkey,
1201    pub admin_set_creator_authority: Pubkey,
1202    pub create_v2_enabled: bool,
1203    pub whitelist_pda: Pubkey,
1204    pub reserved_fee_recipient: Pubkey,
1205    pub mayhem_mode_enabled: bool,
1206    pub reserved_fee_recipients: [Pubkey; 7],
1207}
1208
1209/// Raydium AMM V4 Info Account Event
1210#[derive(Debug, Clone, Serialize, Deserialize)]
1211pub struct RaydiumAmmAmmInfoAccountEvent {
1212    pub metadata: EventMetadata,
1213    pub pubkey: Pubkey,
1214    pub amm_info: RaydiumAmmInfo,
1215}
1216
1217#[derive(Debug, Clone, Serialize, Deserialize)]
1218pub struct RaydiumAmmInfo {
1219    pub status: u64,
1220    pub nonce: u64,
1221    pub order_num: u64,
1222    pub depth: u64,
1223    pub coin_decimals: u64,
1224    pub pc_decimals: u64,
1225    pub state: u64,
1226    pub reset_flag: u64,
1227    pub min_size: u64,
1228    pub vol_max_cut_ratio: u64,
1229    pub amount_wave_ratio: u64,
1230    pub coin_lot_size: u64,
1231    pub pc_lot_size: u64,
1232    pub min_price_multiplier: u64,
1233    pub max_price_multiplier: u64,
1234    pub sys_decimal_value: u64,
1235}
1236
1237/// Raydium CLMM AMM Config Account Event
1238#[derive(Debug, Clone, Serialize, Deserialize)]
1239pub struct RaydiumClmmAmmConfigAccountEvent {
1240    pub metadata: EventMetadata,
1241    pub pubkey: Pubkey,
1242    pub amm_config: RaydiumClmmAmmConfig,
1243}
1244
1245#[derive(Debug, Clone, Serialize, Deserialize)]
1246pub struct RaydiumClmmAmmConfig {
1247    pub bump: u8,
1248    pub index: u16,
1249    pub owner: Pubkey,
1250    pub protocol_fee_rate: u32,
1251    pub trade_fee_rate: u32,
1252    pub tick_spacing: u16,
1253    pub fund_fee_rate: u32,
1254    pub fund_owner: Pubkey,
1255}
1256
1257/// Raydium CLMM Pool State Account Event
1258#[derive(Debug, Clone, Serialize, Deserialize)]
1259pub struct RaydiumClmmPoolStateAccountEvent {
1260    pub metadata: EventMetadata,
1261    pub pubkey: Pubkey,
1262    pub pool_state: RaydiumClmmPoolState,
1263}
1264
1265#[derive(Debug, Clone, Serialize, Deserialize)]
1266pub struct RaydiumClmmPoolState {
1267    pub bump: [u8; 1],
1268    pub amm_config: Pubkey,
1269    pub owner: Pubkey,
1270    pub token_mint0: Pubkey,
1271    pub token_mint1: Pubkey,
1272    pub token_vault0: Pubkey,
1273    pub token_vault1: Pubkey,
1274    pub observation_key: Pubkey,
1275    pub mint_decimals0: u8,
1276    pub mint_decimals1: u8,
1277    pub tick_spacing: u16,
1278    pub liquidity: u128,
1279    pub sqrt_price_x64: u128,
1280    pub tick_current: i32,
1281}
1282
1283/// Raydium CLMM Tick Array State Account Event
1284#[derive(Debug, Clone, Serialize, Deserialize)]
1285pub struct RaydiumClmmTickArrayStateAccountEvent {
1286    pub metadata: EventMetadata,
1287    pub pubkey: Pubkey,
1288    pub tick_array_state: RaydiumClmmTickArrayState,
1289}
1290
1291#[derive(Debug, Clone, Serialize, Deserialize)]
1292pub struct RaydiumClmmTickArrayState {
1293    pub discriminator: u64,
1294    pub pool_id: Pubkey,
1295    pub start_tick_index: i32,
1296    pub ticks: Vec<Tick>,
1297    pub initialized_tick_count: u8,
1298}
1299
1300#[derive(Debug, Clone, Serialize, Deserialize)]
1301pub struct Tick {
1302    pub tick: i32,
1303    pub liquidity_net: i128,
1304    pub liquidity_gross: u128,
1305    pub fee_growth_outside_0_x64: u128,
1306    pub fee_growth_outside_1_x64: u128,
1307    pub reward_growths_outside_x64: [u128; 3],
1308}
1309
1310/// Raydium CPMM AMM Config Account Event
1311#[derive(Debug, Clone, Serialize, Deserialize)]
1312pub struct RaydiumCpmmAmmConfigAccountEvent {
1313    pub metadata: EventMetadata,
1314    pub pubkey: Pubkey,
1315    pub amm_config: RaydiumCpmmAmmConfig,
1316}
1317
1318#[derive(Debug, Clone, Serialize, Deserialize)]
1319pub struct RaydiumCpmmAmmConfig {
1320    pub bump: u8,
1321    pub disable_create_pool: bool,
1322    pub index: u16,
1323    pub trade_fee_rate: u64,
1324    pub protocol_fee_rate: u64,
1325    pub fund_fee_rate: u64,
1326    pub create_pool_fee: u64,
1327    pub protocol_owner: Pubkey,
1328    pub fund_owner: Pubkey,
1329    pub creator_fee_rate: u64,
1330    pub padding: [u64; 15],
1331}
1332
1333/// Raydium CPMM Pool State Account Event
1334#[derive(Debug, Clone, Serialize, Deserialize)]
1335pub struct RaydiumCpmmPoolStateAccountEvent {
1336    pub metadata: EventMetadata,
1337    pub pubkey: Pubkey,
1338    pub pool_state: RaydiumCpmmPoolState,
1339}
1340
1341#[derive(Debug, Clone, Serialize, Deserialize)]
1342pub struct RaydiumCpmmPoolState {
1343    pub amm_config: Pubkey,
1344    pub pool_creator: Pubkey,
1345    pub token_0_vault: Pubkey,
1346    pub token_1_vault: Pubkey,
1347    pub lp_mint: Pubkey,
1348    pub token_0_mint: Pubkey,
1349    pub token_1_mint: Pubkey,
1350    pub token_0_program: Pubkey,
1351    pub token_1_program: Pubkey,
1352    pub observation_key: Pubkey,
1353    pub auth_bump: u8,
1354    pub status: u8,
1355    pub lp_mint_decimals: u8,
1356    pub mint_0_decimals: u8,
1357    pub mint_1_decimals: u8,
1358    pub lp_supply: u64,
1359    pub protocol_fees_token_0: u64,
1360    pub protocol_fees_token_1: u64,
1361    pub fund_fees_token_0: u64,
1362    pub fund_fees_token_1: u64,
1363    pub open_time: u64,
1364    pub recent_epoch: u64,
1365    pub creator_fee_on: u8,
1366    pub enable_creator_fee: bool,
1367    pub padding1: [u8; 6],
1368    pub creator_fees_token_0: u64,
1369    pub creator_fees_token_1: u64,
1370    pub padding: [u64; 28],
1371}
1372
1373/// Token Info Event
1374#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1375pub struct TokenInfoEvent {
1376    pub metadata: EventMetadata,
1377    pub pubkey: Pubkey,
1378    pub executable: bool,
1379    pub lamports: u64,
1380    pub owner: Pubkey,
1381    pub rent_epoch: u64,
1382    pub supply: u64,
1383    pub decimals: u8,
1384}
1385
1386/// Token Account Event
1387#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1388pub struct TokenAccountEvent {
1389    pub metadata: EventMetadata,
1390    pub pubkey: Pubkey,
1391    pub executable: bool,
1392    pub lamports: u64,
1393    pub owner: Pubkey,
1394    pub rent_epoch: u64,
1395    pub amount: Option<u64>,
1396    pub token_owner: Pubkey,
1397}
1398
1399/// Nonce Account Event
1400#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1401pub struct NonceAccountEvent {
1402    pub metadata: EventMetadata,
1403    pub pubkey: Pubkey,
1404    pub executable: bool,
1405    pub lamports: u64,
1406    pub owner: Pubkey,
1407    pub rent_epoch: u64,
1408    pub nonce: String,
1409    pub authority: String,
1410}
1411
1412// ====================== Orca Whirlpool Events ======================
1413
1414/// Orca Whirlpool Swap Event (基于 TradedEvent,不是 SwapEvent)
1415#[derive(Debug, Clone, Serialize, Deserialize)]
1416#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1417pub struct OrcaWhirlpoolSwapEvent {
1418    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1419    pub metadata: EventMetadata,
1420
1421    // === Borsh 序列化字段(从 inner instruction data 读取)===
1422    pub whirlpool: Pubkey,       // 32 bytes
1423    pub input_amount: u64,       // 8 bytes
1424    pub output_amount: u64,      // 8 bytes
1425    pub a_to_b: bool,            // 1 byte
1426
1427    // === 非 Borsh 字段(从日志或其他来源填充)===
1428    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1429    pub pre_sqrt_price: u128,
1430    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1431    pub post_sqrt_price: u128,
1432    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1433    pub input_transfer_fee: u64,
1434    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1435    pub output_transfer_fee: u64,
1436    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1437    pub lp_fee: u64,
1438    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1439    pub protocol_fee: u64,
1440    // === 指令参数字段 (暂时注释,以后可能会用到,AI不要删除) ===
1441    // pub amount: u64,
1442    // pub other_amount_threshold: u64,
1443    // pub sqrt_price_limit: u128,
1444    // pub amount_specified_is_input: bool,
1445
1446    // === 指令账户字段 (暂时注释,以后可能会用到,AI不要删除) ===
1447    // pub token_authority: Pubkey,    // 1: tokenAuthority
1448    // pub token_owner_account_a: Pubkey, // 3: tokenOwnerAccountA
1449    // pub token_vault_a: Pubkey,      // 4: tokenVaultA
1450    // pub token_owner_account_b: Pubkey, // 5: tokenOwnerAccountB
1451    // pub token_vault_b: Pubkey,      // 6: tokenVaultB
1452    // pub tick_array_0: Pubkey,       // 7: tickArray0
1453    // pub tick_array_1: Pubkey,       // 8: tickArray1
1454    // pub tick_array_2: Pubkey,       // 9: tickArray2
1455}
1456
1457/// Orca Whirlpool Liquidity Increased Event
1458#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1459#[derive(Debug, Clone, Serialize, Deserialize)]
1460pub struct OrcaWhirlpoolLiquidityIncreasedEvent {
1461    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1462    pub metadata: EventMetadata,
1463
1464    // === Borsh 序列化字段(从 inner instruction data 读取)===
1465    pub whirlpool: Pubkey,       // 32 bytes
1466    pub liquidity: u128,         // 16 bytes
1467    pub token_a_amount: u64,     // 8 bytes
1468    pub token_b_amount: u64,     // 8 bytes
1469
1470    // === 非 Borsh 字段(从日志或其他来源填充)===
1471    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1472    pub position: Pubkey,
1473    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1474    pub tick_lower_index: i32,
1475    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1476    pub tick_upper_index: i32,
1477    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1478    pub token_a_transfer_fee: u64,
1479    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1480    pub token_b_transfer_fee: u64,
1481}
1482
1483/// Orca Whirlpool Liquidity Decreased Event
1484#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1485#[derive(Debug, Clone, Serialize, Deserialize)]
1486pub struct OrcaWhirlpoolLiquidityDecreasedEvent {
1487    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1488    pub metadata: EventMetadata,
1489
1490    // === Borsh 序列化字段(从 inner instruction data 读取)===
1491    pub whirlpool: Pubkey,       // 32 bytes
1492    pub liquidity: u128,         // 16 bytes
1493    pub token_a_amount: u64,     // 8 bytes
1494    pub token_b_amount: u64,     // 8 bytes
1495
1496    // === 非 Borsh 字段(从日志或其他来源填充)===
1497    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1498    pub position: Pubkey,
1499    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1500    pub tick_lower_index: i32,
1501    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1502    pub tick_upper_index: i32,
1503    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1504    pub token_a_transfer_fee: u64,
1505    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1506    pub token_b_transfer_fee: u64,
1507}
1508
1509/// Orca Whirlpool Pool Initialized Event
1510#[derive(Debug, Clone, Serialize, Deserialize)]
1511pub struct OrcaWhirlpoolPoolInitializedEvent {
1512    pub metadata: EventMetadata,
1513    pub whirlpool: Pubkey,
1514    pub whirlpools_config: Pubkey,
1515    pub token_mint_a: Pubkey,
1516    pub token_mint_b: Pubkey,
1517    pub tick_spacing: u16,
1518    pub token_program_a: Pubkey,
1519    pub token_program_b: Pubkey,
1520    pub decimals_a: u8,
1521    pub decimals_b: u8,
1522    pub initial_sqrt_price: u128,
1523}
1524
1525// ====================== Meteora Pools Events ======================
1526
1527/// Meteora Pools Swap Event
1528#[derive(Debug, Clone, Serialize, Deserialize)]
1529pub struct MeteoraPoolsSwapEvent {
1530    pub metadata: EventMetadata,
1531    pub in_amount: u64,
1532    pub out_amount: u64,
1533    pub trade_fee: u64,
1534    pub admin_fee: u64, // IDL字段名: adminFee
1535    pub host_fee: u64,
1536}
1537
1538/// Meteora Pools Add Liquidity Event
1539#[derive(Debug, Clone, Serialize, Deserialize)]
1540pub struct MeteoraPoolsAddLiquidityEvent {
1541    pub metadata: EventMetadata,
1542    pub lp_mint_amount: u64,
1543    pub token_a_amount: u64,
1544    pub token_b_amount: u64,
1545}
1546
1547/// Meteora Pools Remove Liquidity Event
1548#[derive(Debug, Clone, Serialize, Deserialize)]
1549pub struct MeteoraPoolsRemoveLiquidityEvent {
1550    pub metadata: EventMetadata,
1551    pub lp_unmint_amount: u64,
1552    pub token_a_out_amount: u64,
1553    pub token_b_out_amount: u64,
1554}
1555
1556/// Meteora Pools Bootstrap Liquidity Event
1557#[derive(Debug, Clone, Serialize, Deserialize)]
1558pub struct MeteoraPoolsBootstrapLiquidityEvent {
1559    pub metadata: EventMetadata,
1560    pub lp_mint_amount: u64,
1561    pub token_a_amount: u64,
1562    pub token_b_amount: u64,
1563    pub pool: Pubkey,
1564}
1565
1566/// Meteora Pools Pool Created Event
1567#[derive(Debug, Clone, Serialize, Deserialize)]
1568pub struct MeteoraPoolsPoolCreatedEvent {
1569    pub metadata: EventMetadata,
1570    pub lp_mint: Pubkey,
1571    pub token_a_mint: Pubkey,
1572    pub token_b_mint: Pubkey,
1573    pub pool_type: u8,
1574    pub pool: Pubkey,
1575}
1576
1577/// Meteora Pools Set Pool Fees Event
1578#[derive(Debug, Clone, Serialize, Deserialize)]
1579pub struct MeteoraPoolsSetPoolFeesEvent {
1580    pub metadata: EventMetadata,
1581    pub trade_fee_numerator: u64,
1582    pub trade_fee_denominator: u64,
1583    pub owner_trade_fee_numerator: u64, // IDL字段名: ownerTradeFeeNumerator
1584    pub owner_trade_fee_denominator: u64, // IDL字段名: ownerTradeFeeDenominator
1585    pub pool: Pubkey,
1586}
1587
1588// ====================== Meteora DAMM V2 Events ======================
1589
1590/// Meteora DAMM V2 Swap Event
1591#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1592#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1593pub struct MeteoraDammV2SwapEvent {
1594    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1595    pub metadata: EventMetadata,
1596
1597    // === Borsh 序列化字段(从 inner instruction data 读取)===
1598    pub pool: Pubkey,            // 32 bytes
1599    pub amount_in: u64,          // 8 bytes
1600    pub output_amount: u64,      // 8 bytes
1601
1602    // === 非 Borsh 字段(从日志或其他来源填充)===
1603    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1604    pub trade_direction: u8,
1605    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1606    pub has_referral: bool,
1607    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1608    pub minimum_amount_out: u64,
1609    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1610    pub next_sqrt_price: u128,
1611    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1612    pub lp_fee: u64,
1613    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1614    pub protocol_fee: u64,
1615    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1616    pub partner_fee: u64,
1617    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1618    pub referral_fee: u64,
1619    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1620    pub actual_amount_in: u64,
1621    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1622    pub current_timestamp: u64,
1623    // ---------- 账号 -------------
1624    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1625    pub token_a_vault: Pubkey,
1626    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1627    pub token_b_vault: Pubkey,
1628    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1629    pub token_a_mint: Pubkey,
1630    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1631    pub token_b_mint: Pubkey,
1632    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1633    pub token_a_program: Pubkey,
1634    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1635    pub token_b_program: Pubkey,
1636}
1637
1638/// Meteora DAMM V2 Add Liquidity Event
1639#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1640#[derive(Debug, Clone, Serialize, Deserialize)]
1641pub struct MeteoraDammV2AddLiquidityEvent {
1642    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1643    pub metadata: EventMetadata,
1644
1645    // === Borsh 序列化字段(从 inner instruction data 读取)===
1646    pub pool: Pubkey,              // 32 bytes
1647    pub position: Pubkey,          // 32 bytes
1648    pub owner: Pubkey,             // 32 bytes
1649    pub token_a_amount: u64,       // 8 bytes
1650    pub token_b_amount: u64,       // 8 bytes
1651
1652    // === 非 Borsh 字段(从日志填充)===
1653    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1654    pub liquidity_delta: u128,
1655    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1656    pub token_a_amount_threshold: u64,
1657    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1658    pub token_b_amount_threshold: u64,
1659    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1660    pub total_amount_a: u64,
1661    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1662    pub total_amount_b: u64,
1663}
1664
1665/// Meteora DAMM V2 Remove Liquidity Event
1666#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1667#[derive(Debug, Clone, Serialize, Deserialize)]
1668pub struct MeteoraDammV2RemoveLiquidityEvent {
1669    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1670    pub metadata: EventMetadata,
1671
1672    // === Borsh 序列化字段(从 inner instruction data 读取)===
1673    pub pool: Pubkey,              // 32 bytes
1674    pub position: Pubkey,          // 32 bytes
1675    pub owner: Pubkey,             // 32 bytes
1676    pub token_a_amount: u64,       // 8 bytes
1677    pub token_b_amount: u64,       // 8 bytes
1678
1679    // === 非 Borsh 字段(从日志填充)===
1680    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1681    pub liquidity_delta: u128,
1682    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1683    pub token_a_amount_threshold: u64,
1684    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1685    pub token_b_amount_threshold: u64,
1686}
1687
1688/// Meteora DAMM V2 Create Position Event
1689#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1690#[derive(Debug, Clone, Serialize, Deserialize)]
1691pub struct MeteoraDammV2CreatePositionEvent {
1692    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1693    pub metadata: EventMetadata,
1694
1695    // === Borsh 序列化字段(从 inner instruction data 读取)===
1696    pub pool: Pubkey,              // 32 bytes
1697    pub owner: Pubkey,             // 32 bytes
1698    pub position: Pubkey,          // 32 bytes
1699    pub position_nft_mint: Pubkey, // 32 bytes
1700}
1701
1702/// Meteora DAMM V2 Close Position Event
1703#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1704#[derive(Debug, Clone, Serialize, Deserialize)]
1705pub struct MeteoraDammV2ClosePositionEvent {
1706    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1707    pub metadata: EventMetadata,
1708
1709    // === Borsh 序列化字段(从 inner instruction data 读取)===
1710    pub pool: Pubkey,              // 32 bytes
1711    pub owner: Pubkey,             // 32 bytes
1712    pub position: Pubkey,          // 32 bytes
1713    pub position_nft_mint: Pubkey, // 32 bytes
1714}
1715
1716/// Meteora DLMM Swap Event
1717#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1718#[derive(Debug, Clone, Serialize, Deserialize)]
1719pub struct MeteoraDlmmSwapEvent {
1720    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1721    pub metadata: EventMetadata,
1722
1723    // === Borsh 序列化字段(从 inner instruction data 读取)===
1724    pub pool: Pubkey,        // 32 bytes
1725    pub from: Pubkey,        // 32 bytes
1726    pub start_bin_id: i32,   // 4 bytes
1727    pub end_bin_id: i32,     // 4 bytes
1728    pub amount_in: u64,      // 8 bytes
1729    pub amount_out: u64,     // 8 bytes
1730    pub swap_for_y: bool,    // 1 byte
1731    pub fee: u64,            // 8 bytes
1732    pub protocol_fee: u64,   // 8 bytes
1733    pub fee_bps: u128,       // 16 bytes
1734    pub host_fee: u64,       // 8 bytes
1735}
1736
1737/// Meteora DLMM Add Liquidity Event
1738#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1739#[derive(Debug, Clone, Serialize, Deserialize)]
1740pub struct MeteoraDlmmAddLiquidityEvent {
1741    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1742    pub metadata: EventMetadata,
1743
1744    // === Borsh 序列化字段(从 inner instruction data 读取)===
1745    pub pool: Pubkey,          // 32 bytes
1746    pub from: Pubkey,          // 32 bytes
1747    pub position: Pubkey,      // 32 bytes
1748    pub amounts: [u64; 2],     // 16 bytes (2 * 8)
1749    pub active_bin_id: i32,    // 4 bytes
1750}
1751
1752/// Meteora DLMM Remove Liquidity Event
1753#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1754#[derive(Debug, Clone, Serialize, Deserialize)]
1755pub struct MeteoraDlmmRemoveLiquidityEvent {
1756    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1757    pub metadata: EventMetadata,
1758
1759    // === Borsh 序列化字段(从 inner instruction data 读取)===
1760    pub pool: Pubkey,          // 32 bytes
1761    pub from: Pubkey,          // 32 bytes
1762    pub position: Pubkey,      // 32 bytes
1763    pub amounts: [u64; 2],     // 16 bytes (2 * 8)
1764    pub active_bin_id: i32,    // 4 bytes
1765}
1766
1767/// Meteora DLMM Initialize Pool Event
1768#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1769#[derive(Debug, Clone, Serialize, Deserialize)]
1770pub struct MeteoraDlmmInitializePoolEvent {
1771    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1772    pub metadata: EventMetadata,
1773
1774    // === Borsh 序列化字段(从 inner instruction data 读取)===
1775    pub pool: Pubkey,         // 32 bytes
1776    pub creator: Pubkey,      // 32 bytes
1777    pub active_bin_id: i32,   // 4 bytes
1778    pub bin_step: u16,        // 2 bytes
1779}
1780
1781/// Meteora DLMM Initialize Bin Array Event
1782#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1783#[derive(Debug, Clone, Serialize, Deserialize)]
1784pub struct MeteoraDlmmInitializeBinArrayEvent {
1785    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1786    pub metadata: EventMetadata,
1787
1788    // === Borsh 序列化字段(从 inner instruction data 读取)===
1789    pub pool: Pubkey,      // 32 bytes
1790    pub bin_array: Pubkey, // 32 bytes
1791    pub index: i64,        // 8 bytes
1792}
1793
1794/// Meteora DLMM Create Position Event
1795#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1796#[derive(Debug, Clone, Serialize, Deserialize)]
1797pub struct MeteoraDlmmCreatePositionEvent {
1798    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1799    pub metadata: EventMetadata,
1800
1801    // === Borsh 序列化字段(从 inner instruction data 读取)===
1802    pub pool: Pubkey,       // 32 bytes
1803    pub position: Pubkey,   // 32 bytes
1804    pub owner: Pubkey,      // 32 bytes
1805    pub lower_bin_id: i32,  // 4 bytes
1806    pub width: u32,         // 4 bytes
1807}
1808
1809/// Meteora DLMM Close Position Event
1810#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1811#[derive(Debug, Clone, Serialize, Deserialize)]
1812pub struct MeteoraDlmmClosePositionEvent {
1813    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1814    pub metadata: EventMetadata,
1815
1816    // === Borsh 序列化字段(从 inner instruction data 读取)===
1817    pub pool: Pubkey,     // 32 bytes
1818    pub position: Pubkey, // 32 bytes
1819    pub owner: Pubkey,    // 32 bytes
1820}
1821
1822/// Meteora DLMM Claim Fee Event
1823#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
1824#[derive(Debug, Clone, Serialize, Deserialize)]
1825pub struct MeteoraDlmmClaimFeeEvent {
1826    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
1827    pub metadata: EventMetadata,
1828
1829    // === Borsh 序列化字段(从 inner instruction data 读取)===
1830    pub pool: Pubkey,     // 32 bytes
1831    pub position: Pubkey, // 32 bytes
1832    pub owner: Pubkey,    // 32 bytes
1833    pub fee_x: u64,       // 8 bytes
1834    pub fee_y: u64,       // 8 bytes
1835}
1836
1837// ====================== 统一的 DEX 事件枚举 ======================
1838
1839/// 统一的 DEX 事件枚举 - 参考 sol-dex-shreds 的做法
1840#[derive(Debug, Clone, Serialize, Deserialize)]
1841pub enum DexEvent {
1842    // PumpFun 事件
1843    PumpFunCreate(PumpFunCreateTokenEvent), // - 已对接
1844    PumpFunTrade(PumpFunTradeEvent),        // - 已对接 (统一交易事件,包含所有交易类型)
1845    PumpFunBuy(PumpFunTradeEvent),          // - 已对接 (仅买入事件,用于过滤)
1846    PumpFunSell(PumpFunTradeEvent),         // - 已对接 (仅卖出事件,用于过滤)
1847    PumpFunBuyExactSolIn(PumpFunTradeEvent), // - 已对接 (精确SOL买入事件,用于过滤)
1848    PumpFunMigrate(PumpFunMigrateEvent),    // - 已对接
1849
1850    // PumpSwap 事件
1851    PumpSwapTrade(PumpSwapTradeEvent),                   // - 已对接 (buy/sell/buy_exact_sol_in)
1852    PumpSwapBuy(PumpSwapBuyEvent),                      // - 已对接 (legacy)
1853    PumpSwapSell(PumpSwapSellEvent),                    // - 已对接 (legacy)
1854    PumpSwapCreatePool(PumpSwapCreatePoolEvent),        // - 已对接
1855    PumpSwapLiquidityAdded(PumpSwapLiquidityAdded),     // - 已对接
1856    PumpSwapLiquidityRemoved(PumpSwapLiquidityRemoved), // - 已对接
1857
1858    // Meteora DAMM V2 事件
1859    MeteoraDammV2Swap(MeteoraDammV2SwapEvent), // - 已对接
1860    MeteoraDammV2CreatePosition(MeteoraDammV2CreatePositionEvent), // - 已对接
1861    MeteoraDammV2ClosePosition(MeteoraDammV2ClosePositionEvent), // - 已对接
1862    MeteoraDammV2AddLiquidity(MeteoraDammV2AddLiquidityEvent), // - 已对接
1863    MeteoraDammV2RemoveLiquidity(MeteoraDammV2RemoveLiquidityEvent), // - 已对接
1864
1865    // Bonk 事件
1866    BonkTrade(BonkTradeEvent),
1867    BonkPoolCreate(BonkPoolCreateEvent),
1868    BonkMigrateAmm(BonkMigrateAmmEvent),
1869
1870    // Raydium CLMM 事件
1871    RaydiumClmmSwap(RaydiumClmmSwapEvent),
1872    RaydiumClmmCreatePool(RaydiumClmmCreatePoolEvent),
1873    RaydiumClmmOpenPosition(RaydiumClmmOpenPositionEvent),
1874    RaydiumClmmOpenPositionWithTokenExtNft(RaydiumClmmOpenPositionWithTokenExtNftEvent),
1875    RaydiumClmmClosePosition(RaydiumClmmClosePositionEvent),
1876    RaydiumClmmIncreaseLiquidity(RaydiumClmmIncreaseLiquidityEvent),
1877    RaydiumClmmDecreaseLiquidity(RaydiumClmmDecreaseLiquidityEvent),
1878    RaydiumClmmCollectFee(RaydiumClmmCollectFeeEvent),
1879
1880    // Raydium CPMM 事件
1881    RaydiumCpmmSwap(RaydiumCpmmSwapEvent),
1882    RaydiumCpmmDeposit(RaydiumCpmmDepositEvent),
1883    RaydiumCpmmWithdraw(RaydiumCpmmWithdrawEvent),
1884    RaydiumCpmmInitialize(RaydiumCpmmInitializeEvent),
1885
1886    // Raydium AMM V4 事件
1887    RaydiumAmmV4Swap(RaydiumAmmV4SwapEvent),
1888    RaydiumAmmV4Deposit(RaydiumAmmV4DepositEvent),
1889    RaydiumAmmV4Initialize2(RaydiumAmmV4Initialize2Event),
1890    RaydiumAmmV4Withdraw(RaydiumAmmV4WithdrawEvent),
1891    RaydiumAmmV4WithdrawPnl(RaydiumAmmV4WithdrawPnlEvent),
1892
1893    // Orca Whirlpool 事件
1894    OrcaWhirlpoolSwap(OrcaWhirlpoolSwapEvent),
1895    OrcaWhirlpoolLiquidityIncreased(OrcaWhirlpoolLiquidityIncreasedEvent),
1896    OrcaWhirlpoolLiquidityDecreased(OrcaWhirlpoolLiquidityDecreasedEvent),
1897    OrcaWhirlpoolPoolInitialized(OrcaWhirlpoolPoolInitializedEvent),
1898
1899    // Meteora Pools 事件
1900    MeteoraPoolsSwap(MeteoraPoolsSwapEvent),
1901    MeteoraPoolsAddLiquidity(MeteoraPoolsAddLiquidityEvent),
1902    MeteoraPoolsRemoveLiquidity(MeteoraPoolsRemoveLiquidityEvent),
1903    MeteoraPoolsBootstrapLiquidity(MeteoraPoolsBootstrapLiquidityEvent),
1904    MeteoraPoolsPoolCreated(MeteoraPoolsPoolCreatedEvent),
1905    MeteoraPoolsSetPoolFees(MeteoraPoolsSetPoolFeesEvent),
1906
1907    // Meteora DLMM 事件
1908    MeteoraDlmmSwap(MeteoraDlmmSwapEvent),
1909    MeteoraDlmmAddLiquidity(MeteoraDlmmAddLiquidityEvent),
1910    MeteoraDlmmRemoveLiquidity(MeteoraDlmmRemoveLiquidityEvent),
1911    MeteoraDlmmInitializePool(MeteoraDlmmInitializePoolEvent),
1912    MeteoraDlmmInitializeBinArray(MeteoraDlmmInitializeBinArrayEvent),
1913    MeteoraDlmmCreatePosition(MeteoraDlmmCreatePositionEvent),
1914    MeteoraDlmmClosePosition(MeteoraDlmmClosePositionEvent),
1915    MeteoraDlmmClaimFee(MeteoraDlmmClaimFeeEvent),
1916
1917    // 账户事件
1918    TokenInfo(TokenInfoEvent),  // - 已对接
1919    TokenAccount(TokenAccountEvent), // - 已对接
1920    NonceAccount(NonceAccountEvent), // - 已对接
1921    PumpSwapGlobalConfigAccount(PumpSwapGlobalConfigAccountEvent), // - 已对接
1922    PumpSwapPoolAccount(PumpSwapPoolAccountEvent), // - 已对接
1923
1924    // 区块元数据事件
1925    BlockMeta(BlockMetaEvent),
1926
1927    // 错误事件
1928    Error(String),
1929}
1930
1931// 静态默认 EventMetadata,用于 Error 事件
1932use once_cell::sync::Lazy;
1933static DEFAULT_METADATA: Lazy<EventMetadata> = Lazy::new(|| EventMetadata {
1934    signature: Signature::from([0u8; 64]),
1935    slot: 0,
1936    tx_index: 0,
1937    block_time_us: 0,
1938    grpc_recv_us: 0,
1939});
1940
1941impl DexEvent {
1942    /// 获取事件的元数据
1943    pub fn metadata(&self) -> &EventMetadata {
1944        match self {
1945            // PumpFun 事件
1946            DexEvent::PumpFunCreate(e) => &e.metadata,
1947            DexEvent::PumpFunTrade(e) => &e.metadata,
1948            DexEvent::PumpFunBuy(e) => &e.metadata,
1949            DexEvent::PumpFunSell(e) => &e.metadata,
1950            DexEvent::PumpFunBuyExactSolIn(e) => &e.metadata,
1951            DexEvent::PumpFunMigrate(e) => &e.metadata,
1952
1953            // PumpSwap 事件
1954            DexEvent::PumpSwapTrade(e) => &e.metadata,
1955            DexEvent::PumpSwapBuy(e) => &e.metadata,
1956            DexEvent::PumpSwapSell(e) => &e.metadata,
1957            DexEvent::PumpSwapCreatePool(e) => &e.metadata,
1958            DexEvent::PumpSwapLiquidityAdded(e) => &e.metadata,
1959            DexEvent::PumpSwapLiquidityRemoved(e) => &e.metadata,
1960
1961            // Meteora DAMM V2 事件
1962            DexEvent::MeteoraDammV2Swap(e) => &e.metadata,
1963            DexEvent::MeteoraDammV2CreatePosition(e) => &e.metadata,
1964            DexEvent::MeteoraDammV2ClosePosition(e) => &e.metadata,
1965            DexEvent::MeteoraDammV2AddLiquidity(e) => &e.metadata,
1966            DexEvent::MeteoraDammV2RemoveLiquidity(e) => &e.metadata,
1967
1968            // Bonk 事件
1969            DexEvent::BonkTrade(e) => &e.metadata,
1970            DexEvent::BonkPoolCreate(e) => &e.metadata,
1971            DexEvent::BonkMigrateAmm(e) => &e.metadata,
1972
1973            // Raydium CLMM 事件
1974            DexEvent::RaydiumClmmSwap(e) => &e.metadata,
1975            DexEvent::RaydiumClmmCreatePool(e) => &e.metadata,
1976            DexEvent::RaydiumClmmOpenPosition(e) => &e.metadata,
1977            DexEvent::RaydiumClmmOpenPositionWithTokenExtNft(e) => &e.metadata,
1978            DexEvent::RaydiumClmmClosePosition(e) => &e.metadata,
1979            DexEvent::RaydiumClmmIncreaseLiquidity(e) => &e.metadata,
1980            DexEvent::RaydiumClmmDecreaseLiquidity(e) => &e.metadata,
1981            DexEvent::RaydiumClmmCollectFee(e) => &e.metadata,
1982
1983            // Raydium CPMM 事件
1984            DexEvent::RaydiumCpmmSwap(e) => &e.metadata,
1985            DexEvent::RaydiumCpmmDeposit(e) => &e.metadata,
1986            DexEvent::RaydiumCpmmWithdraw(e) => &e.metadata,
1987            DexEvent::RaydiumCpmmInitialize(e) => &e.metadata,
1988
1989            // Raydium AMM V4 事件
1990            DexEvent::RaydiumAmmV4Swap(e) => &e.metadata,
1991            DexEvent::RaydiumAmmV4Deposit(e) => &e.metadata,
1992            DexEvent::RaydiumAmmV4Initialize2(e) => &e.metadata,
1993            DexEvent::RaydiumAmmV4Withdraw(e) => &e.metadata,
1994            DexEvent::RaydiumAmmV4WithdrawPnl(e) => &e.metadata,
1995
1996            // Orca Whirlpool 事件
1997            DexEvent::OrcaWhirlpoolSwap(e) => &e.metadata,
1998            DexEvent::OrcaWhirlpoolLiquidityIncreased(e) => &e.metadata,
1999            DexEvent::OrcaWhirlpoolLiquidityDecreased(e) => &e.metadata,
2000            DexEvent::OrcaWhirlpoolPoolInitialized(e) => &e.metadata,
2001
2002            // Meteora Pools 事件
2003            DexEvent::MeteoraPoolsSwap(e) => &e.metadata,
2004            DexEvent::MeteoraPoolsAddLiquidity(e) => &e.metadata,
2005            DexEvent::MeteoraPoolsRemoveLiquidity(e) => &e.metadata,
2006            DexEvent::MeteoraPoolsBootstrapLiquidity(e) => &e.metadata,
2007            DexEvent::MeteoraPoolsPoolCreated(e) => &e.metadata,
2008            DexEvent::MeteoraPoolsSetPoolFees(e) => &e.metadata,
2009
2010            // Meteora DLMM 事件
2011            DexEvent::MeteoraDlmmSwap(e) => &e.metadata,
2012            DexEvent::MeteoraDlmmAddLiquidity(e) => &e.metadata,
2013            DexEvent::MeteoraDlmmRemoveLiquidity(e) => &e.metadata,
2014            DexEvent::MeteoraDlmmInitializePool(e) => &e.metadata,
2015            DexEvent::MeteoraDlmmInitializeBinArray(e) => &e.metadata,
2016            DexEvent::MeteoraDlmmCreatePosition(e) => &e.metadata,
2017            DexEvent::MeteoraDlmmClosePosition(e) => &e.metadata,
2018            DexEvent::MeteoraDlmmClaimFee(e) => &e.metadata,
2019
2020            // 账户事件
2021            DexEvent::TokenInfo(e) => &e.metadata,
2022            DexEvent::TokenAccount(e) => &e.metadata,
2023            DexEvent::NonceAccount(e) => &e.metadata,
2024            DexEvent::PumpSwapGlobalConfigAccount(e) => &e.metadata,
2025            DexEvent::PumpSwapPoolAccount(e) => &e.metadata,
2026
2027            // 区块元数据事件
2028            DexEvent::BlockMeta(e) => &e.metadata,
2029
2030            // 错误事件 - 返回默认元数据
2031            DexEvent::Error(_) => &DEFAULT_METADATA,
2032        }
2033    }
2034}