sol-parser-sdk-nodejs 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +449 -0
  3. package/README_CN.md +343 -0
  4. package/dist/accounts/mod.d.ts +11 -0
  5. package/dist/accounts/mod.js +53 -0
  6. package/dist/accounts/nonce.d.ts +5 -0
  7. package/dist/accounts/nonce.js +32 -0
  8. package/dist/accounts/pumpswap.d.ts +8 -0
  9. package/dist/accounts/pumpswap.js +192 -0
  10. package/dist/accounts/token.d.ts +5 -0
  11. package/dist/accounts/token.js +98 -0
  12. package/dist/accounts/types.d.ts +9 -0
  13. package/dist/accounts/types.js +2 -0
  14. package/dist/accounts/utils.d.ts +1 -0
  15. package/dist/accounts/utils.js +12 -0
  16. package/dist/core/account_dispatcher_rpc.d.ts +11 -0
  17. package/dist/core/account_dispatcher_rpc.js +155 -0
  18. package/dist/core/account_fill_bonk.d.ts +4 -0
  19. package/dist/core/account_fill_bonk.js +20 -0
  20. package/dist/core/account_fill_meteora.d.ts +14 -0
  21. package/dist/core/account_fill_meteora.js +26 -0
  22. package/dist/core/account_fill_orca.d.ts +5 -0
  23. package/dist/core/account_fill_orca.js +18 -0
  24. package/dist/core/account_fill_pumpfun.d.ts +7 -0
  25. package/dist/core/account_fill_pumpfun.js +75 -0
  26. package/dist/core/account_fill_pumpswap.d.ts +10 -0
  27. package/dist/core/account_fill_pumpswap.js +78 -0
  28. package/dist/core/account_fill_raydium.d.ts +20 -0
  29. package/dist/core/account_fill_raydium.js +104 -0
  30. package/dist/core/clock.d.ts +2 -0
  31. package/dist/core/clock.js +7 -0
  32. package/dist/core/common_filler_rpc.d.ts +6 -0
  33. package/dist/core/common_filler_rpc.js +21 -0
  34. package/dist/core/dex_event.d.ts +1009 -0
  35. package/dist/core/dex_event.js +14 -0
  36. package/dist/core/error.d.ts +43 -0
  37. package/dist/core/error.js +16 -0
  38. package/dist/core/json_utils.d.ts +8 -0
  39. package/dist/core/json_utils.js +18 -0
  40. package/dist/core/metadata.d.ts +10 -0
  41. package/dist/core/metadata.js +13 -0
  42. package/dist/core/rpc_invoke_map.d.ts +23 -0
  43. package/dist/core/rpc_invoke_map.js +157 -0
  44. package/dist/core/unified_parser.d.ts +19 -0
  45. package/dist/core/unified_parser.js +48 -0
  46. package/dist/grpc/client.d.ts +52 -0
  47. package/dist/grpc/client.js +309 -0
  48. package/dist/grpc/client_stub.d.ts +5 -0
  49. package/dist/grpc/client_stub.js +5 -0
  50. package/dist/grpc/types.d.ts +132 -0
  51. package/dist/grpc/types.js +304 -0
  52. package/dist/grpc/yellowstone_parse.d.ts +9 -0
  53. package/dist/grpc/yellowstone_parse.js +46 -0
  54. package/dist/index.d.ts +18 -0
  55. package/dist/index.js +99 -0
  56. package/dist/instr/bonk_ix.d.ts +5 -0
  57. package/dist/instr/bonk_ix.js +52 -0
  58. package/dist/instr/meteora_damm_ix.d.ts +6 -0
  59. package/dist/instr/meteora_damm_ix.js +349 -0
  60. package/dist/instr/mod.d.ts +15 -0
  61. package/dist/instr/mod.js +95 -0
  62. package/dist/instr/orca_whirlpool_ix.d.ts +5 -0
  63. package/dist/instr/orca_whirlpool_ix.js +73 -0
  64. package/dist/instr/program_ids.d.ts +14 -0
  65. package/dist/instr/program_ids.js +18 -0
  66. package/dist/instr/pumpfun_ix.d.ts +5 -0
  67. package/dist/instr/pumpfun_ix.js +167 -0
  68. package/dist/instr/pumpswap_ix.d.ts +5 -0
  69. package/dist/instr/pumpswap_ix.js +215 -0
  70. package/dist/instr/raydium_amm_v4_ix.d.ts +6 -0
  71. package/dist/instr/raydium_amm_v4_ix.js +46 -0
  72. package/dist/instr/raydium_clmm_ix.d.ts +5 -0
  73. package/dist/instr/raydium_clmm_ix.js +85 -0
  74. package/dist/instr/raydium_cpmm_ix.d.ts +5 -0
  75. package/dist/instr/raydium_cpmm_ix.js +63 -0
  76. package/dist/instr/utils.d.ts +10 -0
  77. package/dist/instr/utils.js +33 -0
  78. package/dist/logs/meteora_amm.d.ts +8 -0
  79. package/dist/logs/meteora_amm.js +113 -0
  80. package/dist/logs/meteora_damm.d.ts +6 -0
  81. package/dist/logs/meteora_damm.js +509 -0
  82. package/dist/logs/meteora_dlmm.d.ts +6 -0
  83. package/dist/logs/meteora_dlmm.js +201 -0
  84. package/dist/logs/optimized_matcher.d.ts +5 -0
  85. package/dist/logs/optimized_matcher.js +194 -0
  86. package/dist/logs/orca.d.ts +6 -0
  87. package/dist/logs/orca.js +148 -0
  88. package/dist/logs/program_data.d.ts +2 -0
  89. package/dist/logs/program_data.js +22 -0
  90. package/dist/logs/program_log_discriminators.d.ts +59 -0
  91. package/dist/logs/program_log_discriminators.js +67 -0
  92. package/dist/logs/pump.d.ts +12 -0
  93. package/dist/logs/pump.js +251 -0
  94. package/dist/logs/pump_amm.d.ts +9 -0
  95. package/dist/logs/pump_amm.js +418 -0
  96. package/dist/logs/raydium_amm.d.ts +9 -0
  97. package/dist/logs/raydium_amm.js +224 -0
  98. package/dist/logs/raydium_clmm.d.ts +8 -0
  99. package/dist/logs/raydium_clmm.js +141 -0
  100. package/dist/logs/raydium_cpmm.d.ts +7 -0
  101. package/dist/logs/raydium_cpmm.js +121 -0
  102. package/dist/logs/raydium_launchpad.d.ts +12 -0
  103. package/dist/logs/raydium_launchpad.js +92 -0
  104. package/dist/parser_alias.d.ts +3 -0
  105. package/dist/parser_alias.js +2 -0
  106. package/dist/rpc_parser.d.ts +16 -0
  107. package/dist/rpc_parser.js +36 -0
  108. package/dist/rpc_transaction.d.ts +25 -0
  109. package/dist/rpc_transaction.js +111 -0
  110. package/dist/util/binary.d.ts +14 -0
  111. package/dist/util/binary.js +82 -0
  112. package/dist/warmup.d.ts +3 -0
  113. package/dist/warmup.js +23 -0
  114. package/package.json +44 -0
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSwapFromData = parseSwapFromData;
4
+ exports.parseIncreaseLiquidityFromData = parseIncreaseLiquidityFromData;
5
+ exports.parseDecreaseLiquidityFromData = parseDecreaseLiquidityFromData;
6
+ exports.parseCreatePoolFromData = parseCreatePoolFromData;
7
+ exports.parseCollectFeeFromData = parseCollectFeeFromData;
8
+ const dex_event_js_1 = require("../core/dex_event.js");
9
+ const binary_js_1 = require("../util/binary.js");
10
+ function bn64(v) {
11
+ return v ?? 0n;
12
+ }
13
+ /** Swap 日志载荷中 16 字节 u128 为 sqrt price limit,映射到 `RaydiumClmmSwapEvent.sqrt_price_x64`(与 Go/Python 字段名一致)。 */
14
+ function parseSwapFromData(data, metadata) {
15
+ let o = 0;
16
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
17
+ if (!pool_state)
18
+ return null;
19
+ o += 32;
20
+ const user = (0, binary_js_1.readPubkey)(data, o);
21
+ if (!user)
22
+ return null;
23
+ o += 32;
24
+ if (o + 8 + 8 + 16 + 1 > data.length)
25
+ return null;
26
+ o += 8;
27
+ o += 8;
28
+ const sqrt_price_limit_x64 = (0, binary_js_1.readU128LE)(data, o);
29
+ o += 16;
30
+ const is_base_input = (0, binary_js_1.readBool)(data, o);
31
+ const ev = {
32
+ metadata,
33
+ pool_state,
34
+ token_account_0: (0, dex_event_js_1.defaultPubkey)(),
35
+ token_account_1: (0, dex_event_js_1.defaultPubkey)(),
36
+ amount_0: 0n,
37
+ amount_1: 0n,
38
+ zero_for_one: is_base_input,
39
+ sqrt_price_x64: sqrt_price_limit_x64,
40
+ liquidity: 0n,
41
+ sender: user,
42
+ transfer_fee_0: 0n,
43
+ transfer_fee_1: 0n,
44
+ tick: 0,
45
+ };
46
+ return { RaydiumClmmSwap: ev };
47
+ }
48
+ function parseIncreaseLiquidityFromData(data, metadata) {
49
+ let o = 0;
50
+ const pool = (0, binary_js_1.readPubkey)(data, o);
51
+ if (!pool)
52
+ return null;
53
+ o += 32;
54
+ const user = (0, binary_js_1.readPubkey)(data, o);
55
+ if (!user)
56
+ return null;
57
+ o += 32;
58
+ const liquidity = (0, binary_js_1.readU128LE)(data, o);
59
+ o += 16;
60
+ const amount0_max = bn64((0, binary_js_1.readU64LE)(data, o));
61
+ o += 8;
62
+ const amount1_max = bn64((0, binary_js_1.readU64LE)(data, o));
63
+ const ev = {
64
+ metadata,
65
+ pool,
66
+ position_nft_mint: (0, dex_event_js_1.defaultPubkey)(),
67
+ user,
68
+ liquidity,
69
+ amount0_max,
70
+ amount1_max,
71
+ };
72
+ return { RaydiumClmmIncreaseLiquidity: ev };
73
+ }
74
+ function parseDecreaseLiquidityFromData(data, metadata) {
75
+ let o = 0;
76
+ const pool = (0, binary_js_1.readPubkey)(data, o);
77
+ if (!pool)
78
+ return null;
79
+ o += 32;
80
+ const user = (0, binary_js_1.readPubkey)(data, o);
81
+ if (!user)
82
+ return null;
83
+ o += 32;
84
+ const liquidity = (0, binary_js_1.readU128LE)(data, o);
85
+ o += 16;
86
+ const amount0_min = bn64((0, binary_js_1.readU64LE)(data, o));
87
+ o += 8;
88
+ const amount1_min = bn64((0, binary_js_1.readU64LE)(data, o));
89
+ const ev = {
90
+ metadata,
91
+ pool,
92
+ position_nft_mint: (0, dex_event_js_1.defaultPubkey)(),
93
+ user,
94
+ liquidity,
95
+ amount0_min,
96
+ amount1_min,
97
+ };
98
+ return { RaydiumClmmDecreaseLiquidity: ev };
99
+ }
100
+ function parseCreatePoolFromData(data, metadata) {
101
+ let o = 0;
102
+ const pool = (0, binary_js_1.readPubkey)(data, o);
103
+ if (!pool)
104
+ return null;
105
+ o += 32;
106
+ const creator = (0, binary_js_1.readPubkey)(data, o);
107
+ if (!creator)
108
+ return null;
109
+ o += 32;
110
+ const sqrt_price_x64 = (0, binary_js_1.readU128LE)(data, o);
111
+ o += 16;
112
+ const open_time = bn64((0, binary_js_1.readU64LE)(data, o));
113
+ const ev = {
114
+ metadata,
115
+ pool,
116
+ token_0_mint: (0, dex_event_js_1.defaultPubkey)(),
117
+ token_1_mint: (0, dex_event_js_1.defaultPubkey)(),
118
+ tick_spacing: 0,
119
+ fee_rate: 0,
120
+ creator,
121
+ sqrt_price_x64,
122
+ open_time,
123
+ };
124
+ return { RaydiumClmmCreatePool: ev };
125
+ }
126
+ function parseCollectFeeFromData(data, metadata) {
127
+ let o = 0;
128
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
129
+ if (!pool_state)
130
+ return null;
131
+ o += 32;
132
+ const position_nft_mint = (0, binary_js_1.readPubkey)(data, o);
133
+ if (!position_nft_mint)
134
+ return null;
135
+ o += 32;
136
+ const amount_0 = bn64((0, binary_js_1.readU64LE)(data, o));
137
+ o += 8;
138
+ const amount_1 = bn64((0, binary_js_1.readU64LE)(data, o));
139
+ const ev = { metadata, pool_state, position_nft_mint, amount_0, amount_1 };
140
+ return { RaydiumClmmCollectFee: ev };
141
+ }
@@ -0,0 +1,7 @@
1
+ import type { EventMetadata } from "../core/metadata.js";
2
+ import type { DexEvent } from "../core/dex_event.js";
3
+ export declare function parseSwapBaseInFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
4
+ export declare function parseSwapBaseOutFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
5
+ export declare function parseCreatePoolFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
6
+ export declare function parseDepositFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
7
+ export declare function parseWithdrawFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSwapBaseInFromData = parseSwapBaseInFromData;
4
+ exports.parseSwapBaseOutFromData = parseSwapBaseOutFromData;
5
+ exports.parseCreatePoolFromData = parseCreatePoolFromData;
6
+ exports.parseDepositFromData = parseDepositFromData;
7
+ exports.parseWithdrawFromData = parseWithdrawFromData;
8
+ const binary_js_1 = require("../util/binary.js");
9
+ function bn64(v) {
10
+ return v ?? 0n;
11
+ }
12
+ function parseSwapBaseInFromData(data, metadata) {
13
+ let o = 0;
14
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
15
+ o += 32;
16
+ o += 32;
17
+ const amount_in = bn64((0, binary_js_1.readU64LE)(data, o));
18
+ o += 8;
19
+ o += 8;
20
+ const amount_out = bn64((0, binary_js_1.readU64LE)(data, o));
21
+ o += 8;
22
+ const is_base_input = (0, binary_js_1.readBool)(data, o);
23
+ const ev = {
24
+ metadata,
25
+ pool_id: pool_state,
26
+ input_vault_before: 0n,
27
+ output_vault_before: 0n,
28
+ input_amount: amount_in,
29
+ output_amount: amount_out,
30
+ input_transfer_fee: 0n,
31
+ output_transfer_fee: 0n,
32
+ base_input: is_base_input,
33
+ };
34
+ return { RaydiumCpmmSwap: ev };
35
+ }
36
+ function parseSwapBaseOutFromData(data, metadata) {
37
+ let o = 0;
38
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
39
+ o += 32;
40
+ o += 32;
41
+ o += 8;
42
+ const amount_out = bn64((0, binary_js_1.readU64LE)(data, o));
43
+ o += 8;
44
+ const amount_in = bn64((0, binary_js_1.readU64LE)(data, o));
45
+ o += 8;
46
+ const is_base_output = (0, binary_js_1.readBool)(data, o);
47
+ const ev = {
48
+ metadata,
49
+ pool_id: pool_state,
50
+ input_vault_before: 0n,
51
+ output_vault_before: 0n,
52
+ input_amount: amount_in,
53
+ output_amount: amount_out,
54
+ input_transfer_fee: 0n,
55
+ output_transfer_fee: 0n,
56
+ base_input: !is_base_output,
57
+ };
58
+ return { RaydiumCpmmSwap: ev };
59
+ }
60
+ function parseCreatePoolFromData(data, metadata) {
61
+ let o = 0;
62
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
63
+ o += 32;
64
+ o += 32;
65
+ o += 32;
66
+ const creator = (0, binary_js_1.readPubkey)(data, o);
67
+ o += 32;
68
+ const initial_amount_0 = bn64((0, binary_js_1.readU64LE)(data, o));
69
+ o += 8;
70
+ const initial_amount_1 = bn64((0, binary_js_1.readU64LE)(data, o));
71
+ const ev = {
72
+ metadata,
73
+ pool: pool_state,
74
+ creator,
75
+ init_amount0: initial_amount_0,
76
+ init_amount1: initial_amount_1,
77
+ };
78
+ return { RaydiumCpmmInitialize: ev };
79
+ }
80
+ function parseDepositFromData(data, metadata) {
81
+ let o = 0;
82
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
83
+ o += 32;
84
+ const user = (0, binary_js_1.readPubkey)(data, o);
85
+ o += 32;
86
+ const lp_token_amount = bn64((0, binary_js_1.readU64LE)(data, o));
87
+ o += 8;
88
+ const token_0_amount = bn64((0, binary_js_1.readU64LE)(data, o));
89
+ o += 8;
90
+ const token_1_amount = bn64((0, binary_js_1.readU64LE)(data, o));
91
+ const ev = {
92
+ metadata,
93
+ pool: pool_state,
94
+ user,
95
+ lp_token_amount,
96
+ token0_amount: token_0_amount,
97
+ token1_amount: token_1_amount,
98
+ };
99
+ return { RaydiumCpmmDeposit: ev };
100
+ }
101
+ function parseWithdrawFromData(data, metadata) {
102
+ let o = 0;
103
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
104
+ o += 32;
105
+ const user = (0, binary_js_1.readPubkey)(data, o);
106
+ o += 32;
107
+ const lp_token_amount = bn64((0, binary_js_1.readU64LE)(data, o));
108
+ o += 8;
109
+ const token_0_amount = bn64((0, binary_js_1.readU64LE)(data, o));
110
+ o += 8;
111
+ const token_1_amount = bn64((0, binary_js_1.readU64LE)(data, o));
112
+ const ev = {
113
+ metadata,
114
+ pool: pool_state,
115
+ user,
116
+ lp_token_amount,
117
+ token0_amount: token_0_amount,
118
+ token1_amount: token_1_amount,
119
+ };
120
+ return { RaydiumCpmmWithdraw: ev };
121
+ }
@@ -0,0 +1,12 @@
1
+ /** Raydium Launchpad / Bonk 日志解析 */
2
+ import type { EventMetadata } from "../core/metadata.js";
3
+ import type { DexEvent } from "../core/dex_event.js";
4
+ export declare const BONK_DISC: {
5
+ TRADE: bigint;
6
+ POOL_CREATE: bigint;
7
+ MIGRATE_AMM: bigint;
8
+ };
9
+ export declare function parseBonkTradeFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
10
+ export declare function parseBonkPoolCreateFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
11
+ export declare function parseBonkMigrateAmmFromData(data: Uint8Array, metadata: EventMetadata): DexEvent | null;
12
+ export declare function parseBonkFromDiscriminator(discriminator: bigint, data: Uint8Array, metadata: EventMetadata): DexEvent | null;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BONK_DISC = void 0;
4
+ exports.parseBonkTradeFromData = parseBonkTradeFromData;
5
+ exports.parseBonkPoolCreateFromData = parseBonkPoolCreateFromData;
6
+ exports.parseBonkMigrateAmmFromData = parseBonkMigrateAmmFromData;
7
+ exports.parseBonkFromDiscriminator = parseBonkFromDiscriminator;
8
+ const binary_js_1 = require("../util/binary.js");
9
+ function disc(bytes) {
10
+ const u8 = new Uint8Array(8);
11
+ for (let i = 0; i < 8; i++)
12
+ u8[i] = bytes[i];
13
+ return new DataView(u8.buffer).getBigUint64(0, true);
14
+ }
15
+ exports.BONK_DISC = {
16
+ TRADE: disc([2, 3, 4, 5, 6, 7, 8, 9]),
17
+ POOL_CREATE: disc([1, 2, 3, 4, 5, 6, 7, 8]),
18
+ MIGRATE_AMM: disc([3, 4, 5, 6, 7, 8, 9, 10]),
19
+ };
20
+ function bn64(v) {
21
+ return v ?? 0n;
22
+ }
23
+ function parseBonkTradeFromData(data, metadata) {
24
+ if (data.length < 32 + 32 + 8 + 8 + 1 + 1)
25
+ return null;
26
+ let o = 0;
27
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
28
+ o += 32;
29
+ const user = (0, binary_js_1.readPubkey)(data, o);
30
+ o += 32;
31
+ const amount_in = bn64((0, binary_js_1.readU64LE)(data, o));
32
+ o += 8;
33
+ const amount_out = bn64((0, binary_js_1.readU64LE)(data, o));
34
+ o += 8;
35
+ const is_buy = (0, binary_js_1.readBool)(data, o);
36
+ o += 1;
37
+ const exact_in = (0, binary_js_1.readBool)(data, o);
38
+ const ev = {
39
+ metadata,
40
+ pool_state,
41
+ user,
42
+ amount_in,
43
+ amount_out,
44
+ is_buy,
45
+ trade_direction: is_buy ? "Buy" : "Sell",
46
+ exact_in,
47
+ };
48
+ return { BonkTrade: ev };
49
+ }
50
+ function parseBonkPoolCreateFromData(data, metadata) {
51
+ if (data.length < 32 + 32 + 32 + 32 + 8 + 8)
52
+ return null;
53
+ let o = 0;
54
+ const pool_state = (0, binary_js_1.readPubkey)(data, o);
55
+ o += 32;
56
+ o += 32;
57
+ o += 32;
58
+ const creator = (0, binary_js_1.readPubkey)(data, o);
59
+ o += 32;
60
+ o += 8;
61
+ o += 8;
62
+ const ev = {
63
+ metadata,
64
+ base_mint_param: { symbol: "BONK", name: "Bonk Pool", uri: "https://bonk.com", decimals: 5 },
65
+ pool_state,
66
+ creator,
67
+ };
68
+ return { BonkPoolCreate: ev };
69
+ }
70
+ function parseBonkMigrateAmmFromData(data, metadata) {
71
+ if (data.length < 32 + 32 + 32 + 8)
72
+ return null;
73
+ let o = 0;
74
+ const old_pool = (0, binary_js_1.readPubkey)(data, o);
75
+ o += 32;
76
+ const new_pool = (0, binary_js_1.readPubkey)(data, o);
77
+ o += 32;
78
+ const user = (0, binary_js_1.readPubkey)(data, o);
79
+ o += 32;
80
+ const liquidity_amount = bn64((0, binary_js_1.readU64LE)(data, o));
81
+ const ev = { metadata, old_pool, new_pool, user, liquidity_amount };
82
+ return { BonkMigrateAmm: ev };
83
+ }
84
+ function parseBonkFromDiscriminator(discriminator, data, metadata) {
85
+ if (discriminator === exports.BONK_DISC.TRADE)
86
+ return parseBonkTradeFromData(data, metadata);
87
+ if (discriminator === exports.BONK_DISC.POOL_CREATE)
88
+ return parseBonkPoolCreateFromData(data, metadata);
89
+ if (discriminator === exports.BONK_DISC.MIGRATE_AMM)
90
+ return parseBonkMigrateAmmFromData(data, metadata);
91
+ return null;
92
+ }
@@ -0,0 +1,3 @@
1
+ import type { DexEvent } from "./core/dex_event.js";
2
+ /** `DexEvent` 别名(兼容旧导入名) */
3
+ export type ParsedEvent = DexEvent;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ import type { DexEvent } from "./core/dex_event.js";
3
+ import type { EventTypeFilter } from "./grpc/types.js";
4
+ import type { ParseError } from "./core/error.js";
5
+ export { parseRpcTransaction, fillAccountsFromTransactionDataRpc, fillDataRpc, applyAccountFillsToLogEvents, } from "./rpc_transaction.js";
6
+ /**
7
+ * 通过 RPC 拉取交易并解析:
8
+ * 外层 + 内层编译指令 + 日志;不含账户字段填充(需另行调用 RPC 填充 API)。
9
+ */
10
+ export declare function parseTransactionFromRpc(connection: Connection, signature: string, filter?: EventTypeFilter): Promise<{
11
+ ok: true;
12
+ events: DexEvent[];
13
+ } | {
14
+ ok: false;
15
+ error: ParseError;
16
+ }>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyAccountFillsToLogEvents = exports.fillDataRpc = exports.fillAccountsFromTransactionDataRpc = exports.parseRpcTransaction = void 0;
4
+ exports.parseTransactionFromRpc = parseTransactionFromRpc;
5
+ const rpc_transaction_js_1 = require("./rpc_transaction.js");
6
+ var rpc_transaction_js_2 = require("./rpc_transaction.js");
7
+ Object.defineProperty(exports, "parseRpcTransaction", { enumerable: true, get: function () { return rpc_transaction_js_2.parseRpcTransaction; } });
8
+ Object.defineProperty(exports, "fillAccountsFromTransactionDataRpc", { enumerable: true, get: function () { return rpc_transaction_js_2.fillAccountsFromTransactionDataRpc; } });
9
+ Object.defineProperty(exports, "fillDataRpc", { enumerable: true, get: function () { return rpc_transaction_js_2.fillDataRpc; } });
10
+ Object.defineProperty(exports, "applyAccountFillsToLogEvents", { enumerable: true, get: function () { return rpc_transaction_js_2.applyAccountFillsToLogEvents; } });
11
+ /**
12
+ * 通过 RPC 拉取交易并解析:
13
+ * 外层 + 内层编译指令 + 日志;不含账户字段填充(需另行调用 RPC 填充 API)。
14
+ */
15
+ async function parseTransactionFromRpc(connection, signature, filter) {
16
+ try {
17
+ const tx = await connection.getTransaction(signature, {
18
+ maxSupportedTransactionVersion: 0,
19
+ });
20
+ if (!tx) {
21
+ return {
22
+ ok: false,
23
+ error: {
24
+ kind: "RpcError",
25
+ message: "Transaction not found or null response (try archive RPC for old txs).",
26
+ },
27
+ };
28
+ }
29
+ const grpcRecvUs = Math.floor(Date.now() * 1000);
30
+ return (0, rpc_transaction_js_1.parseRpcTransaction)(tx, signature, filter, { grpcRecvUs });
31
+ }
32
+ catch (e) {
33
+ const msg = e instanceof Error ? e.message : String(e);
34
+ return { ok: false, error: { kind: "RpcError", message: msg } };
35
+ }
36
+ }
@@ -0,0 +1,25 @@
1
+ import { type VersionedTransactionResponse } from "@solana/web3.js";
2
+ import type { Message, MessageV0 } from "@solana/web3.js";
3
+ import type { ConfirmedTransactionMeta } from "@solana/web3.js";
4
+ import type { DexEvent } from "./core/dex_event.js";
5
+ import type { ParseError } from "./core/error.js";
6
+ import type { EventTypeFilter } from "./grpc/types.js";
7
+ /**
8
+ * 与 Rust gRPC `parse_logs` 中 `fill_accounts_from_transaction_data` + `fill_data` 对齐:
9
+ * 对已由日志解析出的 `DexEvent` 用交易 message + meta 补全账户等字段。
10
+ */
11
+ export declare function applyAccountFillsToLogEvents(events: DexEvent[], msg: Message | MessageV0, meta: ConfirmedTransactionMeta | null): void;
12
+ /**
13
+ * 解析已获取的 `VersionedTransactionResponse`(顺序:指令 → 日志 → 账户/数据填充)。
14
+ */
15
+ export declare function parseRpcTransaction(tx: VersionedTransactionResponse, signature: string, filter?: EventTypeFilter, options?: {
16
+ grpcRecvUs?: number;
17
+ }): {
18
+ ok: true;
19
+ events: DexEvent[];
20
+ } | {
21
+ ok: false;
22
+ error: ParseError;
23
+ };
24
+ export { fillAccountsFromTransactionDataRpc } from "./core/account_dispatcher_rpc.js";
25
+ export { fillDataRpc } from "./core/common_filler_rpc.js";
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fillDataRpc = exports.fillAccountsFromTransactionDataRpc = void 0;
7
+ exports.applyAccountFillsToLogEvents = applyAccountFillsToLogEvents;
8
+ exports.parseRpcTransaction = parseRpcTransaction;
9
+ /**
10
+ * RPC 交易解析:外层 + 内层指令 → 日志 → `fillAccountsFromTransactionDataRpc` → `fillDataRpc`。
11
+ */
12
+ const bs58_1 = __importDefault(require("bs58"));
13
+ const web3_js_1 = require("@solana/web3.js");
14
+ const account_dispatcher_rpc_js_1 = require("./core/account_dispatcher_rpc.js");
15
+ const common_filler_rpc_js_1 = require("./core/common_filler_rpc.js");
16
+ const rpc_invoke_map_js_1 = require("./core/rpc_invoke_map.js");
17
+ const mod_js_1 = require("./instr/mod.js");
18
+ const optimized_matcher_js_1 = require("./logs/optimized_matcher.js");
19
+ const DEFAULT_PK = web3_js_1.PublicKey.default.toBase58();
20
+ function resolveAccounts(resolver, indices) {
21
+ const idxs = indices instanceof Uint8Array ? Array.from(indices) : indices;
22
+ return idxs.map((i) => (0, rpc_invoke_map_js_1.accountKeyToBase58)(resolver.get(i)) ?? DEFAULT_PK);
23
+ }
24
+ function parseOuterAndInnerInstructions(message, meta, signature, slot, txIndex, blockTimeUs, grpcRecvUs, filter, events) {
25
+ const resolver = (0, rpc_invoke_map_js_1.getAccountKeyResolver)(message, meta);
26
+ for (const ix of message.compiledInstructions) {
27
+ const programId = (0, rpc_invoke_map_js_1.accountKeyToBase58)(resolver.get(ix.programIdIndex));
28
+ if (!programId)
29
+ continue;
30
+ const data = (0, rpc_invoke_map_js_1.decodeIxData)(ix.data);
31
+ const accounts = resolveAccounts(resolver, ix.accountKeyIndexes);
32
+ const ev = (0, mod_js_1.parseInstructionUnified)(data, accounts, signature, slot, txIndex, blockTimeUs, grpcRecvUs, filter, programId);
33
+ if (ev)
34
+ events.push(ev);
35
+ }
36
+ const innerGroups = meta?.innerInstructions;
37
+ if (!innerGroups)
38
+ return;
39
+ for (const group of innerGroups) {
40
+ for (const ix of group.instructions) {
41
+ const programId = (0, rpc_invoke_map_js_1.accountKeyToBase58)(resolver.get(ix.programIdIndex));
42
+ if (!programId)
43
+ continue;
44
+ const data = (0, rpc_invoke_map_js_1.decodeIxData)(ix.data);
45
+ const accounts = resolveAccounts(resolver, ix.accounts);
46
+ const ev = (0, mod_js_1.parseInstructionUnified)(data, accounts, signature, slot, txIndex, blockTimeUs, grpcRecvUs, filter, programId);
47
+ if (ev)
48
+ events.push(ev);
49
+ }
50
+ }
51
+ }
52
+ function recentBlockhashBytes(recentBlockhash) {
53
+ try {
54
+ return Uint8Array.from(bs58_1.default.decode(recentBlockhash));
55
+ }
56
+ catch {
57
+ return undefined;
58
+ }
59
+ }
60
+ function applyRpcFills(events, msg, meta) {
61
+ const resolver = (0, rpc_invoke_map_js_1.getAccountKeyResolver)(msg, meta);
62
+ const programInvokes = (0, rpc_invoke_map_js_1.buildProgramInvokesMap)(msg, meta, resolver);
63
+ for (const ev of events) {
64
+ (0, account_dispatcher_rpc_js_1.fillAccountsFromTransactionDataRpc)(ev, msg, meta, programInvokes, resolver);
65
+ (0, common_filler_rpc_js_1.fillDataRpc)(ev, msg, meta, programInvokes);
66
+ }
67
+ }
68
+ /**
69
+ * 与 Rust gRPC `parse_logs` 中 `fill_accounts_from_transaction_data` + `fill_data` 对齐:
70
+ * 对已由日志解析出的 `DexEvent` 用交易 message + meta 补全账户等字段。
71
+ */
72
+ function applyAccountFillsToLogEvents(events, msg, meta) {
73
+ applyRpcFills(events, msg, meta);
74
+ }
75
+ /**
76
+ * 解析已获取的 `VersionedTransactionResponse`(顺序:指令 → 日志 → 账户/数据填充)。
77
+ */
78
+ function parseRpcTransaction(tx, signature, filter, options) {
79
+ const msg = tx.transaction?.message;
80
+ if (!msg || !(0, rpc_invoke_map_js_1.isCompiledVersionedMessage)(msg)) {
81
+ return {
82
+ ok: false,
83
+ error: {
84
+ kind: "ConversionError",
85
+ message: "交易 message 非编译形态(例如使用了 jsonParsed)。请使用默认/非 parsed 的 getTransaction 响应。",
86
+ },
87
+ };
88
+ }
89
+ const meta = tx.meta ?? null;
90
+ const slot = tx.slot;
91
+ const blockTimeUs = tx.blockTime != null ? tx.blockTime * 1_000_000 : undefined;
92
+ const grpcRecvUs = options?.grpcRecvUs ?? Math.floor(Date.now() * 1000);
93
+ const rb = recentBlockhashBytes(msg.recentBlockhash);
94
+ const events = [];
95
+ parseOuterAndInnerInstructions(msg, meta, signature, slot, 0, blockTimeUs, grpcRecvUs, filter, events);
96
+ let isCreatedBuy = false;
97
+ for (const log of meta?.logMessages ?? []) {
98
+ const e = (0, optimized_matcher_js_1.parseLogOptimized)(log, signature, slot, 0, blockTimeUs, grpcRecvUs, filter, isCreatedBuy, rb);
99
+ if (e) {
100
+ if ("PumpFunCreate" in e || "PumpFunCreateV2" in e)
101
+ isCreatedBuy = true;
102
+ events.push(e);
103
+ }
104
+ }
105
+ applyRpcFills(events, msg, meta);
106
+ return { ok: true, events };
107
+ }
108
+ var account_dispatcher_rpc_js_2 = require("./core/account_dispatcher_rpc.js");
109
+ Object.defineProperty(exports, "fillAccountsFromTransactionDataRpc", { enumerable: true, get: function () { return account_dispatcher_rpc_js_2.fillAccountsFromTransactionDataRpc; } });
110
+ var common_filler_rpc_js_2 = require("./core/common_filler_rpc.js");
111
+ Object.defineProperty(exports, "fillDataRpc", { enumerable: true, get: function () { return common_filler_rpc_js_2.fillDataRpc; } });
@@ -0,0 +1,14 @@
1
+ export declare function readU8(u8: Uint8Array, o: number): number | null;
2
+ export declare function readU16LE(u8: Uint8Array, o: number): number | null;
3
+ export declare function readU32LE(u8: Uint8Array, o: number): number | null;
4
+ export declare function readI32LE(u8: Uint8Array, o: number): number | null;
5
+ export declare function readU64LE(u8: Uint8Array, o: number): bigint | null;
6
+ export declare function readI64LE(u8: Uint8Array, o: number): bigint | null;
7
+ export declare function readU128LE(u8: Uint8Array, o: number): bigint | null;
8
+ export declare function readBool(u8: Uint8Array, o: number): boolean | null;
9
+ export declare function readPubkey(u8: Uint8Array, o: number): string | null;
10
+ export declare function readBorshString(u8: Uint8Array, o: number): {
11
+ s: string;
12
+ next: number;
13
+ } | null;
14
+ export declare function readDiscriminatorU64(u8: Uint8Array): bigint | null;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readU8 = readU8;
4
+ exports.readU16LE = readU16LE;
5
+ exports.readU32LE = readU32LE;
6
+ exports.readI32LE = readI32LE;
7
+ exports.readU64LE = readU64LE;
8
+ exports.readI64LE = readI64LE;
9
+ exports.readU128LE = readU128LE;
10
+ exports.readBool = readBool;
11
+ exports.readPubkey = readPubkey;
12
+ exports.readBorshString = readBorshString;
13
+ exports.readDiscriminatorU64 = readDiscriminatorU64;
14
+ const web3_js_1 = require("@solana/web3.js");
15
+ function readU8(u8, o) {
16
+ if (o >= u8.length)
17
+ return null;
18
+ return u8[o];
19
+ }
20
+ function readU16LE(u8, o) {
21
+ if (o + 2 > u8.length)
22
+ return null;
23
+ const v = new DataView(u8.buffer, u8.byteOffset + o, 2);
24
+ return v.getUint16(0, true);
25
+ }
26
+ function readU32LE(u8, o) {
27
+ if (o + 4 > u8.length)
28
+ return null;
29
+ const v = new DataView(u8.buffer, u8.byteOffset + o, 4);
30
+ return v.getUint32(0, true);
31
+ }
32
+ function readI32LE(u8, o) {
33
+ if (o + 4 > u8.length)
34
+ return null;
35
+ const v = new DataView(u8.buffer, u8.byteOffset + o, 4);
36
+ return v.getInt32(0, true);
37
+ }
38
+ function readU64LE(u8, o) {
39
+ if (o + 8 > u8.length)
40
+ return null;
41
+ const v = new DataView(u8.buffer, u8.byteOffset + o, 8);
42
+ return v.getBigUint64(0, true);
43
+ }
44
+ function readI64LE(u8, o) {
45
+ if (o + 8 > u8.length)
46
+ return null;
47
+ const v = new DataView(u8.buffer, u8.byteOffset + o, 8);
48
+ return v.getBigInt64(0, true);
49
+ }
50
+ function readU128LE(u8, o) {
51
+ const lo = readU64LE(u8, o);
52
+ const hi = readU64LE(u8, o + 8);
53
+ if (lo === null || hi === null)
54
+ return null;
55
+ return lo | (hi << 64n);
56
+ }
57
+ function readBool(u8, o) {
58
+ const b = readU8(u8, o);
59
+ if (b === null)
60
+ return null;
61
+ return b === 1;
62
+ }
63
+ function readPubkey(u8, o) {
64
+ if (o + 32 > u8.length)
65
+ return null;
66
+ return new web3_js_1.PublicKey(u8.subarray(o, o + 32)).toBase58();
67
+ }
68
+ function readBorshString(u8, o) {
69
+ const len = readU32LE(u8, o);
70
+ if (len === null || o + 4 + len > u8.length)
71
+ return null;
72
+ const bytes = u8.subarray(o + 4, o + 4 + len);
73
+ try {
74
+ return { s: new TextDecoder().decode(bytes), next: o + 4 + len };
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ }
80
+ function readDiscriminatorU64(u8) {
81
+ return readU64LE(u8, 0);
82
+ }
@@ -0,0 +1,3 @@
1
+ /** 预热 Base64 解码与热路径 */
2
+ export declare function warmupParser(): void;
3
+ export declare function isWarmedUp(): boolean;