@anywalletkit/protocol-swap2-jupiter 0.2.7 → 0.3.1
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 +7 -0
- package/dist/{chunk-RSAOKVP2.js → chunk-7C6Q32TG.js} +2 -2
- package/dist/{chunk-NESHFKWY.js → chunk-EY2HJJXY.js} +49 -2
- package/dist/chunk-EY2HJJXY.js.map +1 -0
- package/dist/index.cjs +45 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/protocol.cjs +47 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +2 -2
- package/dist/provider.cjs +47 -1
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-NESHFKWY.js.map +0 -1
- /package/dist/{chunk-RSAOKVP2.js.map → chunk-7C6Q32TG.js.map} +0 -0
package/README.md
CHANGED
|
@@ -41,6 +41,13 @@ after all of the following hold:
|
|
|
41
41
|
- the instructions call only Jupiter v6 (`JUP6Lkb…`) and the plumbing a swap
|
|
42
42
|
needs: compute budget, System, SPL Token / Token-2022, Associated Token;
|
|
43
43
|
- the taker is the only signer, and there is no tip instruction;
|
|
44
|
+
- every instruction besides the swap is one of the exact shapes a swap needs:
|
|
45
|
+
CreateIdempotent of the taker's own token account (the taker pays), a System
|
|
46
|
+
transfer of exactly the input into the taker's wSOL account (SOL source only,
|
|
47
|
+
once), SyncNative on that account, CloseAccount of it back to the taker, an
|
|
48
|
+
account initialized for the taker. Any other System / Token / Token-2022 /
|
|
49
|
+
Associated Token instruction — a transfer elsewhere, a TransferChecked, a
|
|
50
|
+
second Jupiter call — refuses the quote;
|
|
44
51
|
- the swap instruction is `route_v2` or `shared_accounts_route_v2` (ExactIn),
|
|
45
52
|
and its own arguments — the ones the program enforces on-chain — say exactly
|
|
46
53
|
our input amount, the quoted output in the answer, our slippage, and 0 bps
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
jupiterProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EY2HJJXY.js";
|
|
4
4
|
import {
|
|
5
5
|
jupiter
|
|
6
6
|
} from "./chunk-OVLAYYGP.js";
|
|
@@ -24,4 +24,4 @@ var JupiterSwap2Protocol = class extends SingleProviderSwap2 {
|
|
|
24
24
|
export {
|
|
25
25
|
JupiterSwap2Protocol
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-7C6Q32TG.js.map
|
|
@@ -11,17 +11,21 @@ import {
|
|
|
11
11
|
describeJupiterActivity
|
|
12
12
|
} from "./chunk-H4SP5E76.js";
|
|
13
13
|
import {
|
|
14
|
+
ATA_PROGRAM,
|
|
14
15
|
COMPUTE_BUDGET_PROGRAM,
|
|
15
16
|
JUPITER_API_DEFAULT,
|
|
16
17
|
JUPITER_PROGRAM,
|
|
17
18
|
JUPITER_TX_PROGRAMS,
|
|
18
19
|
SOLANA_CAIP2,
|
|
20
|
+
SYSTEM_PROGRAM,
|
|
21
|
+
TOKEN_PROGRAM,
|
|
19
22
|
WSOL_MINT,
|
|
20
23
|
jupiter,
|
|
21
24
|
jupiterMint
|
|
22
25
|
} from "./chunk-OVLAYYGP.js";
|
|
23
26
|
|
|
24
27
|
// src/provider.ts
|
|
28
|
+
import { address, getAddressEncoder, getProgramDerivedAddress } from "@solana/kit";
|
|
25
29
|
import { timeoutSignal } from "@anywalletkit/protocol-swap2-core/util";
|
|
26
30
|
var DEFAULT_SLIPPAGE_BPS = 50;
|
|
27
31
|
var MAX_SLIPPAGE_BPS = 1e3;
|
|
@@ -64,6 +68,35 @@ function jupiterProvider(config = {}) {
|
|
|
64
68
|
}
|
|
65
69
|
throw last;
|
|
66
70
|
};
|
|
71
|
+
const shapeRefusal = (ix, want) => {
|
|
72
|
+
const data = fromBase64(ix.data ?? "");
|
|
73
|
+
const acc = (i) => ix.accounts[i]?.pubkey;
|
|
74
|
+
if (ix.programId === ATA_PROGRAM) {
|
|
75
|
+
if (data.length !== 1 || data[0] !== 1) return "an associated-token instruction other than CreateIdempotent";
|
|
76
|
+
if (acc(0) !== want.taker || acc(2) !== want.taker) return "an associated token account for someone else";
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (ix.programId === SYSTEM_PROGRAM) {
|
|
80
|
+
if (data.length !== 12 || data[0] !== 2 || data[1] !== 0 || data[2] !== 0 || data[3] !== 0) return "a System instruction other than Transfer";
|
|
81
|
+
if (want.inputMint !== WSOL_MINT) return "a SOL transfer on a token-source swap";
|
|
82
|
+
const lamports = new DataView(data.buffer, data.byteOffset + 4, 8).getBigUint64(0, true);
|
|
83
|
+
if (acc(0) !== want.taker || acc(1) !== want.wsolAta) return `a SOL transfer to ${acc(1)}, not the taker's wSOL account`;
|
|
84
|
+
if (lamports !== want.amountIn) return `a SOL transfer of ${lamports}, not the ${want.amountIn} input`;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (ix.programId === TOKEN_PROGRAM) {
|
|
88
|
+
if (data.length === 1 && data[0] === 17) return acc(0) === want.wsolAta ? null : "SyncNative on another account";
|
|
89
|
+
if (data.length === 1 && data[0] === 9) {
|
|
90
|
+
return acc(0) === want.wsolAta && acc(1) === want.taker && acc(2) === want.taker ? null : "a CloseAccount that is not the taker's wSOL account back to the taker";
|
|
91
|
+
}
|
|
92
|
+
if (data.length === 33 && data[0] === 18) {
|
|
93
|
+
return bytesEqual(data.subarray(1), getAddressEncoder().encode(address(want.taker))) ? null : "a token account initialized for someone else";
|
|
94
|
+
}
|
|
95
|
+
return `a Token instruction (tag ${data[0] ?? "none"}) the swap does not need`;
|
|
96
|
+
}
|
|
97
|
+
if (ix.programId === JUPITER_PROGRAM) return "a second Jupiter instruction";
|
|
98
|
+
return `instruction for program ${ix.programId}`;
|
|
99
|
+
};
|
|
67
100
|
const vet = (b, want) => {
|
|
68
101
|
if (b.swapMode && b.swapMode !== "ExactIn") throw new Error(`swap mode ${b.swapMode}`);
|
|
69
102
|
if (b.inputMint !== want.inputMint || b.outputMint !== want.outputMint) throw new Error("the answer names other mints");
|
|
@@ -84,9 +117,17 @@ function jupiterProvider(config = {}) {
|
|
|
84
117
|
if (d.price !== void 0) price = d.price;
|
|
85
118
|
}
|
|
86
119
|
const instructions = [...b.setupInstructions ?? [], b.swapInstruction, ...b.cleanupInstruction ? [b.cleanupInstruction] : [], ...b.otherInstructions ?? []];
|
|
120
|
+
let funded = false;
|
|
87
121
|
for (const ix of instructions) {
|
|
88
122
|
if (!JUPITER_TX_PROGRAMS.has(ix.programId) || ix.programId === COMPUTE_BUDGET_PROGRAM) throw new Error(`instruction for program ${ix.programId}`);
|
|
89
123
|
for (const a of ix.accounts) if (a.isSigner && a.pubkey !== want.taker) throw new Error(`instruction needs signer ${a.pubkey}`);
|
|
124
|
+
if (ix === b.swapInstruction) continue;
|
|
125
|
+
const why = shapeRefusal(ix, want);
|
|
126
|
+
if (why) throw new Error(why);
|
|
127
|
+
if (ix.programId === SYSTEM_PROGRAM) {
|
|
128
|
+
if (funded) throw new Error("a second SOL transfer");
|
|
129
|
+
funded = true;
|
|
130
|
+
}
|
|
90
131
|
}
|
|
91
132
|
return { instructions, price: price > maxPrice ? maxPrice : price, quotedOut: args.quotedOutAmount };
|
|
92
133
|
};
|
|
@@ -155,8 +196,9 @@ function jupiterProvider(config = {}) {
|
|
|
155
196
|
}
|
|
156
197
|
if (!b.outAmount || !/^\d+$/.test(b.outAmount)) return refuse("answer without an output amount");
|
|
157
198
|
let vetted;
|
|
199
|
+
const [wsolAta] = await getProgramDerivedAddress({ programAddress: address(ATA_PROGRAM), seeds: [getAddressEncoder().encode(address(taker)), getAddressEncoder().encode(address(TOKEN_PROGRAM)), getAddressEncoder().encode(address(WSOL_MINT))] });
|
|
158
200
|
try {
|
|
159
|
-
vetted = vet(b, { taker, inputMint, outputMint, amountIn, slippageBps });
|
|
201
|
+
vetted = vet(b, { taker, inputMint, outputMint, amountIn, slippageBps, wsolAta });
|
|
160
202
|
} catch (e) {
|
|
161
203
|
return refuse(e.message);
|
|
162
204
|
}
|
|
@@ -233,8 +275,13 @@ function jupiterProvider(config = {}) {
|
|
|
233
275
|
}
|
|
234
276
|
};
|
|
235
277
|
}
|
|
278
|
+
function bytesEqual(a, b) {
|
|
279
|
+
if (a.length !== b.length) return false;
|
|
280
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
236
283
|
|
|
237
284
|
export {
|
|
238
285
|
jupiterProvider
|
|
239
286
|
};
|
|
240
|
-
//# sourceMappingURL=chunk-
|
|
287
|
+
//# sourceMappingURL=chunk-EY2HJJXY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["/**\n * Jupiter provider — Swap API V2 Router path, same-chain Solana swaps:\n * quote + instructions GET /swap/v2/build?inputMint&outputMint&amount&taker&slippageBps\n * status getSignatureStatuses on the caller's own Solana RPC (optional)\n * Routing is Metis (Jupiter's on-chain router); the Router path charges no Jupiter swap fee. Keyless access works at\n * 0.5 RPS; pass `apiKey` (sent as `x-api-key`) for a plan's rate limit.\n *\n * Nothing from the API is trusted as-is. Before a live quote is handed out, every instruction is checked: only the\n * Jupiter program and the token / system / ATA / compute-budget plumbing, the taker is the only signer, no tip, and\n * the swap instruction's own arguments (decoded) carry exactly our input amount, the quoted output, our slippage and\n * a zero platform fee — those are what the program enforces on-chain. The compute budget is rebuilt here: a unit price\n * capped by `maxComputeUnitPrice`, and a unit limit from a simulation (1.2× the units used) when `rpcUrls` is given.\n * The account then executes the assembled transaction through its serialized-transaction guard (simulation +\n * balance proof against the quote) and broadcasts it through its own RPC.\n */\nimport {describeJupiterActivity} from \"./activity.js\";\nimport {ATA_PROGRAM, JUPITER_API_DEFAULT, JUPITER_PROGRAM, JUPITER_TX_PROGRAMS, COMPUTE_BUDGET_PROGRAM, SOLANA_CAIP2, SYSTEM_PROGRAM, TOKEN_PROGRAM, WSOL_MINT, jupiter as cfg, jupiterMint} from \"./config.js\";\nimport {address, getAddressEncoder, getProgramDerivedAddress} from \"@solana/kit\";\nimport {decodeComputeBudget, decodeSwapArgs, fromBase64, minOutOf} from \"./codec.js\";\nimport {assembleTransaction, type JupiterInstruction} from \"./transaction.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\nconst DEFAULT_SLIPPAGE_BPS = 50;\nconst MAX_SLIPPAGE_BPS = 1_000;\n/** A /build blockhash lives ~60–90 s; the quote must be signed well inside it. */\nconst QUOTE_TTL_MS = 30_000;\nconst MAX_COMPUTE_UNITS = 1_400_000;\n/** 2 000 000 µlamports/CU: at 1.4 M CU the priority fee is ≤ 0.0028 SOL. */\nconst DEFAULT_MAX_CU_PRICE = 2_000_000n;\nconst BASE_FEE_LAMPORTS = 5_000n;\n/** Taker for a dry quote with no address yet: /build needs one, the price does not depend on it. */\nconst DRY_TAKER = \"9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM\";\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\nexport interface JupiterProviderConfig {\n enabled?: boolean;\n /** Swap API base (default https://api.jup.ag/swap/v2). */\n apiUrl?: string;\n /** Jupiter Developer Platform key, sent as `x-api-key`. Keyless works at 0.5 RPS. */\n apiKey?: string;\n /** Solana JSON-RPC endpoints: compute-unit simulation and status. Without them the limit is 1.4 M CU and status stays pending. */\n rpcUrls?: readonly string[];\n /** Ceiling on the compute-unit price Jupiter suggests, micro-lamports (default 2 000 000). */\n maxComputeUnitPrice?: bigint;\n /** Passed to /build: \"medium\" | \"high\" | \"veryHigh\" or a percentile in bps (default: Jupiter's 50th percentile). */\n computeUnitPricePercentile?: string;\n /** Slippage when the caller names none, bps (default 50). */\n defaultSlippageBps?: number;\n}\n\ninterface BuildResponse {\n inputMint?: string;\n outputMint?: string;\n inAmount?: string;\n outAmount?: string;\n otherAmountThreshold?: string;\n swapMode?: string;\n slippageBps?: number;\n priceImpactPct?: string;\n routePlan?: {bps?: number; swapInfo?: {label?: string}}[];\n computeBudgetInstructions?: JupiterInstruction[];\n setupInstructions?: JupiterInstruction[];\n swapInstruction?: JupiterInstruction;\n cleanupInstruction?: JupiterInstruction | null;\n otherInstructions?: JupiterInstruction[];\n tipInstruction?: JupiterInstruction | null;\n addressesByLookupTableAddress?: Record<string, string[]> | null;\n transactionVersion?: number | string;\n blockhashWithMetadata?: {blockhash?: number[]; lastValidBlockHeight?: number};\n error?: string;\n}\n\nconst INTENT_PREFIX = \"jup:\";\n\nexport function jupiterProvider(config: JupiterProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const base = (config.apiUrl ?? JUPITER_API_DEFAULT).replace(/\\/$/, \"\");\n const maxPrice = config.maxComputeUnitPrice ?? DEFAULT_MAX_CU_PRICE;\n const rpcUrls = config.rpcUrls ?? [];\n\n /** One GET with a single back-off on 429 (keyless traffic is 0.5 RPS), waiting for `x-ratelimit-reset` when given. */\n const get = async (path: string, signal?: AbortSignal): Promise<{ok: boolean; status: number; body: unknown}> => {\n for (let attempt = 0; ; attempt++) {\n const res = await fetch(`${base}${path}`, {headers: {accept: \"application/json\", ...(config.apiKey ? {\"x-api-key\": config.apiKey} : {})}, signal: signal ?? timeoutSignal(12_000)});\n const body = await res.json().catch(() => null);\n if (res.status === 429 && attempt === 0 && !signal?.aborted) {\n const reset = Number(res.headers.get(\"x-ratelimit-reset\"));\n const wait = Number.isFinite(reset) && reset > 0 ? Math.min(3_000, Math.max(250, reset * 1000 - Date.now())) : 1_200;\n await new Promise((r) => setTimeout(r, wait));\n continue;\n }\n return {ok: res.ok, status: res.status, body};\n }\n };\n\n const rpc = async (method: string, params: unknown[]): Promise<unknown> => {\n let last: unknown = new Error(\"no Solana RPC configured\");\n for (const url of rpcUrls) {\n try {\n const res = await fetch(url, {method: \"POST\", headers: {\"content-type\": \"application/json\"}, body: JSON.stringify({jsonrpc: \"2.0\", id: 1, method, params}), signal: timeoutSignal(10_000)});\n const body = (await res.json()) as {result?: unknown; error?: {message?: string}};\n if (body.error) throw new Error(body.error.message ?? \"rpc error\");\n return body.result;\n } catch (e) { last = e; }\n }\n throw last;\n };\n\n /**\n * The setup / cleanup / other instructions /build may carry, by exact shape (scan 2026-10-27 modules, F32/F33):\n * creating the taker's own ATAs, funding the taker's wSOL account with exactly the input (a SOL source), syncing and\n * closing it back to the taker. Anything else — a System transfer elsewhere, a token transfer, a second Jupiter call —\n * is refused; the wallet's balance proof alone let a few hundredths of a SOL and the slippage band leave per swap.\n */\n const shapeRefusal = (ix: JupiterInstruction, want: {taker: string; inputMint: string; amountIn: bigint; wsolAta: string}): string | null => {\n const data = fromBase64(ix.data ?? \"\");\n const acc = (i: number) => ix.accounts[i]?.pubkey;\n if (ix.programId === ATA_PROGRAM) {\n // CreateIdempotent: [payer, ata, owner, mint, system, token program] — the taker pays for its own account.\n if (data.length !== 1 || data[0] !== 1) return \"an associated-token instruction other than CreateIdempotent\";\n if (acc(0) !== want.taker || acc(2) !== want.taker) return \"an associated token account for someone else\";\n return null;\n }\n if (ix.programId === SYSTEM_PROGRAM) {\n // Transfer: u32 LE 2 + u64 lamports, [from, to] — only the input, into the taker's own wSOL account.\n if (data.length !== 12 || data[0] !== 2 || data[1] !== 0 || data[2] !== 0 || data[3] !== 0) return \"a System instruction other than Transfer\";\n if (want.inputMint !== WSOL_MINT) return \"a SOL transfer on a token-source swap\";\n const lamports = new DataView(data.buffer, data.byteOffset + 4, 8).getBigUint64(0, true);\n if (acc(0) !== want.taker || acc(1) !== want.wsolAta) return `a SOL transfer to ${acc(1)}, not the taker's wSOL account`;\n if (lamports !== want.amountIn) return `a SOL transfer of ${lamports}, not the ${want.amountIn} input`;\n return null;\n }\n if (ix.programId === TOKEN_PROGRAM) {\n if (data.length === 1 && data[0] === 17) return acc(0) === want.wsolAta ? null : \"SyncNative on another account\"; // SyncNative\n if (data.length === 1 && data[0] === 9) { // CloseAccount: [account, destination, owner]\n return acc(0) === want.wsolAta && acc(1) === want.taker && acc(2) === want.taker ? null : \"a CloseAccount that is not the taker's wSOL account back to the taker\";\n }\n if (data.length === 33 && data[0] === 18) { // InitializeAccount3(owner): an account the taker owns\n return bytesEqual(data.subarray(1), getAddressEncoder().encode(address(want.taker))) ? null : \"a token account initialized for someone else\";\n }\n return `a Token instruction (tag ${data[0] ?? \"none\"}) the swap does not need`;\n }\n if (ix.programId === JUPITER_PROGRAM) return \"a second Jupiter instruction\";\n return `instruction for program ${ix.programId}`;\n };\n\n /** Every instruction the API returned, checked; returns the ordered list to assemble and the suggested unit price. */\n const vet = (b: BuildResponse, want: {taker: string; inputMint: string; outputMint: string; amountIn: bigint; slippageBps: number; wsolAta: string}): {instructions: JupiterInstruction[]; price: bigint; quotedOut: bigint} => {\n if (b.swapMode && b.swapMode !== \"ExactIn\") throw new Error(`swap mode ${b.swapMode}`);\n if (b.inputMint !== want.inputMint || b.outputMint !== want.outputMint) throw new Error(\"the answer names other mints\");\n if (b.inAmount !== want.amountIn.toString()) throw new Error(`the answer spends ${b.inAmount}, not ${want.amountIn}`);\n if (String(b.transactionVersion ?? \"0\") !== \"0\") throw new Error(`transaction version ${b.transactionVersion}`);\n if (b.tipInstruction) throw new Error(\"unexpected tip instruction\");\n if (!b.swapInstruction) throw new Error(\"no swap instruction\");\n if (b.swapInstruction.programId !== JUPITER_PROGRAM) throw new Error(`swap instruction targets ${b.swapInstruction.programId}`);\n const args = decodeSwapArgs(fromBase64(b.swapInstruction.data));\n if (args.inAmount !== want.amountIn) throw new Error(`swap instruction spends ${args.inAmount}, not ${want.amountIn}`);\n if (String(args.quotedOutAmount) !== b.outAmount) throw new Error(\"swap instruction's quoted output differs from the answer\");\n if (args.slippageBps !== want.slippageBps) throw new Error(`swap instruction allows ${args.slippageBps} bps slippage, not ${want.slippageBps}`);\n if (args.platformFeeBps !== 0 || args.positiveSlippageBps !== 0) throw new Error(\"swap instruction takes a platform fee\");\n let price = 0n;\n for (const ix of b.computeBudgetInstructions ?? []) {\n if (ix.programId !== COMPUTE_BUDGET_PROGRAM) throw new Error(`compute-budget slot holds ${ix.programId}`);\n const d = decodeComputeBudget(fromBase64(ix.data));\n if (d.price !== undefined) price = d.price;\n }\n const instructions = [...(b.setupInstructions ?? []), b.swapInstruction, ...(b.cleanupInstruction ? [b.cleanupInstruction] : []), ...(b.otherInstructions ?? [])];\n let funded = false;\n for (const ix of instructions) {\n if (!JUPITER_TX_PROGRAMS.has(ix.programId) || ix.programId === COMPUTE_BUDGET_PROGRAM) throw new Error(`instruction for program ${ix.programId}`);\n for (const a of ix.accounts) if (a.isSigner && a.pubkey !== want.taker) throw new Error(`instruction needs signer ${a.pubkey}`);\n if (ix === b.swapInstruction) continue;\n const why = shapeRefusal(ix, want);\n if (why) throw new Error(why);\n if (ix.programId === SYSTEM_PROGRAM) {\n if (funded) throw new Error(\"a second SOL transfer\");\n funded = true;\n }\n }\n return {instructions, price: price > maxPrice ? maxPrice : price, quotedOut: args.quotedOutAmount};\n };\n\n /** 1.2× the units a simulation uses (capped); null when no RPC answers. A failing simulation refuses the quote. */\n const simulateUnits = async (wire: string): Promise<number | null> => {\n if (!rpcUrls.length) return null;\n let r: {value?: {err?: unknown; unitsConsumed?: number; logs?: string[]}};\n try {\n r = (await rpc(\"simulateTransaction\", [wire, {encoding: \"base64\", sigVerify: false, replaceRecentBlockhash: true, commitment: \"processed\"}])) as typeof r;\n } catch {\n return null;\n }\n if (r?.value?.err) {\n const log = (r.value.logs ?? []).filter((l) => /error|failed|insufficient/i.test(l)).slice(-1)[0] ?? \"\";\n const err = JSON.stringify(r.value.err);\n // The usual reason, said plainly: the wallet lacks the input. Confirmed 2026-10-24 by building the same\n // USDS / LINK / WBTC → USDC swaps from an empty wallet (6025) and from real holders (built fine).\n // Jupiter 6024 = insufficient funds, 6025 = no token account for the input; System Program 1 = not enough SOL.\n const jupiterCode = /JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 failed/.test(log) ? /\"Custom\":(\\d+)/.exec(err)?.[1] : undefined;\n if (jupiterCode === \"6024\" || jupiterCode === \"6025\" || (/\"Custom\":1\\}/.test(err) && /Program 11111111111111111111111111111111 failed/.test(log))) {\n throw new Error(`not enough of the input token in the wallet${jupiterCode === \"6025\" ? \" (no token account for it)\" : \"\"} — simulation fails: ${err}`);\n }\n throw new Error(`simulation fails: ${err}${log ? ` (${log.slice(0, 160)})` : \"\"}`);\n }\n const used = r?.value?.unitsConsumed;\n return used ? Math.min(MAX_COMPUTE_UNITS, Math.ceil(used * 1.2)) : null;\n };\n\n return {\n name: \"jupiter\",\n describeActivity: describeJupiterActivity,\n enabled: () => config.enabled ?? true,\n supportsSameChain: true,\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (from: string, to: string) => cfg.supports(from, to),\n supportsRoute(from: Asset, to: Asset): boolean {\n if (!cfg.supports(from.chain, to.chain)) return false;\n const a = jupiterMint(from.token), b = jupiterMint(to.token);\n return !!a && !!b && a !== b;\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n const dry = params.dry !== false;\n const refuse = (reason: string): null => {\n params.onRefusal?.(`jupiter: ${reason}`);\n return null;\n };\n if (!cfg.supports(params.sourceChain, params.destChain)) return refuse(`same-chain Solana only (${params.sourceChain} → ${params.destChain})`);\n if (params.flex) return refuse(\"amount-flexible deposits are not supported\");\n const inputMint = jupiterMint(params.sourceToken), outputMint = jupiterMint(params.destToken);\n if (!inputMint || !outputMint) return refuse(`unknown token (${params.sourceToken} → ${params.destToken})`);\n if (inputMint === outputMint) return refuse(\"same token on both sides\");\n const amountIn = BigInt(params.amountIn);\n if (amountIn <= 0n) return refuse(\"amount must be positive\");\n const slippageBps = params.slippageBps ?? config.defaultSlippageBps ?? DEFAULT_SLIPPAGE_BPS;\n if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > MAX_SLIPPAGE_BPS) return refuse(`slippage ${slippageBps} bps is out of range`);\n\n // The swap pays the taker's own token account: a live quote must be for the signer's own address.\n const self = params.refundAddress || params.destAddress;\n if (!dry) {\n if (!self || !BASE58.test(self)) return refuse(\"live quote without the signer's address\");\n if (params.destAddress && params.destAddress !== self) return refuse(\"the recipient must be the signing wallet (Jupiter pays the taker)\");\n }\n const taker = self && BASE58.test(self) ? self : DRY_TAKER;\n\n const qs = new URLSearchParams({inputMint, outputMint, amount: params.amountIn, taker, slippageBps: String(slippageBps)});\n if (config.computeUnitPricePercentile) qs.set(\"computeUnitPricePercentile\", config.computeUnitPricePercentile);\n let b: BuildResponse;\n try {\n const r = await get(`/build?${qs.toString()}`, signal);\n if (!r.ok) return refuse(`build ${r.status}: ${String((r.body as BuildResponse | null)?.error ?? \"\").slice(0, 160)}`);\n b = (r.body ?? {}) as BuildResponse;\n } catch (e) { return refuse(`build failed: ${(e as Error).message.slice(0, 160)}`); }\n if (!b.outAmount || !/^\\d+$/.test(b.outAmount)) return refuse(\"answer without an output amount\");\n\n let vetted: ReturnType<typeof vet>;\n const [wsolAta] = await getProgramDerivedAddress({programAddress: address(ATA_PROGRAM), seeds: [getAddressEncoder().encode(address(taker)), getAddressEncoder().encode(address(TOKEN_PROGRAM)), getAddressEncoder().encode(address(WSOL_MINT))]});\n try { vetted = vet(b, {taker, inputMint, outputMint, amountIn, slippageBps, wsolAta}); } catch (e) { return refuse((e as Error).message); }\n const minOut = minOutOf(vetted.quotedOut, slippageBps);\n if (params.minAmountOut !== undefined && minOut < BigInt(params.minAmountOut)) {\n return refuse(`guaranteed ${minOut} is below the floor ${params.minAmountOut} at ${slippageBps} bps`);\n }\n const route = (b.routePlan ?? []).map((s) => s.swapInfo?.label).filter(Boolean).join(\" + \");\n const impact = Number(b.priceImpactPct ?? 0);\n const common = {\n provider: \"jupiter\",\n depositAddress: \"\",\n depositMemo: null,\n sourceAmount: params.amountIn,\n destAmount: b.outAmount,\n minDestAmount: minOut.toString(),\n feeUsd: 0,\n etaSeconds: 15,\n reliability: impact > 0.05 ? 0.8 : 0.97,\n validUntilMs: Date.now() + QUOTE_TTL_MS,\n };\n if (dry) {\n return {...common, intentId: `dry:${INTENT_PREFIX}${Date.now().toString(36)}`, fees: [{type: \"network\" as const, amount: BASE_FEE_LAMPORTS.toString(), token: \"native\", included: false, description: \"Solana base fee\"}], ...(route ? {providerData: {route}} : {})};\n }\n\n const blockhash = b.blockhashWithMetadata?.blockhash;\n const lastValid = b.blockhashWithMetadata?.lastValidBlockHeight;\n if (!blockhash || blockhash.length !== 32 || !lastValid) return refuse(\"answer without a blockhash\");\n const assemble = (limit: number) => assembleTransaction({\n taker, instructions: vetted.instructions, computeUnitLimit: limit, computeUnitPrice: vetted.price,\n blockhash: Uint8Array.from(blockhash), lastValidBlockHeight: lastValid, addressesByLookupTableAddress: b.addressesByLookupTableAddress,\n });\n let wire: string, limit = MAX_COMPUTE_UNITS;\n try {\n wire = assemble(MAX_COMPUTE_UNITS);\n const units = await simulateUnits(wire);\n if (units) { limit = units; wire = assemble(units); }\n } catch (e) { return refuse((e as Error).message.slice(0, 240)); }\n const priority = (vetted.price * BigInt(limit) + 999_999n) / 1_000_000n;\n return {\n ...common,\n intentId: `${INTENT_PREFIX}${lastValid}:${Date.now().toString(36)}`,\n // `value` declares the native SOL the transaction may take: the input for a SOL source (Jupiter wraps it), none for a token.\n txRequest: {serializedTx: wire, value: inputMint === WSOL_MINT ? params.amountIn : \"0\"},\n fees: [{type: \"network\", amount: (BASE_FEE_LAMPORTS + priority).toString(), token: \"native\", included: false, description: `Solana base + priority fee (${limit} CU at ${vetted.price} µlamports)`}],\n providerData: {inputMint, outputMint, slippageBps: String(slippageBps), computeUnits: String(limit), ...(route ? {route} : {})},\n };\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n const tx = quote.txRequest?.serializedTx;\n if (!tx || quote.intentId.startsWith(\"dry:\")) throw new Error(\"jupiter: not a live quote\");\n return {chain: SOLANA_CAIP2, to: \"\", value: quote.txRequest!.value ?? \"0\", serializedTx: tx};\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n if (!ref.sourceTxHash || !rpcUrls.length) return {state: \"pending\"};\n try {\n const r = (await rpc(\"getSignatureStatuses\", [[ref.sourceTxHash], {searchTransactionHistory: true}])) as {value?: ({err?: unknown; confirmationStatus?: string} | null)[]};\n const s = r?.value?.[0];\n if (!s) return {state: \"pending\"};\n if (s.err) return {state: \"failed\"};\n return s.confirmationStatus === \"confirmed\" || s.confirmationStatus === \"finalized\" ? {state: \"completed\", destTxHash: ref.sourceTxHash} : {state: \"pending\"};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n\nfunction bytesEqual(a: ArrayLike<number>, b: ArrayLike<number>): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAQ,SAAS,mBAAmB,gCAA+B;AAGnE,SAAQ,qBAAoB;AAG5B,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AAEzB,IAAM,eAAe;AACrB,IAAM,oBAAoB;AAE1B,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB;AAE1B,IAAM,YAAY;AAClB,IAAM,SAAS;AAwCf,IAAM,gBAAgB;AAEf,SAAS,gBAAgB,SAAgC,CAAC,GAAuB;AACtF,WAAS,OAAO,OAAO,EAAC,GAAG,OAAM,CAAC;AAClC,QAAM,QAAQ,OAAO,UAAU,qBAAqB,QAAQ,OAAO,EAAE;AACrE,QAAM,WAAW,OAAO,uBAAuB;AAC/C,QAAM,UAAU,OAAO,WAAW,CAAC;AAGnC,QAAM,MAAM,OAAO,MAAc,WAAgF;AAC/G,aAAS,UAAU,KAAK,WAAW;AACjC,YAAM,MAAM,MAAM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AAO;AAClC,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,IAAK,KAAI,EAAE,CAAC,MAAM,EAAE,CAAC,EAAG,QAAO;AAC7D,SAAO;AACT;","names":["limit"]}
|
package/dist/index.cjs
CHANGED
|
@@ -160,6 +160,7 @@ function describeJupiterActivity(tx, ctx) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// src/provider.ts
|
|
163
|
+
var import_kit2 = require("@solana/kit");
|
|
163
164
|
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
164
165
|
var DEFAULT_SLIPPAGE_BPS = 50;
|
|
165
166
|
var MAX_SLIPPAGE_BPS = 1e3;
|
|
@@ -202,6 +203,35 @@ function jupiterProvider(config = {}) {
|
|
|
202
203
|
}
|
|
203
204
|
throw last;
|
|
204
205
|
};
|
|
206
|
+
const shapeRefusal = (ix, want) => {
|
|
207
|
+
const data = fromBase64(ix.data ?? "");
|
|
208
|
+
const acc = (i) => ix.accounts[i]?.pubkey;
|
|
209
|
+
if (ix.programId === ATA_PROGRAM) {
|
|
210
|
+
if (data.length !== 1 || data[0] !== 1) return "an associated-token instruction other than CreateIdempotent";
|
|
211
|
+
if (acc(0) !== want.taker || acc(2) !== want.taker) return "an associated token account for someone else";
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
if (ix.programId === SYSTEM_PROGRAM) {
|
|
215
|
+
if (data.length !== 12 || data[0] !== 2 || data[1] !== 0 || data[2] !== 0 || data[3] !== 0) return "a System instruction other than Transfer";
|
|
216
|
+
if (want.inputMint !== WSOL_MINT) return "a SOL transfer on a token-source swap";
|
|
217
|
+
const lamports = new DataView(data.buffer, data.byteOffset + 4, 8).getBigUint64(0, true);
|
|
218
|
+
if (acc(0) !== want.taker || acc(1) !== want.wsolAta) return `a SOL transfer to ${acc(1)}, not the taker's wSOL account`;
|
|
219
|
+
if (lamports !== want.amountIn) return `a SOL transfer of ${lamports}, not the ${want.amountIn} input`;
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
if (ix.programId === TOKEN_PROGRAM) {
|
|
223
|
+
if (data.length === 1 && data[0] === 17) return acc(0) === want.wsolAta ? null : "SyncNative on another account";
|
|
224
|
+
if (data.length === 1 && data[0] === 9) {
|
|
225
|
+
return acc(0) === want.wsolAta && acc(1) === want.taker && acc(2) === want.taker ? null : "a CloseAccount that is not the taker's wSOL account back to the taker";
|
|
226
|
+
}
|
|
227
|
+
if (data.length === 33 && data[0] === 18) {
|
|
228
|
+
return bytesEqual(data.subarray(1), (0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(want.taker))) ? null : "a token account initialized for someone else";
|
|
229
|
+
}
|
|
230
|
+
return `a Token instruction (tag ${data[0] ?? "none"}) the swap does not need`;
|
|
231
|
+
}
|
|
232
|
+
if (ix.programId === JUPITER_PROGRAM) return "a second Jupiter instruction";
|
|
233
|
+
return `instruction for program ${ix.programId}`;
|
|
234
|
+
};
|
|
205
235
|
const vet = (b, want) => {
|
|
206
236
|
if (b.swapMode && b.swapMode !== "ExactIn") throw new Error(`swap mode ${b.swapMode}`);
|
|
207
237
|
if (b.inputMint !== want.inputMint || b.outputMint !== want.outputMint) throw new Error("the answer names other mints");
|
|
@@ -222,9 +252,17 @@ function jupiterProvider(config = {}) {
|
|
|
222
252
|
if (d.price !== void 0) price = d.price;
|
|
223
253
|
}
|
|
224
254
|
const instructions = [...b.setupInstructions ?? [], b.swapInstruction, ...b.cleanupInstruction ? [b.cleanupInstruction] : [], ...b.otherInstructions ?? []];
|
|
255
|
+
let funded = false;
|
|
225
256
|
for (const ix of instructions) {
|
|
226
257
|
if (!JUPITER_TX_PROGRAMS.has(ix.programId) || ix.programId === COMPUTE_BUDGET_PROGRAM) throw new Error(`instruction for program ${ix.programId}`);
|
|
227
258
|
for (const a of ix.accounts) if (a.isSigner && a.pubkey !== want.taker) throw new Error(`instruction needs signer ${a.pubkey}`);
|
|
259
|
+
if (ix === b.swapInstruction) continue;
|
|
260
|
+
const why = shapeRefusal(ix, want);
|
|
261
|
+
if (why) throw new Error(why);
|
|
262
|
+
if (ix.programId === SYSTEM_PROGRAM) {
|
|
263
|
+
if (funded) throw new Error("a second SOL transfer");
|
|
264
|
+
funded = true;
|
|
265
|
+
}
|
|
228
266
|
}
|
|
229
267
|
return { instructions, price: price > maxPrice ? maxPrice : price, quotedOut: args.quotedOutAmount };
|
|
230
268
|
};
|
|
@@ -293,8 +331,9 @@ function jupiterProvider(config = {}) {
|
|
|
293
331
|
}
|
|
294
332
|
if (!b.outAmount || !/^\d+$/.test(b.outAmount)) return refuse("answer without an output amount");
|
|
295
333
|
let vetted;
|
|
334
|
+
const [wsolAta] = await (0, import_kit2.getProgramDerivedAddress)({ programAddress: (0, import_kit2.address)(ATA_PROGRAM), seeds: [(0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(taker)), (0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(TOKEN_PROGRAM)), (0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(WSOL_MINT))] });
|
|
296
335
|
try {
|
|
297
|
-
vetted = vet(b, { taker, inputMint, outputMint, amountIn, slippageBps });
|
|
336
|
+
vetted = vet(b, { taker, inputMint, outputMint, amountIn, slippageBps, wsolAta });
|
|
298
337
|
} catch (e) {
|
|
299
338
|
return refuse(e.message);
|
|
300
339
|
}
|
|
@@ -371,6 +410,11 @@ function jupiterProvider(config = {}) {
|
|
|
371
410
|
}
|
|
372
411
|
};
|
|
373
412
|
}
|
|
413
|
+
function bytesEqual(a, b) {
|
|
414
|
+
if (a.length !== b.length) return false;
|
|
415
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
374
418
|
|
|
375
419
|
// src/protocol.ts
|
|
376
420
|
var import_single = require("@anywalletkit/protocol-swap2-core/swap2/single");
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/codec.ts","../src/transaction.ts","../src/activity.ts","../src/provider.ts","../src/protocol.ts"],"sourcesContent":["export * from \"./config.js\";\nexport * from \"./codec.js\";\nexport * from \"./transaction.js\";\nexport * from \"./provider.js\";\nexport {JupiterSwap2Protocol, type JupiterSwap2Config} from \"./protocol.js\";\nexport {JupiterSwap2Protocol as default} from \"./protocol.js\";\nexport * from \"./activity.js\";\n","/**\n * Jupiter (Solana) — Swap API V2, Router path (`GET /swap/v2/build`): Metis on-chain routing, raw instructions, no\n * Jupiter swap fee. The transaction is assembled here and executed by the account's serialized-transaction guard\n * (simulation + balance proof), then broadcast through the wallet's own RPC — Jupiter never lands it for us.\n * Same-chain only: Solana → Solana.\n */\nimport {ccAsset, ccAssetByToken} from \"@anywalletkit/swap2-assets\";\n\nexport const JUPITER_API_DEFAULT = \"https://api.jup.ag/swap/v2\";\n\n/** Jupiter Aggregator v6 — the only program a swap instruction may target. */\nexport const JUPITER_PROGRAM = \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\";\nexport const COMPUTE_BUDGET_PROGRAM = \"ComputeBudget111111111111111111111111111111\";\nexport const SYSTEM_PROGRAM = \"11111111111111111111111111111111\";\nexport const TOKEN_PROGRAM = \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\";\nexport const TOKEN_2022_PROGRAM = \"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb\";\nexport const ATA_PROGRAM = \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\";\n/** Wrapped SOL: Jupiter's name for native SOL (it wraps / unwraps around the swap). */\nexport const WSOL_MINT = \"So11111111111111111111111111111111111111112\";\n\n/** Programs the /build instructions may invoke; anything else refuses the quote before the wallet sees it. */\nexport const JUPITER_TX_PROGRAMS: ReadonlySet<string> = new Set([JUPITER_PROGRAM, COMPUTE_BUDGET_PROGRAM, SYSTEM_PROGRAM, TOKEN_PROGRAM, TOKEN_2022_PROGRAM, ATA_PROGRAM]);\n\n/** swap2 names Solana `solana:mainnet`; wallet history uses the genesis-hash form. */\nexport const SOLANA_CAIP2 = \"solana:mainnet\";\nexport const SOLANA_CHAINS: ReadonlySet<string> = new Set([SOLANA_CAIP2, \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\"]);\n\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\nconst NATIVE = new Set([\"\", \"native\", \"sol\", SYSTEM_PROGRAM, WSOL_MINT.toLowerCase(), \"0x0000000000000000000000000000000000000000\"]);\n\n/** A swap2 token ref on Solana (catalog symbol, mint, or a native marker) → the mint Jupiter quotes; null when unknown. */\nexport function jupiterMint(token: string): string | null {\n if (NATIVE.has(token.toLowerCase()) || /^0x0+$/.test(token)) return WSOL_MINT;\n const bySymbol = ccAsset(SOLANA_CAIP2, token);\n if (bySymbol) return bySymbol.contract ?? WSOL_MINT;\n const byMint = BASE58.test(token) ? ccAssetByToken(SOLANA_CAIP2, token) : undefined;\n if (byMint) return byMint.contract ?? WSOL_MINT;\n return BASE58.test(token) ? token : null;\n}\n\nexport const jupiter = {\n supportsChain: (chain: string) => chain === SOLANA_CAIP2,\n supports: (from: string, to: string) => from === SOLANA_CAIP2 && to === SOLANA_CAIP2,\n};\n","/**\n * Byte-level checks of what `/build` returns. The swap instruction is Jupiter v6's Anchor `route_v2` /\n * `shared_accounts_route_v2` (ExactIn): its arguments carry the input amount, the quoted output, the slippage and the\n * platform-fee split that the program enforces on-chain — so they are read back here and must equal the request\n * before the transaction is assembled. Discriminators = sha256(\"global:<name>\")[0..8] (verified 2026-10-23 against\n * live /build answers).\n */\nimport {base64} from \"@scure/base\";\n\n/** `route_v2(in_amount u64, quoted_out_amount u64, slippage_bps u16, platform_fee_bps u16, positive_slippage_bps u16, route_plan Vec)` */\nexport const ROUTE_V2 = \"bb64facc31c4af14\";\n/** `shared_accounts_route_v2(id u8, …the same arguments…)` */\nexport const SHARED_ACCOUNTS_ROUTE_V2 = \"d19853937cfed8e9\";\n\nexport interface JupiterSwapArgs {\n kind: \"route_v2\" | \"shared_accounts_route_v2\";\n inAmount: bigint;\n quotedOutAmount: bigint;\n slippageBps: number;\n platformFeeBps: number;\n positiveSlippageBps: number;\n}\n\nconst hex = (b: Uint8Array) => Array.from(b, (x) => x.toString(16).padStart(2, \"0\")).join(\"\");\nconst u64 = (d: Uint8Array, o: number) => new DataView(d.buffer, d.byteOffset + o, 8).getBigUint64(0, true);\nconst u16 = (d: Uint8Array, o: number) => new DataView(d.buffer, d.byteOffset + o, 2).getUint16(0, true);\n\nexport const fromBase64 = (s: string): Uint8Array => base64.decode(s);\nexport const toBase64 = (b: Uint8Array): string => base64.encode(b);\n\n/** Decode the swap instruction's fixed arguments; throws for any other instruction (ExactOut, legacy v1 routes…). */\nexport function decodeSwapArgs(data: Uint8Array): JupiterSwapArgs {\n const disc = hex(data.subarray(0, 8));\n const at = disc === ROUTE_V2 ? 8 : disc === SHARED_ACCOUNTS_ROUTE_V2 ? 9 : -1;\n if (at < 0) throw new Error(`unsupported Jupiter instruction ${disc}`);\n if (data.length < at + 22 + 4) throw new Error(\"Jupiter swap instruction is truncated\");\n return {\n kind: at === 8 ? \"route_v2\" : \"shared_accounts_route_v2\",\n inAmount: u64(data, at),\n quotedOutAmount: u64(data, at + 8),\n slippageBps: u16(data, at + 16),\n platformFeeBps: u16(data, at + 18),\n positiveSlippageBps: u16(data, at + 20),\n };\n}\n\n/** The worst output the program accepts: quoted · (10 000 − slippage) / 10 000, rounded down (never above the on-chain check). */\nexport function minOutOf(quotedOut: bigint, slippageBps: number): bigint {\n return (quotedOut * BigInt(10_000 - slippageBps)) / 10_000n;\n}\n\n/** ComputeBudget instructions: 2 = SetComputeUnitLimit(u32), 3 = SetComputeUnitPrice(u64 micro-lamports). */\nexport function decodeComputeBudget(data: Uint8Array): {limit?: number; price?: bigint} {\n if (data[0] === 2 && data.length === 5) return {limit: new DataView(data.buffer, data.byteOffset + 1, 4).getUint32(0, true)};\n if (data[0] === 3 && data.length === 9) return {price: u64(data, 1)};\n throw new Error(`unexpected compute-budget instruction ${data[0]}`);\n}\n\nexport function setComputeUnitLimit(units: number): Uint8Array {\n const d = new Uint8Array(5);\n d[0] = 2;\n new DataView(d.buffer).setUint32(1, units, true);\n return d;\n}\n\nexport function setComputeUnitPrice(microLamports: bigint): Uint8Array {\n const d = new Uint8Array(9);\n d[0] = 3;\n new DataView(d.buffer).setBigUint64(1, microLamports, true);\n return d;\n}\n","/**\n * Assemble the v0 transaction from `/build` instructions: our compute budget (limit + capped price), Jupiter's setup,\n * swap, cleanup and other instructions, compressed with the lookup tables the response names, fee payer = the taker,\n * lifetime = the blockhash Jupiter fetched. Signatures stay empty; the account signs after its own guard.\n */\nimport {\n AccountRole, address, appendTransactionMessageInstructions, compileTransaction, compressTransactionMessageUsingAddressLookupTables,\n createTransactionMessage, getBase58Decoder, getBase64EncodedWireTransaction, pipe, setTransactionMessageFeePayer,\n setTransactionMessageLifetimeUsingBlockhash, type Address, type Blockhash, type Instruction,\n} from \"@solana/kit\";\nimport {COMPUTE_BUDGET_PROGRAM} from \"./config.js\";\nimport {fromBase64, setComputeUnitLimit, setComputeUnitPrice} from \"./codec.js\";\n\nexport interface JupiterInstruction {\n programId: string;\n accounts: {pubkey: string; isSigner: boolean; isWritable: boolean}[];\n data: string;\n}\n\nexport interface AssembleInput {\n taker: string;\n /** setup → swap → cleanup → other, in that order; compute-budget instructions are ours and come first. */\n instructions: JupiterInstruction[];\n computeUnitLimit: number;\n computeUnitPrice: bigint;\n blockhash: Uint8Array | string;\n lastValidBlockHeight: number | bigint;\n addressesByLookupTableAddress: Record<string, string[]> | null | undefined;\n}\n\nconst role = (a: {isSigner: boolean; isWritable: boolean}): AccountRole =>\n a.isSigner ? (a.isWritable ? AccountRole.WRITABLE_SIGNER : AccountRole.READONLY_SIGNER) : a.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;\n\nconst toInstruction = (ix: JupiterInstruction): Instruction => ({\n programAddress: address(ix.programId),\n accounts: ix.accounts.map((a) => ({address: address(a.pubkey), role: role(a)})),\n data: fromBase64(ix.data),\n});\n\n/** The unsigned transaction as base64 wire bytes (what `TxRequest.serializedTx` carries). */\nexport function assembleTransaction(input: AssembleInput): string {\n const budget: Instruction[] = [\n {programAddress: address(COMPUTE_BUDGET_PROGRAM), data: setComputeUnitLimit(input.computeUnitLimit)},\n {programAddress: address(COMPUTE_BUDGET_PROGRAM), data: setComputeUnitPrice(input.computeUnitPrice)},\n ];\n const blockhash = (typeof input.blockhash === \"string\" ? input.blockhash : getBase58Decoder().decode(input.blockhash)) as Blockhash;\n const tables: Record<Address, Address[]> = {};\n for (const [table, list] of Object.entries(input.addressesByLookupTableAddress ?? {})) tables[address(table)] = list.map((a) => address(a));\n const message = pipe(\n createTransactionMessage({version: 0}),\n (m) => setTransactionMessageFeePayer(address(input.taker), m),\n (m) => setTransactionMessageLifetimeUsingBlockhash({blockhash, lastValidBlockHeight: BigInt(input.lastValidBlockHeight)}, m),\n (m) => appendTransactionMessageInstructions([...budget, ...input.instructions.map(toInstruction)], m),\n (m) => (Object.keys(tables).length ? compressTransactionMessageUsingAddressLookupTables(m, tables) : m),\n );\n return getBase64EncodedWireTransaction(compileTransaction(message));\n}\n","/**\n * Activity recognition for Jupiter swaps. Solana history (wallet-solana) names the first non-plumbing program a\n * transaction runs as `call.to`: a swap sent to Jupiter v6 directly (this module's /build transactions, jup.ag) has it\n * there. A route that only passes through Jupiter inside another program (an aggregator or bridge CPI-ing into it) names\n * that program instead and is left to its module. The owner must both give and receive an asset: a leg that only sends\n * (a bridge's source leg with a Jupiter pre-swap) is not called a swap.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {JUPITER_PROGRAM, SOLANA_CHAINS} from \"./config.js\";\n\nexport const JUPITER_MODULE = \"@anywalletkit/protocol-swap2-jupiter\";\n\nexport function describeJupiterActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!SOLANA_CHAINS.has(tx.chain) || tx.call?.to !== JUPITER_PROGRAM) return null;\n const item = describeSwapLike(tx, ctx, {protocol: JUPITER_MODULE, subtitle: \"Jupiter\", kind: \"swap\", counterparty: JUPITER_PROGRAM});\n if (item && tx.status !== \"failed\" && (item.assetsIn.length === 0 || item.assetsOut.length === 0)) return null;\n return item;\n}\n","/**\n * Jupiter provider — Swap API V2 Router path, same-chain Solana swaps:\n * quote + instructions GET /swap/v2/build?inputMint&outputMint&amount&taker&slippageBps\n * status getSignatureStatuses on the caller's own Solana RPC (optional)\n * Routing is Metis (Jupiter's on-chain router); the Router path charges no Jupiter swap fee. Keyless access works at\n * 0.5 RPS; pass `apiKey` (sent as `x-api-key`) for a plan's rate limit.\n *\n * Nothing from the API is trusted as-is. Before a live quote is handed out, every instruction is checked: only the\n * Jupiter program and the token / system / ATA / compute-budget plumbing, the taker is the only signer, no tip, and\n * the swap instruction's own arguments (decoded) carry exactly our input amount, the quoted output, our slippage and\n * a zero platform fee — those are what the program enforces on-chain. The compute budget is rebuilt here: a unit price\n * capped by `maxComputeUnitPrice`, and a unit limit from a simulation (1.2× the units used) when `rpcUrls` is given.\n * The account then executes the assembled transaction through its serialized-transaction guard (simulation +\n * balance proof against the quote) and broadcasts it through its own RPC.\n */\nimport {describeJupiterActivity} from \"./activity.js\";\nimport {JUPITER_API_DEFAULT, JUPITER_PROGRAM, JUPITER_TX_PROGRAMS, COMPUTE_BUDGET_PROGRAM, SOLANA_CAIP2, WSOL_MINT, jupiter as cfg, jupiterMint} from \"./config.js\";\nimport {decodeComputeBudget, decodeSwapArgs, fromBase64, minOutOf} from \"./codec.js\";\nimport {assembleTransaction, type JupiterInstruction} from \"./transaction.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\nconst DEFAULT_SLIPPAGE_BPS = 50;\nconst MAX_SLIPPAGE_BPS = 1_000;\n/** A /build blockhash lives ~60–90 s; the quote must be signed well inside it. */\nconst QUOTE_TTL_MS = 30_000;\nconst MAX_COMPUTE_UNITS = 1_400_000;\n/** 2 000 000 µlamports/CU: at 1.4 M CU the priority fee is ≤ 0.0028 SOL. */\nconst DEFAULT_MAX_CU_PRICE = 2_000_000n;\nconst BASE_FEE_LAMPORTS = 5_000n;\n/** Taker for a dry quote with no address yet: /build needs one, the price does not depend on it. */\nconst DRY_TAKER = \"9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM\";\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\nexport interface JupiterProviderConfig {\n enabled?: boolean;\n /** Swap API base (default https://api.jup.ag/swap/v2). */\n apiUrl?: string;\n /** Jupiter Developer Platform key, sent as `x-api-key`. Keyless works at 0.5 RPS. */\n apiKey?: string;\n /** Solana JSON-RPC endpoints: compute-unit simulation and status. Without them the limit is 1.4 M CU and status stays pending. */\n rpcUrls?: readonly string[];\n /** Ceiling on the compute-unit price Jupiter suggests, micro-lamports (default 2 000 000). */\n maxComputeUnitPrice?: bigint;\n /** Passed to /build: \"medium\" | \"high\" | \"veryHigh\" or a percentile in bps (default: Jupiter's 50th percentile). */\n computeUnitPricePercentile?: string;\n /** Slippage when the caller names none, bps (default 50). */\n defaultSlippageBps?: number;\n}\n\ninterface BuildResponse {\n inputMint?: string;\n outputMint?: string;\n inAmount?: string;\n outAmount?: string;\n otherAmountThreshold?: string;\n swapMode?: string;\n slippageBps?: number;\n priceImpactPct?: string;\n routePlan?: {bps?: number; swapInfo?: {label?: string}}[];\n computeBudgetInstructions?: JupiterInstruction[];\n setupInstructions?: JupiterInstruction[];\n swapInstruction?: JupiterInstruction;\n cleanupInstruction?: JupiterInstruction | null;\n otherInstructions?: JupiterInstruction[];\n tipInstruction?: JupiterInstruction | null;\n addressesByLookupTableAddress?: Record<string, string[]> | null;\n transactionVersion?: number | string;\n blockhashWithMetadata?: {blockhash?: number[]; lastValidBlockHeight?: number};\n error?: string;\n}\n\nconst INTENT_PREFIX = \"jup:\";\n\nexport function jupiterProvider(config: JupiterProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const base = (config.apiUrl ?? JUPITER_API_DEFAULT).replace(/\\/$/, \"\");\n const maxPrice = config.maxComputeUnitPrice ?? DEFAULT_MAX_CU_PRICE;\n const rpcUrls = config.rpcUrls ?? [];\n\n /** One GET with a single back-off on 429 (keyless traffic is 0.5 RPS), waiting for `x-ratelimit-reset` when given. */\n const get = async (path: string, signal?: AbortSignal): Promise<{ok: boolean; status: number; body: unknown}> => {\n for (let attempt = 0; ; attempt++) {\n const res = await fetch(`${base}${path}`, {headers: {accept: \"application/json\", ...(config.apiKey ? {\"x-api-key\": config.apiKey} : {})}, signal: signal ?? timeoutSignal(12_000)});\n const body = await res.json().catch(() => null);\n if (res.status === 429 && attempt === 0 && !signal?.aborted) {\n const reset = Number(res.headers.get(\"x-ratelimit-reset\"));\n const wait = Number.isFinite(reset) && reset > 0 ? Math.min(3_000, Math.max(250, reset * 1000 - Date.now())) : 1_200;\n await new Promise((r) => setTimeout(r, wait));\n continue;\n }\n return {ok: res.ok, status: res.status, body};\n }\n };\n\n const rpc = async (method: string, params: unknown[]): Promise<unknown> => {\n let last: unknown = new Error(\"no Solana RPC configured\");\n for (const url of rpcUrls) {\n try {\n const res = await fetch(url, {method: \"POST\", headers: {\"content-type\": \"application/json\"}, body: JSON.stringify({jsonrpc: \"2.0\", id: 1, method, params}), signal: timeoutSignal(10_000)});\n const body = (await res.json()) as {result?: unknown; error?: {message?: string}};\n if (body.error) throw new Error(body.error.message ?? \"rpc error\");\n return body.result;\n } catch (e) { last = e; }\n }\n throw last;\n };\n\n /** Every instruction the API returned, checked; returns the ordered list to assemble and the suggested unit price. */\n const vet = (b: BuildResponse, want: {taker: string; inputMint: string; outputMint: string; amountIn: bigint; slippageBps: number}): {instructions: JupiterInstruction[]; price: bigint; quotedOut: bigint} => {\n if (b.swapMode && b.swapMode !== \"ExactIn\") throw new Error(`swap mode ${b.swapMode}`);\n if (b.inputMint !== want.inputMint || b.outputMint !== want.outputMint) throw new Error(\"the answer names other mints\");\n if (b.inAmount !== want.amountIn.toString()) throw new Error(`the answer spends ${b.inAmount}, not ${want.amountIn}`);\n if (String(b.transactionVersion ?? \"0\") !== \"0\") throw new Error(`transaction version ${b.transactionVersion}`);\n if (b.tipInstruction) throw new Error(\"unexpected tip instruction\");\n if (!b.swapInstruction) throw new Error(\"no swap instruction\");\n if (b.swapInstruction.programId !== JUPITER_PROGRAM) throw new Error(`swap instruction targets ${b.swapInstruction.programId}`);\n const args = decodeSwapArgs(fromBase64(b.swapInstruction.data));\n if (args.inAmount !== want.amountIn) throw new Error(`swap instruction spends ${args.inAmount}, not ${want.amountIn}`);\n if (String(args.quotedOutAmount) !== b.outAmount) throw new Error(\"swap instruction's quoted output differs from the answer\");\n if (args.slippageBps !== want.slippageBps) throw new Error(`swap instruction allows ${args.slippageBps} bps slippage, not ${want.slippageBps}`);\n if (args.platformFeeBps !== 0 || args.positiveSlippageBps !== 0) throw new Error(\"swap instruction takes a platform fee\");\n let price = 0n;\n for (const ix of b.computeBudgetInstructions ?? []) {\n if (ix.programId !== COMPUTE_BUDGET_PROGRAM) throw new Error(`compute-budget slot holds ${ix.programId}`);\n const d = decodeComputeBudget(fromBase64(ix.data));\n if (d.price !== undefined) price = d.price;\n }\n const instructions = [...(b.setupInstructions ?? []), b.swapInstruction, ...(b.cleanupInstruction ? [b.cleanupInstruction] : []), ...(b.otherInstructions ?? [])];\n for (const ix of instructions) {\n if (!JUPITER_TX_PROGRAMS.has(ix.programId) || ix.programId === COMPUTE_BUDGET_PROGRAM) throw new Error(`instruction for program ${ix.programId}`);\n for (const a of ix.accounts) if (a.isSigner && a.pubkey !== want.taker) throw new Error(`instruction needs signer ${a.pubkey}`);\n }\n return {instructions, price: price > maxPrice ? maxPrice : price, quotedOut: args.quotedOutAmount};\n };\n\n /** 1.2× the units a simulation uses (capped); null when no RPC answers. A failing simulation refuses the quote. */\n const simulateUnits = async (wire: string): Promise<number | null> => {\n if (!rpcUrls.length) return null;\n let r: {value?: {err?: unknown; unitsConsumed?: number; logs?: string[]}};\n try {\n r = (await rpc(\"simulateTransaction\", [wire, {encoding: \"base64\", sigVerify: false, replaceRecentBlockhash: true, commitment: \"processed\"}])) as typeof r;\n } catch {\n return null;\n }\n if (r?.value?.err) {\n const log = (r.value.logs ?? []).filter((l) => /error|failed|insufficient/i.test(l)).slice(-1)[0] ?? \"\";\n const err = JSON.stringify(r.value.err);\n // The usual reason, said plainly: the wallet lacks the input. Confirmed 2026-10-24 by building the same\n // USDS / LINK / WBTC → USDC swaps from an empty wallet (6025) and from real holders (built fine).\n // Jupiter 6024 = insufficient funds, 6025 = no token account for the input; System Program 1 = not enough SOL.\n const jupiterCode = /JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 failed/.test(log) ? /\"Custom\":(\\d+)/.exec(err)?.[1] : undefined;\n if (jupiterCode === \"6024\" || jupiterCode === \"6025\" || (/\"Custom\":1\\}/.test(err) && /Program 11111111111111111111111111111111 failed/.test(log))) {\n throw new Error(`not enough of the input token in the wallet${jupiterCode === \"6025\" ? \" (no token account for it)\" : \"\"} — simulation fails: ${err}`);\n }\n throw new Error(`simulation fails: ${err}${log ? ` (${log.slice(0, 160)})` : \"\"}`);\n }\n const used = r?.value?.unitsConsumed;\n return used ? Math.min(MAX_COMPUTE_UNITS, Math.ceil(used * 1.2)) : null;\n };\n\n return {\n name: \"jupiter\",\n describeActivity: describeJupiterActivity,\n enabled: () => config.enabled ?? true,\n supportsSameChain: true,\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (from: string, to: string) => cfg.supports(from, to),\n supportsRoute(from: Asset, to: Asset): boolean {\n if (!cfg.supports(from.chain, to.chain)) return false;\n const a = jupiterMint(from.token), b = jupiterMint(to.token);\n return !!a && !!b && a !== b;\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n const dry = params.dry !== false;\n const refuse = (reason: string): null => {\n params.onRefusal?.(`jupiter: ${reason}`);\n return null;\n };\n if (!cfg.supports(params.sourceChain, params.destChain)) return refuse(`same-chain Solana only (${params.sourceChain} → ${params.destChain})`);\n if (params.flex) return refuse(\"amount-flexible deposits are not supported\");\n const inputMint = jupiterMint(params.sourceToken), outputMint = jupiterMint(params.destToken);\n if (!inputMint || !outputMint) return refuse(`unknown token (${params.sourceToken} → ${params.destToken})`);\n if (inputMint === outputMint) return refuse(\"same token on both sides\");\n const amountIn = BigInt(params.amountIn);\n if (amountIn <= 0n) return refuse(\"amount must be positive\");\n const slippageBps = params.slippageBps ?? config.defaultSlippageBps ?? DEFAULT_SLIPPAGE_BPS;\n if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > MAX_SLIPPAGE_BPS) return refuse(`slippage ${slippageBps} bps is out of range`);\n\n // The swap pays the taker's own token account: a live quote must be for the signer's own address.\n const self = params.refundAddress || params.destAddress;\n if (!dry) {\n if (!self || !BASE58.test(self)) return refuse(\"live quote without the signer's address\");\n if (params.destAddress && params.destAddress !== self) return refuse(\"the recipient must be the signing wallet (Jupiter pays the taker)\");\n }\n const taker = self && BASE58.test(self) ? self : DRY_TAKER;\n\n const qs = new URLSearchParams({inputMint, outputMint, amount: params.amountIn, taker, slippageBps: String(slippageBps)});\n if (config.computeUnitPricePercentile) qs.set(\"computeUnitPricePercentile\", config.computeUnitPricePercentile);\n let b: BuildResponse;\n try {\n const r = await get(`/build?${qs.toString()}`, signal);\n if (!r.ok) return refuse(`build ${r.status}: ${String((r.body as BuildResponse | null)?.error ?? \"\").slice(0, 160)}`);\n b = (r.body ?? {}) as BuildResponse;\n } catch (e) { return refuse(`build failed: ${(e as Error).message.slice(0, 160)}`); }\n if (!b.outAmount || !/^\\d+$/.test(b.outAmount)) return refuse(\"answer without an output amount\");\n\n let vetted: ReturnType<typeof vet>;\n try { vetted = vet(b, {taker, inputMint, outputMint, amountIn, slippageBps}); } catch (e) { return refuse((e as Error).message); }\n const minOut = minOutOf(vetted.quotedOut, slippageBps);\n if (params.minAmountOut !== undefined && minOut < BigInt(params.minAmountOut)) {\n return refuse(`guaranteed ${minOut} is below the floor ${params.minAmountOut} at ${slippageBps} bps`);\n }\n const route = (b.routePlan ?? []).map((s) => s.swapInfo?.label).filter(Boolean).join(\" + \");\n const impact = Number(b.priceImpactPct ?? 0);\n const common = {\n provider: \"jupiter\",\n depositAddress: \"\",\n depositMemo: null,\n sourceAmount: params.amountIn,\n destAmount: b.outAmount,\n minDestAmount: minOut.toString(),\n feeUsd: 0,\n etaSeconds: 15,\n reliability: impact > 0.05 ? 0.8 : 0.97,\n validUntilMs: Date.now() + QUOTE_TTL_MS,\n };\n if (dry) {\n return {...common, intentId: `dry:${INTENT_PREFIX}${Date.now().toString(36)}`, fees: [{type: \"network\" as const, amount: BASE_FEE_LAMPORTS.toString(), token: \"native\", included: false, description: \"Solana base fee\"}], ...(route ? {providerData: {route}} : {})};\n }\n\n const blockhash = b.blockhashWithMetadata?.blockhash;\n const lastValid = b.blockhashWithMetadata?.lastValidBlockHeight;\n if (!blockhash || blockhash.length !== 32 || !lastValid) return refuse(\"answer without a blockhash\");\n const assemble = (limit: number) => assembleTransaction({\n taker, instructions: vetted.instructions, computeUnitLimit: limit, computeUnitPrice: vetted.price,\n blockhash: Uint8Array.from(blockhash), lastValidBlockHeight: lastValid, addressesByLookupTableAddress: b.addressesByLookupTableAddress,\n });\n let wire: string, limit = MAX_COMPUTE_UNITS;\n try {\n wire = assemble(MAX_COMPUTE_UNITS);\n const units = await simulateUnits(wire);\n if (units) { limit = units; wire = assemble(units); }\n } catch (e) { return refuse((e as Error).message.slice(0, 240)); }\n const priority = (vetted.price * BigInt(limit) + 999_999n) / 1_000_000n;\n return {\n ...common,\n intentId: `${INTENT_PREFIX}${lastValid}:${Date.now().toString(36)}`,\n // `value` declares the native SOL the transaction may take: the input for a SOL source (Jupiter wraps it), none for a token.\n txRequest: {serializedTx: wire, value: inputMint === WSOL_MINT ? params.amountIn : \"0\"},\n fees: [{type: \"network\", amount: (BASE_FEE_LAMPORTS + priority).toString(), token: \"native\", included: false, description: `Solana base + priority fee (${limit} CU at ${vetted.price} µlamports)`}],\n providerData: {inputMint, outputMint, slippageBps: String(slippageBps), computeUnits: String(limit), ...(route ? {route} : {})},\n };\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n const tx = quote.txRequest?.serializedTx;\n if (!tx || quote.intentId.startsWith(\"dry:\")) throw new Error(\"jupiter: not a live quote\");\n return {chain: SOLANA_CAIP2, to: \"\", value: quote.txRequest!.value ?? \"0\", serializedTx: tx};\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n if (!ref.sourceTxHash || !rpcUrls.length) return {state: \"pending\"};\n try {\n const r = (await rpc(\"getSignatureStatuses\", [[ref.sourceTxHash], {searchTransactionHistory: true}])) as {value?: ({err?: unknown; confirmationStatus?: string} | null)[]};\n const s = r?.value?.[0];\n if (!s) return {state: \"pending\"};\n if (s.err) return {state: \"failed\"};\n return s.confirmationStatus === \"confirmed\" || s.confirmationStatus === \"finalized\" ? {state: \"completed\", destTxHash: ref.sourceTxHash} : {state: \"pending\"};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n","import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {jupiter as jupCfg} from \"./config.js\";\nimport {jupiterProvider, type JupiterProviderConfig} from \"./provider.js\";\n\nexport interface JupiterSwap2Config extends Swap2EngineConfig, JupiterProviderConfig {}\n\n/** Standalone Jupiter swap2: same-chain Solana swaps (Metis routing, /build, no Jupiter fee). */\nexport class JupiterSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: JupiterSwap2Config) {\n super(account, config);\n this.provider = jupiterProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return jupCfg.supportsChain(caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return jupCfg.supports(fromChain, toChain);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,0BAAsC;AAE/B,IAAM,sBAAsB;AAG5B,IAAM,kBAAkB;AACxB,IAAM,yBAAyB;AAC/B,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAC3B,IAAM,cAAc;AAEpB,IAAM,YAAY;AAGlB,IAAM,sBAA2C,oBAAI,IAAI,CAAC,iBAAiB,wBAAwB,gBAAgB,eAAe,oBAAoB,WAAW,CAAC;AAGlK,IAAM,eAAe;AACrB,IAAM,gBAAqC,oBAAI,IAAI,CAAC,cAAc,yCAAyC,CAAC;AAEnH,IAAM,SAAS;AACf,IAAM,SAAS,oBAAI,IAAI,CAAC,IAAI,UAAU,OAAO,gBAAgB,UAAU,YAAY,GAAG,4CAA4C,CAAC;AAG5H,SAAS,YAAY,OAA8B;AACxD,MAAI,OAAO,IAAI,MAAM,YAAY,CAAC,KAAK,SAAS,KAAK,KAAK,EAAG,QAAO;AACpE,QAAM,eAAW,6BAAQ,cAAc,KAAK;AAC5C,MAAI,SAAU,QAAO,SAAS,YAAY;AAC1C,QAAM,SAAS,OAAO,KAAK,KAAK,QAAI,oCAAe,cAAc,KAAK,IAAI;AAC1E,MAAI,OAAQ,QAAO,OAAO,YAAY;AACtC,SAAO,OAAO,KAAK,KAAK,IAAI,QAAQ;AACtC;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,OAAO;AAAA,EAC3C;AACF;","names":["BASE58","limit"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/codec.ts","../src/transaction.ts","../src/activity.ts","../src/provider.ts","../src/protocol.ts"],"sourcesContent":["export * from \"./config.js\";\nexport * from \"./codec.js\";\nexport * from \"./transaction.js\";\nexport * from \"./provider.js\";\nexport {JupiterSwap2Protocol, type JupiterSwap2Config} from \"./protocol.js\";\nexport {JupiterSwap2Protocol as default} from \"./protocol.js\";\nexport * from \"./activity.js\";\n","/**\n * Jupiter (Solana) — Swap API V2, Router path (`GET /swap/v2/build`): Metis on-chain routing, raw instructions, no\n * Jupiter swap fee. The transaction is assembled here and executed by the account's serialized-transaction guard\n * (simulation + balance proof), then broadcast through the wallet's own RPC — Jupiter never lands it for us.\n * Same-chain only: Solana → Solana.\n */\nimport {ccAsset, ccAssetByToken} from \"@anywalletkit/swap2-assets\";\n\nexport const JUPITER_API_DEFAULT = \"https://api.jup.ag/swap/v2\";\n\n/** Jupiter Aggregator v6 — the only program a swap instruction may target. */\nexport const JUPITER_PROGRAM = \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\";\nexport const COMPUTE_BUDGET_PROGRAM = \"ComputeBudget111111111111111111111111111111\";\nexport const SYSTEM_PROGRAM = \"11111111111111111111111111111111\";\nexport const TOKEN_PROGRAM = \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\";\nexport const TOKEN_2022_PROGRAM = \"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb\";\nexport const ATA_PROGRAM = \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\";\n/** Wrapped SOL: Jupiter's name for native SOL (it wraps / unwraps around the swap). */\nexport const WSOL_MINT = \"So11111111111111111111111111111111111111112\";\n\n/** Programs the /build instructions may invoke; anything else refuses the quote before the wallet sees it. */\nexport const JUPITER_TX_PROGRAMS: ReadonlySet<string> = new Set([JUPITER_PROGRAM, COMPUTE_BUDGET_PROGRAM, SYSTEM_PROGRAM, TOKEN_PROGRAM, TOKEN_2022_PROGRAM, ATA_PROGRAM]);\n\n/** swap2 names Solana `solana:mainnet`; wallet history uses the genesis-hash form. */\nexport const SOLANA_CAIP2 = \"solana:mainnet\";\nexport const SOLANA_CHAINS: ReadonlySet<string> = new Set([SOLANA_CAIP2, \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\"]);\n\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\nconst NATIVE = new Set([\"\", \"native\", \"sol\", SYSTEM_PROGRAM, WSOL_MINT.toLowerCase(), \"0x0000000000000000000000000000000000000000\"]);\n\n/** A swap2 token ref on Solana (catalog symbol, mint, or a native marker) → the mint Jupiter quotes; null when unknown. */\nexport function jupiterMint(token: string): string | null {\n if (NATIVE.has(token.toLowerCase()) || /^0x0+$/.test(token)) return WSOL_MINT;\n const bySymbol = ccAsset(SOLANA_CAIP2, token);\n if (bySymbol) return bySymbol.contract ?? WSOL_MINT;\n const byMint = BASE58.test(token) ? ccAssetByToken(SOLANA_CAIP2, token) : undefined;\n if (byMint) return byMint.contract ?? WSOL_MINT;\n return BASE58.test(token) ? token : null;\n}\n\nexport const jupiter = {\n supportsChain: (chain: string) => chain === SOLANA_CAIP2,\n supports: (from: string, to: string) => from === SOLANA_CAIP2 && to === SOLANA_CAIP2,\n};\n","/**\n * Byte-level checks of what `/build` returns. The swap instruction is Jupiter v6's Anchor `route_v2` /\n * `shared_accounts_route_v2` (ExactIn): its arguments carry the input amount, the quoted output, the slippage and the\n * platform-fee split that the program enforces on-chain — so they are read back here and must equal the request\n * before the transaction is assembled. Discriminators = sha256(\"global:<name>\")[0..8] (verified 2026-10-23 against\n * live /build answers).\n */\nimport {base64} from \"@scure/base\";\n\n/** `route_v2(in_amount u64, quoted_out_amount u64, slippage_bps u16, platform_fee_bps u16, positive_slippage_bps u16, route_plan Vec)` */\nexport const ROUTE_V2 = \"bb64facc31c4af14\";\n/** `shared_accounts_route_v2(id u8, …the same arguments…)` */\nexport const SHARED_ACCOUNTS_ROUTE_V2 = \"d19853937cfed8e9\";\n\nexport interface JupiterSwapArgs {\n kind: \"route_v2\" | \"shared_accounts_route_v2\";\n inAmount: bigint;\n quotedOutAmount: bigint;\n slippageBps: number;\n platformFeeBps: number;\n positiveSlippageBps: number;\n}\n\nconst hex = (b: Uint8Array) => Array.from(b, (x) => x.toString(16).padStart(2, \"0\")).join(\"\");\nconst u64 = (d: Uint8Array, o: number) => new DataView(d.buffer, d.byteOffset + o, 8).getBigUint64(0, true);\nconst u16 = (d: Uint8Array, o: number) => new DataView(d.buffer, d.byteOffset + o, 2).getUint16(0, true);\n\nexport const fromBase64 = (s: string): Uint8Array => base64.decode(s);\nexport const toBase64 = (b: Uint8Array): string => base64.encode(b);\n\n/** Decode the swap instruction's fixed arguments; throws for any other instruction (ExactOut, legacy v1 routes…). */\nexport function decodeSwapArgs(data: Uint8Array): JupiterSwapArgs {\n const disc = hex(data.subarray(0, 8));\n const at = disc === ROUTE_V2 ? 8 : disc === SHARED_ACCOUNTS_ROUTE_V2 ? 9 : -1;\n if (at < 0) throw new Error(`unsupported Jupiter instruction ${disc}`);\n if (data.length < at + 22 + 4) throw new Error(\"Jupiter swap instruction is truncated\");\n return {\n kind: at === 8 ? \"route_v2\" : \"shared_accounts_route_v2\",\n inAmount: u64(data, at),\n quotedOutAmount: u64(data, at + 8),\n slippageBps: u16(data, at + 16),\n platformFeeBps: u16(data, at + 18),\n positiveSlippageBps: u16(data, at + 20),\n };\n}\n\n/** The worst output the program accepts: quoted · (10 000 − slippage) / 10 000, rounded down (never above the on-chain check). */\nexport function minOutOf(quotedOut: bigint, slippageBps: number): bigint {\n return (quotedOut * BigInt(10_000 - slippageBps)) / 10_000n;\n}\n\n/** ComputeBudget instructions: 2 = SetComputeUnitLimit(u32), 3 = SetComputeUnitPrice(u64 micro-lamports). */\nexport function decodeComputeBudget(data: Uint8Array): {limit?: number; price?: bigint} {\n if (data[0] === 2 && data.length === 5) return {limit: new DataView(data.buffer, data.byteOffset + 1, 4).getUint32(0, true)};\n if (data[0] === 3 && data.length === 9) return {price: u64(data, 1)};\n throw new Error(`unexpected compute-budget instruction ${data[0]}`);\n}\n\nexport function setComputeUnitLimit(units: number): Uint8Array {\n const d = new Uint8Array(5);\n d[0] = 2;\n new DataView(d.buffer).setUint32(1, units, true);\n return d;\n}\n\nexport function setComputeUnitPrice(microLamports: bigint): Uint8Array {\n const d = new Uint8Array(9);\n d[0] = 3;\n new DataView(d.buffer).setBigUint64(1, microLamports, true);\n return d;\n}\n","/**\n * Assemble the v0 transaction from `/build` instructions: our compute budget (limit + capped price), Jupiter's setup,\n * swap, cleanup and other instructions, compressed with the lookup tables the response names, fee payer = the taker,\n * lifetime = the blockhash Jupiter fetched. Signatures stay empty; the account signs after its own guard.\n */\nimport {\n AccountRole, address, appendTransactionMessageInstructions, compileTransaction, compressTransactionMessageUsingAddressLookupTables,\n createTransactionMessage, getBase58Decoder, getBase64EncodedWireTransaction, pipe, setTransactionMessageFeePayer,\n setTransactionMessageLifetimeUsingBlockhash, type Address, type Blockhash, type Instruction,\n} from \"@solana/kit\";\nimport {COMPUTE_BUDGET_PROGRAM} from \"./config.js\";\nimport {fromBase64, setComputeUnitLimit, setComputeUnitPrice} from \"./codec.js\";\n\nexport interface JupiterInstruction {\n programId: string;\n accounts: {pubkey: string; isSigner: boolean; isWritable: boolean}[];\n data: string;\n}\n\nexport interface AssembleInput {\n taker: string;\n /** setup → swap → cleanup → other, in that order; compute-budget instructions are ours and come first. */\n instructions: JupiterInstruction[];\n computeUnitLimit: number;\n computeUnitPrice: bigint;\n blockhash: Uint8Array | string;\n lastValidBlockHeight: number | bigint;\n addressesByLookupTableAddress: Record<string, string[]> | null | undefined;\n}\n\nconst role = (a: {isSigner: boolean; isWritable: boolean}): AccountRole =>\n a.isSigner ? (a.isWritable ? AccountRole.WRITABLE_SIGNER : AccountRole.READONLY_SIGNER) : a.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;\n\nconst toInstruction = (ix: JupiterInstruction): Instruction => ({\n programAddress: address(ix.programId),\n accounts: ix.accounts.map((a) => ({address: address(a.pubkey), role: role(a)})),\n data: fromBase64(ix.data),\n});\n\n/** The unsigned transaction as base64 wire bytes (what `TxRequest.serializedTx` carries). */\nexport function assembleTransaction(input: AssembleInput): string {\n const budget: Instruction[] = [\n {programAddress: address(COMPUTE_BUDGET_PROGRAM), data: setComputeUnitLimit(input.computeUnitLimit)},\n {programAddress: address(COMPUTE_BUDGET_PROGRAM), data: setComputeUnitPrice(input.computeUnitPrice)},\n ];\n const blockhash = (typeof input.blockhash === \"string\" ? input.blockhash : getBase58Decoder().decode(input.blockhash)) as Blockhash;\n const tables: Record<Address, Address[]> = {};\n for (const [table, list] of Object.entries(input.addressesByLookupTableAddress ?? {})) tables[address(table)] = list.map((a) => address(a));\n const message = pipe(\n createTransactionMessage({version: 0}),\n (m) => setTransactionMessageFeePayer(address(input.taker), m),\n (m) => setTransactionMessageLifetimeUsingBlockhash({blockhash, lastValidBlockHeight: BigInt(input.lastValidBlockHeight)}, m),\n (m) => appendTransactionMessageInstructions([...budget, ...input.instructions.map(toInstruction)], m),\n (m) => (Object.keys(tables).length ? compressTransactionMessageUsingAddressLookupTables(m, tables) : m),\n );\n return getBase64EncodedWireTransaction(compileTransaction(message));\n}\n","/**\n * Activity recognition for Jupiter swaps. Solana history (wallet-solana) names the first non-plumbing program a\n * transaction runs as `call.to`: a swap sent to Jupiter v6 directly (this module's /build transactions, jup.ag) has it\n * there. A route that only passes through Jupiter inside another program (an aggregator or bridge CPI-ing into it) names\n * that program instead and is left to its module. The owner must both give and receive an asset: a leg that only sends\n * (a bridge's source leg with a Jupiter pre-swap) is not called a swap.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {JUPITER_PROGRAM, SOLANA_CHAINS} from \"./config.js\";\n\nexport const JUPITER_MODULE = \"@anywalletkit/protocol-swap2-jupiter\";\n\nexport function describeJupiterActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!SOLANA_CHAINS.has(tx.chain) || tx.call?.to !== JUPITER_PROGRAM) return null;\n const item = describeSwapLike(tx, ctx, {protocol: JUPITER_MODULE, subtitle: \"Jupiter\", kind: \"swap\", counterparty: JUPITER_PROGRAM});\n if (item && tx.status !== \"failed\" && (item.assetsIn.length === 0 || item.assetsOut.length === 0)) return null;\n return item;\n}\n","/**\n * Jupiter provider — Swap API V2 Router path, same-chain Solana swaps:\n * quote + instructions GET /swap/v2/build?inputMint&outputMint&amount&taker&slippageBps\n * status getSignatureStatuses on the caller's own Solana RPC (optional)\n * Routing is Metis (Jupiter's on-chain router); the Router path charges no Jupiter swap fee. Keyless access works at\n * 0.5 RPS; pass `apiKey` (sent as `x-api-key`) for a plan's rate limit.\n *\n * Nothing from the API is trusted as-is. Before a live quote is handed out, every instruction is checked: only the\n * Jupiter program and the token / system / ATA / compute-budget plumbing, the taker is the only signer, no tip, and\n * the swap instruction's own arguments (decoded) carry exactly our input amount, the quoted output, our slippage and\n * a zero platform fee — those are what the program enforces on-chain. The compute budget is rebuilt here: a unit price\n * capped by `maxComputeUnitPrice`, and a unit limit from a simulation (1.2× the units used) when `rpcUrls` is given.\n * The account then executes the assembled transaction through its serialized-transaction guard (simulation +\n * balance proof against the quote) and broadcasts it through its own RPC.\n */\nimport {describeJupiterActivity} from \"./activity.js\";\nimport {ATA_PROGRAM, JUPITER_API_DEFAULT, JUPITER_PROGRAM, JUPITER_TX_PROGRAMS, COMPUTE_BUDGET_PROGRAM, SOLANA_CAIP2, SYSTEM_PROGRAM, TOKEN_PROGRAM, WSOL_MINT, jupiter as cfg, jupiterMint} from \"./config.js\";\nimport {address, getAddressEncoder, getProgramDerivedAddress} from \"@solana/kit\";\nimport {decodeComputeBudget, decodeSwapArgs, fromBase64, minOutOf} from \"./codec.js\";\nimport {assembleTransaction, type JupiterInstruction} from \"./transaction.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\nconst DEFAULT_SLIPPAGE_BPS = 50;\nconst MAX_SLIPPAGE_BPS = 1_000;\n/** A /build blockhash lives ~60–90 s; the quote must be signed well inside it. */\nconst QUOTE_TTL_MS = 30_000;\nconst MAX_COMPUTE_UNITS = 1_400_000;\n/** 2 000 000 µlamports/CU: at 1.4 M CU the priority fee is ≤ 0.0028 SOL. */\nconst DEFAULT_MAX_CU_PRICE = 2_000_000n;\nconst BASE_FEE_LAMPORTS = 5_000n;\n/** Taker for a dry quote with no address yet: /build needs one, the price does not depend on it. */\nconst DRY_TAKER = \"9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM\";\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\nexport interface JupiterProviderConfig {\n enabled?: boolean;\n /** Swap API base (default https://api.jup.ag/swap/v2). */\n apiUrl?: string;\n /** Jupiter Developer Platform key, sent as `x-api-key`. Keyless works at 0.5 RPS. */\n apiKey?: string;\n /** Solana JSON-RPC endpoints: compute-unit simulation and status. Without them the limit is 1.4 M CU and status stays pending. */\n rpcUrls?: readonly string[];\n /** Ceiling on the compute-unit price Jupiter suggests, micro-lamports (default 2 000 000). */\n maxComputeUnitPrice?: bigint;\n /** Passed to /build: \"medium\" | \"high\" | \"veryHigh\" or a percentile in bps (default: Jupiter's 50th percentile). */\n computeUnitPricePercentile?: string;\n /** Slippage when the caller names none, bps (default 50). */\n defaultSlippageBps?: number;\n}\n\ninterface BuildResponse {\n inputMint?: string;\n outputMint?: string;\n inAmount?: string;\n outAmount?: string;\n otherAmountThreshold?: string;\n swapMode?: string;\n slippageBps?: number;\n priceImpactPct?: string;\n routePlan?: {bps?: number; swapInfo?: {label?: string}}[];\n computeBudgetInstructions?: JupiterInstruction[];\n setupInstructions?: JupiterInstruction[];\n swapInstruction?: JupiterInstruction;\n cleanupInstruction?: JupiterInstruction | null;\n otherInstructions?: JupiterInstruction[];\n tipInstruction?: JupiterInstruction | null;\n addressesByLookupTableAddress?: Record<string, string[]> | null;\n transactionVersion?: number | string;\n blockhashWithMetadata?: {blockhash?: number[]; lastValidBlockHeight?: number};\n error?: string;\n}\n\nconst INTENT_PREFIX = \"jup:\";\n\nexport function jupiterProvider(config: JupiterProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const base = (config.apiUrl ?? JUPITER_API_DEFAULT).replace(/\\/$/, \"\");\n const maxPrice = config.maxComputeUnitPrice ?? DEFAULT_MAX_CU_PRICE;\n const rpcUrls = config.rpcUrls ?? [];\n\n /** One GET with a single back-off on 429 (keyless traffic is 0.5 RPS), waiting for `x-ratelimit-reset` when given. */\n const get = async (path: string, signal?: AbortSignal): Promise<{ok: boolean; status: number; body: unknown}> => {\n for (let attempt = 0; ; attempt++) {\n const res = await fetch(`${base}${path}`, {headers: {accept: \"application/json\", ...(config.apiKey ? {\"x-api-key\": config.apiKey} : {})}, signal: signal ?? timeoutSignal(12_000)});\n const body = await res.json().catch(() => null);\n if (res.status === 429 && attempt === 0 && !signal?.aborted) {\n const reset = Number(res.headers.get(\"x-ratelimit-reset\"));\n const wait = Number.isFinite(reset) && reset > 0 ? Math.min(3_000, Math.max(250, reset * 1000 - Date.now())) : 1_200;\n await new Promise((r) => setTimeout(r, wait));\n continue;\n }\n return {ok: res.ok, status: res.status, body};\n }\n };\n\n const rpc = async (method: string, params: unknown[]): Promise<unknown> => {\n let last: unknown = new Error(\"no Solana RPC configured\");\n for (const url of rpcUrls) {\n try {\n const res = await fetch(url, {method: \"POST\", headers: {\"content-type\": \"application/json\"}, body: JSON.stringify({jsonrpc: \"2.0\", id: 1, method, params}), signal: timeoutSignal(10_000)});\n const body = (await res.json()) as {result?: unknown; error?: {message?: string}};\n if (body.error) throw new Error(body.error.message ?? \"rpc error\");\n return body.result;\n } catch (e) { last = e; }\n }\n throw last;\n };\n\n /**\n * The setup / cleanup / other instructions /build may carry, by exact shape (scan 2026-10-27 modules, F32/F33):\n * creating the taker's own ATAs, funding the taker's wSOL account with exactly the input (a SOL source), syncing and\n * closing it back to the taker. Anything else — a System transfer elsewhere, a token transfer, a second Jupiter call —\n * is refused; the wallet's balance proof alone let a few hundredths of a SOL and the slippage band leave per swap.\n */\n const shapeRefusal = (ix: JupiterInstruction, want: {taker: string; inputMint: string; amountIn: bigint; wsolAta: string}): string | null => {\n const data = fromBase64(ix.data ?? \"\");\n const acc = (i: number) => ix.accounts[i]?.pubkey;\n if (ix.programId === ATA_PROGRAM) {\n // CreateIdempotent: [payer, ata, owner, mint, system, token program] — the taker pays for its own account.\n if (data.length !== 1 || data[0] !== 1) return \"an associated-token instruction other than CreateIdempotent\";\n if (acc(0) !== want.taker || acc(2) !== want.taker) return \"an associated token account for someone else\";\n return null;\n }\n if (ix.programId === SYSTEM_PROGRAM) {\n // Transfer: u32 LE 2 + u64 lamports, [from, to] — only the input, into the taker's own wSOL account.\n if (data.length !== 12 || data[0] !== 2 || data[1] !== 0 || data[2] !== 0 || data[3] !== 0) return \"a System instruction other than Transfer\";\n if (want.inputMint !== WSOL_MINT) return \"a SOL transfer on a token-source swap\";\n const lamports = new DataView(data.buffer, data.byteOffset + 4, 8).getBigUint64(0, true);\n if (acc(0) !== want.taker || acc(1) !== want.wsolAta) return `a SOL transfer to ${acc(1)}, not the taker's wSOL account`;\n if (lamports !== want.amountIn) return `a SOL transfer of ${lamports}, not the ${want.amountIn} input`;\n return null;\n }\n if (ix.programId === TOKEN_PROGRAM) {\n if (data.length === 1 && data[0] === 17) return acc(0) === want.wsolAta ? null : \"SyncNative on another account\"; // SyncNative\n if (data.length === 1 && data[0] === 9) { // CloseAccount: [account, destination, owner]\n return acc(0) === want.wsolAta && acc(1) === want.taker && acc(2) === want.taker ? null : \"a CloseAccount that is not the taker's wSOL account back to the taker\";\n }\n if (data.length === 33 && data[0] === 18) { // InitializeAccount3(owner): an account the taker owns\n return bytesEqual(data.subarray(1), getAddressEncoder().encode(address(want.taker))) ? null : \"a token account initialized for someone else\";\n }\n return `a Token instruction (tag ${data[0] ?? \"none\"}) the swap does not need`;\n }\n if (ix.programId === JUPITER_PROGRAM) return \"a second Jupiter instruction\";\n return `instruction for program ${ix.programId}`;\n };\n\n /** Every instruction the API returned, checked; returns the ordered list to assemble and the suggested unit price. */\n const vet = (b: BuildResponse, want: {taker: string; inputMint: string; outputMint: string; amountIn: bigint; slippageBps: number; wsolAta: string}): {instructions: JupiterInstruction[]; price: bigint; quotedOut: bigint} => {\n if (b.swapMode && b.swapMode !== \"ExactIn\") throw new Error(`swap mode ${b.swapMode}`);\n if (b.inputMint !== want.inputMint || b.outputMint !== want.outputMint) throw new Error(\"the answer names other mints\");\n if (b.inAmount !== want.amountIn.toString()) throw new Error(`the answer spends ${b.inAmount}, not ${want.amountIn}`);\n if (String(b.transactionVersion ?? \"0\") !== \"0\") throw new Error(`transaction version ${b.transactionVersion}`);\n if (b.tipInstruction) throw new Error(\"unexpected tip instruction\");\n if (!b.swapInstruction) throw new Error(\"no swap instruction\");\n if (b.swapInstruction.programId !== JUPITER_PROGRAM) throw new Error(`swap instruction targets ${b.swapInstruction.programId}`);\n const args = decodeSwapArgs(fromBase64(b.swapInstruction.data));\n if (args.inAmount !== want.amountIn) throw new Error(`swap instruction spends ${args.inAmount}, not ${want.amountIn}`);\n if (String(args.quotedOutAmount) !== b.outAmount) throw new Error(\"swap instruction's quoted output differs from the answer\");\n if (args.slippageBps !== want.slippageBps) throw new Error(`swap instruction allows ${args.slippageBps} bps slippage, not ${want.slippageBps}`);\n if (args.platformFeeBps !== 0 || args.positiveSlippageBps !== 0) throw new Error(\"swap instruction takes a platform fee\");\n let price = 0n;\n for (const ix of b.computeBudgetInstructions ?? []) {\n if (ix.programId !== COMPUTE_BUDGET_PROGRAM) throw new Error(`compute-budget slot holds ${ix.programId}`);\n const d = decodeComputeBudget(fromBase64(ix.data));\n if (d.price !== undefined) price = d.price;\n }\n const instructions = [...(b.setupInstructions ?? []), b.swapInstruction, ...(b.cleanupInstruction ? [b.cleanupInstruction] : []), ...(b.otherInstructions ?? [])];\n let funded = false;\n for (const ix of instructions) {\n if (!JUPITER_TX_PROGRAMS.has(ix.programId) || ix.programId === COMPUTE_BUDGET_PROGRAM) throw new Error(`instruction for program ${ix.programId}`);\n for (const a of ix.accounts) if (a.isSigner && a.pubkey !== want.taker) throw new Error(`instruction needs signer ${a.pubkey}`);\n if (ix === b.swapInstruction) continue;\n const why = shapeRefusal(ix, want);\n if (why) throw new Error(why);\n if (ix.programId === SYSTEM_PROGRAM) {\n if (funded) throw new Error(\"a second SOL transfer\");\n funded = true;\n }\n }\n return {instructions, price: price > maxPrice ? maxPrice : price, quotedOut: args.quotedOutAmount};\n };\n\n /** 1.2× the units a simulation uses (capped); null when no RPC answers. A failing simulation refuses the quote. */\n const simulateUnits = async (wire: string): Promise<number | null> => {\n if (!rpcUrls.length) return null;\n let r: {value?: {err?: unknown; unitsConsumed?: number; logs?: string[]}};\n try {\n r = (await rpc(\"simulateTransaction\", [wire, {encoding: \"base64\", sigVerify: false, replaceRecentBlockhash: true, commitment: \"processed\"}])) as typeof r;\n } catch {\n return null;\n }\n if (r?.value?.err) {\n const log = (r.value.logs ?? []).filter((l) => /error|failed|insufficient/i.test(l)).slice(-1)[0] ?? \"\";\n const err = JSON.stringify(r.value.err);\n // The usual reason, said plainly: the wallet lacks the input. Confirmed 2026-10-24 by building the same\n // USDS / LINK / WBTC → USDC swaps from an empty wallet (6025) and from real holders (built fine).\n // Jupiter 6024 = insufficient funds, 6025 = no token account for the input; System Program 1 = not enough SOL.\n const jupiterCode = /JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 failed/.test(log) ? /\"Custom\":(\\d+)/.exec(err)?.[1] : undefined;\n if (jupiterCode === \"6024\" || jupiterCode === \"6025\" || (/\"Custom\":1\\}/.test(err) && /Program 11111111111111111111111111111111 failed/.test(log))) {\n throw new Error(`not enough of the input token in the wallet${jupiterCode === \"6025\" ? \" (no token account for it)\" : \"\"} — simulation fails: ${err}`);\n }\n throw new Error(`simulation fails: ${err}${log ? ` (${log.slice(0, 160)})` : \"\"}`);\n }\n const used = r?.value?.unitsConsumed;\n return used ? Math.min(MAX_COMPUTE_UNITS, Math.ceil(used * 1.2)) : null;\n };\n\n return {\n name: \"jupiter\",\n describeActivity: describeJupiterActivity,\n enabled: () => config.enabled ?? true,\n supportsSameChain: true,\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (from: string, to: string) => cfg.supports(from, to),\n supportsRoute(from: Asset, to: Asset): boolean {\n if (!cfg.supports(from.chain, to.chain)) return false;\n const a = jupiterMint(from.token), b = jupiterMint(to.token);\n return !!a && !!b && a !== b;\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n const dry = params.dry !== false;\n const refuse = (reason: string): null => {\n params.onRefusal?.(`jupiter: ${reason}`);\n return null;\n };\n if (!cfg.supports(params.sourceChain, params.destChain)) return refuse(`same-chain Solana only (${params.sourceChain} → ${params.destChain})`);\n if (params.flex) return refuse(\"amount-flexible deposits are not supported\");\n const inputMint = jupiterMint(params.sourceToken), outputMint = jupiterMint(params.destToken);\n if (!inputMint || !outputMint) return refuse(`unknown token (${params.sourceToken} → ${params.destToken})`);\n if (inputMint === outputMint) return refuse(\"same token on both sides\");\n const amountIn = BigInt(params.amountIn);\n if (amountIn <= 0n) return refuse(\"amount must be positive\");\n const slippageBps = params.slippageBps ?? config.defaultSlippageBps ?? DEFAULT_SLIPPAGE_BPS;\n if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > MAX_SLIPPAGE_BPS) return refuse(`slippage ${slippageBps} bps is out of range`);\n\n // The swap pays the taker's own token account: a live quote must be for the signer's own address.\n const self = params.refundAddress || params.destAddress;\n if (!dry) {\n if (!self || !BASE58.test(self)) return refuse(\"live quote without the signer's address\");\n if (params.destAddress && params.destAddress !== self) return refuse(\"the recipient must be the signing wallet (Jupiter pays the taker)\");\n }\n const taker = self && BASE58.test(self) ? self : DRY_TAKER;\n\n const qs = new URLSearchParams({inputMint, outputMint, amount: params.amountIn, taker, slippageBps: String(slippageBps)});\n if (config.computeUnitPricePercentile) qs.set(\"computeUnitPricePercentile\", config.computeUnitPricePercentile);\n let b: BuildResponse;\n try {\n const r = await get(`/build?${qs.toString()}`, signal);\n if (!r.ok) return refuse(`build ${r.status}: ${String((r.body as BuildResponse | null)?.error ?? \"\").slice(0, 160)}`);\n b = (r.body ?? {}) as BuildResponse;\n } catch (e) { return refuse(`build failed: ${(e as Error).message.slice(0, 160)}`); }\n if (!b.outAmount || !/^\\d+$/.test(b.outAmount)) return refuse(\"answer without an output amount\");\n\n let vetted: ReturnType<typeof vet>;\n const [wsolAta] = await getProgramDerivedAddress({programAddress: address(ATA_PROGRAM), seeds: [getAddressEncoder().encode(address(taker)), getAddressEncoder().encode(address(TOKEN_PROGRAM)), getAddressEncoder().encode(address(WSOL_MINT))]});\n try { vetted = vet(b, {taker, inputMint, outputMint, amountIn, slippageBps, wsolAta}); } catch (e) { return refuse((e as Error).message); }\n const minOut = minOutOf(vetted.quotedOut, slippageBps);\n if (params.minAmountOut !== undefined && minOut < BigInt(params.minAmountOut)) {\n return refuse(`guaranteed ${minOut} is below the floor ${params.minAmountOut} at ${slippageBps} bps`);\n }\n const route = (b.routePlan ?? []).map((s) => s.swapInfo?.label).filter(Boolean).join(\" + \");\n const impact = Number(b.priceImpactPct ?? 0);\n const common = {\n provider: \"jupiter\",\n depositAddress: \"\",\n depositMemo: null,\n sourceAmount: params.amountIn,\n destAmount: b.outAmount,\n minDestAmount: minOut.toString(),\n feeUsd: 0,\n etaSeconds: 15,\n reliability: impact > 0.05 ? 0.8 : 0.97,\n validUntilMs: Date.now() + QUOTE_TTL_MS,\n };\n if (dry) {\n return {...common, intentId: `dry:${INTENT_PREFIX}${Date.now().toString(36)}`, fees: [{type: \"network\" as const, amount: BASE_FEE_LAMPORTS.toString(), token: \"native\", included: false, description: \"Solana base fee\"}], ...(route ? {providerData: {route}} : {})};\n }\n\n const blockhash = b.blockhashWithMetadata?.blockhash;\n const lastValid = b.blockhashWithMetadata?.lastValidBlockHeight;\n if (!blockhash || blockhash.length !== 32 || !lastValid) return refuse(\"answer without a blockhash\");\n const assemble = (limit: number) => assembleTransaction({\n taker, instructions: vetted.instructions, computeUnitLimit: limit, computeUnitPrice: vetted.price,\n blockhash: Uint8Array.from(blockhash), lastValidBlockHeight: lastValid, addressesByLookupTableAddress: b.addressesByLookupTableAddress,\n });\n let wire: string, limit = MAX_COMPUTE_UNITS;\n try {\n wire = assemble(MAX_COMPUTE_UNITS);\n const units = await simulateUnits(wire);\n if (units) { limit = units; wire = assemble(units); }\n } catch (e) { return refuse((e as Error).message.slice(0, 240)); }\n const priority = (vetted.price * BigInt(limit) + 999_999n) / 1_000_000n;\n return {\n ...common,\n intentId: `${INTENT_PREFIX}${lastValid}:${Date.now().toString(36)}`,\n // `value` declares the native SOL the transaction may take: the input for a SOL source (Jupiter wraps it), none for a token.\n txRequest: {serializedTx: wire, value: inputMint === WSOL_MINT ? params.amountIn : \"0\"},\n fees: [{type: \"network\", amount: (BASE_FEE_LAMPORTS + priority).toString(), token: \"native\", included: false, description: `Solana base + priority fee (${limit} CU at ${vetted.price} µlamports)`}],\n providerData: {inputMint, outputMint, slippageBps: String(slippageBps), computeUnits: String(limit), ...(route ? {route} : {})},\n };\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n const tx = quote.txRequest?.serializedTx;\n if (!tx || quote.intentId.startsWith(\"dry:\")) throw new Error(\"jupiter: not a live quote\");\n return {chain: SOLANA_CAIP2, to: \"\", value: quote.txRequest!.value ?? \"0\", serializedTx: tx};\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n if (!ref.sourceTxHash || !rpcUrls.length) return {state: \"pending\"};\n try {\n const r = (await rpc(\"getSignatureStatuses\", [[ref.sourceTxHash], {searchTransactionHistory: true}])) as {value?: ({err?: unknown; confirmationStatus?: string} | null)[]};\n const s = r?.value?.[0];\n if (!s) return {state: \"pending\"};\n if (s.err) return {state: \"failed\"};\n return s.confirmationStatus === \"confirmed\" || s.confirmationStatus === \"finalized\" ? {state: \"completed\", destTxHash: ref.sourceTxHash} : {state: \"pending\"};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n\nfunction bytesEqual(a: ArrayLike<number>, b: ArrayLike<number>): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n","import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {jupiter as jupCfg} from \"./config.js\";\nimport {jupiterProvider, type JupiterProviderConfig} from \"./provider.js\";\n\nexport interface JupiterSwap2Config extends Swap2EngineConfig, JupiterProviderConfig {}\n\n/** Standalone Jupiter swap2: same-chain Solana swaps (Metis routing, /build, no Jupiter fee). */\nexport class JupiterSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: JupiterSwap2Config) {\n super(account, config);\n this.provider = jupiterProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return jupCfg.supportsChain(caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return jupCfg.supports(fromChain, toChain);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA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sB,GAA+B;AACvE,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,IAAK,KAAI,EAAE,CAAC,MAAM,EAAE,CAAC,EAAG,QAAO;AAC7D,SAAO;AACT;;;ACzUA,oBAAkC;AAQ3B,IAAM,uBAAN,cAAmC,kCAAoB;AAAA,EACzC;AAAA,EACnB,YAAY,SAAmC,QAA4B;AACzE,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,gBAAgB,MAAM;AAAA,EACxC;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,QAAO,cAAc,KAAK;AAAA,EACnC;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,QAAO,SAAS,WAAW,OAAO;AAAA,EAC3C;AACF;","names":["import_kit","BASE58","limit"]}
|
package/dist/index.js
CHANGED
package/dist/protocol.cjs
CHANGED
|
@@ -63,6 +63,9 @@ function describeJupiterActivity(tx, ctx) {
|
|
|
63
63
|
return item;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// src/provider.ts
|
|
67
|
+
var import_kit2 = require("@solana/kit");
|
|
68
|
+
|
|
66
69
|
// src/codec.ts
|
|
67
70
|
var import_base = require("@scure/base");
|
|
68
71
|
var ROUTE_V2 = "bb64facc31c4af14";
|
|
@@ -175,6 +178,35 @@ function jupiterProvider(config = {}) {
|
|
|
175
178
|
}
|
|
176
179
|
throw last;
|
|
177
180
|
};
|
|
181
|
+
const shapeRefusal = (ix, want) => {
|
|
182
|
+
const data = fromBase64(ix.data ?? "");
|
|
183
|
+
const acc = (i) => ix.accounts[i]?.pubkey;
|
|
184
|
+
if (ix.programId === ATA_PROGRAM) {
|
|
185
|
+
if (data.length !== 1 || data[0] !== 1) return "an associated-token instruction other than CreateIdempotent";
|
|
186
|
+
if (acc(0) !== want.taker || acc(2) !== want.taker) return "an associated token account for someone else";
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
if (ix.programId === SYSTEM_PROGRAM) {
|
|
190
|
+
if (data.length !== 12 || data[0] !== 2 || data[1] !== 0 || data[2] !== 0 || data[3] !== 0) return "a System instruction other than Transfer";
|
|
191
|
+
if (want.inputMint !== WSOL_MINT) return "a SOL transfer on a token-source swap";
|
|
192
|
+
const lamports = new DataView(data.buffer, data.byteOffset + 4, 8).getBigUint64(0, true);
|
|
193
|
+
if (acc(0) !== want.taker || acc(1) !== want.wsolAta) return `a SOL transfer to ${acc(1)}, not the taker's wSOL account`;
|
|
194
|
+
if (lamports !== want.amountIn) return `a SOL transfer of ${lamports}, not the ${want.amountIn} input`;
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
if (ix.programId === TOKEN_PROGRAM) {
|
|
198
|
+
if (data.length === 1 && data[0] === 17) return acc(0) === want.wsolAta ? null : "SyncNative on another account";
|
|
199
|
+
if (data.length === 1 && data[0] === 9) {
|
|
200
|
+
return acc(0) === want.wsolAta && acc(1) === want.taker && acc(2) === want.taker ? null : "a CloseAccount that is not the taker's wSOL account back to the taker";
|
|
201
|
+
}
|
|
202
|
+
if (data.length === 33 && data[0] === 18) {
|
|
203
|
+
return bytesEqual(data.subarray(1), (0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(want.taker))) ? null : "a token account initialized for someone else";
|
|
204
|
+
}
|
|
205
|
+
return `a Token instruction (tag ${data[0] ?? "none"}) the swap does not need`;
|
|
206
|
+
}
|
|
207
|
+
if (ix.programId === JUPITER_PROGRAM) return "a second Jupiter instruction";
|
|
208
|
+
return `instruction for program ${ix.programId}`;
|
|
209
|
+
};
|
|
178
210
|
const vet = (b, want) => {
|
|
179
211
|
if (b.swapMode && b.swapMode !== "ExactIn") throw new Error(`swap mode ${b.swapMode}`);
|
|
180
212
|
if (b.inputMint !== want.inputMint || b.outputMint !== want.outputMint) throw new Error("the answer names other mints");
|
|
@@ -195,9 +227,17 @@ function jupiterProvider(config = {}) {
|
|
|
195
227
|
if (d.price !== void 0) price = d.price;
|
|
196
228
|
}
|
|
197
229
|
const instructions = [...b.setupInstructions ?? [], b.swapInstruction, ...b.cleanupInstruction ? [b.cleanupInstruction] : [], ...b.otherInstructions ?? []];
|
|
230
|
+
let funded = false;
|
|
198
231
|
for (const ix of instructions) {
|
|
199
232
|
if (!JUPITER_TX_PROGRAMS.has(ix.programId) || ix.programId === COMPUTE_BUDGET_PROGRAM) throw new Error(`instruction for program ${ix.programId}`);
|
|
200
233
|
for (const a of ix.accounts) if (a.isSigner && a.pubkey !== want.taker) throw new Error(`instruction needs signer ${a.pubkey}`);
|
|
234
|
+
if (ix === b.swapInstruction) continue;
|
|
235
|
+
const why = shapeRefusal(ix, want);
|
|
236
|
+
if (why) throw new Error(why);
|
|
237
|
+
if (ix.programId === SYSTEM_PROGRAM) {
|
|
238
|
+
if (funded) throw new Error("a second SOL transfer");
|
|
239
|
+
funded = true;
|
|
240
|
+
}
|
|
201
241
|
}
|
|
202
242
|
return { instructions, price: price > maxPrice ? maxPrice : price, quotedOut: args.quotedOutAmount };
|
|
203
243
|
};
|
|
@@ -266,8 +306,9 @@ function jupiterProvider(config = {}) {
|
|
|
266
306
|
}
|
|
267
307
|
if (!b.outAmount || !/^\d+$/.test(b.outAmount)) return refuse("answer without an output amount");
|
|
268
308
|
let vetted;
|
|
309
|
+
const [wsolAta] = await (0, import_kit2.getProgramDerivedAddress)({ programAddress: (0, import_kit2.address)(ATA_PROGRAM), seeds: [(0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(taker)), (0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(TOKEN_PROGRAM)), (0, import_kit2.getAddressEncoder)().encode((0, import_kit2.address)(WSOL_MINT))] });
|
|
269
310
|
try {
|
|
270
|
-
vetted = vet(b, { taker, inputMint, outputMint, amountIn, slippageBps });
|
|
311
|
+
vetted = vet(b, { taker, inputMint, outputMint, amountIn, slippageBps, wsolAta });
|
|
271
312
|
} catch (e) {
|
|
272
313
|
return refuse(e.message);
|
|
273
314
|
}
|
|
@@ -344,6 +385,11 @@ function jupiterProvider(config = {}) {
|
|
|
344
385
|
}
|
|
345
386
|
};
|
|
346
387
|
}
|
|
388
|
+
function bytesEqual(a, b) {
|
|
389
|
+
if (a.length !== b.length) return false;
|
|
390
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
347
393
|
|
|
348
394
|
// src/protocol.ts
|
|
349
395
|
var JupiterSwap2Protocol = class extends import_single.SingleProviderSwap2 {
|