sol-parser-sdk-nodejs 0.3.0 → 0.4.4
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 +100 -352
- package/README_CN.md +107 -253
- package/dist/accounts/mod.d.ts +3 -0
- package/dist/accounts/mod.js +18 -1
- package/dist/accounts/pumpfun.d.ts +6 -0
- package/dist/accounts/pumpfun.js +157 -0
- package/dist/accounts/rpc_wallet.d.ts +5 -0
- package/dist/accounts/rpc_wallet.js +18 -0
- package/dist/accounts/rust_aliases.d.ts +10 -0
- package/dist/accounts/rust_aliases.js +21 -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_fill_pumpfun.js +17 -0
- 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 +172 -44
- package/dist/core/metadata.d.ts +1 -0
- package/dist/core/pumpfun_fee_enrich.d.ts +4 -0
- package/dist/core/pumpfun_fee_enrich.js +80 -0
- package/dist/core/unified_parser.d.ts +2 -2
- package/dist/core/unified_parser.js +8 -6
- package/dist/grpc/client.d.ts +32 -1
- package/dist/grpc/client.js +400 -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/log_instr_dedup.d.ts +2 -0
- package/dist/grpc/log_instr_dedup.js +330 -0
- package/dist/grpc/order_buffer.d.ts +27 -0
- package/dist/grpc/order_buffer.js +166 -0
- package/dist/grpc/program_ids.d.ts +26 -0
- package/dist/grpc/program_ids.js +55 -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 +57 -2
- package/dist/grpc/types.js +199 -7
- package/dist/grpc/yellowstone_parse.d.ts +8 -1
- package/dist/grpc/yellowstone_parse.js +27 -11
- package/dist/index.d.ts +39 -8
- package/dist/index.js +184 -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.d.ts +1 -0
- package/dist/instr/mod.js +16 -3
- 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 +20 -15
- package/dist/instr/pump_fees_ix.d.ts +2 -0
- package/dist/instr/pump_fees_ix.js +166 -0
- package/dist/instr/pumpfun_ix.js +57 -0
- 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 +84 -30
- 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 +8 -0
- package/dist/instr/rust_aliases.js +16 -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 +62 -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 +123 -23
- package/dist/logs/program_log_discriminators.d.ts +10 -0
- package/dist/logs/program_log_discriminators.js +10 -0
- package/dist/logs/pump.d.ts +2 -0
- package/dist/logs/pump.js +51 -4
- package/dist/logs/pump_fees.d.ts +23 -0
- package/dist/logs/pump_fees.js +364 -0
- 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/rpc_transaction.d.ts +2 -0
- package/dist/rpc_transaction.js +14 -6
- 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 +49 -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">
|
|
@@ -31,154 +16,82 @@
|
|
|
31
16
|
<a href="https://discord.gg/vuazbGkqQE">Discord</a>
|
|
32
17
|
</p>
|
|
33
18
|
|
|
34
|
-
|
|
19
|
+
> ☕ **Support This Project**
|
|
20
|
+
>
|
|
21
|
+
> This SDK is completely free and open source. However, maintaining and continuously updating it requires significant AI computing resources and token consumption. If this SDK helps with your development, consider making a monthly SOL donation — any amount is appreciated and helps keep this project alive!
|
|
22
|
+
>
|
|
23
|
+
> **Donation Wallet:** `6oW7AXz1yRb57pYSxysuXnMs2aR1ha5rzGzReZ1MjPV8`
|
|
35
24
|
|
|
36
|
-
|
|
25
|
+
---
|
|
37
26
|
|
|
38
|
-
|
|
27
|
+
## Other language SDKs
|
|
39
28
|
|
|
40
|
-
| Language | Repository |
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
29
|
+
| Language | Repository |
|
|
30
|
+
|----------|------------|
|
|
31
|
+
| Rust | [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk) |
|
|
32
|
+
| Node.js | [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) |
|
|
33
|
+
| Python | [sol-parser-sdk-python](https://github.com/0xfnzero/sol-parser-sdk-python) |
|
|
34
|
+
| Go | [sol-parser-sdk-golang](https://github.com/0xfnzero/sol-parser-sdk-golang) |
|
|
46
35
|
|
|
47
36
|
---
|
|
48
37
|
|
|
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
|
|
73
|
-
|
|
74
|
-
---
|
|
38
|
+
## How to use
|
|
75
39
|
|
|
76
|
-
|
|
40
|
+
### 1. Install
|
|
77
41
|
|
|
78
|
-
|
|
42
|
+
**From npm**
|
|
79
43
|
|
|
80
44
|
```bash
|
|
81
|
-
|
|
82
|
-
cd sol-parser-sdk-nodejs
|
|
83
|
-
npm install --ignore-scripts
|
|
84
|
-
npm run build
|
|
45
|
+
npm install sol-parser-sdk-nodejs
|
|
85
46
|
```
|
|
86
47
|
|
|
87
|
-
|
|
48
|
+
**From source** (folder may be named `sol-parser-sdk-ts` in a monorepo)
|
|
88
49
|
|
|
89
50
|
```bash
|
|
90
|
-
|
|
51
|
+
git clone https://github.com/0xfnzero/sol-parser-sdk-nodejs
|
|
52
|
+
cd sol-parser-sdk-nodejs
|
|
53
|
+
npm install
|
|
54
|
+
# npm run build # only if you import from dist/ instead of examples/tsx → src
|
|
91
55
|
```
|
|
92
56
|
|
|
93
|
-
###
|
|
57
|
+
### 2. Environment (Yellowstone gRPC examples)
|
|
94
58
|
|
|
95
|
-
|
|
59
|
+
At the **package root** (next to `package.json`):
|
|
96
60
|
|
|
97
61
|
```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
|
|
62
|
+
cp .env.example .env
|
|
63
|
+
# Set GRPC_URL and GRPC_TOKEN
|
|
109
64
|
```
|
|
110
65
|
|
|
111
|
-
|
|
66
|
+
Run examples from that directory so `.env` is picked up.
|
|
112
67
|
|
|
113
|
-
|
|
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 |
|
|
68
|
+
### 3. Smoke test
|
|
123
69
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
70
|
+
```bash
|
|
71
|
+
npx tsx scripts/test-grpc-ts.ts
|
|
72
|
+
```
|
|
153
73
|
|
|
154
|
-
|
|
74
|
+
Requires `GRPC_URL` and `GRPC_TOKEN`. See `.env.example` for optional vars (`MAX_EVENTS`, `TIMEOUT_MS`, etc.).
|
|
155
75
|
|
|
156
|
-
|
|
157
|
-
import { createRequire } from "module";
|
|
158
|
-
import { fileURLToPath } from "url";
|
|
159
|
-
import path from "path";
|
|
76
|
+
### 4. Minimal gRPC subscribe + parse
|
|
160
77
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const {
|
|
78
|
+
```typescript
|
|
79
|
+
import {
|
|
164
80
|
YellowstoneGrpc,
|
|
165
81
|
parseDexEventsFromGrpcTransactionInfo,
|
|
166
82
|
dexEventToJsonString,
|
|
167
|
-
}
|
|
83
|
+
} from "sol-parser-sdk-nodejs";
|
|
168
84
|
|
|
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 || "";
|
|
85
|
+
const ENDPOINT = process.env.GRPC_URL?.trim() ?? "";
|
|
86
|
+
const X_TOKEN = process.env.GRPC_TOKEN?.trim() ?? "";
|
|
87
|
+
if (!ENDPOINT || !X_TOKEN) throw new Error("GRPC_URL and GRPC_TOKEN are required");
|
|
175
88
|
|
|
176
89
|
const client = new YellowstoneGrpc(ENDPOINT, X_TOKEN);
|
|
177
90
|
|
|
178
91
|
const filter = {
|
|
179
92
|
account_include: [
|
|
180
93
|
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", // PumpFun
|
|
181
|
-
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap
|
|
94
|
+
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap
|
|
182
95
|
],
|
|
183
96
|
account_exclude: [],
|
|
184
97
|
account_required: [],
|
|
@@ -188,262 +101,97 @@ const filter = {
|
|
|
188
101
|
|
|
189
102
|
const sub = await client.subscribeTransactions(filter, {
|
|
190
103
|
onUpdate: (update) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const slot = update.transaction
|
|
194
|
-
if (!txInfo.transactionRaw || !txInfo.metaRaw) return;
|
|
195
|
-
|
|
104
|
+
const txInfo = update.transaction?.transaction;
|
|
105
|
+
if (!txInfo?.transactionRaw || !txInfo.metaRaw) return;
|
|
106
|
+
const slot = update.transaction!.slot;
|
|
196
107
|
const events = parseDexEventsFromGrpcTransactionInfo(txInfo, slot, undefined);
|
|
197
|
-
for (const ev of events)
|
|
198
|
-
console.log(dexEventToJsonString(ev, 2));
|
|
199
|
-
}
|
|
108
|
+
for (const ev of events) console.log(dexEventToJsonString(ev, 2));
|
|
200
109
|
},
|
|
201
|
-
onError: (err) => console.error(
|
|
202
|
-
onEnd: () =>
|
|
110
|
+
onError: (err) => console.error(err.message),
|
|
111
|
+
onEnd: () => {},
|
|
203
112
|
});
|
|
204
113
|
|
|
205
|
-
console.log(
|
|
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
|
-
}
|
|
114
|
+
console.log("subscribed", sub.id);
|
|
245
115
|
```
|
|
246
116
|
|
|
247
|
-
|
|
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
|
-
```
|
|
117
|
+
**Lighter path:** `parseLogsOnly(logs, signature, slot, …)` — no `transactionRaw`; use `applyAccountFillsToLogEvents` if you need filled accounts without full gRPC meta.
|
|
264
118
|
|
|
265
|
-
|
|
119
|
+
### 5. ShredStream (HTTP — not Yellowstone gRPC)
|
|
266
120
|
|
|
267
|
-
|
|
121
|
+
Uses **`SHREDSTREAM_URL`** or **`SHRED_URL`** (default `http://127.0.0.1:10800`), or CLI **`--url`**. Not `GRPC_URL`.
|
|
268
122
|
|
|
269
|
-
|
|
123
|
+
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**.
|
|
270
124
|
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
};
|
|
125
|
+
```bash
|
|
126
|
+
npx tsx examples/shredstream_example.ts -- --url=http://127.0.0.1:10800
|
|
291
127
|
```
|
|
292
128
|
|
|
293
|
-
|
|
294
|
-
- 60-80% reduction in processing
|
|
295
|
-
- Lower memory usage
|
|
296
|
-
- Reduced network bandwidth
|
|
129
|
+
`shredstream_pumpfun_json.ts` also needs a Solana **`RPC_URL`** (or `--rpc`) for ALTs.
|
|
297
130
|
|
|
298
131
|
---
|
|
299
132
|
|
|
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).
|
|
133
|
+
## Examples
|
|
334
134
|
|
|
335
|
-
|
|
135
|
+
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).
|
|
336
136
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
137
|
+
| Description | Run command | Source |
|
|
138
|
+
|-------------|-------------|--------|
|
|
139
|
+
| **Scripts** | | |
|
|
140
|
+
| 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) |
|
|
141
|
+
| 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) |
|
|
142
|
+
| **PumpFun** | | |
|
|
143
|
+
| 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) |
|
|
144
|
+
| 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) |
|
|
145
|
+
| 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) |
|
|
146
|
+
| 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) |
|
|
147
|
+
| **PumpSwap** | | |
|
|
148
|
+
| 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) |
|
|
149
|
+
| 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) |
|
|
150
|
+
| 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) |
|
|
151
|
+
| **Meteora DAMM** | | |
|
|
152
|
+
| 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) |
|
|
153
|
+
| **ShredStream** (HTTP, not Yellowstone gRPC; see **step 5** above) | | |
|
|
154
|
+
| 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) |
|
|
155
|
+
| 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) |
|
|
156
|
+
| **Multi-protocol** | | |
|
|
157
|
+
| 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) |
|
|
158
|
+
| **Utility** | | |
|
|
159
|
+
| 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) |
|
|
160
|
+
| 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
161
|
|
|
344
|
-
|
|
162
|
+
**`npm run` aliases** (same source files as the ShredStream rows above):
|
|
345
163
|
|
|
346
|
-
|
|
164
|
+
- `npm run example:shredstream` → [shredstream_example.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_example.ts)
|
|
165
|
+
- `npm run example:shredstream:subscribe` → [shredstream_example.ts](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/examples/shredstream_example.ts)
|
|
166
|
+
- `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
167
|
|
|
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
|
-
```
|
|
168
|
+
**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
169
|
|
|
385
170
|
---
|
|
386
171
|
|
|
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
|
|
172
|
+
## Protocols
|
|
398
173
|
|
|
399
|
-
|
|
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
|
|
174
|
+
PumpFun, PumpSwap, Raydium AMM V4 / CLMM / CPMM, Orca Whirlpool, Meteora DAMM V2 / DLMM, Bonk Launchpad (see `src/instr/`).
|
|
413
175
|
|
|
414
176
|
---
|
|
415
177
|
|
|
416
|
-
##
|
|
417
|
-
|
|
418
|
-
MIT License
|
|
178
|
+
## Useful exports
|
|
419
179
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
-
|
|
423
|
-
- **Website**: https://fnzero.dev/
|
|
424
|
-
- **Telegram**: https://t.me/fnzero_group
|
|
425
|
-
- **Discord**: https://discord.gg/vuazbGkqQE
|
|
180
|
+
- `parseDexEventsFromGrpcTransactionInfo` — needs `transactionRaw` + `metaRaw` (Rust gRPC parity).
|
|
181
|
+
- `parseRpcTransaction` / `parseTransactionFromRpc` — HTTP RPC path.
|
|
182
|
+
- `dexEventToJsonString` — BigInt-safe JSON.
|
|
426
183
|
|
|
427
184
|
---
|
|
428
185
|
|
|
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
|
|
186
|
+
## Development
|
|
439
187
|
|
|
440
188
|
```bash
|
|
441
|
-
# Build
|
|
442
189
|
npm run build
|
|
190
|
+
npm run check:migration # parity checks; needs build
|
|
191
|
+
```
|
|
443
192
|
|
|
444
|
-
|
|
445
|
-
npm run dev
|
|
193
|
+
---
|
|
446
194
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT — https://github.com/0xfnzero/sol-parser-sdk-nodejs
|