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/README_CN.md
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h1>⚡ Sol Parser SDK - Node.js</h1>
|
|
3
|
-
<h3><em>高性能 Solana DEX
|
|
3
|
+
<h3><em>高性能 Solana DEX 事件解析(Node.js / TypeScript)</em></h3>
|
|
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,142 +16,82 @@
|
|
|
31
16
|
<a href="https://discord.gg/vuazbGkqQE">Discord</a>
|
|
32
17
|
</p>
|
|
33
18
|
|
|
34
|
-
|
|
19
|
+
> ☕ **支持本项目**
|
|
20
|
+
>
|
|
21
|
+
> 本 SDK 完全免费且开源。但维护和持续更新需要消耗大量 AI 算力与 Token。如果这个 SDK 对您的开发有帮助,欢迎每月捐赠任意数量的 SOL,您的支持将帮助这个项目持续运行!
|
|
22
|
+
>
|
|
23
|
+
> **捐赠钱包:** `6oW7AXz1yRb57pYSxysuXnMs2aR1ha5rzGzReZ1MjPV8`
|
|
35
24
|
|
|
36
|
-
|
|
25
|
+
---
|
|
37
26
|
|
|
38
|
-
|
|
27
|
+
## 其他语言 SDK
|
|
39
28
|
|
|
40
|
-
| 语言 | 仓库 |
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
29
|
+
| 语言 | 仓库 |
|
|
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
|
-
### ⚡ 实时解析
|
|
52
|
-
- **零延迟** 基于日志的事件解析
|
|
53
|
-
- **gRPC 流式传输** 支持 Yellowstone/Geyser 协议
|
|
54
|
-
- **多协议** 单次订阅同时监听多个 DEX
|
|
55
|
-
- **事件类型过滤** 精准解析所需事件
|
|
56
|
-
|
|
57
|
-
### 🏗️ 支持的协议
|
|
58
|
-
- ✅ **PumpFun** - Meme 代币交易
|
|
59
|
-
- ✅ **PumpSwap** - PumpFun 交换协议
|
|
60
|
-
- ✅ **Raydium AMM V4** - 自动做市商
|
|
61
|
-
- ✅ **Raydium CLMM** - 集中流动性
|
|
62
|
-
- ✅ **Raydium CPMM** - 集中池
|
|
63
|
-
- ✅ **Orca Whirlpool** - 集中流动性 AMM
|
|
64
|
-
- ✅ **Meteora DAMM V2** - 动态 AMM
|
|
65
|
-
- ✅ **Meteora DLMM** - 动态流动性做市商
|
|
66
|
-
- ✅ **Bonk Launchpad** - 代币发射平台
|
|
38
|
+
## 怎么用
|
|
67
39
|
|
|
68
|
-
|
|
40
|
+
### 1. 安装
|
|
69
41
|
|
|
70
|
-
|
|
42
|
+
**npm**
|
|
71
43
|
|
|
72
|
-
|
|
44
|
+
```bash
|
|
45
|
+
npm install sol-parser-sdk-nodejs
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**源码**(monorepo 里目录可能是 `sol-parser-sdk-ts`)
|
|
73
49
|
|
|
74
50
|
```bash
|
|
75
51
|
git clone https://github.com/0xfnzero/sol-parser-sdk-nodejs
|
|
76
52
|
cd sol-parser-sdk-nodejs
|
|
77
|
-
npm install
|
|
78
|
-
npm run build
|
|
53
|
+
npm install
|
|
54
|
+
# npm run build # 若从 dist 引用而非 tsx 跑 examples,再执行
|
|
79
55
|
```
|
|
80
56
|
|
|
81
|
-
###
|
|
57
|
+
### 2. 环境变量(Yellowstone gRPC 示例)
|
|
82
58
|
|
|
83
|
-
|
|
59
|
+
在**包根目录**(与 `package.json` 同级):
|
|
84
60
|
|
|
85
61
|
```bash
|
|
86
|
-
|
|
87
|
-
GRPC_URL
|
|
88
|
-
|
|
89
|
-
# PumpFun 详细性能指标(单事件明细 + 每 10 秒统计)
|
|
90
|
-
GRPC_TOKEN=你的token node examples/pumpfun_with_metrics.mjs
|
|
91
|
-
|
|
92
|
-
# PumpSwap 详细性能指标(单事件明细 + 每 10 秒统计)
|
|
93
|
-
GRPC_TOKEN=你的token node examples/pumpswap_with_metrics.mjs
|
|
94
|
-
|
|
95
|
-
# PumpSwap 超低延迟测试
|
|
96
|
-
GRPC_TOKEN=你的token node examples/pumpswap_low_latency.mjs
|
|
62
|
+
cp .env.example .env
|
|
63
|
+
# 填写 GRPC_URL、GRPC_TOKEN
|
|
97
64
|
```
|
|
98
65
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
| 变量 | 说明 |
|
|
102
|
-
|------|------|
|
|
103
|
-
| **`GRPC_URL`** | Yellowstone gRPC 端点(优先使用)。例:`https://solana-yellowstone-grpc.publicnode.com:443` |
|
|
104
|
-
| **`GRPC_TOKEN`** | 对应端点的 `x-token`(优先使用) |
|
|
105
|
-
| **`GEYSER_ENDPOINT`** | 与 `GRPC_URL` 同义,兼容旧配置 |
|
|
106
|
-
| **`GEYSER_API_TOKEN`** | 与 `GRPC_TOKEN` 同义,兼容旧配置 |
|
|
107
|
-
| **`MAX_EVENTS`** | `*_grpc_json.mjs` 与 `npm run test:grpc`:解析满 N 条事件后退出;`0` 表示持续运行直到 Ctrl+C |
|
|
108
|
-
| **`TIMEOUT_MS`** | 仅 `npm run test:grpc`:运行 N 毫秒后自动退出;`0` 表示不超时(可与 `MAX_EVENTS` 同时设,先满足任一条件即退出) |
|
|
109
|
-
| **`JSON_PRETTY`** | `npm run test:grpc`:设为 `1` 或 `true` 时多行缩进打印(默认单行紧凑 JSON) |
|
|
110
|
-
| **`JSON_MAX_CHARS`** | `npm run test:grpc`:每条事件 JSON 最大字符数;不设或 `0` 表示不截断 |
|
|
111
|
-
|
|
112
|
-
部分脚本对公共节点带默认 token;生产环境请显式设置 `GRPC_TOKEN`。
|
|
113
|
-
|
|
114
|
-
### 示例列表
|
|
66
|
+
在该目录下执行下面的 `npx tsx`,以便加载 `.env`。
|
|
115
67
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
| 描述 | 运行命令 | 源码 |
|
|
119
|
-
|------|----------|------|
|
|
120
|
-
| **本包脚本** | | |
|
|
121
|
-
| gRPC 集成测试(PumpFun + PumpSwap,账户填充后的 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) |
|
|
122
|
-
| 调试:打印 meta / 日志结构 | `npm run debug:grpc` | [scripts/debug-grpc-ts.mjs](https://github.com/0xfnzero/sol-parser-sdk-nodejs/blob/main/scripts/debug-grpc-ts.mjs) |
|
|
123
|
-
| **PumpFun** | | |
|
|
124
|
-
| gRPC 订阅并输出**完整 JSON** DexEvent(字段与 Rust 对齐) | `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) |
|
|
125
|
-
| PumpFun 事件解析 + 性能指标 | `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) |
|
|
126
|
-
| PumpFun 交易类型过滤 | `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) |
|
|
127
|
-
| PumpFun 快速连接测试 | `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) |
|
|
128
|
-
| **PumpSwap** | | |
|
|
129
|
-
| gRPC 订阅并输出**完整 JSON** DexEvent(字段与 Rust 对齐) | `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) |
|
|
130
|
-
| PumpSwap 事件 + 性能统计 | `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) |
|
|
131
|
-
| PumpSwap 超低延迟 | `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) |
|
|
132
|
-
| **Meteora DAMM** | | |
|
|
133
|
-
| Meteora DAMM V2 事件 | `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) |
|
|
134
|
-
| **多协议** | | |
|
|
135
|
-
| 同时订阅所有 DEX 协议 | `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) |
|
|
136
|
-
| **工具 / 测试** | | |
|
|
137
|
-
| 验证 onUpdate 同步抛错不会打断 gRPC 流 | `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) |
|
|
138
|
-
| 通过签名解析交易(RPC,非 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) |
|
|
68
|
+
### 3. 冒烟
|
|
139
69
|
|
|
140
|
-
|
|
70
|
+
```bash
|
|
71
|
+
npx tsx scripts/test-grpc-ts.ts
|
|
72
|
+
```
|
|
141
73
|
|
|
142
|
-
|
|
74
|
+
需要 `GRPC_URL`、`GRPC_TOKEN`。更多变量见 `.env.example`(如 `MAX_EVENTS`、`TIMEOUT_MS`)。
|
|
143
75
|
|
|
144
|
-
|
|
145
|
-
import { createRequire } from "module";
|
|
146
|
-
import { fileURLToPath } from "url";
|
|
147
|
-
import path from "path";
|
|
76
|
+
### 4. 最小 gRPC 订阅示例
|
|
148
77
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const {
|
|
78
|
+
```typescript
|
|
79
|
+
import {
|
|
152
80
|
YellowstoneGrpc,
|
|
153
81
|
parseDexEventsFromGrpcTransactionInfo,
|
|
154
82
|
dexEventToJsonString,
|
|
155
|
-
}
|
|
83
|
+
} from "sol-parser-sdk-nodejs";
|
|
156
84
|
|
|
157
|
-
const ENDPOINT =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
"https://solana-yellowstone-grpc.publicnode.com:443";
|
|
161
|
-
const X_TOKEN =
|
|
162
|
-
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");
|
|
163
88
|
|
|
164
89
|
const client = new YellowstoneGrpc(ENDPOINT, X_TOKEN);
|
|
165
90
|
|
|
166
91
|
const filter = {
|
|
167
92
|
account_include: [
|
|
168
93
|
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", // PumpFun
|
|
169
|
-
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap
|
|
94
|
+
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", // PumpSwap
|
|
170
95
|
],
|
|
171
96
|
account_exclude: [],
|
|
172
97
|
account_required: [],
|
|
@@ -176,168 +101,97 @@ const filter = {
|
|
|
176
101
|
|
|
177
102
|
const sub = await client.subscribeTransactions(filter, {
|
|
178
103
|
onUpdate: (update) => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const slot = update.transaction
|
|
182
|
-
if (!txInfo.transactionRaw || !txInfo.metaRaw) return;
|
|
183
|
-
|
|
104
|
+
const txInfo = update.transaction?.transaction;
|
|
105
|
+
if (!txInfo?.transactionRaw || !txInfo.metaRaw) return;
|
|
106
|
+
const slot = update.transaction!.slot;
|
|
184
107
|
const events = parseDexEventsFromGrpcTransactionInfo(txInfo, slot, undefined);
|
|
185
|
-
for (const ev of events)
|
|
186
|
-
console.log(dexEventToJsonString(ev, 2));
|
|
187
|
-
}
|
|
108
|
+
for (const ev of events) console.log(dexEventToJsonString(ev, 2));
|
|
188
109
|
},
|
|
189
|
-
onError: (err) => console.error(
|
|
190
|
-
onEnd: () =>
|
|
110
|
+
onError: (err) => console.error(err.message),
|
|
111
|
+
onEnd: () => {},
|
|
191
112
|
});
|
|
192
113
|
|
|
193
|
-
console.log(
|
|
114
|
+
console.log("subscribed", sub.id);
|
|
194
115
|
```
|
|
195
116
|
|
|
196
|
-
|
|
117
|
+
更轻量:仅用日志用 `parseLogsOnly`;要补账户可再配合 `applyAccountFillsToLogEvents`。
|
|
197
118
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
## 🏗️ 支持的协议与事件
|
|
201
|
-
|
|
202
|
-
### 事件类型
|
|
203
|
-
每个协议均支持:
|
|
204
|
-
- 📈 **交易/兑换事件** - 买入/卖出交易
|
|
205
|
-
- 💧 **流动性事件** - 存入/提取
|
|
206
|
-
- 🏊 **池子事件** - 池子创建/初始化
|
|
207
|
-
- 🎯 **仓位事件** - 开仓/平仓(CLMM)
|
|
208
|
-
|
|
209
|
-
### PumpFun 事件
|
|
210
|
-
- `PumpFunBuy` - 买入代币
|
|
211
|
-
- `PumpFunSell` - 卖出代币
|
|
212
|
-
- `PumpFunBuyExactSolIn` - 指定 SOL 数量买入
|
|
213
|
-
- `PumpFunCreate` - 创建新代币
|
|
214
|
-
- `PumpFunTrade` - 通用交易(兜底)
|
|
215
|
-
|
|
216
|
-
### PumpSwap 事件
|
|
217
|
-
- `PumpSwapBuy` - 通过池子买入代币
|
|
218
|
-
- `PumpSwapSell` - 通过池子卖出代币
|
|
219
|
-
- `PumpSwapCreatePool` - 创建流动性池
|
|
220
|
-
- `PumpSwapLiquidityAdded` - 添加流动性
|
|
221
|
-
- `PumpSwapLiquidityRemoved` - 移除流动性
|
|
222
|
-
|
|
223
|
-
### Raydium 事件
|
|
224
|
-
- `RaydiumAmmV4Swap` - AMM V4 兑换
|
|
225
|
-
- `RaydiumClmmSwap` - CLMM 兑换
|
|
226
|
-
- `RaydiumCpmmSwap` - CPMM 兑换
|
|
227
|
-
|
|
228
|
-
### Orca 事件
|
|
229
|
-
- `OrcaWhirlpoolSwap` - Whirlpool 兑换
|
|
230
|
-
|
|
231
|
-
### Meteora 事件
|
|
232
|
-
- `MeteoraDammV2Swap` - DAMM V2 兑换
|
|
233
|
-
- `MeteoraDammV2AddLiquidity` - 添加流动性
|
|
234
|
-
- `MeteoraDammV2RemoveLiquidity` - 移除流动性
|
|
235
|
-
- `MeteoraDammV2CreatePosition` - 创建仓位
|
|
236
|
-
- `MeteoraDammV2ClosePosition` - 关闭仓位
|
|
237
|
-
|
|
238
|
-
### Bonk 事件
|
|
239
|
-
- `BonkTrade` - Bonk Launchpad 交易
|
|
119
|
+
### 5. ShredStream(HTTP,不是 Yellowstone gRPC)
|
|
240
120
|
|
|
241
|
-
|
|
121
|
+
使用 **`SHREDSTREAM_URL`** / **`SHRED_URL`**(默认 `http://127.0.0.1:10800`)或命令行 **`--url`**,**不用** `GRPC_URL`。
|
|
242
122
|
|
|
243
|
-
|
|
123
|
+
客户端在 **TypeScript** 中解码 gRPC `entries` 负载(布局与 Go `shredstream/entries_decode` 一致),并用 `@solana/web3.js` 反序列化线格式交易,**无需 WebAssembly / wasm-pack**。
|
|
244
124
|
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
├── src/
|
|
248
|
-
│ ├── core/
|
|
249
|
-
│ │ ├── unified_parser.ts # parseLogsOnly 等
|
|
250
|
-
│ │ ├── dex_event.ts # DexEvent 类型定义
|
|
251
|
-
│ │ ├── rpc_invoke_map.ts # 程序 invoke 映射、accountKeyToBase58
|
|
252
|
-
│ │ └── json_utils.ts # dexEventToJsonString
|
|
253
|
-
│ ├── grpc/
|
|
254
|
-
│ │ ├── client.ts # YellowstoneGrpc 客户端
|
|
255
|
-
│ │ ├── yellowstone_parse.ts # parseDexEventsFromGrpcTransactionInfo
|
|
256
|
-
│ │ └── types.ts # ClientConfig、TransactionFilter 等
|
|
257
|
-
│ ├── rpc_transaction.ts # parseRpcTransaction、applyAccountFillsToLogEvents
|
|
258
|
-
│ ├── logs/
|
|
259
|
-
│ │ └── optimized_matcher.ts # 日志解析(所有协议)
|
|
260
|
-
│ ├── instr/
|
|
261
|
-
│ │ └── *.ts # 指令解析器
|
|
262
|
-
│ └── index.ts # 公共 API 导出
|
|
263
|
-
├── dist/ # 编译后的 JavaScript
|
|
264
|
-
├── scripts/
|
|
265
|
-
│ ├── test-grpc-ts.mjs # npm run test:grpc
|
|
266
|
-
│ └── debug-grpc-ts.mjs # npm run debug:grpc
|
|
267
|
-
├── examples/
|
|
268
|
-
│ ├── pumpfun_grpc_json.mjs
|
|
269
|
-
│ ├── pumpswap_grpc_json.mjs
|
|
270
|
-
│ ├── grpc_onupdate_error_test.mjs
|
|
271
|
-
│ ├── pumpfun_with_metrics.mjs
|
|
272
|
-
│ ├── pumpfun_trade_filter.mjs
|
|
273
|
-
│ ├── pumpfun_quick_test.mjs
|
|
274
|
-
│ ├── pumpswap_with_metrics.mjs
|
|
275
|
-
│ ├── pumpswap_low_latency.mjs
|
|
276
|
-
│ ├── meteora_damm_grpc.mjs
|
|
277
|
-
│ ├── multi_protocol_grpc.mjs
|
|
278
|
-
│ └── parse_tx_by_signature.mjs
|
|
279
|
-
└── package.json
|
|
125
|
+
```bash
|
|
126
|
+
npx tsx examples/shredstream_example.ts -- --url=http://127.0.0.1:10800
|
|
280
127
|
```
|
|
281
128
|
|
|
129
|
+
`shredstream_pumpfun_json.ts` 另需 Solana **`RPC_URL`**(或 `--rpc`)解析 ALT。
|
|
130
|
+
|
|
282
131
|
---
|
|
283
132
|
|
|
284
|
-
##
|
|
133
|
+
## 示例列表
|
|
285
134
|
|
|
286
|
-
|
|
135
|
+
在**包根目录**执行,`npm install` 后即可。示例用 `npx tsx` 直接加载 **`src/`**,**不必先 `npm run build`**。**源码**列每个文件单独一行,链接指向 GitHub 上的对应源码(GitHub / npm 均可点击)。
|
|
287
136
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
137
|
+
| 描述 | 运行命令 | 源码 |
|
|
138
|
+
|------|----------|------|
|
|
139
|
+
| **本包脚本** | | |
|
|
140
|
+
| gRPC 集成测试(PumpFun + PumpSwap,账户填充后的 `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
|
+
| 调试:打印 `metaRaw` / 日志结构 | `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
|
+
| gRPC 输出完整 JSON `DexEvent` | `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 事件 + 性能指标 | `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 交易类型过滤 | `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
|
+
| PumpFun 快速连接测试 | `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
|
+
| gRPC 输出完整 JSON `DexEvent` | `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 事件 + 性能指标 | `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 超低延迟 | `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 事件 | `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,**非** Yellowstone gRPC;端点见上文步骤 5) | | |
|
|
154
|
+
| 超低延迟订阅、队列与延迟统计。端点:`--url` / `SHREDSTREAM_URL` / `.env`(默认 `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
|
+
| ShredStream → PumpFun `DexEvent` JSON;需 Solana **RPC** 解析 ALT(`RPC_URL` 或 `--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
|
+
| **多协议** | | |
|
|
157
|
+
| 同时订阅所有 DEX 协议 | `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
|
+
| **工具** | | |
|
|
159
|
+
| 验证 onUpdate 同步错误不会打断 gRPC 流 | `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
|
+
| 按签名解析交易(`parseTransactionFromRpc`;非 gRPC)。在 `.env` 或环境中设置 `TX_SIGNATURE`。 | `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) |
|
|
299
161
|
|
|
300
|
-
|
|
301
|
-
- **`applyAccountFillsToLogEvents(events, message, meta)`** — 若你已有日志解析结果,用手里的 message + meta 补全字段。
|
|
302
|
-
- **`parseRpcTransaction` / `parseTransactionFromRpc`** — 完整 RPC 交易解析(指令 + 日志 + 填充)。
|
|
162
|
+
**`npm run` 别名**(与上表 ShredStream 行同一源码文件,每行一条):
|
|
303
163
|
|
|
304
|
-
|
|
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)
|
|
305
167
|
|
|
306
|
-
|
|
307
|
-
const sub = await client.subscribeTransactions(filter, callbacks);
|
|
168
|
+
**环境变量:** gRPC 示例需要 **`GRPC_URL`**、**`GRPC_TOKEN`**。ShredStream 使用 **`SHREDSTREAM_URL`** / **`SHRED_URL`** 或 **`--url`**;**`shredstream_pumpfun_json`** 另需 **`RPC_URL`** / **`--rpc`**。详见 **`.env.example`**。
|
|
308
169
|
|
|
309
|
-
|
|
310
|
-
client.unsubscribe(sub.id);
|
|
311
|
-
```
|
|
170
|
+
---
|
|
312
171
|
|
|
313
|
-
|
|
172
|
+
## 协议
|
|
314
173
|
|
|
315
|
-
|
|
316
|
-
const { dexEventToJsonString } = require("./dist/index.js");
|
|
174
|
+
PumpFun、PumpSwap、Raydium AMM V4 / CLMM / CPMM、Orca Whirlpool、Meteora DAMM V2 / DLMM、Bonk Launchpad(见 `src/instr/`)。
|
|
317
175
|
|
|
318
|
-
|
|
319
|
-
// 正确处理 BigInt 序列化
|
|
320
|
-
console.log(dexEventToJsonString(ev));
|
|
321
|
-
}
|
|
322
|
-
```
|
|
176
|
+
---
|
|
323
177
|
|
|
324
|
-
|
|
178
|
+
## 常用 API
|
|
325
179
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
4. **避免对 BigInt 使用 JSON.stringify** — 请使用 `dexEventToJsonString`
|
|
330
|
-
5. **监控延迟** — 生产环境检查 `metadata.grpc_recv_us`
|
|
180
|
+
- `parseDexEventsFromGrpcTransactionInfo` — 需要 `transactionRaw` + `metaRaw`(与 Rust gRPC 对齐)。
|
|
181
|
+
- `parseRpcTransaction` / `parseTransactionFromRpc` — HTTP RPC 全量解析。
|
|
182
|
+
- `dexEventToJsonString` — 含 BigInt 的安全 JSON 输出。
|
|
331
183
|
|
|
332
184
|
---
|
|
333
185
|
|
|
334
|
-
##
|
|
186
|
+
## 开发
|
|
335
187
|
|
|
336
|
-
|
|
188
|
+
```bash
|
|
189
|
+
npm run build
|
|
190
|
+
npm run check:migration # 对齐与校验,需先 build
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
337
194
|
|
|
338
|
-
##
|
|
195
|
+
## 许可证
|
|
339
196
|
|
|
340
|
-
|
|
341
|
-
- **官网**: https://fnzero.dev/
|
|
342
|
-
- **Telegram**: https://t.me/fnzero_group
|
|
343
|
-
- **Discord**: https://discord.gg/vuazbGkqQE
|
|
197
|
+
MIT — https://github.com/0xfnzero/sol-parser-sdk-nodejs
|
package/dist/accounts/mod.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ import type { EventTypeFilter } from "../grpc/types.js";
|
|
|
5
5
|
export type { AccountData } from "./types.js";
|
|
6
6
|
export { parseNonceAccount, isNonceAccount } from "./nonce.js";
|
|
7
7
|
export { parseTokenAccount } from "./token.js";
|
|
8
|
+
export { parsePumpfunGlobal, parsePumpfunAccount, isPumpfunGlobalAccount, } from "./pumpfun.js";
|
|
8
9
|
export { parsePumpswapGlobalConfig, parsePumpswapPool, parsePumpswapAccount, isGlobalConfigAccount, isPoolAccount, } from "./pumpswap.js";
|
|
9
10
|
export { hasDiscriminator } from "./utils.js";
|
|
11
|
+
export { userWalletPubkeyForOnchainAccount } from "./wallet_resolve.js";
|
|
12
|
+
export { rpcResolveUserWalletPubkey } from "./rpc_wallet.js";
|
|
10
13
|
/** 账户数据统一解析入口 */
|
|
11
14
|
export declare function parseAccountUnified(account: AccountData, metadata: EventMetadata, eventTypeFilter?: EventTypeFilter): DexEvent | null;
|
package/dist/accounts/mod.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasDiscriminator = exports.isPoolAccount = exports.isGlobalConfigAccount = exports.parsePumpswapAccount = exports.parsePumpswapPool = exports.parsePumpswapGlobalConfig = exports.parseTokenAccount = exports.isNonceAccount = exports.parseNonceAccount = void 0;
|
|
3
|
+
exports.rpcResolveUserWalletPubkey = exports.userWalletPubkeyForOnchainAccount = exports.hasDiscriminator = exports.isPoolAccount = exports.isGlobalConfigAccount = exports.parsePumpswapAccount = exports.parsePumpswapPool = exports.parsePumpswapGlobalConfig = exports.isPumpfunGlobalAccount = exports.parsePumpfunAccount = exports.parsePumpfunGlobal = exports.parseTokenAccount = exports.isNonceAccount = exports.parseNonceAccount = void 0;
|
|
4
4
|
exports.parseAccountUnified = parseAccountUnified;
|
|
5
5
|
const program_ids_js_1 = require("../instr/program_ids.js");
|
|
6
6
|
const nonce_js_1 = require("./nonce.js");
|
|
7
7
|
const token_js_1 = require("./token.js");
|
|
8
8
|
const pumpswap_js_1 = require("./pumpswap.js");
|
|
9
|
+
const pumpfun_js_1 = require("./pumpfun.js");
|
|
9
10
|
var nonce_js_2 = require("./nonce.js");
|
|
10
11
|
Object.defineProperty(exports, "parseNonceAccount", { enumerable: true, get: function () { return nonce_js_2.parseNonceAccount; } });
|
|
11
12
|
Object.defineProperty(exports, "isNonceAccount", { enumerable: true, get: function () { return nonce_js_2.isNonceAccount; } });
|
|
12
13
|
var token_js_2 = require("./token.js");
|
|
13
14
|
Object.defineProperty(exports, "parseTokenAccount", { enumerable: true, get: function () { return token_js_2.parseTokenAccount; } });
|
|
15
|
+
var pumpfun_js_2 = require("./pumpfun.js");
|
|
16
|
+
Object.defineProperty(exports, "parsePumpfunGlobal", { enumerable: true, get: function () { return pumpfun_js_2.parsePumpfunGlobal; } });
|
|
17
|
+
Object.defineProperty(exports, "parsePumpfunAccount", { enumerable: true, get: function () { return pumpfun_js_2.parsePumpfunAccount; } });
|
|
18
|
+
Object.defineProperty(exports, "isPumpfunGlobalAccount", { enumerable: true, get: function () { return pumpfun_js_2.isPumpfunGlobalAccount; } });
|
|
14
19
|
var pumpswap_js_2 = require("./pumpswap.js");
|
|
15
20
|
Object.defineProperty(exports, "parsePumpswapGlobalConfig", { enumerable: true, get: function () { return pumpswap_js_2.parsePumpswapGlobalConfig; } });
|
|
16
21
|
Object.defineProperty(exports, "parsePumpswapPool", { enumerable: true, get: function () { return pumpswap_js_2.parsePumpswapPool; } });
|
|
@@ -19,9 +24,14 @@ Object.defineProperty(exports, "isGlobalConfigAccount", { enumerable: true, get:
|
|
|
19
24
|
Object.defineProperty(exports, "isPoolAccount", { enumerable: true, get: function () { return pumpswap_js_2.isPoolAccount; } });
|
|
20
25
|
var utils_js_1 = require("./utils.js");
|
|
21
26
|
Object.defineProperty(exports, "hasDiscriminator", { enumerable: true, get: function () { return utils_js_1.hasDiscriminator; } });
|
|
27
|
+
var wallet_resolve_js_1 = require("./wallet_resolve.js");
|
|
28
|
+
Object.defineProperty(exports, "userWalletPubkeyForOnchainAccount", { enumerable: true, get: function () { return wallet_resolve_js_1.userWalletPubkeyForOnchainAccount; } });
|
|
29
|
+
var rpc_wallet_js_1 = require("./rpc_wallet.js");
|
|
30
|
+
Object.defineProperty(exports, "rpcResolveUserWalletPubkey", { enumerable: true, get: function () { return rpc_wallet_js_1.rpcResolveUserWalletPubkey; } });
|
|
22
31
|
const ACCOUNT_EVENT_TYPES = [
|
|
23
32
|
"TokenAccount",
|
|
24
33
|
"NonceAccount",
|
|
34
|
+
"AccountPumpFunGlobal",
|
|
25
35
|
"AccountPumpSwapGlobalConfig",
|
|
26
36
|
"AccountPumpSwapPool",
|
|
27
37
|
];
|
|
@@ -42,6 +52,13 @@ function parseAccountUnified(account, metadata, eventTypeFilter) {
|
|
|
42
52
|
return ev;
|
|
43
53
|
}
|
|
44
54
|
}
|
|
55
|
+
if (account.owner === program_ids_js_1.PUMPFUN_PROGRAM_ID && eventTypeFilter) {
|
|
56
|
+
if (eventTypeFilter.shouldInclude("AccountPumpFunGlobal")) {
|
|
57
|
+
const ev = (0, pumpfun_js_1.parsePumpfunAccount)(account, metadata);
|
|
58
|
+
if (ev)
|
|
59
|
+
return ev;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
45
62
|
if ((0, nonce_js_1.isNonceAccount)(account.data)) {
|
|
46
63
|
if (eventTypeFilter && !eventTypeFilter.shouldInclude("NonceAccount"))
|
|
47
64
|
return null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EventMetadata } from "../core/metadata.js";
|
|
2
|
+
import type { DexEvent } from "../core/dex_event.js";
|
|
3
|
+
import type { AccountData } from "./types.js";
|
|
4
|
+
export declare function isPumpfunGlobalAccount(data: Uint8Array): boolean;
|
|
5
|
+
export declare function parsePumpfunGlobal(account: AccountData, metadata: EventMetadata): DexEvent | null;
|
|
6
|
+
export declare function parsePumpfunAccount(account: AccountData, metadata: EventMetadata): DexEvent | null;
|