@qntx/wallet-chains 0.13.0 → 0.14.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/README.md +13 -10
- package/dist/{account-ref-D2rW_qlI.mjs → account-ref-BFTeEyHt.mjs} +2 -2
- package/dist/{account-ref-D2rW_qlI.mjs.map → account-ref-BFTeEyHt.mjs.map} +1 -1
- package/dist/assemble-8GvNDony.mjs +405 -0
- package/dist/assemble-8GvNDony.mjs.map +1 -0
- package/dist/assemble-B3sO9Fvc.mjs +629 -0
- package/dist/assemble-B3sO9Fvc.mjs.map +1 -0
- package/dist/assemble-BdiPo0ZX.mjs +32 -0
- package/dist/assemble-BdiPo0ZX.mjs.map +1 -0
- package/dist/assets-sg2_Z3nZ.mjs +200 -0
- package/dist/assets-sg2_Z3nZ.mjs.map +1 -0
- package/dist/bitcoin-sign.d.mts +3 -0
- package/dist/bitcoin-sign.mjs +52 -18
- package/dist/bitcoin-sign.mjs.map +1 -1
- package/dist/bitcoin.d.mts +123 -7
- package/dist/bitcoin.mjs +162 -69
- package/dist/bitcoin.mjs.map +1 -1
- package/dist/evm-sign.d.mts +3 -1
- package/dist/evm-sign.mjs +25 -108
- package/dist/evm-sign.mjs.map +1 -1
- package/dist/evm.d.mts +152 -28
- package/dist/evm.mjs +2216 -753
- package/dist/evm.mjs.map +1 -1
- package/dist/families-BlgplKAJ.mjs +412 -0
- package/dist/families-BlgplKAJ.mjs.map +1 -0
- package/dist/index-CIRaHKpx.d.mts +941 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/networks.d.mts +29 -0
- package/dist/networks.mjs +245 -0
- package/dist/networks.mjs.map +1 -0
- package/dist/plan-wCnxHqRu.mjs +1311 -0
- package/dist/plan-wCnxHqRu.mjs.map +1 -0
- package/dist/solana-sign.d.mts +3 -0
- package/dist/solana-sign.mjs +23 -10
- package/dist/solana-sign.mjs.map +1 -1
- package/dist/solana.d.mts +117 -34
- package/dist/solana.mjs +796 -99
- package/dist/solana.mjs.map +1 -1
- package/dist/src-CHB_z45M.mjs +387 -0
- package/dist/src-CHB_z45M.mjs.map +1 -0
- package/dist/tasks-7AFv3PQn.mjs +86 -0
- package/dist/tasks-7AFv3PQn.mjs.map +1 -0
- package/dist/token-call-DH22g8BL.mjs +914 -0
- package/dist/token-call-DH22g8BL.mjs.map +1 -0
- package/dist/tron-sign.d.mts +10 -0
- package/dist/tron-sign.mjs +36 -0
- package/dist/tron-sign.mjs.map +1 -0
- package/dist/tron.d.mts +328 -0
- package/dist/tron.mjs +1484 -0
- package/dist/tron.mjs.map +1 -0
- package/dist/typed-data-CE9h4U0F.d.mts +51 -0
- package/dist/{typed-data-B4PJ1v8F.mjs → typed-data-DRtKULsH.mjs} +158 -10
- package/dist/typed-data-DRtKULsH.mjs.map +1 -0
- package/package.json +17 -10
- package/dist/index-DpL5hvPl.d.mts +0 -354
- package/dist/message-zf3XHwwc.mjs +0 -188
- package/dist/message-zf3XHwwc.mjs.map +0 -1
- package/dist/src-8NZeEnrW.mjs +0 -67
- package/dist/src-8NZeEnrW.mjs.map +0 -1
- package/dist/typed-data-B4PJ1v8F.mjs.map +0 -1
package/dist/solana.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { t as ChainError } from "./src-
|
|
2
|
-
import { n as requestBase, t as isRecord$1 } from "./account-ref-
|
|
1
|
+
import { t as ChainError } from "./src-CHB_z45M.mjs";
|
|
2
|
+
import { n as requestBase, t as isRecord$1 } from "./account-ref-BFTeEyHt.mjs";
|
|
3
|
+
import { withNativeAmountMeta } from "./networks.mjs";
|
|
4
|
+
import { t as RECOGNISED_FAMILIES } from "./families-BlgplKAJ.mjs";
|
|
5
|
+
import { n as planSolana, t as assembleSolana } from "./assemble-BdiPo0ZX.mjs";
|
|
6
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
3
7
|
import { address, getAddressDecoder, getAddressEncoder } from "@solana/addresses";
|
|
4
8
|
import { getCompiledTransactionMessageDecoder } from "@solana/transaction-messages";
|
|
5
9
|
import { getI64Decoder, getU16Decoder, getU32Decoder, getU64Decoder } from "@solana/codecs";
|
|
6
|
-
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
7
10
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
11
|
+
import { getTransactionDecoder } from "@solana/transactions";
|
|
8
12
|
// src/solana/ids.ts
|
|
9
13
|
/** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */
|
|
10
14
|
const PROGRAM_IDS = Object.freeze({
|
|
@@ -13,7 +17,10 @@ const PROGRAM_IDS = Object.freeze({
|
|
|
13
17
|
associatedToken: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
14
18
|
token: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
15
19
|
token2022: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
|
|
16
|
-
stake: "Stake11111111111111111111111111111111111111"
|
|
20
|
+
stake: "Stake11111111111111111111111111111111111111",
|
|
21
|
+
ed25519: "Ed25519SigVerify111111111111111111111111111",
|
|
22
|
+
secp256k1: "KeccakSecp256k11111111111111111111111111111",
|
|
23
|
+
secp256r1: "Secp256r1SigVerify1111111111111111111111111"
|
|
17
24
|
});
|
|
18
25
|
/**
|
|
19
26
|
* CAIP-2 ids the wallet knows. The wire message itself carries no network marker — `network` is the
|
|
@@ -28,27 +35,60 @@ function solanaAddressFromPublicKey(pubkey) {
|
|
|
28
35
|
if (pubkey.length !== 32) throw new ChainError("invalid-address", "expected a 32-byte ed25519 public key");
|
|
29
36
|
return decoder$2.decode(pubkey);
|
|
30
37
|
}
|
|
38
|
+
// src/solana/message.ts
|
|
39
|
+
const LEGACY_TRANSACTION_MAX_BYTES = 1232;
|
|
40
|
+
const V1_TRANSACTION_MAX_BYTES = 4096;
|
|
31
41
|
const decoder$1 = getCompiledTransactionMessageDecoder();
|
|
42
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
43
|
+
/**
|
|
44
|
+
* Whether a cluster could accept `bytes` as the message of a transaction — signing them as a raw
|
|
45
|
+
* message would authorise it.
|
|
46
|
+
*/
|
|
47
|
+
const mayBeTransactionMessage = (bytes) => {
|
|
48
|
+
const [first] = bytes;
|
|
49
|
+
if (first === void 0 || first === 255) return false;
|
|
50
|
+
if (first >= 128) try {
|
|
51
|
+
utf8.decode(bytes);
|
|
52
|
+
return false;
|
|
53
|
+
} catch {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const [, end] = decoder$1.read(bytes, 0);
|
|
58
|
+
return end === bytes.length;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
32
63
|
/**
|
|
33
|
-
* Decodes a compiled wire message; rejects trailing bytes and the
|
|
34
|
-
* fee payer is `staticAccounts[0]` — every valid
|
|
64
|
+
* Decodes a compiled wire message; rejects trailing bytes and the transaction size limit (1232 for
|
|
65
|
+
* legacy/v0, 4096 including signatures for v1). The fee payer is `staticAccounts[0]` — every valid
|
|
66
|
+
* transaction signs it.
|
|
35
67
|
*/
|
|
36
68
|
const parseCompiledMessage = (bytes) => {
|
|
69
|
+
const [first] = bytes;
|
|
70
|
+
if (first === void 0) throw new ChainError("invalid-request", "compiled message is empty");
|
|
71
|
+
if (first === 129) return parseV1Message(bytes);
|
|
72
|
+
if (first > 129) throw new ChainError("unsupported", `Solana transaction version ${first - 128} is not supported`);
|
|
37
73
|
if (bytes.length > 1232) throw new ChainError("invalid-request", "compiled message exceeds the 1232-byte limit");
|
|
38
|
-
if (bytes.length === 0) throw new ChainError("invalid-request", "compiled message is empty");
|
|
39
74
|
let decoded;
|
|
75
|
+
let end;
|
|
40
76
|
try {
|
|
41
|
-
decoded = decoder$1.
|
|
77
|
+
[decoded, end] = decoder$1.read(bytes, 0);
|
|
42
78
|
} catch {
|
|
43
79
|
throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
44
80
|
}
|
|
81
|
+
if (end !== bytes.length) throw new ChainError("invalid-request", "compiled message has trailing bytes");
|
|
45
82
|
const message = asCompiledMessage(decoded);
|
|
46
83
|
const staticAccounts = [...message.staticAccounts];
|
|
47
84
|
const lookups = message.addressTableLookups;
|
|
48
85
|
return {
|
|
49
86
|
version: message.version,
|
|
50
87
|
numRequiredSignatures: message.numSignerAccounts,
|
|
88
|
+
numReadonlySignerAccounts: message.numReadonlySignerAccounts,
|
|
89
|
+
numReadonlyNonSignerAccounts: message.numReadonlyNonSignerAccounts,
|
|
51
90
|
staticAccounts,
|
|
91
|
+
lifetimeToken: message.lifetimeToken,
|
|
52
92
|
instructions: message.instructions,
|
|
53
93
|
lookups: lookups.map((l) => ({
|
|
54
94
|
address: l.lookupTableAddress,
|
|
@@ -60,8 +100,7 @@ const parseCompiledMessage = (bytes) => {
|
|
|
60
100
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
61
101
|
const isStringArray = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
62
102
|
const isNumberArray = (value) => Array.isArray(value) && value.every((v) => typeof v === "number");
|
|
63
|
-
const
|
|
64
|
-
const isIx = (value) => isRecord(value) && typeof value["programAddressIndex"] === "number" && (value["accountIndices"] === void 0 || isNumberArray(value["accountIndices"]) || isArrayLike(value["accountIndices"])) && value["data"] instanceof Uint8Array;
|
|
103
|
+
const isIx = (value) => isRecord(value) && typeof value["programAddressIndex"] === "number" && (value["accountIndices"] === void 0 || isNumberArray(value["accountIndices"]) || value["accountIndices"] instanceof Uint8Array) && (value["data"] === void 0 || value["data"] instanceof Uint8Array);
|
|
65
104
|
const isLookup = (value) => isRecord(value) && typeof value["lookupTableAddress"] === "string" && (isNumberArray(value["readonlyIndexes"]) || value["readonlyIndexes"] instanceof Uint8Array) && (isNumberArray(value["writableIndexes"]) || value["writableIndexes"] instanceof Uint8Array);
|
|
66
105
|
const asCompiledMessage = (value) => {
|
|
67
106
|
if (!isRecord(value) || !isRecord(value["header"])) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
@@ -69,15 +108,18 @@ const asCompiledMessage = (value) => {
|
|
|
69
108
|
const { staticAccounts } = value;
|
|
70
109
|
const { instructions } = value;
|
|
71
110
|
const lookups = value["addressTableLookups"];
|
|
72
|
-
|
|
73
|
-
|
|
111
|
+
const { lifetimeToken } = value;
|
|
112
|
+
if (typeof header["numSignerAccounts"] !== "number" || typeof header["numReadonlySignerAccounts"] !== "number" || typeof header["numReadonlyNonSignerAccounts"] !== "number" || !isStringArray(staticAccounts) || typeof lifetimeToken !== "string" || !Array.isArray(instructions) || !instructions.every(isIx) || lookups !== void 0 && (!Array.isArray(lookups) || !lookups.every(isLookup))) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
113
|
+
const versionField = value["version"];
|
|
114
|
+
if (versionField !== "legacy" && versionField !== 0) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
115
|
+
const version = versionField;
|
|
74
116
|
const ixs = instructions.map((ix) => {
|
|
75
117
|
if (!isIx(ix)) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
76
118
|
const indices = ix.accountIndices;
|
|
77
119
|
return {
|
|
78
120
|
programAddressIndex: ix.programAddressIndex,
|
|
79
121
|
accountIndices: indices === void 0 ? [] : [...indices],
|
|
80
|
-
data: ix.data
|
|
122
|
+
data: ix.data ?? /* @__PURE__ */ new Uint8Array(0)
|
|
81
123
|
};
|
|
82
124
|
});
|
|
83
125
|
const tables = (lookups ?? []).map((t) => {
|
|
@@ -91,11 +133,144 @@ const asCompiledMessage = (value) => {
|
|
|
91
133
|
return {
|
|
92
134
|
version,
|
|
93
135
|
numSignerAccounts: header["numSignerAccounts"],
|
|
136
|
+
numReadonlySignerAccounts: header["numReadonlySignerAccounts"],
|
|
137
|
+
numReadonlyNonSignerAccounts: header["numReadonlyNonSignerAccounts"],
|
|
94
138
|
staticAccounts,
|
|
139
|
+
lifetimeToken,
|
|
95
140
|
instructions: ixs,
|
|
96
141
|
addressTableLookups: tables
|
|
97
142
|
};
|
|
98
143
|
};
|
|
144
|
+
const V1_MESSAGE_MIN_BYTES = 42;
|
|
145
|
+
const V1_PRIORITY_FEE_BITS = 3;
|
|
146
|
+
const V1_MAX_SIGNATURES = 12;
|
|
147
|
+
const V1_MAX_ACCOUNTS = 64;
|
|
148
|
+
const V1_MAX_INSTRUCTIONS = 64;
|
|
149
|
+
const V1_HEAP_MIN = 32768;
|
|
150
|
+
const V1_HEAP_MAX = 262144;
|
|
151
|
+
const V1_HEAP_MULTIPLE = 1024;
|
|
152
|
+
const isV1InstructionHeader = (value) => isRecord(value) && typeof value["programAccountIndex"] === "number" && typeof value["numInstructionAccounts"] === "number" && typeof value["numInstructionDataBytes"] === "number";
|
|
153
|
+
const isV1InstructionPayload = (value) => isRecord(value) && (isNumberArray(value["instructionAccountIndices"]) || value["instructionAccountIndices"] instanceof Uint8Array) && value["instructionData"] instanceof Uint8Array;
|
|
154
|
+
const asV1Message = (value) => {
|
|
155
|
+
if (!isRecord(value) || !isRecord(value["header"])) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
156
|
+
const { header } = value;
|
|
157
|
+
const { staticAccounts } = value;
|
|
158
|
+
const headers = value["instructionHeaders"];
|
|
159
|
+
const payloads = value["instructionPayloads"];
|
|
160
|
+
if (value["version"] !== 1 || typeof header["numSignerAccounts"] !== "number" || typeof header["numReadonlySignerAccounts"] !== "number" || typeof header["numReadonlyNonSignerAccounts"] !== "number" || typeof value["lifetimeToken"] !== "string" || !isStringArray(staticAccounts) || !Array.isArray(headers) || !Array.isArray(payloads)) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
161
|
+
const instructions = headers.map((h, i) => {
|
|
162
|
+
const payload = payloads[i];
|
|
163
|
+
if (!isV1InstructionHeader(h) || !isV1InstructionPayload(payload)) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
164
|
+
return {
|
|
165
|
+
programAccountIndex: h.programAccountIndex,
|
|
166
|
+
accountIndices: payload.instructionAccountIndices,
|
|
167
|
+
data: payload.instructionData
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
version: 1,
|
|
172
|
+
header: {
|
|
173
|
+
numSignerAccounts: header["numSignerAccounts"],
|
|
174
|
+
numReadonlySignerAccounts: header["numReadonlySignerAccounts"],
|
|
175
|
+
numReadonlyNonSignerAccounts: header["numReadonlyNonSignerAccounts"]
|
|
176
|
+
},
|
|
177
|
+
instructions,
|
|
178
|
+
lifetimeToken: value["lifetimeToken"],
|
|
179
|
+
staticAccounts
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
const v1Config = (mask, bytes, staticAccountCount) => {
|
|
183
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset + 42 + 32 * staticAccountCount);
|
|
184
|
+
let offset = 0;
|
|
185
|
+
const config = {};
|
|
186
|
+
if ((mask & V1_PRIORITY_FEE_BITS) !== 0) {
|
|
187
|
+
config.priorityFeeLamports = view.getBigUint64(offset, true);
|
|
188
|
+
offset += 8;
|
|
189
|
+
}
|
|
190
|
+
if ((mask & 4) !== 0) {
|
|
191
|
+
config.computeUnitLimit = view.getUint32(offset, true);
|
|
192
|
+
offset += 4;
|
|
193
|
+
}
|
|
194
|
+
if ((mask & 8) !== 0) {
|
|
195
|
+
config.loadedAccountsDataSizeLimit = view.getUint32(offset, true);
|
|
196
|
+
offset += 4;
|
|
197
|
+
}
|
|
198
|
+
if ((mask & 16) !== 0) config.heapSize = view.getUint32(offset, true);
|
|
199
|
+
return config;
|
|
200
|
+
};
|
|
201
|
+
const sanitizeV1Message = (message, config) => {
|
|
202
|
+
const { numSignerAccounts: signatures, numReadonlySignerAccounts: readonlySigners, numReadonlyNonSignerAccounts: readonlyNonSigners } = message.header;
|
|
203
|
+
const accounts = message.staticAccounts.length;
|
|
204
|
+
if (signatures < 1 || signatures > V1_MAX_SIGNATURES) throw new ChainError("invalid-request", `v1 message requires ${signatures} signatures (1–12 allowed)`);
|
|
205
|
+
if (readonlySigners >= signatures) throw new ChainError("invalid-request", `v1 message marks ${readonlySigners} of ${signatures} signers read-only`);
|
|
206
|
+
if (accounts > V1_MAX_ACCOUNTS) throw new ChainError("invalid-request", `v1 message declares ${accounts} accounts (64 allowed)`);
|
|
207
|
+
if (accounts < signatures + readonlyNonSigners) throw new ChainError("invalid-request", `v1 message has ${accounts} accounts for ${signatures} signers and ${readonlyNonSigners} read-only non-signers`);
|
|
208
|
+
if (message.instructions.length > V1_MAX_INSTRUCTIONS) throw new ChainError("invalid-request", `v1 message declares ${message.instructions.length} instructions (64 allowed)`);
|
|
209
|
+
const seen = /* @__PURE__ */ new Set();
|
|
210
|
+
for (const account of message.staticAccounts) {
|
|
211
|
+
if (seen.has(account)) throw new ChainError("invalid-request", `v1 message repeats account ${account}`);
|
|
212
|
+
seen.add(account);
|
|
213
|
+
}
|
|
214
|
+
for (const [i, instruction] of message.instructions.entries()) {
|
|
215
|
+
if (instruction.programAccountIndex === 0) throw new ChainError("invalid-request", `v1 instruction ${i} uses the fee payer as its program`);
|
|
216
|
+
if (instruction.programAccountIndex >= accounts) throw new ChainError("invalid-request", `v1 instruction ${i} uses program index ${instruction.programAccountIndex} of ${accounts} accounts`);
|
|
217
|
+
for (const index of instruction.accountIndices) if (index >= accounts) throw new ChainError("invalid-request", `v1 instruction ${i} uses account index ${index} of ${accounts} accounts`);
|
|
218
|
+
}
|
|
219
|
+
const heap = config.heapSize;
|
|
220
|
+
if (heap !== void 0 && (heap % V1_HEAP_MULTIPLE !== 0 || heap < V1_HEAP_MIN || heap > V1_HEAP_MAX)) throw new ChainError("invalid-request", `v1 heap size ${heap} is not a multiple of 1024 within 32768–262144`);
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* A v1 message: the mask is checked before kit decodes — kit reads only the bits it knows, so an
|
|
224
|
+
* unknown bit or a half priority-fee pair must be caught here. The size bound covers the whole
|
|
225
|
+
* transaction (message plus 64 bytes per required signature), then every Agave sanitize rule runs
|
|
226
|
+
* before the message maps onto the same model as legacy/v0.
|
|
227
|
+
*/
|
|
228
|
+
const parseV1Message = (bytes) => {
|
|
229
|
+
if (bytes.length < V1_MESSAGE_MIN_BYTES) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
230
|
+
const mask = new DataView(bytes.buffer, bytes.byteOffset + 4, 4).getUint32(0, true);
|
|
231
|
+
if ((mask & -32) !== 0) throw new ChainError("unsupported", `Solana v1 transaction config mask 0x${mask.toString(16)} sets bits this wallet does not know`);
|
|
232
|
+
if ((mask & V1_PRIORITY_FEE_BITS) !== 0 && (mask & V1_PRIORITY_FEE_BITS) !== V1_PRIORITY_FEE_BITS) throw new ChainError("invalid-request", "Solana v1 transaction config mask sets only one of the two priority-fee bits");
|
|
233
|
+
if (bytes.length + 64 * (bytes[1] ?? 0) > 4096) throw new ChainError("invalid-request", "v1 transaction exceeds the 4096-byte limit");
|
|
234
|
+
let decoded;
|
|
235
|
+
let end;
|
|
236
|
+
try {
|
|
237
|
+
[decoded, end] = decoder$1.read(bytes, 0);
|
|
238
|
+
} catch {
|
|
239
|
+
throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
240
|
+
}
|
|
241
|
+
if (end !== bytes.length) throw new ChainError("invalid-request", "compiled message has trailing bytes");
|
|
242
|
+
const message = asV1Message(decoded);
|
|
243
|
+
const config = v1Config(mask, bytes, message.staticAccounts.length);
|
|
244
|
+
sanitizeV1Message(message, config);
|
|
245
|
+
return {
|
|
246
|
+
version: 1,
|
|
247
|
+
numRequiredSignatures: message.header.numSignerAccounts,
|
|
248
|
+
numReadonlySignerAccounts: message.header.numReadonlySignerAccounts,
|
|
249
|
+
numReadonlyNonSignerAccounts: message.header.numReadonlyNonSignerAccounts,
|
|
250
|
+
staticAccounts: [...message.staticAccounts],
|
|
251
|
+
lifetimeToken: message.lifetimeToken,
|
|
252
|
+
instructions: message.instructions.map((instruction) => ({
|
|
253
|
+
programAddressIndex: instruction.programAccountIndex,
|
|
254
|
+
accountIndices: [...instruction.accountIndices],
|
|
255
|
+
data: new Uint8Array(instruction.data)
|
|
256
|
+
})),
|
|
257
|
+
lookups: [],
|
|
258
|
+
config
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Whether the account `index` is writable in the message: a static signer index is writable below
|
|
263
|
+
* `numRequiredSignatures - numReadonlySignerAccounts`, a static non-signer index below
|
|
264
|
+
* `staticAccounts.length - numReadonlyNonSignerAccounts`, and a loaded index is writable exactly in
|
|
265
|
+
* the leading writable section of the loaded addresses.
|
|
266
|
+
*/
|
|
267
|
+
const isWritableIndex = (parsed, index) => {
|
|
268
|
+
const n = parsed.staticAccounts.length;
|
|
269
|
+
if (index < n) return index < parsed.numRequiredSignatures ? index < parsed.numRequiredSignatures - parsed.numReadonlySignerAccounts : index < n - parsed.numReadonlyNonSignerAccounts;
|
|
270
|
+
let writable = 0;
|
|
271
|
+
for (const lookup of parsed.lookups) writable += lookup.writableIndexes.length;
|
|
272
|
+
return index - n < writable;
|
|
273
|
+
};
|
|
99
274
|
/**
|
|
100
275
|
* Resolves an account index across static accounts and (request-declared) lookup tables in the
|
|
101
276
|
* compiled lookup order: writable entries then readable.
|
|
@@ -106,14 +281,22 @@ const resolveAccountIndex = (parsed, index, lookups) => {
|
|
|
106
281
|
const declared = new Map(lookups.map((t) => [t.address, t.addresses]));
|
|
107
282
|
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];
|
|
108
283
|
};
|
|
284
|
+
const namedAccounts = (parsed, lookups) => {
|
|
285
|
+
const fromTable = /* @__PURE__ */ new Set();
|
|
286
|
+
return {
|
|
287
|
+
fromTable,
|
|
288
|
+
at: (index) => {
|
|
289
|
+
if (index < parsed.staticAccounts.length) return parsed.staticAccounts[index];
|
|
290
|
+
const resolved = resolveAccountIndex(parsed, index, lookups);
|
|
291
|
+
if (resolved !== void 0) fromTable.add(resolved);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
};
|
|
109
295
|
/** All declared lookup-table entries must be valid base58 32-byte addresses. */
|
|
110
296
|
const validateLookupTables = (tables) => {
|
|
111
297
|
if (tables === void 0) return;
|
|
112
298
|
for (const table of tables) if (!isSolanaAddress(table.address) || !table.addresses.every(isSolanaAddress)) throw new ChainError("invalid-address", "lookup table entries must be base58 32-byte addresses");
|
|
113
299
|
};
|
|
114
|
-
// src/solana/assets.ts
|
|
115
|
-
/** The native asset id in `AssetFlow` and simulated asset changes. */
|
|
116
|
-
const SOLANA_NATIVE_ASSET = "lamports";
|
|
117
300
|
// src/solana/ata.ts
|
|
118
301
|
const PDA_SEED = new TextEncoder().encode("ProgramDerivedAddress");
|
|
119
302
|
const encoder = getAddressEncoder();
|
|
@@ -156,6 +339,210 @@ const associatedTokenAddress = (owner, mint, tokenProgram) => {
|
|
|
156
339
|
}
|
|
157
340
|
throw new ChainError("invalid-request", "no PDA bump for the associated token account");
|
|
158
341
|
};
|
|
342
|
+
/** SPL Token — AMM v4 asserts its token program account equals this id (processor.rs check). */
|
|
343
|
+
const SPL_TOKEN = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
344
|
+
const SWAP_V2 = Uint8Array.from([
|
|
345
|
+
43,
|
|
346
|
+
4,
|
|
347
|
+
237,
|
|
348
|
+
11,
|
|
349
|
+
26,
|
|
350
|
+
201,
|
|
351
|
+
30,
|
|
352
|
+
98
|
|
353
|
+
]);
|
|
354
|
+
const SWAP_BASE_INPUT = Uint8Array.from([
|
|
355
|
+
143,
|
|
356
|
+
190,
|
|
357
|
+
90,
|
|
358
|
+
218,
|
|
359
|
+
196,
|
|
360
|
+
30,
|
|
361
|
+
51,
|
|
362
|
+
222
|
|
363
|
+
]);
|
|
364
|
+
const DLMM_SWAP = Uint8Array.from([
|
|
365
|
+
248,
|
|
366
|
+
198,
|
|
367
|
+
158,
|
|
368
|
+
145,
|
|
369
|
+
225,
|
|
370
|
+
117,
|
|
371
|
+
135,
|
|
372
|
+
200
|
|
373
|
+
]);
|
|
374
|
+
const DLMM_SWAP2 = Uint8Array.from([
|
|
375
|
+
65,
|
|
376
|
+
75,
|
|
377
|
+
63,
|
|
378
|
+
76,
|
|
379
|
+
235,
|
|
380
|
+
91,
|
|
381
|
+
91,
|
|
382
|
+
136
|
|
383
|
+
]);
|
|
384
|
+
const u32$3 = getU32Decoder();
|
|
385
|
+
const u64$4 = getU64Decoder();
|
|
386
|
+
const startsWith$1 = (data, prefix) => data.length >= prefix.length && prefix.every((b, i) => data[i] === b);
|
|
387
|
+
/**
|
|
388
|
+
* AMM swap instructions whose account layout pins the signer's worst-case in/out. Anything that
|
|
389
|
+
* does not match a documented shape exactly — tag, data length, account count, signer slot, the AMM
|
|
390
|
+
* v4 token program — returns undefined and falls back to the program-authority rule.
|
|
391
|
+
*/
|
|
392
|
+
const decodeAmmSwapIx = (ix, named, program) => {
|
|
393
|
+
const { data } = ix;
|
|
394
|
+
const account = (i) => {
|
|
395
|
+
const index = ix.accountIndices[i];
|
|
396
|
+
return index === void 0 ? void 0 : named.at(index);
|
|
397
|
+
};
|
|
398
|
+
if (program === "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8") {
|
|
399
|
+
const tag = data.at(0);
|
|
400
|
+
if (!(tag === 9 || tag === 16) && !(tag === 17) || data.length !== 17) return;
|
|
401
|
+
const n = ix.accountIndices.length;
|
|
402
|
+
const expected = tag === 16 || tag === 17 ? 8 : null;
|
|
403
|
+
if (expected === null ? n !== 17 && n !== 18 : n !== expected) return;
|
|
404
|
+
if (account(0) !== SPL_TOKEN) return;
|
|
405
|
+
const authority = account(n - 1);
|
|
406
|
+
const sourceAccount = account(n - 3);
|
|
407
|
+
const destinationAccount = account(n - 2);
|
|
408
|
+
if (authority === void 0 || sourceAccount === void 0 || destinationAccount === void 0) return;
|
|
409
|
+
return {
|
|
410
|
+
program,
|
|
411
|
+
protocol: "raydium-amm-v4",
|
|
412
|
+
authority,
|
|
413
|
+
sourceAccount,
|
|
414
|
+
destinationAccount,
|
|
415
|
+
maxIn: u64$4.decode(data, 1),
|
|
416
|
+
minOut: u64$4.decode(data, 9)
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
if (program === "CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C") {
|
|
420
|
+
if (!startsWith$1(data, SWAP_BASE_INPUT) || data.length !== 24 || ix.accountIndices.length !== 13) return;
|
|
421
|
+
const authority = account(0);
|
|
422
|
+
const sourceAccount = account(4);
|
|
423
|
+
const destinationAccount = account(5);
|
|
424
|
+
const sourceMint = account(10);
|
|
425
|
+
const destinationMint = account(11);
|
|
426
|
+
const destinationTokenProgram = account(9);
|
|
427
|
+
if (authority === void 0 || sourceAccount === void 0 || destinationAccount === void 0 || sourceMint === void 0 || destinationMint === void 0 || destinationTokenProgram === void 0) return;
|
|
428
|
+
return {
|
|
429
|
+
program,
|
|
430
|
+
protocol: "raydium-cpmm",
|
|
431
|
+
authority,
|
|
432
|
+
sourceAccount,
|
|
433
|
+
destinationAccount,
|
|
434
|
+
sourceMint,
|
|
435
|
+
destinationMint,
|
|
436
|
+
destinationTokenProgram,
|
|
437
|
+
maxIn: u64$4.decode(data, 8),
|
|
438
|
+
minOut: u64$4.decode(data, 16)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
if (program === "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK") {
|
|
442
|
+
if (!startsWith$1(data, SWAP_V2) || data.length !== 41 || ix.accountIndices.length < 13) return;
|
|
443
|
+
const authority = account(0);
|
|
444
|
+
const sourceAccount = account(3);
|
|
445
|
+
const destinationAccount = account(4);
|
|
446
|
+
const sourceMint = account(11);
|
|
447
|
+
const destinationMint = account(12);
|
|
448
|
+
if (authority === void 0 || sourceAccount === void 0 || destinationAccount === void 0 || sourceMint === void 0 || destinationMint === void 0) return;
|
|
449
|
+
if (data.at(40) !== 1) return;
|
|
450
|
+
return {
|
|
451
|
+
program,
|
|
452
|
+
protocol: "raydium-clmm",
|
|
453
|
+
authority,
|
|
454
|
+
sourceAccount,
|
|
455
|
+
destinationAccount,
|
|
456
|
+
sourceMint,
|
|
457
|
+
destinationMint,
|
|
458
|
+
maxIn: u64$4.decode(data, 8),
|
|
459
|
+
minOut: u64$4.decode(data, 16)
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (program === "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc") {
|
|
463
|
+
if (!startsWith$1(data, SWAP_V2) || data.length < 43 || ix.accountIndices.length < 15) return;
|
|
464
|
+
const option = data.at(42);
|
|
465
|
+
if (option === 0) {
|
|
466
|
+
if (data.length !== 43) return;
|
|
467
|
+
} else if (option === 1) {
|
|
468
|
+
if (data.length < 47) return;
|
|
469
|
+
const slices = u32$3.decode(data, 43);
|
|
470
|
+
if (data.length !== 47 + slices * 2) return;
|
|
471
|
+
} else return;
|
|
472
|
+
const authority = account(3);
|
|
473
|
+
if (authority === void 0) return;
|
|
474
|
+
const aToB = data.at(41);
|
|
475
|
+
if (aToB !== 0 && aToB !== 1 || data.at(40) !== 1) return;
|
|
476
|
+
const sourceIndex = aToB === 1 ? 7 : 9;
|
|
477
|
+
const destinationIndex = aToB === 1 ? 9 : 7;
|
|
478
|
+
const sourceAccount = account(sourceIndex);
|
|
479
|
+
const destinationAccount = account(destinationIndex);
|
|
480
|
+
const sourceMint = account(aToB === 1 ? 5 : 6);
|
|
481
|
+
const destinationMint = account(aToB === 1 ? 6 : 5);
|
|
482
|
+
const destinationTokenProgram = account(aToB === 1 ? 1 : 0);
|
|
483
|
+
if (sourceAccount === void 0 || destinationAccount === void 0 || sourceMint === void 0 || destinationMint === void 0 || destinationTokenProgram === void 0) return;
|
|
484
|
+
return {
|
|
485
|
+
program,
|
|
486
|
+
protocol: "orca-whirlpool",
|
|
487
|
+
authority,
|
|
488
|
+
sourceAccount,
|
|
489
|
+
destinationAccount,
|
|
490
|
+
sourceMint,
|
|
491
|
+
destinationMint,
|
|
492
|
+
destinationTokenProgram,
|
|
493
|
+
maxIn: u64$4.decode(data, 8),
|
|
494
|
+
minOut: u64$4.decode(data, 16)
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
if (program === "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo") {
|
|
498
|
+
const swap = startsWith$1(data, DLMM_SWAP);
|
|
499
|
+
const swap2 = !swap && startsWith$1(data, DLMM_SWAP2);
|
|
500
|
+
if (!swap && !swap2 || data.length < 24 || ix.accountIndices.length < (swap ? 15 : 16)) return;
|
|
501
|
+
if (swap) {
|
|
502
|
+
if (data.length !== 24) return;
|
|
503
|
+
} else {
|
|
504
|
+
if (data.length < 28) return;
|
|
505
|
+
const slices = u32$3.decode(data, 24);
|
|
506
|
+
let offset = 28;
|
|
507
|
+
for (let i = 0; i < slices; i++) {
|
|
508
|
+
const tag = data.at(offset);
|
|
509
|
+
if (tag === void 0 || tag > 4) return;
|
|
510
|
+
offset += tag === 3 ? 2 : 1;
|
|
511
|
+
if (data.at(offset) === void 0) return;
|
|
512
|
+
offset += 1;
|
|
513
|
+
}
|
|
514
|
+
if (offset !== data.length) return;
|
|
515
|
+
}
|
|
516
|
+
const authority = account(10);
|
|
517
|
+
const sourceAccount = account(4);
|
|
518
|
+
const destinationAccount = account(5);
|
|
519
|
+
const mintX = account(6);
|
|
520
|
+
const mintY = account(7);
|
|
521
|
+
const programX = account(11);
|
|
522
|
+
const programY = account(12);
|
|
523
|
+
if (authority === void 0 || sourceAccount === void 0 || destinationAccount === void 0 || mintX === void 0 || mintY === void 0 || programX === void 0 || programY === void 0) return;
|
|
524
|
+
const ataX = associatedTokenAddress(authority, mintX, programX);
|
|
525
|
+
const ataY = associatedTokenAddress(authority, mintY, programY);
|
|
526
|
+
const sourceMint = sourceAccount === ataX ? mintX : sourceAccount === ataY ? mintY : void 0;
|
|
527
|
+
const destinationMint = destinationAccount === ataX ? mintX : destinationAccount === ataY ? mintY : void 0;
|
|
528
|
+
if (sourceMint !== void 0 && sourceMint === destinationMint) return;
|
|
529
|
+
return {
|
|
530
|
+
program,
|
|
531
|
+
protocol: "meteora-dlmm",
|
|
532
|
+
authority,
|
|
533
|
+
sourceAccount,
|
|
534
|
+
destinationAccount,
|
|
535
|
+
sourceMint,
|
|
536
|
+
destinationMint,
|
|
537
|
+
...destinationMint === void 0 ? {} : { destinationTokenProgram: destinationMint === mintX ? programX : programY },
|
|
538
|
+
maxIn: u64$4.decode(data, 8),
|
|
539
|
+
minOut: u64$4.decode(data, 16)
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
// src/solana/assets.ts
|
|
544
|
+
/** The native asset id in `AssetFlow` and simulated asset changes. */
|
|
545
|
+
const SOLANA_NATIVE_ASSET = "lamports";
|
|
159
546
|
// src/solana/core.ts
|
|
160
547
|
/** Metaplex Core — recognised by program id; the transfer authority is verified on-chain. */
|
|
161
548
|
const MPL_CORE_PROGRAM = "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d";
|
|
@@ -170,11 +557,11 @@ const TRANSFER_V1 = Uint8Array.from([14, 0]);
|
|
|
170
557
|
* authority slot resolves to the payer when it is the placeholder; it must be the signer for the
|
|
171
558
|
* call to count as a transfer the wallet is doing.
|
|
172
559
|
*/
|
|
173
|
-
const decodeCoreIx = (
|
|
560
|
+
const decodeCoreIx = (ix, named) => {
|
|
174
561
|
const { data } = ix;
|
|
175
562
|
const account = (i) => {
|
|
176
563
|
const index = ix.accountIndices[i];
|
|
177
|
-
return index === void 0 ? void 0 :
|
|
564
|
+
return index === void 0 ? void 0 : named.at(index);
|
|
178
565
|
};
|
|
179
566
|
if (data.length !== 2 || data[0] !== TRANSFER_V1[0] || data[1] !== TRANSFER_V1[1]) return;
|
|
180
567
|
const asset = account(0);
|
|
@@ -216,18 +603,21 @@ const u16$1 = getU16Decoder();
|
|
|
216
603
|
const u32$2 = getU32Decoder();
|
|
217
604
|
const u64$3 = getU64Decoder();
|
|
218
605
|
const startsWith = (data, prefix) => data.length >= prefix.length && prefix.every((b, i) => data[i] === b);
|
|
606
|
+
const MAX_BPS = 1e4;
|
|
607
|
+
/** A slippage above 100% has no "minimum received" — such a route is not recognised. */
|
|
608
|
+
const withinSlippage = (swap) => swap.slippageBps > MAX_BPS ? void 0 : swap;
|
|
219
609
|
/**
|
|
220
610
|
* `route_v2` / `shared_accounts_route_v2`: the fixed scalar prefix must be exact and the trailing
|
|
221
611
|
* `route_plan` vector must declare enough remaining bytes (each step is ≥ 5 bytes on the wire). The
|
|
222
612
|
* route steps themselves stay opaque — the intent only shows the inputs and the floor.
|
|
223
613
|
*/
|
|
224
|
-
const decodeJupiterIx = (
|
|
614
|
+
const decodeJupiterIx = (ix, named) => {
|
|
225
615
|
const { data } = ix;
|
|
226
616
|
const account = (i) => {
|
|
227
617
|
const index = ix.accountIndices[i];
|
|
228
|
-
return index === void 0 ? void 0 :
|
|
618
|
+
return index === void 0 ? void 0 : named.at(index);
|
|
229
619
|
};
|
|
230
|
-
const
|
|
620
|
+
const accountAt = (i) => account(i) ?? "";
|
|
231
621
|
const planWellFormed = (offset) => {
|
|
232
622
|
if (data.length < offset + 4) return false;
|
|
233
623
|
const count = u32$2.decode(data, offset);
|
|
@@ -241,26 +631,26 @@ const decodeJupiterIx = (parsed, ix, lookups) => {
|
|
|
241
631
|
});
|
|
242
632
|
if (startsWith(data, ROUTE_V2)) {
|
|
243
633
|
if (ix.accountIndices.length < 10 || !planWellFormed(30)) return;
|
|
244
|
-
const optionalDest =
|
|
245
|
-
return {
|
|
246
|
-
authority:
|
|
247
|
-
sourceMint:
|
|
248
|
-
destinationMint:
|
|
249
|
-
destinationTokenProgram:
|
|
250
|
-
destinationAccount: optionalDest === "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4" ?
|
|
634
|
+
const optionalDest = accountAt(7);
|
|
635
|
+
return withinSlippage({
|
|
636
|
+
authority: accountAt(0),
|
|
637
|
+
sourceMint: accountAt(3),
|
|
638
|
+
destinationMint: accountAt(4),
|
|
639
|
+
destinationTokenProgram: accountAt(6),
|
|
640
|
+
destinationAccount: optionalDest === "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4" ? accountAt(2) : optionalDest,
|
|
251
641
|
...scalars(8)
|
|
252
|
-
};
|
|
642
|
+
});
|
|
253
643
|
}
|
|
254
644
|
if (startsWith(data, SHARED_ROUTE_V2)) {
|
|
255
645
|
if (ix.accountIndices.length < 12 || !planWellFormed(31)) return;
|
|
256
|
-
return {
|
|
257
|
-
authority:
|
|
258
|
-
sourceMint:
|
|
259
|
-
destinationMint:
|
|
260
|
-
destinationTokenProgram:
|
|
261
|
-
destinationAccount:
|
|
646
|
+
return withinSlippage({
|
|
647
|
+
authority: accountAt(1),
|
|
648
|
+
sourceMint: accountAt(6),
|
|
649
|
+
destinationMint: accountAt(7),
|
|
650
|
+
destinationTokenProgram: accountAt(9),
|
|
651
|
+
destinationAccount: accountAt(5),
|
|
262
652
|
...scalars(9)
|
|
263
|
-
};
|
|
653
|
+
});
|
|
264
654
|
}
|
|
265
655
|
};
|
|
266
656
|
// src/solana/stake.ts
|
|
@@ -280,7 +670,7 @@ const u32le$1 = (data, offset) => u32$1.decode(data, offset);
|
|
|
280
670
|
const u64le$1 = (data, offset) => u64$2.decode(data, offset);
|
|
281
671
|
const i64le = (data, offset) => i64.decode(data, offset);
|
|
282
672
|
const key = (data, offset) => solanaAddressFromPublicKey(data.subarray(offset, offset + 32));
|
|
283
|
-
const account = (
|
|
673
|
+
const account = (ix, index, named) => index < ix.accountIndices.length ? named.at(ix.accountIndices[index] ?? 0) : void 0;
|
|
284
674
|
const role = (data, offset) => {
|
|
285
675
|
const r = u32le$1(data, offset);
|
|
286
676
|
return r === 0 ? "staker" : r === 1 ? "withdrawer" : "other";
|
|
@@ -290,9 +680,9 @@ const role = (data, offset) => {
|
|
|
290
680
|
* current form or the legacy one (recognised by the sysvar it inserts at a fixed position).
|
|
291
681
|
* Anything else is `undefined` → the whole transaction decodes `opaque`.
|
|
292
682
|
*/
|
|
293
|
-
const decodeStakeIx = (
|
|
683
|
+
const decodeStakeIx = (ix, named) => {
|
|
294
684
|
const { data } = ix;
|
|
295
|
-
const acc = (i) => account(
|
|
685
|
+
const acc = (i) => account(ix, i, named);
|
|
296
686
|
const n = ix.accountIndices.length;
|
|
297
687
|
if (data.length < 4) return;
|
|
298
688
|
switch (u32le$1(data, 0)) {
|
|
@@ -333,6 +723,19 @@ const decodeStakeIx = (parsed, ix, lookups) => {
|
|
|
333
723
|
validator: vote
|
|
334
724
|
};
|
|
335
725
|
}
|
|
726
|
+
case 3: {
|
|
727
|
+
const stake = acc(0);
|
|
728
|
+
const to = acc(1);
|
|
729
|
+
const staker = acc(2);
|
|
730
|
+
if (data.length !== 12 || stake === void 0 || to === void 0 || staker === void 0 || n !== 3) return;
|
|
731
|
+
return {
|
|
732
|
+
kind: "split",
|
|
733
|
+
account: stake,
|
|
734
|
+
to,
|
|
735
|
+
staker,
|
|
736
|
+
lamports: u64le$1(data, 4)
|
|
737
|
+
};
|
|
738
|
+
}
|
|
336
739
|
case 4: {
|
|
337
740
|
const legacy = acc(2) === SYSVAR_IDS.clock && acc(3) === SYSVAR_IDS.stakeHistory;
|
|
338
741
|
const stake = acc(0);
|
|
@@ -384,25 +787,25 @@ const decodeStakeIx = (parsed, ix, lookups) => {
|
|
|
384
787
|
}
|
|
385
788
|
};
|
|
386
789
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
790
|
+
* One system-program account creation (CreateAccount or CreateAccountWithSeed), for any new-owner
|
|
791
|
+
* program. A with-seed creation whose `account` does not match sha256(base ‖ seed ‖ owner) is
|
|
792
|
+
* `"other"` — the program itself would reject it. `undefined` when the data is neither instruction;
|
|
793
|
+
* `"other"` when it is one but malformed.
|
|
390
794
|
*/
|
|
391
|
-
const
|
|
795
|
+
const decodeSystemCreate = (ix, named) => {
|
|
392
796
|
const { data } = ix;
|
|
393
|
-
const acc = (i) => account(
|
|
797
|
+
const acc = (i) => account(ix, i, named);
|
|
394
798
|
if (data.length < 4) return "other";
|
|
395
799
|
if (u32le$1(data, 0) === 0) {
|
|
396
800
|
if (data.length !== 52 || ix.accountIndices.length !== 2) return "other";
|
|
397
801
|
const from = acc(0);
|
|
398
802
|
const to = acc(1);
|
|
399
803
|
if (from === void 0 || to === void 0) return "other";
|
|
400
|
-
if (key(data, 20) !== PROGRAM_IDS.stake) return "other";
|
|
401
804
|
return {
|
|
402
|
-
kind: "create",
|
|
403
805
|
account: to,
|
|
404
806
|
from,
|
|
405
|
-
lamports: u64le$1(data, 4)
|
|
807
|
+
lamports: u64le$1(data, 4),
|
|
808
|
+
owner: key(data, 20)
|
|
406
809
|
};
|
|
407
810
|
}
|
|
408
811
|
if (u32le$1(data, 0) === 3) {
|
|
@@ -413,19 +816,19 @@ const decodeStakeCreate = (parsed, ix, lookups) => {
|
|
|
413
816
|
const to = acc(1);
|
|
414
817
|
if (from === void 0 || to === void 0 || !(ix.accountIndices.length === 2 || ix.accountIndices.length === 3)) return "other";
|
|
415
818
|
const base = key(data, 4);
|
|
416
|
-
|
|
819
|
+
const owner = key(data, end - 32);
|
|
417
820
|
if (ix.accountIndices.length === 3 && acc(2) !== base) return "other";
|
|
418
821
|
if (ix.accountIndices.length === 2 && base !== from) return "other";
|
|
419
822
|
const seed = data.subarray(44, 44 + seedLen);
|
|
420
823
|
return to === solanaAddressFromPublicKey(sha256(new Uint8Array([
|
|
421
824
|
...addr.encode(address(base)),
|
|
422
825
|
...seed,
|
|
423
|
-
...addr.encode(address(
|
|
826
|
+
...addr.encode(address(owner))
|
|
424
827
|
]))) ? {
|
|
425
|
-
kind: "create",
|
|
426
828
|
account: to,
|
|
427
829
|
from,
|
|
428
|
-
lamports: u64le$1(data, 44 + seedLen)
|
|
830
|
+
lamports: u64le$1(data, 44 + seedLen),
|
|
831
|
+
owner
|
|
429
832
|
} : "other";
|
|
430
833
|
}
|
|
431
834
|
};
|
|
@@ -454,21 +857,30 @@ const u64le = (data, offset) => u64$1.decode(data, offset);
|
|
|
454
857
|
* Classifies one instruction by program + discriminator/layout. Exact-length checks keep
|
|
455
858
|
* non-canonical encodings out of the `full` class.
|
|
456
859
|
*/
|
|
457
|
-
const classifyIx = (
|
|
458
|
-
const program =
|
|
860
|
+
const classifyIx = (ix, named, signer) => {
|
|
861
|
+
const program = named.at(ix.programAddressIndex);
|
|
459
862
|
const { data } = ix;
|
|
460
863
|
if (program === PROGRAM_IDS.system) {
|
|
461
864
|
if (data.length === 12 && u32le(data, 0) === 2) return {
|
|
462
865
|
kind: "system-transfer",
|
|
463
|
-
from:
|
|
464
|
-
to:
|
|
866
|
+
from: named.at(ix.accountIndices[0] ?? 0),
|
|
867
|
+
to: named.at(ix.accountIndices[1] ?? 0),
|
|
465
868
|
amount: u64le(data, 4)
|
|
466
869
|
};
|
|
467
|
-
const create =
|
|
468
|
-
if (create !== void 0 && create !== "other") return {
|
|
870
|
+
const create = decodeSystemCreate(ix, named);
|
|
871
|
+
if (create !== void 0 && create !== "other") return create.owner === PROGRAM_IDS.stake ? {
|
|
469
872
|
kind: "system-create",
|
|
470
|
-
stake:
|
|
873
|
+
stake: {
|
|
874
|
+
kind: "create",
|
|
875
|
+
account: create.account,
|
|
876
|
+
from: create.from,
|
|
877
|
+
lamports: create.lamports
|
|
878
|
+
}
|
|
879
|
+
} : {
|
|
880
|
+
kind: "system-create-account",
|
|
881
|
+
create
|
|
471
882
|
};
|
|
883
|
+
if (data.length === 4 && u32le(data, 0) === 4 && ix.accountIndices.length === 3) return { kind: "system-advance-nonce" };
|
|
472
884
|
return { kind: "other" };
|
|
473
885
|
}
|
|
474
886
|
if (program === PROGRAM_IDS.computeBudget) {
|
|
@@ -492,35 +904,59 @@ const classifyIx = (parsed, ix, lookups, signer) => {
|
|
|
492
904
|
kind: "token-transfer-checked",
|
|
493
905
|
amount: u64le(data, 1),
|
|
494
906
|
decimals: data[9],
|
|
495
|
-
to:
|
|
496
|
-
mint:
|
|
907
|
+
to: named.at(ix.accountIndices[2] ?? 0),
|
|
908
|
+
mint: named.at(ix.accountIndices[1] ?? 0)
|
|
497
909
|
};
|
|
910
|
+
if (data.length === 9 && data[0] === 3 && ix.accountIndices.length === 3) return named.at(ix.accountIndices[2] ?? 0) === signer ? {
|
|
911
|
+
kind: "token-transfer",
|
|
912
|
+
amount: u64le(data, 1),
|
|
913
|
+
tokenAccount: named.at(ix.accountIndices[0] ?? 0),
|
|
914
|
+
to: named.at(ix.accountIndices[1] ?? 0)
|
|
915
|
+
} : { kind: "other" };
|
|
916
|
+
if ((data.length === 9 && data[0] === 8 || data.length === 10 && data[0] === 15) && ix.accountIndices.length === 3) return named.at(ix.accountIndices[2] ?? 0) === signer ? {
|
|
917
|
+
kind: "token-burn",
|
|
918
|
+
amount: u64le(data, 1),
|
|
919
|
+
mint: named.at(ix.accountIndices[1] ?? 0),
|
|
920
|
+
to: named.at(ix.accountIndices[0] ?? 0)
|
|
921
|
+
} : { kind: "other" };
|
|
498
922
|
if (data.length === 9 && data[0] === 4) return {
|
|
499
923
|
kind: "token-approve",
|
|
500
924
|
amount: u64le(data, 1),
|
|
501
|
-
to:
|
|
925
|
+
to: named.at(ix.accountIndices[1] ?? 0)
|
|
502
926
|
};
|
|
503
927
|
if (data.length === 1 && data[0] === 17) return { kind: "token-sync-native" };
|
|
504
|
-
if (data.length === 1 && data[0] === 9) return
|
|
928
|
+
if (data.length === 1 && data[0] === 9) return named.at(ix.accountIndices[1] ?? 0) === signer ? { kind: "token-close-account" } : { kind: "other" };
|
|
929
|
+
if (data.length === 1 && data[0] === 1 && ix.accountIndices.length === 4) return { kind: "token-initialize-account" };
|
|
930
|
+
if (data.length === 1 && data[0] === 5 && ix.accountIndices.length === 2) return {
|
|
931
|
+
kind: "token-revoke",
|
|
932
|
+
tokenAccount: named.at(ix.accountIndices[0] ?? 0)
|
|
933
|
+
};
|
|
505
934
|
return { kind: "other" };
|
|
506
935
|
}
|
|
507
936
|
if (program === "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4") {
|
|
508
|
-
const jupiter = decodeJupiterIx(
|
|
937
|
+
const jupiter = decodeJupiterIx(ix, named);
|
|
509
938
|
return jupiter !== void 0 && jupiter.authority === signer ? {
|
|
510
939
|
kind: "jupiter",
|
|
511
940
|
jupiter
|
|
512
941
|
} : { kind: "other" };
|
|
513
942
|
}
|
|
943
|
+
if (program === "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8" || program === "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK" || program === "CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C" || program === "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc" || program === "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo") {
|
|
944
|
+
const amm = decodeAmmSwapIx(ix, named, program);
|
|
945
|
+
return amm !== void 0 && amm.authority === signer ? {
|
|
946
|
+
kind: "amm-swap",
|
|
947
|
+
amm
|
|
948
|
+
} : { kind: "other" };
|
|
949
|
+
}
|
|
514
950
|
if (program === "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d") {
|
|
515
|
-
const core = decodeCoreIx(
|
|
951
|
+
const core = decodeCoreIx(ix, named);
|
|
516
952
|
return core !== void 0 && core.authority === signer ? {
|
|
517
953
|
kind: "core-transfer",
|
|
518
954
|
core
|
|
519
955
|
} : { kind: "other" };
|
|
520
956
|
}
|
|
521
957
|
if (program === PROGRAM_IDS.stake) {
|
|
522
|
-
const stake = decodeStakeIx(
|
|
523
|
-
return stake === void 0 ? { kind: "other" } : {
|
|
958
|
+
const stake = decodeStakeIx(ix, named);
|
|
959
|
+
return stake === void 0 || stake.kind === "split" && stake.staker !== signer ? { kind: "other" } : {
|
|
524
960
|
kind: "stake",
|
|
525
961
|
stake
|
|
526
962
|
};
|
|
@@ -530,30 +966,63 @@ const classifyIx = (parsed, ix, lookups, signer) => {
|
|
|
530
966
|
const FULL_KINDS = /* @__PURE__ */ new Set([
|
|
531
967
|
"system-transfer",
|
|
532
968
|
"system-create",
|
|
969
|
+
"system-create-account",
|
|
970
|
+
"system-advance-nonce",
|
|
533
971
|
"cu-limit",
|
|
534
972
|
"cu-price",
|
|
535
973
|
"ata-create",
|
|
536
974
|
"ata-create-idempotent",
|
|
537
975
|
"stake",
|
|
538
976
|
"token-sync-native",
|
|
539
|
-
"token-close-account"
|
|
977
|
+
"token-close-account",
|
|
978
|
+
"token-initialize-account",
|
|
979
|
+
"token-revoke"
|
|
540
980
|
]);
|
|
541
981
|
const classify = (parsed, calls, network, table) => {
|
|
542
982
|
let allFull = true;
|
|
543
983
|
for (const call of calls) {
|
|
544
984
|
if (call.kind === "other") return "opaque";
|
|
545
|
-
if (call.kind === "token-approve" || call.kind === "jupiter" || call.kind === "core-transfer") allFull = false;
|
|
985
|
+
if (call.kind === "token-approve" || call.kind === "jupiter" || call.kind === "amm-swap" || call.kind === "core-transfer" || call.kind === "token-transfer" || call.kind === "token-burn") allFull = false;
|
|
546
986
|
if (call.kind === "token-transfer-checked" && lookupSolanaToken(table, network, call.mint ?? "") === void 0) allFull = false;
|
|
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";
|
|
987
|
+
if (!FULL_KINDS.has(call.kind) && call.kind !== "token-transfer-checked" && call.kind !== "token-transfer" && call.kind !== "token-burn" && call.kind !== "token-approve" && call.kind !== "jupiter" && call.kind !== "amm-swap" && call.kind !== "core-transfer") return "opaque";
|
|
548
988
|
}
|
|
549
989
|
if (parsed.lookups.length > 0) return "partial";
|
|
550
990
|
return allFull ? "full" : "partial";
|
|
551
991
|
};
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
992
|
+
/** The most writable accounts a signer-taking unknown program may reach before it is blind. */
|
|
993
|
+
const PROGRAM_AUTHORITY_ACCOUNTS = 12;
|
|
994
|
+
const DEFAULT_INSTRUCTION_CU = 200000n;
|
|
995
|
+
const BUILTIN_INSTRUCTION_CU = 3000n;
|
|
996
|
+
const MAX_COMPUTE_UNIT_LIMIT = 1400000n;
|
|
997
|
+
const PRECOMPILE_PROGRAMS = /* @__PURE__ */ new Set([
|
|
998
|
+
PROGRAM_IDS.ed25519,
|
|
999
|
+
PROGRAM_IDS.secp256k1,
|
|
1000
|
+
PROGRAM_IDS.secp256r1
|
|
1001
|
+
]);
|
|
1002
|
+
const signatureCount = (parsed, lookups) => {
|
|
1003
|
+
let count = parsed.numRequiredSignatures;
|
|
1004
|
+
for (const ix of parsed.instructions) {
|
|
1005
|
+
const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);
|
|
1006
|
+
if (program !== void 0 && PRECOMPILE_PROGRAMS.has(program)) count += ix.data[0] ?? 0;
|
|
1007
|
+
}
|
|
1008
|
+
return count;
|
|
1009
|
+
};
|
|
1010
|
+
const feeLamports = (parsed, lookups, calls) => {
|
|
1011
|
+
const signatures = BigInt(signatureCount(parsed, lookups));
|
|
1012
|
+
if (parsed.version === 1) return 5000n * signatures + (parsed.config.priorityFeeLamports ?? 0n);
|
|
1013
|
+
const price = calls.find((c) => c.kind === "cu-price")?.microLamports ?? 0n;
|
|
1014
|
+
let builtin = 0n;
|
|
1015
|
+
let other = 0n;
|
|
1016
|
+
for (const ix of parsed.instructions) {
|
|
1017
|
+
const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);
|
|
1018
|
+
if (program === PROGRAM_IDS.system || program === PROGRAM_IDS.computeBudget) builtin += 1n;
|
|
1019
|
+
else other += 1n;
|
|
1020
|
+
}
|
|
1021
|
+
const defaultLimit = BUILTIN_INSTRUCTION_CU * builtin + DEFAULT_INSTRUCTION_CU * other;
|
|
1022
|
+
const requested = calls.find((c) => c.kind === "cu-limit")?.units;
|
|
1023
|
+
const limit = requested === void 0 ? defaultLimit : BigInt(requested);
|
|
1024
|
+
const capped = limit < MAX_COMPUTE_UNIT_LIMIT ? limit : MAX_COMPUTE_UNIT_LIMIT;
|
|
1025
|
+
return 5000n * signatures + (price * capped + 999999n) / 1000000n;
|
|
557
1026
|
};
|
|
558
1027
|
const decodeTransaction = (request, signer, table) => {
|
|
559
1028
|
const parsed = parseCompiledMessage(request.message);
|
|
@@ -561,16 +1030,23 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
561
1030
|
address: t.address,
|
|
562
1031
|
addresses: t.addresses
|
|
563
1032
|
}));
|
|
564
|
-
const
|
|
565
|
-
const
|
|
1033
|
+
const named = namedAccounts(parsed, lookups);
|
|
1034
|
+
const calls = parsed.instructions.map((ix) => classifyIx(ix, named, signer));
|
|
1035
|
+
if (calls.filter((c) => c.kind === "cu-limit").length > 1 || calls.filter((c) => c.kind === "cu-price").length > 1) throw new ChainError("invalid-request", "duplicate compute-budget instruction");
|
|
1036
|
+
const verifiability = named.fromTable.size === 0 ? classify(parsed, calls, request.network, table) : "opaque";
|
|
566
1037
|
const outflows = [];
|
|
567
1038
|
const approvals = [];
|
|
568
1039
|
const staking = [];
|
|
569
1040
|
const warnings = [];
|
|
570
1041
|
const minimumReceived = [];
|
|
571
1042
|
const wsolAtas = /* @__PURE__ */ new Set([associatedTokenAddress(signer, WSOL_MINT, PROGRAM_IDS.token), associatedTokenAddress(signer, WSOL_MINT, PROGRAM_IDS.token2022)]);
|
|
1043
|
+
const atas = /* @__PURE__ */ new Map();
|
|
1044
|
+
for (const [mint, token] of Object.entries(table[request.network] ?? {})) for (const tokenProgram of [PROGRAM_IDS.token, PROGRAM_IDS.token2022]) atas.set(associatedTokenAddress(signer, mint, tokenProgram), {
|
|
1045
|
+
mint,
|
|
1046
|
+
symbol: token.symbol
|
|
1047
|
+
});
|
|
572
1048
|
let otherTransfer = false;
|
|
573
|
-
let
|
|
1049
|
+
let hasSwap = false;
|
|
574
1050
|
for (const call of calls) {
|
|
575
1051
|
if (call.kind === "system-transfer" && call.to !== void 0 && call.from === signer) {
|
|
576
1052
|
if (wsolAtas.has(call.to)) continue;
|
|
@@ -584,9 +1060,20 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
584
1060
|
verified: true
|
|
585
1061
|
});
|
|
586
1062
|
}
|
|
1063
|
+
if (call.kind === "system-create-account" && call.create !== void 0 && call.create.from === signer) {
|
|
1064
|
+
otherTransfer = true;
|
|
1065
|
+
outflows.push({
|
|
1066
|
+
to: call.create.account,
|
|
1067
|
+
amount: {
|
|
1068
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
1069
|
+
amount: call.create.lamports.toString(10)
|
|
1070
|
+
},
|
|
1071
|
+
verified: true
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
587
1074
|
if (call.kind === "jupiter" && call.jupiter !== void 0) {
|
|
588
1075
|
const swap = call.jupiter;
|
|
589
|
-
|
|
1076
|
+
hasSwap = true;
|
|
590
1077
|
otherTransfer = true;
|
|
591
1078
|
const sell = lookupSolanaToken(table, request.network, swap.sourceMint);
|
|
592
1079
|
outflows.push({
|
|
@@ -606,9 +1093,9 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
606
1093
|
});
|
|
607
1094
|
const minimum = (swap.quotedOut * BigInt(1e4 - swap.slippageBps) + 9999n) / 10000n;
|
|
608
1095
|
const buy = lookupSolanaToken(table, request.network, swap.destinationMint);
|
|
609
|
-
const destAta = associatedTokenAddress(signer, swap.destinationMint, swap.destinationTokenProgram);
|
|
1096
|
+
const destAta = swap.destinationMint === "" || swap.destinationTokenProgram === "" ? void 0 : associatedTokenAddress(signer, swap.destinationMint, swap.destinationTokenProgram);
|
|
610
1097
|
minimumReceived.push({
|
|
611
|
-
to: swap.destinationAccount === destAta ? signer : swap.destinationAccount,
|
|
1098
|
+
to: swap.destinationAccount === "" ? "" : swap.destinationAccount === destAta ? signer : swap.destinationAccount,
|
|
612
1099
|
amount: swap.destinationMint === "So11111111111111111111111111111111111111112" ? {
|
|
613
1100
|
asset: SOLANA_NATIVE_ASSET,
|
|
614
1101
|
amount: minimum.toString(10)
|
|
@@ -626,6 +1113,60 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
626
1113
|
message: `${swap.platformFeeBps} bps`
|
|
627
1114
|
});
|
|
628
1115
|
}
|
|
1116
|
+
if (call.kind === "amm-swap" && call.amm !== void 0) {
|
|
1117
|
+
const swap = call.amm;
|
|
1118
|
+
hasSwap = true;
|
|
1119
|
+
otherTransfer = true;
|
|
1120
|
+
const sourceMint = swap.sourceMint ?? atas.get(swap.sourceAccount)?.mint;
|
|
1121
|
+
const sourceToken = sourceMint === void 0 ? void 0 : lookupSolanaToken(table, request.network, sourceMint);
|
|
1122
|
+
outflows.push(sourceMint === void 0 ? {
|
|
1123
|
+
to: swap.program,
|
|
1124
|
+
amount: {
|
|
1125
|
+
asset: swap.sourceAccount,
|
|
1126
|
+
amount: swap.maxIn.toString(10)
|
|
1127
|
+
},
|
|
1128
|
+
verified: false,
|
|
1129
|
+
tokenAccount: swap.sourceAccount
|
|
1130
|
+
} : {
|
|
1131
|
+
to: swap.program,
|
|
1132
|
+
amount: sourceMint === "So11111111111111111111111111111111111111112" ? {
|
|
1133
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
1134
|
+
amount: swap.maxIn.toString(10)
|
|
1135
|
+
} : {
|
|
1136
|
+
asset: sourceMint,
|
|
1137
|
+
amount: swap.maxIn.toString(10),
|
|
1138
|
+
...sourceToken === void 0 ? {} : {
|
|
1139
|
+
symbol: sourceToken.symbol,
|
|
1140
|
+
decimals: sourceToken.decimals
|
|
1141
|
+
}
|
|
1142
|
+
},
|
|
1143
|
+
verified: sourceMint === "So11111111111111111111111111111111111111112" || sourceToken !== void 0
|
|
1144
|
+
});
|
|
1145
|
+
const destinationMint = swap.destinationMint ?? atas.get(swap.destinationAccount)?.mint;
|
|
1146
|
+
const destinationToken = destinationMint === void 0 ? void 0 : lookupSolanaToken(table, request.network, destinationMint);
|
|
1147
|
+
const ownAta = (swap.destinationTokenProgram === void 0 ? [PROGRAM_IDS.token, PROGRAM_IDS.token2022].map((p) => destinationMint === void 0 ? "" : associatedTokenAddress(signer, destinationMint, p)) : [destinationMint === void 0 ? "" : associatedTokenAddress(signer, destinationMint, swap.destinationTokenProgram)]).includes(swap.destinationAccount);
|
|
1148
|
+
minimumReceived.push(destinationMint === void 0 ? {
|
|
1149
|
+
to: swap.destinationAccount,
|
|
1150
|
+
amount: {
|
|
1151
|
+
asset: swap.destinationAccount,
|
|
1152
|
+
amount: swap.minOut.toString(10)
|
|
1153
|
+
},
|
|
1154
|
+
tokenAccount: swap.destinationAccount
|
|
1155
|
+
} : {
|
|
1156
|
+
to: ownAta ? signer : swap.destinationAccount,
|
|
1157
|
+
amount: destinationMint === "So11111111111111111111111111111111111111112" ? {
|
|
1158
|
+
asset: SOLANA_NATIVE_ASSET,
|
|
1159
|
+
amount: swap.minOut.toString(10)
|
|
1160
|
+
} : {
|
|
1161
|
+
asset: destinationMint,
|
|
1162
|
+
amount: swap.minOut.toString(10),
|
|
1163
|
+
...destinationToken === void 0 ? {} : {
|
|
1164
|
+
symbol: destinationToken.symbol,
|
|
1165
|
+
decimals: destinationToken.decimals
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
629
1170
|
if (call.kind === "core-transfer" && call.core !== void 0) {
|
|
630
1171
|
otherTransfer = true;
|
|
631
1172
|
outflows.push({
|
|
@@ -653,6 +1194,40 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
653
1194
|
verified: token !== void 0
|
|
654
1195
|
});
|
|
655
1196
|
}
|
|
1197
|
+
if (call.kind === "token-transfer" && call.tokenAccount !== void 0) {
|
|
1198
|
+
otherTransfer = true;
|
|
1199
|
+
outflows.push({
|
|
1200
|
+
to: call.to ?? "",
|
|
1201
|
+
amount: {
|
|
1202
|
+
asset: call.tokenAccount,
|
|
1203
|
+
amount: (call.amount ?? 0n).toString(10)
|
|
1204
|
+
},
|
|
1205
|
+
verified: false,
|
|
1206
|
+
tokenAccount: call.tokenAccount
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
if (call.kind === "token-burn") {
|
|
1210
|
+
otherTransfer = true;
|
|
1211
|
+
const token = lookupSolanaToken(table, request.network, call.mint ?? "");
|
|
1212
|
+
outflows.push({
|
|
1213
|
+
to: call.to ?? "",
|
|
1214
|
+
amount: {
|
|
1215
|
+
asset: call.mint ?? "",
|
|
1216
|
+
amount: (call.amount ?? 0n).toString(10),
|
|
1217
|
+
...token === void 0 ? {} : {
|
|
1218
|
+
symbol: token.symbol,
|
|
1219
|
+
decimals: token.decimals
|
|
1220
|
+
}
|
|
1221
|
+
},
|
|
1222
|
+
verified: token !== void 0,
|
|
1223
|
+
burn: true
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
if (call.kind === "token-revoke" && call.tokenAccount !== void 0) approvals.push({
|
|
1227
|
+
kind: "delegate-revoked",
|
|
1228
|
+
account: call.tokenAccount,
|
|
1229
|
+
verified: false
|
|
1230
|
+
});
|
|
656
1231
|
if (call.kind === "token-approve") {
|
|
657
1232
|
const token = lookupSolanaToken(table, request.network, call.mint ?? "");
|
|
658
1233
|
approvals.push({
|
|
@@ -738,6 +1313,14 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
738
1313
|
verified: true
|
|
739
1314
|
});
|
|
740
1315
|
break;
|
|
1316
|
+
case "split":
|
|
1317
|
+
staking.push({
|
|
1318
|
+
kind: "split",
|
|
1319
|
+
account: stake.account,
|
|
1320
|
+
to: stake.to,
|
|
1321
|
+
lamports: stake.lamports.toString(10)
|
|
1322
|
+
});
|
|
1323
|
+
break;
|
|
741
1324
|
case "authorize": if (stake.authority !== signer) approvals.push({
|
|
742
1325
|
kind: "stake-authority",
|
|
743
1326
|
account: stake.account,
|
|
@@ -747,27 +1330,81 @@ const decodeTransaction = (request, signer, table) => {
|
|
|
747
1330
|
});
|
|
748
1331
|
}
|
|
749
1332
|
}
|
|
750
|
-
const fee = feeLamports(parsed, calls);
|
|
751
|
-
const
|
|
1333
|
+
const fee = parsed.staticAccounts[0] === signer ? feeLamports(parsed, lookups, calls) : 0n;
|
|
1334
|
+
const programs = [];
|
|
1335
|
+
const authority = /* @__PURE__ */ new Map();
|
|
1336
|
+
const signerIndex = parsed.staticAccounts.indexOf(signer);
|
|
1337
|
+
const signerWritable = signerIndex !== -1 && isWritableIndex(parsed, signerIndex);
|
|
1338
|
+
const altWritable = parsed.lookups.some((l) => l.writableIndexes.length > 0);
|
|
1339
|
+
let blind;
|
|
1340
|
+
for (const [index, ix] of parsed.instructions.entries()) {
|
|
1341
|
+
const program = calls[index]?.kind === "other" ? resolveAccountIndex(parsed, ix.programAddressIndex, lookups) : void 0;
|
|
1342
|
+
if (program === void 0) continue;
|
|
1343
|
+
if (!programs.includes(program)) programs.push(program);
|
|
1344
|
+
const row = RECOGNISED_FAMILIES.find((family) => family.claim.surface === "solana.instruction" && PROGRAM_IDS[family.claim.program] === program);
|
|
1345
|
+
const takesSigner = ix.accountIndices.some((i) => i < parsed.numRequiredSignatures && parsed.staticAccounts[i] === signer);
|
|
1346
|
+
if (row !== void 0) {
|
|
1347
|
+
if (blind === void 0 && takesSigner) blind = row.nearMiss;
|
|
1348
|
+
continue;
|
|
1349
|
+
}
|
|
1350
|
+
if (!takesSigner) continue;
|
|
1351
|
+
const entry = authority.get(program) ?? {
|
|
1352
|
+
sol: signerWritable,
|
|
1353
|
+
accounts: []
|
|
1354
|
+
};
|
|
1355
|
+
for (const i of ix.accountIndices) {
|
|
1356
|
+
const account = resolveAccountIndex(parsed, i, lookups);
|
|
1357
|
+
if (account === void 0 || account === signer || !isWritableIndex(parsed, i) || entry.accounts.includes(account)) continue;
|
|
1358
|
+
entry.accounts.push(account);
|
|
1359
|
+
}
|
|
1360
|
+
authority.set(program, entry);
|
|
1361
|
+
if (blind === void 0 && (altWritable || entry.accounts.length > 12)) blind = "program-authority";
|
|
1362
|
+
}
|
|
1363
|
+
if (named.fromTable.size > 0) blind = "lookup-table-account";
|
|
1364
|
+
const summary = hasSwap ? "swap" : otherTransfer ? "transfer" : staking.length > 0 ? "stake" : outflows.length > 0 ? "transfer" : "contract-call";
|
|
1365
|
+
const programAuthority = [...authority.entries()].map(([program, entry]) => ({
|
|
1366
|
+
program,
|
|
1367
|
+
sol: entry.sol,
|
|
1368
|
+
accounts: entry.accounts.map((a) => {
|
|
1369
|
+
const token = atas.get(a);
|
|
1370
|
+
return token === void 0 ? { address: a } : {
|
|
1371
|
+
address: a,
|
|
1372
|
+
token
|
|
1373
|
+
};
|
|
1374
|
+
})
|
|
1375
|
+
}));
|
|
752
1376
|
return {
|
|
753
1377
|
family: "solana",
|
|
754
1378
|
network: request.network,
|
|
755
1379
|
summary,
|
|
756
1380
|
outflows,
|
|
757
1381
|
approvals,
|
|
758
|
-
fee:
|
|
1382
|
+
fee: { max: {
|
|
759
1383
|
asset: SOLANA_NATIVE_ASSET,
|
|
760
1384
|
amount: fee.toString(10)
|
|
761
1385
|
} },
|
|
762
1386
|
...staking.length === 0 ? {} : { staking },
|
|
763
1387
|
...minimumReceived.length === 0 ? {} : { minimumReceived },
|
|
1388
|
+
...programs.length === 0 ? {} : { programs },
|
|
1389
|
+
...programAuthority.length === 0 ? {} : { programAuthority },
|
|
764
1390
|
warnings,
|
|
765
|
-
verifiability
|
|
1391
|
+
verifiability,
|
|
1392
|
+
...blind === void 0 ? {} : { blind }
|
|
766
1393
|
};
|
|
767
1394
|
};
|
|
1395
|
+
/**
|
|
1396
|
+
* The resolved addresses a decoded intent would name to the user that come from caller-supplied
|
|
1397
|
+
* lookup-table contents — the set a transaction builder must keep as static keys so the intent it
|
|
1398
|
+
* signs is verifiable.
|
|
1399
|
+
*/
|
|
1400
|
+
const namedTableAccounts = (parsed, lookups) => {
|
|
1401
|
+
const named = namedAccounts(parsed, lookups);
|
|
1402
|
+
for (const ix of parsed.instructions) classifyIx(ix, named, "");
|
|
1403
|
+
return [...named.fromTable];
|
|
1404
|
+
};
|
|
768
1405
|
/** What the signer can guarantee about this request (WD-065). */
|
|
769
1406
|
const verifiabilitySolana = (request, signer, table = solanaTokenTable) => decodeSolana(request, signer, table).verifiability;
|
|
770
|
-
const decodeSolana = (request, signer, table = solanaTokenTable) => decodeTransaction(request, signer, table);
|
|
1407
|
+
const decodeSolana = (request, signer, table = solanaTokenTable) => withNativeAmountMeta(decodeTransaction(request, signer, table), request.network, SOLANA_NATIVE_ASSET, 9);
|
|
771
1408
|
// src/solana/token2022.ts
|
|
772
1409
|
/** SPL Token-2022 mint-account TLV extension type numbers (spl-token-2022 `ExtensionType`). */
|
|
773
1410
|
const EXT = {
|
|
@@ -858,6 +1495,69 @@ const verifySolanaSignature = (message, signature, accountAddress) => {
|
|
|
858
1495
|
return false;
|
|
859
1496
|
}
|
|
860
1497
|
};
|
|
1498
|
+
// src/solana/transaction.ts
|
|
1499
|
+
const transactionDecoder = getTransactionDecoder();
|
|
1500
|
+
/**
|
|
1501
|
+
* The structural half of `decodeSolanaTransaction`: the wire decodes, the message is a supported
|
|
1502
|
+
* compiled message, the whole transaction fits the version's size limit (a v1 wire puts the message
|
|
1503
|
+
* first and is 4096; legacy/v0 put a signature-count shortvec first and are 1232) and the signature
|
|
1504
|
+
* count agrees with the message header. Yields the message, its parse, and the signature slots in
|
|
1505
|
+
* wire order — the slot byte offset follows from them.
|
|
1506
|
+
*/
|
|
1507
|
+
const readTransaction = (wire) => {
|
|
1508
|
+
const limit = wire[0] === 129 ? V1_TRANSACTION_MAX_BYTES : LEGACY_TRANSACTION_MAX_BYTES;
|
|
1509
|
+
if (wire.length > limit) throw new ChainError("invalid-request", `transaction exceeds the ${limit}-byte limit`);
|
|
1510
|
+
let tx;
|
|
1511
|
+
try {
|
|
1512
|
+
tx = transactionDecoder.decode(wire);
|
|
1513
|
+
} catch {
|
|
1514
|
+
throw new ChainError("invalid-request", "transaction failed to decode");
|
|
1515
|
+
}
|
|
1516
|
+
const message = new Uint8Array(tx.messageBytes);
|
|
1517
|
+
const parsed = parseCompiledMessage(message);
|
|
1518
|
+
const slots = Object.entries(tx.signatures).map(([account, signature]) => [account, signature ?? void 0]);
|
|
1519
|
+
if (slots.length !== parsed.numRequiredSignatures) throw new ChainError("invalid-request", `transaction carries ${slots.length} signatures for ${parsed.numRequiredSignatures} required signers`);
|
|
1520
|
+
return {
|
|
1521
|
+
message,
|
|
1522
|
+
parsed,
|
|
1523
|
+
slots
|
|
1524
|
+
};
|
|
1525
|
+
};
|
|
1526
|
+
/**
|
|
1527
|
+
* Reads the serialized transaction `wire` as the Wallet Standard passes it for `signer`: the
|
|
1528
|
+
* compiled message the signer signs, and which other required signers have not signed yet. Every
|
|
1529
|
+
* non-empty signature slot must verify over the message — one that cannot land is refused.
|
|
1530
|
+
*/
|
|
1531
|
+
const decodeSolanaTransaction = (wire, signer) => {
|
|
1532
|
+
const { message, slots } = readTransaction(wire);
|
|
1533
|
+
if (!slots.some(([account]) => account === signer)) throw new ChainError("invalid-request", "signer is not a required signer of the transaction");
|
|
1534
|
+
const unsigned = [];
|
|
1535
|
+
for (const [account, signature] of slots) {
|
|
1536
|
+
if (signature === void 0) {
|
|
1537
|
+
if (account !== signer) unsigned.push(account);
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
if (!verifySolanaSignature(message, signature, account)) throw new ChainError("invalid-request", `the signature of ${account} does not verify`);
|
|
1541
|
+
}
|
|
1542
|
+
return {
|
|
1543
|
+
message,
|
|
1544
|
+
unsigned
|
|
1545
|
+
};
|
|
1546
|
+
};
|
|
1547
|
+
/**
|
|
1548
|
+
* `wire` with `signer`'s slot set to `signature`; every other byte unchanged — the other signatures
|
|
1549
|
+
* and their order are preserved byte for byte (a v1 wire keeps the message first).
|
|
1550
|
+
*/
|
|
1551
|
+
const addSolanaSignature = (wire, signer, signature) => {
|
|
1552
|
+
if (signature.length !== 64) throw new ChainError("invalid-request", "signature must be 64 bytes");
|
|
1553
|
+
const { message, parsed, slots } = readTransaction(wire);
|
|
1554
|
+
const index = slots.findIndex(([account]) => account === signer);
|
|
1555
|
+
if (index === -1) throw new ChainError("invalid-request", "signer is not a required signer of the transaction");
|
|
1556
|
+
const offset = parsed.version === 1 ? message.length + 64 * index : wire.length - message.length - 64 * (slots.length - index);
|
|
1557
|
+
const out = new Uint8Array(wire);
|
|
1558
|
+
out.set(signature, offset);
|
|
1559
|
+
return out;
|
|
1560
|
+
};
|
|
861
1561
|
// src/solana/index.ts
|
|
862
1562
|
const solanaNetwork = (network) => {
|
|
863
1563
|
if (!SOLANA_NETWORKS.includes(network)) throw new ChainError("unsupported", `unknown Solana network: ${network}`);
|
|
@@ -880,10 +1580,12 @@ const validateLookupTablesRaw = (tables) => {
|
|
|
880
1580
|
return parsed;
|
|
881
1581
|
};
|
|
882
1582
|
/**
|
|
883
|
-
* Normalizes a Solana sign request. `signer` is
|
|
884
|
-
* message must declare it
|
|
885
|
-
*
|
|
886
|
-
*
|
|
1583
|
+
* Normalizes a Solana sign request. `signer` is a required signer the wallet is about to sign for —
|
|
1584
|
+
* the message must declare it among the first `numRequiredSignatures` static accounts.
|
|
1585
|
+
* `lookupTables` may only accompany a v0 message — v1 has no address lookup tables (SIMD-0385). A
|
|
1586
|
+
* raw `solana.message` must not decode as a transaction message (chains.mdx rule — a bytes-to-sign
|
|
1587
|
+
* path that produces a transaction signature is a wallet-drainer): bytes a cluster could accept as
|
|
1588
|
+
* a transaction message of any version are never signed as a raw message. Idempotent.
|
|
887
1589
|
*/
|
|
888
1590
|
const normalizeSolana = (request, signer) => {
|
|
889
1591
|
if (!isRecord$1(request) || typeof request["kind"] !== "string") throw new ChainError("invalid-request", "request must be an object with a kind");
|
|
@@ -894,8 +1596,9 @@ const normalizeSolana = (request, signer) => {
|
|
|
894
1596
|
if (!(message instanceof Uint8Array)) throw new ChainError("invalid-request", "message must be bytes");
|
|
895
1597
|
if (request["kind"] === "solana.transaction") {
|
|
896
1598
|
const lookupTables = validateLookupTablesRaw(request["lookupTables"]);
|
|
897
|
-
const
|
|
898
|
-
if (
|
|
1599
|
+
const parsed = parseCompiledMessage(message);
|
|
1600
|
+
if (parsed.version === 1 && lookupTables !== void 0) throw new ChainError("invalid-request", "a v1 transaction has no address lookup tables");
|
|
1601
|
+
if (!parsed.staticAccounts.slice(0, parsed.numRequiredSignatures).includes(signer)) throw new ChainError("invalid-request", "signer is not a required signer of the transaction");
|
|
899
1602
|
return {
|
|
900
1603
|
kind: "solana.transaction",
|
|
901
1604
|
network,
|
|
@@ -910,13 +1613,7 @@ const normalizeSolana = (request, signer) => {
|
|
|
910
1613
|
if (request["kind"] === "solana.message") {
|
|
911
1614
|
const { format } = request;
|
|
912
1615
|
if (format !== "raw") throw new ChainError("unsupported", `solana.message format ${String(format)} is not supported`);
|
|
913
|
-
|
|
914
|
-
try {
|
|
915
|
-
parseCompiledMessage(message);
|
|
916
|
-
} catch {
|
|
917
|
-
decodesAsTransaction = false;
|
|
918
|
-
}
|
|
919
|
-
if (decodesAsTransaction) throw new ChainError("invalid-request", "solana.message payload decodes as a transaction message — use solana.transaction");
|
|
1616
|
+
if (mayBeTransactionMessage(message)) throw new ChainError("invalid-request", "solana.message payload could be a transaction message — use solana.transaction");
|
|
920
1617
|
return {
|
|
921
1618
|
kind: "solana.message",
|
|
922
1619
|
network,
|
|
@@ -927,6 +1624,6 @@ const normalizeSolana = (request, signer) => {
|
|
|
927
1624
|
}
|
|
928
1625
|
throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
|
|
929
1626
|
};
|
|
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 };
|
|
1627
|
+
export { EXT, JUPITER_PROGRAM, MPL_CORE_PROGRAM, PROGRAM_AUTHORITY_ACCOUNTS, PROGRAM_IDS, SOLANA_NATIVE_ASSET, SOLANA_NETWORKS, WSOL_MINT, addSolanaSignature, assembleSolana, associatedTokenAddress, decodeCoreIx, decodeSolana, decodeSolanaTransaction, isSolanaAddress, isWritableIndex, mayBeTransactionMessage, namedTableAccounts, netAfterTransferFee, normalizeSolana, parseCompiledMessage, parseMintExtensions, planSolana, solanaAddressFromPublicKey, solanaTokenTable, verifiabilitySolana, verifySolanaSignature };
|
|
931
1628
|
|
|
932
1629
|
//# sourceMappingURL=solana.mjs.map
|