@qntx/wallet-chains 0.11.0 → 0.13.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/dist/bitcoin-sign.mjs +1 -1
- package/dist/bitcoin.d.mts +2 -2
- package/dist/bitcoin.mjs +31 -14
- package/dist/bitcoin.mjs.map +1 -1
- package/dist/evm-sign.d.mts +1 -1
- package/dist/evm-sign.mjs +28 -2
- package/dist/evm-sign.mjs.map +1 -1
- package/dist/evm.d.mts +111 -5
- package/dist/evm.mjs +570 -21
- package/dist/evm.mjs.map +1 -1
- package/dist/{index-QxoxkD5m.d.mts → index-DpL5hvPl.d.mts} +115 -7
- package/dist/index.d.mts +2 -2
- package/dist/{message-ChhEZ0lx.mjs → message-zf3XHwwc.mjs} +2 -2
- package/dist/{message-ChhEZ0lx.mjs.map → message-zf3XHwwc.mjs.map} +1 -1
- package/dist/solana.d.mts +30 -1
- package/dist/solana.mjs +507 -23
- package/dist/solana.mjs.map +1 -1
- package/dist/src-8NZeEnrW.mjs.map +1 -1
- package/dist/{typed-data-J5g2WemC.mjs → typed-data-B4PJ1v8F.mjs} +97 -6
- package/dist/typed-data-B4PJ1v8F.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/typed-data-J5g2WemC.mjs.map +0 -1
package/dist/solana.mjs
CHANGED
|
@@ -2,8 +2,9 @@ import { t as ChainError } from "./src-8NZeEnrW.mjs";
|
|
|
2
2
|
import { n as requestBase, t as isRecord$1 } from "./account-ref-D2rW_qlI.mjs";
|
|
3
3
|
import { address, getAddressDecoder, getAddressEncoder } from "@solana/addresses";
|
|
4
4
|
import { getCompiledTransactionMessageDecoder } from "@solana/transaction-messages";
|
|
5
|
-
import { getU32Decoder, getU64Decoder } from "@solana/codecs";
|
|
5
|
+
import { getI64Decoder, getU16Decoder, getU32Decoder, getU64Decoder } from "@solana/codecs";
|
|
6
6
|
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
7
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
7
8
|
// src/solana/ids.ts
|
|
8
9
|
/** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */
|
|
9
10
|
const PROGRAM_IDS = Object.freeze({
|
|
@@ -21,13 +22,13 @@ const PROGRAM_IDS = Object.freeze({
|
|
|
21
22
|
const SOLANA_NETWORKS = Object.freeze(["solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"]);
|
|
22
23
|
const BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
23
24
|
const isSolanaAddress = (value) => BASE58.test(value);
|
|
24
|
-
const decoder$
|
|
25
|
+
const decoder$2 = getAddressDecoder();
|
|
25
26
|
/** Base58-encoded address for a 32-byte ed25519 public key. */
|
|
26
27
|
function solanaAddressFromPublicKey(pubkey) {
|
|
27
28
|
if (pubkey.length !== 32) throw new ChainError("invalid-address", "expected a 32-byte ed25519 public key");
|
|
28
|
-
return decoder$
|
|
29
|
+
return decoder$2.decode(pubkey);
|
|
29
30
|
}
|
|
30
|
-
const decoder = getCompiledTransactionMessageDecoder();
|
|
31
|
+
const decoder$1 = getCompiledTransactionMessageDecoder();
|
|
31
32
|
/**
|
|
32
33
|
* Decodes a compiled wire message; rejects trailing bytes and the 1232-byte transaction limit. The
|
|
33
34
|
* fee payer is `staticAccounts[0]` — every valid transaction signs it.
|
|
@@ -37,7 +38,7 @@ const parseCompiledMessage = (bytes) => {
|
|
|
37
38
|
if (bytes.length === 0) throw new ChainError("invalid-request", "compiled message is empty");
|
|
38
39
|
let decoded;
|
|
39
40
|
try {
|
|
40
|
-
decoded = decoder.decode(bytes);
|
|
41
|
+
decoded = decoder$1.decode(bytes);
|
|
41
42
|
} catch {
|
|
42
43
|
throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
43
44
|
}
|
|
@@ -102,11 +103,8 @@ const asCompiledMessage = (value) => {
|
|
|
102
103
|
const resolveAccountIndex = (parsed, index, lookups) => {
|
|
103
104
|
if (index < parsed.staticAccounts.length) return parsed.staticAccounts[index];
|
|
104
105
|
if (lookups === void 0) return;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (offset < table.addresses.length) return table.addresses[offset];
|
|
108
|
-
offset -= table.addresses.length;
|
|
109
|
-
}
|
|
106
|
+
const declared = new Map(lookups.map((t) => [t.address, t.addresses]));
|
|
107
|
+
return [...parsed.lookups.flatMap((t) => t.writableIndexes.map((i) => declared.get(t.address)?.[i])), ...parsed.lookups.flatMap((t) => t.readonlyIndexes.map((i) => declared.get(t.address)?.[i]))][index - parsed.staticAccounts.length];
|
|
110
108
|
};
|
|
111
109
|
/** All declared lookup-table entries must be valid base58 32-byte addresses. */
|
|
112
110
|
const validateLookupTables = (tables) => {
|
|
@@ -116,6 +114,321 @@ const validateLookupTables = (tables) => {
|
|
|
116
114
|
// src/solana/assets.ts
|
|
117
115
|
/** The native asset id in `AssetFlow` and simulated asset changes. */
|
|
118
116
|
const SOLANA_NATIVE_ASSET = "lamports";
|
|
117
|
+
// src/solana/ata.ts
|
|
118
|
+
const PDA_SEED = new TextEncoder().encode("ProgramDerivedAddress");
|
|
119
|
+
const encoder = getAddressEncoder();
|
|
120
|
+
const decoder = getAddressDecoder();
|
|
121
|
+
const onCurve = (candidate) => {
|
|
122
|
+
try {
|
|
123
|
+
ed25519.Point.fromBytes(candidate);
|
|
124
|
+
return true;
|
|
125
|
+
} catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Sync Associated Token Account derivation for the kernel: `findAssociatedTokenPda` is async, so
|
|
131
|
+
* the decoder derives `sha256(owner ‖ tokenProgram ‖ mint ‖ bump ‖ ata ‖ "ProgramDerivedAddress")`
|
|
132
|
+
* over bump 255→0 and takes the first hash off the ed25519 curve — matching the on-chain rule.
|
|
133
|
+
*/
|
|
134
|
+
const associatedTokenAddress = (owner, mint, tokenProgram) => {
|
|
135
|
+
const ownerBytes = encoder.encode(address(owner));
|
|
136
|
+
const programBytes = encoder.encode(address(tokenProgram));
|
|
137
|
+
const mintBytes = encoder.encode(address(mint));
|
|
138
|
+
const ataBytes = encoder.encode(address(PROGRAM_IDS.associatedToken));
|
|
139
|
+
const input = new Uint8Array(ownerBytes.length + programBytes.length + mintBytes.length + 1 + ataBytes.length + PDA_SEED.length);
|
|
140
|
+
let o = 0;
|
|
141
|
+
const put = (bytes) => {
|
|
142
|
+
input.set(bytes, o);
|
|
143
|
+
o += bytes.length;
|
|
144
|
+
};
|
|
145
|
+
put(ownerBytes);
|
|
146
|
+
put(programBytes);
|
|
147
|
+
put(mintBytes);
|
|
148
|
+
const bumpAt = o;
|
|
149
|
+
o += 1;
|
|
150
|
+
put(ataBytes);
|
|
151
|
+
put(PDA_SEED);
|
|
152
|
+
for (let bump = 255; bump >= 0; bump -= 1) {
|
|
153
|
+
input[bumpAt] = bump;
|
|
154
|
+
const candidate = sha256(input);
|
|
155
|
+
if (!onCurve(candidate)) return decoder.decode(candidate);
|
|
156
|
+
}
|
|
157
|
+
throw new ChainError("invalid-request", "no PDA bump for the associated token account");
|
|
158
|
+
};
|
|
159
|
+
// src/solana/core.ts
|
|
160
|
+
/** Metaplex Core — recognised by program id; the transfer authority is verified on-chain. */
|
|
161
|
+
const MPL_CORE_PROGRAM = "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d";
|
|
162
|
+
/**
|
|
163
|
+
* `MplAssetInstruction::TransferV1` = 14; `TransferV1Args` is `{ compressionProof: Option }` — a
|
|
164
|
+
* bare transfer carries `[14, 0]` (no compression proof). mpl-core IDL at c8732ac.
|
|
165
|
+
*/
|
|
166
|
+
const TRANSFER_V1 = Uint8Array.from([14, 0]);
|
|
167
|
+
/**
|
|
168
|
+
* `TransferV1` with the accounts `[asset, collection, payer, authority, newOwner, systemProgram,
|
|
169
|
+
* logWrapper]` — omitted optionals carry the program id itself (the Shank convention). The
|
|
170
|
+
* authority slot resolves to the payer when it is the placeholder; it must be the signer for the
|
|
171
|
+
* call to count as a transfer the wallet is doing.
|
|
172
|
+
*/
|
|
173
|
+
const decodeCoreIx = (parsed, ix, lookups) => {
|
|
174
|
+
const { data } = ix;
|
|
175
|
+
const account = (i) => {
|
|
176
|
+
const index = ix.accountIndices[i];
|
|
177
|
+
return index === void 0 ? void 0 : resolveAccountIndex(parsed, index, lookups);
|
|
178
|
+
};
|
|
179
|
+
if (data.length !== 2 || data[0] !== TRANSFER_V1[0] || data[1] !== TRANSFER_V1[1]) return;
|
|
180
|
+
const asset = account(0);
|
|
181
|
+
const payer = account(2);
|
|
182
|
+
const authoritySlot = account(3);
|
|
183
|
+
const newOwner = account(4);
|
|
184
|
+
if (asset === void 0 || payer === void 0 || authoritySlot === void 0 || newOwner === void 0) return;
|
|
185
|
+
return {
|
|
186
|
+
authority: authoritySlot === "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d" ? payer : authoritySlot,
|
|
187
|
+
asset,
|
|
188
|
+
newOwner
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
// src/solana/jupiter.ts
|
|
192
|
+
/** Jupiter's swap program — recognised by program id like Lido's upgradeable proxies. */
|
|
193
|
+
const JUPITER_PROGRAM = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
|
194
|
+
const WSOL_MINT = "So11111111111111111111111111111111111111112";
|
|
195
|
+
const ROUTE_V2 = Uint8Array.from([
|
|
196
|
+
187,
|
|
197
|
+
100,
|
|
198
|
+
250,
|
|
199
|
+
204,
|
|
200
|
+
49,
|
|
201
|
+
196,
|
|
202
|
+
175,
|
|
203
|
+
20
|
|
204
|
+
]);
|
|
205
|
+
const SHARED_ROUTE_V2 = Uint8Array.from([
|
|
206
|
+
209,
|
|
207
|
+
152,
|
|
208
|
+
83,
|
|
209
|
+
147,
|
|
210
|
+
124,
|
|
211
|
+
254,
|
|
212
|
+
216,
|
|
213
|
+
233
|
|
214
|
+
]);
|
|
215
|
+
const u16$1 = getU16Decoder();
|
|
216
|
+
const u32$2 = getU32Decoder();
|
|
217
|
+
const u64$3 = getU64Decoder();
|
|
218
|
+
const startsWith = (data, prefix) => data.length >= prefix.length && prefix.every((b, i) => data[i] === b);
|
|
219
|
+
/**
|
|
220
|
+
* `route_v2` / `shared_accounts_route_v2`: the fixed scalar prefix must be exact and the trailing
|
|
221
|
+
* `route_plan` vector must declare enough remaining bytes (each step is ≥ 5 bytes on the wire). The
|
|
222
|
+
* route steps themselves stay opaque — the intent only shows the inputs and the floor.
|
|
223
|
+
*/
|
|
224
|
+
const decodeJupiterIx = (parsed, ix, lookups) => {
|
|
225
|
+
const { data } = ix;
|
|
226
|
+
const account = (i) => {
|
|
227
|
+
const index = ix.accountIndices[i];
|
|
228
|
+
return index === void 0 ? void 0 : resolveAccountIndex(parsed, index, lookups);
|
|
229
|
+
};
|
|
230
|
+
const require = (i) => account(i) ?? "";
|
|
231
|
+
const planWellFormed = (offset) => {
|
|
232
|
+
if (data.length < offset + 4) return false;
|
|
233
|
+
const count = u32$2.decode(data, offset);
|
|
234
|
+
return data.length >= offset + 4 + count * 5;
|
|
235
|
+
};
|
|
236
|
+
const scalars = (o) => ({
|
|
237
|
+
inAmount: u64$3.decode(data, o),
|
|
238
|
+
quotedOut: u64$3.decode(data, o + 8),
|
|
239
|
+
slippageBps: u16$1.decode(data, o + 16),
|
|
240
|
+
platformFeeBps: u16$1.decode(data, o + 18)
|
|
241
|
+
});
|
|
242
|
+
if (startsWith(data, ROUTE_V2)) {
|
|
243
|
+
if (ix.accountIndices.length < 10 || !planWellFormed(30)) return;
|
|
244
|
+
const optionalDest = require(7);
|
|
245
|
+
return {
|
|
246
|
+
authority: require(0),
|
|
247
|
+
sourceMint: require(3),
|
|
248
|
+
destinationMint: require(4),
|
|
249
|
+
destinationTokenProgram: require(6),
|
|
250
|
+
destinationAccount: optionalDest === "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4" ? require(2) : optionalDest,
|
|
251
|
+
...scalars(8)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
if (startsWith(data, SHARED_ROUTE_V2)) {
|
|
255
|
+
if (ix.accountIndices.length < 12 || !planWellFormed(31)) return;
|
|
256
|
+
return {
|
|
257
|
+
authority: require(1),
|
|
258
|
+
sourceMint: require(6),
|
|
259
|
+
destinationMint: require(7),
|
|
260
|
+
destinationTokenProgram: require(9),
|
|
261
|
+
destinationAccount: require(5),
|
|
262
|
+
...scalars(9)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
// src/solana/stake.ts
|
|
267
|
+
/** Sysvars the legacy stake account lists carry; post-SIMD-0490 forms omit them. */
|
|
268
|
+
const SYSVAR_IDS = Object.freeze({
|
|
269
|
+
clock: "SysvarC1ock11111111111111111111111111111111",
|
|
270
|
+
rent: "SysvarRent111111111111111111111111111111111",
|
|
271
|
+
stakeHistory: "SysvarStakeHistory1111111111111111111111111",
|
|
272
|
+
stakeConfig: "StakeConfig11111111111111111111111111111111"
|
|
273
|
+
});
|
|
274
|
+
const ZERO_ADDRESS = "11111111111111111111111111111111";
|
|
275
|
+
const u32$1 = getU32Decoder();
|
|
276
|
+
const u64$2 = getU64Decoder();
|
|
277
|
+
const i64 = getI64Decoder();
|
|
278
|
+
const addr = getAddressEncoder();
|
|
279
|
+
const u32le$1 = (data, offset) => u32$1.decode(data, offset);
|
|
280
|
+
const u64le$1 = (data, offset) => u64$2.decode(data, offset);
|
|
281
|
+
const i64le = (data, offset) => i64.decode(data, offset);
|
|
282
|
+
const key = (data, offset) => solanaAddressFromPublicKey(data.subarray(offset, offset + 32));
|
|
283
|
+
const account = (parsed, ix, index, lookups) => index < ix.accountIndices.length ? resolveAccountIndex(parsed, ix.accountIndices[index] ?? 0, lookups) : void 0;
|
|
284
|
+
const role = (data, offset) => {
|
|
285
|
+
const r = u32le$1(data, offset);
|
|
286
|
+
return r === 0 ? "staker" : r === 1 ? "withdrawer" : "other";
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Decodes one Stake-program instruction — exact data length and an account list matching either the
|
|
290
|
+
* current form or the legacy one (recognised by the sysvar it inserts at a fixed position).
|
|
291
|
+
* Anything else is `undefined` → the whole transaction decodes `opaque`.
|
|
292
|
+
*/
|
|
293
|
+
const decodeStakeIx = (parsed, ix, lookups) => {
|
|
294
|
+
const { data } = ix;
|
|
295
|
+
const acc = (i) => account(parsed, ix, i, lookups);
|
|
296
|
+
const n = ix.accountIndices.length;
|
|
297
|
+
if (data.length < 4) return;
|
|
298
|
+
switch (u32le$1(data, 0)) {
|
|
299
|
+
case 0: {
|
|
300
|
+
if (data.length !== 116 || !(n === 1 || n === 2 && acc(1) === SYSVAR_IDS.rent)) return;
|
|
301
|
+
const stake = acc(0);
|
|
302
|
+
if (stake === void 0) return;
|
|
303
|
+
const lockup = i64le(data, 68) !== 0n || u64le$1(data, 76) !== 0n || key(data, 84) !== ZERO_ADDRESS;
|
|
304
|
+
return {
|
|
305
|
+
kind: "initialize",
|
|
306
|
+
account: stake,
|
|
307
|
+
staker: key(data, 4),
|
|
308
|
+
withdrawer: key(data, 36),
|
|
309
|
+
lockup
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
case 1: {
|
|
313
|
+
if (data.length !== 40) return;
|
|
314
|
+
const r = role(data, 36);
|
|
315
|
+
const legacy = acc(1) === SYSVAR_IDS.clock;
|
|
316
|
+
const stake = acc(0);
|
|
317
|
+
if (r === "other" || stake === void 0 || !(legacy ? n === 3 || n === 4 : n === 2 || n === 3)) return;
|
|
318
|
+
return {
|
|
319
|
+
kind: "authorize",
|
|
320
|
+
account: stake,
|
|
321
|
+
role: r,
|
|
322
|
+
authority: key(data, 4)
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
case 2: {
|
|
326
|
+
const legacy = acc(2) === SYSVAR_IDS.clock;
|
|
327
|
+
const stake = acc(0);
|
|
328
|
+
const vote = acc(1);
|
|
329
|
+
if (data.length !== 4 || stake === void 0 || vote === void 0 || !(n === 3 || n === 6 && legacy && acc(3) === SYSVAR_IDS.stakeHistory && acc(4) === SYSVAR_IDS.stakeConfig)) return;
|
|
330
|
+
return {
|
|
331
|
+
kind: "delegate",
|
|
332
|
+
account: stake,
|
|
333
|
+
validator: vote
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
case 4: {
|
|
337
|
+
const legacy = acc(2) === SYSVAR_IDS.clock && acc(3) === SYSVAR_IDS.stakeHistory;
|
|
338
|
+
const stake = acc(0);
|
|
339
|
+
const to = acc(1);
|
|
340
|
+
if (data.length !== 12 || stake === void 0 || to === void 0 || !(n === 3 || n === 4 || (n === 5 || n === 6) && legacy)) return;
|
|
341
|
+
return {
|
|
342
|
+
kind: "withdraw",
|
|
343
|
+
account: stake,
|
|
344
|
+
to,
|
|
345
|
+
lamports: u64le$1(data, 4)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
case 5: {
|
|
349
|
+
const stake = acc(0);
|
|
350
|
+
if (data.length !== 4 || stake === void 0 || !(n === 2 || n === 3 && acc(1) === SYSVAR_IDS.clock)) return;
|
|
351
|
+
return {
|
|
352
|
+
kind: "deactivate",
|
|
353
|
+
account: stake
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
case 9: {
|
|
357
|
+
const legacy = acc(1) === SYSVAR_IDS.rent;
|
|
358
|
+
const stake = acc(0);
|
|
359
|
+
const staker = acc(legacy ? 2 : 1);
|
|
360
|
+
const withdrawer = acc(legacy ? 3 : 2);
|
|
361
|
+
if (data.length !== 4 || stake === void 0 || staker === void 0 || withdrawer === void 0 || !(n === 3 || n === 4 && legacy)) return;
|
|
362
|
+
return {
|
|
363
|
+
kind: "initialize-checked",
|
|
364
|
+
account: stake,
|
|
365
|
+
staker,
|
|
366
|
+
withdrawer
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
case 10: {
|
|
370
|
+
if (data.length !== 8) return;
|
|
371
|
+
const r = role(data, 4);
|
|
372
|
+
const legacy = acc(1) === SYSVAR_IDS.clock;
|
|
373
|
+
const stake = acc(0);
|
|
374
|
+
const authority = acc(legacy ? 3 : 2);
|
|
375
|
+
if (r === "other" || stake === void 0 || authority === void 0 || !(legacy ? n === 4 || n === 5 : n === 3 || n === 4)) return;
|
|
376
|
+
return {
|
|
377
|
+
kind: "authorize",
|
|
378
|
+
account: stake,
|
|
379
|
+
role: r,
|
|
380
|
+
authority
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
default: return;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* A system-program `CreateAccount` (u32 0) or `CreateAccountWithSeed` (u32 3) whose owner is the
|
|
388
|
+
* Stake program — `undefined` for other owners or any layout deviation. A with-seed creation is
|
|
389
|
+
* only recognised when `to` is the sha256(base ‖ seed ‖ owner) derived address.
|
|
390
|
+
*/
|
|
391
|
+
const decodeStakeCreate = (parsed, ix, lookups) => {
|
|
392
|
+
const { data } = ix;
|
|
393
|
+
const acc = (i) => account(parsed, ix, i, lookups);
|
|
394
|
+
if (data.length < 4) return "other";
|
|
395
|
+
if (u32le$1(data, 0) === 0) {
|
|
396
|
+
if (data.length !== 52 || ix.accountIndices.length !== 2) return "other";
|
|
397
|
+
const from = acc(0);
|
|
398
|
+
const to = acc(1);
|
|
399
|
+
if (from === void 0 || to === void 0) return "other";
|
|
400
|
+
if (key(data, 20) !== PROGRAM_IDS.stake) return "other";
|
|
401
|
+
return {
|
|
402
|
+
kind: "create",
|
|
403
|
+
account: to,
|
|
404
|
+
from,
|
|
405
|
+
lamports: u64le$1(data, 4)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
if (u32le$1(data, 0) === 3) {
|
|
409
|
+
const seedLen = data.length >= 44 ? Number(u64le$1(data, 36)) : -1;
|
|
410
|
+
const end = 92 + seedLen;
|
|
411
|
+
if (seedLen < 0 || seedLen > 32 || data.length !== end) return "other";
|
|
412
|
+
const from = acc(0);
|
|
413
|
+
const to = acc(1);
|
|
414
|
+
if (from === void 0 || to === void 0 || !(ix.accountIndices.length === 2 || ix.accountIndices.length === 3)) return "other";
|
|
415
|
+
const base = key(data, 4);
|
|
416
|
+
if (key(data, end - 32) !== PROGRAM_IDS.stake) return "other";
|
|
417
|
+
if (ix.accountIndices.length === 3 && acc(2) !== base) return "other";
|
|
418
|
+
if (ix.accountIndices.length === 2 && base !== from) return "other";
|
|
419
|
+
const seed = data.subarray(44, 44 + seedLen);
|
|
420
|
+
return to === solanaAddressFromPublicKey(sha256(new Uint8Array([
|
|
421
|
+
...addr.encode(address(base)),
|
|
422
|
+
...seed,
|
|
423
|
+
...addr.encode(address(PROGRAM_IDS.stake))
|
|
424
|
+
]))) ? {
|
|
425
|
+
kind: "create",
|
|
426
|
+
account: to,
|
|
427
|
+
from,
|
|
428
|
+
lamports: u64le$1(data, 44 + seedLen)
|
|
429
|
+
} : "other";
|
|
430
|
+
}
|
|
431
|
+
};
|
|
119
432
|
// src/solana/tokens.ts
|
|
120
433
|
const USDC = Object.freeze({
|
|
121
434
|
symbol: "USDC",
|
|
@@ -141,15 +454,21 @@ const u64le = (data, offset) => u64$1.decode(data, offset);
|
|
|
141
454
|
* Classifies one instruction by program + discriminator/layout. Exact-length checks keep
|
|
142
455
|
* non-canonical encodings out of the `full` class.
|
|
143
456
|
*/
|
|
144
|
-
const classifyIx = (parsed, ix, lookups) => {
|
|
457
|
+
const classifyIx = (parsed, ix, lookups, signer) => {
|
|
145
458
|
const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);
|
|
146
459
|
const { data } = ix;
|
|
147
460
|
if (program === PROGRAM_IDS.system) {
|
|
148
461
|
if (data.length === 12 && u32le(data, 0) === 2) return {
|
|
149
462
|
kind: "system-transfer",
|
|
463
|
+
from: resolveAccountIndex(parsed, ix.accountIndices[0] ?? 0, lookups),
|
|
150
464
|
to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),
|
|
151
465
|
amount: u64le(data, 4)
|
|
152
466
|
};
|
|
467
|
+
const create = decodeStakeCreate(parsed, ix, lookups);
|
|
468
|
+
if (create !== void 0 && create !== "other") return {
|
|
469
|
+
kind: "system-create",
|
|
470
|
+
stake: create
|
|
471
|
+
};
|
|
153
472
|
return { kind: "other" };
|
|
154
473
|
}
|
|
155
474
|
if (program === PROGRAM_IDS.computeBudget) {
|
|
@@ -181,27 +500,53 @@ const classifyIx = (parsed, ix, lookups) => {
|
|
|
181
500
|
amount: u64le(data, 1),
|
|
182
501
|
to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups)
|
|
183
502
|
};
|
|
503
|
+
if (data.length === 1 && data[0] === 17) return { kind: "token-sync-native" };
|
|
504
|
+
if (data.length === 1 && data[0] === 9) return resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups) === signer ? { kind: "token-close-account" } : { kind: "other" };
|
|
184
505
|
return { kind: "other" };
|
|
185
506
|
}
|
|
186
|
-
if (program ===
|
|
507
|
+
if (program === "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4") {
|
|
508
|
+
const jupiter = decodeJupiterIx(parsed, ix, lookups);
|
|
509
|
+
return jupiter !== void 0 && jupiter.authority === signer ? {
|
|
510
|
+
kind: "jupiter",
|
|
511
|
+
jupiter
|
|
512
|
+
} : { kind: "other" };
|
|
513
|
+
}
|
|
514
|
+
if (program === "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d") {
|
|
515
|
+
const core = decodeCoreIx(parsed, ix, lookups);
|
|
516
|
+
return core !== void 0 && core.authority === signer ? {
|
|
517
|
+
kind: "core-transfer",
|
|
518
|
+
core
|
|
519
|
+
} : { kind: "other" };
|
|
520
|
+
}
|
|
521
|
+
if (program === PROGRAM_IDS.stake) {
|
|
522
|
+
const stake = decodeStakeIx(parsed, ix, lookups);
|
|
523
|
+
return stake === void 0 ? { kind: "other" } : {
|
|
524
|
+
kind: "stake",
|
|
525
|
+
stake
|
|
526
|
+
};
|
|
527
|
+
}
|
|
187
528
|
return { kind: "other" };
|
|
188
529
|
};
|
|
189
530
|
const FULL_KINDS = /* @__PURE__ */ new Set([
|
|
190
531
|
"system-transfer",
|
|
532
|
+
"system-create",
|
|
191
533
|
"cu-limit",
|
|
192
534
|
"cu-price",
|
|
193
535
|
"ata-create",
|
|
194
|
-
"ata-create-idempotent"
|
|
536
|
+
"ata-create-idempotent",
|
|
537
|
+
"stake",
|
|
538
|
+
"token-sync-native",
|
|
539
|
+
"token-close-account"
|
|
195
540
|
]);
|
|
196
541
|
const classify = (parsed, calls, network, table) => {
|
|
197
|
-
if (parsed.lookups.length > 0) return "partial";
|
|
198
542
|
let allFull = true;
|
|
199
543
|
for (const call of calls) {
|
|
200
544
|
if (call.kind === "other") return "opaque";
|
|
201
|
-
if (call.kind === "token-approve" || call.kind === "
|
|
545
|
+
if (call.kind === "token-approve" || call.kind === "jupiter" || call.kind === "core-transfer") allFull = false;
|
|
202
546
|
if (call.kind === "token-transfer-checked" && lookupSolanaToken(table, network, call.mint ?? "") === void 0) allFull = false;
|
|
203
|
-
if (!FULL_KINDS.has(call.kind) && call.kind !== "token-transfer-checked" && call.kind !== "token-approve" && call.kind !== "
|
|
547
|
+
if (!FULL_KINDS.has(call.kind) && call.kind !== "token-transfer-checked" && call.kind !== "token-approve" && call.kind !== "jupiter" && call.kind !== "core-transfer") return "opaque";
|
|
204
548
|
}
|
|
549
|
+
if (parsed.lookups.length > 0) return "partial";
|
|
205
550
|
return allFull ? "full" : "partial";
|
|
206
551
|
};
|
|
207
552
|
const feeLamports = (parsed, calls) => {
|
|
@@ -216,14 +561,21 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
216
561
|
address: t.address,
|
|
217
562
|
addresses: t.addresses
|
|
218
563
|
}));
|
|
219
|
-
const calls = parsed.instructions.map((ix) => classifyIx(parsed, ix, lookups));
|
|
564
|
+
const calls = parsed.instructions.map((ix) => classifyIx(parsed, ix, lookups, signer));
|
|
220
565
|
const verifiability = classify(parsed, calls, request.network, table);
|
|
221
566
|
const outflows = [];
|
|
222
567
|
const approvals = [];
|
|
568
|
+
const staking = [];
|
|
569
|
+
const warnings = [];
|
|
570
|
+
const minimumReceived = [];
|
|
571
|
+
const wsolAtas = /* @__PURE__ */ new Set([associatedTokenAddress(signer, WSOL_MINT, PROGRAM_IDS.token), associatedTokenAddress(signer, WSOL_MINT, PROGRAM_IDS.token2022)]);
|
|
572
|
+
let otherTransfer = false;
|
|
573
|
+
let hasJupiter = false;
|
|
223
574
|
for (const call of calls) {
|
|
224
|
-
if (call.kind === "system-transfer" && call.to !== void 0) {
|
|
225
|
-
|
|
226
|
-
|
|
575
|
+
if (call.kind === "system-transfer" && call.to !== void 0 && call.from === signer) {
|
|
576
|
+
if (wsolAtas.has(call.to)) continue;
|
|
577
|
+
otherTransfer = true;
|
|
578
|
+
outflows.push({
|
|
227
579
|
to: call.to,
|
|
228
580
|
amount: {
|
|
229
581
|
asset: SOLANA_NATIVE_ASSET,
|
|
@@ -232,7 +584,61 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
232
584
|
verified: true
|
|
233
585
|
});
|
|
234
586
|
}
|
|
587
|
+
if (call.kind === "jupiter" && call.jupiter !== void 0) {
|
|
588
|
+
const swap = call.jupiter;
|
|
589
|
+
hasJupiter = true;
|
|
590
|
+
otherTransfer = true;
|
|
591
|
+
const sell = lookupSolanaToken(table, request.network, swap.sourceMint);
|
|
592
|
+
outflows.push({
|
|
593
|
+
to: JUPITER_PROGRAM,
|
|
594
|
+
amount: swap.sourceMint === "So11111111111111111111111111111111111111112" ? {
|
|
595
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
596
|
+
amount: swap.inAmount.toString(10)
|
|
597
|
+
} : {
|
|
598
|
+
asset: swap.sourceMint,
|
|
599
|
+
amount: swap.inAmount.toString(10),
|
|
600
|
+
...sell === void 0 ? {} : {
|
|
601
|
+
symbol: sell.symbol,
|
|
602
|
+
decimals: sell.decimals
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
verified: swap.sourceMint === "So11111111111111111111111111111111111111112" || sell !== void 0
|
|
606
|
+
});
|
|
607
|
+
const minimum = (swap.quotedOut * BigInt(1e4 - swap.slippageBps) + 9999n) / 10000n;
|
|
608
|
+
const buy = lookupSolanaToken(table, request.network, swap.destinationMint);
|
|
609
|
+
const destAta = associatedTokenAddress(signer, swap.destinationMint, swap.destinationTokenProgram);
|
|
610
|
+
minimumReceived.push({
|
|
611
|
+
to: swap.destinationAccount === destAta ? signer : swap.destinationAccount,
|
|
612
|
+
amount: swap.destinationMint === "So11111111111111111111111111111111111111112" ? {
|
|
613
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
614
|
+
amount: minimum.toString(10)
|
|
615
|
+
} : {
|
|
616
|
+
asset: swap.destinationMint,
|
|
617
|
+
amount: minimum.toString(10),
|
|
618
|
+
...buy === void 0 ? {} : {
|
|
619
|
+
symbol: buy.symbol,
|
|
620
|
+
decimals: buy.decimals
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
if (swap.platformFeeBps > 0) warnings.push({
|
|
625
|
+
kind: "platform-fee",
|
|
626
|
+
message: `${swap.platformFeeBps} bps`
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
if (call.kind === "core-transfer" && call.core !== void 0) {
|
|
630
|
+
otherTransfer = true;
|
|
631
|
+
outflows.push({
|
|
632
|
+
to: call.core.newOwner,
|
|
633
|
+
amount: {
|
|
634
|
+
asset: call.core.asset,
|
|
635
|
+
amount: "1"
|
|
636
|
+
},
|
|
637
|
+
verified: false
|
|
638
|
+
});
|
|
639
|
+
}
|
|
235
640
|
if (call.kind === "token-transfer-checked") {
|
|
641
|
+
otherTransfer = true;
|
|
236
642
|
const token = lookupSolanaToken(table, request.network, call.mint ?? "");
|
|
237
643
|
outflows.push({
|
|
238
644
|
to: call.to ?? "",
|
|
@@ -265,19 +671,97 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
265
671
|
verified: token !== void 0
|
|
266
672
|
});
|
|
267
673
|
}
|
|
674
|
+
const { stake } = call;
|
|
675
|
+
if (stake !== void 0) switch (stake.kind) {
|
|
676
|
+
case "create":
|
|
677
|
+
staking.push({
|
|
678
|
+
kind: "create",
|
|
679
|
+
account: stake.account,
|
|
680
|
+
lamports: stake.lamports.toString(10)
|
|
681
|
+
});
|
|
682
|
+
if (stake.from === signer) outflows.push({
|
|
683
|
+
to: stake.account,
|
|
684
|
+
amount: {
|
|
685
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
686
|
+
amount: stake.lamports.toString(10)
|
|
687
|
+
},
|
|
688
|
+
verified: true
|
|
689
|
+
});
|
|
690
|
+
break;
|
|
691
|
+
case "initialize":
|
|
692
|
+
case "initialize-checked":
|
|
693
|
+
if (stake.staker !== signer) approvals.push({
|
|
694
|
+
kind: "stake-authority",
|
|
695
|
+
account: stake.account,
|
|
696
|
+
role: "staker",
|
|
697
|
+
authority: stake.staker,
|
|
698
|
+
verified: false
|
|
699
|
+
});
|
|
700
|
+
if (stake.withdrawer !== signer) approvals.push({
|
|
701
|
+
kind: "stake-authority",
|
|
702
|
+
account: stake.account,
|
|
703
|
+
role: "withdrawer",
|
|
704
|
+
authority: stake.withdrawer,
|
|
705
|
+
verified: false
|
|
706
|
+
});
|
|
707
|
+
if (stake.kind === "initialize" && stake.lockup) warnings.push({
|
|
708
|
+
kind: "stake-lockup",
|
|
709
|
+
message: "the stake account is locked — funds cannot move until the lockup expires"
|
|
710
|
+
});
|
|
711
|
+
break;
|
|
712
|
+
case "delegate":
|
|
713
|
+
staking.push({
|
|
714
|
+
kind: "delegate",
|
|
715
|
+
account: stake.account,
|
|
716
|
+
validator: stake.validator
|
|
717
|
+
});
|
|
718
|
+
break;
|
|
719
|
+
case "deactivate":
|
|
720
|
+
staking.push({
|
|
721
|
+
kind: "deactivate",
|
|
722
|
+
account: stake.account
|
|
723
|
+
});
|
|
724
|
+
break;
|
|
725
|
+
case "withdraw":
|
|
726
|
+
staking.push({
|
|
727
|
+
kind: "withdraw",
|
|
728
|
+
account: stake.account,
|
|
729
|
+
to: stake.to,
|
|
730
|
+
lamports: stake.lamports.toString(10)
|
|
731
|
+
});
|
|
732
|
+
if (stake.to !== signer) outflows.push({
|
|
733
|
+
to: stake.to,
|
|
734
|
+
amount: {
|
|
735
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
736
|
+
amount: stake.lamports.toString(10)
|
|
737
|
+
},
|
|
738
|
+
verified: true
|
|
739
|
+
});
|
|
740
|
+
break;
|
|
741
|
+
case "authorize": if (stake.authority !== signer) approvals.push({
|
|
742
|
+
kind: "stake-authority",
|
|
743
|
+
account: stake.account,
|
|
744
|
+
role: stake.role,
|
|
745
|
+
authority: stake.authority,
|
|
746
|
+
verified: false
|
|
747
|
+
});
|
|
748
|
+
}
|
|
268
749
|
}
|
|
269
750
|
const fee = feeLamports(parsed, calls);
|
|
751
|
+
const summary = hasJupiter ? "swap" : otherTransfer ? "transfer" : staking.length > 0 ? "stake" : outflows.length > 0 ? "transfer" : "contract-call";
|
|
270
752
|
return {
|
|
271
753
|
family: "solana",
|
|
272
754
|
network: request.network,
|
|
273
|
-
summary
|
|
755
|
+
summary,
|
|
274
756
|
outflows,
|
|
275
757
|
approvals,
|
|
276
758
|
fee: fee === void 0 ? void 0 : { max: {
|
|
277
759
|
asset: SOLANA_NATIVE_ASSET,
|
|
278
760
|
amount: fee.toString(10)
|
|
279
761
|
} },
|
|
280
|
-
|
|
762
|
+
...staking.length === 0 ? {} : { staking },
|
|
763
|
+
...minimumReceived.length === 0 ? {} : { minimumReceived },
|
|
764
|
+
warnings,
|
|
281
765
|
verifiability
|
|
282
766
|
};
|
|
283
767
|
};
|
|
@@ -443,6 +927,6 @@ const normalizeSolana = (request, signer) => {
|
|
|
443
927
|
}
|
|
444
928
|
throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
|
|
445
929
|
};
|
|
446
|
-
export { EXT, PROGRAM_IDS, SOLANA_NATIVE_ASSET, SOLANA_NETWORKS, decodeSolana, isSolanaAddress, netAfterTransferFee, normalizeSolana, parseCompiledMessage, parseMintExtensions, solanaAddressFromPublicKey, solanaTokenTable, verifiabilitySolana, verifySolanaSignature };
|
|
930
|
+
export { EXT, JUPITER_PROGRAM, MPL_CORE_PROGRAM, PROGRAM_IDS, SOLANA_NATIVE_ASSET, SOLANA_NETWORKS, WSOL_MINT, associatedTokenAddress, decodeCoreIx, decodeSolana, isSolanaAddress, netAfterTransferFee, normalizeSolana, parseCompiledMessage, parseMintExtensions, solanaAddressFromPublicKey, solanaTokenTable, verifiabilitySolana, verifySolanaSignature };
|
|
447
931
|
|
|
448
932
|
//# sourceMappingURL=solana.mjs.map
|