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