sol-parser-sdk-nodejs 0.3.0

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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +449 -0
  3. package/README_CN.md +343 -0
  4. package/dist/accounts/mod.d.ts +11 -0
  5. package/dist/accounts/mod.js +53 -0
  6. package/dist/accounts/nonce.d.ts +5 -0
  7. package/dist/accounts/nonce.js +32 -0
  8. package/dist/accounts/pumpswap.d.ts +8 -0
  9. package/dist/accounts/pumpswap.js +192 -0
  10. package/dist/accounts/token.d.ts +5 -0
  11. package/dist/accounts/token.js +98 -0
  12. package/dist/accounts/types.d.ts +9 -0
  13. package/dist/accounts/types.js +2 -0
  14. package/dist/accounts/utils.d.ts +1 -0
  15. package/dist/accounts/utils.js +12 -0
  16. package/dist/core/account_dispatcher_rpc.d.ts +11 -0
  17. package/dist/core/account_dispatcher_rpc.js +155 -0
  18. package/dist/core/account_fill_bonk.d.ts +4 -0
  19. package/dist/core/account_fill_bonk.js +20 -0
  20. package/dist/core/account_fill_meteora.d.ts +14 -0
  21. package/dist/core/account_fill_meteora.js +26 -0
  22. package/dist/core/account_fill_orca.d.ts +5 -0
  23. package/dist/core/account_fill_orca.js +18 -0
  24. package/dist/core/account_fill_pumpfun.d.ts +7 -0
  25. package/dist/core/account_fill_pumpfun.js +75 -0
  26. package/dist/core/account_fill_pumpswap.d.ts +10 -0
  27. package/dist/core/account_fill_pumpswap.js +78 -0
  28. package/dist/core/account_fill_raydium.d.ts +20 -0
  29. package/dist/core/account_fill_raydium.js +104 -0
  30. package/dist/core/clock.d.ts +2 -0
  31. package/dist/core/clock.js +7 -0
  32. package/dist/core/common_filler_rpc.d.ts +6 -0
  33. package/dist/core/common_filler_rpc.js +21 -0
  34. package/dist/core/dex_event.d.ts +1009 -0
  35. package/dist/core/dex_event.js +14 -0
  36. package/dist/core/error.d.ts +43 -0
  37. package/dist/core/error.js +16 -0
  38. package/dist/core/json_utils.d.ts +8 -0
  39. package/dist/core/json_utils.js +18 -0
  40. package/dist/core/metadata.d.ts +10 -0
  41. package/dist/core/metadata.js +13 -0
  42. package/dist/core/rpc_invoke_map.d.ts +23 -0
  43. package/dist/core/rpc_invoke_map.js +157 -0
  44. package/dist/core/unified_parser.d.ts +19 -0
  45. package/dist/core/unified_parser.js +48 -0
  46. package/dist/grpc/client.d.ts +52 -0
  47. package/dist/grpc/client.js +309 -0
  48. package/dist/grpc/client_stub.d.ts +5 -0
  49. package/dist/grpc/client_stub.js +5 -0
  50. package/dist/grpc/types.d.ts +132 -0
  51. package/dist/grpc/types.js +304 -0
  52. package/dist/grpc/yellowstone_parse.d.ts +9 -0
  53. package/dist/grpc/yellowstone_parse.js +46 -0
  54. package/dist/index.d.ts +18 -0
  55. package/dist/index.js +99 -0
  56. package/dist/instr/bonk_ix.d.ts +5 -0
  57. package/dist/instr/bonk_ix.js +52 -0
  58. package/dist/instr/meteora_damm_ix.d.ts +6 -0
  59. package/dist/instr/meteora_damm_ix.js +349 -0
  60. package/dist/instr/mod.d.ts +15 -0
  61. package/dist/instr/mod.js +95 -0
  62. package/dist/instr/orca_whirlpool_ix.d.ts +5 -0
  63. package/dist/instr/orca_whirlpool_ix.js +73 -0
  64. package/dist/instr/program_ids.d.ts +14 -0
  65. package/dist/instr/program_ids.js +18 -0
  66. package/dist/instr/pumpfun_ix.d.ts +5 -0
  67. package/dist/instr/pumpfun_ix.js +167 -0
  68. package/dist/instr/pumpswap_ix.d.ts +5 -0
  69. package/dist/instr/pumpswap_ix.js +215 -0
  70. package/dist/instr/raydium_amm_v4_ix.d.ts +6 -0
  71. package/dist/instr/raydium_amm_v4_ix.js +46 -0
  72. package/dist/instr/raydium_clmm_ix.d.ts +5 -0
  73. package/dist/instr/raydium_clmm_ix.js +85 -0
  74. package/dist/instr/raydium_cpmm_ix.d.ts +5 -0
  75. package/dist/instr/raydium_cpmm_ix.js +63 -0
  76. package/dist/instr/utils.d.ts +10 -0
  77. package/dist/instr/utils.js +33 -0
  78. package/dist/logs/meteora_amm.d.ts +8 -0
  79. package/dist/logs/meteora_amm.js +113 -0
  80. package/dist/logs/meteora_damm.d.ts +6 -0
  81. package/dist/logs/meteora_damm.js +509 -0
  82. package/dist/logs/meteora_dlmm.d.ts +6 -0
  83. package/dist/logs/meteora_dlmm.js +201 -0
  84. package/dist/logs/optimized_matcher.d.ts +5 -0
  85. package/dist/logs/optimized_matcher.js +194 -0
  86. package/dist/logs/orca.d.ts +6 -0
  87. package/dist/logs/orca.js +148 -0
  88. package/dist/logs/program_data.d.ts +2 -0
  89. package/dist/logs/program_data.js +22 -0
  90. package/dist/logs/program_log_discriminators.d.ts +59 -0
  91. package/dist/logs/program_log_discriminators.js +67 -0
  92. package/dist/logs/pump.d.ts +12 -0
  93. package/dist/logs/pump.js +251 -0
  94. package/dist/logs/pump_amm.d.ts +9 -0
  95. package/dist/logs/pump_amm.js +418 -0
  96. package/dist/logs/raydium_amm.d.ts +9 -0
  97. package/dist/logs/raydium_amm.js +224 -0
  98. package/dist/logs/raydium_clmm.d.ts +8 -0
  99. package/dist/logs/raydium_clmm.js +141 -0
  100. package/dist/logs/raydium_cpmm.d.ts +7 -0
  101. package/dist/logs/raydium_cpmm.js +121 -0
  102. package/dist/logs/raydium_launchpad.d.ts +12 -0
  103. package/dist/logs/raydium_launchpad.js +92 -0
  104. package/dist/parser_alias.d.ts +3 -0
  105. package/dist/parser_alias.js +2 -0
  106. package/dist/rpc_parser.d.ts +16 -0
  107. package/dist/rpc_parser.js +36 -0
  108. package/dist/rpc_transaction.d.ts +25 -0
  109. package/dist/rpc_transaction.js +111 -0
  110. package/dist/util/binary.d.ts +14 -0
  111. package/dist/util/binary.js +82 -0
  112. package/dist/warmup.d.ts +3 -0
  113. package/dist/warmup.js +23 -0
  114. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MiracleAI-Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,449 @@
1
+ <div align="center">
2
+ <h1>⚡ Sol Parser SDK - Node.js</h1>
3
+ <h3><em>High-performance Solana DEX event parser for Node.js/TypeScript</em></h3>
4
+ </div>
5
+
6
+ <p align="center">
7
+ <strong>High-performance Node.js/TypeScript library for parsing Solana DEX events in real-time via Yellowstone gRPC</strong>
8
+ </p>
9
+
10
+ <p align="center">
11
+ <a href="https://www.npmjs.com/package/sol-parser-sdk-nodejs">
12
+ <img src="https://img.shields.io/badge/npm-sol--parser--sdk--nodejs-red.svg" alt="npm">
13
+ </a>
14
+ <a href="https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/LICENSE">
15
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
16
+ </a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img src="https://img.shields.io/badge/Node.js-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js">
21
+ <img src="https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript">
22
+ <img src="https://img.shields.io/badge/Solana-9945FF?style=for-the-badge&logo=solana&logoColor=white" alt="Solana">
23
+ <img src="https://img.shields.io/badge/gRPC-4285F4?style=for-the-badge&logo=grpc&logoColor=white" alt="gRPC">
24
+ </p>
25
+
26
+ <p align="center">
27
+ <a href="./README_CN.md">中文</a> |
28
+ <a href="./README.md">English</a> |
29
+ <a href="https://fnzero.dev/">Website</a> |
30
+ <a href="https://t.me/fnzero_group">Telegram</a> |
31
+ <a href="https://discord.gg/vuazbGkqQE">Discord</a>
32
+ </p>
33
+
34
+ ---
35
+
36
+ ## 📦 SDK Versions
37
+
38
+ This SDK is available in multiple languages:
39
+
40
+ | Language | Repository | Description |
41
+ |----------|------------|-------------|
42
+ | **Rust** | [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk) | Ultra-low latency with SIMD optimization |
43
+ | **Node.js** | [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) | TypeScript/JavaScript for Node.js |
44
+ | **Python** | [sol-parser-sdk-python](https://github.com/0xfnzero/sol-parser-sdk-python) | Async/await native support |
45
+ | **Go** | [sol-parser-sdk-golang](https://github.com/0xfnzero/sol-parser-sdk-golang) | Concurrent-safe with goroutine support |
46
+
47
+ ---
48
+
49
+ ## 📊 Performance Highlights
50
+
51
+ ### ⚡ Real-Time Parsing
52
+ - **Sub-millisecond** log-based event parsing
53
+ - **gRPC streaming** with Yellowstone/Geyser protocol
54
+ - **Optimized pattern matching** with compiled regex
55
+ - **Event type filtering** for targeted parsing
56
+ - **Zero-allocation** on hot paths where possible
57
+
58
+ ### 🎚️ Flexible Order Modes
59
+ | Mode | Latency | Description |
60
+ |------|---------|-------------|
61
+ | **Unordered** | <1ms | Immediate output, ultra-low latency |
62
+ | **MicroBatch** | 1-5ms | Micro-batch ordering with time window |
63
+ | **StreamingOrdered** | 5-20ms | Stream ordering with continuous sequence release |
64
+ | **Ordered** | 10-100ms | Full slot ordering, wait for complete slot |
65
+
66
+ ### 🚀 Optimization Highlights
67
+ - ✅ **Optimized log parsing** with minimal allocations
68
+ - ✅ **Compiled pattern matchers** for all protocol detection
69
+ - ✅ **Event type filtering** for targeted parsing
70
+ - ✅ **Conditional Create detection** (only when needed)
71
+ - ✅ **Multiple order modes** for latency vs ordering trade-off
72
+ - ✅ **BigInt-safe JSON serialization** for correct number handling
73
+
74
+ ---
75
+
76
+ ## 🔥 Quick Start
77
+
78
+ ### Installation
79
+
80
+ ```bash
81
+ git clone https://github.com/0xfnzero/sol-parser-sdk-nodejs
82
+ cd sol-parser-sdk-nodejs
83
+ npm install --ignore-scripts
84
+ npm run build
85
+ ```
86
+
87
+ ### Use npm
88
+
89
+ ```bash
90
+ npm install sol-parser-sdk-nodejs
91
+ ```
92
+
93
+ ### Performance Testing
94
+
95
+ From the **package root** (`sol-parser-sdk-ts/`), after `npm run build`:
96
+
97
+ ```bash
98
+ # Integration test: PumpFun + PumpSwap, parsed events with account fills (same path as Rust gRPC)
99
+ GRPC_URL=https://solana-yellowstone-grpc.publicnode.com:443 GRPC_TOKEN=your_token npm run test:grpc
100
+
101
+ # PumpFun with detailed metrics (per-event + 10s stats)
102
+ GRPC_TOKEN=your_token node examples/pumpfun_with_metrics.mjs
103
+
104
+ # PumpSwap with detailed metrics (per-event + 10s stats)
105
+ GRPC_TOKEN=your_token node examples/pumpswap_with_metrics.mjs
106
+
107
+ # PumpSwap ultra-low latency test
108
+ GRPC_TOKEN=your_token node examples/pumpswap_low_latency.mjs
109
+ ```
110
+
111
+ ### Environment variables (gRPC examples)
112
+
113
+ | Variable | Description |
114
+ |----------|-------------|
115
+ | **`GRPC_URL`** | Yellowstone gRPC endpoint (preferred). Example: `https://solana-yellowstone-grpc.publicnode.com:443` |
116
+ | **`GRPC_TOKEN`** | `x-token` for the endpoint (preferred) |
117
+ | **`GEYSER_ENDPOINT`** | Alias for `GRPC_URL` (backward compatible) |
118
+ | **`GEYSER_API_TOKEN`** | Alias for `GRPC_TOKEN` (backward compatible) |
119
+ | **`MAX_EVENTS`** | In `*_grpc_json.mjs` and `npm run test:grpc`: stop after N parsed events; `0` = run until Ctrl+C |
120
+ | **`TIMEOUT_MS`** | `npm run test:grpc` only: auto-exit after N ms; `0` = no timeout (can combine with `MAX_EVENTS`, whichever first) |
121
+ | **`JSON_PRETTY`** | `npm run test:grpc`: set to `1` or `true` for indented JSON (default is compact one-line) |
122
+ | **`JSON_MAX_CHARS`** | `npm run test:grpc`: max characters per event line; unset or `0` = no truncation |
123
+
124
+ Some scripts ship a default public token for public endpoints; for production, set `GRPC_TOKEN` explicitly.
125
+
126
+ ### Examples
127
+
128
+ All commands assume the **package root** and `npm run build` already run.
129
+
130
+ | Description | Run Command | Source Code |
131
+ |-------------|-------------|-------------|
132
+ | **Scripts (package)** | | |
133
+ | gRPC integration test (PumpFun + PumpSwap, account-filled `DexEvent`) | `npm run test:grpc` | [scripts/test-grpc-ts.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/scripts/test-grpc-ts.mjs) |
134
+ | Debug: print `metaRaw` / log structure | `npm run debug:grpc` | [scripts/debug-grpc-ts.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/scripts/debug-grpc-ts.mjs) |
135
+ | **PumpFun** | | |
136
+ | Pretty-print **full JSON** `DexEvent` over gRPC (Rust-compatible fields) | `node examples/pumpfun_grpc_json.mjs` | [examples/pumpfun_grpc_json.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_grpc_json.mjs) |
137
+ | PumpFun event parsing with metrics | `node examples/pumpfun_with_metrics.mjs` | [examples/pumpfun_with_metrics.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_with_metrics.mjs) |
138
+ | PumpFun trade type filtering | `node examples/pumpfun_trade_filter.mjs` | [examples/pumpfun_trade_filter.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_trade_filter.mjs) |
139
+ | Quick PumpFun connection test | `node examples/pumpfun_quick_test.mjs` | [examples/pumpfun_quick_test.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_quick_test.mjs) |
140
+ | **PumpSwap** | | |
141
+ | Pretty-print **full JSON** `DexEvent` over gRPC (Rust-compatible fields) | `node examples/pumpswap_grpc_json.mjs` | [examples/pumpswap_grpc_json.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpswap_grpc_json.mjs) |
142
+ | PumpSwap events with metrics | `node examples/pumpswap_with_metrics.mjs` | [examples/pumpswap_with_metrics.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpswap_with_metrics.mjs) |
143
+ | PumpSwap ultra-low latency | `node examples/pumpswap_low_latency.mjs` | [examples/pumpswap_low_latency.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpswap_low_latency.mjs) |
144
+ | **Meteora DAMM** | | |
145
+ | Meteora DAMM V2 events | `node examples/meteora_damm_grpc.mjs` | [examples/meteora_damm_grpc.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/meteora_damm_grpc.mjs) |
146
+ | **Multi-Protocol** | | |
147
+ | Subscribe to all DEX protocols | `node examples/multi_protocol_grpc.mjs` | [examples/multi_protocol_grpc.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/multi_protocol_grpc.mjs) |
148
+ | **Utility / QA** | | |
149
+ | Verify `onUpdate` sync errors do not kill the gRPC stream | `node examples/grpc_onupdate_error_test.mjs` | [examples/grpc_onupdate_error_test.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/grpc_onupdate_error_test.mjs) |
150
+ | Parse tx by signature (RPC, not gRPC) | `TX_SIGNATURE=<sig> node examples/parse_tx_by_signature.mjs` | [examples/parse_tx_by_signature.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/parse_tx_by_signature.mjs) |
151
+
152
+ ### Basic Usage
153
+
154
+ **Recommended (aligned with Rust gRPC `parse_logs`):** parse log lines **and** fill mint / pool token accounts from the compiled transaction using `transactionRaw` + `metaRaw` from the subscription:
155
+
156
+ ```javascript
157
+ import { createRequire } from "module";
158
+ import { fileURLToPath } from "url";
159
+ import path from "path";
160
+
161
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
162
+ const require = createRequire(import.meta.url);
163
+ const {
164
+ YellowstoneGrpc,
165
+ parseDexEventsFromGrpcTransactionInfo,
166
+ dexEventToJsonString,
167
+ } = require(path.join(__dirname, "../dist/index.js"));
168
+
169
+ const ENDPOINT =
170
+ process.env.GRPC_URL ||
171
+ process.env.GEYSER_ENDPOINT ||
172
+ "https://solana-yellowstone-grpc.publicnode.com:443";
173
+ const X_TOKEN =
174
+ process.env.GRPC_TOKEN || process.env.GEYSER_API_TOKEN || "";
175
+
176
+ const client = new YellowstoneGrpc(ENDPOINT, X_TOKEN);
177
+
178
+ const filter = {
179
+ account_include: [
180
+ "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", // PumpFun
181
+ "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap (Pump AMM)
182
+ ],
183
+ account_exclude: [],
184
+ account_required: [],
185
+ vote: false,
186
+ failed: false,
187
+ };
188
+
189
+ const sub = await client.subscribeTransactions(filter, {
190
+ onUpdate: (update) => {
191
+ if (!update.transaction?.transaction) return;
192
+ const txInfo = update.transaction.transaction;
193
+ const slot = update.transaction.slot;
194
+ if (!txInfo.transactionRaw || !txInfo.metaRaw) return;
195
+
196
+ const events = parseDexEventsFromGrpcTransactionInfo(txInfo, slot, undefined);
197
+ for (const ev of events) {
198
+ console.log(dexEventToJsonString(ev, 2));
199
+ }
200
+ },
201
+ onError: (err) => console.error("Error:", err.message),
202
+ onEnd: () => console.log("Stream ended"),
203
+ });
204
+
205
+ console.log(`Subscribed: ${sub.id}`);
206
+ ```
207
+
208
+ **Logs-only (lighter):** `parseLogsOnly(logs, signature, slot, blockTimeUs)` does not require `transactionRaw`; some account fields (e.g. PumpSwap `base_mint`) may stay as the default zero pubkey until you call `applyAccountFillsToLogEvents` yourself with a deserialized message + meta.
209
+
210
+ ---
211
+
212
+ ## 🏗️ Supported Protocols
213
+
214
+ ### DEX Protocols
215
+ - ✅ **PumpFun** - Meme coin trading
216
+ - ✅ **PumpSwap** - PumpFun swap protocol
217
+ - ✅ **Raydium AMM V4** - Automated Market Maker
218
+ - ✅ **Raydium CLMM** - Concentrated Liquidity
219
+ - ✅ **Raydium CPMM** - Concentrated Pool
220
+ - ✅ **Orca Whirlpool** - Concentrated liquidity AMM
221
+ - ✅ **Meteora DAMM V2** - Dynamic AMM
222
+ - ✅ **Meteora DLMM** - Dynamic Liquidity Market Maker
223
+ - ✅ **Bonk Launchpad** - Token launch platform
224
+
225
+ ### Event Types
226
+ Each protocol supports:
227
+ - 📈 **Trade/Swap Events** - Buy/sell transactions
228
+ - 💧 **Liquidity Events** - Deposits/withdrawals
229
+ - 🏊 **Pool Events** - Pool creation/initialization
230
+ - 🎯 **Position Events** - Open/close positions (CLMM)
231
+
232
+ ---
233
+
234
+ ## ⚡ Performance Features
235
+
236
+ ### Optimized Pattern Matching
237
+ ```javascript
238
+ // Pre-compiled regex patterns for fast protocol detection
239
+ const PUMPFUN_PATTERN = /Program 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P/;
240
+
241
+ // Fast check before full parsing
242
+ if (PUMPFUN_PATTERN.test(logString)) {
243
+ return parsePumpFunEvent(logs, signature, slot);
244
+ }
245
+ ```
246
+
247
+ ### Event Type Filtering
248
+ ```javascript
249
+ // Filter specific event types for targeted parsing
250
+ const eventFilter = {
251
+ include_only: ["PumpFunTrade", "PumpSwapBuy", "PumpSwapSell"]
252
+ };
253
+ ```
254
+
255
+ ### JSON Serialization
256
+ ```javascript
257
+ const { dexEventToJsonString } = require("./dist/index.js");
258
+
259
+ for (const ev of events) {
260
+ // Handles BigInt serialization correctly
261
+ console.log(dexEventToJsonString(ev));
262
+ }
263
+ ```
264
+
265
+ ---
266
+
267
+ ## 🎯 Event Filtering
268
+
269
+ Reduce processing overhead by filtering specific events:
270
+
271
+ ### Example: Trading Bot
272
+ ```javascript
273
+ const eventFilter = {
274
+ include_only: [
275
+ "PumpFunTrade",
276
+ "RaydiumAmmV4Swap",
277
+ "RaydiumClmmSwap",
278
+ "OrcaWhirlpoolSwap",
279
+ ]
280
+ };
281
+ ```
282
+
283
+ ### Example: Pool Monitor
284
+ ```javascript
285
+ const eventFilter = {
286
+ include_only: [
287
+ "PumpFunCreate",
288
+ "PumpSwapCreatePool",
289
+ ]
290
+ };
291
+ ```
292
+
293
+ **Performance Impact:**
294
+ - 60-80% reduction in processing
295
+ - Lower memory usage
296
+ - Reduced network bandwidth
297
+
298
+ ---
299
+
300
+ ## 🔧 Advanced Features
301
+
302
+ ### Create+Buy Detection
303
+ Automatically detects when a token is created and immediately bought in the same transaction:
304
+
305
+ ```javascript
306
+ // Automatically detects "Program data: GB7IKAUcB3c..." pattern
307
+ const events = parseLogsOnly(logs, signature, slot, undefined);
308
+
309
+ // Sets is_created_buy flag on Trade events
310
+ for (const ev of events) {
311
+ if (ev.PumpFunTrade && ev.PumpFunTrade.is_created_buy) {
312
+ console.log("Create+Buy detected!");
313
+ }
314
+ }
315
+ ```
316
+
317
+ ### Custom gRPC Endpoint
318
+
319
+ ```javascript
320
+ const ENDPOINT =
321
+ process.env.GRPC_URL ||
322
+ process.env.GEYSER_ENDPOINT ||
323
+ "https://solana-yellowstone-grpc.publicnode.com:443";
324
+ const TOKEN =
325
+ process.env.GRPC_TOKEN || process.env.GEYSER_API_TOKEN || "";
326
+ const client = new YellowstoneGrpc(ENDPOINT, TOKEN);
327
+ ```
328
+
329
+ ### gRPC helpers (Rust parity)
330
+
331
+ - **`parseDexEventsFromGrpcTransactionInfo(txInfo, slot, options?)`** — Decode logs, then apply the same account / data filling as the Rust SDK’s gRPC path (`fill_accounts` + `fill_data`). Requires `txInfo.transactionRaw` and `txInfo.metaRaw`.
332
+ - **`applyAccountFillsToLogEvents(events, message, meta)`** — If you already parsed events from logs, apply fills using a `VersionedTransaction` message and `ConfirmedTransactionMeta`.
333
+ - **`parseRpcTransaction`** / **`parseTransactionFromRpc`** — Full RPC transaction parsing (instructions + logs + fills).
334
+
335
+ ### Unsubscribe
336
+
337
+ ```javascript
338
+ const sub = await client.subscribeTransactions(filter, callbacks);
339
+
340
+ // Later, cancel:
341
+ client.unsubscribe(sub.id);
342
+ ```
343
+
344
+ ---
345
+
346
+ ## 📁 Project Structure
347
+
348
+ ```
349
+ sol-parser-sdk-ts/ (npm: sol-parser-sdk-nodejs)
350
+ ├── src/
351
+ │ ├── core/
352
+ │ │ ├── unified_parser.ts # parseLogsOnly, etc.
353
+ │ │ ├── dex_event.ts # DexEvent type definition
354
+ │ │ ├── rpc_invoke_map.ts # Program invoke map, accountKeyToBase58
355
+ │ │ └── json_utils.ts # dexEventToJsonString
356
+ │ ├── grpc/
357
+ │ │ ├── client.ts # YellowstoneGrpc client
358
+ │ │ ├── yellowstone_parse.ts # parseDexEventsFromGrpcTransactionInfo
359
+ │ │ └── types.ts # ClientConfig, TransactionFilter, etc.
360
+ │ ├── rpc_transaction.ts # parseRpcTransaction, applyAccountFillsToLogEvents
361
+ │ ├── logs/
362
+ │ │ └── optimized_matcher.ts # Log parsing (all protocols)
363
+ │ ├── instr/
364
+ │ │ └── *.ts # Instruction parsers
365
+ │ └── index.ts # Public API exports
366
+ ├── dist/ # Compiled JavaScript
367
+ ├── scripts/
368
+ │ ├── test-grpc-ts.mjs # npm run test:grpc
369
+ │ └── debug-grpc-ts.mjs # npm run debug:grpc
370
+ ├── examples/
371
+ │ ├── pumpfun_grpc_json.mjs
372
+ │ ├── pumpswap_grpc_json.mjs
373
+ │ ├── grpc_onupdate_error_test.mjs
374
+ │ ├── pumpfun_with_metrics.mjs
375
+ │ ├── pumpfun_trade_filter.mjs
376
+ │ ├── pumpfun_quick_test.mjs
377
+ │ ├── pumpswap_with_metrics.mjs
378
+ │ ├── pumpswap_low_latency.mjs
379
+ │ ├── meteora_damm_grpc.mjs
380
+ │ ├── multi_protocol_grpc.mjs
381
+ │ └── parse_tx_by_signature.mjs
382
+ └── package.json
383
+ ```
384
+
385
+ ---
386
+
387
+ ## 🚀 Optimization Techniques
388
+
389
+ ### 1. **Optimized Pattern Matching**
390
+ - Pre-compiled regex patterns for protocol detection
391
+ - Fast path for single-protocol filtering
392
+ - Minimal string allocations
393
+
394
+ ### 2. **Event Type Filtering**
395
+ - Early filtering at protocol level
396
+ - Conditional Create detection
397
+ - Single-type ultra-fast path
398
+
399
+ ### 3. **BigInt-Safe Serialization**
400
+ - Custom JSON serializer for BigInt values
401
+ - Avoids JSON.stringify overflow
402
+ - Preserves numeric precision
403
+
404
+ ### 4. **Efficient Buffer Handling**
405
+ - Direct Buffer operations for hex encoding
406
+ - Minimal conversions between formats
407
+ - Reusable buffers where possible
408
+
409
+ ### 5. **Callback-Based Streaming**
410
+ - Direct event delivery via callbacks
411
+ - No intermediate queue overhead
412
+ - Immediate processing on receipt
413
+
414
+ ---
415
+
416
+ ## 📄 License
417
+
418
+ MIT License
419
+
420
+ ## 📞 Contact
421
+
422
+ - **Repository**: https://github.com/0xfnzero/sol-parser-sdk-nodejs
423
+ - **Website**: https://fnzero.dev/
424
+ - **Telegram**: https://t.me/fnzero_group
425
+ - **Discord**: https://discord.gg/vuazbGkqQE
426
+
427
+ ---
428
+
429
+ ## ⚠️ Performance Tips
430
+
431
+ 1. **Use Event Filtering** — Filter by program ID for 60-80% performance gain
432
+ 2. **Prefer `parseDexEventsFromGrpcTransactionInfo` for gRPC** — Full `DexEvent` fields (mints, pool ATAs) match the Rust SDK when `transactionRaw` + `metaRaw` are present
433
+ 3. **Read logs only once** — `parseLogsOnly` is optimized for hot path
434
+ 4. **Avoid JSON.stringify on BigInt** — Use `dexEventToJsonString` instead
435
+ 5. **Monitor latency** — Check `metadata.grpc_recv_us` in production
436
+ 6. **Use latest Node.js** — Newer versions have better optimization
437
+
438
+ ## 🔬 Development
439
+
440
+ ```bash
441
+ # Build
442
+ npm run build
443
+
444
+ # Watch mode
445
+ npm run dev
446
+
447
+ # Type check
448
+ npm run typecheck
449
+ ```