sol-parser-sdk 0.5.9
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/LICENSE +21 -0
- package/README.md +236 -0
- package/README_CN.md +236 -0
- package/dist/accounts/mod.d.ts +15 -0
- package/dist/accounts/mod.js +173 -0
- package/dist/accounts/nonce.d.ts +5 -0
- package/dist/accounts/nonce.js +32 -0
- package/dist/accounts/pumpfun.d.ts +16 -0
- package/dist/accounts/pumpfun.js +538 -0
- package/dist/accounts/pumpswap.d.ts +8 -0
- package/dist/accounts/pumpswap.js +192 -0
- package/dist/accounts/raydium_orca.d.ts +26 -0
- package/dist/accounts/raydium_orca.js +453 -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/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/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.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 +15 -0
- package/dist/core/account_fill_meteora.js +27 -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 +167 -0
- package/dist/core/account_fill_pumpswap.d.ts +10 -0
- package/dist/core/account_fill_pumpswap.js +128 -0
- package/dist/core/account_fill_raydium.d.ts +20 -0
- package/dist/core/account_fill_raydium.js +104 -0
- package/dist/core/account_fill_raydium_launchlab.d.ts +4 -0
- package/dist/core/account_fill_raydium_launchlab.js +20 -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 +8 -0
- package/dist/core/clock.js +20 -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 +1704 -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 +11 -0
- package/dist/core/metadata.js +13 -0
- package/dist/core/pumpfun_fee_enrich.d.ts +6 -0
- package/dist/core/pumpfun_fee_enrich.js +159 -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 +50 -0
- package/dist/grpc/client.d.ts +83 -0
- package/dist/grpc/client.js +645 -0
- package/dist/grpc/client_stub.d.ts +5 -0
- package/dist/grpc/client_stub.js +5 -0
- 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 +402 -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 +27 -0
- package/dist/grpc/program_ids.js +61 -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 +195 -0
- package/dist/grpc/types.js +551 -0
- package/dist/grpc/yellowstone_parse.d.ts +16 -0
- package/dist/grpc/yellowstone_parse.js +62 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +298 -0
- package/dist/instr/bonk_ix.d.ts +8 -0
- package/dist/instr/bonk_ix.js +131 -0
- package/dist/instr/inner.d.ts +4 -0
- package/dist/instr/inner.js +453 -0
- package/dist/instr/meteora_damm_ix.d.ts +8 -0
- package/dist/instr/meteora_damm_ix.js +601 -0
- package/dist/instr/meteora_dlmm_ix.d.ts +2 -0
- package/dist/instr/meteora_dlmm_ix.js +134 -0
- package/dist/instr/meteora_pools_ix.d.ts +2 -0
- package/dist/instr/meteora_pools_ix.js +78 -0
- package/dist/instr/mod.d.ts +18 -0
- package/dist/instr/mod.js +129 -0
- package/dist/instr/orca_whirlpool_ix.d.ts +8 -0
- package/dist/instr/orca_whirlpool_ix.js +119 -0
- package/dist/instr/program_ids.d.ts +4 -0
- package/dist/instr/program_ids.js +20 -0
- package/dist/instr/pump_fees_ix.d.ts +2 -0
- package/dist/instr/pump_fees_ix.js +168 -0
- package/dist/instr/pumpfun_ix.d.ts +6 -0
- package/dist/instr/pumpfun_ix.js +448 -0
- package/dist/instr/pumpswap_ix.d.ts +5 -0
- package/dist/instr/pumpswap_ix.js +270 -0
- package/dist/instr/raydium_amm_v4_ix.d.ts +6 -0
- package/dist/instr/raydium_amm_v4_ix.js +112 -0
- package/dist/instr/raydium_clmm_ix.d.ts +5 -0
- package/dist/instr/raydium_clmm_ix.js +184 -0
- package/dist/instr/raydium_cpmm_ix.d.ts +5 -0
- package/dist/instr/raydium_cpmm_ix.js +109 -0
- package/dist/instr/raydium_launchlab_ix.d.ts +8 -0
- package/dist/instr/raydium_launchlab_ix.js +125 -0
- package/dist/instr/rust_aliases.d.ts +10 -0
- package/dist/instr/rust_aliases.js +20 -0
- package/dist/instr/utils.d.ts +10 -0
- package/dist/instr/utils.js +35 -0
- package/dist/logs/discriminator_lut.d.ts +19 -0
- package/dist/logs/discriminator_lut.js +62 -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 +5 -0
- package/dist/logs/meteora_damm.js +367 -0
- package/dist/logs/meteora_dbc.d.ts +11 -0
- package/dist/logs/meteora_dbc.js +142 -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 +11 -0
- package/dist/logs/optimized_matcher.js +941 -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 +20 -0
- package/dist/logs/program_log_discriminators.d.ts +80 -0
- package/dist/logs/program_log_discriminators.js +88 -0
- package/dist/logs/pump.d.ts +14 -0
- package/dist/logs/pump.js +378 -0
- package/dist/logs/pump_amm.d.ts +9 -0
- package/dist/logs/pump_amm.js +418 -0
- package/dist/logs/pump_fees.d.ts +23 -0
- package/dist/logs/pump_fees.js +364 -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 +17 -0
- package/dist/logs/raydium_clmm.js +624 -0
- package/dist/logs/raydium_cpmm.d.ts +7 -0
- package/dist/logs/raydium_cpmm.js +121 -0
- package/dist/logs/raydium_launchlab.d.ts +10 -0
- package/dist/logs/raydium_launchlab.js +84 -0
- package/dist/logs/raydium_launchpad.d.ts +12 -0
- package/dist/logs/raydium_launchpad.js +92 -0
- package/dist/logs/rust_aliases.d.ts +7 -0
- package/dist/logs/rust_aliases.js +16 -0
- package/dist/parser_alias.d.ts +3 -0
- package/dist/parser_alias.js +2 -0
- package/dist/rpc_parser.d.ts +17 -0
- package/dist/rpc_parser.js +39 -0
- package/dist/rpc_transaction.d.ts +27 -0
- package/dist/rpc_transaction.js +416 -0
- package/dist/shredstream/alt_lookup.d.ts +9 -0
- package/dist/shredstream/alt_lookup.js +70 -0
- package/dist/shredstream/client.d.ts +65 -0
- package/dist/shredstream/client.js +403 -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 +79 -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/dist/util/binary.d.ts +14 -0
- package/dist/util/binary.js +82 -0
- package/dist/util/market.d.ts +18 -0
- package/dist/util/market.js +54 -0
- package/dist/warmup.d.ts +3 -0
- package/dist/warmup.js +23 -0
- package/package.json +61 -0
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMeteoraDammInstruction = parseMeteoraDammInstruction;
|
|
4
|
+
const dex_event_js_1 = require("../core/dex_event.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const Z = (0, dex_event_js_1.defaultPubkey)();
|
|
7
|
+
function disc8(a) {
|
|
8
|
+
return Uint8Array.from(a);
|
|
9
|
+
}
|
|
10
|
+
const CPI = {
|
|
11
|
+
SWAP_LOG: disc8([27, 60, 21, 213, 138, 170, 187, 147]),
|
|
12
|
+
SWAP2_LOG: disc8([189, 66, 51, 168, 38, 80, 117, 153]),
|
|
13
|
+
CREATE_POSITION_LOG: disc8([156, 15, 119, 198, 29, 181, 221, 55]),
|
|
14
|
+
CLOSE_POSITION_LOG: disc8([20, 145, 144, 68, 143, 142, 214, 178]),
|
|
15
|
+
ADD_LIQUIDITY_LOG: disc8([175, 242, 8, 157, 30, 247, 185, 169]),
|
|
16
|
+
REMOVE_LIQUIDITY_LOG: disc8([87, 46, 88, 98, 175, 96, 34, 91]),
|
|
17
|
+
};
|
|
18
|
+
/** 与 cp_amm Anchor IDL `instructions[].discriminator` 一致(用户直接调用的外层指令) */
|
|
19
|
+
const ANCHOR = {
|
|
20
|
+
SWAP: disc8([248, 198, 158, 145, 225, 117, 135, 200]),
|
|
21
|
+
/** `swap2` — `SwapParameters2`(amount_0, amount_1, swap_mode) */
|
|
22
|
+
SWAP2: disc8([65, 75, 63, 76, 235, 91, 91, 136]),
|
|
23
|
+
ADD_LIQUIDITY: disc8([181, 157, 89, 67, 143, 182, 52, 72]),
|
|
24
|
+
REMOVE_LIQUIDITY: disc8([80, 85, 209, 72, 24, 206, 177, 108]),
|
|
25
|
+
REMOVE_ALL_LIQUIDITY: disc8([10, 51, 61, 35, 112, 105, 24, 85]),
|
|
26
|
+
INITIALIZE_POOL: disc8([95, 180, 10, 172, 84, 174, 232, 40]),
|
|
27
|
+
/** `create_position` / `close_position` 无额外 Borsh 参数,仅 8 字节 disc */
|
|
28
|
+
CREATE_POSITION: disc8([48, 215, 197, 153, 96, 203, 180, 133]),
|
|
29
|
+
CLOSE_POSITION: disc8([123, 134, 81, 0, 49, 68, 98, 98]),
|
|
30
|
+
};
|
|
31
|
+
function headEq(data, disc) {
|
|
32
|
+
if (data.length < 8)
|
|
33
|
+
return false;
|
|
34
|
+
for (let i = 0; i < 8; i++)
|
|
35
|
+
if (data[i] !== disc[i])
|
|
36
|
+
return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function discEq(h, d) {
|
|
40
|
+
for (let i = 0; i < 8; i++)
|
|
41
|
+
if (h[i] !== d[i])
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
function vaults() {
|
|
46
|
+
return {
|
|
47
|
+
token_a_vault: Z,
|
|
48
|
+
token_b_vault: Z,
|
|
49
|
+
token_a_mint: Z,
|
|
50
|
+
token_b_mint: Z,
|
|
51
|
+
token_a_program: Z,
|
|
52
|
+
token_b_program: Z,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* cp_amm 外层 `swap` / `swap2` 账户顺序(见 `idls/meteora_damm_v2.json`):
|
|
57
|
+
* 0 pool_authority, 1 pool, 2 input_token_account, 3 output_token_account,
|
|
58
|
+
* 4 token_a_vault, 5 token_b_vault, 6–7 mints, 8 payer, 9–10 token programs;
|
|
59
|
+
* 11 起为可选 referral、event_authority、program 等。
|
|
60
|
+
*/
|
|
61
|
+
function meteoraSwapVaultsFromAccounts(accounts) {
|
|
62
|
+
if (accounts.length < 11) {
|
|
63
|
+
return vaults();
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
token_a_vault: (0, utils_js_1.getAccount)(accounts, 4) ?? Z,
|
|
67
|
+
token_b_vault: (0, utils_js_1.getAccount)(accounts, 5) ?? Z,
|
|
68
|
+
token_a_mint: (0, utils_js_1.getAccount)(accounts, 6) ?? Z,
|
|
69
|
+
token_b_mint: (0, utils_js_1.getAccount)(accounts, 7) ?? Z,
|
|
70
|
+
token_a_program: (0, utils_js_1.getAccount)(accounts, 9) ?? Z,
|
|
71
|
+
token_b_program: (0, utils_js_1.getAccount)(accounts, 10) ?? Z,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 外层 `swap`:`SwapParameters` = amount_in (u64) + minimum_amount_out (u64)。
|
|
76
|
+
* 成交额、手续费、`next_sqrt_price` 等仅在程序 `emit!`(日志 / 内联 CPI 载荷)中;**仅解析外层指令时这些字段保持 0**(与无日志的 ShredStream 一致)。
|
|
77
|
+
*/
|
|
78
|
+
function parseOuterSwapIx(instructionData, accounts, meta) {
|
|
79
|
+
const amount_in = (0, utils_js_1.readU64LE)(instructionData, 8) ?? 0n;
|
|
80
|
+
const minimum_amount_out = (0, utils_js_1.readU64LE)(instructionData, 16) ?? 0n;
|
|
81
|
+
const pool = (0, utils_js_1.getAccount)(accounts, 1) ?? Z;
|
|
82
|
+
const ev = {
|
|
83
|
+
metadata: meta,
|
|
84
|
+
pool,
|
|
85
|
+
trade_direction: 0,
|
|
86
|
+
has_referral: false,
|
|
87
|
+
amount_in,
|
|
88
|
+
minimum_amount_out,
|
|
89
|
+
output_amount: 0n,
|
|
90
|
+
next_sqrt_price: 0n,
|
|
91
|
+
lp_fee: 0n,
|
|
92
|
+
protocol_fee: 0n,
|
|
93
|
+
partner_fee: 0n,
|
|
94
|
+
referral_fee: 0n,
|
|
95
|
+
actual_amount_in: amount_in,
|
|
96
|
+
current_timestamp: 0n,
|
|
97
|
+
...meteoraSwapVaultsFromAccounts(accounts),
|
|
98
|
+
};
|
|
99
|
+
return { MeteoraDammV2Swap: ev };
|
|
100
|
+
}
|
|
101
|
+
/** 外层 `swap2`:`SwapParameters2` = amount_0 + amount_1 + swap_mode (u8) */
|
|
102
|
+
function parseOuterSwap2Ix(instructionData, accounts, meta) {
|
|
103
|
+
if (instructionData.length < 25)
|
|
104
|
+
return null;
|
|
105
|
+
const amount_0 = (0, utils_js_1.readU64LE)(instructionData, 8) ?? 0n;
|
|
106
|
+
const amount_1 = (0, utils_js_1.readU64LE)(instructionData, 16) ?? 0n;
|
|
107
|
+
const swap_mode = (0, utils_js_1.readU8)(instructionData, 24);
|
|
108
|
+
if (swap_mode === null)
|
|
109
|
+
return null;
|
|
110
|
+
const [amount_in, minimum_amount_out] = swap_mode === 0 ? [amount_0, amount_1] : [amount_1, amount_0];
|
|
111
|
+
const pool = (0, utils_js_1.getAccount)(accounts, 1) ?? Z;
|
|
112
|
+
const ev = {
|
|
113
|
+
metadata: meta,
|
|
114
|
+
pool,
|
|
115
|
+
trade_direction: 0,
|
|
116
|
+
has_referral: false,
|
|
117
|
+
amount_in,
|
|
118
|
+
minimum_amount_out,
|
|
119
|
+
output_amount: 0n,
|
|
120
|
+
next_sqrt_price: 0n,
|
|
121
|
+
lp_fee: 0n,
|
|
122
|
+
protocol_fee: 0n,
|
|
123
|
+
partner_fee: 0n,
|
|
124
|
+
referral_fee: 0n,
|
|
125
|
+
actual_amount_in: amount_in,
|
|
126
|
+
current_timestamp: 0n,
|
|
127
|
+
...meteoraSwapVaultsFromAccounts(accounts),
|
|
128
|
+
};
|
|
129
|
+
return { MeteoraDammV2Swap: ev };
|
|
130
|
+
}
|
|
131
|
+
/** 外层 `add_liquidity`:`AddLiquidityParameters` = u128 + u64 + u64;pool(0), position(1), owner(9) */
|
|
132
|
+
function parseOuterAddLiquidityIx(instructionData, accounts, meta) {
|
|
133
|
+
const liquidity_delta = (0, utils_js_1.readU128LE)(instructionData, 8) ?? 0n;
|
|
134
|
+
const token_a_amount_threshold = (0, utils_js_1.readU64LE)(instructionData, 24) ?? 0n;
|
|
135
|
+
const token_b_amount_threshold = (0, utils_js_1.readU64LE)(instructionData, 32) ?? 0n;
|
|
136
|
+
return {
|
|
137
|
+
MeteoraDammV2AddLiquidity: {
|
|
138
|
+
metadata: meta,
|
|
139
|
+
pool: (0, utils_js_1.getAccount)(accounts, 0) ?? Z,
|
|
140
|
+
position: (0, utils_js_1.getAccount)(accounts, 1) ?? Z,
|
|
141
|
+
owner: (0, utils_js_1.getAccount)(accounts, 9) ?? Z,
|
|
142
|
+
liquidity_delta,
|
|
143
|
+
token_a_amount_threshold,
|
|
144
|
+
token_b_amount_threshold,
|
|
145
|
+
token_a_amount: 0n,
|
|
146
|
+
token_b_amount: 0n,
|
|
147
|
+
total_amount_a: 0n,
|
|
148
|
+
total_amount_b: 0n,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** 外层 `remove_all_liquidity`:两 u64 阈值;账户顺序同 `remove_liquidity` */
|
|
153
|
+
function parseOuterRemoveAllLiquidityIx(instructionData, accounts, meta) {
|
|
154
|
+
const token_a_amount_threshold = (0, utils_js_1.readU64LE)(instructionData, 8) ?? 0n;
|
|
155
|
+
const token_b_amount_threshold = (0, utils_js_1.readU64LE)(instructionData, 16) ?? 0n;
|
|
156
|
+
return {
|
|
157
|
+
MeteoraDammV2RemoveLiquidity: {
|
|
158
|
+
metadata: meta,
|
|
159
|
+
pool: (0, utils_js_1.getAccount)(accounts, 1) ?? Z,
|
|
160
|
+
position: (0, utils_js_1.getAccount)(accounts, 2) ?? Z,
|
|
161
|
+
owner: (0, utils_js_1.getAccount)(accounts, 10) ?? Z,
|
|
162
|
+
token_a_amount: 0n,
|
|
163
|
+
token_b_amount: 0n,
|
|
164
|
+
liquidity_delta: 0n,
|
|
165
|
+
token_a_amount_threshold,
|
|
166
|
+
token_b_amount_threshold,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** 外层 `initialize_pool`:`InitializePoolParameters` = u128 + u128 + Option(u64);creator(0), pool(6), position(7), mints(8,9) */
|
|
171
|
+
function parseOuterInitializePoolIx(instructionData, accounts, meta) {
|
|
172
|
+
if (instructionData.length < 41)
|
|
173
|
+
return null;
|
|
174
|
+
const liquidity = (0, utils_js_1.readU128LE)(instructionData, 8) ?? 0n;
|
|
175
|
+
const sqrt_price = (0, utils_js_1.readU128LE)(instructionData, 24) ?? 0n;
|
|
176
|
+
const tag = (0, utils_js_1.readU8)(instructionData, 40);
|
|
177
|
+
if (tag === null)
|
|
178
|
+
return null;
|
|
179
|
+
let activation_point = 0n;
|
|
180
|
+
if (tag === 1) {
|
|
181
|
+
if (instructionData.length < 49)
|
|
182
|
+
return null;
|
|
183
|
+
activation_point = (0, utils_js_1.readU64LE)(instructionData, 41) ?? 0n;
|
|
184
|
+
}
|
|
185
|
+
else if (tag !== 0)
|
|
186
|
+
return null;
|
|
187
|
+
if (accounts.length < 10)
|
|
188
|
+
return null;
|
|
189
|
+
return {
|
|
190
|
+
MeteoraDammV2InitializePool: {
|
|
191
|
+
metadata: meta,
|
|
192
|
+
creator: (0, utils_js_1.getAccount)(accounts, 0) ?? Z,
|
|
193
|
+
position_nft_mint: (0, utils_js_1.getAccount)(accounts, 1) ?? Z,
|
|
194
|
+
pool: (0, utils_js_1.getAccount)(accounts, 6) ?? Z,
|
|
195
|
+
position: (0, utils_js_1.getAccount)(accounts, 7) ?? Z,
|
|
196
|
+
token_a_mint: (0, utils_js_1.getAccount)(accounts, 8) ?? Z,
|
|
197
|
+
token_b_mint: (0, utils_js_1.getAccount)(accounts, 9) ?? Z,
|
|
198
|
+
payer: Z,
|
|
199
|
+
alpha_vault: Z,
|
|
200
|
+
pool_fees: null,
|
|
201
|
+
sqrt_min_price: 0n,
|
|
202
|
+
sqrt_max_price: 0n,
|
|
203
|
+
activation_type: 0,
|
|
204
|
+
collect_fee_mode: 0,
|
|
205
|
+
liquidity,
|
|
206
|
+
sqrt_price,
|
|
207
|
+
activation_point,
|
|
208
|
+
token_a_flag: 0,
|
|
209
|
+
token_b_flag: 0,
|
|
210
|
+
token_a_amount: 0n,
|
|
211
|
+
token_b_amount: 0n,
|
|
212
|
+
total_amount_a: 0n,
|
|
213
|
+
total_amount_b: 0n,
|
|
214
|
+
pool_type: 0,
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/** 外层 `remove_liquidity`:同上 Borsh;pool_authority(0), pool(1), position(2), owner(10) */
|
|
219
|
+
function parseOuterRemoveLiquidityIx(instructionData, accounts, meta) {
|
|
220
|
+
const liquidity_delta = (0, utils_js_1.readU128LE)(instructionData, 8) ?? 0n;
|
|
221
|
+
const token_a_amount_threshold = (0, utils_js_1.readU64LE)(instructionData, 24) ?? 0n;
|
|
222
|
+
const token_b_amount_threshold = (0, utils_js_1.readU64LE)(instructionData, 32) ?? 0n;
|
|
223
|
+
return {
|
|
224
|
+
MeteoraDammV2RemoveLiquidity: {
|
|
225
|
+
metadata: meta,
|
|
226
|
+
pool: (0, utils_js_1.getAccount)(accounts, 1) ?? Z,
|
|
227
|
+
position: (0, utils_js_1.getAccount)(accounts, 2) ?? Z,
|
|
228
|
+
owner: (0, utils_js_1.getAccount)(accounts, 10) ?? Z,
|
|
229
|
+
liquidity_delta,
|
|
230
|
+
token_a_amount_threshold,
|
|
231
|
+
token_b_amount_threshold,
|
|
232
|
+
token_a_amount: 0n,
|
|
233
|
+
token_b_amount: 0n,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/** 外层 `create_position`:无 args;owner(0), position_nft_mint(1), position_nft_account(2), pool(3), position(4) */
|
|
238
|
+
function parseOuterCreatePositionIx(accounts, meta) {
|
|
239
|
+
if (accounts.length < 5)
|
|
240
|
+
return null;
|
|
241
|
+
return {
|
|
242
|
+
MeteoraDammV2CreatePosition: {
|
|
243
|
+
metadata: meta,
|
|
244
|
+
owner: (0, utils_js_1.getAccount)(accounts, 0) ?? Z,
|
|
245
|
+
position_nft_mint: (0, utils_js_1.getAccount)(accounts, 1) ?? Z,
|
|
246
|
+
pool: (0, utils_js_1.getAccount)(accounts, 3) ?? Z,
|
|
247
|
+
position: (0, utils_js_1.getAccount)(accounts, 4) ?? Z,
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** 外层 `close_position`:无 args;position_nft_mint(0), …, pool(2), position(3), …, owner(6) */
|
|
252
|
+
function parseOuterClosePositionIx(accounts, meta) {
|
|
253
|
+
if (accounts.length < 7)
|
|
254
|
+
return null;
|
|
255
|
+
return {
|
|
256
|
+
MeteoraDammV2ClosePosition: {
|
|
257
|
+
metadata: meta,
|
|
258
|
+
position_nft_mint: (0, utils_js_1.getAccount)(accounts, 0) ?? Z,
|
|
259
|
+
pool: (0, utils_js_1.getAccount)(accounts, 2) ?? Z,
|
|
260
|
+
position: (0, utils_js_1.getAccount)(accounts, 3) ?? Z,
|
|
261
|
+
owner: (0, utils_js_1.getAccount)(accounts, 6) ?? Z,
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function parseSwapCpi(data, accounts, meta) {
|
|
266
|
+
let o = 0;
|
|
267
|
+
const pool = (0, utils_js_1.readPubkeyIx)(data, o);
|
|
268
|
+
if (!pool)
|
|
269
|
+
return null;
|
|
270
|
+
o += 32;
|
|
271
|
+
const trade_direction = (0, utils_js_1.readU8)(data, o);
|
|
272
|
+
if (trade_direction === null)
|
|
273
|
+
return null;
|
|
274
|
+
o += 1;
|
|
275
|
+
const has_referral = (0, utils_js_1.readBool)(data, o);
|
|
276
|
+
if (has_referral === null)
|
|
277
|
+
return null;
|
|
278
|
+
o += 1;
|
|
279
|
+
const amount_in = (0, utils_js_1.readU64LE)(data, o);
|
|
280
|
+
if (amount_in === null)
|
|
281
|
+
return null;
|
|
282
|
+
o += 8;
|
|
283
|
+
const min_out = (0, utils_js_1.readU64LE)(data, o);
|
|
284
|
+
if (min_out === null)
|
|
285
|
+
return null;
|
|
286
|
+
o += 8;
|
|
287
|
+
const output_amount = (0, utils_js_1.readU64LE)(data, o);
|
|
288
|
+
if (output_amount === null)
|
|
289
|
+
return null;
|
|
290
|
+
o += 8;
|
|
291
|
+
const next_sqrt_price = (0, utils_js_1.readU128LE)(data, o);
|
|
292
|
+
if (next_sqrt_price === null)
|
|
293
|
+
return null;
|
|
294
|
+
o += 16;
|
|
295
|
+
const lp_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
296
|
+
if (lp_fee === null)
|
|
297
|
+
return null;
|
|
298
|
+
o += 8;
|
|
299
|
+
const protocol_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
300
|
+
if (protocol_fee === null)
|
|
301
|
+
return null;
|
|
302
|
+
o += 8;
|
|
303
|
+
const partner_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
304
|
+
if (partner_fee === null)
|
|
305
|
+
return null;
|
|
306
|
+
o += 8;
|
|
307
|
+
const referral_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
308
|
+
if (referral_fee === null)
|
|
309
|
+
return null;
|
|
310
|
+
o += 8;
|
|
311
|
+
const actual_amount_in = (0, utils_js_1.readU64LE)(data, o);
|
|
312
|
+
if (actual_amount_in === null)
|
|
313
|
+
return null;
|
|
314
|
+
o += 8;
|
|
315
|
+
const current_timestamp = (0, utils_js_1.readU64LE)(data, o);
|
|
316
|
+
if (current_timestamp === null)
|
|
317
|
+
return null;
|
|
318
|
+
const ev = {
|
|
319
|
+
metadata: meta,
|
|
320
|
+
pool,
|
|
321
|
+
trade_direction,
|
|
322
|
+
has_referral,
|
|
323
|
+
amount_in,
|
|
324
|
+
minimum_amount_out: min_out,
|
|
325
|
+
output_amount,
|
|
326
|
+
next_sqrt_price,
|
|
327
|
+
lp_fee,
|
|
328
|
+
protocol_fee,
|
|
329
|
+
partner_fee,
|
|
330
|
+
referral_fee,
|
|
331
|
+
actual_amount_in,
|
|
332
|
+
current_timestamp,
|
|
333
|
+
...meteoraSwapVaultsFromAccounts(accounts),
|
|
334
|
+
};
|
|
335
|
+
return { MeteoraDammV2Swap: ev };
|
|
336
|
+
}
|
|
337
|
+
function parseSwap2Cpi(data, accounts, meta) {
|
|
338
|
+
let o = 0;
|
|
339
|
+
const pool = (0, utils_js_1.readPubkeyIx)(data, o);
|
|
340
|
+
if (!pool)
|
|
341
|
+
return null;
|
|
342
|
+
o += 32;
|
|
343
|
+
const trade_direction = (0, utils_js_1.readU8)(data, o);
|
|
344
|
+
if (trade_direction === null)
|
|
345
|
+
return null;
|
|
346
|
+
o += 1;
|
|
347
|
+
const _cfm = (0, utils_js_1.readU8)(data, o);
|
|
348
|
+
if (_cfm === null)
|
|
349
|
+
return null;
|
|
350
|
+
o += 1;
|
|
351
|
+
const has_referral = (0, utils_js_1.readBool)(data, o);
|
|
352
|
+
if (has_referral === null)
|
|
353
|
+
return null;
|
|
354
|
+
o += 1;
|
|
355
|
+
const amount_0 = (0, utils_js_1.readU64LE)(data, o);
|
|
356
|
+
if (amount_0 === null)
|
|
357
|
+
return null;
|
|
358
|
+
o += 8;
|
|
359
|
+
const amount_1 = (0, utils_js_1.readU64LE)(data, o);
|
|
360
|
+
if (amount_1 === null)
|
|
361
|
+
return null;
|
|
362
|
+
o += 8;
|
|
363
|
+
const swap_mode = (0, utils_js_1.readU8)(data, o);
|
|
364
|
+
if (swap_mode === null)
|
|
365
|
+
return null;
|
|
366
|
+
o += 1;
|
|
367
|
+
const included_fee_input_amount = (0, utils_js_1.readU64LE)(data, o);
|
|
368
|
+
if (included_fee_input_amount === null)
|
|
369
|
+
return null;
|
|
370
|
+
o += 8;
|
|
371
|
+
o += 8;
|
|
372
|
+
o += 8;
|
|
373
|
+
const output_amount = (0, utils_js_1.readU64LE)(data, o);
|
|
374
|
+
if (output_amount === null)
|
|
375
|
+
return null;
|
|
376
|
+
o += 8;
|
|
377
|
+
const next_sqrt_price = (0, utils_js_1.readU128LE)(data, o);
|
|
378
|
+
if (next_sqrt_price === null)
|
|
379
|
+
return null;
|
|
380
|
+
o += 16;
|
|
381
|
+
const lp_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
382
|
+
if (lp_fee === null)
|
|
383
|
+
return null;
|
|
384
|
+
o += 8;
|
|
385
|
+
const protocol_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
386
|
+
if (protocol_fee === null)
|
|
387
|
+
return null;
|
|
388
|
+
o += 8;
|
|
389
|
+
const referral_fee = (0, utils_js_1.readU64LE)(data, o);
|
|
390
|
+
if (referral_fee === null)
|
|
391
|
+
return null;
|
|
392
|
+
o += 8;
|
|
393
|
+
o += 8;
|
|
394
|
+
o += 8;
|
|
395
|
+
const current_timestamp = (0, utils_js_1.readU64LE)(data, o);
|
|
396
|
+
if (current_timestamp === null)
|
|
397
|
+
return null;
|
|
398
|
+
const [amount_in, minimum_amount_out] = swap_mode === 0 ? [amount_0, amount_1] : [amount_1, amount_0];
|
|
399
|
+
const ev = {
|
|
400
|
+
metadata: meta,
|
|
401
|
+
pool,
|
|
402
|
+
trade_direction,
|
|
403
|
+
has_referral,
|
|
404
|
+
amount_in,
|
|
405
|
+
minimum_amount_out,
|
|
406
|
+
output_amount,
|
|
407
|
+
next_sqrt_price,
|
|
408
|
+
lp_fee,
|
|
409
|
+
protocol_fee,
|
|
410
|
+
partner_fee: 0n,
|
|
411
|
+
referral_fee,
|
|
412
|
+
actual_amount_in: included_fee_input_amount,
|
|
413
|
+
current_timestamp,
|
|
414
|
+
...meteoraSwapVaultsFromAccounts(accounts),
|
|
415
|
+
};
|
|
416
|
+
return { MeteoraDammV2Swap: ev };
|
|
417
|
+
}
|
|
418
|
+
function parseMeteoraDammInstruction(instructionData, accounts, signature, slot, txIndex, blockTimeUs, grpcRecvUs) {
|
|
419
|
+
if (instructionData.length < 8)
|
|
420
|
+
return null;
|
|
421
|
+
const meta = (0, utils_js_1.ixMeta)(signature, slot, txIndex, blockTimeUs, grpcRecvUs);
|
|
422
|
+
if (instructionData.length >= 24 && headEq(instructionData, ANCHOR.SWAP)) {
|
|
423
|
+
return parseOuterSwapIx(instructionData, accounts, meta);
|
|
424
|
+
}
|
|
425
|
+
if (instructionData.length >= 25 && headEq(instructionData, ANCHOR.SWAP2)) {
|
|
426
|
+
return parseOuterSwap2Ix(instructionData, accounts, meta);
|
|
427
|
+
}
|
|
428
|
+
if (instructionData.length >= 41 && headEq(instructionData, ANCHOR.INITIALIZE_POOL)) {
|
|
429
|
+
return parseOuterInitializePoolIx(instructionData, accounts, meta);
|
|
430
|
+
}
|
|
431
|
+
if (instructionData.length >= 40 && headEq(instructionData, ANCHOR.ADD_LIQUIDITY)) {
|
|
432
|
+
return parseOuterAddLiquidityIx(instructionData, accounts, meta);
|
|
433
|
+
}
|
|
434
|
+
if (instructionData.length >= 40 && headEq(instructionData, ANCHOR.REMOVE_LIQUIDITY)) {
|
|
435
|
+
return parseOuterRemoveLiquidityIx(instructionData, accounts, meta);
|
|
436
|
+
}
|
|
437
|
+
if (instructionData.length >= 24 && headEq(instructionData, ANCHOR.REMOVE_ALL_LIQUIDITY)) {
|
|
438
|
+
return parseOuterRemoveAllLiquidityIx(instructionData, accounts, meta);
|
|
439
|
+
}
|
|
440
|
+
if (instructionData.length >= 8 && headEq(instructionData, ANCHOR.CREATE_POSITION)) {
|
|
441
|
+
return parseOuterCreatePositionIx(accounts, meta);
|
|
442
|
+
}
|
|
443
|
+
if (instructionData.length >= 8 && headEq(instructionData, ANCHOR.CLOSE_POSITION)) {
|
|
444
|
+
return parseOuterClosePositionIx(accounts, meta);
|
|
445
|
+
}
|
|
446
|
+
if (instructionData.length < 16)
|
|
447
|
+
return null;
|
|
448
|
+
const cpiHead = instructionData.subarray(8, 16);
|
|
449
|
+
const cpiData = instructionData.subarray(16);
|
|
450
|
+
if (discEq(cpiHead, CPI.SWAP_LOG))
|
|
451
|
+
return parseSwapCpi(cpiData, accounts, meta);
|
|
452
|
+
if (discEq(cpiHead, CPI.SWAP2_LOG))
|
|
453
|
+
return parseSwap2Cpi(cpiData, accounts, meta);
|
|
454
|
+
if (discEq(cpiHead, CPI.CREATE_POSITION_LOG)) {
|
|
455
|
+
let o = 0;
|
|
456
|
+
const pool = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
457
|
+
if (!pool)
|
|
458
|
+
return null;
|
|
459
|
+
o += 32;
|
|
460
|
+
const owner = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
461
|
+
if (!owner)
|
|
462
|
+
return null;
|
|
463
|
+
o += 32;
|
|
464
|
+
const position = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
465
|
+
if (!position)
|
|
466
|
+
return null;
|
|
467
|
+
o += 32;
|
|
468
|
+
const position_nft_mint = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
469
|
+
if (!position_nft_mint)
|
|
470
|
+
return null;
|
|
471
|
+
return {
|
|
472
|
+
MeteoraDammV2CreatePosition: { metadata: meta, pool, owner, position, position_nft_mint },
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (discEq(cpiHead, CPI.CLOSE_POSITION_LOG)) {
|
|
476
|
+
let o = 0;
|
|
477
|
+
const pool = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
478
|
+
if (!pool)
|
|
479
|
+
return null;
|
|
480
|
+
o += 32;
|
|
481
|
+
const owner = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
482
|
+
if (!owner)
|
|
483
|
+
return null;
|
|
484
|
+
o += 32;
|
|
485
|
+
const position = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
486
|
+
if (!position)
|
|
487
|
+
return null;
|
|
488
|
+
o += 32;
|
|
489
|
+
const position_nft_mint = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
490
|
+
if (!position_nft_mint)
|
|
491
|
+
return null;
|
|
492
|
+
return {
|
|
493
|
+
MeteoraDammV2ClosePosition: { metadata: meta, pool, owner, position, position_nft_mint },
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (discEq(cpiHead, CPI.ADD_LIQUIDITY_LOG)) {
|
|
497
|
+
let o = 0;
|
|
498
|
+
const pool = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
499
|
+
if (!pool)
|
|
500
|
+
return null;
|
|
501
|
+
o += 32;
|
|
502
|
+
const position = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
503
|
+
if (!position)
|
|
504
|
+
return null;
|
|
505
|
+
o += 32;
|
|
506
|
+
const owner = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
507
|
+
if (!owner)
|
|
508
|
+
return null;
|
|
509
|
+
o += 32;
|
|
510
|
+
const liquidity_delta = (0, utils_js_1.readU128LE)(cpiData, o);
|
|
511
|
+
if (liquidity_delta === null)
|
|
512
|
+
return null;
|
|
513
|
+
o += 16;
|
|
514
|
+
const token_a_amount_threshold = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
515
|
+
if (token_a_amount_threshold === null)
|
|
516
|
+
return null;
|
|
517
|
+
o += 8;
|
|
518
|
+
const token_b_amount_threshold = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
519
|
+
if (token_b_amount_threshold === null)
|
|
520
|
+
return null;
|
|
521
|
+
o += 8;
|
|
522
|
+
const token_a_amount = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
523
|
+
if (token_a_amount === null)
|
|
524
|
+
return null;
|
|
525
|
+
o += 8;
|
|
526
|
+
const token_b_amount = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
527
|
+
if (token_b_amount === null)
|
|
528
|
+
return null;
|
|
529
|
+
o += 8;
|
|
530
|
+
const total_amount_a = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
531
|
+
if (total_amount_a === null)
|
|
532
|
+
return null;
|
|
533
|
+
o += 8;
|
|
534
|
+
const total_amount_b = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
535
|
+
if (total_amount_b === null)
|
|
536
|
+
return null;
|
|
537
|
+
return {
|
|
538
|
+
MeteoraDammV2AddLiquidity: {
|
|
539
|
+
metadata: meta,
|
|
540
|
+
pool,
|
|
541
|
+
position,
|
|
542
|
+
owner,
|
|
543
|
+
liquidity_delta,
|
|
544
|
+
token_a_amount_threshold,
|
|
545
|
+
token_b_amount_threshold,
|
|
546
|
+
token_a_amount,
|
|
547
|
+
token_b_amount,
|
|
548
|
+
total_amount_a,
|
|
549
|
+
total_amount_b,
|
|
550
|
+
},
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
if (discEq(cpiHead, CPI.REMOVE_LIQUIDITY_LOG)) {
|
|
554
|
+
let o = 0;
|
|
555
|
+
const pool = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
556
|
+
if (!pool)
|
|
557
|
+
return null;
|
|
558
|
+
o += 32;
|
|
559
|
+
const position = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
560
|
+
if (!position)
|
|
561
|
+
return null;
|
|
562
|
+
o += 32;
|
|
563
|
+
const owner = (0, utils_js_1.readPubkeyIx)(cpiData, o);
|
|
564
|
+
if (!owner)
|
|
565
|
+
return null;
|
|
566
|
+
o += 32;
|
|
567
|
+
const liquidity_delta = (0, utils_js_1.readU128LE)(cpiData, o);
|
|
568
|
+
if (liquidity_delta === null)
|
|
569
|
+
return null;
|
|
570
|
+
o += 16;
|
|
571
|
+
const token_a_amount_threshold = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
572
|
+
if (token_a_amount_threshold === null)
|
|
573
|
+
return null;
|
|
574
|
+
o += 8;
|
|
575
|
+
const token_b_amount_threshold = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
576
|
+
if (token_b_amount_threshold === null)
|
|
577
|
+
return null;
|
|
578
|
+
o += 8;
|
|
579
|
+
const token_a_amount = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
580
|
+
if (token_a_amount === null)
|
|
581
|
+
return null;
|
|
582
|
+
o += 8;
|
|
583
|
+
const token_b_amount = (0, utils_js_1.readU64LE)(cpiData, o);
|
|
584
|
+
if (token_b_amount === null)
|
|
585
|
+
return null;
|
|
586
|
+
return {
|
|
587
|
+
MeteoraDammV2RemoveLiquidity: {
|
|
588
|
+
metadata: meta,
|
|
589
|
+
pool,
|
|
590
|
+
position,
|
|
591
|
+
owner,
|
|
592
|
+
liquidity_delta,
|
|
593
|
+
token_a_amount_threshold,
|
|
594
|
+
token_b_amount_threshold,
|
|
595
|
+
token_a_amount,
|
|
596
|
+
token_b_amount,
|
|
597
|
+
},
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
return null;
|
|
601
|
+
}
|