sol-parser-sdk-python 0.4.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. sol_parser/__init__.py +400 -0
  2. sol_parser/account_dispatcher.py +209 -0
  3. sol_parser/account_fillers/__init__.py +5 -0
  4. sol_parser/account_fillers/bonk.py +30 -0
  5. sol_parser/account_fillers/meteora.py +51 -0
  6. sol_parser/account_fillers/orca.py +40 -0
  7. sol_parser/account_fillers/pumpfun.py +97 -0
  8. sol_parser/account_fillers/pumpswap.py +93 -0
  9. sol_parser/account_fillers/raydium.py +119 -0
  10. sol_parser/accounts/__init__.py +461 -0
  11. sol_parser/accounts/rpc_wallet.py +64 -0
  12. sol_parser/accounts/utils.py +71 -0
  13. sol_parser/check_migration.py +18 -0
  14. sol_parser/clock.py +10 -0
  15. sol_parser/common/__init__.py +27 -0
  16. sol_parser/dex_parsers.py +2576 -0
  17. sol_parser/entries_decode.py +186 -0
  18. sol_parser/env_config.py +215 -0
  19. sol_parser/event_types.py +1750 -0
  20. sol_parser/geyser_pb2.py +148 -0
  21. sol_parser/geyser_pb2_grpc.py +398 -0
  22. sol_parser/grpc/__init__.py +61 -0
  23. sol_parser/grpc/geyser_connect.py +42 -0
  24. sol_parser/grpc/subscribe_builder.py +133 -0
  25. sol_parser/grpc/transaction_meta.py +183 -0
  26. sol_parser/grpc_client.py +870 -0
  27. sol_parser/grpc_instruction_parser.py +318 -0
  28. sol_parser/grpc_types.py +919 -0
  29. sol_parser/inner_instruction_parser.py +281 -0
  30. sol_parser/instr/__init__.py +15 -0
  31. sol_parser/instr_account_utils.py +58 -0
  32. sol_parser/instructions.py +1026 -0
  33. sol_parser/json_util.py +41 -0
  34. sol_parser/log_instr_dedup.py +284 -0
  35. sol_parser/logs/__init__.py +15 -0
  36. sol_parser/merger.py +233 -0
  37. sol_parser/order_buffer.py +171 -0
  38. sol_parser/parser.py +300 -0
  39. sol_parser/pumpfun_fee_enrich.py +75 -0
  40. sol_parser/rpc_parser.py +655 -0
  41. sol_parser/rust_api_inventory.py +42 -0
  42. sol_parser/rust_event_json.py +50 -0
  43. sol_parser/shredstream_client.py +191 -0
  44. sol_parser/shredstream_pb2.py +40 -0
  45. sol_parser/shredstream_pb2_grpc.py +81 -0
  46. sol_parser/shredstream_pumpfun.py +296 -0
  47. sol_parser/solana_storage_pb2.py +75 -0
  48. sol_parser/solana_storage_pb2_grpc.py +24 -0
  49. sol_parser/u128_parity.py +115 -0
  50. sol_parser/verify_discriminators.py +85 -0
  51. sol_parser_sdk_python-0.4.4.dist-info/METADATA +14 -0
  52. sol_parser_sdk_python-0.4.4.dist-info/RECORD +54 -0
  53. sol_parser_sdk_python-0.4.4.dist-info/WHEEL +4 -0
  54. sol_parser_sdk_python-0.4.4.dist-info/entry_points.txt +4 -0
sol_parser/__init__.py ADDED
@@ -0,0 +1,400 @@
1
+ """Solana DEX 日志解析 — 与本仓库 TS 包事件形态及解析约定对齐的子集与扩展入口。"""
2
+
3
+ from .json_util import dex_event_json_dumps, dex_event_to_jsonable, format_dex_event_json
4
+ from .parser import (
5
+ EventListener,
6
+ StreamingEventListener,
7
+ parse_log,
8
+ parse_log_optimized,
9
+ parse_log_unified,
10
+ parse_logs_only,
11
+ parse_logs_streaming,
12
+ parse_transaction_events,
13
+ parse_transaction_events_streaming,
14
+ parse_transaction_with_listener,
15
+ parse_transaction_with_streaming_listener,
16
+ warmup_parser,
17
+ )
18
+ from .clock import now_micros
19
+ from .grpc_types import (
20
+ OrderMode,
21
+ CommitmentLevel,
22
+ SlotStatus,
23
+ EventType,
24
+ EventMetadata,
25
+ ClientConfig,
26
+ TransactionFilter,
27
+ AccountFilter,
28
+ Protocol,
29
+ SlotFilter,
30
+ account_filter_memcmp,
31
+ EventTypeFilter,
32
+ IncludeOnlyFilter,
33
+ ExcludeFilter,
34
+ SubscribeCallbacks,
35
+ SubscribeRequest,
36
+ SubscribeUpdate,
37
+ GetLatestBlockhashResponse,
38
+ GetBlockHeightResponse,
39
+ GetSlotResponse,
40
+ GetVersionResponse,
41
+ IsBlockhashValidResponse,
42
+ PongResponse,
43
+ SubscribeReplayInfoResponse,
44
+ event_type_filter_include_only,
45
+ event_type_filter_exclude,
46
+ event_type_filter_includes_pumpfun,
47
+ event_type_filter_includes_pumpswap,
48
+ event_type_filter_includes_meteora_damm_v2,
49
+ event_type_filter_includes_pump_fees,
50
+ event_type_filter_allows_instruction_parsing,
51
+ all_event_types,
52
+ program_ids_for_protocols,
53
+ transaction_filter_for_protocols,
54
+ account_filter_for_protocols,
55
+ )
56
+ from .event_types import (
57
+ # Base type
58
+ DexEventBase,
59
+ # PumpFun events
60
+ PumpFunTradeEvent,
61
+ PumpFunCreateEvent,
62
+ PumpFunCreateV2TokenEvent,
63
+ PumpFunMigrateEvent,
64
+ PumpFeesShareholder,
65
+ PumpFeesFees,
66
+ PumpFeesFeeTier,
67
+ PumpFeesCreateFeeSharingConfigEvent,
68
+ PumpFeesInitializeFeeConfigEvent,
69
+ PumpFeesResetFeeSharingConfigEvent,
70
+ PumpFeesRevokeFeeSharingAuthorityEvent,
71
+ PumpFeesTransferFeeSharingAuthorityEvent,
72
+ PumpFeesUpdateAdminEvent,
73
+ PumpFeesUpdateFeeConfigEvent,
74
+ PumpFeesUpdateFeeSharesEvent,
75
+ PumpFeesUpsertFeeTiersEvent,
76
+ PumpFunMigrateBondingCurveCreatorEvent,
77
+ # PumpSwap events
78
+ PumpSwapBuyEvent,
79
+ PumpSwapSellEvent,
80
+ PumpSwapCreatePoolEvent,
81
+ PumpSwapLiquidityAddedEvent,
82
+ PumpSwapLiquidityRemovedEvent,
83
+ # Raydium CLMM events
84
+ RaydiumClmmSwapEvent,
85
+ RaydiumClmmIncreaseLiquidityEvent,
86
+ RaydiumClmmDecreaseLiquidityEvent,
87
+ RaydiumClmmCreatePoolEvent,
88
+ RaydiumClmmOpenPositionEvent,
89
+ RaydiumClmmOpenPositionWithTokenExtNftEvent,
90
+ RaydiumClmmClosePositionEvent,
91
+ RaydiumClmmCollectFeeEvent,
92
+ # Raydium AMM V4 (legacy)
93
+ RaydiumAmmV4SwapEvent,
94
+ RaydiumAmmV4DepositEvent,
95
+ RaydiumAmmV4WithdrawEvent,
96
+ RaydiumAmmV4WithdrawPnlEvent,
97
+ RaydiumAmmV4Initialize2Event,
98
+ # Raydium CPMM events
99
+ RaydiumCpmmSwapEvent,
100
+ RaydiumCpmmDepositEvent,
101
+ RaydiumCpmmWithdrawEvent,
102
+ RaydiumCpmmInitializeEvent,
103
+ # Orca Whirlpool events
104
+ OrcaWhirlpoolSwapEvent,
105
+ OrcaWhirlpoolLiquidityIncreasedEvent,
106
+ OrcaWhirlpoolLiquidityDecreasedEvent,
107
+ OrcaWhirlpoolPoolInitializedEvent,
108
+ # Meteora DLMM events
109
+ MeteoraDlmmSwapEvent,
110
+ MeteoraDlmmAddLiquidityEvent,
111
+ MeteoraDlmmRemoveLiquidityEvent,
112
+ MeteoraDlmmInitializePoolEvent,
113
+ MeteoraDlmmInitializeBinArrayEvent,
114
+ MeteoraDlmmCreatePositionEvent,
115
+ MeteoraDlmmClosePositionEvent,
116
+ MeteoraDlmmClaimFeeEvent,
117
+ # Meteora Pools events
118
+ MeteoraPoolsSetPoolFeesEvent,
119
+ MeteoraPoolsSwapEvent,
120
+ MeteoraPoolsAddLiquidityEvent,
121
+ MeteoraPoolsRemoveLiquidityEvent,
122
+ MeteoraPoolsBootstrapLiquidityEvent,
123
+ MeteoraPoolsPoolCreatedEvent,
124
+ # Meteora DAMM v2 events
125
+ MeteoraDammV2SwapEvent,
126
+ MeteoraDammV2CreatePositionEvent,
127
+ MeteoraDammV2ClosePositionEvent,
128
+ MeteoraDammV2AddLiquidityEvent,
129
+ MeteoraDammV2RemoveLiquidityEvent,
130
+ MeteoraDammV2InitializePoolEvent,
131
+ # Bonk events
132
+ BonkTradeEvent,
133
+ BonkPoolCreateEvent,
134
+ BonkMigrateAmmEvent,
135
+ # Union type and helper
136
+ TypedDexEvent,
137
+ to_typed_event,
138
+ legacy_dict_to_dex_event,
139
+ )
140
+ from .pumpfun_fee_enrich import (
141
+ enrich_create_v2_observed_fee_recipient,
142
+ enrich_pumpfun_same_tx_post_merge,
143
+ enrich_pumpfun_trades_from_create_instructions,
144
+ )
145
+ from .grpc_instruction_parser import (
146
+ apply_account_fill_to_events,
147
+ enrich_dex_events_with_subscribe_tx_info,
148
+ parse_instructions_enhanced_from_parsed,
149
+ parse_instructions_enhanced_from_subscribe_tx_info,
150
+ merge_instruction_events,
151
+ detect_pumpfun_create_from_logs,
152
+ )
153
+ from .merger import merge_dex_events
154
+ from .account_dispatcher import fill_accounts_with_owned_keys, fill_data
155
+ from .entries_decode import decode_entries_bincode_flat
156
+ from .shredstream_client import ShredStreamClient, ShredStreamConfig
157
+ from .env_config import (
158
+ load_dotenv_silent,
159
+ parse_grpc_credentials,
160
+ parse_optional_rpc_url,
161
+ parse_rpc_and_tx_signature,
162
+ parse_shredstream_url,
163
+ require_grpc_env,
164
+ )
165
+ from .grpc_client import parse_commitment_level
166
+ from .grpc_client import (
167
+ YellowstoneGrpc,
168
+ Subscription,
169
+ )
170
+ from .rpc_parser import (
171
+ ParseError,
172
+ RpcClient,
173
+ RpcTransactionResponse,
174
+ RpcTransactionMeta,
175
+ RpcTransaction,
176
+ enrich_dex_events_from_rpc_get_transaction_result,
177
+ parse_transaction_from_rpc,
178
+ parse_rpc_transaction,
179
+ convert_rpc_to_grpc,
180
+ rpc_get_transaction_result_dict_to_response,
181
+ rpc_response_to_solana_storage,
182
+ )
183
+ from .accounts import (
184
+ AccountData,
185
+ parse_account_unified,
186
+ parse_token_account,
187
+ parse_nonce_account,
188
+ parse_pumpfun_global,
189
+ is_nonce_account,
190
+ is_pumpfun_global_account,
191
+ parse_pumpswap_global_config,
192
+ parse_pumpswap_pool,
193
+ is_global_config_account,
194
+ is_pool_account,
195
+ has_discriminator,
196
+ rpc_resolve_user_wallet_pubkey,
197
+ user_wallet_pubkey_for_onchain_account,
198
+ )
199
+ from .grpc.subscribe_builder import (
200
+ build_subscribe_request,
201
+ build_subscribe_request_with_commitment,
202
+ build_subscribe_transaction_filters_named,
203
+ )
204
+ from .instructions import (
205
+ parse_instruction_unified,
206
+ parse_pumpfun_instruction,
207
+ parse_pumpswap_instruction,
208
+ parse_meteora_damm_instruction,
209
+ parse_pump_fees_instruction,
210
+ )
211
+
212
+ __all__ = [
213
+ # Parser functions
214
+ "dex_event_json_dumps",
215
+ "dex_event_to_jsonable",
216
+ "format_dex_event_json",
217
+ "apply_account_fill_to_events",
218
+ "enrich_dex_events_with_subscribe_tx_info",
219
+ "parse_log_unified",
220
+ "parse_log_optimized",
221
+ "parse_log",
222
+ "parse_logs_only",
223
+ "parse_logs_streaming",
224
+ "parse_transaction_events",
225
+ "parse_transaction_events_streaming",
226
+ "parse_transaction_with_listener",
227
+ "parse_transaction_with_streaming_listener",
228
+ "EventListener",
229
+ "StreamingEventListener",
230
+ "warmup_parser",
231
+ "now_micros",
232
+ # RPC parser
233
+ "ParseError",
234
+ "RpcClient",
235
+ "RpcTransactionResponse",
236
+ "RpcTransactionMeta",
237
+ "RpcTransaction",
238
+ "parse_transaction_from_rpc",
239
+ "parse_rpc_transaction",
240
+ "convert_rpc_to_grpc",
241
+ "enrich_dex_events_from_rpc_get_transaction_result",
242
+ "rpc_get_transaction_result_dict_to_response",
243
+ "rpc_response_to_solana_storage",
244
+ # Accounts
245
+ "AccountData",
246
+ "parse_account_unified",
247
+ "parse_token_account",
248
+ "parse_nonce_account",
249
+ "parse_pumpfun_global",
250
+ "is_nonce_account",
251
+ "is_pumpfun_global_account",
252
+ "parse_pumpswap_global_config",
253
+ "parse_pumpswap_pool",
254
+ "is_global_config_account",
255
+ "is_pool_account",
256
+ "has_discriminator",
257
+ "rpc_resolve_user_wallet_pubkey",
258
+ "user_wallet_pubkey_for_onchain_account",
259
+ "build_subscribe_request",
260
+ "build_subscribe_request_with_commitment",
261
+ "build_subscribe_transaction_filters_named",
262
+ # Instructions
263
+ "parse_instruction_unified",
264
+ "parse_pumpfun_instruction",
265
+ "parse_pumpswap_instruction",
266
+ "parse_meteora_damm_instruction",
267
+ "parse_pump_fees_instruction",
268
+ # gRPC types
269
+ "OrderMode",
270
+ "CommitmentLevel",
271
+ "SlotStatus",
272
+ "EventType",
273
+ "EventMetadata",
274
+ "ClientConfig",
275
+ "TransactionFilter",
276
+ "AccountFilter",
277
+ "Protocol",
278
+ "SlotFilter",
279
+ "account_filter_memcmp",
280
+ "EventTypeFilter",
281
+ "IncludeOnlyFilter",
282
+ "ExcludeFilter",
283
+ "SubscribeCallbacks",
284
+ "SubscribeRequest",
285
+ "SubscribeUpdate",
286
+ "GetLatestBlockhashResponse",
287
+ "GetBlockHeightResponse",
288
+ "GetSlotResponse",
289
+ "GetVersionResponse",
290
+ "IsBlockhashValidResponse",
291
+ "PongResponse",
292
+ "SubscribeReplayInfoResponse",
293
+ # gRPC filter helpers
294
+ "event_type_filter_include_only",
295
+ "event_type_filter_exclude",
296
+ "event_type_filter_includes_pumpfun",
297
+ "event_type_filter_includes_pumpswap",
298
+ "event_type_filter_includes_meteora_damm_v2",
299
+ "event_type_filter_includes_pump_fees",
300
+ "event_type_filter_allows_instruction_parsing",
301
+ "all_event_types",
302
+ "program_ids_for_protocols",
303
+ "transaction_filter_for_protocols",
304
+ "account_filter_for_protocols",
305
+ "parse_commitment_level",
306
+ # Env / CLI (aligned with sol-parser-sdk-nodejs)
307
+ "load_dotenv_silent",
308
+ "parse_grpc_credentials",
309
+ "parse_optional_rpc_url",
310
+ "parse_rpc_and_tx_signature",
311
+ "parse_shredstream_url",
312
+ "require_grpc_env",
313
+ # gRPC client
314
+ "YellowstoneGrpc",
315
+ "Subscription",
316
+ # Typed events
317
+ "DexEventBase",
318
+ "PumpFunTradeEvent",
319
+ "PumpFunCreateEvent",
320
+ "PumpFunCreateV2TokenEvent",
321
+ "PumpFunMigrateEvent",
322
+ "PumpFeesShareholder",
323
+ "PumpFeesFees",
324
+ "PumpFeesFeeTier",
325
+ "PumpFeesCreateFeeSharingConfigEvent",
326
+ "PumpFeesInitializeFeeConfigEvent",
327
+ "PumpFeesResetFeeSharingConfigEvent",
328
+ "PumpFeesRevokeFeeSharingAuthorityEvent",
329
+ "PumpFeesTransferFeeSharingAuthorityEvent",
330
+ "PumpFeesUpdateAdminEvent",
331
+ "PumpFeesUpdateFeeConfigEvent",
332
+ "PumpFeesUpdateFeeSharesEvent",
333
+ "PumpFeesUpsertFeeTiersEvent",
334
+ "PumpFunMigrateBondingCurveCreatorEvent",
335
+ "PumpSwapBuyEvent",
336
+ "PumpSwapSellEvent",
337
+ "PumpSwapCreatePoolEvent",
338
+ "PumpSwapLiquidityAddedEvent",
339
+ "PumpSwapLiquidityRemovedEvent",
340
+ "RaydiumClmmSwapEvent",
341
+ "RaydiumClmmIncreaseLiquidityEvent",
342
+ "RaydiumClmmDecreaseLiquidityEvent",
343
+ "RaydiumClmmCreatePoolEvent",
344
+ "RaydiumClmmOpenPositionEvent",
345
+ "RaydiumClmmOpenPositionWithTokenExtNftEvent",
346
+ "RaydiumClmmClosePositionEvent",
347
+ "RaydiumClmmCollectFeeEvent",
348
+ "RaydiumAmmV4SwapEvent",
349
+ "RaydiumAmmV4DepositEvent",
350
+ "RaydiumAmmV4WithdrawEvent",
351
+ "RaydiumAmmV4WithdrawPnlEvent",
352
+ "RaydiumAmmV4Initialize2Event",
353
+ "RaydiumCpmmSwapEvent",
354
+ "RaydiumCpmmDepositEvent",
355
+ "RaydiumCpmmWithdrawEvent",
356
+ "RaydiumCpmmInitializeEvent",
357
+ "OrcaWhirlpoolSwapEvent",
358
+ "OrcaWhirlpoolLiquidityIncreasedEvent",
359
+ "OrcaWhirlpoolLiquidityDecreasedEvent",
360
+ "OrcaWhirlpoolPoolInitializedEvent",
361
+ "MeteoraDlmmSwapEvent",
362
+ "MeteoraDlmmAddLiquidityEvent",
363
+ "MeteoraDlmmRemoveLiquidityEvent",
364
+ "MeteoraDlmmInitializePoolEvent",
365
+ "MeteoraDlmmInitializeBinArrayEvent",
366
+ "MeteoraDlmmCreatePositionEvent",
367
+ "MeteoraDlmmClosePositionEvent",
368
+ "MeteoraDlmmClaimFeeEvent",
369
+ "MeteoraPoolsSetPoolFeesEvent",
370
+ "MeteoraPoolsSwapEvent",
371
+ "MeteoraPoolsAddLiquidityEvent",
372
+ "MeteoraPoolsRemoveLiquidityEvent",
373
+ "MeteoraPoolsBootstrapLiquidityEvent",
374
+ "MeteoraPoolsPoolCreatedEvent",
375
+ "MeteoraDammV2SwapEvent",
376
+ "MeteoraDammV2CreatePositionEvent",
377
+ "MeteoraDammV2ClosePositionEvent",
378
+ "MeteoraDammV2AddLiquidityEvent",
379
+ "MeteoraDammV2RemoveLiquidityEvent",
380
+ "MeteoraDammV2InitializePoolEvent",
381
+ "BonkTradeEvent",
382
+ "BonkPoolCreateEvent",
383
+ "BonkMigrateAmmEvent",
384
+ "TypedDexEvent",
385
+ "to_typed_event",
386
+ "legacy_dict_to_dex_event",
387
+ "enrich_create_v2_observed_fee_recipient",
388
+ "enrich_pumpfun_same_tx_post_merge",
389
+ "enrich_pumpfun_trades_from_create_instructions",
390
+ "parse_instructions_enhanced_from_parsed",
391
+ "parse_instructions_enhanced_from_subscribe_tx_info",
392
+ "merge_instruction_events",
393
+ "merge_dex_events",
394
+ "detect_pumpfun_create_from_logs",
395
+ "fill_accounts_with_owned_keys",
396
+ "fill_data",
397
+ "decode_entries_bincode_flat",
398
+ "ShredStreamClient",
399
+ "ShredStreamConfig",
400
+ ]
@@ -0,0 +1,209 @@
1
+ """账户上下文填充(对齐 Rust ``account_dispatcher`` / ``common_filler``)。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict, List, Optional, Tuple
6
+
7
+ import base58
8
+
9
+ from .account_fillers import bonk, meteora, orca, pumpfun, pumpswap, raydium
10
+ from .event_types import DexEvent
11
+ from .grpc_types import EventType
12
+ from .instr_account_utils import get_instruction_account_getter
13
+ from .instructions import (
14
+ BONK_LAUNCHPAD_PROGRAM_ID,
15
+ METEORA_DAMM_V2_PROGRAM_ID,
16
+ METEORA_DLMM_PROGRAM_ID,
17
+ METEORA_POOLS_PROGRAM_ID,
18
+ ORCA_WHIRLPOOL_PROGRAM_ID,
19
+ PUMPFUN_PROGRAM_ID,
20
+ PUMPSWAP_FEES_PROGRAM_ID,
21
+ PUMPSWAP_PROGRAM_ID,
22
+ RAYDIUM_AMM_V4_PROGRAM_ID,
23
+ RAYDIUM_CLMM_PROGRAM_ID,
24
+ RAYDIUM_CPMM_PROGRAM_ID,
25
+ )
26
+
27
+
28
+ def find_instruction_invoke(
29
+ invokes: List[Tuple[int, int]],
30
+ meta_pb: Any,
31
+ transaction_pb: Any,
32
+ ) -> Optional[Tuple[int, int]]:
33
+ """账户数最多的 invoke(与 Rust ``find_instruction_invoke`` 一致)。"""
34
+ best: Optional[Tuple[int, int]] = None
35
+ best_len = -1
36
+ for outer_idx, inner_idx in invokes:
37
+ n = 0
38
+ if inner_idx >= 0:
39
+ for inn in meta_pb.inner_instructions:
40
+ if int(inn.index) == int(outer_idx):
41
+ if inner_idx < len(inn.instructions):
42
+ n = len(inn.instructions[inner_idx].accounts)
43
+ break
44
+ else:
45
+ msg = transaction_pb.message
46
+ if outer_idx < len(msg.instructions):
47
+ n = len(msg.instructions[outer_idx].accounts)
48
+ if n > best_len:
49
+ best_len = n
50
+ best = (outer_idx, inner_idx)
51
+ return best
52
+
53
+
54
+ def get_instruction_data(
55
+ meta_pb: Any,
56
+ transaction_pb: Any,
57
+ index: Tuple[int, int],
58
+ ) -> Optional[bytes]:
59
+ oi, ii = index
60
+ if ii >= 0:
61
+ for inn in meta_pb.inner_instructions:
62
+ if int(inn.index) == int(oi):
63
+ if ii < len(inn.instructions):
64
+ return bytes(inn.instructions[ii].data)
65
+ return None
66
+ return None
67
+ msg = transaction_pb.message
68
+ if oi < len(msg.instructions):
69
+ return bytes(msg.instructions[oi].data)
70
+ return None
71
+
72
+
73
+ def fill_accounts_with_owned_keys(
74
+ event: DexEvent,
75
+ meta_pb: Any,
76
+ transaction_pb: Any,
77
+ invokes: Dict[bytes, List[Tuple[int, int]]],
78
+ ) -> None:
79
+ if transaction_pb is None:
80
+ return
81
+ static_keys = [bytes(x) for x in transaction_pb.message.account_keys]
82
+ w = [bytes(x) for x in meta_pb.loaded_writable_addresses]
83
+ r = [bytes(x) for x in meta_pb.loaded_readonly_addresses]
84
+
85
+ def run(program_b58: str, filler) -> None:
86
+ pid = base58.b58decode(program_b58)
87
+ inv = invokes.get(pid)
88
+ if not inv:
89
+ return
90
+ ix = find_instruction_invoke(inv, meta_pb, transaction_pb)
91
+ if ix is None:
92
+ return
93
+ get = get_instruction_account_getter(meta_pb, transaction_pb, static_keys, w, r, ix)
94
+ if get is None:
95
+ return
96
+ filler(get)
97
+
98
+ et = event.type
99
+ data = event.data
100
+
101
+ if et in (
102
+ EventType.PUMP_FUN_TRADE,
103
+ EventType.PUMP_FUN_BUY,
104
+ EventType.PUMP_FUN_SELL,
105
+ EventType.PUMP_FUN_BUY_EXACT_SOL_IN,
106
+ ):
107
+ run(PUMPFUN_PROGRAM_ID, lambda g: pumpfun.fill_trade_accounts(data, g))
108
+ elif et == EventType.PUMP_FUN_CREATE:
109
+ run(PUMPFUN_PROGRAM_ID, lambda g: pumpfun.fill_create_accounts(data, g))
110
+ elif et == EventType.PUMP_FUN_CREATE_V2:
111
+ run(PUMPFUN_PROGRAM_ID, lambda g: pumpfun.fill_create_v2_accounts(data, g))
112
+ elif et == EventType.PUMP_FUN_MIGRATE:
113
+ run(PUMPFUN_PROGRAM_ID, lambda g: pumpfun.fill_migrate_accounts(data, g))
114
+ elif et == EventType.PUMP_SWAP_BUY:
115
+ run(PUMPSWAP_PROGRAM_ID, lambda g: pumpswap.fill_buy_accounts(data, g))
116
+ elif et == EventType.PUMP_SWAP_SELL:
117
+ run(PUMPSWAP_PROGRAM_ID, lambda g: pumpswap.fill_sell_accounts(data, g))
118
+ elif et == EventType.PUMP_SWAP_TRADE:
119
+ run(PUMPSWAP_PROGRAM_ID, lambda g: pumpswap.fill_trade_accounts(data, g))
120
+ elif et == EventType.PUMP_SWAP_CREATE_POOL:
121
+ run(PUMPSWAP_PROGRAM_ID, lambda g: pumpswap.fill_create_pool_accounts(data, g))
122
+ elif et == EventType.PUMP_SWAP_LIQUIDITY_ADDED:
123
+ run(PUMPSWAP_PROGRAM_ID, lambda g: pumpswap.fill_liquidity_added_accounts(data, g))
124
+ elif et == EventType.PUMP_SWAP_LIQUIDITY_REMOVED:
125
+ run(PUMPSWAP_PROGRAM_ID, lambda g: pumpswap.fill_liquidity_removed_accounts(data, g))
126
+ elif et == EventType.RAYDIUM_CLMM_SWAP:
127
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_swap_accounts(data, g))
128
+ elif et == EventType.RAYDIUM_CLMM_CREATE_POOL:
129
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_create_pool_accounts(data, g))
130
+ elif et == EventType.RAYDIUM_CLMM_OPEN_POSITION:
131
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_open_position_accounts(data, g))
132
+ elif et == EventType.RAYDIUM_CLMM_OPEN_POSITION_WITH_TOKEN_EXT_NFT:
133
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_open_position_with_token_ext_nft_accounts(data, g))
134
+ elif et == EventType.RAYDIUM_CLMM_CLOSE_POSITION:
135
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_close_position_accounts(data, g))
136
+ elif et == EventType.RAYDIUM_CLMM_INCREASE_LIQUIDITY:
137
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_increase_liquidity_accounts(data, g))
138
+ elif et == EventType.RAYDIUM_CLMM_DECREASE_LIQUIDITY:
139
+ run(RAYDIUM_CLMM_PROGRAM_ID, lambda g: raydium.fill_clmm_decrease_liquidity_accounts(data, g))
140
+ elif et == EventType.RAYDIUM_CPMM_SWAP:
141
+ run(RAYDIUM_CPMM_PROGRAM_ID, lambda g: raydium.fill_cpmm_swap_accounts(data, g))
142
+ elif et == EventType.RAYDIUM_CPMM_DEPOSIT:
143
+ run(RAYDIUM_CPMM_PROGRAM_ID, lambda g: raydium.fill_cpmm_deposit_accounts(data, g))
144
+ elif et == EventType.RAYDIUM_CPMM_WITHDRAW:
145
+ run(RAYDIUM_CPMM_PROGRAM_ID, lambda g: raydium.fill_cpmm_withdraw_accounts(data, g))
146
+ elif et == EventType.RAYDIUM_CPMM_INITIALIZE:
147
+ run(RAYDIUM_CPMM_PROGRAM_ID, lambda g: raydium.fill_cpmm_initialize_accounts(data, g))
148
+ elif et == EventType.RAYDIUM_AMM_V4_SWAP:
149
+ run(RAYDIUM_AMM_V4_PROGRAM_ID, lambda g: raydium.fill_amm_v4_swap_accounts(data, g))
150
+ elif et == EventType.RAYDIUM_AMM_V4_DEPOSIT:
151
+ run(RAYDIUM_AMM_V4_PROGRAM_ID, lambda g: raydium.fill_amm_v4_deposit_accounts(data, g))
152
+ elif et == EventType.RAYDIUM_AMM_V4_WITHDRAW:
153
+ run(RAYDIUM_AMM_V4_PROGRAM_ID, lambda g: raydium.fill_amm_v4_withdraw_accounts(data, g))
154
+ elif et == EventType.ORCA_WHIRLPOOL_SWAP:
155
+ run(ORCA_WHIRLPOOL_PROGRAM_ID, lambda g: orca.fill_whirlpool_swap_accounts(data, g))
156
+ elif et == EventType.ORCA_WHIRLPOOL_LIQUIDITY_INCREASED:
157
+ run(ORCA_WHIRLPOOL_PROGRAM_ID, lambda g: orca.fill_whirlpool_liquidity_increased_accounts(data, g))
158
+ elif et == EventType.ORCA_WHIRLPOOL_LIQUIDITY_DECREASED:
159
+ run(ORCA_WHIRLPOOL_PROGRAM_ID, lambda g: orca.fill_whirlpool_liquidity_decreased_accounts(data, g))
160
+ elif et == EventType.METEORA_DAMM_V2_SWAP:
161
+ run(METEORA_DAMM_V2_PROGRAM_ID, lambda g: meteora.fill_damm_v2_swap_accounts(data, g))
162
+ elif et == EventType.METEORA_DAMM_V2_CREATE_POSITION:
163
+ run(METEORA_DAMM_V2_PROGRAM_ID, lambda g: meteora.fill_damm_v2_create_position_accounts(data, g))
164
+ elif et == EventType.METEORA_DAMM_V2_CLOSE_POSITION:
165
+ run(METEORA_DAMM_V2_PROGRAM_ID, lambda g: meteora.fill_damm_v2_close_position_accounts(data, g))
166
+ elif et == EventType.METEORA_DAMM_V2_ADD_LIQUIDITY:
167
+ run(METEORA_DAMM_V2_PROGRAM_ID, lambda g: meteora.fill_damm_v2_add_liquidity_accounts(data, g))
168
+ elif et == EventType.METEORA_DAMM_V2_REMOVE_LIQUIDITY:
169
+ run(METEORA_DAMM_V2_PROGRAM_ID, lambda g: meteora.fill_damm_v2_remove_liquidity_accounts(data, g))
170
+ elif et == EventType.METEORA_POOLS_SWAP:
171
+ run(METEORA_POOLS_PROGRAM_ID, lambda g: meteora.fill_pools_swap_accounts(data, g))
172
+ elif et == EventType.METEORA_POOLS_ADD_LIQUIDITY:
173
+ run(METEORA_POOLS_PROGRAM_ID, lambda g: meteora.fill_pools_add_liquidity_accounts(data, g))
174
+ elif et == EventType.METEORA_POOLS_REMOVE_LIQUIDITY:
175
+ run(METEORA_POOLS_PROGRAM_ID, lambda g: meteora.fill_pools_remove_liquidity_accounts(data, g))
176
+ elif et == EventType.METEORA_DLMM_SWAP:
177
+ run(METEORA_DLMM_PROGRAM_ID, lambda g: meteora.fill_dlmm_swap_accounts(data, g))
178
+ elif et == EventType.METEORA_DLMM_ADD_LIQUIDITY:
179
+ run(METEORA_DLMM_PROGRAM_ID, lambda g: meteora.fill_dlmm_add_liquidity_accounts(data, g))
180
+ elif et == EventType.METEORA_DLMM_REMOVE_LIQUIDITY:
181
+ run(METEORA_DLMM_PROGRAM_ID, lambda g: meteora.fill_dlmm_remove_liquidity_accounts(data, g))
182
+ elif et == EventType.BONK_TRADE:
183
+ run(BONK_LAUNCHPAD_PROGRAM_ID, lambda g: bonk.fill_trade_accounts(data, g))
184
+ elif et == EventType.BONK_POOL_CREATE:
185
+ run(BONK_LAUNCHPAD_PROGRAM_ID, lambda g: bonk.fill_pool_create_accounts(data, g))
186
+
187
+
188
+ def fill_data(
189
+ event: DexEvent,
190
+ meta_pb: Any,
191
+ transaction_pb: Any,
192
+ invokes_str: Dict[str, List[Tuple[int, int]]],
193
+ ) -> None:
194
+ """对齐 Rust ``common_filler::fill_data``(PumpSwap Buy/Sell ``is_pump_pool``)。"""
195
+ if transaction_pb is None:
196
+ return
197
+ et = event.type
198
+ data = event.data
199
+ if et not in (EventType.PUMP_SWAP_BUY, EventType.PUMP_SWAP_SELL):
200
+ return
201
+ inv = invokes_str.get(PUMPSWAP_FEES_PROGRAM_ID)
202
+ if not inv:
203
+ return
204
+ ix = inv[-1]
205
+ raw = get_instruction_data(meta_pb, transaction_pb, ix)
206
+ if raw is None or len(raw) <= 9:
207
+ return
208
+ is_pump = raw[9] != 0
209
+ setattr(data, "is_pump_pool", is_pump)
@@ -0,0 +1,5 @@
1
+ """账户填充子模块(对齐 Rust ``core/account_fillers``)。"""
2
+
3
+ from . import bonk, meteora, orca, pumpfun, pumpswap, raydium
4
+
5
+ __all__ = ["bonk", "meteora", "orca", "pumpfun", "pumpswap", "raydium"]
@@ -0,0 +1,30 @@
1
+ """Bonk 账户填充(对齐 ``account_fillers/bonk.rs``)。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Callable
6
+
7
+ from ..event_types import BonkPoolCreateEvent, BonkTradeEvent
8
+
9
+ Z = "11111111111111111111111111111111"
10
+
11
+
12
+ def _empty(s: str) -> bool:
13
+ return not s or s == Z
14
+
15
+
16
+ AccountGetter = Callable[[int], str]
17
+
18
+
19
+ def fill_trade_accounts(e: BonkTradeEvent, get: AccountGetter) -> None:
20
+ if _empty(e.user):
21
+ e.user = get(0)
22
+ if _empty(e.pool_state):
23
+ e.pool_state = get(1)
24
+
25
+
26
+ def fill_pool_create_accounts(e: BonkPoolCreateEvent, get: AccountGetter) -> None:
27
+ if _empty(e.pool_state):
28
+ e.pool_state = get(1)
29
+ if _empty(e.creator):
30
+ e.creator = get(8)
@@ -0,0 +1,51 @@
1
+ """Meteora 账户填充(对齐 ``account_fillers/meteora.rs``,多数为占位)。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Callable
6
+
7
+ AccountGetter = Callable[[int], str]
8
+
9
+
10
+ def fill_damm_v2_swap_accounts(_e: Any, _get: AccountGetter) -> None:
11
+ pass
12
+
13
+
14
+ def fill_damm_v2_create_position_accounts(_e: Any, _get: AccountGetter) -> None:
15
+ pass
16
+
17
+
18
+ def fill_damm_v2_close_position_accounts(_e: Any, _get: AccountGetter) -> None:
19
+ pass
20
+
21
+
22
+ def fill_damm_v2_add_liquidity_accounts(_e: Any, _get: AccountGetter) -> None:
23
+ pass
24
+
25
+
26
+ def fill_damm_v2_remove_liquidity_accounts(_e: Any, _get: AccountGetter) -> None:
27
+ pass
28
+
29
+
30
+ def fill_pools_swap_accounts(_e: Any, _get: AccountGetter) -> None:
31
+ pass
32
+
33
+
34
+ def fill_pools_add_liquidity_accounts(_e: Any, _get: AccountGetter) -> None:
35
+ pass
36
+
37
+
38
+ def fill_pools_remove_liquidity_accounts(_e: Any, _get: AccountGetter) -> None:
39
+ pass
40
+
41
+
42
+ def fill_dlmm_swap_accounts(_e: Any, _get: AccountGetter) -> None:
43
+ pass
44
+
45
+
46
+ def fill_dlmm_add_liquidity_accounts(_e: Any, _get: AccountGetter) -> None:
47
+ pass
48
+
49
+
50
+ def fill_dlmm_remove_liquidity_accounts(_e: Any, _get: AccountGetter) -> None:
51
+ pass