sol-parser-sdk 0.3.1

A lightweight Rust library for real-time event streaming from Solana DEX trading programs. Supports PumpFun, PumpSwap, Bonk, and Raydium protocols with Yellowstone gRPC and ShredStream.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
//! 所有具体的事件类型定义
//!
//! 基于您提供的回调事件列表,定义所有需要的具体事件类型

// use prost_types::Timestamp;
use borsh::BorshDeserialize;
use serde::{Deserialize, Serialize};
use solana_sdk::{pubkey::Pubkey, signature::Signature};

/// 基础元数据 - 所有事件共享的字段
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EventMetadata {
    pub signature: Signature,
    pub slot: u64,
    pub tx_index: u64, // 交易在slot中的索引,参考solana-streamer
    pub block_time_us: i64,
    pub grpc_recv_us: i64,
    /// Transaction's recent blockhash as base58 string, when available.
    #[serde(default)]
    pub recent_blockhash: Option<String>,
}

/// Block Meta Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockMetaEvent {
    pub metadata: EventMetadata,
}

/// Bonk Pool Create Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkPoolCreateEvent {
    pub metadata: EventMetadata,
    pub base_mint_param: BaseMintParam,
    pub pool_state: Pubkey,
    pub creator: Pubkey,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BaseMintParam {
    pub symbol: String,
    pub name: String,
    pub uri: String,
    pub decimals: u8,
}

/// Bonk Trade Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkTradeEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool_state: Pubkey, // 32 bytes
    pub user: Pubkey,       // 32 bytes
    pub amount_in: u64,     // 8 bytes
    pub amount_out: u64,    // 8 bytes
    pub is_buy: bool,       // 1 byte

    // === 非 Borsh 字段(派生字段)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub trade_direction: TradeDirection,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub exact_in: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub enum TradeDirection {
    #[default]
    Buy,
    Sell,
}

/// Bonk Migrate AMM Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkMigrateAmmEvent {
    pub metadata: EventMetadata,
    pub old_pool: Pubkey,
    pub new_pool: Pubkey,
    pub user: Pubkey,
    pub liquidity_amount: u64,
}

/// PumpFun Trade Event - 基于官方IDL定义
///
/// 字段来源标记:
/// - [EVENT]: 来自原始IDL事件定义,由程序日志直接解析获得
/// - [INSTRUCTION]: 来自指令解析,用于补充事件缺失的上下文信息
#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
pub struct PumpFunTradeEvent {
    #[borsh(skip)]
    pub metadata: EventMetadata,

    // === IDL TradeEvent 事件字段(Borsh 序列化字段,按顺序)===
    pub mint: Pubkey,
    pub sol_amount: u64,
    pub token_amount: u64,
    pub is_buy: bool,
    #[borsh(skip)]
    pub is_created_buy: bool, // 由外层逻辑设置,不在 Borsh 数据中
    pub user: Pubkey,
    pub timestamp: i64,
    pub virtual_sol_reserves: u64,
    pub virtual_token_reserves: u64,
    pub real_sol_reserves: u64,
    pub real_token_reserves: u64,
    pub fee_recipient: Pubkey,
    pub fee_basis_points: u64,
    pub fee: u64,
    pub creator: Pubkey,
    pub creator_fee_basis_points: u64,
    pub creator_fee: u64,
    pub track_volume: bool,
    pub total_unclaimed_tokens: u64,
    pub total_claimed_tokens: u64,
    pub current_sol_volume: u64,
    pub last_update_timestamp: i64,
    /// Instruction name: "buy" | "sell" | "buy_exact_sol_in"
    pub ix_name: String,
    /// 与链上 / Explorer `tradeEvent` 中 `mayhemMode` 一致(gRPC 日志解析填充;勿用 fee 地址推断)。
    pub mayhem_mode: bool,
    /// Cashback fee basis points (PUMP_CASHBACK_README)
    pub cashback_fee_basis_points: u64,
    /// Cashback amount (PUMP_CASHBACK_README)
    pub cashback: u64,
    /// 是否返现代币(由 cashback_fee_basis_points > 0 推导,供 sol-trade-sdk 等构造 sell 指令用)
    #[borsh(skip)]
    pub is_cashback_coin: bool,

    // === Instruction parameter fields (reserved for future use, DO NOT delete) ===
    // pub amount: u64,                     // buy/sell.args.amount
    // pub max_sol_cost: u64,               // buy.args.maxSolCost
    // pub min_sol_output: u64,             // sell.args.minSolOutput

    // === 指令账户字段 (从指令账户填充,不在 Borsh 数据中) ===
    // pub global: Pubkey,                  // 0
    #[borsh(skip)]
    pub bonding_curve: Pubkey, // 3
    #[borsh(skip)]
    pub associated_bonding_curve: Pubkey, // 4
    // pub associated_user: Pubkey,         // 5
    #[borsh(skip)]
    pub token_program: Pubkey, // sell - 9 / buy - 8
    #[borsh(skip)]
    pub creator_vault: Pubkey, // sell - 8 / buy - 9
    /// 第 17 个指令账户 (index 16),区块浏览器显示为 "Account",部分 buy/sell 会传入
    #[borsh(skip)]
    pub account: Option<Pubkey>,
}

/// PumpFun Migrate Event
#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
pub struct PumpFunMigrateEvent {
    #[borsh(skip)]
    pub metadata: EventMetadata,
    // Borsh 序列化字段(按顺序)
    pub user: Pubkey,
    pub mint: Pubkey,
    pub mint_amount: u64,
    pub sol_amount: u64,
    pub pool_migration_fee: u64,
    pub bonding_curve: Pubkey,
    pub timestamp: i64,
    pub pool: Pubkey,
    // === 额外账户信息(用于指令解析,暂时注释,以后可能会用到,AI不要删除) ===
    // pub global: Pubkey,
    // pub withdraw_authority: Pubkey,
    // pub associated_bonding_curve: Pubkey,
    // pub pump_amm: Pubkey,
    // pub pool_authority: Pubkey,
    // pub pool_authority_mint_account: Pubkey,
    // pub pool_authority_wsol_account: Pubkey,
    // pub amm_global_config: Pubkey,
    // pub wsol_mint: Pubkey,
    // pub lp_mint: Pubkey,
    // pub user_pool_token_account: Pubkey,
    // pub pool_base_token_account: Pubkey,
    // pub pool_quote_token_account: Pubkey,
}

/// PumpFun Create Token Event - Based on IDL CreateEvent definition
#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
pub struct PumpFunCreateTokenEvent {
    #[borsh(skip)]
    pub metadata: EventMetadata,
    // IDL CreateEvent 字段(Borsh 序列化字段,按顺序)
    pub name: String,
    pub symbol: String,
    pub uri: String,
    pub mint: Pubkey,
    pub bonding_curve: Pubkey,
    pub user: Pubkey,
    pub creator: Pubkey,
    pub timestamp: i64,
    pub virtual_token_reserves: u64,
    pub virtual_sol_reserves: u64,
    pub real_token_reserves: u64,
    pub token_total_supply: u64,

    pub token_program: Pubkey,
    pub is_mayhem_mode: bool,
    /// Cashback 是否开启 (IDL CreateEvent.is_cashback_enabled)
    pub is_cashback_enabled: bool,
}

/// PumpFun Create V2 Token Event (SPL-22 / Mayhem Mode)
/// 与 solana-streamer 对齐;指令解析时从 accounts 0..15 填充。
#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
pub struct PumpFunCreateV2TokenEvent {
    #[borsh(skip)]
    pub metadata: EventMetadata,
    pub name: String,
    pub symbol: String,
    pub uri: String,
    pub mint: Pubkey,
    pub bonding_curve: Pubkey,
    pub user: Pubkey,
    pub creator: Pubkey,
    pub timestamp: i64,
    pub virtual_token_reserves: u64,
    pub virtual_sol_reserves: u64,
    pub real_token_reserves: u64,
    pub token_total_supply: u64,
    pub token_program: Pubkey,
    pub is_mayhem_mode: bool,
    pub is_cashback_enabled: bool,
    #[borsh(skip)]
    pub mint_authority: Pubkey,
    #[borsh(skip)]
    pub associated_bonding_curve: Pubkey,
    #[borsh(skip)]
    pub global: Pubkey,
    #[borsh(skip)]
    pub system_program: Pubkey,
    #[borsh(skip)]
    pub associated_token_program: Pubkey,
    #[borsh(skip)]
    pub mayhem_program_id: Pubkey,
    #[borsh(skip)]
    pub global_params: Pubkey,
    #[borsh(skip)]
    pub sol_vault: Pubkey,
    #[borsh(skip)]
    pub mayhem_state: Pubkey,
    #[borsh(skip)]
    pub mayhem_token_vault: Pubkey,
    #[borsh(skip)]
    pub event_authority: Pubkey,
    #[borsh(skip)]
    pub program: Pubkey,
    /// 同笔交易中后续 Pump Buy 的账户 #2(或 trade 日志中的 fee recipient);由 `pumpfun_fee_enrich` 回填。
    #[borsh(skip)]
    pub observed_fee_recipient: Pubkey,
}

/// PumpSwap Trade Event - Unified trade event from IDL TradeEvent
/// Produced by: buy, sell, buy_exact_sol_in instructions
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapTradeEvent {
    pub metadata: EventMetadata,
    // === IDL TradeEvent fields ===
    pub mint: Pubkey,
    pub sol_amount: u64,
    pub token_amount: u64,
    pub is_buy: bool,
    pub user: Pubkey,
    pub timestamp: i64,
    pub virtual_sol_reserves: u64,
    pub virtual_token_reserves: u64,
    pub real_sol_reserves: u64,
    pub real_token_reserves: u64,
    pub fee_recipient: Pubkey,
    pub fee_basis_points: u64,
    pub fee: u64,
    pub creator: Pubkey,
    pub creator_fee_basis_points: u64,
    pub creator_fee: u64,
    pub track_volume: bool,
    pub total_unclaimed_tokens: u64,
    pub total_claimed_tokens: u64,
    pub current_sol_volume: u64,
    pub last_update_timestamp: i64,
    pub ix_name: String, // "buy" | "sell" | "buy_exact_sol_in"
}

/// PumpSwap Buy Event
#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
pub struct PumpSwapBuyEvent {
    #[borsh(skip)]
    pub metadata: EventMetadata,
    pub timestamp: i64,
    pub base_amount_out: u64,
    pub max_quote_amount_in: u64,
    pub user_base_token_reserves: u64,
    pub user_quote_token_reserves: u64,
    pub pool_base_token_reserves: u64,
    pub pool_quote_token_reserves: u64,
    pub quote_amount_in: u64,
    pub lp_fee_basis_points: u64,
    pub lp_fee: u64,
    pub protocol_fee_basis_points: u64,
    pub protocol_fee: u64,
    pub quote_amount_in_with_lp_fee: u64,
    pub user_quote_amount_in: u64,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub user_base_token_account: Pubkey,
    pub user_quote_token_account: Pubkey,
    pub protocol_fee_recipient: Pubkey,
    pub protocol_fee_recipient_token_account: Pubkey,
    pub coin_creator: Pubkey,
    pub coin_creator_fee_basis_points: u64,
    pub coin_creator_fee: u64,
    pub track_volume: bool,
    pub total_unclaimed_tokens: u64,
    pub total_claimed_tokens: u64,
    pub current_sol_volume: u64,
    pub last_update_timestamp: i64,
    /// Minimum base token amount expected (new field from IDL update)
    pub min_base_amount_out: u64,
    /// Instruction name (new field from IDL update)
    pub ix_name: String,
    /// Cashback fee basis points (PUMP_CASHBACK_README)
    pub cashback_fee_basis_points: u64,
    /// Cashback amount (PUMP_CASHBACK_README)
    pub cashback: u64,

    // === 额外的信息 ===
    #[borsh(skip)]
    pub is_pump_pool: bool,

    // === 额外账户信息 (from instruction accounts, not event data) ===
    #[borsh(skip)]
    pub base_mint: Pubkey,
    #[borsh(skip)]
    pub quote_mint: Pubkey,
    #[borsh(skip)]
    pub pool_base_token_account: Pubkey,
    #[borsh(skip)]
    pub pool_quote_token_account: Pubkey,
    #[borsh(skip)]
    pub coin_creator_vault_ata: Pubkey,
    #[borsh(skip)]
    pub coin_creator_vault_authority: Pubkey,
    #[borsh(skip)]
    pub base_token_program: Pubkey,
    #[borsh(skip)]
    pub quote_token_program: Pubkey,
}

/// PumpSwap Sell Event
#[derive(Debug, Clone, Serialize, Deserialize, Default, BorshDeserialize)]
pub struct PumpSwapSellEvent {
    #[borsh(skip)]
    pub metadata: EventMetadata,
    pub timestamp: i64,
    pub base_amount_in: u64,
    pub min_quote_amount_out: u64,
    pub user_base_token_reserves: u64,
    pub user_quote_token_reserves: u64,
    pub pool_base_token_reserves: u64,
    pub pool_quote_token_reserves: u64,
    pub quote_amount_out: u64,
    pub lp_fee_basis_points: u64,
    pub lp_fee: u64,
    pub protocol_fee_basis_points: u64,
    pub protocol_fee: u64,
    pub quote_amount_out_without_lp_fee: u64,
    pub user_quote_amount_out: u64,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub user_base_token_account: Pubkey,
    pub user_quote_token_account: Pubkey,
    pub protocol_fee_recipient: Pubkey,
    pub protocol_fee_recipient_token_account: Pubkey,
    pub coin_creator: Pubkey,
    pub coin_creator_fee_basis_points: u64,
    pub coin_creator_fee: u64,
    /// Cashback fee basis points (PUMP_CASHBACK_README)
    pub cashback_fee_basis_points: u64,
    /// Cashback amount (PUMP_CASHBACK_README)
    pub cashback: u64,

    // === 额外的信息 ===
    #[borsh(skip)]
    pub is_pump_pool: bool,

    // === 额外账户信息 (from instruction accounts, not event data) ===
    #[borsh(skip)]
    pub base_mint: Pubkey,
    #[borsh(skip)]
    pub quote_mint: Pubkey,
    #[borsh(skip)]
    pub pool_base_token_account: Pubkey,
    #[borsh(skip)]
    pub pool_quote_token_account: Pubkey,
    #[borsh(skip)]
    pub coin_creator_vault_ata: Pubkey,
    #[borsh(skip)]
    pub coin_creator_vault_authority: Pubkey,
    #[borsh(skip)]
    pub base_token_program: Pubkey,
    #[borsh(skip)]
    pub quote_token_program: Pubkey,
}

/// PumpSwap Create Pool Event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapCreatePoolEvent {
    pub metadata: EventMetadata,
    pub timestamp: i64,
    pub index: u16,
    pub creator: Pubkey,
    pub base_mint: Pubkey,
    pub quote_mint: Pubkey,
    pub base_mint_decimals: u8,
    pub quote_mint_decimals: u8,
    pub base_amount_in: u64,
    pub quote_amount_in: u64,
    pub pool_base_amount: u64,
    pub pool_quote_amount: u64,
    pub minimum_liquidity: u64,
    pub initial_liquidity: u64,
    pub lp_token_amount_out: u64,
    pub pool_bump: u8,
    pub pool: Pubkey,
    pub lp_mint: Pubkey,
    pub user_base_token_account: Pubkey,
    pub user_quote_token_account: Pubkey,
    pub coin_creator: Pubkey,
    /// IDL CreatePoolEvent 最后一列
    pub is_mayhem_mode: bool,
}

/// PumpSwap Pool Created Event - 指令解析版本
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpSwapPoolCreated {
    pub metadata: EventMetadata,
    pub pool_account: Pubkey,
    pub token_a_mint: Pubkey,
    pub token_b_mint: Pubkey,
    pub token_a_vault: Pubkey,
    pub token_b_vault: Pubkey,
    pub lp_mint: Pubkey,
    pub creator: Pubkey,
    pub authority: Pubkey,
    pub initial_token_a_amount: u64,
    pub initial_token_b_amount: u64,
}

/// PumpSwap Trade Event - 指令解析版本
// #[derive(Debug, Clone, Serialize, Deserialize)]
// pub struct PumpSwapTrade {
//     pub metadata: EventMetadata,
//     pub pool_account: Pubkey,
//     pub user: Pubkey,
//     pub user_token_in_account: Pubkey,
//     pub user_token_out_account: Pubkey,
//     pub pool_token_in_vault: Pubkey,
//     pub pool_token_out_vault: Pubkey,
//     pub token_in_mint: Pubkey,
//     pub token_out_mint: Pubkey,
//     pub amount_in: u64,
//     pub minimum_amount_out: u64,
//     pub is_token_a_to_b: bool,
// }

/// PumpSwap Liquidity Added Event - Instruction parsing version
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapLiquidityAdded {
    pub metadata: EventMetadata,
    pub timestamp: i64,
    pub lp_token_amount_out: u64,
    pub max_base_amount_in: u64,
    pub max_quote_amount_in: u64,
    pub user_base_token_reserves: u64,
    pub user_quote_token_reserves: u64,
    pub pool_base_token_reserves: u64,
    pub pool_quote_token_reserves: u64,
    pub base_amount_in: u64,
    pub quote_amount_in: u64,
    pub lp_mint_supply: u64,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub user_base_token_account: Pubkey,
    pub user_quote_token_account: Pubkey,
    pub user_pool_token_account: Pubkey,
}

/// PumpSwap Liquidity Removed Event - Instruction parsing version
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapLiquidityRemoved {
    pub metadata: EventMetadata,
    pub timestamp: i64,
    pub lp_token_amount_in: u64,
    pub min_base_amount_out: u64,
    pub min_quote_amount_out: u64,
    pub user_base_token_reserves: u64,
    pub user_quote_token_reserves: u64,
    pub pool_base_token_reserves: u64,
    pub pool_quote_token_reserves: u64,
    pub base_amount_out: u64,
    pub quote_amount_out: u64,
    pub lp_mint_supply: u64,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub user_base_token_account: Pubkey,
    pub user_quote_token_account: Pubkey,
    pub user_pool_token_account: Pubkey,
}

/// PumpSwap Pool Updated Event - 指令解析版本
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpSwapPoolUpdated {
    pub metadata: EventMetadata,
    pub pool_account: Pubkey,
    pub authority: Pubkey,
    pub admin: Pubkey,
    pub new_fee_rate: u64,
}

/// PumpSwap Fees Claimed Event - 指令解析版本
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpSwapFeesClaimed {
    pub metadata: EventMetadata,
    pub pool_account: Pubkey,
    pub authority: Pubkey,
    pub admin: Pubkey,
    pub admin_token_a_account: Pubkey,
    pub admin_token_b_account: Pubkey,
    pub pool_fee_vault: Pubkey,
}

/// PumpSwap Deposit Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpSwapDepositEvent {
    pub metadata: EventMetadata,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub amount: u64,
}

/// PumpSwap Withdraw Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpSwapWithdrawEvent {
    pub metadata: EventMetadata,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub amount: u64,
}

/// Raydium CPMM Swap Event (基于IDL SwapEvent + swapBaseInput指令定义)
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmSwapEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub pool_id: Pubkey,
    pub input_amount: u64,
    pub output_amount: u64,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub input_vault_before: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub output_vault_before: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub input_transfer_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub output_transfer_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub base_input: bool,
    // === 指令参数字段 (暂时注释,以后可能会用到,AI不要删除) ===
    // pub amount_in: u64,
    // pub minimum_amount_out: u64,

    // === 指令账户字段 (暂时注释,以后可能会用到,AI不要删除) ===
    // pub payer: Pubkey,              // 0: payer
    // pub authority: Pubkey,          // 1: authority
    // pub amm_config: Pubkey,         // 2: ammConfig
    // pub pool_state: Pubkey,         // 3: poolState
    // pub input_token_account: Pubkey, // 4: inputTokenAccount
    // pub output_token_account: Pubkey, // 5: outputTokenAccount
    // pub input_vault: Pubkey,        // 6: inputVault
    // pub output_vault: Pubkey,       // 7: outputVault
    // pub input_token_mint: Pubkey,   // 10: inputTokenMint
    // pub output_token_mint: Pubkey,  // 11: outputTokenMint
}

/// Raydium CPMM Deposit Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmDepositEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub pool: Pubkey,
    pub token0_amount: u64,
    pub token1_amount: u64,
    pub lp_token_amount: u64,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user: Pubkey,
}

/// Raydium CPMM Initialize Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmInitializeEvent {
    pub metadata: EventMetadata,
    pub pool: Pubkey,
    pub creator: Pubkey,
    pub init_amount0: u64,
    pub init_amount1: u64,
}

/// Raydium CPMM Withdraw Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmWithdrawEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub pool: Pubkey,
    pub lp_token_amount: u64,
    pub token0_amount: u64,
    pub token1_amount: u64,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user: Pubkey,
}

/// Raydium CLMM Swap Event (基于IDL SwapEvent + swap指令定义)
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmSwapEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === IDL SwapEvent 事件字段 (Borsh 序列化字段) ===
    pub pool_state: Pubkey,
    pub token_account_0: Pubkey,
    pub token_account_1: Pubkey,
    pub amount_0: u64,
    pub amount_1: u64,
    pub zero_for_one: bool,
    pub sqrt_price_x64: u128,
    pub liquidity: u128,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub sender: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub transfer_fee_0: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub transfer_fee_1: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub tick: i32,
    // === 指令参数字段 (暂时注释,以后可能会用到,AI不要删除) ===
    // pub amount: u64,
    // pub other_amount_threshold: u64,
    // pub sqrt_price_limit_x64: u128,
    // pub is_base_input: bool,

    // === 指令账户字段 (暂时注释,以后可能会用到,AI不要删除) ===
    // TODO: 根据Raydium CLMM swap指令IDL添加账户字段
}

/// Raydium CLMM Close Position Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmClosePositionEvent {
    pub metadata: EventMetadata,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub position_nft_mint: Pubkey,
}

/// Raydium CLMM Decrease Liquidity Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmDecreaseLiquidityEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段 ===
    pub pool: Pubkey,
    pub position_nft_mint: Pubkey,
    pub amount0_min: u64,
    pub amount1_min: u64,
    pub liquidity: u128,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user: Pubkey,
}

/// Raydium CLMM Collect Fee Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmCollectFeeEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段 ===
    pub pool_state: Pubkey,
    pub position_nft_mint: Pubkey,
    pub amount_0: u64,
    pub amount_1: u64,
}

/// Raydium CLMM Create Pool Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmCreatePoolEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub pool: Pubkey,
    pub token_0_mint: Pubkey,
    pub token_1_mint: Pubkey,
    pub tick_spacing: u16,
    pub fee_rate: u32,
    pub sqrt_price_x64: u128,

    // === 非 Borsh 字段(从指令或账户) ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub creator: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub open_time: u64,
}

/// Raydium CLMM Increase Liquidity Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmIncreaseLiquidityEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段 ===
    pub pool: Pubkey,
    pub position_nft_mint: Pubkey,
    pub amount0_max: u64,
    pub amount1_max: u64,
    pub liquidity: u128,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user: Pubkey,
}

/// Raydium CLMM Open Position with Token Extension NFT Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmOpenPositionWithTokenExtNftEvent {
    pub metadata: EventMetadata,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub position_nft_mint: Pubkey,
    pub tick_lower_index: i32,
    pub tick_upper_index: i32,
    pub liquidity: u128,
}

/// Raydium CLMM Open Position Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmOpenPositionEvent {
    pub metadata: EventMetadata,
    pub pool: Pubkey,
    pub user: Pubkey,
    pub position_nft_mint: Pubkey,
    pub tick_lower_index: i32,
    pub tick_upper_index: i32,
    pub liquidity: u128,
}

/// Raydium AMM V4 Deposit Event (简化版)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmDepositEvent {
    pub metadata: EventMetadata,
    pub amm_id: Pubkey,
    pub user: Pubkey,
    pub max_coin_amount: u64,
    pub max_pc_amount: u64,
}

/// Raydium AMM V4 Initialize Alt Event (简化版)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmInitializeAltEvent {
    pub metadata: EventMetadata,
    pub amm_id: Pubkey,
    pub creator: Pubkey,
    pub nonce: u8,
    pub open_time: u64,
}

/// Raydium AMM V4 Withdraw Event (简化版)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmWithdrawEvent {
    pub metadata: EventMetadata,
    pub amm_id: Pubkey,
    pub user: Pubkey,
    pub pool_coin_amount: u64,
}

/// Raydium AMM V4 Withdraw PnL Event (简化版)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmWithdrawPnlEvent {
    pub metadata: EventMetadata,
    pub amm_id: Pubkey,
    pub user: Pubkey,
}

// ====================== Raydium AMM V4 Events ======================

/// Raydium AMM V4 Swap Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmV4SwapEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub amm: Pubkey,
    pub amount_in: u64,
    pub amount_out: u64,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub minimum_amount_out: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub max_amount_in: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_program: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_authority: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_open_orders: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_target_orders: Option<Pubkey>,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_coin_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_pc_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_program: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_market: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_bids: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_asks: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_event_queue: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_coin_vault_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_pc_vault_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_vault_signer: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_source_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_destination_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_source_owner: Pubkey,
}

/// Raydium AMM V4 Deposit Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmV4DepositEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub amm: Pubkey,
    pub max_coin_amount: u64,
    pub max_pc_amount: u64,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub base_side: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_program: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_authority: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_open_orders: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_target_orders: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub lp_mint_address: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_coin_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_pc_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_market: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_coin_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_pc_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_lp_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_owner: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_event_queue: Pubkey,
}

/// Raydium AMM V4 Initialize2 Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmV4Initialize2Event {
    pub metadata: EventMetadata,
    pub nonce: u8,
    pub open_time: u64,
    pub init_pc_amount: u64,
    pub init_coin_amount: u64,

    pub token_program: Pubkey,
    pub spl_associated_token_account: Pubkey,
    pub system_program: Pubkey,
    pub rent: Pubkey,
    pub amm: Pubkey,
    pub amm_authority: Pubkey,
    pub amm_open_orders: Pubkey,
    pub lp_mint: Pubkey,
    pub coin_mint: Pubkey,
    pub pc_mint: Pubkey,
    pub pool_coin_token_account: Pubkey,
    pub pool_pc_token_account: Pubkey,
    pub pool_withdraw_queue: Pubkey,
    pub amm_target_orders: Pubkey,
    pub pool_temp_lp: Pubkey,
    pub serum_program: Pubkey,
    pub serum_market: Pubkey,
    pub user_wallet: Pubkey,
    pub user_token_coin: Pubkey,
    pub user_token_pc: Pubkey,
    pub user_lp_token_account: Pubkey,
}

/// Raydium AMM V4 Withdraw Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmV4WithdrawEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction 事件)===
    pub amm: Pubkey,
    pub amount: u64,

    // === 非 Borsh 字段 ===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_program: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_authority: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_open_orders: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub amm_target_orders: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub lp_mint_address: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_coin_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_pc_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_withdraw_queue: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pool_temp_lp_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_program: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_market: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_coin_vault_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_pc_vault_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_vault_signer: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_lp_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_coin_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_pc_token_account: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub user_owner: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_event_queue: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_bids: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub serum_asks: Pubkey,
}

/// Raydium AMM V4 Withdraw PnL Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmV4WithdrawPnlEvent {
    pub metadata: EventMetadata,

    pub token_program: Pubkey,
    pub amm: Pubkey,
    pub amm_config: Pubkey,
    pub amm_authority: Pubkey,
    pub amm_open_orders: Pubkey,
    pub pool_coin_token_account: Pubkey,
    pub pool_pc_token_account: Pubkey,
    pub coin_pnl_token_account: Pubkey,
    pub pc_pnl_token_account: Pubkey,
    pub pnl_owner: Pubkey,
    pub amm_target_orders: Pubkey,
    pub serum_program: Pubkey,
    pub serum_market: Pubkey,
    pub serum_event_queue: Pubkey,
    pub serum_coin_vault_account: Pubkey,
    pub serum_pc_vault_account: Pubkey,
    pub serum_vault_signer: Pubkey,
}

// ====================== Account Events ======================

/// Bonk (Raydium Launchpad) AmmCreatorFeeOn enum
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AmmCreatorFeeOn {
    QuoteToken = 0,
    BothToken = 1,
}

/// Bonk (Raydium Launchpad) VestingSchedule
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VestingSchedule {
    pub total_locked_amount: u64,
    pub cliff_period: u64,
    pub unlock_period: u64,
}

/// Bonk Pool State Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkPoolStateAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub pool_state: BonkPoolState,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkPoolState {
    pub epoch: u64,
    pub auth_bump: u8,
    pub status: u8,
    pub base_decimals: u8,
    pub quote_decimals: u8,
    pub migrate_type: u8,
    pub supply: u64,
    pub total_base_sell: u64,
    pub virtual_base: u64,
    pub virtual_quote: u64,
    pub real_base: u64,
    pub real_quote: u64,
    pub total_quote_fund_raising: u64,
    pub quote_protocol_fee: u64,
    pub platform_fee: u64,
    pub migrate_fee: u64,
    pub vesting_schedule: VestingSchedule,
    pub global_config: Pubkey,
    pub platform_config: Pubkey,
    pub base_mint: Pubkey,
    pub quote_mint: Pubkey,
    pub base_vault: Pubkey,
    pub quote_vault: Pubkey,
    pub creator: Pubkey,
    pub token_program_flag: u8,
    pub amm_creator_fee_on: AmmCreatorFeeOn,
    pub platform_vesting_share: u64,
    #[serde(with = "serde_big_array::BigArray")]
    pub padding: [u8; 54],
}

/// Bonk Global Config Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkGlobalConfigAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub global_config: BonkGlobalConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkGlobalConfig {
    pub protocol_fee_rate: u64,
    pub trade_fee_rate: u64,
    pub migration_fee_rate: u64,
}

/// Bonk Platform Config Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkPlatformConfigAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub platform_config: BonkPlatformConfig,
}

/// Bonk (Raydium Launchpad) BondingCurveParam
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BondingCurveParam {
    pub migrate_type: u8,
    pub migrate_cpmm_fee_on: u8,
    pub supply: u64,
    pub total_base_sell: u64,
    pub total_quote_fund_raising: u64,
    pub total_locked_amount: u64,
    pub cliff_period: u64,
    pub unlock_period: u64,
}

/// Bonk (Raydium Launchpad) PlatformCurveParam
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlatformCurveParam {
    pub epoch: u64,
    pub index: u8,
    pub global_config: Pubkey,
    pub bonding_curve_param: BondingCurveParam,
    #[serde(with = "serde_big_array::BigArray")]
    pub padding: [u64; 50],
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BonkPlatformConfig {
    pub epoch: u64,
    pub platform_fee_wallet: Pubkey,
    pub platform_nft_wallet: Pubkey,
    pub platform_scale: u64,
    pub creator_scale: u64,
    pub burn_scale: u64,
    pub fee_rate: u64,
    #[serde(with = "serde_big_array::BigArray")]
    pub name: [u8; 64],
    #[serde(with = "serde_big_array::BigArray")]
    pub web: [u8; 256],
    #[serde(with = "serde_big_array::BigArray")]
    pub img: [u8; 256],
    pub cpswap_config: Pubkey,
    pub creator_fee_rate: u64,
    pub transfer_fee_extension_auth: Pubkey,
    pub platform_vesting_wallet: Pubkey,
    pub platform_vesting_scale: u64,
    pub platform_cp_creator: Pubkey,
    #[serde(with = "serde_big_array::BigArray")]
    pub padding: [u8; 108],
    pub curve_params: Vec<PlatformCurveParam>,
}

/// PumpSwap Global Config Account Event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapGlobalConfigAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub executable: bool,
    pub lamports: u64,
    pub owner: Pubkey,
    pub rent_epoch: u64,
    pub global_config: PumpSwapGlobalConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapGlobalConfig {
    pub admin: Pubkey,
    pub lp_fee_basis_points: u64,
    pub protocol_fee_basis_points: u64,
    pub disable_flags: u8,
    pub protocol_fee_recipients: [Pubkey; 8],
    pub coin_creator_fee_basis_points: u64,
    pub admin_set_coin_creator_authority: Pubkey,
    pub whitelist_pda: Pubkey,
    pub reserved_fee_recipient: Pubkey,
    pub mayhem_mode_enabled: bool,
    pub reserved_fee_recipients: [Pubkey; 7],
}

/// PumpSwap Pool Account Event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapPoolAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub executable: bool,
    pub lamports: u64,
    pub owner: Pubkey,
    pub rent_epoch: u64,
    pub pool: PumpSwapPool,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpSwapPool {
    pub pool_bump: u8,
    pub index: u16,
    pub creator: Pubkey,
    pub base_mint: Pubkey,
    pub quote_mint: Pubkey,
    pub lp_mint: Pubkey,
    pub pool_base_token_account: Pubkey,
    pub pool_quote_token_account: Pubkey,
    pub lp_supply: u64,
    pub coin_creator: Pubkey,
    pub is_mayhem_mode: bool,
    pub is_cashback_coin: bool,
}

/// PumpFun Bonding Curve Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpFunBondingCurveAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub bonding_curve: PumpFunBondingCurve,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PumpFunBondingCurve {
    pub virtual_token_reserves: u64,
    pub virtual_sol_reserves: u64,
    pub real_token_reserves: u64,
    pub real_sol_reserves: u64,
    pub token_total_supply: u64,
    pub complete: bool,
    /// Cashback 币种标记 (PUMP_CASHBACK_README)
    #[serde(default)]
    pub is_cashback_coin: bool,
}

/// PumpFun Global Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpFunGlobalAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub global: PumpFunGlobal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PumpFunGlobal {
    pub initialized: bool,
    pub authority: Pubkey,
    pub fee_recipient: Pubkey,
    pub initial_virtual_token_reserves: u64,
    pub initial_virtual_sol_reserves: u64,
    pub initial_real_token_reserves: u64,
    pub token_total_supply: u64,
    pub fee_basis_points: u64,
    pub withdraw_authority: Pubkey,
    pub enable_migrate: bool,
    pub pool_migration_fee: u64,
    pub creator_fee_basis_points: u64,
    pub fee_recipients: [Pubkey; 8],
    pub set_creator_authority: Pubkey,
    pub admin_set_creator_authority: Pubkey,
    pub create_v2_enabled: bool,
    pub whitelist_pda: Pubkey,
    pub reserved_fee_recipient: Pubkey,
    pub mayhem_mode_enabled: bool,
    pub reserved_fee_recipients: [Pubkey; 7],
}

/// Raydium AMM V4 Info Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmAmmInfoAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub amm_info: RaydiumAmmInfo,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumAmmInfo {
    pub status: u64,
    pub nonce: u64,
    pub order_num: u64,
    pub depth: u64,
    pub coin_decimals: u64,
    pub pc_decimals: u64,
    pub state: u64,
    pub reset_flag: u64,
    pub min_size: u64,
    pub vol_max_cut_ratio: u64,
    pub amount_wave_ratio: u64,
    pub coin_lot_size: u64,
    pub pc_lot_size: u64,
    pub min_price_multiplier: u64,
    pub max_price_multiplier: u64,
    pub sys_decimal_value: u64,
}

/// Raydium CLMM AMM Config Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmAmmConfigAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub amm_config: RaydiumClmmAmmConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmAmmConfig {
    pub bump: u8,
    pub index: u16,
    pub owner: Pubkey,
    pub protocol_fee_rate: u32,
    pub trade_fee_rate: u32,
    pub tick_spacing: u16,
    pub fund_fee_rate: u32,
    pub fund_owner: Pubkey,
}

/// Raydium CLMM Pool State Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmPoolStateAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub pool_state: RaydiumClmmPoolState,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmPoolState {
    pub bump: [u8; 1],
    pub amm_config: Pubkey,
    pub owner: Pubkey,
    pub token_mint0: Pubkey,
    pub token_mint1: Pubkey,
    pub token_vault0: Pubkey,
    pub token_vault1: Pubkey,
    pub observation_key: Pubkey,
    pub mint_decimals0: u8,
    pub mint_decimals1: u8,
    pub tick_spacing: u16,
    pub liquidity: u128,
    pub sqrt_price_x64: u128,
    pub tick_current: i32,
}

/// Raydium CLMM Tick Array State Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmTickArrayStateAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub tick_array_state: RaydiumClmmTickArrayState,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumClmmTickArrayState {
    pub discriminator: u64,
    pub pool_id: Pubkey,
    pub start_tick_index: i32,
    pub ticks: Vec<Tick>,
    pub initialized_tick_count: u8,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tick {
    pub tick: i32,
    pub liquidity_net: i128,
    pub liquidity_gross: u128,
    pub fee_growth_outside_0_x64: u128,
    pub fee_growth_outside_1_x64: u128,
    pub reward_growths_outside_x64: [u128; 3],
}

/// Raydium CPMM AMM Config Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmAmmConfigAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub amm_config: RaydiumCpmmAmmConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmAmmConfig {
    pub bump: u8,
    pub disable_create_pool: bool,
    pub index: u16,
    pub trade_fee_rate: u64,
    pub protocol_fee_rate: u64,
    pub fund_fee_rate: u64,
    pub create_pool_fee: u64,
    pub protocol_owner: Pubkey,
    pub fund_owner: Pubkey,
    pub creator_fee_rate: u64,
    pub padding: [u64; 15],
}

/// Raydium CPMM Pool State Account Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmPoolStateAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub pool_state: RaydiumCpmmPoolState,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaydiumCpmmPoolState {
    pub amm_config: Pubkey,
    pub pool_creator: Pubkey,
    pub token_0_vault: Pubkey,
    pub token_1_vault: Pubkey,
    pub lp_mint: Pubkey,
    pub token_0_mint: Pubkey,
    pub token_1_mint: Pubkey,
    pub token_0_program: Pubkey,
    pub token_1_program: Pubkey,
    pub observation_key: Pubkey,
    pub auth_bump: u8,
    pub status: u8,
    pub lp_mint_decimals: u8,
    pub mint_0_decimals: u8,
    pub mint_1_decimals: u8,
    pub lp_supply: u64,
    pub protocol_fees_token_0: u64,
    pub protocol_fees_token_1: u64,
    pub fund_fees_token_0: u64,
    pub fund_fees_token_1: u64,
    pub open_time: u64,
    pub recent_epoch: u64,
    pub creator_fee_on: u8,
    pub enable_creator_fee: bool,
    pub padding1: [u8; 6],
    pub creator_fees_token_0: u64,
    pub creator_fees_token_1: u64,
    pub padding: [u64; 28],
}

/// Token Info Event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TokenInfoEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub executable: bool,
    pub lamports: u64,
    pub owner: Pubkey,
    pub rent_epoch: u64,
    pub supply: u64,
    pub decimals: u8,
}

/// Token Account Event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TokenAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub executable: bool,
    pub lamports: u64,
    pub owner: Pubkey,
    pub rent_epoch: u64,
    pub amount: Option<u64>,
    pub token_owner: Pubkey,
}

/// Nonce Account Event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct NonceAccountEvent {
    pub metadata: EventMetadata,
    pub pubkey: Pubkey,
    pub executable: bool,
    pub lamports: u64,
    pub owner: Pubkey,
    pub rent_epoch: u64,
    pub nonce: String,
    pub authority: String,
}

// ====================== Orca Whirlpool Events ======================

/// Orca Whirlpool Swap Event (基于 TradedEvent,不是 SwapEvent)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
pub struct OrcaWhirlpoolSwapEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub whirlpool: Pubkey,  // 32 bytes
    pub input_amount: u64,  // 8 bytes
    pub output_amount: u64, // 8 bytes
    pub a_to_b: bool,       // 1 byte

    // === 非 Borsh 字段(从日志或其他来源填充)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub pre_sqrt_price: u128,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub post_sqrt_price: u128,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub input_transfer_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub output_transfer_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub lp_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub protocol_fee: u64,
    // === 指令参数字段 (暂时注释,以后可能会用到,AI不要删除) ===
    // pub amount: u64,
    // pub other_amount_threshold: u64,
    // pub sqrt_price_limit: u128,
    // pub amount_specified_is_input: bool,

    // === 指令账户字段 (暂时注释,以后可能会用到,AI不要删除) ===
    // pub token_authority: Pubkey,    // 1: tokenAuthority
    // pub token_owner_account_a: Pubkey, // 3: tokenOwnerAccountA
    // pub token_vault_a: Pubkey,      // 4: tokenVaultA
    // pub token_owner_account_b: Pubkey, // 5: tokenOwnerAccountB
    // pub token_vault_b: Pubkey,      // 6: tokenVaultB
    // pub tick_array_0: Pubkey,       // 7: tickArray0
    // pub tick_array_1: Pubkey,       // 8: tickArray1
    // pub tick_array_2: Pubkey,       // 9: tickArray2
}

/// Orca Whirlpool Liquidity Increased Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrcaWhirlpoolLiquidityIncreasedEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub whirlpool: Pubkey,   // 32 bytes
    pub liquidity: u128,     // 16 bytes
    pub token_a_amount: u64, // 8 bytes
    pub token_b_amount: u64, // 8 bytes

    // === 非 Borsh 字段(从日志或其他来源填充)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub position: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub tick_lower_index: i32,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub tick_upper_index: i32,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_transfer_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_transfer_fee: u64,
}

/// Orca Whirlpool Liquidity Decreased Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrcaWhirlpoolLiquidityDecreasedEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub whirlpool: Pubkey,   // 32 bytes
    pub liquidity: u128,     // 16 bytes
    pub token_a_amount: u64, // 8 bytes
    pub token_b_amount: u64, // 8 bytes

    // === 非 Borsh 字段(从日志或其他来源填充)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub position: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub tick_lower_index: i32,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub tick_upper_index: i32,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_transfer_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_transfer_fee: u64,
}

/// Orca Whirlpool Pool Initialized Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrcaWhirlpoolPoolInitializedEvent {
    pub metadata: EventMetadata,
    pub whirlpool: Pubkey,
    pub whirlpools_config: Pubkey,
    pub token_mint_a: Pubkey,
    pub token_mint_b: Pubkey,
    pub tick_spacing: u16,
    pub token_program_a: Pubkey,
    pub token_program_b: Pubkey,
    pub decimals_a: u8,
    pub decimals_b: u8,
    pub initial_sqrt_price: u128,
}

// ====================== Meteora Pools Events ======================

/// Meteora Pools Swap Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraPoolsSwapEvent {
    pub metadata: EventMetadata,
    pub in_amount: u64,
    pub out_amount: u64,
    pub trade_fee: u64,
    pub admin_fee: u64, // IDL字段名: adminFee
    pub host_fee: u64,
}

/// Meteora Pools Add Liquidity Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraPoolsAddLiquidityEvent {
    pub metadata: EventMetadata,
    pub lp_mint_amount: u64,
    pub token_a_amount: u64,
    pub token_b_amount: u64,
}

/// Meteora Pools Remove Liquidity Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraPoolsRemoveLiquidityEvent {
    pub metadata: EventMetadata,
    pub lp_unmint_amount: u64,
    pub token_a_out_amount: u64,
    pub token_b_out_amount: u64,
}

/// Meteora Pools Bootstrap Liquidity Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraPoolsBootstrapLiquidityEvent {
    pub metadata: EventMetadata,
    pub lp_mint_amount: u64,
    pub token_a_amount: u64,
    pub token_b_amount: u64,
    pub pool: Pubkey,
}

/// Meteora Pools Pool Created Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraPoolsPoolCreatedEvent {
    pub metadata: EventMetadata,
    pub lp_mint: Pubkey,
    pub token_a_mint: Pubkey,
    pub token_b_mint: Pubkey,
    pub pool_type: u8,
    pub pool: Pubkey,
}

/// Meteora Pools Set Pool Fees Event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraPoolsSetPoolFeesEvent {
    pub metadata: EventMetadata,
    pub trade_fee_numerator: u64,
    pub trade_fee_denominator: u64,
    pub owner_trade_fee_numerator: u64, // IDL字段名: ownerTradeFeeNumerator
    pub owner_trade_fee_denominator: u64, // IDL字段名: ownerTradeFeeDenominator
    pub pool: Pubkey,
}

// ====================== Meteora DAMM V2 Events ======================

/// Meteora DAMM V2 Swap Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MeteoraDammV2SwapEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,       // 32 bytes
    pub amount_in: u64,     // 8 bytes
    pub output_amount: u64, // 8 bytes

    // === 非 Borsh 字段(从日志或其他来源填充)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub trade_direction: u8,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub has_referral: bool,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub minimum_amount_out: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub next_sqrt_price: u128,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub lp_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub protocol_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub partner_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub referral_fee: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub actual_amount_in: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub current_timestamp: u64,
    // ---------- 账号 -------------
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_vault: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_vault: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_mint: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_mint: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_program: Pubkey,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_program: Pubkey,
}

/// Meteora DAMM V2 Add Liquidity Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDammV2AddLiquidityEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,        // 32 bytes
    pub position: Pubkey,    // 32 bytes
    pub owner: Pubkey,       // 32 bytes
    pub token_a_amount: u64, // 8 bytes
    pub token_b_amount: u64, // 8 bytes

    // === 非 Borsh 字段(从日志填充)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub liquidity_delta: u128,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_amount_threshold: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_amount_threshold: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub total_amount_a: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub total_amount_b: u64,
}

/// Meteora DAMM V2 Remove Liquidity Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDammV2RemoveLiquidityEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,        // 32 bytes
    pub position: Pubkey,    // 32 bytes
    pub owner: Pubkey,       // 32 bytes
    pub token_a_amount: u64, // 8 bytes
    pub token_b_amount: u64, // 8 bytes

    // === 非 Borsh 字段(从日志填充)===
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub liquidity_delta: u128,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_a_amount_threshold: u64,
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub token_b_amount_threshold: u64,
}

/// Meteora DAMM V2 Create Position Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDammV2CreatePositionEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,              // 32 bytes
    pub owner: Pubkey,             // 32 bytes
    pub position: Pubkey,          // 32 bytes
    pub position_nft_mint: Pubkey, // 32 bytes
}

/// Meteora DAMM V2 Close Position Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDammV2ClosePositionEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,              // 32 bytes
    pub owner: Pubkey,             // 32 bytes
    pub position: Pubkey,          // 32 bytes
    pub position_nft_mint: Pubkey, // 32 bytes
}

/// Meteora DLMM Swap Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmSwapEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,      // 32 bytes
    pub from: Pubkey,      // 32 bytes
    pub start_bin_id: i32, // 4 bytes
    pub end_bin_id: i32,   // 4 bytes
    pub amount_in: u64,    // 8 bytes
    pub amount_out: u64,   // 8 bytes
    pub swap_for_y: bool,  // 1 byte
    pub fee: u64,          // 8 bytes
    pub protocol_fee: u64, // 8 bytes
    pub fee_bps: u128,     // 16 bytes
    pub host_fee: u64,     // 8 bytes
}

/// Meteora DLMM Add Liquidity Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmAddLiquidityEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,       // 32 bytes
    pub from: Pubkey,       // 32 bytes
    pub position: Pubkey,   // 32 bytes
    pub amounts: [u64; 2],  // 16 bytes (2 * 8)
    pub active_bin_id: i32, // 4 bytes
}

/// Meteora DLMM Remove Liquidity Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmRemoveLiquidityEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,       // 32 bytes
    pub from: Pubkey,       // 32 bytes
    pub position: Pubkey,   // 32 bytes
    pub amounts: [u64; 2],  // 16 bytes (2 * 8)
    pub active_bin_id: i32, // 4 bytes
}

/// Meteora DLMM Initialize Pool Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmInitializePoolEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,       // 32 bytes
    pub creator: Pubkey,    // 32 bytes
    pub active_bin_id: i32, // 4 bytes
    pub bin_step: u16,      // 2 bytes
}

/// Meteora DLMM Initialize Bin Array Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmInitializeBinArrayEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,      // 32 bytes
    pub bin_array: Pubkey, // 32 bytes
    pub index: i64,        // 8 bytes
}

/// Meteora DLMM Create Position Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmCreatePositionEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,      // 32 bytes
    pub position: Pubkey,  // 32 bytes
    pub owner: Pubkey,     // 32 bytes
    pub lower_bin_id: i32, // 4 bytes
    pub width: u32,        // 4 bytes
}

/// Meteora DLMM Close Position Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmClosePositionEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,     // 32 bytes
    pub position: Pubkey, // 32 bytes
    pub owner: Pubkey,    // 32 bytes
}

/// Meteora DLMM Claim Fee Event
#[cfg_attr(feature = "parse-borsh", derive(BorshDeserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeteoraDlmmClaimFeeEvent {
    #[cfg_attr(feature = "parse-borsh", borsh(skip))]
    pub metadata: EventMetadata,

    // === Borsh 序列化字段(从 inner instruction data 读取)===
    pub pool: Pubkey,     // 32 bytes
    pub position: Pubkey, // 32 bytes
    pub owner: Pubkey,    // 32 bytes
    pub fee_x: u64,       // 8 bytes
    pub fee_y: u64,       // 8 bytes
}

// ====================== 统一的 DEX 事件枚举 ======================

/// 统一的 DEX 事件枚举 - 参考 sol-dex-shreds 的做法
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DexEvent {
    // PumpFun 事件
    PumpFunCreate(PumpFunCreateTokenEvent),     // - 已对接
    PumpFunCreateV2(PumpFunCreateV2TokenEvent), // - 已对接 (CreateV2 / Mayhem)
    PumpFunTrade(PumpFunTradeEvent),            // - 已对接 (统一交易事件,包含所有交易类型)
    PumpFunBuy(PumpFunTradeEvent),              // - 已对接 (仅买入事件,用于过滤)
    PumpFunSell(PumpFunTradeEvent),             // - 已对接 (仅卖出事件,用于过滤)
    PumpFunBuyExactSolIn(PumpFunTradeEvent),    // - 已对接 (精确SOL买入事件,用于过滤)
    PumpFunMigrate(PumpFunMigrateEvent),        // - 已对接

    // PumpSwap 事件
    PumpSwapTrade(PumpSwapTradeEvent), // - 已对接 (buy/sell/buy_exact_sol_in)
    PumpSwapBuy(PumpSwapBuyEvent),     // - 已对接 (legacy)
    PumpSwapSell(PumpSwapSellEvent),   // - 已对接 (legacy)
    PumpSwapCreatePool(PumpSwapCreatePoolEvent), // - 已对接
    PumpSwapLiquidityAdded(PumpSwapLiquidityAdded), // - 已对接
    PumpSwapLiquidityRemoved(PumpSwapLiquidityRemoved), // - 已对接

    // Meteora DAMM V2 事件
    MeteoraDammV2Swap(MeteoraDammV2SwapEvent), // - 已对接
    MeteoraDammV2CreatePosition(MeteoraDammV2CreatePositionEvent), // - 已对接
    MeteoraDammV2ClosePosition(MeteoraDammV2ClosePositionEvent), // - 已对接
    MeteoraDammV2AddLiquidity(MeteoraDammV2AddLiquidityEvent), // - 已对接
    MeteoraDammV2RemoveLiquidity(MeteoraDammV2RemoveLiquidityEvent), // - 已对接

    // Bonk 事件
    BonkTrade(BonkTradeEvent),
    BonkPoolCreate(BonkPoolCreateEvent),
    BonkMigrateAmm(BonkMigrateAmmEvent),

    // Raydium CLMM 事件
    RaydiumClmmSwap(RaydiumClmmSwapEvent),
    RaydiumClmmCreatePool(RaydiumClmmCreatePoolEvent),
    RaydiumClmmOpenPosition(RaydiumClmmOpenPositionEvent),
    RaydiumClmmOpenPositionWithTokenExtNft(RaydiumClmmOpenPositionWithTokenExtNftEvent),
    RaydiumClmmClosePosition(RaydiumClmmClosePositionEvent),
    RaydiumClmmIncreaseLiquidity(RaydiumClmmIncreaseLiquidityEvent),
    RaydiumClmmDecreaseLiquidity(RaydiumClmmDecreaseLiquidityEvent),
    RaydiumClmmCollectFee(RaydiumClmmCollectFeeEvent),

    // Raydium CPMM 事件
    RaydiumCpmmSwap(RaydiumCpmmSwapEvent),
    RaydiumCpmmDeposit(RaydiumCpmmDepositEvent),
    RaydiumCpmmWithdraw(RaydiumCpmmWithdrawEvent),
    RaydiumCpmmInitialize(RaydiumCpmmInitializeEvent),

    // Raydium AMM V4 事件
    RaydiumAmmV4Swap(RaydiumAmmV4SwapEvent),
    RaydiumAmmV4Deposit(RaydiumAmmV4DepositEvent),
    RaydiumAmmV4Initialize2(RaydiumAmmV4Initialize2Event),
    RaydiumAmmV4Withdraw(RaydiumAmmV4WithdrawEvent),
    RaydiumAmmV4WithdrawPnl(RaydiumAmmV4WithdrawPnlEvent),

    // Orca Whirlpool 事件
    OrcaWhirlpoolSwap(OrcaWhirlpoolSwapEvent),
    OrcaWhirlpoolLiquidityIncreased(OrcaWhirlpoolLiquidityIncreasedEvent),
    OrcaWhirlpoolLiquidityDecreased(OrcaWhirlpoolLiquidityDecreasedEvent),
    OrcaWhirlpoolPoolInitialized(OrcaWhirlpoolPoolInitializedEvent),

    // Meteora Pools 事件
    MeteoraPoolsSwap(MeteoraPoolsSwapEvent),
    MeteoraPoolsAddLiquidity(MeteoraPoolsAddLiquidityEvent),
    MeteoraPoolsRemoveLiquidity(MeteoraPoolsRemoveLiquidityEvent),
    MeteoraPoolsBootstrapLiquidity(MeteoraPoolsBootstrapLiquidityEvent),
    MeteoraPoolsPoolCreated(MeteoraPoolsPoolCreatedEvent),
    MeteoraPoolsSetPoolFees(MeteoraPoolsSetPoolFeesEvent),

    // Meteora DLMM 事件
    MeteoraDlmmSwap(MeteoraDlmmSwapEvent),
    MeteoraDlmmAddLiquidity(MeteoraDlmmAddLiquidityEvent),
    MeteoraDlmmRemoveLiquidity(MeteoraDlmmRemoveLiquidityEvent),
    MeteoraDlmmInitializePool(MeteoraDlmmInitializePoolEvent),
    MeteoraDlmmInitializeBinArray(MeteoraDlmmInitializeBinArrayEvent),
    MeteoraDlmmCreatePosition(MeteoraDlmmCreatePositionEvent),
    MeteoraDlmmClosePosition(MeteoraDlmmClosePositionEvent),
    MeteoraDlmmClaimFee(MeteoraDlmmClaimFeeEvent),

    // 账户事件
    TokenInfo(TokenInfoEvent),       // - 已对接
    TokenAccount(TokenAccountEvent), // - 已对接
    NonceAccount(NonceAccountEvent), // - 已对接
    PumpSwapGlobalConfigAccount(PumpSwapGlobalConfigAccountEvent), // - 已对接
    PumpSwapPoolAccount(PumpSwapPoolAccountEvent), // - 已对接

    // 区块元数据事件
    BlockMeta(BlockMetaEvent),

    // 错误事件
    Error(String),
}

// 静态默认 EventMetadata,用于 Error 事件
use once_cell::sync::Lazy;
static DEFAULT_METADATA: Lazy<EventMetadata> = Lazy::new(|| EventMetadata {
    signature: Signature::from([0u8; 64]),
    slot: 0,
    tx_index: 0,
    block_time_us: 0,
    grpc_recv_us: 0,
    recent_blockhash: None,
});

impl DexEvent {
    /// 获取事件的元数据
    pub fn metadata(&self) -> &EventMetadata {
        match self {
            // PumpFun 事件
            DexEvent::PumpFunCreate(e) => &e.metadata,
            DexEvent::PumpFunCreateV2(e) => &e.metadata,
            DexEvent::PumpFunTrade(e) => &e.metadata,
            DexEvent::PumpFunBuy(e) => &e.metadata,
            DexEvent::PumpFunSell(e) => &e.metadata,
            DexEvent::PumpFunBuyExactSolIn(e) => &e.metadata,
            DexEvent::PumpFunMigrate(e) => &e.metadata,

            // PumpSwap 事件
            DexEvent::PumpSwapTrade(e) => &e.metadata,
            DexEvent::PumpSwapBuy(e) => &e.metadata,
            DexEvent::PumpSwapSell(e) => &e.metadata,
            DexEvent::PumpSwapCreatePool(e) => &e.metadata,
            DexEvent::PumpSwapLiquidityAdded(e) => &e.metadata,
            DexEvent::PumpSwapLiquidityRemoved(e) => &e.metadata,

            // Meteora DAMM V2 事件
            DexEvent::MeteoraDammV2Swap(e) => &e.metadata,
            DexEvent::MeteoraDammV2CreatePosition(e) => &e.metadata,
            DexEvent::MeteoraDammV2ClosePosition(e) => &e.metadata,
            DexEvent::MeteoraDammV2AddLiquidity(e) => &e.metadata,
            DexEvent::MeteoraDammV2RemoveLiquidity(e) => &e.metadata,

            // Bonk 事件
            DexEvent::BonkTrade(e) => &e.metadata,
            DexEvent::BonkPoolCreate(e) => &e.metadata,
            DexEvent::BonkMigrateAmm(e) => &e.metadata,

            // Raydium CLMM 事件
            DexEvent::RaydiumClmmSwap(e) => &e.metadata,
            DexEvent::RaydiumClmmCreatePool(e) => &e.metadata,
            DexEvent::RaydiumClmmOpenPosition(e) => &e.metadata,
            DexEvent::RaydiumClmmOpenPositionWithTokenExtNft(e) => &e.metadata,
            DexEvent::RaydiumClmmClosePosition(e) => &e.metadata,
            DexEvent::RaydiumClmmIncreaseLiquidity(e) => &e.metadata,
            DexEvent::RaydiumClmmDecreaseLiquidity(e) => &e.metadata,
            DexEvent::RaydiumClmmCollectFee(e) => &e.metadata,

            // Raydium CPMM 事件
            DexEvent::RaydiumCpmmSwap(e) => &e.metadata,
            DexEvent::RaydiumCpmmDeposit(e) => &e.metadata,
            DexEvent::RaydiumCpmmWithdraw(e) => &e.metadata,
            DexEvent::RaydiumCpmmInitialize(e) => &e.metadata,

            // Raydium AMM V4 事件
            DexEvent::RaydiumAmmV4Swap(e) => &e.metadata,
            DexEvent::RaydiumAmmV4Deposit(e) => &e.metadata,
            DexEvent::RaydiumAmmV4Initialize2(e) => &e.metadata,
            DexEvent::RaydiumAmmV4Withdraw(e) => &e.metadata,
            DexEvent::RaydiumAmmV4WithdrawPnl(e) => &e.metadata,

            // Orca Whirlpool 事件
            DexEvent::OrcaWhirlpoolSwap(e) => &e.metadata,
            DexEvent::OrcaWhirlpoolLiquidityIncreased(e) => &e.metadata,
            DexEvent::OrcaWhirlpoolLiquidityDecreased(e) => &e.metadata,
            DexEvent::OrcaWhirlpoolPoolInitialized(e) => &e.metadata,

            // Meteora Pools 事件
            DexEvent::MeteoraPoolsSwap(e) => &e.metadata,
            DexEvent::MeteoraPoolsAddLiquidity(e) => &e.metadata,
            DexEvent::MeteoraPoolsRemoveLiquidity(e) => &e.metadata,
            DexEvent::MeteoraPoolsBootstrapLiquidity(e) => &e.metadata,
            DexEvent::MeteoraPoolsPoolCreated(e) => &e.metadata,
            DexEvent::MeteoraPoolsSetPoolFees(e) => &e.metadata,

            // Meteora DLMM 事件
            DexEvent::MeteoraDlmmSwap(e) => &e.metadata,
            DexEvent::MeteoraDlmmAddLiquidity(e) => &e.metadata,
            DexEvent::MeteoraDlmmRemoveLiquidity(e) => &e.metadata,
            DexEvent::MeteoraDlmmInitializePool(e) => &e.metadata,
            DexEvent::MeteoraDlmmInitializeBinArray(e) => &e.metadata,
            DexEvent::MeteoraDlmmCreatePosition(e) => &e.metadata,
            DexEvent::MeteoraDlmmClosePosition(e) => &e.metadata,
            DexEvent::MeteoraDlmmClaimFee(e) => &e.metadata,

            // 账户事件
            DexEvent::TokenInfo(e) => &e.metadata,
            DexEvent::TokenAccount(e) => &e.metadata,
            DexEvent::NonceAccount(e) => &e.metadata,
            DexEvent::PumpSwapGlobalConfigAccount(e) => &e.metadata,
            DexEvent::PumpSwapPoolAccount(e) => &e.metadata,

            // 区块元数据事件
            DexEvent::BlockMeta(e) => &e.metadata,

            // 错误事件 - 返回默认元数据
            DexEvent::Error(_) => &DEFAULT_METADATA,
        }
    }

    /// Mutable metadata for filling shared fields (e.g. recent_blockhash). Returns None for Error variant.
    pub fn metadata_mut(&mut self) -> Option<&mut EventMetadata> {
        match self {
            DexEvent::PumpFunCreate(e) => Some(&mut e.metadata),
            DexEvent::PumpFunCreateV2(e) => Some(&mut e.metadata),
            DexEvent::PumpFunTrade(e) => Some(&mut e.metadata),
            DexEvent::PumpFunBuy(e) => Some(&mut e.metadata),
            DexEvent::PumpFunSell(e) => Some(&mut e.metadata),
            DexEvent::PumpFunBuyExactSolIn(e) => Some(&mut e.metadata),
            DexEvent::PumpFunMigrate(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapTrade(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapBuy(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapSell(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapCreatePool(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapLiquidityAdded(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapLiquidityRemoved(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDammV2Swap(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDammV2CreatePosition(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDammV2ClosePosition(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDammV2AddLiquidity(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDammV2RemoveLiquidity(e) => Some(&mut e.metadata),
            DexEvent::BonkTrade(e) => Some(&mut e.metadata),
            DexEvent::BonkPoolCreate(e) => Some(&mut e.metadata),
            DexEvent::BonkMigrateAmm(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmSwap(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmCreatePool(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmOpenPosition(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmOpenPositionWithTokenExtNft(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmClosePosition(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmIncreaseLiquidity(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmDecreaseLiquidity(e) => Some(&mut e.metadata),
            DexEvent::RaydiumClmmCollectFee(e) => Some(&mut e.metadata),
            DexEvent::RaydiumCpmmSwap(e) => Some(&mut e.metadata),
            DexEvent::RaydiumCpmmDeposit(e) => Some(&mut e.metadata),
            DexEvent::RaydiumCpmmWithdraw(e) => Some(&mut e.metadata),
            DexEvent::RaydiumCpmmInitialize(e) => Some(&mut e.metadata),
            DexEvent::RaydiumAmmV4Swap(e) => Some(&mut e.metadata),
            DexEvent::RaydiumAmmV4Deposit(e) => Some(&mut e.metadata),
            DexEvent::RaydiumAmmV4Initialize2(e) => Some(&mut e.metadata),
            DexEvent::RaydiumAmmV4Withdraw(e) => Some(&mut e.metadata),
            DexEvent::RaydiumAmmV4WithdrawPnl(e) => Some(&mut e.metadata),
            DexEvent::OrcaWhirlpoolSwap(e) => Some(&mut e.metadata),
            DexEvent::OrcaWhirlpoolLiquidityIncreased(e) => Some(&mut e.metadata),
            DexEvent::OrcaWhirlpoolLiquidityDecreased(e) => Some(&mut e.metadata),
            DexEvent::OrcaWhirlpoolPoolInitialized(e) => Some(&mut e.metadata),
            DexEvent::MeteoraPoolsSwap(e) => Some(&mut e.metadata),
            DexEvent::MeteoraPoolsAddLiquidity(e) => Some(&mut e.metadata),
            DexEvent::MeteoraPoolsRemoveLiquidity(e) => Some(&mut e.metadata),
            DexEvent::MeteoraPoolsBootstrapLiquidity(e) => Some(&mut e.metadata),
            DexEvent::MeteoraPoolsPoolCreated(e) => Some(&mut e.metadata),
            DexEvent::MeteoraPoolsSetPoolFees(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmSwap(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmAddLiquidity(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmRemoveLiquidity(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmInitializePool(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmInitializeBinArray(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmCreatePosition(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmClosePosition(e) => Some(&mut e.metadata),
            DexEvent::MeteoraDlmmClaimFee(e) => Some(&mut e.metadata),
            DexEvent::TokenInfo(e) => Some(&mut e.metadata),
            DexEvent::TokenAccount(e) => Some(&mut e.metadata),
            DexEvent::NonceAccount(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapGlobalConfigAccount(e) => Some(&mut e.metadata),
            DexEvent::PumpSwapPoolAccount(e) => Some(&mut e.metadata),
            DexEvent::BlockMeta(e) => Some(&mut e.metadata),
            DexEvent::Error(_) => None,
        }
    }
}