sol-parser-sdk-nodejs 0.4.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.
Files changed (50) hide show
  1. package/README.md +6 -0
  2. package/README_CN.md +6 -0
  3. package/dist/accounts/mod.d.ts +1 -0
  4. package/dist/accounts/mod.js +14 -1
  5. package/dist/accounts/pumpfun.d.ts +6 -0
  6. package/dist/accounts/pumpfun.js +157 -0
  7. package/dist/accounts/rust_aliases.d.ts +1 -0
  8. package/dist/accounts/rust_aliases.js +3 -1
  9. package/dist/core/account_fill_pumpfun.js +17 -0
  10. package/dist/core/dex_event.d.ts +147 -0
  11. package/dist/core/pumpfun_fee_enrich.d.ts +4 -0
  12. package/dist/core/pumpfun_fee_enrich.js +80 -0
  13. package/dist/core/unified_parser.js +2 -0
  14. package/dist/grpc/client.d.ts +26 -1
  15. package/dist/grpc/client.js +279 -0
  16. package/dist/grpc/log_instr_dedup.d.ts +2 -0
  17. package/dist/grpc/log_instr_dedup.js +330 -0
  18. package/dist/grpc/order_buffer.d.ts +27 -0
  19. package/dist/grpc/order_buffer.js +166 -0
  20. package/dist/grpc/program_ids.d.ts +1 -0
  21. package/dist/grpc/program_ids.js +2 -1
  22. package/dist/grpc/types.d.ts +5 -1
  23. package/dist/grpc/types.js +101 -0
  24. package/dist/grpc/yellowstone_parse.d.ts +3 -1
  25. package/dist/grpc/yellowstone_parse.js +13 -10
  26. package/dist/index.d.ts +8 -7
  27. package/dist/index.js +16 -4
  28. package/dist/instr/mod.d.ts +1 -0
  29. package/dist/instr/mod.js +9 -1
  30. package/dist/instr/program_ids.d.ts +1 -1
  31. package/dist/instr/program_ids.js +2 -1
  32. package/dist/instr/pump_fees_ix.d.ts +2 -0
  33. package/dist/instr/pump_fees_ix.js +166 -0
  34. package/dist/instr/pumpfun_ix.js +57 -0
  35. package/dist/instr/raydium_clmm_ix.js +73 -52
  36. package/dist/instr/rust_aliases.d.ts +1 -0
  37. package/dist/instr/rust_aliases.js +3 -1
  38. package/dist/logs/discriminator_lut.d.ts +1 -1
  39. package/dist/logs/discriminator_lut.js +2 -0
  40. package/dist/logs/optimized_matcher.js +120 -20
  41. package/dist/logs/program_log_discriminators.d.ts +10 -0
  42. package/dist/logs/program_log_discriminators.js +10 -0
  43. package/dist/logs/pump.d.ts +2 -0
  44. package/dist/logs/pump.js +51 -4
  45. package/dist/logs/pump_fees.d.ts +23 -0
  46. package/dist/logs/pump_fees.js +364 -0
  47. package/dist/rpc_transaction.d.ts +2 -0
  48. package/dist/rpc_transaction.js +14 -6
  49. package/dist/shredstream/instruction_parse.js +2 -0
  50. package/package.json +1 -1
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readFeesAt = readFeesAt;
4
+ exports.readShareholdersVec = readShareholdersVec;
5
+ exports.readFeeTiersVec = readFeeTiersVec;
6
+ exports.parseCreateFeeSharingConfigFromData = parseCreateFeeSharingConfigFromData;
7
+ exports.parseInitializeFeeConfigFromData = parseInitializeFeeConfigFromData;
8
+ exports.parseResetFeeSharingConfigFromData = parseResetFeeSharingConfigFromData;
9
+ exports.parseRevokeFeeSharingAuthorityFromData = parseRevokeFeeSharingAuthorityFromData;
10
+ exports.parseTransferFeeSharingAuthorityFromData = parseTransferFeeSharingAuthorityFromData;
11
+ exports.parseUpdateAdminFromData = parseUpdateAdminFromData;
12
+ exports.parseUpdateFeeConfigFromData = parseUpdateFeeConfigFromData;
13
+ exports.parseUpdateFeeSharesFromData = parseUpdateFeeSharesFromData;
14
+ exports.parseUpsertFeeTiersFromData = parseUpsertFeeTiersFromData;
15
+ const dex_event_js_1 = require("../core/dex_event.js");
16
+ const binary_js_1 = require("../util/binary.js");
17
+ const MAX_SHAREHOLDERS = 64;
18
+ const MAX_FEE_TIERS = 64;
19
+ function bnI64(v) {
20
+ return v ?? 0n;
21
+ }
22
+ function bnU64(v) {
23
+ return v ?? 0n;
24
+ }
25
+ function readFeesAt(data, offset) {
26
+ if (offset + 24 > data.length)
27
+ return null;
28
+ const lp_fee_bps = bnU64((0, binary_js_1.readU64LE)(data, offset));
29
+ offset += 8;
30
+ const protocol_fee_bps = bnU64((0, binary_js_1.readU64LE)(data, offset));
31
+ offset += 8;
32
+ const creator_fee_bps = bnU64((0, binary_js_1.readU64LE)(data, offset));
33
+ offset += 8;
34
+ return { value: { lp_fee_bps, protocol_fee_bps, creator_fee_bps }, next: offset };
35
+ }
36
+ function readShareholdersVec(data, offset) {
37
+ const n = (0, binary_js_1.readU32LE)(data, offset);
38
+ if (n === null || n > MAX_SHAREHOLDERS)
39
+ return null;
40
+ offset += 4;
41
+ const value = [];
42
+ for (let i = 0; i < n; i++) {
43
+ const address = (0, binary_js_1.readPubkey)(data, offset);
44
+ if (!address)
45
+ return null;
46
+ offset += 32;
47
+ const share_bps = (0, binary_js_1.readU16LE)(data, offset);
48
+ if (share_bps === null)
49
+ return null;
50
+ offset += 2;
51
+ value.push({ address, share_bps });
52
+ }
53
+ return { value, next: offset };
54
+ }
55
+ function readFeeTiersVec(data, offset) {
56
+ const n = (0, binary_js_1.readU32LE)(data, offset);
57
+ if (n === null || n > MAX_FEE_TIERS)
58
+ return null;
59
+ offset += 4;
60
+ const value = [];
61
+ for (let i = 0; i < n; i++) {
62
+ const market_cap_lamports_threshold = (0, binary_js_1.readU128LE)(data, offset);
63
+ if (market_cap_lamports_threshold === null)
64
+ return null;
65
+ offset += 16;
66
+ const fees = readFeesAt(data, offset);
67
+ if (!fees)
68
+ return null;
69
+ offset = fees.next;
70
+ value.push({ market_cap_lamports_threshold, fees: fees.value });
71
+ }
72
+ return { value, next: offset };
73
+ }
74
+ function readOptionPubkeyAt(data, offset) {
75
+ const tag = (0, binary_js_1.readU8)(data, offset);
76
+ if (tag === null)
77
+ return null;
78
+ offset += 1;
79
+ if (tag === 0)
80
+ return { value: undefined, next: offset };
81
+ if (tag !== 1)
82
+ return null;
83
+ const value = (0, binary_js_1.readPubkey)(data, offset);
84
+ if (!value)
85
+ return null;
86
+ return { value, next: offset + 32 };
87
+ }
88
+ function readConfigStatusAt(data, offset) {
89
+ const tag = (0, binary_js_1.readU8)(data, offset);
90
+ if (tag === null)
91
+ return null;
92
+ if (tag === 0)
93
+ return { value: "Paused", next: offset + 1 };
94
+ if (tag === 1)
95
+ return { value: "Active", next: offset + 1 };
96
+ return null;
97
+ }
98
+ function parseCreateFeeSharingConfigFromData(data, metadata) {
99
+ let o = 0;
100
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
101
+ if (o + 8 > data.length)
102
+ return null;
103
+ o += 8;
104
+ const mint = (0, binary_js_1.readPubkey)(data, o);
105
+ if (!mint)
106
+ return null;
107
+ o += 32;
108
+ const bonding_curve = (0, binary_js_1.readPubkey)(data, o);
109
+ if (!bonding_curve)
110
+ return null;
111
+ o += 32;
112
+ const pool = readOptionPubkeyAt(data, o);
113
+ if (!pool)
114
+ return null;
115
+ o = pool.next;
116
+ const sharing_config = (0, binary_js_1.readPubkey)(data, o);
117
+ if (!sharing_config)
118
+ return null;
119
+ o += 32;
120
+ const admin = (0, binary_js_1.readPubkey)(data, o);
121
+ if (!admin)
122
+ return null;
123
+ o += 32;
124
+ const initial_shareholders = readShareholdersVec(data, o);
125
+ if (!initial_shareholders)
126
+ return null;
127
+ o = initial_shareholders.next;
128
+ const status = readConfigStatusAt(data, o);
129
+ if (!status)
130
+ return null;
131
+ o = status.next;
132
+ if (o !== data.length)
133
+ return null;
134
+ return {
135
+ PumpFeesCreateFeeSharingConfig: {
136
+ metadata,
137
+ timestamp,
138
+ mint,
139
+ bonding_curve,
140
+ pool: pool.value,
141
+ sharing_config,
142
+ admin,
143
+ initial_shareholders: initial_shareholders.value,
144
+ status: status.value,
145
+ },
146
+ };
147
+ }
148
+ function parseInitializeFeeConfigFromData(data, metadata) {
149
+ if (data.length !== 8 + 32 + 32)
150
+ return null;
151
+ let o = 0;
152
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
153
+ o += 8;
154
+ const admin = (0, binary_js_1.readPubkey)(data, o);
155
+ if (!admin)
156
+ return null;
157
+ o += 32;
158
+ const fee_config = (0, binary_js_1.readPubkey)(data, o);
159
+ if (!fee_config)
160
+ return null;
161
+ return { PumpFeesInitializeFeeConfig: { metadata, timestamp, admin, fee_config } };
162
+ }
163
+ function parseResetFeeSharingConfigFromData(data, metadata) {
164
+ let o = 0;
165
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
166
+ if (o + 8 > data.length)
167
+ return null;
168
+ o += 8;
169
+ const mint = (0, binary_js_1.readPubkey)(data, o);
170
+ if (!mint)
171
+ return null;
172
+ o += 32;
173
+ const sharing_config = (0, binary_js_1.readPubkey)(data, o);
174
+ if (!sharing_config)
175
+ return null;
176
+ o += 32;
177
+ const old_admin = (0, binary_js_1.readPubkey)(data, o);
178
+ if (!old_admin)
179
+ return null;
180
+ o += 32;
181
+ const old_shareholders = readShareholdersVec(data, o);
182
+ if (!old_shareholders)
183
+ return null;
184
+ o = old_shareholders.next;
185
+ const new_admin = (0, binary_js_1.readPubkey)(data, o);
186
+ if (!new_admin)
187
+ return null;
188
+ o += 32;
189
+ const new_shareholders = readShareholdersVec(data, o);
190
+ if (!new_shareholders)
191
+ return null;
192
+ o = new_shareholders.next;
193
+ if (o !== data.length)
194
+ return null;
195
+ return {
196
+ PumpFeesResetFeeSharingConfig: {
197
+ metadata,
198
+ timestamp,
199
+ mint,
200
+ sharing_config,
201
+ old_admin,
202
+ old_shareholders: old_shareholders.value,
203
+ new_admin,
204
+ new_shareholders: new_shareholders.value,
205
+ },
206
+ };
207
+ }
208
+ function parseRevokeFeeSharingAuthorityFromData(data, metadata) {
209
+ if (data.length !== 8 + 32 + 32 + 32)
210
+ return null;
211
+ let o = 0;
212
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
213
+ o += 8;
214
+ const mint = (0, binary_js_1.readPubkey)(data, o);
215
+ if (!mint)
216
+ return null;
217
+ o += 32;
218
+ const sharing_config = (0, binary_js_1.readPubkey)(data, o);
219
+ if (!sharing_config)
220
+ return null;
221
+ o += 32;
222
+ const admin = (0, binary_js_1.readPubkey)(data, o);
223
+ if (!admin)
224
+ return null;
225
+ return { PumpFeesRevokeFeeSharingAuthority: { metadata, timestamp, mint, sharing_config, admin } };
226
+ }
227
+ function parseTransferFeeSharingAuthorityFromData(data, metadata) {
228
+ if (data.length !== 8 + 32 + 32 + 32 + 32)
229
+ return null;
230
+ let o = 0;
231
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
232
+ o += 8;
233
+ const mint = (0, binary_js_1.readPubkey)(data, o);
234
+ if (!mint)
235
+ return null;
236
+ o += 32;
237
+ const sharing_config = (0, binary_js_1.readPubkey)(data, o);
238
+ if (!sharing_config)
239
+ return null;
240
+ o += 32;
241
+ const old_admin = (0, binary_js_1.readPubkey)(data, o);
242
+ if (!old_admin)
243
+ return null;
244
+ o += 32;
245
+ const new_admin = (0, binary_js_1.readPubkey)(data, o);
246
+ if (!new_admin)
247
+ return null;
248
+ return {
249
+ PumpFeesTransferFeeSharingAuthority: { metadata, timestamp, mint, sharing_config, old_admin, new_admin },
250
+ };
251
+ }
252
+ function parseUpdateAdminFromData(data, metadata) {
253
+ if (data.length !== 8 + 32 + 32)
254
+ return null;
255
+ let o = 0;
256
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
257
+ o += 8;
258
+ const old_admin = (0, binary_js_1.readPubkey)(data, o);
259
+ if (!old_admin)
260
+ return null;
261
+ o += 32;
262
+ const new_admin = (0, binary_js_1.readPubkey)(data, o);
263
+ if (!new_admin)
264
+ return null;
265
+ return { PumpFeesUpdateAdmin: { metadata, timestamp, old_admin, new_admin } };
266
+ }
267
+ function parseUpdateFeeConfigFromData(data, metadata) {
268
+ let o = 0;
269
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
270
+ if (o + 8 > data.length)
271
+ return null;
272
+ o += 8;
273
+ const admin = (0, binary_js_1.readPubkey)(data, o);
274
+ if (!admin)
275
+ return null;
276
+ o += 32;
277
+ const fee_config = (0, binary_js_1.readPubkey)(data, o);
278
+ if (!fee_config)
279
+ return null;
280
+ o += 32;
281
+ const fee_tiers = readFeeTiersVec(data, o);
282
+ if (!fee_tiers)
283
+ return null;
284
+ o = fee_tiers.next;
285
+ const flat_fees = readFeesAt(data, o);
286
+ if (!flat_fees)
287
+ return null;
288
+ o = flat_fees.next;
289
+ if (o !== data.length)
290
+ return null;
291
+ return {
292
+ PumpFeesUpdateFeeConfig: {
293
+ metadata,
294
+ timestamp,
295
+ admin,
296
+ fee_config,
297
+ fee_tiers: fee_tiers.value,
298
+ flat_fees: flat_fees.value,
299
+ },
300
+ };
301
+ }
302
+ function parseUpdateFeeSharesFromData(data, metadata) {
303
+ let o = 0;
304
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
305
+ if (o + 8 > data.length)
306
+ return null;
307
+ o += 8;
308
+ const mint = (0, binary_js_1.readPubkey)(data, o);
309
+ if (!mint)
310
+ return null;
311
+ o += 32;
312
+ const sharing_config = (0, binary_js_1.readPubkey)(data, o);
313
+ if (!sharing_config)
314
+ return null;
315
+ o += 32;
316
+ const admin = (0, binary_js_1.readPubkey)(data, o);
317
+ if (!admin)
318
+ return null;
319
+ o += 32;
320
+ const new_shareholders = readShareholdersVec(data, o);
321
+ if (!new_shareholders)
322
+ return null;
323
+ o = new_shareholders.next;
324
+ if (o !== data.length)
325
+ return null;
326
+ return {
327
+ PumpFeesUpdateFeeShares: {
328
+ metadata,
329
+ timestamp,
330
+ mint,
331
+ sharing_config,
332
+ admin,
333
+ bonding_curve: (0, dex_event_js_1.defaultPubkey)(),
334
+ pump_creator_vault: (0, dex_event_js_1.defaultPubkey)(),
335
+ new_shareholders: new_shareholders.value,
336
+ },
337
+ };
338
+ }
339
+ function parseUpsertFeeTiersFromData(data, metadata) {
340
+ let o = 0;
341
+ const timestamp = bnI64((0, binary_js_1.readI64LE)(data, o));
342
+ if (o + 8 > data.length)
343
+ return null;
344
+ o += 8;
345
+ const admin = (0, binary_js_1.readPubkey)(data, o);
346
+ if (!admin)
347
+ return null;
348
+ o += 32;
349
+ const fee_config = (0, binary_js_1.readPubkey)(data, o);
350
+ if (!fee_config)
351
+ return null;
352
+ o += 32;
353
+ const fee_tiers = readFeeTiersVec(data, o);
354
+ if (!fee_tiers)
355
+ return null;
356
+ o = fee_tiers.next;
357
+ const offset = (0, binary_js_1.readU8)(data, o);
358
+ if (offset === null)
359
+ return null;
360
+ o += 1;
361
+ if (o !== data.length)
362
+ return null;
363
+ return { PumpFeesUpsertFeeTiers: { metadata, timestamp, admin, fee_config, fee_tiers: fee_tiers.value, offset } };
364
+ }
@@ -14,6 +14,8 @@ export declare function applyAccountFillsToLogEvents(events: DexEvent[], msg: Me
14
14
  */
15
15
  export declare function parseRpcTransaction(tx: VersionedTransactionResponse, signature: string, filter?: EventTypeFilter, options?: {
16
16
  grpcRecvUs?: number;
17
+ txIndex?: number;
18
+ blockTimeUs?: number;
17
19
  }): {
18
20
  ok: true;
19
21
  events: DexEvent[];
@@ -13,7 +13,9 @@ const bs58_1 = __importDefault(require("bs58"));
13
13
  const web3_js_1 = require("@solana/web3.js");
14
14
  const account_dispatcher_rpc_js_1 = require("./core/account_dispatcher_rpc.js");
15
15
  const common_filler_rpc_js_1 = require("./core/common_filler_rpc.js");
16
+ const pumpfun_fee_enrich_js_1 = require("./core/pumpfun_fee_enrich.js");
16
17
  const rpc_invoke_map_js_1 = require("./core/rpc_invoke_map.js");
18
+ const log_instr_dedup_js_1 = require("./grpc/log_instr_dedup.js");
17
19
  const mod_js_1 = require("./instr/mod.js");
18
20
  const optimized_matcher_js_1 = require("./logs/optimized_matcher.js");
19
21
  const DEFAULT_PK = web3_js_1.PublicKey.default.toBase58();
@@ -71,6 +73,7 @@ function applyRpcFills(events, msg, meta) {
71
73
  */
72
74
  function applyAccountFillsToLogEvents(events, msg, meta) {
73
75
  applyRpcFills(events, msg, meta);
76
+ (0, pumpfun_fee_enrich_js_1.enrichPumpfunSameTxPostMerge)(events);
74
77
  }
75
78
  /**
76
79
  * 解析已获取的 `VersionedTransactionResponse`(顺序:指令 → 日志 → 账户/数据填充)。
@@ -88,21 +91,26 @@ function parseRpcTransaction(tx, signature, filter, options) {
88
91
  }
89
92
  const meta = tx.meta ?? null;
90
93
  const slot = tx.slot;
91
- const blockTimeUs = tx.blockTime != null ? tx.blockTime * 1_000_000 : undefined;
94
+ const blockTimeUs = options?.blockTimeUs ?? (tx.blockTime != null ? tx.blockTime * 1_000_000 : undefined);
92
95
  const grpcRecvUs = options?.grpcRecvUs ?? Math.floor(Date.now() * 1000);
96
+ const txIndex = options?.txIndex ?? 0;
93
97
  const rb = recentBlockhashBytes(msg.recentBlockhash);
94
- const events = [];
95
- parseOuterAndInnerInstructions(msg, meta, signature, slot, 0, blockTimeUs, grpcRecvUs, filter, events);
98
+ const instructionEvents = [];
99
+ parseOuterAndInnerInstructions(msg, meta, signature, slot, txIndex, blockTimeUs, grpcRecvUs, filter, instructionEvents);
100
+ const logEvents = [];
96
101
  let isCreatedBuy = false;
97
102
  for (const log of meta?.logMessages ?? []) {
98
- const e = (0, optimized_matcher_js_1.parseLogOptimized)(log, signature, slot, 0, blockTimeUs, grpcRecvUs, filter, isCreatedBuy, rb);
103
+ const e = (0, optimized_matcher_js_1.parseLogOptimized)(log, signature, slot, txIndex, blockTimeUs, grpcRecvUs, filter, isCreatedBuy, rb);
99
104
  if (e) {
100
105
  if ("PumpFunCreate" in e || "PumpFunCreateV2" in e)
101
106
  isCreatedBuy = true;
102
- events.push(e);
107
+ logEvents.push(e);
103
108
  }
104
109
  }
105
- applyRpcFills(events, msg, meta);
110
+ applyRpcFills(instructionEvents, msg, meta);
111
+ applyRpcFills(logEvents, msg, meta);
112
+ const events = (0, log_instr_dedup_js_1.dedupeLogInstructionEvents)(logEvents, instructionEvents);
113
+ (0, pumpfun_fee_enrich_js_1.enrichPumpfunSameTxPostMerge)(events);
106
114
  return { ok: true, events };
107
115
  }
108
116
  var account_dispatcher_rpc_js_2 = require("./core/account_dispatcher_rpc.js");
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dexEventsFromShredWasmTxWithFullKeys = dexEventsFromShredWasmTxWithFullKeys;
4
4
  exports.dexEventsFromShredWasmTx = dexEventsFromShredWasmTx;
5
+ const pumpfun_fee_enrich_js_1 = require("../core/pumpfun_fee_enrich.js");
5
6
  const mod_js_1 = require("../instr/mod.js");
6
7
  function asU8(b) {
7
8
  if (b instanceof Uint8Array)
@@ -39,6 +40,7 @@ function dexEventsFromShredWasmTxWithFullKeys(tx, fullAccountKeys, slot, txIndex
39
40
  if (ev)
40
41
  out.push(ev);
41
42
  }
43
+ (0, pumpfun_fee_enrich_js_1.enrichPumpfunSameTxPostMerge)(out);
42
44
  return out;
43
45
  }
44
46
  /** 仅静态账户表(无 RPC 时;V0+ALT 交易多数指令无法解析) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sol-parser-sdk-nodejs",
3
- "version": "0.4.0",
3
+ "version": "0.4.4",
4
4
  "description": "High-performance Solana DEX event parser for Node.js/TypeScript (Yellowstone gRPC, log parsing)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",