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.
- package/LICENSE +21 -0
- package/README.md +449 -0
- package/README_CN.md +343 -0
- package/dist/accounts/mod.d.ts +11 -0
- package/dist/accounts/mod.js +53 -0
- package/dist/accounts/nonce.d.ts +5 -0
- package/dist/accounts/nonce.js +32 -0
- package/dist/accounts/pumpswap.d.ts +8 -0
- package/dist/accounts/pumpswap.js +192 -0
- package/dist/accounts/token.d.ts +5 -0
- package/dist/accounts/token.js +98 -0
- package/dist/accounts/types.d.ts +9 -0
- package/dist/accounts/types.js +2 -0
- package/dist/accounts/utils.d.ts +1 -0
- package/dist/accounts/utils.js +12 -0
- package/dist/core/account_dispatcher_rpc.d.ts +11 -0
- package/dist/core/account_dispatcher_rpc.js +155 -0
- package/dist/core/account_fill_bonk.d.ts +4 -0
- package/dist/core/account_fill_bonk.js +20 -0
- package/dist/core/account_fill_meteora.d.ts +14 -0
- package/dist/core/account_fill_meteora.js +26 -0
- package/dist/core/account_fill_orca.d.ts +5 -0
- package/dist/core/account_fill_orca.js +18 -0
- package/dist/core/account_fill_pumpfun.d.ts +7 -0
- package/dist/core/account_fill_pumpfun.js +75 -0
- package/dist/core/account_fill_pumpswap.d.ts +10 -0
- package/dist/core/account_fill_pumpswap.js +78 -0
- package/dist/core/account_fill_raydium.d.ts +20 -0
- package/dist/core/account_fill_raydium.js +104 -0
- package/dist/core/clock.d.ts +2 -0
- package/dist/core/clock.js +7 -0
- package/dist/core/common_filler_rpc.d.ts +6 -0
- package/dist/core/common_filler_rpc.js +21 -0
- package/dist/core/dex_event.d.ts +1009 -0
- package/dist/core/dex_event.js +14 -0
- package/dist/core/error.d.ts +43 -0
- package/dist/core/error.js +16 -0
- package/dist/core/json_utils.d.ts +8 -0
- package/dist/core/json_utils.js +18 -0
- package/dist/core/metadata.d.ts +10 -0
- package/dist/core/metadata.js +13 -0
- package/dist/core/rpc_invoke_map.d.ts +23 -0
- package/dist/core/rpc_invoke_map.js +157 -0
- package/dist/core/unified_parser.d.ts +19 -0
- package/dist/core/unified_parser.js +48 -0
- package/dist/grpc/client.d.ts +52 -0
- package/dist/grpc/client.js +309 -0
- package/dist/grpc/client_stub.d.ts +5 -0
- package/dist/grpc/client_stub.js +5 -0
- package/dist/grpc/types.d.ts +132 -0
- package/dist/grpc/types.js +304 -0
- package/dist/grpc/yellowstone_parse.d.ts +9 -0
- package/dist/grpc/yellowstone_parse.js +46 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +99 -0
- package/dist/instr/bonk_ix.d.ts +5 -0
- package/dist/instr/bonk_ix.js +52 -0
- package/dist/instr/meteora_damm_ix.d.ts +6 -0
- package/dist/instr/meteora_damm_ix.js +349 -0
- package/dist/instr/mod.d.ts +15 -0
- package/dist/instr/mod.js +95 -0
- package/dist/instr/orca_whirlpool_ix.d.ts +5 -0
- package/dist/instr/orca_whirlpool_ix.js +73 -0
- package/dist/instr/program_ids.d.ts +14 -0
- package/dist/instr/program_ids.js +18 -0
- package/dist/instr/pumpfun_ix.d.ts +5 -0
- package/dist/instr/pumpfun_ix.js +167 -0
- package/dist/instr/pumpswap_ix.d.ts +5 -0
- package/dist/instr/pumpswap_ix.js +215 -0
- package/dist/instr/raydium_amm_v4_ix.d.ts +6 -0
- package/dist/instr/raydium_amm_v4_ix.js +46 -0
- package/dist/instr/raydium_clmm_ix.d.ts +5 -0
- package/dist/instr/raydium_clmm_ix.js +85 -0
- package/dist/instr/raydium_cpmm_ix.d.ts +5 -0
- package/dist/instr/raydium_cpmm_ix.js +63 -0
- package/dist/instr/utils.d.ts +10 -0
- package/dist/instr/utils.js +33 -0
- package/dist/logs/meteora_amm.d.ts +8 -0
- package/dist/logs/meteora_amm.js +113 -0
- package/dist/logs/meteora_damm.d.ts +6 -0
- package/dist/logs/meteora_damm.js +509 -0
- package/dist/logs/meteora_dlmm.d.ts +6 -0
- package/dist/logs/meteora_dlmm.js +201 -0
- package/dist/logs/optimized_matcher.d.ts +5 -0
- package/dist/logs/optimized_matcher.js +194 -0
- package/dist/logs/orca.d.ts +6 -0
- package/dist/logs/orca.js +148 -0
- package/dist/logs/program_data.d.ts +2 -0
- package/dist/logs/program_data.js +22 -0
- package/dist/logs/program_log_discriminators.d.ts +59 -0
- package/dist/logs/program_log_discriminators.js +67 -0
- package/dist/logs/pump.d.ts +12 -0
- package/dist/logs/pump.js +251 -0
- package/dist/logs/pump_amm.d.ts +9 -0
- package/dist/logs/pump_amm.js +418 -0
- package/dist/logs/raydium_amm.d.ts +9 -0
- package/dist/logs/raydium_amm.js +224 -0
- package/dist/logs/raydium_clmm.d.ts +8 -0
- package/dist/logs/raydium_clmm.js +141 -0
- package/dist/logs/raydium_cpmm.d.ts +7 -0
- package/dist/logs/raydium_cpmm.js +121 -0
- package/dist/logs/raydium_launchpad.d.ts +12 -0
- package/dist/logs/raydium_launchpad.js +92 -0
- package/dist/parser_alias.d.ts +3 -0
- package/dist/parser_alias.js +2 -0
- package/dist/rpc_parser.d.ts +16 -0
- package/dist/rpc_parser.js +36 -0
- package/dist/rpc_transaction.d.ts +25 -0
- package/dist/rpc_transaction.js +111 -0
- package/dist/util/binary.d.ts +14 -0
- package/dist/util/binary.js +82 -0
- package/dist/warmup.d.ts +3 -0
- package/dist/warmup.js +23 -0
- package/package.json +44 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSwapFromData = parseSwapFromData;
|
|
4
|
+
exports.parseAddLiquidityFromData = parseAddLiquidityFromData;
|
|
5
|
+
exports.parseRemoveLiquidityFromData = parseRemoveLiquidityFromData;
|
|
6
|
+
exports.parseBootstrapLiquidityFromData = parseBootstrapLiquidityFromData;
|
|
7
|
+
exports.parseSetPoolFeesFromData = parseSetPoolFeesFromData;
|
|
8
|
+
exports.parsePoolCreatedFromData = parsePoolCreatedFromData;
|
|
9
|
+
const binary_js_1 = require("../util/binary.js");
|
|
10
|
+
function bn64(v) {
|
|
11
|
+
return v ?? 0n;
|
|
12
|
+
}
|
|
13
|
+
function parseSwapFromData(data, metadata) {
|
|
14
|
+
let o = 0;
|
|
15
|
+
const in_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
16
|
+
o += 8;
|
|
17
|
+
const out_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
18
|
+
o += 8;
|
|
19
|
+
const trade_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
20
|
+
o += 8;
|
|
21
|
+
const admin_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
22
|
+
o += 8;
|
|
23
|
+
const host_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
24
|
+
const ev = { metadata, in_amount, out_amount, trade_fee, admin_fee, host_fee };
|
|
25
|
+
return { MeteoraPoolsSwap: ev };
|
|
26
|
+
}
|
|
27
|
+
function parseAddLiquidityFromData(data, metadata) {
|
|
28
|
+
let o = 0;
|
|
29
|
+
const lp_mint_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
30
|
+
o += 8;
|
|
31
|
+
const token_a_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
32
|
+
o += 8;
|
|
33
|
+
const token_b_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
34
|
+
const ev = { metadata, lp_mint_amount, token_a_amount, token_b_amount };
|
|
35
|
+
return { MeteoraPoolsAddLiquidity: ev };
|
|
36
|
+
}
|
|
37
|
+
function parseRemoveLiquidityFromData(data, metadata) {
|
|
38
|
+
let o = 0;
|
|
39
|
+
const lp_unmint_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
40
|
+
o += 8;
|
|
41
|
+
const token_a_out_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
42
|
+
o += 8;
|
|
43
|
+
const token_b_out_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
44
|
+
const ev = {
|
|
45
|
+
metadata,
|
|
46
|
+
lp_unmint_amount,
|
|
47
|
+
token_a_out_amount,
|
|
48
|
+
token_b_out_amount,
|
|
49
|
+
};
|
|
50
|
+
return { MeteoraPoolsRemoveLiquidity: ev };
|
|
51
|
+
}
|
|
52
|
+
function parseBootstrapLiquidityFromData(data, metadata) {
|
|
53
|
+
let o = 0;
|
|
54
|
+
const lp_mint_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
55
|
+
o += 8;
|
|
56
|
+
const token_a_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
57
|
+
o += 8;
|
|
58
|
+
const token_b_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
59
|
+
o += 8;
|
|
60
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
61
|
+
const ev = {
|
|
62
|
+
metadata,
|
|
63
|
+
lp_mint_amount,
|
|
64
|
+
token_a_amount,
|
|
65
|
+
token_b_amount,
|
|
66
|
+
pool,
|
|
67
|
+
};
|
|
68
|
+
return { MeteoraPoolsBootstrapLiquidity: ev };
|
|
69
|
+
}
|
|
70
|
+
function parseSetPoolFeesFromData(data, metadata) {
|
|
71
|
+
if (data.length < 8 + 8 + 8 + 8 + 32)
|
|
72
|
+
return null;
|
|
73
|
+
let o = 0;
|
|
74
|
+
const trade_fee_numerator = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
75
|
+
o += 8;
|
|
76
|
+
const trade_fee_denominator = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
77
|
+
o += 8;
|
|
78
|
+
const owner_trade_fee_numerator = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
79
|
+
o += 8;
|
|
80
|
+
const owner_trade_fee_denominator = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
81
|
+
o += 8;
|
|
82
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
83
|
+
const ev = {
|
|
84
|
+
metadata,
|
|
85
|
+
trade_fee_numerator,
|
|
86
|
+
trade_fee_denominator,
|
|
87
|
+
owner_trade_fee_numerator,
|
|
88
|
+
owner_trade_fee_denominator,
|
|
89
|
+
pool,
|
|
90
|
+
};
|
|
91
|
+
return { MeteoraPoolsSetPoolFees: ev };
|
|
92
|
+
}
|
|
93
|
+
function parsePoolCreatedFromData(data, metadata) {
|
|
94
|
+
let o = 0;
|
|
95
|
+
const lp_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
96
|
+
o += 32;
|
|
97
|
+
const token_a_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
98
|
+
o += 32;
|
|
99
|
+
const token_b_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
100
|
+
o += 32;
|
|
101
|
+
const pool_type = (0, binary_js_1.readU8)(data, o);
|
|
102
|
+
o += 1;
|
|
103
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
104
|
+
const ev = {
|
|
105
|
+
metadata,
|
|
106
|
+
lp_mint,
|
|
107
|
+
token_a_mint,
|
|
108
|
+
token_b_mint,
|
|
109
|
+
pool_type,
|
|
110
|
+
pool,
|
|
111
|
+
};
|
|
112
|
+
return { MeteoraPoolsPoolCreated: ev };
|
|
113
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type EventMetadata } from "../core/metadata.js";
|
|
2
|
+
import type { DexEvent } from "../core/dex_event.js";
|
|
3
|
+
/** `EvtInitializePool`:6 个 pubkey 后接 `PoolFeeParameters`(变长 Option)再接固定尾部 109 字节 */
|
|
4
|
+
export declare function parseInitializePoolEvent(data: Uint8Array, meta: EventMetadata): DexEvent | null;
|
|
5
|
+
/** Meteora DAMM Program data 入口;布局与 `parseMeteoraDammInstruction` CPI 内层载荷一致(Swap/Swap2 另含日志侧 32 字节填充,见 parseSwapEvent) */
|
|
6
|
+
export declare function parseMeteoraDammLog(log: string, signature: string, slot: number, txIndex: number, blockTimeUs: number | undefined, grpcRecvUs: number): DexEvent | null;
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseInitializePoolEvent = parseInitializePoolEvent;
|
|
4
|
+
exports.parseMeteoraDammLog = parseMeteoraDammLog;
|
|
5
|
+
const metadata_js_1 = require("../core/metadata.js");
|
|
6
|
+
const dex_event_js_1 = require("../core/dex_event.js");
|
|
7
|
+
const program_data_js_1 = require("./program_data.js");
|
|
8
|
+
const binary_js_1 = require("../util/binary.js");
|
|
9
|
+
function discOf(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
|
+
const SWAP = discOf([27, 60, 21, 213, 138, 170, 187, 147]);
|
|
16
|
+
const SWAP2 = discOf([189, 66, 51, 168, 38, 80, 117, 153]);
|
|
17
|
+
/** 与 `instr/meteora_damm_ix.ts` CPI 内层事件 disc 一致;Program data 去掉前 8 字节后与 CPI 载荷布局相同 */
|
|
18
|
+
const CREATE_POSITION = discOf([156, 15, 119, 198, 29, 181, 221, 55]);
|
|
19
|
+
const CLOSE_POSITION = discOf([20, 145, 144, 68, 143, 142, 214, 178]);
|
|
20
|
+
const ADD_LIQUIDITY = discOf([175, 242, 8, 157, 30, 247, 185, 169]);
|
|
21
|
+
const REMOVE_LIQUIDITY = discOf([87, 46, 88, 98, 175, 96, 34, 91]);
|
|
22
|
+
/** Meteora `cp-amm` `EvtInitializePool`(见 `programs/cp-amm/src/event.rs`) */
|
|
23
|
+
const INITIALIZE_POOL = discOf([228, 50, 246, 85, 203, 66, 134, 37]);
|
|
24
|
+
function bn64(v) {
|
|
25
|
+
return v ?? 0n;
|
|
26
|
+
}
|
|
27
|
+
function emptyVaults() {
|
|
28
|
+
const z = (0, dex_event_js_1.defaultPubkey)();
|
|
29
|
+
return {
|
|
30
|
+
token_a_vault: z,
|
|
31
|
+
token_b_vault: z,
|
|
32
|
+
token_a_mint: z,
|
|
33
|
+
token_b_mint: z,
|
|
34
|
+
token_a_program: z,
|
|
35
|
+
token_b_program: z,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function parseSwapEvent(data, meta) {
|
|
39
|
+
let o = 0;
|
|
40
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
41
|
+
o += 32;
|
|
42
|
+
o += 32;
|
|
43
|
+
const trade_direction = (0, binary_js_1.readU8)(data, o);
|
|
44
|
+
o += 1;
|
|
45
|
+
const has_referral = (0, binary_js_1.readBool)(data, o);
|
|
46
|
+
o += 1;
|
|
47
|
+
const amount_in = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
48
|
+
o += 8;
|
|
49
|
+
const minimum_amount_out = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
50
|
+
o += 8;
|
|
51
|
+
const actual_input_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
52
|
+
o += 8;
|
|
53
|
+
const output_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
54
|
+
o += 8;
|
|
55
|
+
const next_sqrt_price = (0, binary_js_1.readU128LE)(data, o);
|
|
56
|
+
o += 16;
|
|
57
|
+
const lp_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
58
|
+
o += 8;
|
|
59
|
+
const protocol_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
60
|
+
o += 8;
|
|
61
|
+
const referral_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
62
|
+
o += 8;
|
|
63
|
+
o += 8;
|
|
64
|
+
const current_timestamp = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
65
|
+
const ev = {
|
|
66
|
+
metadata: meta,
|
|
67
|
+
pool,
|
|
68
|
+
amount_in,
|
|
69
|
+
output_amount,
|
|
70
|
+
trade_direction,
|
|
71
|
+
has_referral,
|
|
72
|
+
minimum_amount_out,
|
|
73
|
+
next_sqrt_price,
|
|
74
|
+
lp_fee,
|
|
75
|
+
protocol_fee,
|
|
76
|
+
partner_fee: 0n,
|
|
77
|
+
referral_fee,
|
|
78
|
+
actual_amount_in: actual_input_amount,
|
|
79
|
+
current_timestamp,
|
|
80
|
+
...emptyVaults(),
|
|
81
|
+
};
|
|
82
|
+
return { MeteoraDammV2Swap: ev };
|
|
83
|
+
}
|
|
84
|
+
function parseSwap2Event(data, meta) {
|
|
85
|
+
let o = 0;
|
|
86
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
87
|
+
o += 32;
|
|
88
|
+
const trade_direction = (0, binary_js_1.readU8)(data, o);
|
|
89
|
+
o += 1;
|
|
90
|
+
o += 1;
|
|
91
|
+
const has_referral = (0, binary_js_1.readBool)(data, o);
|
|
92
|
+
o += 1;
|
|
93
|
+
const amount_0 = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
94
|
+
o += 8;
|
|
95
|
+
const amount_1 = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
96
|
+
o += 8;
|
|
97
|
+
const swap_mode = (0, binary_js_1.readU8)(data, o);
|
|
98
|
+
o += 1;
|
|
99
|
+
const included_fee_input_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
100
|
+
o += 8;
|
|
101
|
+
o += 8;
|
|
102
|
+
o += 8;
|
|
103
|
+
const output_amount = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
104
|
+
o += 8;
|
|
105
|
+
const next_sqrt_price = (0, binary_js_1.readU128LE)(data, o);
|
|
106
|
+
o += 16;
|
|
107
|
+
const lp_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
108
|
+
o += 8;
|
|
109
|
+
const protocol_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
110
|
+
o += 8;
|
|
111
|
+
const referral_fee = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
112
|
+
o += 8;
|
|
113
|
+
o += 8;
|
|
114
|
+
o += 8;
|
|
115
|
+
const current_timestamp = bn64((0, binary_js_1.readU64LE)(data, o));
|
|
116
|
+
const [amount_in, minimum_amount_out] = swap_mode === 0 ? [amount_0, amount_1] : [amount_1, amount_0];
|
|
117
|
+
const ev = {
|
|
118
|
+
metadata: meta,
|
|
119
|
+
pool,
|
|
120
|
+
amount_in,
|
|
121
|
+
output_amount,
|
|
122
|
+
trade_direction,
|
|
123
|
+
has_referral,
|
|
124
|
+
minimum_amount_out,
|
|
125
|
+
next_sqrt_price,
|
|
126
|
+
lp_fee,
|
|
127
|
+
protocol_fee,
|
|
128
|
+
partner_fee: 0n,
|
|
129
|
+
referral_fee,
|
|
130
|
+
actual_amount_in: included_fee_input_amount,
|
|
131
|
+
current_timestamp,
|
|
132
|
+
...emptyVaults(),
|
|
133
|
+
};
|
|
134
|
+
return { MeteoraDammV2Swap: ev };
|
|
135
|
+
}
|
|
136
|
+
function parseCreatePositionEvent(data, meta) {
|
|
137
|
+
if (data.length < 32 * 4)
|
|
138
|
+
return null;
|
|
139
|
+
let o = 0;
|
|
140
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
141
|
+
if (!pool)
|
|
142
|
+
return null;
|
|
143
|
+
o += 32;
|
|
144
|
+
const owner = (0, binary_js_1.readPubkey)(data, o);
|
|
145
|
+
if (!owner)
|
|
146
|
+
return null;
|
|
147
|
+
o += 32;
|
|
148
|
+
const position = (0, binary_js_1.readPubkey)(data, o);
|
|
149
|
+
if (!position)
|
|
150
|
+
return null;
|
|
151
|
+
o += 32;
|
|
152
|
+
const position_nft_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
153
|
+
if (!position_nft_mint)
|
|
154
|
+
return null;
|
|
155
|
+
return { MeteoraDammV2CreatePosition: { metadata: meta, pool, owner, position, position_nft_mint } };
|
|
156
|
+
}
|
|
157
|
+
function parseClosePositionEvent(data, meta) {
|
|
158
|
+
if (data.length < 32 * 4)
|
|
159
|
+
return null;
|
|
160
|
+
let o = 0;
|
|
161
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
162
|
+
if (!pool)
|
|
163
|
+
return null;
|
|
164
|
+
o += 32;
|
|
165
|
+
const owner = (0, binary_js_1.readPubkey)(data, o);
|
|
166
|
+
if (!owner)
|
|
167
|
+
return null;
|
|
168
|
+
o += 32;
|
|
169
|
+
const position = (0, binary_js_1.readPubkey)(data, o);
|
|
170
|
+
if (!position)
|
|
171
|
+
return null;
|
|
172
|
+
o += 32;
|
|
173
|
+
const position_nft_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
174
|
+
if (!position_nft_mint)
|
|
175
|
+
return null;
|
|
176
|
+
return { MeteoraDammV2ClosePosition: { metadata: meta, pool, owner, position, position_nft_mint } };
|
|
177
|
+
}
|
|
178
|
+
function parseAddLiquidityEvent(data, meta) {
|
|
179
|
+
if (data.length < 32 * 3 + 16 + 8 * 6)
|
|
180
|
+
return null;
|
|
181
|
+
let o = 0;
|
|
182
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
183
|
+
if (!pool)
|
|
184
|
+
return null;
|
|
185
|
+
o += 32;
|
|
186
|
+
const position = (0, binary_js_1.readPubkey)(data, o);
|
|
187
|
+
if (!position)
|
|
188
|
+
return null;
|
|
189
|
+
o += 32;
|
|
190
|
+
const owner = (0, binary_js_1.readPubkey)(data, o);
|
|
191
|
+
if (!owner)
|
|
192
|
+
return null;
|
|
193
|
+
o += 32;
|
|
194
|
+
const liquidity_delta = (0, binary_js_1.readU128LE)(data, o);
|
|
195
|
+
if (liquidity_delta === null)
|
|
196
|
+
return null;
|
|
197
|
+
o += 16;
|
|
198
|
+
const token_a_amount_threshold = (0, binary_js_1.readU64LE)(data, o);
|
|
199
|
+
if (token_a_amount_threshold === null)
|
|
200
|
+
return null;
|
|
201
|
+
o += 8;
|
|
202
|
+
const token_b_amount_threshold = (0, binary_js_1.readU64LE)(data, o);
|
|
203
|
+
if (token_b_amount_threshold === null)
|
|
204
|
+
return null;
|
|
205
|
+
o += 8;
|
|
206
|
+
const token_a_amount = (0, binary_js_1.readU64LE)(data, o);
|
|
207
|
+
if (token_a_amount === null)
|
|
208
|
+
return null;
|
|
209
|
+
o += 8;
|
|
210
|
+
const token_b_amount = (0, binary_js_1.readU64LE)(data, o);
|
|
211
|
+
if (token_b_amount === null)
|
|
212
|
+
return null;
|
|
213
|
+
o += 8;
|
|
214
|
+
const total_amount_a = (0, binary_js_1.readU64LE)(data, o);
|
|
215
|
+
if (total_amount_a === null)
|
|
216
|
+
return null;
|
|
217
|
+
o += 8;
|
|
218
|
+
const total_amount_b = (0, binary_js_1.readU64LE)(data, o);
|
|
219
|
+
if (total_amount_b === null)
|
|
220
|
+
return null;
|
|
221
|
+
return {
|
|
222
|
+
MeteoraDammV2AddLiquidity: {
|
|
223
|
+
metadata: meta,
|
|
224
|
+
pool,
|
|
225
|
+
position,
|
|
226
|
+
owner,
|
|
227
|
+
liquidity_delta,
|
|
228
|
+
token_a_amount_threshold,
|
|
229
|
+
token_b_amount_threshold,
|
|
230
|
+
token_a_amount,
|
|
231
|
+
token_b_amount,
|
|
232
|
+
total_amount_a,
|
|
233
|
+
total_amount_b,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function parseRemoveLiquidityEvent(data, meta) {
|
|
238
|
+
if (data.length < 32 * 3 + 16 + 8 * 4)
|
|
239
|
+
return null;
|
|
240
|
+
let o = 0;
|
|
241
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
242
|
+
if (!pool)
|
|
243
|
+
return null;
|
|
244
|
+
o += 32;
|
|
245
|
+
const position = (0, binary_js_1.readPubkey)(data, o);
|
|
246
|
+
if (!position)
|
|
247
|
+
return null;
|
|
248
|
+
o += 32;
|
|
249
|
+
const owner = (0, binary_js_1.readPubkey)(data, o);
|
|
250
|
+
if (!owner)
|
|
251
|
+
return null;
|
|
252
|
+
o += 32;
|
|
253
|
+
const liquidity_delta = (0, binary_js_1.readU128LE)(data, o);
|
|
254
|
+
if (liquidity_delta === null)
|
|
255
|
+
return null;
|
|
256
|
+
o += 16;
|
|
257
|
+
const token_a_amount_threshold = (0, binary_js_1.readU64LE)(data, o);
|
|
258
|
+
if (token_a_amount_threshold === null)
|
|
259
|
+
return null;
|
|
260
|
+
o += 8;
|
|
261
|
+
const token_b_amount_threshold = (0, binary_js_1.readU64LE)(data, o);
|
|
262
|
+
if (token_b_amount_threshold === null)
|
|
263
|
+
return null;
|
|
264
|
+
o += 8;
|
|
265
|
+
const token_a_amount = (0, binary_js_1.readU64LE)(data, o);
|
|
266
|
+
if (token_a_amount === null)
|
|
267
|
+
return null;
|
|
268
|
+
o += 8;
|
|
269
|
+
const token_b_amount = (0, binary_js_1.readU64LE)(data, o);
|
|
270
|
+
if (token_b_amount === null)
|
|
271
|
+
return null;
|
|
272
|
+
return {
|
|
273
|
+
MeteoraDammV2RemoveLiquidity: {
|
|
274
|
+
metadata: meta,
|
|
275
|
+
pool,
|
|
276
|
+
position,
|
|
277
|
+
owner,
|
|
278
|
+
liquidity_delta,
|
|
279
|
+
token_a_amount_threshold,
|
|
280
|
+
token_b_amount_threshold,
|
|
281
|
+
token_a_amount,
|
|
282
|
+
token_b_amount,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function bytesToHex(u8, start, len) {
|
|
287
|
+
let out = "";
|
|
288
|
+
for (let i = 0; i < len; i++)
|
|
289
|
+
out += u8[start + i].toString(16).padStart(2, "0");
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
function parseDynamicFeeParameters(data, start) {
|
|
293
|
+
let o = start;
|
|
294
|
+
const bin_step = (0, binary_js_1.readU16LE)(data, o);
|
|
295
|
+
if (bin_step === null)
|
|
296
|
+
return null;
|
|
297
|
+
o += 2;
|
|
298
|
+
const bin_step_u128 = (0, binary_js_1.readU128LE)(data, o);
|
|
299
|
+
if (bin_step_u128 === null)
|
|
300
|
+
return null;
|
|
301
|
+
o += 16;
|
|
302
|
+
const filter_period = (0, binary_js_1.readU16LE)(data, o);
|
|
303
|
+
if (filter_period === null)
|
|
304
|
+
return null;
|
|
305
|
+
o += 2;
|
|
306
|
+
const decay_period = (0, binary_js_1.readU16LE)(data, o);
|
|
307
|
+
if (decay_period === null)
|
|
308
|
+
return null;
|
|
309
|
+
o += 2;
|
|
310
|
+
const reduction_factor = (0, binary_js_1.readU16LE)(data, o);
|
|
311
|
+
if (reduction_factor === null)
|
|
312
|
+
return null;
|
|
313
|
+
o += 2;
|
|
314
|
+
const max_volatility_accumulator = (0, binary_js_1.readU32LE)(data, o);
|
|
315
|
+
if (max_volatility_accumulator === null)
|
|
316
|
+
return null;
|
|
317
|
+
o += 4;
|
|
318
|
+
const variable_fee_control = (0, binary_js_1.readU32LE)(data, o);
|
|
319
|
+
if (variable_fee_control === null)
|
|
320
|
+
return null;
|
|
321
|
+
o += 4;
|
|
322
|
+
return {
|
|
323
|
+
v: {
|
|
324
|
+
bin_step,
|
|
325
|
+
bin_step_u128,
|
|
326
|
+
filter_period,
|
|
327
|
+
decay_period,
|
|
328
|
+
reduction_factor,
|
|
329
|
+
max_volatility_accumulator,
|
|
330
|
+
variable_fee_control,
|
|
331
|
+
},
|
|
332
|
+
next: o,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function parsePoolFeeParametersParsed(data, start) {
|
|
336
|
+
let o = start;
|
|
337
|
+
if (o + 30 > data.length)
|
|
338
|
+
return null;
|
|
339
|
+
const base_fee_data = bytesToHex(data, o, 27);
|
|
340
|
+
o += 27;
|
|
341
|
+
const compounding_fee_bps = (0, binary_js_1.readU16LE)(data, o);
|
|
342
|
+
if (compounding_fee_bps === null)
|
|
343
|
+
return null;
|
|
344
|
+
o += 2;
|
|
345
|
+
const padding = (0, binary_js_1.readU8)(data, o);
|
|
346
|
+
if (padding === null)
|
|
347
|
+
return null;
|
|
348
|
+
o += 1;
|
|
349
|
+
const tag = (0, binary_js_1.readU8)(data, o);
|
|
350
|
+
if (tag === null)
|
|
351
|
+
return null;
|
|
352
|
+
o += 1;
|
|
353
|
+
let dynamic_fee = null;
|
|
354
|
+
if (tag === 1) {
|
|
355
|
+
const inner = parseDynamicFeeParameters(data, o);
|
|
356
|
+
if (!inner)
|
|
357
|
+
return null;
|
|
358
|
+
dynamic_fee = inner.v;
|
|
359
|
+
o = inner.next;
|
|
360
|
+
}
|
|
361
|
+
else if (tag !== 0)
|
|
362
|
+
return null;
|
|
363
|
+
return {
|
|
364
|
+
v: { base_fee_data, compounding_fee_bps, padding, dynamic_fee },
|
|
365
|
+
next: o,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/** `EvtInitializePool`:6 个 pubkey 后接 `PoolFeeParameters`(变长 Option)再接固定尾部 109 字节 */
|
|
369
|
+
function parseInitializePoolEvent(data, meta) {
|
|
370
|
+
const minTail = 31 + 109;
|
|
371
|
+
if (data.length < 32 * 6 + minTail)
|
|
372
|
+
return null;
|
|
373
|
+
let o = 0;
|
|
374
|
+
const pool = (0, binary_js_1.readPubkey)(data, o);
|
|
375
|
+
if (!pool)
|
|
376
|
+
return null;
|
|
377
|
+
o += 32;
|
|
378
|
+
const token_a_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
379
|
+
if (!token_a_mint)
|
|
380
|
+
return null;
|
|
381
|
+
o += 32;
|
|
382
|
+
const token_b_mint = (0, binary_js_1.readPubkey)(data, o);
|
|
383
|
+
if (!token_b_mint)
|
|
384
|
+
return null;
|
|
385
|
+
o += 32;
|
|
386
|
+
const creator = (0, binary_js_1.readPubkey)(data, o);
|
|
387
|
+
if (!creator)
|
|
388
|
+
return null;
|
|
389
|
+
o += 32;
|
|
390
|
+
const payer = (0, binary_js_1.readPubkey)(data, o);
|
|
391
|
+
if (!payer)
|
|
392
|
+
return null;
|
|
393
|
+
o += 32;
|
|
394
|
+
const alpha_vault = (0, binary_js_1.readPubkey)(data, o);
|
|
395
|
+
if (!alpha_vault)
|
|
396
|
+
return null;
|
|
397
|
+
o += 32;
|
|
398
|
+
const pfp = parsePoolFeeParametersParsed(data, o);
|
|
399
|
+
if (!pfp)
|
|
400
|
+
return null;
|
|
401
|
+
o = pfp.next;
|
|
402
|
+
if (o + 109 > data.length)
|
|
403
|
+
return null;
|
|
404
|
+
const sqrt_min_price = (0, binary_js_1.readU128LE)(data, o);
|
|
405
|
+
if (sqrt_min_price === null)
|
|
406
|
+
return null;
|
|
407
|
+
o += 16;
|
|
408
|
+
const sqrt_max_price = (0, binary_js_1.readU128LE)(data, o);
|
|
409
|
+
if (sqrt_max_price === null)
|
|
410
|
+
return null;
|
|
411
|
+
o += 16;
|
|
412
|
+
const activation_type = (0, binary_js_1.readU8)(data, o);
|
|
413
|
+
if (activation_type === null)
|
|
414
|
+
return null;
|
|
415
|
+
o += 1;
|
|
416
|
+
const collect_fee_mode = (0, binary_js_1.readU8)(data, o);
|
|
417
|
+
if (collect_fee_mode === null)
|
|
418
|
+
return null;
|
|
419
|
+
o += 1;
|
|
420
|
+
const liquidity = (0, binary_js_1.readU128LE)(data, o);
|
|
421
|
+
if (liquidity === null)
|
|
422
|
+
return null;
|
|
423
|
+
o += 16;
|
|
424
|
+
const sqrt_price = (0, binary_js_1.readU128LE)(data, o);
|
|
425
|
+
if (sqrt_price === null)
|
|
426
|
+
return null;
|
|
427
|
+
o += 16;
|
|
428
|
+
const activation_point = (0, binary_js_1.readU64LE)(data, o);
|
|
429
|
+
if (activation_point === null)
|
|
430
|
+
return null;
|
|
431
|
+
o += 8;
|
|
432
|
+
const token_a_flag = (0, binary_js_1.readU8)(data, o);
|
|
433
|
+
if (token_a_flag === null)
|
|
434
|
+
return null;
|
|
435
|
+
o += 1;
|
|
436
|
+
const token_b_flag = (0, binary_js_1.readU8)(data, o);
|
|
437
|
+
if (token_b_flag === null)
|
|
438
|
+
return null;
|
|
439
|
+
o += 1;
|
|
440
|
+
const token_a_amount = (0, binary_js_1.readU64LE)(data, o);
|
|
441
|
+
if (token_a_amount === null)
|
|
442
|
+
return null;
|
|
443
|
+
o += 8;
|
|
444
|
+
const token_b_amount = (0, binary_js_1.readU64LE)(data, o);
|
|
445
|
+
if (token_b_amount === null)
|
|
446
|
+
return null;
|
|
447
|
+
o += 8;
|
|
448
|
+
const total_amount_a = (0, binary_js_1.readU64LE)(data, o);
|
|
449
|
+
if (total_amount_a === null)
|
|
450
|
+
return null;
|
|
451
|
+
o += 8;
|
|
452
|
+
const total_amount_b = (0, binary_js_1.readU64LE)(data, o);
|
|
453
|
+
if (total_amount_b === null)
|
|
454
|
+
return null;
|
|
455
|
+
o += 8;
|
|
456
|
+
const pool_type = (0, binary_js_1.readU8)(data, o);
|
|
457
|
+
if (pool_type === null)
|
|
458
|
+
return null;
|
|
459
|
+
return {
|
|
460
|
+
MeteoraDammV2InitializePool: {
|
|
461
|
+
metadata: meta,
|
|
462
|
+
pool,
|
|
463
|
+
token_a_mint,
|
|
464
|
+
token_b_mint,
|
|
465
|
+
creator,
|
|
466
|
+
payer,
|
|
467
|
+
alpha_vault,
|
|
468
|
+
pool_fees: pfp.v,
|
|
469
|
+
sqrt_min_price,
|
|
470
|
+
sqrt_max_price,
|
|
471
|
+
activation_type,
|
|
472
|
+
collect_fee_mode,
|
|
473
|
+
liquidity,
|
|
474
|
+
sqrt_price,
|
|
475
|
+
activation_point,
|
|
476
|
+
token_a_flag,
|
|
477
|
+
token_b_flag,
|
|
478
|
+
token_a_amount,
|
|
479
|
+
token_b_amount,
|
|
480
|
+
total_amount_a,
|
|
481
|
+
total_amount_b,
|
|
482
|
+
pool_type,
|
|
483
|
+
},
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** Meteora DAMM Program data 入口;布局与 `parseMeteoraDammInstruction` CPI 内层载荷一致(Swap/Swap2 另含日志侧 32 字节填充,见 parseSwapEvent) */
|
|
487
|
+
function parseMeteoraDammLog(log, signature, slot, txIndex, blockTimeUs, grpcRecvUs) {
|
|
488
|
+
const programData = (0, program_data_js_1.decodeProgramDataLine)(log);
|
|
489
|
+
if (!programData)
|
|
490
|
+
return null;
|
|
491
|
+
const disc = new DataView(programData.buffer, programData.byteOffset, 8).getBigUint64(0, true);
|
|
492
|
+
const data = programData.subarray(8);
|
|
493
|
+
const meta = (0, metadata_js_1.makeMetadata)(signature, slot, txIndex, blockTimeUs, grpcRecvUs);
|
|
494
|
+
if (disc === SWAP)
|
|
495
|
+
return parseSwapEvent(data, meta);
|
|
496
|
+
if (disc === SWAP2)
|
|
497
|
+
return parseSwap2Event(data, meta);
|
|
498
|
+
if (disc === CREATE_POSITION)
|
|
499
|
+
return parseCreatePositionEvent(data, meta);
|
|
500
|
+
if (disc === CLOSE_POSITION)
|
|
501
|
+
return parseClosePositionEvent(data, meta);
|
|
502
|
+
if (disc === ADD_LIQUIDITY)
|
|
503
|
+
return parseAddLiquidityEvent(data, meta);
|
|
504
|
+
if (disc === REMOVE_LIQUIDITY)
|
|
505
|
+
return parseRemoveLiquidityEvent(data, meta);
|
|
506
|
+
if (disc === INITIALIZE_POOL)
|
|
507
|
+
return parseInitializePoolEvent(data, meta);
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Meteora DLMM 结构化日志解析 */
|
|
2
|
+
import { type EventMetadata } from "../core/metadata.js";
|
|
3
|
+
import type { DexEvent } from "../core/dex_event.js";
|
|
4
|
+
export declare function parseDlmmFromDecoded(programData: Uint8Array, metadata: EventMetadata): DexEvent | null;
|
|
5
|
+
/** 从整行日志解析 */
|
|
6
|
+
export declare function parseMeteoraDlmmLog(log: string, signature: string, slot: number, txIndex: number, blockTimeUs: number | undefined, grpcRecvUs: number): DexEvent | null;
|