sol-parser-sdk-nodejs 0.3.0 → 0.4.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.
- package/.env.example +24 -0
- package/README.md +94 -352
- package/README_CN.md +101 -253
- package/dist/accounts/mod.d.ts +2 -0
- package/dist/accounts/mod.js +5 -1
- package/dist/accounts/rpc_wallet.d.ts +5 -0
- package/dist/accounts/rpc_wallet.js +18 -0
- package/dist/accounts/rust_aliases.d.ts +9 -0
- package/dist/accounts/rust_aliases.js +19 -0
- package/dist/accounts/wallet_resolve.d.ts +1 -0
- package/dist/accounts/wallet_resolve.js +28 -0
- package/dist/common/constants.d.ts +10 -0
- package/dist/common/constants.js +13 -0
- package/dist/core/account_dispatcher_rpc.js +26 -5
- package/dist/core/account_fill_meteora.d.ts +4 -2
- package/dist/core/account_fill_meteora.js +5 -2
- package/dist/core/account_pubkey_cache.d.ts +12 -0
- package/dist/core/account_pubkey_cache.js +26 -0
- package/dist/core/clock.d.ts +6 -0
- package/dist/core/clock.js +13 -0
- package/dist/core/dex_event.d.ts +25 -44
- package/dist/core/metadata.d.ts +1 -0
- package/dist/core/unified_parser.d.ts +2 -2
- package/dist/core/unified_parser.js +6 -6
- package/dist/grpc/client.d.ts +6 -0
- package/dist/grpc/client.js +121 -64
- package/dist/grpc/event_parser.d.ts +6 -0
- package/dist/grpc/event_parser.js +15 -0
- package/dist/grpc/geyser_connect.d.ts +30 -0
- package/dist/grpc/geyser_connect.js +40 -0
- package/dist/grpc/program_ids.d.ts +25 -0
- package/dist/grpc/program_ids.js +54 -0
- package/dist/grpc/rpc_to_grpc.d.ts +18 -0
- package/dist/grpc/rpc_to_grpc.js +127 -0
- package/dist/grpc/subscribe_builder.d.ts +13 -0
- package/dist/grpc/subscribe_builder.js +66 -0
- package/dist/grpc/transaction_meta.d.ts +29 -0
- package/dist/grpc/transaction_meta.js +208 -0
- package/dist/grpc/types.d.ts +53 -2
- package/dist/grpc/types.js +98 -7
- package/dist/grpc/yellowstone_parse.d.ts +5 -0
- package/dist/grpc/yellowstone_parse.js +15 -2
- package/dist/index.d.ts +36 -6
- package/dist/index.js +172 -2
- package/dist/instr/bonk_ix.d.ts +4 -1
- package/dist/instr/bonk_ix.js +106 -27
- package/dist/instr/meteora_damm_ix.d.ts +4 -2
- package/dist/instr/meteora_damm_ix.js +248 -13
- package/dist/instr/mod.js +7 -2
- package/dist/instr/orca_whirlpool_ix.d.ts +4 -1
- package/dist/instr/orca_whirlpool_ix.js +45 -16
- package/dist/instr/program_ids.d.ts +7 -13
- package/dist/instr/program_ids.js +19 -15
- package/dist/instr/pumpswap_ix.d.ts +1 -1
- package/dist/instr/pumpswap_ix.js +78 -57
- package/dist/instr/raydium_amm_v4_ix.d.ts +1 -1
- package/dist/instr/raydium_amm_v4_ix.js +94 -28
- package/dist/instr/raydium_clmm_ix.d.ts +1 -1
- package/dist/instr/raydium_clmm_ix.js +59 -26
- package/dist/instr/raydium_cpmm_ix.d.ts +1 -1
- package/dist/instr/raydium_cpmm_ix.js +46 -12
- package/dist/instr/rust_aliases.d.ts +7 -0
- package/dist/instr/rust_aliases.js +14 -0
- package/dist/instr/utils.d.ts +1 -1
- package/dist/instr/utils.js +2 -1
- package/dist/logs/discriminator_lut.d.ts +19 -0
- package/dist/logs/discriminator_lut.js +60 -0
- package/dist/logs/meteora_damm.d.ts +3 -4
- package/dist/logs/meteora_damm.js +3 -369
- package/dist/logs/optimized_matcher.d.ts +2 -2
- package/dist/logs/optimized_matcher.js +3 -3
- package/dist/logs/rust_aliases.d.ts +6 -0
- package/dist/logs/rust_aliases.js +13 -0
- package/dist/rpc_parser.d.ts +1 -0
- package/dist/rpc_parser.js +4 -1
- package/dist/shredstream/alt_lookup.d.ts +9 -0
- package/dist/shredstream/alt_lookup.js +70 -0
- package/dist/shredstream/client.d.ts +62 -0
- package/dist/shredstream/client.js +399 -0
- package/dist/shredstream/config.d.ts +30 -0
- package/dist/shredstream/config.js +34 -0
- package/dist/shredstream/entries_decode.d.ts +28 -0
- package/dist/shredstream/entries_decode.js +251 -0
- package/dist/shredstream/index.d.ts +17 -0
- package/dist/shredstream/index.js +33 -0
- package/dist/shredstream/instruction_parse.d.ts +34 -0
- package/dist/shredstream/instruction_parse.js +47 -0
- package/dist/shredstream/proto_types.d.ts +9 -0
- package/dist/shredstream/proto_types.js +2 -0
- package/dist/shredstream/shredstream.proto +15 -0
- package/dist/shredstream/wire_to_shred_tx.d.ts +2 -0
- package/dist/shredstream/wire_to_shred_tx.js +59 -0
- package/package.json +28 -11
package/.env.example
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# 复制本文件为 `.env` 并填写真实值(`.env` 已在 .gitignore,勿提交密钥)
|
|
2
|
+
# Copy to `.env` and fill in real values (`.env` is gitignored)
|
|
3
|
+
|
|
4
|
+
# --- Yellowstone gRPC(跑 gRPC 示例、npx tsx scripts/test-grpc-ts.ts / debug-grpc-ts.ts 时必填)---
|
|
5
|
+
GRPC_URL=https://your-yellowstone-host:443
|
|
6
|
+
GRPC_TOKEN=your_x_token_here
|
|
7
|
+
|
|
8
|
+
# --- 可选:仅 npx tsx scripts/test-grpc-ts.ts ---
|
|
9
|
+
# MAX_EVENTS=0
|
|
10
|
+
# TIMEOUT_MS=0
|
|
11
|
+
# JSON_PRETTY=0
|
|
12
|
+
# JSON_MAX_CHARS=
|
|
13
|
+
|
|
14
|
+
# --- 可选:仅 examples/parse_tx_by_signature.ts(HTTP RPC,非 gRPC)---
|
|
15
|
+
# TX_SIGNATURE=
|
|
16
|
+
# RPC_URL=https://api.mainnet-beta.solana.com
|
|
17
|
+
|
|
18
|
+
# --- ShredStream 示例(examples/shredstream_*.ts;亦可 CLI:--url / --rpc)---
|
|
19
|
+
# SHREDSTREAM_URL=http://127.0.0.1:10800
|
|
20
|
+
# 别名: SHRED_URL
|
|
21
|
+
# PumpFun ShredStream 示例拉 ALT 时需 HTTP RPC(可与上栏 RPC_URL 共用):
|
|
22
|
+
# RPC_URL=https://api.mainnet-beta.solana.com
|
|
23
|
+
# MAX_EVENTS=0
|
|
24
|
+
# SHREDSTREAM_STATS_SEC=0
|
package/README.md
CHANGED
|
@@ -4,23 +4,8 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
7
|
-
<
|
|
8
|
-
|
|
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">
|
|
7
|
+
<a href="https://www.npmjs.com/package/sol-parser-sdk-nodejs"><img src="https://img.shields.io/badge/npm-sol--parser--sdk--nodejs-red.svg" alt="npm"></a>
|
|
8
|
+
<a href="https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
|
|
24
9
|
</p>
|
|
25
10
|
|
|
26
11
|
<p align="center">
|
|
@@ -33,152 +18,74 @@
|
|
|
33
18
|
|
|
34
19
|
---
|
|
35
20
|
|
|
36
|
-
##
|
|
37
|
-
|
|
38
|
-
This SDK is available in multiple languages:
|
|
21
|
+
## Other language SDKs
|
|
39
22
|
|
|
40
|
-
| Language | Repository |
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
23
|
+
| Language | Repository |
|
|
24
|
+
|----------|------------|
|
|
25
|
+
| Rust | [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk) |
|
|
26
|
+
| Node.js | [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) |
|
|
27
|
+
| Python | [sol-parser-sdk-python](https://github.com/0xfnzero/sol-parser-sdk-python) |
|
|
28
|
+
| Go | [sol-parser-sdk-golang](https://github.com/0xfnzero/sol-parser-sdk-golang) |
|
|
46
29
|
|
|
47
30
|
---
|
|
48
31
|
|
|
49
|
-
##
|
|
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
|
|
32
|
+
## How to use
|
|
73
33
|
|
|
74
|
-
|
|
34
|
+
### 1. Install
|
|
75
35
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
### Installation
|
|
36
|
+
**From npm**
|
|
79
37
|
|
|
80
38
|
```bash
|
|
81
|
-
|
|
82
|
-
cd sol-parser-sdk-nodejs
|
|
83
|
-
npm install --ignore-scripts
|
|
84
|
-
npm run build
|
|
39
|
+
npm install sol-parser-sdk-nodejs
|
|
85
40
|
```
|
|
86
41
|
|
|
87
|
-
|
|
42
|
+
**From source** (folder may be named `sol-parser-sdk-ts` in a monorepo)
|
|
88
43
|
|
|
89
44
|
```bash
|
|
90
|
-
|
|
45
|
+
git clone https://github.com/0xfnzero/sol-parser-sdk-nodejs
|
|
46
|
+
cd sol-parser-sdk-nodejs
|
|
47
|
+
npm install
|
|
48
|
+
# npm run build # only if you import from dist/ instead of examples/tsx → src
|
|
91
49
|
```
|
|
92
50
|
|
|
93
|
-
###
|
|
51
|
+
### 2. Environment (Yellowstone gRPC examples)
|
|
94
52
|
|
|
95
|
-
|
|
53
|
+
At the **package root** (next to `package.json`):
|
|
96
54
|
|
|
97
55
|
```bash
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|
56
|
+
cp .env.example .env
|
|
57
|
+
# Set GRPC_URL and GRPC_TOKEN
|
|
109
58
|
```
|
|
110
59
|
|
|
111
|
-
|
|
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 |
|
|
60
|
+
Run examples from that directory so `.env` is picked up.
|
|
123
61
|
|
|
124
|
-
|
|
62
|
+
### 3. Smoke test
|
|
125
63
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
64
|
+
```bash
|
|
65
|
+
npx tsx scripts/test-grpc-ts.ts
|
|
66
|
+
```
|
|
153
67
|
|
|
154
|
-
|
|
68
|
+
Requires `GRPC_URL` and `GRPC_TOKEN`. See `.env.example` for optional vars (`MAX_EVENTS`, `TIMEOUT_MS`, etc.).
|
|
155
69
|
|
|
156
|
-
|
|
157
|
-
import { createRequire } from "module";
|
|
158
|
-
import { fileURLToPath } from "url";
|
|
159
|
-
import path from "path";
|
|
70
|
+
### 4. Minimal gRPC subscribe + parse
|
|
160
71
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const {
|
|
72
|
+
```typescript
|
|
73
|
+
import {
|
|
164
74
|
YellowstoneGrpc,
|
|
165
75
|
parseDexEventsFromGrpcTransactionInfo,
|
|
166
76
|
dexEventToJsonString,
|
|
167
|
-
}
|
|
77
|
+
} from "sol-parser-sdk-nodejs";
|
|
168
78
|
|
|
169
|
-
const ENDPOINT =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"https://solana-yellowstone-grpc.publicnode.com:443";
|
|
173
|
-
const X_TOKEN =
|
|
174
|
-
process.env.GRPC_TOKEN || process.env.GEYSER_API_TOKEN || "";
|
|
79
|
+
const ENDPOINT = process.env.GRPC_URL?.trim() ?? "";
|
|
80
|
+
const X_TOKEN = process.env.GRPC_TOKEN?.trim() ?? "";
|
|
81
|
+
if (!ENDPOINT || !X_TOKEN) throw new Error("GRPC_URL and GRPC_TOKEN are required");
|
|
175
82
|
|
|
176
83
|
const client = new YellowstoneGrpc(ENDPOINT, X_TOKEN);
|
|
177
84
|
|
|
178
85
|
const filter = {
|
|
179
86
|
account_include: [
|
|
180
87
|
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", // PumpFun
|
|
181
|
-
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap
|
|
88
|
+
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap
|
|
182
89
|
],
|
|
183
90
|
account_exclude: [],
|
|
184
91
|
account_required: [],
|
|
@@ -188,262 +95,97 @@ const filter = {
|
|
|
188
95
|
|
|
189
96
|
const sub = await client.subscribeTransactions(filter, {
|
|
190
97
|
onUpdate: (update) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const slot = update.transaction
|
|
194
|
-
if (!txInfo.transactionRaw || !txInfo.metaRaw) return;
|
|
195
|
-
|
|
98
|
+
const txInfo = update.transaction?.transaction;
|
|
99
|
+
if (!txInfo?.transactionRaw || !txInfo.metaRaw) return;
|
|
100
|
+
const slot = update.transaction!.slot;
|
|
196
101
|
const events = parseDexEventsFromGrpcTransactionInfo(txInfo, slot, undefined);
|
|
197
|
-
for (const ev of events)
|
|
198
|
-
console.log(dexEventToJsonString(ev, 2));
|
|
199
|
-
}
|
|
102
|
+
for (const ev of events) console.log(dexEventToJsonString(ev, 2));
|
|
200
103
|
},
|
|
201
|
-
onError: (err) => console.error(
|
|
202
|
-
onEnd: () =>
|
|
104
|
+
onError: (err) => console.error(err.message),
|
|
105
|
+
onEnd: () => {},
|
|
203
106
|
});
|
|
204
107
|
|
|
205
|
-
console.log(
|
|
108
|
+
console.log("subscribed", sub.id);
|
|
206
109
|
```
|
|
207
110
|
|
|
208
|
-
**
|
|
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
|
|
111
|
+
**Lighter path:** `parseLogsOnly(logs, signature, slot, …)` — no `transactionRaw`; use `applyAccountFillsToLogEvents` if you need filled accounts without full gRPC meta.
|
|
235
112
|
|
|
236
|
-
###
|
|
237
|
-
```javascript
|
|
238
|
-
// Pre-compiled regex patterns for fast protocol detection
|
|
239
|
-
const PUMPFUN_PATTERN = /Program 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P/;
|
|
113
|
+
### 5. ShredStream (HTTP — not Yellowstone gRPC)
|
|
240
114
|
|
|
241
|
-
|
|
242
|
-
if (PUMPFUN_PATTERN.test(logString)) {
|
|
243
|
-
return parsePumpFunEvent(logs, signature, slot);
|
|
244
|
-
}
|
|
245
|
-
```
|
|
115
|
+
Uses **`SHREDSTREAM_URL`** or **`SHRED_URL`** (default `http://127.0.0.1:10800`), or CLI **`--url`**. Not `GRPC_URL`.
|
|
246
116
|
|
|
247
|
-
|
|
248
|
-
```javascript
|
|
249
|
-
// Filter specific event types for targeted parsing
|
|
250
|
-
const eventFilter = {
|
|
251
|
-
include_only: ["PumpFunTrade", "PumpSwapBuy", "PumpSwapSell"]
|
|
252
|
-
};
|
|
253
|
-
```
|
|
117
|
+
The client decodes gRPC `entries` bytes in **TypeScript** (same layout as the Go `shredstream/entries_decode` path) and deserializes wire transactions with `@solana/web3.js` — **no WebAssembly or wasm-pack build**.
|
|
254
118
|
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
};
|
|
119
|
+
```bash
|
|
120
|
+
npx tsx examples/shredstream_example.ts -- --url=http://127.0.0.1:10800
|
|
291
121
|
```
|
|
292
122
|
|
|
293
|
-
|
|
294
|
-
- 60-80% reduction in processing
|
|
295
|
-
- Lower memory usage
|
|
296
|
-
- Reduced network bandwidth
|
|
123
|
+
`shredstream_pumpfun_json.ts` also needs a Solana **`RPC_URL`** (or `--rpc`) for ALTs.
|
|
297
124
|
|
|
298
125
|
---
|
|
299
126
|
|
|
300
|
-
##
|
|
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
|
|
127
|
+
## Examples
|
|
336
128
|
|
|
337
|
-
|
|
338
|
-
const sub = await client.subscribeTransactions(filter, callbacks);
|
|
129
|
+
From the **package root** after `npm install`. Examples use `npx tsx` and load `src/` directly — **no `npm run build` required** for examples. **Source** is one file per row (click to open on GitHub or npm).
|
|
339
130
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
131
|
+
| Description | Run command | Source |
|
|
132
|
+
|-------------|-------------|--------|
|
|
133
|
+
| **Scripts** | | |
|
|
134
|
+
| gRPC integration test (PumpFun + PumpSwap, account-filled `DexEvent`) | `npx tsx scripts/test-grpc-ts.ts` | [test-grpc-ts.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/scripts/test-grpc-ts.ts) |
|
|
135
|
+
| Debug: print `metaRaw` / log structure | `npx tsx scripts/debug-grpc-ts.ts` | [debug-grpc-ts.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/scripts/debug-grpc-ts.ts) |
|
|
136
|
+
| **PumpFun** | | |
|
|
137
|
+
| Pretty-print full JSON `DexEvent` over gRPC | `npx tsx examples/pumpfun_grpc_json.ts` | [pumpfun_grpc_json.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_grpc_json.ts) |
|
|
138
|
+
| PumpFun events + metrics | `npx tsx examples/pumpfun_with_metrics.ts` | [pumpfun_with_metrics.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_with_metrics.ts) |
|
|
139
|
+
| PumpFun trade filter | `npx tsx examples/pumpfun_trade_filter.ts` | [pumpfun_trade_filter.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_trade_filter.ts) |
|
|
140
|
+
| Quick PumpFun connection test | `npx tsx examples/pumpfun_quick_test.ts` | [pumpfun_quick_test.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpfun_quick_test.ts) |
|
|
141
|
+
| **PumpSwap** | | |
|
|
142
|
+
| Pretty-print full JSON `DexEvent` over gRPC | `npx tsx examples/pumpswap_grpc_json.ts` | [pumpswap_grpc_json.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpswap_grpc_json.ts) |
|
|
143
|
+
| PumpSwap events + metrics | `npx tsx examples/pumpswap_with_metrics.ts` | [pumpswap_with_metrics.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpswap_with_metrics.ts) |
|
|
144
|
+
| PumpSwap ultra-low latency | `npx tsx examples/pumpswap_low_latency.ts` | [pumpswap_low_latency.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/pumpswap_low_latency.ts) |
|
|
145
|
+
| **Meteora DAMM** | | |
|
|
146
|
+
| Meteora DAMM V2 events | `npx tsx examples/meteora_damm_grpc.ts` | [meteora_damm_grpc.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/meteora_damm_grpc.ts) |
|
|
147
|
+
| **ShredStream** (HTTP, not Yellowstone gRPC; see **step 5** above) | | |
|
|
148
|
+
| Ultra-low-latency subscribe + queue / latency stats. URL: `--url` / `SHREDSTREAM_URL` / `.env` (default `http://127.0.0.1:10800`). | `npx tsx examples/shredstream_example.ts` | [shredstream_example.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_example.ts) |
|
|
149
|
+
| PumpFun `DexEvent` JSON from ShredStream; needs Solana **RPC** for ALTs (`RPC_URL` or `--rpc`). | `npx tsx examples/shredstream_pumpfun_json.ts` | [shredstream_pumpfun_json.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_pumpfun_json.ts) |
|
|
150
|
+
| **Multi-protocol** | | |
|
|
151
|
+
| Subscribe to all DEX protocols | `npx tsx examples/multi_protocol_grpc.ts` | [multi_protocol_grpc.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/multi_protocol_grpc.ts) |
|
|
152
|
+
| **Utility** | | |
|
|
153
|
+
| Verify `onUpdate` sync errors do not kill the gRPC stream | `npx tsx examples/grpc_onupdate_error_test.ts` | [grpc_onupdate_error_test.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/grpc_onupdate_error_test.ts) |
|
|
154
|
+
| Parse tx by signature (`parseTransactionFromRpc`; not gRPC). Set `TX_SIGNATURE` in `.env` or env. | `npx tsx examples/parse_tx_by_signature.ts` | [parse_tx_by_signature.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/parse_tx_by_signature.ts) |
|
|
343
155
|
|
|
344
|
-
|
|
156
|
+
**`npm run` aliases** (same source files as the ShredStream rows above):
|
|
345
157
|
|
|
346
|
-
|
|
158
|
+
- `npm run example:shredstream` → [shredstream_example.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_example.ts)
|
|
159
|
+
- `npm run example:shredstream:subscribe` → [shredstream_example.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_example.ts)
|
|
160
|
+
- `npm run example:shredstream:pumpfun-json` → [shredstream_pumpfun_json.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_pumpfun_json.ts)
|
|
347
161
|
|
|
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
|
-
```
|
|
162
|
+
**Env:** gRPC examples need **`GRPC_URL`** + **`GRPC_TOKEN`**. ShredStream uses **`SHREDSTREAM_URL`** / **`SHRED_URL`** or **`--url`**; `shredstream_pumpfun_json` also needs **`RPC_URL`** / **`--rpc`**. See **`.env.example`**.
|
|
384
163
|
|
|
385
164
|
---
|
|
386
165
|
|
|
387
|
-
##
|
|
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
|
|
166
|
+
## Protocols
|
|
403
167
|
|
|
404
|
-
|
|
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
|
|
168
|
+
PumpFun, PumpSwap, Raydium AMM V4 / CLMM / CPMM, Orca Whirlpool, Meteora DAMM V2 / DLMM, Bonk Launchpad (see `src/instr/`).
|
|
413
169
|
|
|
414
170
|
---
|
|
415
171
|
|
|
416
|
-
##
|
|
417
|
-
|
|
418
|
-
MIT License
|
|
419
|
-
|
|
420
|
-
## 📞 Contact
|
|
172
|
+
## Useful exports
|
|
421
173
|
|
|
422
|
-
-
|
|
423
|
-
-
|
|
424
|
-
-
|
|
425
|
-
- **Discord**: https://discord.gg/vuazbGkqQE
|
|
174
|
+
- `parseDexEventsFromGrpcTransactionInfo` — needs `transactionRaw` + `metaRaw` (Rust gRPC parity).
|
|
175
|
+
- `parseRpcTransaction` / `parseTransactionFromRpc` — HTTP RPC path.
|
|
176
|
+
- `dexEventToJsonString` — BigInt-safe JSON.
|
|
426
177
|
|
|
427
178
|
---
|
|
428
179
|
|
|
429
|
-
##
|
|
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
|
|
180
|
+
## Development
|
|
439
181
|
|
|
440
182
|
```bash
|
|
441
|
-
# Build
|
|
442
183
|
npm run build
|
|
184
|
+
npm run check:migration # parity checks; needs build
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
443
188
|
|
|
444
|
-
|
|
445
|
-
npm run dev
|
|
189
|
+
## License
|
|
446
190
|
|
|
447
|
-
|
|
448
|
-
npm run typecheck
|
|
449
|
-
```
|
|
191
|
+
MIT — https://github.com/0xfnzero/sol-parser-sdk-nodejs
|