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,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bincodeVecEntryCount = bincodeVecEntryCount;
|
|
4
|
+
exports.decodeCompactU16 = decodeCompactU16;
|
|
5
|
+
exports.parseTransaction = parseTransaction;
|
|
6
|
+
exports.decodeEntriesBincodeFlat = decodeEntriesBincodeFlat;
|
|
7
|
+
exports.decodeEntriesBincodeNested = decodeEntriesBincodeNested;
|
|
8
|
+
exports.decodeShredstreamEntriesBincode = decodeShredstreamEntriesBincode;
|
|
9
|
+
const wire_to_shred_tx_js_1 = require("./wire_to_shred_tx.js");
|
|
10
|
+
const MAX_VEC_ENTRIES = 100_000;
|
|
11
|
+
function readU64LE(buf, offset) {
|
|
12
|
+
const v = new DataView(buf.buffer, buf.byteOffset + offset, 8);
|
|
13
|
+
return v.getBigUint64(0, true);
|
|
14
|
+
}
|
|
15
|
+
/** 与 Go `BincodeVecEntryCount` 一致 */
|
|
16
|
+
function bincodeVecEntryCount(entriesBytes) {
|
|
17
|
+
if (entriesBytes.length < 8) {
|
|
18
|
+
throw new Error("shredstream: entries payload too short for vec length");
|
|
19
|
+
}
|
|
20
|
+
const n = readU64LE(entriesBytes, 0);
|
|
21
|
+
if (n > BigInt(MAX_VEC_ENTRIES)) {
|
|
22
|
+
throw new Error(`shredstream: corrupt entry_count ${n} exceeds limit`);
|
|
23
|
+
}
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
/** compact-u16,与 Go `decodeCompactU16` 一致 */
|
|
27
|
+
function decodeCompactU16(buf, pos) {
|
|
28
|
+
if (pos >= buf.length)
|
|
29
|
+
return null;
|
|
30
|
+
const b0 = buf[pos];
|
|
31
|
+
if (b0 < 0x80)
|
|
32
|
+
return { value: b0, bytes: 1 };
|
|
33
|
+
if (pos + 1 >= buf.length)
|
|
34
|
+
return null;
|
|
35
|
+
const b1 = buf[pos + 1];
|
|
36
|
+
if (b1 < 0x80) {
|
|
37
|
+
return { value: (b0 & 0x7f) | (b1 << 7), bytes: 2 };
|
|
38
|
+
}
|
|
39
|
+
if (pos + 2 >= buf.length)
|
|
40
|
+
return null;
|
|
41
|
+
const b2 = buf[pos + 2];
|
|
42
|
+
return { value: (b0 & 0x7f) | ((b1 & 0x7f) << 7) | (b2 << 14), bytes: 3 };
|
|
43
|
+
}
|
|
44
|
+
/** 返回 (txWireLength, signatures);失败返回 null */
|
|
45
|
+
function parseTransaction(buf, pos) {
|
|
46
|
+
const start = pos;
|
|
47
|
+
if (pos >= buf.length)
|
|
48
|
+
return null;
|
|
49
|
+
const sigCountEnc = decodeCompactU16(buf, pos);
|
|
50
|
+
if (!sigCountEnc)
|
|
51
|
+
return null;
|
|
52
|
+
let p = pos + sigCountEnc.bytes;
|
|
53
|
+
const sigCount = sigCountEnc.value;
|
|
54
|
+
const sigsEnd = p + sigCount * 64;
|
|
55
|
+
if (sigsEnd > buf.length)
|
|
56
|
+
return null;
|
|
57
|
+
const sigs = [];
|
|
58
|
+
for (let i = 0; i < sigCount; i++) {
|
|
59
|
+
sigs.push(buf.subarray(p, p + 64));
|
|
60
|
+
p += 64;
|
|
61
|
+
}
|
|
62
|
+
if (p >= buf.length)
|
|
63
|
+
return null;
|
|
64
|
+
const msgFirst = buf[p];
|
|
65
|
+
const isV0 = msgFirst >= 0x80;
|
|
66
|
+
if (isV0)
|
|
67
|
+
p += 1;
|
|
68
|
+
p += 3;
|
|
69
|
+
if (p > buf.length)
|
|
70
|
+
return null;
|
|
71
|
+
const acctEnc = decodeCompactU16(buf, p);
|
|
72
|
+
if (!acctEnc)
|
|
73
|
+
return null;
|
|
74
|
+
p += acctEnc.bytes;
|
|
75
|
+
p += acctEnc.value * 32;
|
|
76
|
+
if (p > buf.length)
|
|
77
|
+
return null;
|
|
78
|
+
p += 32;
|
|
79
|
+
if (p > buf.length)
|
|
80
|
+
return null;
|
|
81
|
+
const ixCountEnc = decodeCompactU16(buf, p);
|
|
82
|
+
if (!ixCountEnc)
|
|
83
|
+
return null;
|
|
84
|
+
p += ixCountEnc.bytes;
|
|
85
|
+
const ixCount = ixCountEnc.value;
|
|
86
|
+
for (let ix = 0; ix < ixCount; ix++) {
|
|
87
|
+
p += 1;
|
|
88
|
+
if (p > buf.length)
|
|
89
|
+
return null;
|
|
90
|
+
const acctLenEnc = decodeCompactU16(buf, p);
|
|
91
|
+
if (!acctLenEnc)
|
|
92
|
+
return null;
|
|
93
|
+
p += acctLenEnc.bytes;
|
|
94
|
+
p += acctLenEnc.value;
|
|
95
|
+
if (p > buf.length)
|
|
96
|
+
return null;
|
|
97
|
+
const dataLenEnc = decodeCompactU16(buf, p);
|
|
98
|
+
if (!dataLenEnc)
|
|
99
|
+
return null;
|
|
100
|
+
p += dataLenEnc.bytes;
|
|
101
|
+
p += dataLenEnc.value;
|
|
102
|
+
if (p > buf.length)
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
if (isV0) {
|
|
106
|
+
if (p >= buf.length)
|
|
107
|
+
return null;
|
|
108
|
+
const atlCountEnc = decodeCompactU16(buf, p);
|
|
109
|
+
if (!atlCountEnc)
|
|
110
|
+
return null;
|
|
111
|
+
p += atlCountEnc.bytes;
|
|
112
|
+
const atlCount = atlCountEnc.value;
|
|
113
|
+
for (let atl = 0; atl < atlCount; atl++) {
|
|
114
|
+
p += 32;
|
|
115
|
+
if (p > buf.length)
|
|
116
|
+
return null;
|
|
117
|
+
const wLenEnc = decodeCompactU16(buf, p);
|
|
118
|
+
if (!wLenEnc)
|
|
119
|
+
return null;
|
|
120
|
+
p += wLenEnc.bytes;
|
|
121
|
+
p += wLenEnc.value;
|
|
122
|
+
if (p > buf.length)
|
|
123
|
+
return null;
|
|
124
|
+
const rLenEnc = decodeCompactU16(buf, p);
|
|
125
|
+
if (!rLenEnc)
|
|
126
|
+
return null;
|
|
127
|
+
p += rLenEnc.bytes;
|
|
128
|
+
p += rLenEnc.value;
|
|
129
|
+
if (p > buf.length)
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { txLen: p - start, sigs };
|
|
134
|
+
}
|
|
135
|
+
class BatchDecoder {
|
|
136
|
+
buffer = new Uint8Array(0);
|
|
137
|
+
expectedEntryCount = 0;
|
|
138
|
+
entriesYielded = 0;
|
|
139
|
+
cursor = 0;
|
|
140
|
+
append(payload) {
|
|
141
|
+
const merged = new Uint8Array(this.buffer.length + payload.length);
|
|
142
|
+
merged.set(this.buffer);
|
|
143
|
+
merged.set(payload, this.buffer.length);
|
|
144
|
+
this.buffer = merged;
|
|
145
|
+
}
|
|
146
|
+
tryDecodeEntry() {
|
|
147
|
+
const pos = this.cursor;
|
|
148
|
+
const buf = this.buffer;
|
|
149
|
+
if (pos + 48 > buf.length)
|
|
150
|
+
return null;
|
|
151
|
+
let p = pos + 8 + 32;
|
|
152
|
+
const txCount = Number(readU64LE(buf, p));
|
|
153
|
+
p += 8;
|
|
154
|
+
const txs = [];
|
|
155
|
+
for (let i = 0; i < txCount; i++) {
|
|
156
|
+
const txStart = p;
|
|
157
|
+
const parsed = parseTransaction(buf, p);
|
|
158
|
+
if (!parsed) {
|
|
159
|
+
throw new Error(`shredstream: truncated transaction ${i} in entry`);
|
|
160
|
+
}
|
|
161
|
+
const { txLen, sigs } = parsed;
|
|
162
|
+
const raw = buf.subarray(txStart, txStart + txLen);
|
|
163
|
+
txs.push({
|
|
164
|
+
raw: Uint8Array.from(raw),
|
|
165
|
+
signatures: sigs.map((s) => Uint8Array.from(s)),
|
|
166
|
+
});
|
|
167
|
+
p = txStart + txLen;
|
|
168
|
+
}
|
|
169
|
+
this.cursor = p;
|
|
170
|
+
return txs;
|
|
171
|
+
}
|
|
172
|
+
/** 扁平列表,对齐 Go `DecodeEntriesBincode` */
|
|
173
|
+
pushFlat(payload) {
|
|
174
|
+
this.append(payload);
|
|
175
|
+
if (this.expectedEntryCount === 0 && this.entriesYielded === 0 && this.cursor === 0) {
|
|
176
|
+
if (this.buffer.length < 8) {
|
|
177
|
+
throw new Error("shredstream: entries payload too short for vec length");
|
|
178
|
+
}
|
|
179
|
+
const count = readU64LE(this.buffer, 0);
|
|
180
|
+
if (count > BigInt(MAX_VEC_ENTRIES)) {
|
|
181
|
+
throw new Error(`shredstream: corrupt entry_count ${count} exceeds limit`);
|
|
182
|
+
}
|
|
183
|
+
this.expectedEntryCount = Number(count);
|
|
184
|
+
this.cursor = 8;
|
|
185
|
+
}
|
|
186
|
+
const out = [];
|
|
187
|
+
while (this.entriesYielded < this.expectedEntryCount) {
|
|
188
|
+
const entryTxs = this.tryDecodeEntry();
|
|
189
|
+
if (entryTxs === null) {
|
|
190
|
+
throw new Error(`shredstream: incomplete entry at offset ${this.cursor}`);
|
|
191
|
+
}
|
|
192
|
+
out.push(...entryTxs);
|
|
193
|
+
this.entriesYielded++;
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
/** 按 Solana `Entry` 分层,供 ShredStream 客户端(Entry 内 tx_index) */
|
|
198
|
+
pushNested(payload) {
|
|
199
|
+
this.append(payload);
|
|
200
|
+
if (this.expectedEntryCount === 0 && this.entriesYielded === 0 && this.cursor === 0) {
|
|
201
|
+
if (this.buffer.length < 8) {
|
|
202
|
+
throw new Error("shredstream: entries payload too short for vec length");
|
|
203
|
+
}
|
|
204
|
+
const count = readU64LE(this.buffer, 0);
|
|
205
|
+
if (count > BigInt(MAX_VEC_ENTRIES)) {
|
|
206
|
+
throw new Error(`shredstream: corrupt entry_count ${count} exceeds limit`);
|
|
207
|
+
}
|
|
208
|
+
this.expectedEntryCount = Number(count);
|
|
209
|
+
this.cursor = 8;
|
|
210
|
+
}
|
|
211
|
+
const nested = [];
|
|
212
|
+
while (this.entriesYielded < this.expectedEntryCount) {
|
|
213
|
+
const entryTxs = this.tryDecodeEntry();
|
|
214
|
+
if (entryTxs === null) {
|
|
215
|
+
throw new Error(`shredstream: incomplete entry at offset ${this.cursor}`);
|
|
216
|
+
}
|
|
217
|
+
nested.push(entryTxs);
|
|
218
|
+
this.entriesYielded++;
|
|
219
|
+
}
|
|
220
|
+
return nested;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function decodeEntriesBincodeFlat(entriesBytes) {
|
|
224
|
+
if (entriesBytes.length === 0)
|
|
225
|
+
return [];
|
|
226
|
+
const dec = new BatchDecoder();
|
|
227
|
+
return dec.pushFlat(entriesBytes);
|
|
228
|
+
}
|
|
229
|
+
function decodeEntriesBincodeNested(entriesBytes) {
|
|
230
|
+
if (entriesBytes.length === 0)
|
|
231
|
+
return [];
|
|
232
|
+
const dec = new BatchDecoder();
|
|
233
|
+
return dec.pushNested(entriesBytes);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 解码 gRPC `entries` 字节并展开为与旧 WASM 相同的嵌套 `ShredWasmTx`(跳过无法反序列化的单笔交易)。
|
|
237
|
+
*/
|
|
238
|
+
function decodeShredstreamEntriesBincode(bytes) {
|
|
239
|
+
const nested = decodeEntriesBincodeNested(bytes);
|
|
240
|
+
const out = [];
|
|
241
|
+
for (const entryTxs of nested) {
|
|
242
|
+
const row = [];
|
|
243
|
+
for (const w of entryTxs) {
|
|
244
|
+
const tx = (0, wire_to_shred_tx_js_1.wireBytesToShredWasmTx)(w.raw);
|
|
245
|
+
if (tx)
|
|
246
|
+
row.push(tx);
|
|
247
|
+
}
|
|
248
|
+
out.push(row);
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jito ShredStream 超低延迟订阅(与 Rust `sol-parser-sdk::shredstream` 对齐)。
|
|
3
|
+
*
|
|
4
|
+
* 限制(与 Rust `shredstream/mod.rs` 文档一致):
|
|
5
|
+
* - 仅静态账户键;使用 ALT 的交易账户列表不完整
|
|
6
|
+
* - 无 inner instructions,无法 CPI 解析
|
|
7
|
+
* - 无 block_time
|
|
8
|
+
* - 无交易日志(program logs);客户端对每条交易走 **外层 `parseInstructionUnified`**(与 gRPC 指令解析同源),可产出 `DexEvent`(V0+ALT 若账户下标超出静态表则用默认 pubkey best-effort)
|
|
9
|
+
* - `metadata.tx_index` 为**单条 gRPC `Entry` 消息内**跨所有 Solana `Entry` 分组的连续下标(与 golang `shredstream_entries` 扁平 `ti` 对齐),非 slot 级全局序号
|
|
10
|
+
*/
|
|
11
|
+
export { type ShredStreamConfig, defaultShredStreamConfig, lowLatencyShredStreamConfig, highThroughputShredStreamConfig, } from "./config.js";
|
|
12
|
+
export { ShredStreamClient, ShredEventQueue, type ShredStreamReceiveStats, } from "./client.js";
|
|
13
|
+
export { dexEventsFromShredWasmTx, dexEventsFromShredWasmTxWithFullKeys, type ShredWasmTx, type ShredWasmCompiledIx, } from "./instruction_parse.js";
|
|
14
|
+
export { fullAccountKeyStringsFromShredTx, loadAddressLookupTableAccounts } from "./alt_lookup.js";
|
|
15
|
+
export type { SubscribeEntriesRequest, ShredstreamEntryMessage } from "./proto_types.js";
|
|
16
|
+
export { bincodeVecEntryCount, decodeEntriesBincodeFlat, decodeEntriesBincodeNested, decodeShredstreamEntriesBincode, type DecodedWireTransaction, } from "./entries_decode.js";
|
|
17
|
+
export { wireBytesToShredWasmTx } from "./wire_to_shred_tx.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wireBytesToShredWasmTx = exports.decodeShredstreamEntriesBincode = exports.decodeEntriesBincodeNested = exports.decodeEntriesBincodeFlat = exports.bincodeVecEntryCount = exports.loadAddressLookupTableAccounts = exports.fullAccountKeyStringsFromShredTx = exports.dexEventsFromShredWasmTxWithFullKeys = exports.dexEventsFromShredWasmTx = exports.ShredEventQueue = exports.ShredStreamClient = exports.highThroughputShredStreamConfig = exports.lowLatencyShredStreamConfig = exports.defaultShredStreamConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Jito ShredStream 超低延迟订阅(与 Rust `sol-parser-sdk::shredstream` 对齐)。
|
|
6
|
+
*
|
|
7
|
+
* 限制(与 Rust `shredstream/mod.rs` 文档一致):
|
|
8
|
+
* - 仅静态账户键;使用 ALT 的交易账户列表不完整
|
|
9
|
+
* - 无 inner instructions,无法 CPI 解析
|
|
10
|
+
* - 无 block_time
|
|
11
|
+
* - 无交易日志(program logs);客户端对每条交易走 **外层 `parseInstructionUnified`**(与 gRPC 指令解析同源),可产出 `DexEvent`(V0+ALT 若账户下标超出静态表则用默认 pubkey best-effort)
|
|
12
|
+
* - `metadata.tx_index` 为**单条 gRPC `Entry` 消息内**跨所有 Solana `Entry` 分组的连续下标(与 golang `shredstream_entries` 扁平 `ti` 对齐),非 slot 级全局序号
|
|
13
|
+
*/
|
|
14
|
+
var config_js_1 = require("./config.js");
|
|
15
|
+
Object.defineProperty(exports, "defaultShredStreamConfig", { enumerable: true, get: function () { return config_js_1.defaultShredStreamConfig; } });
|
|
16
|
+
Object.defineProperty(exports, "lowLatencyShredStreamConfig", { enumerable: true, get: function () { return config_js_1.lowLatencyShredStreamConfig; } });
|
|
17
|
+
Object.defineProperty(exports, "highThroughputShredStreamConfig", { enumerable: true, get: function () { return config_js_1.highThroughputShredStreamConfig; } });
|
|
18
|
+
var client_js_1 = require("./client.js");
|
|
19
|
+
Object.defineProperty(exports, "ShredStreamClient", { enumerable: true, get: function () { return client_js_1.ShredStreamClient; } });
|
|
20
|
+
Object.defineProperty(exports, "ShredEventQueue", { enumerable: true, get: function () { return client_js_1.ShredEventQueue; } });
|
|
21
|
+
var instruction_parse_js_1 = require("./instruction_parse.js");
|
|
22
|
+
Object.defineProperty(exports, "dexEventsFromShredWasmTx", { enumerable: true, get: function () { return instruction_parse_js_1.dexEventsFromShredWasmTx; } });
|
|
23
|
+
Object.defineProperty(exports, "dexEventsFromShredWasmTxWithFullKeys", { enumerable: true, get: function () { return instruction_parse_js_1.dexEventsFromShredWasmTxWithFullKeys; } });
|
|
24
|
+
var alt_lookup_js_1 = require("./alt_lookup.js");
|
|
25
|
+
Object.defineProperty(exports, "fullAccountKeyStringsFromShredTx", { enumerable: true, get: function () { return alt_lookup_js_1.fullAccountKeyStringsFromShredTx; } });
|
|
26
|
+
Object.defineProperty(exports, "loadAddressLookupTableAccounts", { enumerable: true, get: function () { return alt_lookup_js_1.loadAddressLookupTableAccounts; } });
|
|
27
|
+
var entries_decode_js_1 = require("./entries_decode.js");
|
|
28
|
+
Object.defineProperty(exports, "bincodeVecEntryCount", { enumerable: true, get: function () { return entries_decode_js_1.bincodeVecEntryCount; } });
|
|
29
|
+
Object.defineProperty(exports, "decodeEntriesBincodeFlat", { enumerable: true, get: function () { return entries_decode_js_1.decodeEntriesBincodeFlat; } });
|
|
30
|
+
Object.defineProperty(exports, "decodeEntriesBincodeNested", { enumerable: true, get: function () { return entries_decode_js_1.decodeEntriesBincodeNested; } });
|
|
31
|
+
Object.defineProperty(exports, "decodeShredstreamEntriesBincode", { enumerable: true, get: function () { return entries_decode_js_1.decodeShredstreamEntriesBincode; } });
|
|
32
|
+
var wire_to_shred_tx_js_1 = require("./wire_to_shred_tx.js");
|
|
33
|
+
Object.defineProperty(exports, "wireBytesToShredWasmTx", { enumerable: true, get: function () { return wire_to_shred_tx_js_1.wireBytesToShredWasmTx; } });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShredStream:外层编译指令 → `parseInstructionUnified`(与 gRPC 指令解析同源)。
|
|
3
|
+
* `ShredWasmTx` 来自线格式交易经 `@solana/web3.js` 反序列化(见 `wire_to_shred_tx.ts`),非 WASM。
|
|
4
|
+
* 有 `ShredStreamConfig.connection` 时可展开 V0 ALT;无 RPC 时用静态账户表 + 默认 pubkey best-effort。
|
|
5
|
+
*/
|
|
6
|
+
import type { MessageHeader } from "@solana/web3.js";
|
|
7
|
+
import { type DexEvent } from "../core/dex_event.js";
|
|
8
|
+
import { type EventTypeFilter } from "../grpc/types.js";
|
|
9
|
+
export type ShredWasmCompiledIx = {
|
|
10
|
+
programIdIndex: number;
|
|
11
|
+
accounts: Uint8Array;
|
|
12
|
+
data: Uint8Array;
|
|
13
|
+
};
|
|
14
|
+
export type ShredAddressTableLookup = {
|
|
15
|
+
accountKey: string;
|
|
16
|
+
writableIndexes: Uint8Array;
|
|
17
|
+
readonlyIndexes: Uint8Array;
|
|
18
|
+
};
|
|
19
|
+
export type ShredWasmTx = {
|
|
20
|
+
signature: string;
|
|
21
|
+
accounts: string[];
|
|
22
|
+
instructions?: ShredWasmCompiledIx[];
|
|
23
|
+
/** 缺省则按仅静态账户处理 */
|
|
24
|
+
messageVersion?: "legacy" | "v0";
|
|
25
|
+
header?: MessageHeader;
|
|
26
|
+
recentBlockhash?: Uint8Array;
|
|
27
|
+
addressTableLookups?: ShredAddressTableLookup[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 使用已解析的完整账户表(静态+ALT)解析外层指令。
|
|
31
|
+
*/
|
|
32
|
+
export declare function dexEventsFromShredWasmTxWithFullKeys(tx: ShredWasmTx, fullAccountKeys: string[], slot: number, txIndex: number, grpcRecvUs: number, eventTypeFilter?: EventTypeFilter): DexEvent[];
|
|
33
|
+
/** 仅静态账户表(无 RPC 时;V0+ALT 缺失账户以默认 pubkey 占位) */
|
|
34
|
+
export declare function dexEventsFromShredWasmTx(tx: ShredWasmTx, slot: number, txIndex: number, grpcRecvUs: number, eventTypeFilter?: EventTypeFilter): DexEvent[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dexEventsFromShredWasmTxWithFullKeys = dexEventsFromShredWasmTxWithFullKeys;
|
|
4
|
+
exports.dexEventsFromShredWasmTx = dexEventsFromShredWasmTx;
|
|
5
|
+
const dex_event_js_1 = require("../core/dex_event.js");
|
|
6
|
+
const pumpfun_fee_enrich_js_1 = require("../core/pumpfun_fee_enrich.js");
|
|
7
|
+
const types_js_1 = require("../grpc/types.js");
|
|
8
|
+
const mod_js_1 = require("../instr/mod.js");
|
|
9
|
+
const program_ids_js_1 = require("../instr/program_ids.js");
|
|
10
|
+
function asU8(b) {
|
|
11
|
+
if (b instanceof Uint8Array)
|
|
12
|
+
return b;
|
|
13
|
+
return Uint8Array.from(b);
|
|
14
|
+
}
|
|
15
|
+
const UNKNOWN_PROGRAM_CANDIDATES = [
|
|
16
|
+
program_ids_js_1.PUMPFUN_PROGRAM_ID,
|
|
17
|
+
program_ids_js_1.PUMPSWAP_PROGRAM_ID,
|
|
18
|
+
program_ids_js_1.PUMP_FEES_PROGRAM_ID,
|
|
19
|
+
program_ids_js_1.RAYDIUM_LAUNCHLAB_PROGRAM_ID,
|
|
20
|
+
program_ids_js_1.RAYDIUM_CPMM_PROGRAM_ID,
|
|
21
|
+
program_ids_js_1.RAYDIUM_CLMM_PROGRAM_ID,
|
|
22
|
+
program_ids_js_1.RAYDIUM_AMM_V4_PROGRAM_ID,
|
|
23
|
+
program_ids_js_1.ORCA_WHIRLPOOL_PROGRAM_ID,
|
|
24
|
+
program_ids_js_1.METEORA_POOLS_PROGRAM_ID,
|
|
25
|
+
program_ids_js_1.METEORA_DAMM_V2_PROGRAM_ID,
|
|
26
|
+
program_ids_js_1.METEORA_DLMM_PROGRAM_ID,
|
|
27
|
+
];
|
|
28
|
+
const SHRED_DEFAULT_PUBKEY = (0, dex_event_js_1.defaultPubkey)();
|
|
29
|
+
function shouldParseShredInstructions(eventTypeFilter) {
|
|
30
|
+
const includeOnly = eventTypeFilter?.include_only;
|
|
31
|
+
return !includeOnly || (0, types_js_1.eventTypeFilterAllowsInstructionParsing)(includeOnly);
|
|
32
|
+
}
|
|
33
|
+
function ixAccountStrings(fullAccountKeys, accBytes) {
|
|
34
|
+
const accountStrs = [];
|
|
35
|
+
for (let i = 0; i < accBytes.length; i++) {
|
|
36
|
+
const ai = accBytes[i];
|
|
37
|
+
accountStrs.push(ai < fullAccountKeys.length ? fullAccountKeys[ai] : SHRED_DEFAULT_PUBKEY);
|
|
38
|
+
}
|
|
39
|
+
return accountStrs;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 使用已解析的完整账户表(静态+ALT)解析外层指令。
|
|
43
|
+
*/
|
|
44
|
+
function dexEventsFromShredWasmTxWithFullKeys(tx, fullAccountKeys, slot, txIndex, grpcRecvUs, eventTypeFilter) {
|
|
45
|
+
const ixs = tx.instructions;
|
|
46
|
+
if (!ixs?.length || fullAccountKeys.length === 0)
|
|
47
|
+
return [];
|
|
48
|
+
if (!shouldParseShredInstructions(eventTypeFilter))
|
|
49
|
+
return [];
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const rawIx of ixs) {
|
|
52
|
+
const pidIdx = rawIx.programIdIndex;
|
|
53
|
+
if (!Number.isFinite(pidIdx) || pidIdx < 0)
|
|
54
|
+
continue;
|
|
55
|
+
const accBytes = asU8(rawIx.accounts);
|
|
56
|
+
const data = asU8(rawIx.data);
|
|
57
|
+
const accountStrs = ixAccountStrings(fullAccountKeys, accBytes);
|
|
58
|
+
if (pidIdx >= fullAccountKeys.length) {
|
|
59
|
+
for (const programId of UNKNOWN_PROGRAM_CANDIDATES) {
|
|
60
|
+
const ev = (0, mod_js_1.parseInstructionUnified)(data, accountStrs, tx.signature, slot, txIndex, undefined, grpcRecvUs, eventTypeFilter, programId);
|
|
61
|
+
if (ev) {
|
|
62
|
+
out.push(ev);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const programId = fullAccountKeys[pidIdx];
|
|
69
|
+
const ev = (0, mod_js_1.parseInstructionUnified)(data, accountStrs, tx.signature, slot, txIndex, undefined, grpcRecvUs, eventTypeFilter, programId);
|
|
70
|
+
if (ev)
|
|
71
|
+
out.push(ev);
|
|
72
|
+
}
|
|
73
|
+
(0, pumpfun_fee_enrich_js_1.enrichPumpfunSameTxPostMerge)(out);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/** 仅静态账户表(无 RPC 时;V0+ALT 缺失账户以默认 pubkey 占位) */
|
|
77
|
+
function dexEventsFromShredWasmTx(tx, slot, txIndex, grpcRecvUs, eventTypeFilter) {
|
|
78
|
+
return dexEventsFromShredWasmTxWithFullKeys(tx, tx.accounts, slot, txIndex, grpcRecvUs, eventTypeFilter);
|
|
79
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShredStream gRPC 消息形状(与 Rust `shredstream::proto` 中 prost 定义一致)。
|
|
3
|
+
* 实际线路仍由 `shredstream.proto` + `@grpc/proto-loader` 解析。
|
|
4
|
+
*/
|
|
5
|
+
export type SubscribeEntriesRequest = Record<string, never>;
|
|
6
|
+
export interface ShredstreamEntryMessage {
|
|
7
|
+
slot: number | string | bigint;
|
|
8
|
+
entries: Uint8Array | Buffer;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package shredstream;
|
|
4
|
+
|
|
5
|
+
// 与 Rust `shredstream/proto/mod.rs` 内嵌定义一致;路径 /shredstream.ShredstreamProxy/SubscribeEntries
|
|
6
|
+
service ShredstreamProxy {
|
|
7
|
+
rpc SubscribeEntries(SubscribeEntriesRequest) returns (stream Entry);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
message SubscribeEntriesRequest {}
|
|
11
|
+
|
|
12
|
+
message Entry {
|
|
13
|
+
uint64 slot = 1;
|
|
14
|
+
bytes entries = 2;
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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.wireBytesToShredWasmTx = wireBytesToShredWasmTx;
|
|
7
|
+
/**
|
|
8
|
+
* 线格式交易字节 → `ShredWasmTx`(与原 wasm-pack 展开字段对齐,供 `parseInstructionUnified`)。
|
|
9
|
+
*/
|
|
10
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
12
|
+
function wireBytesToShredWasmTx(raw) {
|
|
13
|
+
try {
|
|
14
|
+
const vt = web3_js_1.VersionedTransaction.deserialize(Buffer.from(raw));
|
|
15
|
+
const sig0 = vt.signatures[0];
|
|
16
|
+
if (!sig0)
|
|
17
|
+
return null;
|
|
18
|
+
const signature = bs58_1.default.encode(sig0);
|
|
19
|
+
const msg = vt.message;
|
|
20
|
+
if (msg instanceof web3_js_1.MessageV0) {
|
|
21
|
+
const lookups = msg.addressTableLookups.map((l) => ({
|
|
22
|
+
accountKey: l.accountKey.toBase58(),
|
|
23
|
+
writableIndexes: new Uint8Array(l.writableIndexes),
|
|
24
|
+
readonlyIndexes: new Uint8Array(l.readonlyIndexes),
|
|
25
|
+
}));
|
|
26
|
+
const instructions = msg.compiledInstructions.map((ix) => ({
|
|
27
|
+
programIdIndex: ix.programIdIndex,
|
|
28
|
+
accounts: new Uint8Array(ix.accountKeyIndexes),
|
|
29
|
+
data: new Uint8Array(ix.data),
|
|
30
|
+
}));
|
|
31
|
+
return {
|
|
32
|
+
signature,
|
|
33
|
+
accounts: msg.staticAccountKeys.map((k) => k.toBase58()),
|
|
34
|
+
instructions,
|
|
35
|
+
messageVersion: "v0",
|
|
36
|
+
header: msg.header,
|
|
37
|
+
recentBlockhash: Uint8Array.from(bs58_1.default.decode(msg.recentBlockhash)),
|
|
38
|
+
addressTableLookups: lookups,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const m = msg;
|
|
42
|
+
const instructions = m.compiledInstructions.map((ix) => ({
|
|
43
|
+
programIdIndex: ix.programIdIndex,
|
|
44
|
+
accounts: new Uint8Array(ix.accountKeyIndexes),
|
|
45
|
+
data: new Uint8Array(ix.data),
|
|
46
|
+
}));
|
|
47
|
+
return {
|
|
48
|
+
signature,
|
|
49
|
+
accounts: m.staticAccountKeys.map((k) => k.toBase58()),
|
|
50
|
+
instructions,
|
|
51
|
+
messageVersion: "legacy",
|
|
52
|
+
header: m.header,
|
|
53
|
+
recentBlockhash: Uint8Array.from(bs58_1.default.decode(m.recentBlockhash)),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -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,18 @@
|
|
|
1
|
+
export type NumericAmount = bigint | number | string;
|
|
2
|
+
export type NormalizedTradeSide = "Buy" | "Sell";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a Q64.64 sqrt price into quote-token units per one base token.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sqrtPriceX64ToPrice(sqrtPriceX64: NumericAmount, baseDecimals: number, quoteDecimals: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Compute quote-token price per one base token from raw vault balances.
|
|
9
|
+
*/
|
|
10
|
+
export declare function vaultPriceFromBalances(baseRaw: NumericAmount, quoteRaw: NumericAmount, baseDecimals: number, quoteDecimals: number): number | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Positive watched-token delta means Buy; negative means Sell.
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeBuySellFromTokenDelta(tokenDelta: NumericAmount): NormalizedTradeSide | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* If input is quote, the user buys base. If input is base, the user sells base.
|
|
17
|
+
*/
|
|
18
|
+
export declare function normalizeBuySellFromInputMint(inputMint: string, baseMint: string, quoteMint: string): NormalizedTradeSide | undefined;
|