@anywalletkit/protocol-swap2-core 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +2 -2
  2. package/dist/{chunk-FHEU7E5A.js → chunk-AY7DVYAN.js} +3 -3
  3. package/dist/{chunk-5FPDKWBG.js → chunk-F5TRF52T.js} +12 -3
  4. package/dist/chunk-F5TRF52T.js.map +1 -0
  5. package/dist/{chunk-6MTZNYKM.js → chunk-KB2GX6R2.js} +2 -1
  6. package/dist/{chunk-6MTZNYKM.js.map → chunk-KB2GX6R2.js.map} +1 -1
  7. package/dist/{chunk-CRCDWV3L.js → chunk-PN76KVPT.js} +59 -12
  8. package/dist/chunk-PN76KVPT.js.map +1 -0
  9. package/dist/index.cjs +67 -13
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +8 -4
  14. package/dist/remote.cjs +1 -0
  15. package/dist/remote.cjs.map +1 -1
  16. package/dist/remote.js +1 -1
  17. package/dist/server.cjs +13 -3
  18. package/dist/server.cjs.map +1 -1
  19. package/dist/server.js +8 -2
  20. package/dist/server.js.map +1 -1
  21. package/dist/swap2/base.cjs +58 -11
  22. package/dist/swap2/base.cjs.map +1 -1
  23. package/dist/swap2/base.d.cts +18 -0
  24. package/dist/swap2/base.d.ts +18 -0
  25. package/dist/swap2/base.js +2 -1
  26. package/dist/swap2/single.cjs +119 -68
  27. package/dist/swap2/single.cjs.map +1 -1
  28. package/dist/swap2/single.js +3 -3
  29. package/dist/types.cjs.map +1 -1
  30. package/dist/types.d.cts +18 -0
  31. package/dist/types.d.ts +18 -0
  32. package/dist/validate.cjs +11 -2
  33. package/dist/validate.cjs.map +1 -1
  34. package/dist/validate.d.cts +13 -3
  35. package/dist/validate.d.ts +13 -3
  36. package/dist/validate.js +5 -1
  37. package/package.json +6 -6
  38. package/dist/chunk-5FPDKWBG.js.map +0 -1
  39. package/dist/chunk-CRCDWV3L.js.map +0 -1
  40. /package/dist/{chunk-FHEU7E5A.js.map → chunk-AY7DVYAN.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/swap2/single.ts","../../src/swap2/base.ts","../../src/util.ts","../../src/errors.ts","../../src/validate.ts"],"sourcesContent":["import type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {BaseSwap2Protocol} from \"./base.js\";\nimport type {CrossChainProvider, Quote, QuoteParams} from \"../types.js\";\nimport {remotePinRefusal, validQuote} from \"../validate.js\";\n\n/** A single-provider swap2: quoting/tracking route through one solver. The\n * per-provider packages subclass this — the contribution unit shape. */\nexport abstract class SingleProviderSwap2 extends BaseSwap2Protocol {\n protected abstract readonly provider: CrossChainProvider;\n /** Why the last resolveQuote came back empty — the provider's own reason, like the router's. */\n private lastRefusal = \"\";\n protected async resolveQuote(params: QuoteParams): Promise<Quote | null> {\n this.lastRefusal = \"\";\n const name = this.provider.name;\n const outer = params.onRefusal;\n const snapshot = Object.freeze({...params, onRefusal: (reason: string) => {\n this.lastRefusal ||= reason.startsWith(`${name}:`) ? reason : `${name}: ${reason}`;\n try { outer?.(reason); } catch { /* diagnostics only */ }\n }});\n const from = Object.freeze({chain: snapshot.sourceChain, token: snapshot.sourceToken});\n const to = Object.freeze({chain: snapshot.destChain, token: snapshot.destToken});\n try {\n // Standalone contribution classes must enforce the same dark flag,\n // capability and quote-integrity boundary as the aggregator. Previously\n // they called getQuote directly, so `enabled: false` was advisory only.\n if (!this.provider.enabled() || !this.provider.supportsRoute(from, to)) return null;\n if (snapshot.sourceChain === snapshot.destChain && this.provider.supportsSameChain !== true) return null;\n const quote = await this.provider.getQuote(snapshot);\n if (!quote) return null;\n if (!validQuote(quote, snapshot, name)) {\n this.lastRefusal ||= `${name}: rejected by validation (minDest=${quote.minDestAmount} vs floor=${snapshot.minAmountOut ?? \"-\"})`;\n return null;\n }\n const unpinned = remotePinRefusal(this.provider, quote, snapshot.sourceChain);\n if (unpinned) {\n this.lastRefusal ||= unpinned;\n return null;\n }\n return {...quote, provider: name};\n } catch (err) {\n this.lastRefusal ||= `${name}: ${(err instanceof Error ? err.message : String(err)).slice(0, 160)}`;\n return null;\n }\n }\n protected override noRouteDetail(): string {\n return this.lastRefusal.slice(0, 400);\n }\n protected providerFor(name: string): CrossChainProvider | undefined {\n return name === this.provider.name ? this.provider : undefined;\n }\n /** Activity recognition lives on the provider (shared with the router); null when it has none. */\n override describeActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n return this.provider.describeActivity?.(tx, ctx) ?? null;\n }\n protected override protocolEnabled(): boolean {\n try { return this.provider.enabled(); } catch { return false; }\n }\n close(): void {\n this.provider.close?.();\n }\n}\n","/**\n * `Swap2Protocol` adapter over the cross-chain engine.\n *\n * The engine speaks in symbols + CAIP-2 chain ids and a deposit-address /\n * calldata execution model; core's `Swap2Protocol` speaks in provider token ids\n * bound to an account whose chain is the source. This base bridges the two:\n * it maps `Swap2Options` → the engine's `QuoteParams`, delegates quoting to a\n * provider (or the router, in the aggregator), and executes the source leg\n * through the bound account. Subclasses only supply \"which provider(s)\".\n */\nimport {Swap2Protocol} from \"@anywalletkit/core\";\nimport {encodeFunctionData, getAddress} from \"viem\";\nimport {decodeCall} from \"@anywalletkit/tx-preview-evm\";\nimport type {\n Swap2Options,\n Swap2Quote,\n Swap2Result,\n Swap2StatusOptions,\n Swap2StatusResult,\n Swap2Status,\n Swap2Fee,\n Swap2ProtocolConfig,\n Swap2SupportedChain,\n Swap2SupportedToken,\n Swap2SupportedTokensOptions,\n BridgeOptions,\n BridgeResult,\n SwapOptions,\n SwapResult,\n} from \"@anywalletkit/core\";\nimport {\n CC_SOURCE_CHAINS,\n ccAsset,\n ccAssetByToken,\n isTokenAddress,\n isUnlisted,\n resolveAsset,\n type CcAsset,\n type CcChain,\n} from \"@anywalletkit/swap2-assets\";\nimport type {CrossChainProvider, IntentStatus, QuoteParams, Quote, UnsignedTx} from \"../types.js\";\nimport {tonRawAddress} from \"../util.js\";\nimport {\n Swap2ConfigurationError,\n Swap2ExecutionError,\n Swap2FeeLimitError,\n Swap2InFlightError,\n Swap2InsufficientGasError,\n Swap2MaybeSentError,\n Swap2QuoteError,\n Swap2StatusError,\n Swap2UnsupportedOperationError,\n Swap2ValidationError,\n} from \"../errors.js\";\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nconst ERC20_TRANSFER_ABI = [\n {\n type: \"function\",\n name: \"transfer\",\n stateMutability: \"nonpayable\",\n inputs: [\n {name: \"to\", type: \"address\"},\n {name: \"amount\", type: \"uint256\"},\n ],\n outputs: [{type: \"bool\"}],\n },\n] as const;\nconst ERC20_APPROVE_ABI = [\n {type: \"function\", name: \"approve\", stateMutability: \"nonpayable\", inputs: [{name: \"spender\", type: \"address\"}, {name: \"amount\", type: \"uint256\"}], outputs: [{type: \"bool\"}]},\n] as const;\nconst approveData = (spender: string, amount: bigint) =>\n encodeFunctionData({abi: ERC20_APPROVE_ABI, functionName: \"approve\", args: [spender as `0x${string}`, amount]});\n\n/** swap2() calls running per account object, keyed by their options: a double tap must not run two swaps. */\nconst IN_FLIGHT = new WeakMap<object, Set<string>>();\nconst inFlightKey = (fromChain: string, o: Swap2Options) =>\n JSON.stringify([fromChain, o.fromToken, o.toToken, o.toChain, o.recipient, o.refundAddress, o.fromTokenAmount, o.toTokenAmount, o.minAmountOut, o.slippage],\n (_k, v) => (typeof v === \"bigint\" ? v.toString() : v));\n\n/** A lost transport answer, in a message, an error code or an error name (Node / undici / React Native / browsers). */\nconst LOST_ANSWER = /socket hang up|ECONNRESET|ECONNABORTED|ETIMEDOUT|EPIPE|ENETUNREACH|EHOSTUNREACH|EAI_AGAIN|UND_ERR_[A-Z_]+|timed? ?out|TimeoutError|request aborted|AbortError|connection (?:closed|reset)|fetch failed|failed to fetch|network request failed|other side closed/i;\n\n/**\n * Did a failed broadcast possibly reach the node? Every chain package says so on its error\n * (`BroadcastUnknownError`: `maybeSent` + the locally computed `hash`), anywhere in the cause\n * chain. A node's explicit refusal (`answered: true`) is a clean failure. Otherwise a lost\n * transport answer — in the message, code or name of any error in the chain (`fetch failed` with\n * an `UND_ERR_*` cause, React Native's `Network request failed`, `ECONNRESET`, a `TimeoutError`) —\n * is treated as possibly sent (round 3, M12). A refusal before signing is a clean failure.\n */\nfunction maybeSent(error: unknown): {hash?: string} | null {\n const chain: Array<{maybeSent?: unknown; hash?: unknown; answered?: unknown; message?: unknown; code?: unknown; name?: unknown}> = [];\n for (let e = error as {cause?: unknown} | undefined, i = 0; e && typeof e === \"object\" && i < 6; e = e.cause as typeof e, i++) chain.push(e as never);\n for (const e of chain) if (e.maybeSent === true) return typeof e.hash === \"string\" && e.hash ? {hash: e.hash} : {};\n if (chain.some((e) => e.answered === true)) return null;\n const texts = chain.length ? chain.map((e) => [e.message, e.code, e.name].filter((x) => typeof x === \"string\").join(\" \")) : [String(error)];\n return texts.some((t) => LOST_ANSWER.test(t)) ? {} : null;\n}\n\n/** Our config adds the account's source chain (CAIP-2) the base type omits. */\n/**\n * Where an execution is, for progress UIs. A source leg can spend a minute\n * before anything is signed (two awaited ERC-20 approvals for USDT), so\n * \"signing\" alone reads as hung. \"requoting\": the mined approvals outlived\n * the quote's TTL and the engine is fetching a fresh quote for the same\n * spender and amount (the allowance is kept, not revoked). Diagnostics only:\n * a throwing observer can never change the outcome.\n */\n/**\n * Most native coin a route may charge on top of the input (bridge messaging\n * fees), base units per chain. Above this the quote is refused even though it\n * declared the fee — a provider bug or a hostile backend must not turn a\n * token swap into a native drain.\n */\n/**\n * Base-unit precision of a chain's native coin — what `value`, `eth_getBalance`\n * and a declared `nativeFee` are counted in. Every EVM chain the engine knows\n * accounts for gas in 18-decimal units, Arc included: Arc's gas token is USDC,\n * but its native accounting is 18-decimal (\"the native USDC gas token uses 18\n * decimals of precision, while the USDC ERC-20 interface uses 6\" —\n * docs.arc.network, gas-and-fees / contract-addresses, 2026-10-14). Arc is\n * pinned here so the 6-decimal ERC-20 view can never leak into a ceiling:\n * 10 USDC of fee headroom is 10 × 10^18 base units, not 10 × 10^6. A chain\n * whose native accounting is genuinely not 18-decimal gets its own row and\n * every cap below, declared in whole coins, scales with it.\n */\nexport const NATIVE_DECIMALS: Readonly<Record<string, number>> = Object.freeze({\n \"eip155:5042\": 18, // Arc — USDC gas token, 18-decimal native accounting (ERC-20 view at 0x3600… is 6)\n});\nconst DEFAULT_NATIVE_DECIMALS = 18;\n/** Decimals of `chain`'s native coin in base units (18 unless the chain says otherwise). */\nexport function nativeDecimals(chain: string): number {\n return NATIVE_DECIMALS[chain] ?? DEFAULT_NATIVE_DECIMALS;\n}\n/** `whole` native coins (an integer, or a decimal string such as \"0.005\") in `chain`'s base units. */\nexport function nativeUnits(chain: string, whole: number | string): bigint {\n const text = String(whole);\n if (!/^\\d+(\\.\\d+)?$/.test(text)) throw new Error(`swap2: malformed native amount '${text}'`);\n const [int, frac = \"\"] = text.split(\".\") as [string, string?];\n const decimals = nativeDecimals(chain);\n if (frac.length > decimals) throw new Error(`swap2: '${text}' has more than ${decimals} fractional digits for ${chain}`);\n return BigInt(int + frac.padEnd(decimals, \"0\"));\n}\nconst NATIVE_FEE_CAP: Readonly<Record<string, bigint>> = Object.freeze({\n \"eip155:1\": 5_000_000_000_000_000n, // 0.005 ETH\n \"eip155:137\": 20_000_000_000_000_000_000n, // 20 POL\n \"eip155:56\": 5_000_000_000_000_000n, // 0.005 BNB\n \"eip155:43114\": 100_000_000_000_000_000n, // 0.1 AVAX\n \"eip155:999\": 100_000_000_000_000_000n, // 0.1 HYPE\n // Non-ETH natives, ~$10-12 each at 2026-10-13 prices (0.005 ETH ≈ $12.6).\n \"eip155:100\": 10_000_000_000_000_000_000n, // 10 xDAI\n \"eip155:143\": 400_000_000_000_000_000_000n, // 400 MON\n \"eip155:146\": 200_000_000_000_000_000_000n, // 200 S\n \"eip155:9745\": 150_000_000_000_000_000_000n, // 150 XPL\n \"eip155:42220\": 100_000_000_000_000_000_000n, // 100 CELO\n \"eip155:80094\": 50_000_000_000_000_000_000n, // 50 BERA\n \"eip155:1329\": 200_000_000_000_000_000_000n, // 200 SEI\n \"eip155:98866\": 500_000_000_000_000_000_000n, // 500 PLUME\n \"eip155:196\": 100_000_000_000_000_000n, // 0.1 OKB\n // 2026-10-14 batch, ~$10 each at 2026-10-14 prices; declared in whole coins so the chain's native decimals apply.\n \"eip155:5000\": nativeUnits(\"eip155:5000\", 20), // 20 MNT (≈ $0.53 each)\n \"eip155:14\": nativeUnits(\"eip155:14\", 1500), // 1500 FLR (≈ $0.0067 each)\n \"eip155:5042\": nativeUnits(\"eip155:5042\", 10), // 10 USDC — Arc's gas token, in its 18-decimal native units\n // Katana and Morph are ETH-denominated: the 0.005 ETH default applies.\n});\nconst DEFAULT_NATIVE_FEE_CAP = 5_000_000_000_000_000n; // 0.005 of an ETH-denominated L2\n\nfunction declaredNativeFee(q: {txRequest?: {nativeFee?: string}}, chain: string): bigint {\n const raw = q.txRequest?.nativeFee;\n if (raw === undefined) return 0n;\n if (!/^\\d+$/.test(raw)) throw new Error(\"swap2: quote declares a malformed native fee\");\n const fee = BigInt(raw);\n const cap = NATIVE_FEE_CAP[chain] ?? DEFAULT_NATIVE_FEE_CAP;\n if (fee > cap) throw new Error(`swap2: quoted native fee ${fee} exceeds the cap ${cap} for ${chain}`);\n return fee;\n}\n\nexport type Swap2ExecutionPhase = \"approving\" | \"requoting\" | \"preflight\" | \"signing\" | \"broadcast\";\nexport interface Swap2ExecutionPhaseDetail {\n /** approving: which approval of how many (USDT on Ethereum needs two). */\n index?: number;\n total?: number;\n /** broadcast: the source transaction hash. */\n hash?: string;\n}\n\n/** A bigint chain id as a number, or undefined outside the safe range (checked before converting: Hermes mis-converts above 2^63). */\nconst safeChainId = (v: bigint): number | undefined => (v >= 0n && v <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(v.toString()) : undefined);\n\n/** EIP-712 domain with `chainId` as a number whatever notation the provider used. */\nexport function normalizeTypedDomain(domain: unknown): unknown {\n if (!domain || typeof domain !== \"object\") return domain;\n const raw = (domain as {chainId?: unknown}).chainId;\n let chainId: number | undefined;\n if (typeof raw === \"number\") chainId = raw;\n else if (typeof raw === \"bigint\") chainId = safeChainId(raw);\n else if (typeof raw === \"string\" && /^\\d+$/.test(raw)) chainId = Number(raw);\n else if (typeof raw === \"string\" && /^0x[0-9a-fA-F]+$/.test(raw)) chainId = safeChainId(BigInt(raw));\n return chainId === undefined || !Number.isSafeInteger(chainId) ? domain : {...(domain as object), chainId};\n}\n\n/**\n * Bind a provider's EIP-712 payload to the swap before anything is approved or signed (scan 2026-10-27 modules, F4):\n * only a Limit Order Protocol `Order` for the settlement contract the swap approves, on the source chain, from this\n * account, selling exactly the swap's input of the source token. A `Permit*` or any other typed message a backend\n * chose — an allowance to anyone, signed off-chain — is refused.\n */\nfunction assertTypedOrder(typedData: string, approvalAddress: string | undefined, e: {self: string; token: string | undefined; amount: string; chainId: number | null}): void {\n const fail = (why: string) => new Swap2ValidationError(`swap2: typed order refused — ${why}`);\n let parsed: unknown;\n try { parsed = JSON.parse(typedData); } catch { throw fail(\"the typed data is not JSON\"); }\n if (!parsed || typeof parsed !== \"object\") throw fail(\"the typed data is not an object\");\n const td = parsed as {domain?: {verifyingContract?: unknown}; types?: Record<string, unknown>; primaryType?: unknown; message?: Record<string, unknown>};\n const primary = td.primaryType;\n if (typeof primary !== \"string\" || !primary) throw fail(\"it names no primaryType\");\n if (/^permit/i.test(primary)) throw fail(`${primary} is a token approval, not an order`);\n if (primary !== \"Order\") throw fail(`primaryType ${primary} is not an order this engine signs`);\n const fields = td.types?.Order;\n const has = (name: string, type: string) => Array.isArray(fields) && fields.some((f: {name?: unknown; type?: unknown} | null) => f?.name === name && f?.type === type);\n if (!has(\"maker\", \"address\") || !has(\"makerAsset\", \"address\") || !has(\"makingAmount\", \"uint256\")) throw fail(\"the Order type has no maker / makerAsset / makingAmount\");\n const verifying = td.domain?.verifyingContract;\n if (!approvalAddress || typeof verifying !== \"string\" || verifying.toLowerCase() !== approvalAddress.toLowerCase()) {\n throw fail(`verifyingContract ${String(verifying)} is not the settlement contract the swap approves`);\n }\n if (e.chainId !== null && (normalizeTypedDomain(td.domain) as {chainId?: unknown} | undefined)?.chainId !== e.chainId) throw fail(\"the domain chainId is not the source chain\");\n const m = td.message ?? {};\n if (String(m.maker ?? \"\").toLowerCase() !== e.self.toLowerCase()) throw fail(\"the maker is not this account\");\n if (!e.token || String(m.makerAsset ?? \"\").toLowerCase() !== e.token.toLowerCase()) throw fail(\"the makerAsset is not the source token\");\n // uint256 fields come as decimal or 0x-hex strings (Omniston sends hex, live 2026-10-16).\n const raw = m.makingAmount;\n const making = typeof raw === \"string\" && /^(?:0x[0-9a-fA-F]{1,64}|[0-9]{1,78})$/.test(raw) ? BigInt(raw) : typeof raw === \"number\" && Number.isSafeInteger(raw) ? BigInt(raw) : null;\n if (making === null || making !== BigInt(e.amount)) throw fail(`makingAmount ${String(raw)} is not the swap's ${e.amount}`);\n}\n\nexport interface Swap2EngineConfig extends Swap2ProtocolConfig {\n /** CAIP-2 of the chain the bound account lives on (the swap2 source). */\n fromChain: string;\n /** Progress observer, see {@link Swap2ExecutionPhase}. */\n onExecutionPhase?: (phase: Swap2ExecutionPhase, detail?: Swap2ExecutionPhaseDetail) => void;\n /** Explicit escape hatch for adapters that can prove chain binding elsewhere. */\n skipAccountChainCheck?: boolean;\n /** Optional account chain identity when the account does not expose a provider. */\n accountChain?: string;\n /**\n * Decodes a base64 BoC into a TON `Cell` for deposits that carry a cell body\n * (e.g. Omniston escrow payloads). The package deliberately does not depend on\n * `@ton/core`; the caller supplies e.g. `(b) => Cell.fromBase64(b)`. Without\n * it, cell-body deposits fail closed — a TON account treats a string body\n * as a TEXT COMMENT, which would strand the swap.\n */\n decodeTonBody?: (bocBase64: string) => unknown;\n /**\n * Provider-SERIALIZED legs (a swap aggregator's fully built Solana\n * transaction): how much native coin, in base units, the account may lose\n * on top of the swap input — rent for a destination token account, wrapped\n * SOL juggling, priority fees. Default 20 000 000 lamports (0.02 SOL).\n */\n serializedNativeAllowance?: bigint | number | string;\n /**\n * The most nanoTON a TON cell-body deposit may attach as gas: on top of the input for a native source, the whole\n * attached value for a jetton source (default 1 TON; live Omniston swaps attach 0.1–0.4). A build attaching more is\n * refused (scan 2026-10-27 modules, F7).\n */\n tonGasCeiling?: bigint | number | string;\n /**\n * Review gate: called once the live quote is built and every payload/value\n * check has passed, BEFORE any approval or signature. It receives a copy of\n * exactly what will be signed; throwing (the user cancelled) aborts with\n * nothing sent. A quote that expires while the gate is open is refused\n * before the first approval. When the quote expires while the engine's own\n * approval is being mined, the engine re-quotes once; if the fresh quote\n * differs from the reviewed one (payload, gas, a worse output) the gate is\n * called again with `requoted: true`, and throwing then revokes the allowance.\n */\n reviewExecution?: (plan: Swap2ExecutionPlan) => Promise<void> | void;\n /**\n * Accept tokens the swap catalog does not list, named by their contract (EVM) or mint (Solana):\n * tokens the user added at their own risk. Off by default. The source token's decimals are read\n * with the account's `getTokenInfo` (a `fromTokenDecimals` that disagrees is refused); an account\n * without it must be given `fromTokenDecimals`. Only providers that trade any token (LI.FI,\n * Uniswap, Balancer, Fynd, Jupiter) quote them, and they have no USD value: the router cannot\n * judge their price, so show the user the amounts.\n */\n allowUnlistedTokens?: boolean;\n}\n\n/** What a TON cell body does, as the engine read it before signing (scan 2026-10-27 modules, F13): its op, and the jetton transfer it is. */\nexport interface TonBodySummary {\n op: number | null;\n /** TEP-74 transfer from the account's own jetton wallet: amount, where it goes, where the excess returns, the TON forwarded. */\n jettonTransfer?: {amount: bigint; destination: string | null; responseDestination: string | null; forwardTon: bigint};\n}\n\n/** What `swap2()` is about to sign, handed to {@link Swap2EngineConfig.reviewExecution}. */\nexport interface Swap2ExecutionPlan {\n provider: string;\n fromChain: string;\n destChain: string;\n destToken: string;\n recipient: string;\n refundAddress: string;\n sourceAmount: bigint;\n destAmount: bigint;\n minDestAmount: bigint;\n feeUsd: number;\n etaSeconds: number;\n validUntilMs: number;\n /** ERC-20 approvals sent first, in order (USDT on Ethereum resets to 0 first). */\n approvals: {token: string; spender: string; amount: bigint; chainId?: number}[];\n /**\n * `true` on a second review: the first quote expired while its approval was being mined, and\n * the fresh one differs from what was reviewed (another payload, a worse output). The allowance\n * is already in place, so `approvals` is empty; cancelling revokes it.\n */\n requoted?: true;\n /** The source leg exactly as the account will receive it. */\n source:\n | {kind: \"call\"; to: string; data?: string; value: bigint; chainId?: number; gasLimit?: bigint; memo?: string; memoEncoding?: \"utf8\" | \"hex\"; cellBody?: boolean; cellBodyDecoded?: TonBodySummary}\n | {kind: \"token-transfer\"; token: string; recipient: string; amount: bigint; memo?: string; memoEncoding?: \"utf8\" | \"hex\"}\n | {kind: \"serialized\"; serializedTx: string}\n | {kind: \"typed-order\"; typedData: string};\n}\n\n/**\n * What a provider-serialized transaction is allowed to do with the bound\n * account's balances; derived from the validated quote and handed to the\n * account's `sendSerializedTransaction` hook, which must prove it (simulate\n * with post-state balances) before signing. Amounts are base-unit strings.\n */\nexport interface SerializedExecutionExpectation {\n /** Most native coin the account may lose, fee excluded: swap input (native source) + allowance. */\n maxValueOut: string;\n /** Same-chain swaps: the token the account must receive and the quoted minimum (zero address = native). */\n tokenIn?: {token: string; minAmount: string};\n /** Token sources: the token the account may send and the exact swap input. */\n source?: {token: string; maxAmount: string};\n}\n\nconst DEFAULT_SERIALIZED_NATIVE_ALLOWANCE = 20_000_000n;\nconst DEFAULT_TON_GAS_CEILING = 1_000_000_000n;\nconst JETTON_TRANSFER_OP = 0x0f8a7ea5;\n\n/** A TON cell body read as a TEP-74 jetton transfer, duck-typed over the Cell `decodeTonBody` returned (@ton/core); null when it is not one. */\nfunction readTonBody(cell: unknown): TonBodySummary {\n type Slice = {loadUint(n: number): number; loadUintBig(n: number): bigint; loadCoins(): bigint; loadAddress(): unknown; loadMaybeAddress(): unknown; loadMaybeRef(): unknown};\n let s: Slice;\n try { s = (cell as {beginParse(): Slice}).beginParse(); } catch { return {op: null}; }\n let op: number;\n try { op = s.loadUint(32); } catch { return {op: null}; }\n if (op !== JETTON_TRANSFER_OP) return {op};\n try {\n s.loadUintBig(64); // query_id\n const amount = s.loadCoins();\n const destination = tonRawAddress(s.loadAddress());\n const response = s.loadMaybeAddress();\n s.loadMaybeRef(); // custom_payload\n const forwardTon = s.loadCoins();\n return {op, jettonTransfer: {amount, destination, responseDestination: response == null ? null : tonRawAddress(response), forwardTon}};\n } catch {\n return {op};\n }\n}\n\n/**\n * A bound wallet account, accepted opaquely: the write surface we need is\n * reached through {@link Swap2Signer}. Passing `undefined` builds a quote-only\n * protocol (no `swap2()` execution).\n */\nexport type Swap2Account = unknown;\n\n/** Minimal write surface we need off the bound account to send the leg. */\ninterface Swap2Signer {\n getAddress(): Promise<string> | string;\n sendTransaction(tx: {\n to?: string;\n data?: string;\n value?: bigint;\n chainId?: number;\n gasLimit?: bigint;\n /** TON message body: a text comment (string) or a decoded Cell. */\n body?: string | unknown;\n /** Tron: swap memo the account must place in `raw_data.data`. */\n memo?: string;\n /** Tron: 'hex' = `memo` is a binary payload in 0x-hex (default 'utf8'). */\n memoEncoding?: \"utf8\" | \"hex\";\n }): Promise<{hash?: string}>;\n /** The account's token-transfer surface, used by TON/Solana/Tron accounts. */\n transfer?: (options: {\n token: string;\n recipient: string;\n amount: bigint;\n /** Tron TRC-20: memo in `raw_data.data` next to the TriggerSmartContract. */\n memo?: string;\n /** Tron: 'hex' = `memo` is a binary payload in 0x-hex (default 'utf8'). */\n memoEncoding?: \"utf8\" | \"hex\";\n }) => Promise<{hash?: string}>;\n signTypedData?: (args: {domain: unknown; types: unknown; primaryType?: string; message: unknown}) => Promise<string>;\n /** TON: this account's jetton wallet for a jetton master — a jetton-source cell body must be sent to it. */\n getJettonWalletAddress?: (token: string) => Promise<unknown>;\n /**\n * Execute a provider-built transaction the account cannot rebuild (a swap\n * aggregator's serialized Solana tx). The account owns the proof: it must\n * refuse anything beyond `expect` before signing. Behind the kit's policies it also receives\n * `{ maxFee }` (the policy fee cap), to hold the transaction it signs to.\n */\n sendSerializedTransaction?: (serializedTx: string, expect: SerializedExecutionExpectation, options?: {maxFee?: bigint | number}) => Promise<{hash?: string}>;\n /**\n * Wait until a transaction this account sent is INCLUDED (and succeeded).\n * Used between an ERC-20 approval and the deposit that spends it: a signer\n * that returns on broadcast leaves the deposit's gas estimate looking at a\n * block where the allowance is still zero (or, for USDT's approve(0) →\n * approve(n) dance, still non-zero) — \"execution reverted\" before any\n * funds move. Accounts without it keep the fire-and-forget behaviour.\n */\n waitForTransaction?: (hash: string) => Promise<void>;\n /**\n * Current ERC-20 allowance of this account for `spender`. With it the\n * engine sends only the approvals the chain needs: none when the exact\n * allowance is already live, a single approve(n) for mainnet USDT when the\n * current allowance is 0 (its reset rule only bites non-zero → non-zero).\n * Without it (or when the read fails) the engine assumes the worst and\n * resets USDT every time.\n */\n getAllowance?: (token: string, spender: string) => Promise<bigint | number | string>;\n /** EVM gas pre-check before approvals: native balance and a fee upper bound per tx. */\n getBalance?: () => Promise<bigint | number | string>;\n quoteSendTransaction?: (tx: {to: string; data?: string; value?: bigint; chainId?: number; gasLimit?: bigint}) => Promise<{fee: bigint}>;\n /** CAIP-2 id of a @anywalletkit/core account. */\n chain?: string;\n getChainId?: () => Promise<number | bigint> | number | bigint;\n getNetwork?: () => Promise<{chainId?: number | bigint} | string> | {chainId?: number | bigint} | string;\n chainId?: number | bigint;\n _provider?: {getNetwork?: () => Promise<{chainId?: number | bigint}>};\n provider?: {getNetwork?: () => Promise<{chainId?: number | bigint}>};\n}\n\n/**\n * An exact allowance the first execution pass mined before its quote\n * expired, handed to the re-quote pass (SDK-128). The pass that adopts it\n * owns its cleanup; until then the first pass revokes on any failure.\n */\ninterface CarriedAllowance {\n token: string;\n spender: string;\n amount: bigint;\n revoke: () => Promise<void>;\n adopted: boolean;\n /** What the first pass's `reviewExecution` approved; the re-quote is reviewed again if it differs. */\n reviewed?: Swap2ExecutionPlan;\n}\n\n/**\n * What a reviewer committed to, minus what a re-quote may refresh without asking again: the\n * timing, fee estimate and ETA, the approvals (already mined), and the expected output, which is\n * compared separately (only a worse one asks again).\n */\nfunction reviewedIdentity(plan: Swap2ExecutionPlan): string {\n const {feeUsd: _fee, etaSeconds: _eta, validUntilMs: _valid, approvals: _approvals, destAmount: _dest, requoted: _requoted, ...pinned} = plan;\n return JSON.stringify(pinned, (_k, v: unknown) => (typeof v === \"bigint\" ? v.toString() : v));\n}\n\n/** Swap2 status ids are `awk1.<provider>.<intent>[.<sourceTxHash>]` (URI-encoded segments). */\nexport const SWAP2_ID_PREFIX = \"awk1\";\n\n/** Versioned provider/intent/source-hash id for durable status tracking. */\n/**\n * `awk1.<provider>.<intentId>[.<sourceTxHash>[.<destTxHash>]]`. The destination claim's hash rides\n * in the id `claimSwap2` returns, so a provider without a destination RPC can still tell the\n * delivery completed (round 3, M27).\n */\nfunction encodeId(provider: string, intentId: string, sourceTxHash?: string, destTxHash?: string): string {\n // encodeURIComponent leaves \".\" unescaped, which would shift decodeId's\n // split — escape it explicitly so segments are dot-safe.\n const enc = (v: string) => encodeURIComponent(v).replace(/\\./g, \"%2E\");\n const parts = [provider, intentId, ...(sourceTxHash != null ? [sourceTxHash, ...(destTxHash != null ? [destTxHash] : [])] : [])];\n return `${SWAP2_ID_PREFIX}.${parts.map(enc).join(\".\")}`;\n}\nfunction decodeId(id: string): {provider: string; intentId: string; sourceTxHash?: string; destTxHash?: string} {\n try {\n if (!id.startsWith(`${SWAP2_ID_PREFIX}.`)) throw new Error(\"unsupported id version\");\n const parts = id.slice(SWAP2_ID_PREFIX.length + 1).split(\".\");\n if (parts.length < 2 || parts.length > 4 || !parts[0] || !parts[1]) throw new Error(\"invalid id shape\");\n const provider = decodeURIComponent(parts[0]);\n const intentId = decodeURIComponent(parts[1]);\n const sourceTxHash = parts[2] ? decodeURIComponent(parts[2]) : undefined;\n const destTxHash = parts[3] ? decodeURIComponent(parts[3]) : undefined;\n if (!/^[A-Za-z0-9_-]+$/.test(provider) || !intentId || (parts[2] !== undefined && !sourceTxHash) || (parts[3] !== undefined && !destTxHash)) {\n throw new Error(\"invalid id contents\");\n }\n return {provider, intentId, ...(sourceTxHash ? {sourceTxHash} : {}), ...(destTxHash ? {destTxHash} : {})};\n } catch {\n throw new Swap2ValidationError(\"swap2: malformed swap2 status id\");\n }\n}\n\nasync function readAccountChain(signer: Swap2Signer, configured?: string): Promise<string | number | bigint | undefined> {\n if (configured) return configured;\n // @anywalletkit/core accounts carry their CAIP-2 id directly.\n if (typeof signer.chain === \"string\" && signer.chain && !signer.chain.endsWith(\":unknown\")) return signer.chain;\n if (typeof signer.getChainId === \"function\") return await signer.getChainId();\n if (typeof signer.getNetwork === \"function\") {\n const network = await signer.getNetwork();\n return typeof network === \"string\" ? network : network?.chainId;\n }\n if (signer.chainId != null) return signer.chainId;\n for (const provider of [signer._provider, signer.provider]) {\n if (provider?.getNetwork) {\n const network = await provider.getNetwork();\n if (network?.chainId != null) return network.chainId;\n }\n }\n return undefined;\n}\n\n/** CAIP-2 → the coarse VM family Swap2SupportedChain.type expects. */\nfunction chainType(caip2: string): string {\n const ns = caip2.split(\":\")[0] ?? \"\";\n if (ns === \"eip155\") return \"evm\";\n if (ns === \"solana\") return \"svm\";\n if (ns === \"tron\") return \"tvm\";\n if ([\"bitcoin\", \"litecoin\", \"doge\", \"bch\", \"zcash\"].includes(ns)) return \"utxo\";\n return ns;\n}\n\n/**\n * The wallet packages name non-EVM chains by genesis hash (CAIP-2 proper:\n * `account.chain` of a Solana account is `solana:5eykt…`), while the swap2\n * catalog and every provider use the short ids. The engine takes either.\n */\nexport const SWAP2_CHAIN_ALIASES: Readonly<Record<string, string>> = Object.freeze({\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\": \"solana:mainnet\",\n \"tron:0x2b6653dc\": \"tron:728126428\",\n \"bip122:000000000019d6689c085ae165831e93\": \"bitcoin:mainnet\",\n});\n/** The swap2 id for `chain` (itself when it has no alias). */\nexport const swap2ChainId = (chain: string): string => SWAP2_CHAIN_ALIASES[chain] ?? chain;\n\n/** Normalize a `toChain` (number chainId | CAIP-2 | numeric string) to CAIP-2. */\nfunction toCaip2(chain: string | number | undefined, fallback: string): string {\n if (chain == null || chain === \"\") return fallback;\n if (typeof chain === \"number\") {\n if (!Number.isSafeInteger(chain) || chain <= 0) throw new Swap2ValidationError(\"swap2: chain id must be a positive safe integer\");\n return `eip155:${chain}`;\n }\n if (/^\\d+$/.test(chain)) {\n const id = Number(chain);\n if (!Number.isSafeInteger(id) || id <= 0) throw new Swap2ValidationError(\"swap2: chain id must be a positive safe integer\");\n return `eip155:${id}`;\n }\n if (!/^[a-z0-9]{3,8}:[-_A-Za-z0-9]{1,32}$/.test(chain)) {\n throw new Swap2ValidationError(\"swap2: chain must be a valid CAIP-2 identifier\");\n }\n return swap2ChainId(chain);\n}\n\n/** An empty token ref would resolve to the native coin (round 3, M25): it is refused instead. */\nfunction nonEmptyRef(ref: string, side: string): string {\n if (typeof ref !== \"string\" || ref.trim() === \"\") throw new Swap2ValidationError(`swap2: ${side} token must not be empty (pass the symbol or the contract address)`);\n return ref;\n}\n\n/** Resolve a token ref (symbol OR on-chain address) to the engine's symbol. */\nfunction toSymbol(caip2: string, ref: string): string {\n nonEmptyRef(ref, \"source\");\n const byToken = ref.startsWith(\"0x\") || ref.length > 20 ? ccAssetByToken(caip2, ref) : undefined;\n if (byToken) return byToken.symbol;\n if (ccAsset(caip2, ref)) return ref; // already a symbol we know\n return ref;\n}\n\n/** Resolve a dest token ref to the engine's dest address (zero = native). */\nfunction toDestAddress(caip2: string, ref: string, allowUnlisted = false): string {\n nonEmptyRef(ref, \"destination\");\n if (ref.startsWith(\"0x\")) return ref;\n const asset = ccAssetByToken(caip2, ref) ?? ccAsset(caip2, ref);\n if (!asset) {\n if (allowUnlisted && isTokenAddress(caip2, ref)) return ref;\n throw new Error(`swap2: unknown destination token '${ref}' on ${caip2}`);\n }\n return asset.contract ?? ZERO;\n}\n\nfunction snapshotOptions(options: Swap2Options): Swap2Options {\n return Object.freeze({...options});\n}\n\nfunction snapshotConfig(config?: Swap2ProtocolConfig): Swap2ProtocolConfig | undefined {\n return config ? Object.freeze({...config}) : undefined;\n}\n\nfunction snapshotQuote<T extends Quote>(quote: T): T {\n return Object.freeze({\n ...quote,\n ...(quote.txRequest ? {txRequest: Object.freeze({...quote.txRequest})} : {}),\n ...(quote.providerData ? {providerData: Object.freeze({...quote.providerData})} : {}),\n ...(quote.fees ? {fees: Object.freeze(quote.fees.map((fee) => Object.freeze({...fee})))} : {}),\n }) as T;\n}\n\nfunction exactPositiveAmount(value: number | bigint, name: string): bigint {\n if (typeof value === \"number\") {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new Swap2ValidationError(`swap2: ${name} must be a positive safe integer or bigint`);\n }\n return BigInt(value);\n }\n if (value <= 0n) throw new Swap2ValidationError(`swap2: ${name} must be a positive safe integer or bigint`);\n return value;\n}\n\n/**\n * floor(x × scale) that forgives binary representation error: a caller's\n * 0.0029 is 29 bps, though 0.0029 × 10 000 is 28.999…96 in floating point\n * (573 of the 10 001 whole-bps decimals land one short with a plain floor).\n */\nfunction floorScaled(x: number, scale: number): number {\n const v = x * scale;\n const nearest = Math.round(v);\n return Math.abs(v - nearest) < 1e-6 ? nearest : Math.floor(v);\n}\n\nfunction callerConstraints(options: Swap2Options): {minAmountOut?: bigint; slippageBps?: number} {\n let minAmountOut: bigint | undefined;\n if (options.minAmountOut !== undefined) {\n try {\n minAmountOut = BigInt(options.minAmountOut);\n } catch {\n throw new Error(\"swap2: minAmountOut must be a positive integer\");\n }\n if (minAmountOut <= 0n) throw new Error(\"swap2: minAmountOut must be a positive integer\");\n }\n let slippageBps: number | undefined;\n if (options.slippage !== undefined) {\n if (!Number.isFinite(options.slippage) || options.slippage < 0 || options.slippage >= 1) {\n throw new Error(\"swap2: slippage must be a finite decimal in [0, 1)\");\n }\n // Providers accept whole bps. Round down so their on-chain/API tolerance\n // can never be wider than the caller requested; the exact decimal is also\n // checked against the returned quote below.\n slippageBps = floorScaled(options.slippage, 10_000);\n }\n return {\n ...(minAmountOut !== undefined ? {minAmountOut} : {}),\n ...(slippageBps !== undefined ? {slippageBps} : {}),\n };\n}\n\nfunction assertQuoteConstraints(q: Quote, options: Swap2Options): void {\n const {minAmountOut} = callerConstraints(options);\n const nominal = BigInt(q.destAmount);\n const guaranteed = BigInt(q.minDestAmount);\n if (minAmountOut !== undefined && guaranteed < minAmountOut) {\n throw new Error(`swap2: quoted minimum ${guaranteed} is below caller minAmountOut ${minAmountOut}`);\n }\n if (options.slippage !== undefined) {\n const scale = 1_000_000_000n;\n const permitted = BigInt(floorScaled(options.slippage, 1_000_000_000));\n // Floor, like the providers compute their minimum (see validQuote).\n const required = (nominal * (scale - permitted)) / scale;\n if (guaranteed < required) {\n throw new Error(`swap2: quote exceeds caller slippage (${options.slippage})`);\n }\n }\n}\n\nfunction requireExecutionFloor(options: Swap2Options): void {\n if (options.minAmountOut === undefined) {\n throw new Error(\"swap2: swap2() requires caller-supplied minAmountOut\");\n }\n callerConstraints(options);\n}\n\nfunction mapStatus(s: IntentStatus): Swap2StatusResult {\n const status: Swap2Status =\n s.state === \"completed\"\n ? \"completed\"\n : s.state === \"action-required\"\n ? \"action-required\"\n : s.state === \"refund-pending\"\n ? \"refund-pending\"\n : s.state === \"partial\"\n ? \"partial\"\n : s.state === \"failed\"\n ? \"failed\"\n : s.state === \"refunded\"\n ? \"refunded\"\n : s.state === \"cancelled\"\n ? \"cancelled\"\n : s.state === \"expired\"\n ? \"expired\"\n : \"pending\";\n return s.destTxHash\n ? {status, transactions: [{hash: s.destTxHash, type: \"destination\"}]}\n : {status};\n}\n\n/** `\"\"` / whitespace → undefined: an empty input field names no address. */\nfunction blankToUndefined(v: string | undefined): string | undefined {\n return typeof v === \"string\" && v.trim() === \"\" ? undefined : v;\n}\n\n/** The options with blank `recipient` / `refundAddress` dropped (they default to the account). */\nfunction withoutBlankAddresses(o: Swap2Options): Swap2Options {\n const {recipient, refundAddress, ...rest} = o;\n const r = blankToUndefined(recipient);\n const f = blankToUndefined(refundAddress);\n return {...rest, ...(r !== undefined ? {recipient: r} : {}), ...(f !== undefined ? {refundAddress: f} : {})} as Swap2Options;\n}\n\n/**\n * Abstract swap2 protocol backed by the engine. Concrete subclasses bind\n * either a single provider (contribution-shaped) or the router (aggregator).\n */\nexport abstract class BaseSwap2Protocol extends Swap2Protocol {\n protected readonly fromChain: string;\n\n constructor(account: Swap2Account | undefined, config: Swap2EngineConfig) {\n const fromChain = toCaip2(config.fromChain, \"\");\n if (!fromChain) throw new Swap2ValidationError(\"swap2: fromChain is required\");\n const configSnapshot = Object.freeze({...config, fromChain});\n super(account as never, configSnapshot);\n this.fromChain = fromChain;\n }\n\n /** Quote the route (single provider, or best across the router). */\n protected abstract resolveQuote(params: QuoteParams): Promise<Quote | null>;\n\n /** Why the last resolveQuote came back empty (venue names + reasons), or \"\".\n * Rides inside the no-route error so execution failures are diagnosable\n * from the surface that shows them. */\n protected noRouteDetail(): string {\n return \"\";\n }\n /** Look up a provider by name to resume/track an in-flight swap2. */\n protected abstract providerFor(name: string): CrossChainProvider | undefined;\n /** Whether this protocol can route a chain at all (for support discovery). */\n protected abstract chainSupported(caip2: string): boolean;\n\n /** Report an execution phase; an observer that throws is ignored. */\n protected emitPhase(phase: Swap2ExecutionPhase, detail?: Swap2ExecutionPhaseDetail): void {\n const observer = (this._config as Swap2EngineConfig).onExecutionPhase;\n if (!observer) return;\n try {\n observer(phase, detail);\n } catch {\n /* diagnostics only */\n }\n }\n /** Runtime availability used by the public discovery methods. */\n protected protocolEnabled(): boolean { return true; }\n /** Pair-level capability used when discovery specifies both endpoints. */\n protected pairSupported(fromChain: string, toChain: string): boolean {\n return this.chainSupported(fromChain) && this.chainSupported(toChain);\n }\n\n private unlistedAllowed(): boolean {\n return (this._config as Swap2EngineConfig).allowUnlistedTokens === true;\n }\n\n /** The source asset the options name: the catalog's, or (allowUnlistedTokens) an unlisted one with its decimals. */\n protected sourceAsset(options: Swap2Options): CcAsset | undefined {\n const decimals = options.fromTokenDecimals;\n return resolveAsset(this.fromChain, toSymbol(this.fromChain, options.fromToken), {\n allowUnlisted: this.unlistedAllowed(),\n ...(decimals !== undefined ? {decimals} : {}),\n });\n }\n\n private readonly unlistedDecimals = new Map<string, number>();\n\n /**\n * Options ready to quote: with `allowUnlistedTokens`, an unlisted source token gets its decimals,\n * read from the chain through the account (cached per token) — a caller's `fromTokenDecimals` that\n * disagrees is refused. Listed tokens and every option otherwise pass through unchanged.\n */\n protected async prepareOptions(options: Swap2Options): Promise<Swap2Options> {\n if (!this.unlistedAllowed()) return options;\n const ref = toSymbol(this.fromChain, options.fromToken);\n if (resolveAsset(this.fromChain, ref) || !isTokenAddress(this.fromChain, ref)) return options;\n const key = ref.startsWith(\"0x\") ? ref.toLowerCase() : ref;\n let decimals = this.unlistedDecimals.get(key);\n if (decimals === undefined) {\n const reader = this._account as {getTokenInfo?: (token: string) => Promise<{decimals: number}>} | undefined;\n if (typeof reader?.getTokenInfo !== \"function\") {\n if (options.fromTokenDecimals === undefined) {\n throw new Swap2ValidationError(`swap2: '${ref}' is not in the catalog — pass fromTokenDecimals, or use an account that can read token info`);\n }\n return options;\n }\n decimals = (await reader.getTokenInfo(ref)).decimals;\n this.unlistedDecimals.set(key, decimals);\n }\n if (options.fromTokenDecimals !== undefined && options.fromTokenDecimals !== decimals) {\n throw new Swap2ValidationError(`swap2: fromTokenDecimals ${options.fromTokenDecimals} does not match the token's ${decimals}`);\n }\n return snapshotOptions({...options, fromTokenDecimals: decimals});\n }\n\n /** Swap2Options → the engine's QuoteParams (exact-in only). */\n protected toParams(given: Swap2Options, dry: boolean): QuoteParams {\n const options = withoutBlankAddresses(given);\n if (options.fromTokenAmount == null) {\n throw new Swap2UnsupportedOperationError(\"swap2: exact-out swap2 is not supported by the engine\");\n }\n const destChain = toCaip2(options.toChain, this.fromChain);\n const constraints = callerConstraints(options);\n const amountIn = exactPositiveAmount(options.fromTokenAmount, \"fromTokenAmount\");\n const source = this.sourceAsset(options);\n const params: QuoteParams = {\n sourceChain: this.fromChain,\n sourceToken: isUnlisted(source) ? source.contract : toSymbol(this.fromChain, options.fromToken),\n ...(isUnlisted(source) ? {sourceDecimals: source.decimals} : {}),\n destChain,\n destToken: toDestAddress(destChain, options.toToken, this.unlistedAllowed()),\n amountIn: amountIn.toString(),\n destAddress: options.recipient ?? \"\",\n dry,\n ...(constraints.minAmountOut !== undefined ? {minAmountOut: constraints.minAmountOut.toString()} : {}),\n ...(constraints.slippageBps !== undefined ? {slippageBps: constraints.slippageBps} : {}),\n };\n return options.refundAddress ? {...params, refundAddress: options.refundAddress} : params;\n }\n\n private async assertAccountChain(signer: Swap2Signer): Promise<void> {\n const config = this._config as Swap2EngineConfig;\n if (config.skipAccountChainCheck) return;\n const actual = await readAccountChain(signer, config.accountChain);\n if (actual == null) {\n throw new Error(`swap2: account chain identity is unavailable for ${this.fromChain}; set accountChain or explicitly opt out with skipAccountChainCheck`);\n }\n const expected = this.fromChain;\n const expectedId = expected.startsWith(\"eip155:\") ? expected.slice(\"eip155:\".length) : expected;\n const actualText = swap2ChainId(typeof actual === \"string\" ? actual : String(actual));\n const actualId = actualText.startsWith(\"eip155:\") ? actualText.slice(\"eip155:\".length) : actualText;\n if (actualId !== expectedId) {\n throw new Error(`swap2: account is bound to ${actualText}, but fromChain is ${expected}`);\n }\n }\n\n protected assertFeeConfig(config?: Swap2ProtocolConfig): void {\n const configured = {...(this._config as Swap2ProtocolConfig), ...(config ?? {})};\n for (const [name, value] of [[\"maxNetworkFeeBps\", configured.maxNetworkFeeBps], [\"maxProtocolFeeBps\", configured.maxProtocolFeeBps]] as const) {\n if (value === undefined) continue;\n const bps = typeof value === \"bigint\" ? value : Number.isSafeInteger(value) ? BigInt(value) : -1n;\n if (bps < 0n || bps > 10_000n) throw new Swap2ConfigurationError(`swap2: ${name} must be an integer between 0 and 10000`);\n }\n }\n\n protected assertFeeCaps(\n fees: readonly Swap2Fee[] | undefined,\n sourceAmount: bigint,\n sourceToken: string,\n config?: Swap2ProtocolConfig,\n ): void {\n this.assertFeeConfig(config);\n const configured = {...(this._config as Swap2ProtocolConfig), ...(config ?? {})};\n const caps = [\n [\"network\", configured.maxNetworkFeeBps],\n [\"protocol\", configured.maxProtocolFeeBps],\n ] as const;\n if (!caps.some(([, cap]) => cap !== undefined)) return;\n if (!fees) throw new Swap2FeeLimitError(\"swap2: fee caps require an itemized provider fee breakdown\");\n const normalizedSource = sourceToken.toLowerCase();\n for (const [type, cap] of caps) {\n if (cap === undefined) continue;\n const matching = fees.filter((fee) => fee.type === type);\n if (matching.some((fee) => fee.token.toLowerCase() !== normalizedSource)) {\n throw new Swap2FeeLimitError(`swap2: cannot apply ${type} fee cap across different fee tokens`);\n }\n const total = matching.reduce((sum, fee) => sum + fee.amount, 0n);\n const bps = typeof cap === \"bigint\" ? cap : BigInt(cap);\n if (total * 10_000n > sourceAmount * bps) {\n throw new Swap2FeeLimitError(`swap2: ${type} fee exceeds configured cap`);\n }\n }\n }\n\n protected assertQuoteFeeCaps(q: Quote, options: Swap2Options, config?: Swap2ProtocolConfig): void {\n const source = this.sourceAsset(options);\n if (!source) throw new Error(`swap2: unknown source token '${options.fromToken}' on ${this.fromChain}`);\n const token = source.contract ?? source.assetId;\n const fees = q.fees?.map((fee) => ({...fee, amount: BigInt(fee.amount)} as Swap2Fee));\n this.assertFeeCaps(fees, BigInt(q.sourceAmount), token, config);\n }\n\n protected toQuote(q: Quote, options: Swap2Options): Swap2Quote {\n // Never fabricate a zero-valued fee. Providers that expose base-unit fee\n // amounts map them precisely; otherwise the net guaranteed output remains\n // authoritative and the itemized list is honestly empty.\n const fees: Swap2Fee[] = (q.fees ?? []).map((fee) => ({\n type: fee.type,\n amount: BigInt(fee.amount),\n token: fee.token,\n included: fee.included,\n ...(fee.description ? {description: fee.description} : {}),\n }));\n return {\n fromTokenAmount: BigInt(q.sourceAmount),\n toTokenAmount: BigInt(q.destAmount),\n toTokenAmountMin: BigInt(q.minDestAmount),\n fees,\n ...(q.etaSeconds ? {estimatedDuration: q.etaSeconds} : {}),\n ...(q.validUntilMs ? {expiry: Math.floor(q.validUntilMs / 1000)} : {}),\n };\n }\n\n /** A frozen, validated copy of caller options (what every engine path works from). */\n protected snapshotOf(options: Swap2Options): Swap2Options {\n return snapshotOptions(options);\n }\n\n /** A dry route the auction already validated → the public quote, or null when the caller's floor / fee caps refuse it. */\n protected routeQuote(q: Quote, options: Swap2Options): Swap2Quote | null {\n try {\n assertQuoteConstraints(q, options);\n this.assertQuoteFeeCaps(q, options);\n return this.toQuote(q, options);\n } catch {\n return null;\n }\n }\n\n /**\n * Ask for a quote and check it against the request (amounts, slippage floor, fee ceilings in the\n * protocol config). Works on a read-only account.\n *\n * @throws {@link Swap2QuoteError} when no route answers, with the provider's own reason when it\n * gave one.\n */\n override async quoteSwap2(options: Swap2Options): Promise<Swap2Quote> {\n const snapshot = await this.prepareOptions(snapshotOptions(options));\n const q = await this.resolveQuote(this.toParams(snapshot, true));\n if (!q) {\n const detail = this.noRouteDetail();\n throw new Swap2QuoteError(`swap2: no route available for the requested pair${detail ? ` :: ${detail}` : \"\"}`);\n }\n assertQuoteConstraints(q, snapshot);\n this.assertQuoteFeeCaps(q, snapshot);\n return this.toQuote(q, snapshot);\n }\n\n /**\n * Re-quote, check the quote, show it to `reviewExecution` when configured, send any approvals,\n * then sign and broadcast the source leg. An identical call already in flight on the same account\n * is refused.\n *\n * @throws {@link Swap2ExecutionError} for a read-only account, {@link Swap2InFlightError} for a\n * double tap, {@link Swap2MaybeSentError} when the broadcast outcome is unknown (do not retry;\n * track `hash`).\n */\n override async swap2(options: Swap2Options, config?: Swap2ProtocolConfig): Promise<Swap2Result> {\n // Account first: a read-only or missing account is refused before any option is\n // validated or any network call is made (SDK protocol conformance).\n const signerCandidate = this._account as Partial<Swap2Signer> | undefined;\n if (!signerCandidate || typeof signerCandidate.sendTransaction !== \"function\") {\n throw new Swap2ExecutionError(\"swap2: swap2() requires a signing account (read-only accounts can only quote)\");\n }\n const snapshot = snapshotOptions(options);\n requireExecutionFloor(snapshot);\n // A double tap re-quotes and would run a second complete swap: refuse it\n // while the identical call is still in flight on this account.\n const key = inFlightKey(this.fromChain, snapshot);\n const running = IN_FLIGHT.get(signerCandidate) ?? new Set<string>();\n if (running.has(key)) throw new Swap2InFlightError(\"swap2: an identical swap is already in progress on this account — wait for its result\");\n running.add(key);\n IN_FLIGHT.set(signerCandidate, running);\n try {\n return await this.executeSwap2(signerCandidate as Swap2Signer, snapshot, config);\n } finally {\n running.delete(key);\n }\n }\n\n private async executeSwap2(signer: Swap2Signer, snapshot: Swap2Options, config?: Swap2ProtocolConfig, carried?: CarriedAllowance): Promise<Swap2Result> {\n const configSnapshot = snapshotConfig(config);\n this.assertFeeConfig(configSnapshot);\n await this.assertAccountChain(signer);\n // Refunds land on the SOURCE chain, so the only safe default is the bound\n // account's own address — never the recipient, which may be a dest-chain\n // address (a TON-source swap with an EVM recipient would otherwise hand the\n // provider an EVM string as the TON refund/trader wallet).\n const selfAddress = await signer.getAddress();\n // A blank field (\"\" from an empty input) is no address at all: this account, never a provider's placeholder (round 3, H8).\n const recipient = blankToUndefined(snapshot.recipient) ?? selfAddress;\n const refundAddress = blankToUndefined(snapshot.refundAddress) ?? selfAddress;\n const executionOptions = await this.prepareOptions(snapshotOptions({...snapshot, recipient, refundAddress}));\n const params = this.toParams(executionOptions, false);\n const resolved = await this.resolveQuote(params);\n if (!resolved) {\n const detail = this.noRouteDetail();\n throw new Swap2QuoteError(`swap2: no route available for the requested pair${detail ? ` :: ${detail}` : \"\"}`);\n }\n const q = snapshotQuote(resolved);\n assertQuoteConstraints(q, executionOptions);\n this.assertQuoteFeeCaps(q, executionOptions, configSnapshot);\n\n const provider = this.providerFor(q.provider);\n if (!provider) throw new Error(`swap2: provider '${q.provider}' is not registered`);\n let providerEnabled = false;\n try { providerEnabled = provider.enabled(); } catch { /* fail closed below */ }\n if (!providerEnabled) throw new Error(`swap2: provider '${q.provider}' is disabled`);\n let unsigned: UnsignedTx = Object.freeze({...await provider.buildDeposit(q)});\n\n const serialized = unsigned.serializedTx !== undefined;\n if (serialized) {\n if (!unsigned.serializedTx) throw new Error(\"swap2: provider returned an empty serialized transaction\");\n if (unsigned.data !== undefined || unsigned.bodyBoc !== undefined || unsigned.typedData !== undefined || unsigned.memo !== undefined || unsigned.approvalAddress !== undefined) {\n throw new Error(\"swap2: provider returned ambiguous execution payloads\");\n }\n if (typeof signer.sendSerializedTransaction !== \"function\") {\n throw new Swap2ExecutionError(`swap2: ${this.fromChain} serialized execution requires account.sendSerializedTransaction`);\n }\n }\n if (unsigned.chain && unsigned.chain !== this.fromChain) {\n throw new Error(`swap2: provider transaction chain ${unsigned.chain} does not match ${this.fromChain}`);\n }\n if (unsigned.stateInitBoc !== undefined) {\n throw new Error(\"swap2: deposit requires a stateInit the generic account cannot attach\");\n }\n // A remote build response is not a new authority. For ordinary calldata and\n // deposit-address providers the validated quote already commits every\n // execution field; require buildDeposit to reproduce it exactly.\n if (q.txRequest) {\n const tx = q.txRequest;\n const sameAddress = (a: string | undefined, b: string | undefined) =>\n a === b || (!!a && !!b && a.startsWith(\"0x\") && b.startsWith(\"0x\") && a.toLowerCase() === b.toLowerCase());\n if (\n !sameAddress(unsigned.to, tx.to ?? \"\") ||\n unsigned.data !== tx.data ||\n unsigned.value !== (tx.value ?? \"0\") ||\n unsigned.chainId !== tx.chainId ||\n unsigned.gasLimit !== tx.gasLimit ||\n !sameAddress(unsigned.approvalAddress, tx.approvalAddress) ||\n unsigned.serializedTx !== tx.serializedTx\n ) {\n throw new Error(\"swap2: provider build does not match the validated quote transaction\");\n }\n } else if (!unsigned.bodyBoc && !unsigned.typedData) {\n // A deposit-address quote commits the address and the memo only: the build may not add\n // calldata, a spender or a serialized transaction the quote never had (round 3, L15).\n if (!q.depositAddress || unsigned.to !== q.depositAddress || (unsigned.memo ?? null) !== q.depositMemo ||\n unsigned.data !== undefined || unsigned.approvalAddress !== undefined || unsigned.serializedTx !== undefined) {\n throw new Error(\"swap2: provider build does not match the validated quote deposit\");\n }\n }\n const executionModels = [unsigned.data !== undefined, unsigned.bodyBoc !== undefined, unsigned.typedData !== undefined]\n .filter(Boolean).length;\n if (executionModels > 1 || (unsigned.memo !== undefined && (unsigned.bodyBoc !== undefined || unsigned.typedData !== undefined)) ||\n (unsigned.orderExtension !== undefined && unsigned.typedData === undefined)) {\n throw new Error(\"swap2: provider returned ambiguous execution payloads\");\n }\n if (unsigned.approvalAddress && !unsigned.data && !unsigned.typedData) {\n throw new Error(\"swap2: approval is only valid for calldata or typed-order execution\");\n }\n // A remote stub's build that pays an address its backend named — a deposit address, a plain value send — skips\n // every pin below; it runs only on a stub the app opened to such routes (scan 2026-10-28, F9).\n if (provider.remote === true && provider.depositAddressRoutes !== true &&\n unsigned.data === undefined && unsigned.bodyBoc === undefined && unsigned.typedData === undefined && !serialized) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' sends the input to ${unsigned.to}, an address its backend named, and the app did not allow deposit-address routes for it (remoteProvider depositAddressRoutes) — refused`);\n }\n // Memo'd deposits: TON carries it as the message body, Tron in\n // raw_data.data (both TRX and TRC-20 — bifrost reads that field for\n // either contract type). Every other chain would silently drop it.\n const tronSource = this.fromChain.startsWith(\"tron:\");\n // NEAR: a NEP-141 `ft_transfer` carries `memo`; a native transfer cannot\n // (the account refuses a memo it would otherwise drop).\n const nearSource = this.fromChain.startsWith(\"near:\");\n if (unsigned.memo && !this.fromChain.startsWith(\"ton:\") && !tronSource && !nearSource) {\n throw new Error(`swap2: deposit memo execution is not implemented for ${this.fromChain}`);\n }\n if (unsigned.data !== undefined && !this.fromChain.startsWith(\"eip155:\")) {\n throw new Error(`swap2: calldata execution is not implemented for ${this.fromChain}`);\n }\n // Cell-body deposits (Omniston escrow): the body MUST be decoded to a Cell —\n // a TON account renders a string body as a text comment, stranding the\n // swap. Fail closed unless the caller supplied `decodeTonBody`.\n let cellBody: unknown;\n if (unsigned.bodyBoc !== undefined) {\n if (!unsigned.bodyBoc) throw new Error(\"swap2: cell-body deposit has an empty body\");\n if (!this.fromChain.startsWith(\"ton:\")) {\n throw new Error(`swap2: cell-body execution is not implemented for ${this.fromChain}`);\n }\n const decode = (this._config as Swap2EngineConfig).decodeTonBody;\n if (!decode) {\n throw new Error(\"swap2: cell-body deposit needs config.decodeTonBody (e.g. Cell.fromBase64)\");\n }\n cellBody = decode(unsigned.bodyBoc);\n if (cellBody == null) {\n throw new Error(\"swap2: config.decodeTonBody returned no Cell\");\n }\n }\n if (unsigned.chainId !== undefined && this.fromChain.startsWith(\"eip155:\") && String(unsigned.chainId) !== this.fromChain.slice(\"eip155:\".length)) {\n throw new Error(`swap2: provider transaction chain ${unsigned.chainId} does not match ${this.fromChain}`);\n }\n\n // TOKEN-asset sources on deposit-address routes need token-transfer\n // semantics: a bare {to, value} would move the NATIVE coin with the\n // token's base-unit amount (audit C1 — e.g. USDT source via a 1Click\n // deposit address would have sent ETH wei). EVM sources are rewritten\n // into an ERC-20 transfer(depositAddress, amount); supported non-EVM\n // sources use the account's transfer() token surface below.\n let tokenId: string | undefined;\n // The deposit-address transfer the engine writes itself (source token, quoted amount, quoted deposit address).\n let engineTransfer = false;\n if (!unsigned.data && !unsigned.bodyBoc && !unsigned.typedData && !serialized) {\n const src = this.sourceAsset(executionOptions);\n if (src?.contract) {\n if (this.fromChain.startsWith(\"eip155:\")) {\n engineTransfer = true;\n unsigned = {\n ...unsigned,\n to: src.contract,\n data: encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: \"transfer\",\n args: [unsigned.to as `0x${string}`, BigInt(q.sourceAmount)],\n }),\n value: \"0\",\n };\n } else if (\n this.fromChain.startsWith(\"solana:\") ||\n this.fromChain.startsWith(\"ton:\") ||\n this.fromChain.startsWith(\"tron:\") ||\n nearSource\n ) {\n // Solana SPL / TON jetton / Tron TRC-20 / NEAR NEP-141 source. These\n // accounts expose token movement through `transfer()`; their\n // `sendTransaction({to,value})` surface is a NATIVE transfer and does\n // not recognize custom token metadata.\n tokenId = src.contract;\n } else {\n throw new Error(\n `swap2: token deposit-address execution is not implemented for ${this.fromChain} — only cell-body/calldata providers can move non-native assets here`,\n );\n }\n }\n }\n\n // A TON jetton transfer carries the memo as its forward-payload comment: the\n // account's `transfer({memo})` surface places it there (TEP-74), exactly as\n // Tron puts it in raw_data.data and NEAR in the ft_transfer memo.\n const tonSource = this.fromChain.startsWith(\"ton:\");\n if (tokenId && (cellBody !== undefined || (unsigned.memo !== undefined && !tronSource && !nearSource && !tonSource))) {\n throw new Error(\"swap2: token deposit with memo/cell payload is not implemented\");\n }\n\n // Bind the value presented to the signer to the already validated quote.\n // Native deposits and the amount handed to transfer() must carry the exact\n // input amount; EVM token execution must never attach native value.\n const source = this.sourceAsset(executionOptions);\n if (!source) throw new Error(`swap2: unknown source token '${executionOptions.fromToken}' on ${this.fromChain}`);\n const executionValue = BigInt(unsigned.value);\n if (serialized) {\n // The native coin leaves through the serialized tx itself; `value` only\n // declares what the account may let it take: the input for a native\n // source, nothing for a token source.\n if (executionValue !== (source.contract ? 0n : BigInt(q.sourceAmount))) {\n throw new Error(\"swap2: provider execution amount does not match the validated quote\");\n }\n } else if (source.contract && this.fromChain.startsWith(\"eip155:\")) {\n // Only a fee the sealed quote declared, and only up to the chain's cap.\n const declared = declaredNativeFee(q, this.fromChain);\n if (executionValue !== declared) {\n throw new Error(declared === 0n\n ? \"swap2: token execution attempted to attach native value\"\n : `swap2: token execution value ${executionValue} does not match the quoted native fee ${declared}`);\n }\n } else if (!unsigned.typedData && !unsigned.bodyBoc && executionValue !== BigInt(q.sourceAmount) + declaredNativeFee(q, this.fromChain)) {\n throw new Error(\"swap2: provider execution amount does not match the validated quote\");\n }\n\n // A TON cell body is bound like every other build (scan 2026-10-27 modules, F7/F13/F18/F19): the TON it attaches is\n // the input (native source) plus gas up to `tonGasCeiling`; a jetton source's body is a TEP-74 transfer of exactly\n // the input from this account's own jetton wallet, its excess returning here. A remote stub's cell body also needs\n // the app's own validator (`remoteProvider` `verifyBuild`, e.g. Omniston's `omnistonVerifyBuild`).\n let tonBody: TonBodySummary | undefined;\n if (cellBody !== undefined) {\n const refuse = (why: string): never => { throw new Swap2ValidationError(`swap2: TON cell-body build refused — ${why}`); };\n const raw = (this._config as Swap2EngineConfig).tonGasCeiling;\n const ceiling = raw === undefined ? DEFAULT_TON_GAS_CEILING : BigInt(raw);\n if (ceiling < 0n) throw new Swap2ConfigurationError(\"swap2: tonGasCeiling must be non-negative\");\n if (provider.remote === true && provider.verifiesBuilds !== true) refuse(\"a remote provider's cell body needs the app's own validator (remoteProvider verifyBuild)\");\n tonBody = readTonBody(cellBody);\n const input = BigInt(q.sourceAmount);\n if (source.contract) {\n if (executionValue > ceiling) refuse(`it attaches ${executionValue} nanoTON to a jetton transfer, more than the ${ceiling} gas ceiling`);\n const t = tonBody.jettonTransfer;\n if (!t) refuse(\"a jetton-source body must be a jetton transfer\");\n if (t!.amount !== input) refuse(`the jetton transfer moves ${t!.amount}, not the swap's ${input}`);\n if (!t!.responseDestination || t!.responseDestination !== tonRawAddress(selfAddress)) refuse(\"the jetton transfer returns its excess to another wallet\");\n if (t!.forwardTon >= executionValue) refuse(\"the jetton transfer forwards more TON than the message carries\");\n const own = typeof signer.getJettonWalletAddress === \"function\" ? tonRawAddress(await signer.getJettonWalletAddress(source.contract)) : null;\n if (!own) refuse(\"the account cannot name its own jetton wallet (getJettonWalletAddress), so the target cannot be checked\");\n if (tonRawAddress(unsigned.to) !== own) refuse(`it is sent to ${unsigned.to}, not this account's ${source.symbol ?? \"source\"} jetton wallet`);\n } else {\n if (executionValue < input || executionValue - input > ceiling) refuse(`it attaches ${executionValue} nanoTON for a ${input} input, more than the ${ceiling} gas ceiling on top`);\n // A remote native-source body goes to a contract the app pinned, when it pins any (DEX pools are too many to\n // pin: then the app's verifyBuild, required above, checks the target).\n const pinned = provider.remote === true ? [...(provider.callTargets?.(this.fromChain) ?? []), ...(q.depositAddress ? [q.depositAddress] : [])].map(tonRawAddress).filter((a): a is string => !!a) : [];\n if (pinned.length && !pinned.includes(tonRawAddress(unsigned.to) ?? \"\")) refuse(`remote provider '${q.provider}' sends it to ${unsigned.to}, which the app did not pin (remoteProvider callTargets)`);\n }\n }\n\n // The engine binds the build to the quote; also bind what the quote's own calldata hands out\n // (scan 2026-10-27 modules, F8/F9/F16). A token call may only move the SOURCE token, at most the\n // swap amount, to this account, the deposit address of a deposit-address route, or a declared\n // spender; operator and Permit2 approvals are never a swap's main call. For a remote provider the\n // addresses come only from the app's pins (`callTargets` / `spenders`): the backend that wrote\n // `to`, `approvalAddress` and `depositAddress` is not the authority over them. Aggregator calldata\n // (a LI.FI diamond, a THORChain router) is not decoded here — its target is pinned, and the\n // provider's own checks and the review screen cover what it does.\n const remote = provider.remote === true;\n const pins = (list: readonly string[] | undefined) => (list ?? []).filter((a) => typeof a === \"string\" && /^0x[0-9a-fA-F]{40}$/.test(a)).map((a) => a.toLowerCase());\n const pinnedTargets = remote ? pins(provider.callTargets?.(this.fromChain)) : [];\n const pinnedSpenders = remote ? pins(provider.spenders?.(this.fromChain)) : [];\n if (remote && unsigned.approvalAddress && !pinnedSpenders.includes(unsigned.approvalAddress.toLowerCase())) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' asks to approve ${unsigned.approvalAddress} on ${this.fromChain}, which the app did not pin as a spender (remoteProvider spenders) — refused`);\n }\n if (unsigned.typedData !== undefined) {\n // The engine binds the domain, the maker and the input; the price, the receiver, the traits and the extension\n // are the provider's to check. A remote stub's order is signed only after the app's own validator ran on it\n // (`remoteProvider` `verifyBuild`, e.g. `omnistonVerifyBuild`), as for cell bodies (scan 2026-10-28, F6).\n if (remote && provider.verifiesBuilds !== true) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' asks to sign a typed order, which needs the app's own validator (remoteProvider verifyBuild) — refused`);\n }\n const chainId = this.fromChain.startsWith(\"eip155:\") ? Number(this.fromChain.slice(\"eip155:\".length)) : null;\n assertTypedOrder(unsigned.typedData, unsigned.approvalAddress, {self: selfAddress, token: source.contract ?? undefined, amount: q.sourceAmount, chainId});\n }\n if (unsigned.data !== undefined && this.fromChain.startsWith(\"eip155:\")) {\n const call = decodeCall({to: unsigned.to, data: unsigned.data, value: executionValue});\n // Calldata that is not hex bytes cannot be judged: refused, not passed as a plain call (scan 2026-10-27 modules F3).\n if (call.undecodable) throw new Swap2ValidationError(\"swap2: quote calldata is not hex bytes — refused\");\n if (call.approval && call.approval.kind !== \"erc20\") {\n throw new Swap2ValidationError(`swap2: quote calldata is ${call.approval.kind === \"operator\" ? \"an operator approval (setApprovalForAll)\" : \"a Permit2 approval\"} — never a swap's main call; refused`);\n }\n if (call.transfer || call.approval) {\n // A token call: the token is the call's target.\n if (!source.contract || unsigned.to.toLowerCase() !== source.contract.toLowerCase()) {\n throw new Swap2ValidationError(`swap2: quote calldata (${call.method}) moves ${getAddress(unsigned.to)}, not the source token — refused`);\n }\n if (call.method === \"transferFrom\") throw new Swap2ValidationError(\"swap2: quote calldata pulls the source token with transferFrom — refused\");\n const amount = call.transfer?.amount ?? call.approval?.amount ?? null;\n if (amount === null || amount > BigInt(q.sourceAmount)) {\n throw new Swap2ValidationError(`swap2: quote calldata (${call.method}) covers ${amount === null ? \"an unlimited amount\" : amount} of the source token, more than the swap's ${q.sourceAmount} — refused`);\n }\n const named = (call.transfer?.to ?? call.approval!.spender).toLowerCase();\n const allowed = engineTransfer\n ? [q.depositAddress]\n : remote\n ? [selfAddress, ...pinnedTargets, ...pinnedSpenders]\n : [selfAddress, q.depositAddress, unsigned.approvalAddress];\n if (!allowed.filter((a): a is string => !!a).map((a) => a.toLowerCase()).includes(named)) {\n throw new Swap2ValidationError(`swap2: quote calldata (${call.method}) names ${getAddress(named)}, which is not this account, the deposit address or ${remote ? \"a spender the app pinned\" : \"the declared spender\"} — refused`);\n }\n } else if (remote && !pinnedTargets.includes(unsigned.to.toLowerCase())) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' calls ${getAddress(unsigned.to)} on ${this.fromChain}, which the app did not pin as a call target (remoteProvider callTargets) — refused`);\n }\n }\n\n // ERC-20 calldata/typed-order routes need an exact allowance. Decide the\n // approvals now (the reviewer sees exactly what will be sent) but send\n // them only after every local payload/value check, so a malformed build\n // cannot leave an allowance behind before failing validation.\n const needsApproval = !!unsigned.approvalAddress && !!source.contract;\n const approvalAmount = needsApproval ? BigInt(executionOptions.fromTokenAmount!) : 0n;\n const sameHex = (a: string, b: string) => a.toLowerCase() === b.toLowerCase();\n let approvalAmounts: bigint[] = [];\n let revokeApproval: (() => Promise<void>) | undefined;\n if (carried && !needsApproval) {\n // The fresh quote no longer spends through an allowance: the one the\n // first pass mined would outlive this swap with nobody to revoke it.\n carried.adopted = true;\n await carried.revoke().catch(() => {});\n throw new Swap2QuoteError(\"swap2: the fresh quote no longer spends through an allowance — aborted, the allowance was revoked\");\n }\n if (needsApproval && carried) {\n // Re-quote pass: the allowance must fit the fresh quote exactly;\n // otherwise it is revoked and the swap aborts (the caller may retry).\n if (!sameHex(carried.token, source.contract!) || !sameHex(carried.spender, unsigned.approvalAddress!) || carried.amount !== approvalAmount) {\n carried.adopted = true;\n await carried.revoke().catch(() => {});\n throw new Swap2QuoteError(`swap2: the fresh quote moved the spender to ${unsigned.approvalAddress} — aborted, the allowance for ${carried.spender} was revoked`);\n }\n carried.adopted = true;\n revokeApproval = carried.revoke;\n } else if (needsApproval) {\n // Mainnet USDT refuses non-zero → non-zero; every other token\n // overwrites. The live allowance decides what is actually needed: the\n // reset only when USDT holds a non-zero value, nothing at all when the\n // exact amount is already in place (an allowance this engine did not\n // create is left alone on failure). A failed read assumes the worst.\n const usdtMainnet = this.fromChain === \"eip155:1\" && source.symbol.toUpperCase() === \"USDT\";\n let current: bigint | undefined;\n if (typeof signer.getAllowance === \"function\") {\n try {\n current = BigInt(await signer.getAllowance(source.contract!, unsigned.approvalAddress!));\n } catch {\n current = undefined;\n }\n }\n approvalAmounts = current === approvalAmount ? [] : [...(usdtMainnet && current !== 0n ? [0n] : []), approvalAmount];\n }\n\n // The re-quote pass is reviewed again only when it differs from what the\n // reviewer approved: source amount, spender and the caller's floor are\n // pinned by construction, but the payload (calldata, deposit, memo, gas)\n // and the output come fresh from the provider.\n const review = (this._config as Swap2EngineConfig).reviewExecution;\n let reviewed: Swap2ExecutionPlan | undefined;\n if (review && (!carried || carried.reviewed)) {\n const chainId = unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {};\n const approvals: Swap2ExecutionPlan[\"approvals\"] = approvalAmounts.map((amount) =>\n ({token: source.contract!, spender: unsigned.approvalAddress!, amount, ...chainId}));\n const plan: Swap2ExecutionPlan = {\n provider: q.provider,\n fromChain: this.fromChain,\n destChain: params.destChain,\n destToken: params.destToken,\n recipient,\n refundAddress,\n sourceAmount: BigInt(q.sourceAmount),\n destAmount: BigInt(q.destAmount),\n minDestAmount: BigInt(q.minDestAmount),\n feeUsd: q.feeUsd,\n etaSeconds: q.etaSeconds,\n validUntilMs: q.validUntilMs,\n approvals,\n source: serialized\n ? {kind: \"serialized\", serializedTx: unsigned.serializedTx!}\n : unsigned.typedData\n ? {kind: \"typed-order\", typedData: unsigned.typedData}\n : tokenId\n ? {kind: \"token-transfer\", token: tokenId, recipient: unsigned.to, amount: BigInt(q.sourceAmount), ...(unsigned.memo ? {memo: unsigned.memo, ...(unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : {})}\n : {\n kind: \"call\",\n to: unsigned.to,\n ...(unsigned.data ? {data: unsigned.data} : {}),\n value: BigInt(unsigned.value),\n ...(unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {}),\n ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {}),\n ...(unsigned.memo ? {memo: unsigned.memo, ...(unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : {}),\n ...(cellBody !== undefined ? {cellBody: true, ...(tonBody ? {cellBodyDecoded: tonBody} : {})} : {}),\n },\n };\n const previous = carried?.reviewed;\n if (!previous || reviewedIdentity(previous) !== reviewedIdentity(plan) || plan.destAmount < previous.destAmount) {\n try {\n // A frozen deep copy: nothing the reviewer does reaches the payload sent below.\n reviewed = deepFreeze(structuredCloneSafe(previous ? {...plan, requoted: true as const} : plan));\n await review(reviewed);\n if (q.validUntilMs > 0 && q.validUntilMs <= Date.now()) {\n throw new Swap2QuoteError(`swap2: quote expired during review — ${previous ? \"the allowance was revoked\" : \"nothing was signed\"}`);\n }\n } catch (error) {\n // Second review: the allowance is ours and already adopted by this pass.\n if (previous) await revokeApproval?.().catch(() => {});\n throw error;\n }\n }\n }\n\n try {\n await this.assertNativeGas(signer, unsigned, approvalAmounts, source.contract ?? undefined, !!unsigned.typedData || serialized || !!tokenId);\n } catch (error) {\n // Re-quote pass: the allowance is adopted here, nobody else revokes it.\n if (carried) await revokeApproval?.().catch(() => {});\n throw error;\n }\n\n if (approvalAmounts.length) {\n const approve = async (amount: bigint) => {\n const sent = await signer.sendTransaction({\n to: source.contract!,\n data: approveData(unsigned.approvalAddress!, amount),\n value: 0n,\n ...(unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {}),\n });\n // The next step (a second approve, or the deposit's gas estimate)\n // reads on-chain allowance: it must see this approval mined.\n if (sent.hash && typeof signer.waitForTransaction === \"function\") await signer.waitForTransaction(sent.hash);\n return sent;\n };\n // Install cleanup BEFORE broadcasting approval. An RPC can lose the\n // response after the transaction was accepted; treating that exception\n // as \"nothing happened\" would leave a live allowance with no callback.\n revokeApproval = async () => { await approve(0n); };\n try {\n for (const [i, amount] of approvalAmounts.entries()) {\n this.emitPhase(\"approving\", {index: i + 1, total: approvalAmounts.length});\n await approve(amount);\n }\n } catch (error) {\n await revokeApproval().catch(() => {});\n throw error;\n }\n }\n\n // The quote/build step can be separated from the actual send by an ERC-20\n // approval. Recheck rotating/halt-sensitive provider state only now.\n if (q.validUntilMs > 0 && q.validUntilMs <= Date.now()) {\n // The mined approvals outlived the quote (mainnet USDT: 50–108 s of\n // approvals against a 55 s LI.FI / 45 s Omniston TTL, SDK-128). The\n // allowance is exact and ours: quote once more and spend it, instead of\n // revoking it (a third tx) and making the caller pay for the approvals\n // again. The second pass is bound to the same spender and amount, held\n // to the caller's floor like the first, and never re-quotes itself.\n if (!carried && approvalAmounts.length && revokeApproval) {\n this.emitPhase(\"requoting\");\n const handoff: CarriedAllowance = {token: source.contract!, spender: unsigned.approvalAddress!, amount: approvalAmount, revoke: revokeApproval, adopted: false, ...(reviewed ? {reviewed} : {})};\n try {\n return await this.executeSwap2(signer, snapshot, config, handoff);\n } catch (error) {\n if (!handoff.adopted) await revokeApproval().catch(() => {});\n throw error;\n }\n }\n await revokeApproval?.().catch(() => {});\n throw new Swap2QuoteError(\"swap2: quote expired before source broadcast\");\n }\n try {\n let providerStillEnabled = false;\n try { providerStillEnabled = provider.enabled(); } catch { /* fail closed below */ }\n if (!providerStillEnabled) throw new Error(`swap2: provider '${q.provider}' was disabled before source broadcast`);\n if (provider.preflightDeposit) this.emitPhase(\"preflight\");\n await provider.preflightDeposit?.(q, unsigned);\n } catch (error) {\n await revokeApproval?.().catch(() => {});\n throw error;\n }\n\n // GASLESS typed-order execution (Omniston EVM-source): sign the EIP-712\n // payload and register it with the provider — there is no source tx.\n if (unsigned.typedData) {\n try {\n if (!signer.signTypedData) {\n throw new Error(\"swap2: typed-order execution needs an account with signTypedData\");\n }\n if (!provider.registerSignedOrder) {\n throw new Error(`swap2: provider '${q.provider}' cannot register signed orders`);\n }\n const td = JSON.parse(unsigned.typedData) as {\n domain: unknown;\n types: Record<string, unknown>;\n primaryType?: string;\n message: unknown;\n };\n if (!td || typeof td !== \"object\" || !td.domain || !td.types || typeof td.types !== \"object\" || !td.message) {\n throw new Error(\"swap2: provider returned malformed typed data\");\n }\n // ethers and the account infer the domain type and reject an explicit\n // EIP712Domain entry as an ambiguous primary type.\n const {EIP712Domain: _domain, ...types} = td.types;\n // Providers may send the domain chainId as a hex string (\"0x89\");\n // signers that build the EIP712Domain type from value types (viem)\n // would then drop chainId from the domain and produce a signature the\n // verifying contract rejects (Omniston order, 2026-10-16). Sign with a number.\n const signature = await signer.signTypedData({\n domain: normalizeTypedDomain(td.domain),\n types,\n ...(td.primaryType ? {primaryType: td.primaryType} : {}),\n message: td.message,\n });\n await provider.registerSignedOrder(q.intentId, signature);\n return {\n id: encodeId(q.provider, q.intentId),\n fees: this.toQuote(q, executionOptions).fees,\n fromTokenAmount: BigInt(q.sourceAmount),\n toTokenAmount: BigInt(q.destAmount),\n toTokenAmountMin: BigInt(q.minDestAmount),\n };\n } catch (error) {\n // Any failed validation/sign/registration must not leave a reusable\n // exact allowance behind. If the RPC response was lost after\n // registration, revocation safely prevents execution.\n await revokeApproval?.().catch(() => {});\n throw error;\n }\n }\n\n // Execute the source leg through the bound account. Non-EVM token deposits\n // MUST use the account's transfer({token,recipient,amount}); passing token metadata\n // to sendTransaction would be ignored and send native SOL/TON/TRX instead.\n let sent: {hash?: string};\n this.emitPhase(\"signing\");\n try {\n if (serialized) {\n const allowanceRaw = (this._config as Swap2EngineConfig).serializedNativeAllowance;\n const allowance = allowanceRaw === undefined ? DEFAULT_SERIALIZED_NATIVE_ALLOWANCE : BigInt(allowanceRaw);\n if (allowance < 0n) throw new Swap2ConfigurationError(\"swap2: serializedNativeAllowance must be non-negative\");\n const expect: SerializedExecutionExpectation = {\n maxValueOut: ((source.contract ? 0n : BigInt(q.sourceAmount)) + allowance).toString(),\n // Only a same-chain swap lands in this account; a bridge delivers elsewhere.\n ...(params.destChain === this.fromChain ? {tokenIn: {token: params.destToken, minAmount: q.minDestAmount}} : {}),\n ...(source.contract ? {source: {token: source.contract, maxAmount: q.sourceAmount}} : {}),\n };\n sent = await signer.sendSerializedTransaction!(unsigned.serializedTx!, expect);\n } else if (tokenId) {\n if (typeof signer.transfer !== \"function\") {\n throw new Swap2ExecutionError(\n `swap2: ${this.fromChain} token execution requires account.transfer({token, recipient, amount})`,\n );\n }\n sent = await signer.transfer({\n token: tokenId,\n recipient: unsigned.to,\n amount: BigInt(q.sourceAmount),\n ...((tronSource || nearSource || tonSource) && unsigned.memo ? {memo: unsigned.memo, ...(tronSource && unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : {}),\n });\n } else {\n sent = await signer.sendTransaction({\n to: unsigned.to,\n ...(unsigned.data ? {data: unsigned.data} : {}),\n value: BigInt(unsigned.value),\n ...(unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {}),\n ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {}),\n ...(cellBody !== undefined\n ? {body: cellBody}\n : unsigned.memo\n ? (tronSource ? {memo: unsigned.memo, ...(unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : nearSource ? {memo: unsigned.memo} : {body: unsigned.memo})\n : {}),\n });\n }\n if (!sent.hash) throw new Swap2ExecutionError(\"swap2: account did not return a source transaction hash\");\n this.emitPhase(\"broadcast\", {hash: sent.hash});\n } catch (error) {\n // The deposit may be in the mempool: revoking would race it, and a\n // \"clean\" error invites a retry that sends a second deposit.\n const unknown = maybeSent(error);\n if (unknown) {\n throw new Swap2MaybeSentError(\n `swap2: the source transaction may have been broadcast (${error instanceof Error ? error.message.slice(0, 160) : String(error).slice(0, 160)}) — do not retry; ${unknown.hash ? `poll the status of ${unknown.hash}` : \"check the account's recent transactions\"}`,\n unknown.hash,\n unknown.hash ? encodeId(q.provider, q.intentId, unknown.hash) : undefined,\n {cause: error},\n );\n }\n await revokeApproval?.().catch(() => {});\n throw error;\n }\n\n if (provider.notifyDeposit) {\n await provider.notifyDeposit(q.intentId, sent.hash).catch(() => {});\n }\n\n const fees = this.toQuote(q, executionOptions).fees;\n return {\n id: encodeId(q.provider, q.intentId, sent.hash),\n fees,\n fromTokenAmount: BigInt(q.sourceAmount),\n toTokenAmount: BigInt(q.destAmount),\n toTokenAmountMin: BigInt(q.minDestAmount),\n ...(sent.hash ? {hash: sent.hash, transactions: [{hash: sent.hash, type: \"source\"}]} : {}),\n };\n }\n\n /**\n * EVM: refuse before the first approval when the native balance cannot pay\n * every approval, the main call and its value. Fees are the account's own\n * upper bound (`quoteSendTransaction`: gas × max fee). The main call's gas\n * comes from the quote's gas limit; without one it is estimated, which a\n * not-yet-approved call cannot do — then only approvals + value count.\n * Accounts without `getBalance`/`quoteSendTransaction` (and non-EVM chains,\n * whose accounts check their own fee at send) are not checked here.\n */\n private async assertNativeGas(signer: Swap2Signer, unsigned: UnsignedTx, approvalAmounts: bigint[], token: string | undefined, noMainCall: boolean): Promise<void> {\n if (!this.fromChain.startsWith(\"eip155:\") || typeof signer.getBalance !== \"function\" || typeof signer.quoteSendTransaction !== \"function\") return;\n const chainId = unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {};\n const fees = await Promise.all(approvalAmounts.map(async (amount) =>\n (await signer.quoteSendTransaction!({to: token!, data: approveData(unsigned.approvalAddress!, amount), value: 0n, ...chainId})).fee));\n const value = noMainCall ? 0n : BigInt(unsigned.value);\n if (!noMainCall) {\n const main = {to: unsigned.to, ...(unsigned.data ? {data: unsigned.data} : {}), value, ...chainId, ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {})};\n fees.push(await signer.quoteSendTransaction(main).then((r) => r.fee, (error) => {\n if (approvalAmounts.length) return 0n; // estimation needs the allowance the approval creates\n throw error;\n }));\n }\n const need = fees.reduce((a, b) => a + b, 0n) + value;\n const balance = BigInt(await signer.getBalance());\n if (balance < need) {\n throw new Swap2InsufficientGasError(`swap2: native balance ${balance} cannot pay this swap's gas: need ${need} (${fees.length} transaction${fees.length === 1 ? \"\" : \"s\"}${value ? ` + value ${value}` : \"\"}) — nothing was signed`);\n }\n }\n\n /** Status of a swap by the id `swap2()` returned, asked from the provider that executed it. */\n override async getSwap2Status(id: string, _options?: Swap2StatusOptions): Promise<Swap2StatusResult> {\n const {provider: name, intentId, sourceTxHash, destTxHash} = decodeId(id);\n const provider = this.providerFor(name);\n if (!provider) throw new Error(`swap2: no swap2 found for id '${id}'`);\n return mapStatus(await provider.trackIntent({intentId, ...(sourceTxHash != null ? {sourceTxHash} : {}), ...(destTxHash != null ? {destTxHash} : {})}));\n }\n\n /**\n * Two-phase routes (CCTP-style burn-and-mint): once `getSwap2Status` reports\n * \"action-required\", the delivery needs a second transaction on the\n * DESTINATION chain, signed there and paid in that chain's gas. `account` is\n * the destination-chain account (the bound source account is not reused:\n * the chains differ). The provider builds the claim from the attestation; it\n * is refused when not ready, when it names another chain than the account,\n * or when it is anything but plain EVM calldata. Returns the claim hash and\n * the status id to keep polling with.\n */\n async claimSwap2(id: string, account: Swap2Account): Promise<{hash: string; chain: string; id: string}> {\n const {provider: name, intentId, sourceTxHash} = decodeId(id);\n const provider = this.providerFor(name);\n if (!provider) throw new Error(`swap2: no swap2 found for id '${id}'`);\n if (typeof provider.buildClaim !== \"function\") {\n throw new Swap2UnsupportedOperationError(`swap2: provider '${name}' has no claim step`);\n }\n const signerCandidate = account as Partial<Swap2Signer> | undefined;\n if (!signerCandidate || typeof signerCandidate.sendTransaction !== \"function\") {\n throw new Swap2ExecutionError(\"swap2: claimSwap2() requires a signing account on the destination chain\");\n }\n const signer = signerCandidate as Swap2Signer;\n let providerEnabled = false;\n try { providerEnabled = provider.enabled(); } catch { /* fail closed below */ }\n if (!providerEnabled) throw new Error(`swap2: provider '${name}' is disabled`);\n const unsigned = await provider.buildClaim(sourceTxHash == null ? {intentId} : {intentId, sourceTxHash});\n if (!unsigned) throw new Swap2StatusError(\"swap2: the claim is not ready yet (attestation pending) — poll the status and retry\");\n if (!unsigned.chain || !unsigned.chain.startsWith(\"eip155:\")) {\n throw new Swap2UnsupportedOperationError(`swap2: claim execution is only implemented for EVM destinations (got '${unsigned.chain || \"?\"}')`);\n }\n if (!unsigned.to || !unsigned.data || !/^0x(?:[0-9a-fA-F]{2})+$/.test(unsigned.data)) {\n throw new Error(\"swap2: provider returned a malformed claim transaction\");\n }\n if (unsigned.serializedTx !== undefined || unsigned.bodyBoc !== undefined || unsigned.typedData !== undefined || unsigned.memo !== undefined || unsigned.approvalAddress !== undefined) {\n throw new Error(\"swap2: claim must be plain calldata\");\n }\n if (unsigned.value !== undefined && unsigned.value !== \"0\") throw new Error(\"swap2: a claim must not carry native value\");\n const expectedId = unsigned.chain.slice(\"eip155:\".length);\n if (unsigned.chainId !== undefined && String(unsigned.chainId) !== expectedId) {\n throw new Error(`swap2: claim chainId ${unsigned.chainId} does not match ${unsigned.chain}`);\n }\n // Only a contract the provider declares for this chain, and nothing that moves this account's\n // tokens or grants an allowance (the source leg's decodeCall refusals) — round 3, M24.\n if (typeof provider.claimTargets !== \"function\") {\n throw new Swap2UnsupportedOperationError(`swap2: provider '${name}' declares no claimTargets — a claim may only call contracts the provider names for its chain`);\n }\n const targets = provider.claimTargets(unsigned.chain).map((a) => a.toLowerCase());\n if (!targets.includes(unsigned.to.toLowerCase())) {\n throw new Swap2ValidationError(`swap2: claim target ${unsigned.to} is not a contract '${name}' declares for ${unsigned.chain} — refused`);\n }\n const claimCall = decodeCall({to: unsigned.to, data: unsigned.data, value: 0n});\n if (claimCall.undecodable) throw new Swap2ValidationError(\"swap2: claim calldata is not hex bytes — refused\");\n if (claimCall.transfer || claimCall.approval) {\n throw new Swap2ValidationError(`swap2: claim calldata (${claimCall.method}) moves tokens or grants an allowance — refused`);\n }\n const actual = await readAccountChain(signer);\n if (actual == null) throw new Error(`swap2: destination account chain identity is unavailable for ${unsigned.chain}`);\n const actualText = typeof actual === \"string\" ? actual : String(actual);\n const actualId = actualText.startsWith(\"eip155:\") ? actualText.slice(\"eip155:\".length) : actualText;\n if (actualId !== expectedId) throw new Error(`swap2: claim is on ${unsigned.chain}, but the account is bound to ${actualText}`);\n this.emitPhase(\"signing\");\n const sent = await signer.sendTransaction({\n to: unsigned.to,\n data: unsigned.data,\n value: 0n,\n chainId: Number(expectedId),\n ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {}),\n });\n if (!sent.hash) throw new Swap2ExecutionError(\"swap2: account did not return a claim transaction hash\");\n this.emitPhase(\"broadcast\", {hash: sent.hash});\n // The id to keep polling names the claim, so the status can complete without a destination RPC (round 3, M27).\n return {hash: sent.hash, chain: unsigned.chain, id: encodeId(name, intentId, sourceTxHash, sent.hash)};\n }\n\n /** The inherited bridge() has no floor field: quote first, then bind execution\n * to that quote's minimum so the inherited convenience API stays safe. */\n override async bridge(options: BridgeOptions): Promise<BridgeResult> {\n const amount = exactPositiveAmount(options.amount, \"amount\");\n const swap2Options: Swap2Options = {\n fromToken: options.token,\n toToken: options.token,\n toChain: options.targetChain,\n recipient: options.recipient,\n fromTokenAmount: amount,\n };\n const quote = await this.quoteSwap2(swap2Options);\n const result = await this.swap2({...swap2Options, minAmountOut: quote.toTokenAmountMin});\n const fee = result.fees.filter((f) => f.type === \"network\").reduce((sum, f) => sum + f.amount, 0n);\n const bridgeFee = result.fees.filter((f) => f.type === \"protocol\").reduce((sum, f) => sum + f.amount, 0n);\n return {hash: result.id, fee, bridgeFee};\n }\n\n /** Same protection for legacy exact-in swap() calls whose min is optional. */\n override async swap(options: SwapOptions): Promise<SwapResult> {\n if (options.tokenInAmount === undefined) {\n throw new Swap2UnsupportedOperationError(\"swap2: exact-out swap is not supported by the engine\");\n }\n const amount = exactPositiveAmount(options.tokenInAmount, \"tokenInAmount\");\n const swap2Options: Swap2Options = {\n fromToken: options.tokenIn,\n toToken: options.tokenOut,\n fromTokenAmount: amount,\n // `to` is optional on the legacy API: omit the key rather than passing\n // undefined, so swap2() falls back to the bound account's own address.\n ...(options.to !== undefined ? {recipient: options.to} : {}),\n ...(options.minAmountOut !== undefined ? {minAmountOut: options.minAmountOut} : {}),\n };\n const floor = options.minAmountOut ?? (await this.quoteSwap2(swap2Options)).toTokenAmountMin;\n const result = await this.swap2({...swap2Options, minAmountOut: floor});\n const fee = result.fees.reduce((sum, item) => sum + item.amount, 0n);\n return {hash: result.id, fee, tokenInAmount: result.fromTokenAmount, tokenOutAmount: result.toTokenAmount};\n }\n\n /** Source chains this protocol can swap from. */\n override async getSupportedChains(): Promise<Swap2SupportedChain[]> {\n if (!this.protocolEnabled()) return [];\n return CC_SOURCE_CHAINS.filter((c: CcChain) => this.chainSupported(c.caip2)).map((c) => ({\n id: c.caip2,\n name: c.label,\n type: chainType(c.caip2),\n nativeToken: c.assets[0]?.symbol ?? \"\",\n }));\n }\n\n /** Tokens of the asset catalog on the supported chains, optionally narrowed. */\n override async getSupportedTokens(options?: Swap2SupportedTokensOptions): Promise<Swap2SupportedToken[]> {\n const wantFrom = options?.fromChain != null ? toCaip2(options.fromChain, \"\") : undefined;\n const wantTo = options?.toChain != null ? toCaip2(options.toChain, \"\") : undefined;\n if (!this.protocolEnabled() || (wantFrom && wantTo && !this.pairSupported(wantFrom, wantTo))) return [];\n const out: Swap2SupportedToken[] = [];\n for (const c of CC_SOURCE_CHAINS) {\n if (!this.chainSupported(c.caip2)) continue;\n if ((wantFrom || wantTo) && c.caip2 !== wantFrom && c.caip2 !== wantTo) continue;\n for (const a of c.assets) {\n out.push({\n // What quoteSwap2 takes back: the contract, or the symbol of the native coin — never the\n // provider-specific assetId, which is \"\" for most catalog entries (round 3, M25).\n token: a.contract ?? a.symbol,\n chain: c.caip2,\n symbol: a.symbol,\n decimals: a.decimals,\n ...(a.contract ? {address: a.contract} : {}),\n });\n }\n }\n return out;\n }\n}\n\nfunction structuredCloneSafe<T>(value: T): T {\n if (value === null || typeof value !== \"object\") return value;\n if (Array.isArray(value)) return value.map((v) => structuredCloneSafe(v)) as T;\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) out[k] = structuredCloneSafe(v);\n return out as T;\n}\n\nfunction deepFreeze<T>(value: T): T {\n if (value && typeof value === \"object\") {\n for (const v of Object.values(value as Record<string, unknown>)) deepFreeze(v);\n Object.freeze(value);\n }\n return value;\n}\n","import {resolveAsset, type CcAsset} from \"@anywalletkit/swap2-assets\";\nimport type {QuoteParams} from \"./types.js\";\n/** Shared CAIP-2 helpers. Contribution packages never read deployment env. */\nexport function namespace(chain: string): string {\n return chain.split(\":\")[0] ?? \"\";\n}\n/** True for an `eip155:` chain id. */\nexport function isEvm(chain: string): boolean {\n return namespace(chain) === \"eip155\";\n}\n/** Numeric chain id of an `eip155:<id>` CAIP-2 id. */\nexport function evmRef(chain: string): number {\n return Number(chain.split(\":\")[1] ?? \"0\");\n}\n\n/**\n * `AbortSignal.timeout`, portably: Hermes (React Native) ships AbortController\n * but not the static helpers, and the unguarded call threw\n * \"AbortSignal.timeout is not a function\" on every remote execution — which\n * the auction then read as \"no route\". Falls back to a manual controller.\n */\nexport function timeoutSignal(ms: number): AbortSignal {\n const native = (AbortSignal as unknown as {timeout?: (ms: number) => AbortSignal}).timeout;\n if (typeof native === \"function\") return native.call(AbortSignal, ms);\n const ctrl = new AbortController();\n setTimeout(() => ctrl.abort(), ms);\n return ctrl.signal;\n}\n\n/** `AbortSignal.any`, portably (see timeoutSignal). */\nexport function anySignal(signals: readonly AbortSignal[]): AbortSignal {\n const native = (AbortSignal as unknown as {any?: (s: readonly AbortSignal[]) => AbortSignal}).any;\n if (typeof native === \"function\") return native.call(AbortSignal, signals);\n const ctrl = new AbortController();\n for (const s of signals) {\n if (s.aborted) {\n ctrl.abort();\n break;\n }\n s.addEventListener(\"abort\", () => ctrl.abort(), {once: true});\n }\n return ctrl.signal;\n}\n\n/** Longest URL scheme taken out (`https`, `wss`, `git+ssh`…): a letter and up to 31 of `[A-Za-z0-9+.-]`. */\nconst SCHEME_MAX = 32;\nconst isLetter = (c: number): boolean => (c >= 97 && c <= 122) || (c >= 65 && c <= 90);\nconst isSchemeChar = (c: number): boolean => isLetter(c) || (c >= 48 && c <= 57) || c === 43 || c === 45 || c === 46;\n/** What ends a URL in text: `\\s` as regexes define it, and `\"` `'` `<` `>`. */\nconst endsUrl = (c: number): boolean =>\n c === 34 || c === 39 || c === 60 || c === 62 || (c >= 9 && c <= 13) || c === 32 || c === 0xa0 || c === 0x1680 ||\n (c >= 0x2000 && c <= 0x200a) || c === 0x2028 || c === 0x2029 || c === 0x202f || c === 0x205f || c === 0x3000 || c === 0xfeff;\n\n/**\n * Remove URLs from text that may travel to a client (a refusal reason, a build error):\n * transport errors carry the endpoint — and with a keyed RPC (QuickNode, Alchemy,\n * Infura…) the key sits in its path (scan 2026-10-23 F8). What `/[a-z][a-z0-9+.-]{0,31}:\\/\\/[^\\s\"'<>]+/gi`\n * would replace, found from each `://` instead of tried at every position: linear in the length of\n * `text` whatever an API or a client puts in it (\"a.a.a…\" made the regex this replaced quadratic;\n * scan 2026-10-27 modules, F34). A URL glued to a word loses its last 32 scheme characters and the rest.\n */\nexport function redactUrls(text: string): string {\n let out = \"\";\n let done = 0; // text[0, done) is in `out`\n for (let at = text.indexOf(\"://\"); at !== -1; at = text.indexOf(\"://\", at + 3)) {\n let start = at;\n while (start > done && at - start < SCHEME_MAX && isSchemeChar(text.charCodeAt(start - 1))) start--;\n while (start < at && !isLetter(text.charCodeAt(start))) start++;\n if (start === at) continue; // no scheme: not a URL (and its tail is not scanned, so \"://://…\" stays linear)\n let end = at + 3;\n while (end < text.length && !endsUrl(text.charCodeAt(end))) end++;\n if (end === at + 3) continue; // nothing after \"://\"\n out += `${text.slice(done, start)}<url>`;\n done = end;\n at = end - 3;\n }\n return done === 0 ? text : out + text.slice(done);\n}\n\n/**\n * The source asset a provider is asked to sell: the catalog's entry for `params.sourceToken`, or —\n * only when the engine sent `sourceDecimals` (an unlisted token the user added) — an unlisted asset\n * named by its contract / mint. Providers that can trade any token use this instead of the catalog\n * lookup; the others keep refusing what the catalog does not list.\n */\nexport function sourceAssetOf(params: Pick<QuoteParams, \"sourceChain\" | \"sourceToken\" | \"sourceDecimals\">): CcAsset | undefined {\n const decimals = params.sourceDecimals;\n return resolveAsset(params.sourceChain, params.sourceToken, decimals === undefined ? {} : {allowUnlisted: true, decimals});\n}\n\nconst B64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n/** Standard or URL-safe base64 → bytes, without Buffer or atob (Hermes); null for anything else. */\nexport function base64Bytes(text: string): Uint8Array | null {\n const s = text.replace(/-/g, \"+\").replace(/_/g, \"/\").replace(/=+$/, \"\");\n if (!/^[A-Za-z0-9+/]*$/.test(s) || s.length % 4 === 1) return null;\n const out = new Uint8Array(Math.floor((s.length * 3) / 4));\n let bits = 0, acc = 0, n = 0;\n for (const ch of s) {\n acc = (acc << 6) | B64.indexOf(ch);\n bits += 6;\n if (bits >= 8) { bits -= 8; out[n++] = (acc >> bits) & 0xff; }\n }\n return out.subarray(0, n);\n}\n\n/** CRC16-XMODEM, the checksum of a user-friendly TON address. */\nfunction crc16(bytes: Uint8Array): number {\n let crc = 0;\n for (const b of bytes) {\n crc ^= b << 8;\n for (let i = 0; i < 8; i++) crc = crc & 0x8000 ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;\n }\n return crc;\n}\n\n/**\n * A TON address in raw form (`<workchain>:<64 hex>`, lowercase) from a raw string, a user-friendly one (bounceable or\n * not, checksum verified), or an address object (`toRawString()` / `workChain` + `hash`); null for anything else. Two\n * spellings of one address compare equal in this form.\n */\nexport function tonRawAddress(address: unknown): string | null {\n if (address && typeof address === \"object\") {\n const o = address as {toRawString?: () => string; workChain?: unknown; hash?: unknown};\n if (typeof o.toRawString === \"function\") { try { return tonRawAddress(o.toRawString()); } catch { return null; } }\n if (typeof o.workChain === \"number\" && o.hash instanceof Uint8Array && o.hash.length === 32) {\n return `${o.workChain}:${Array.from(o.hash, (b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`;\n }\n return null;\n }\n if (typeof address !== \"string\") return null;\n const raw = /^(-?[0-9]{1,3}):([0-9a-fA-F]{64})$/.exec(address.trim());\n if (raw) return `${Number(raw[1])}:${raw[2]!.toLowerCase()}`;\n if (!/^[A-Za-z0-9+/_-]{48}$/.test(address.trim())) return null;\n const bytes = base64Bytes(address.trim());\n if (!bytes || bytes.length !== 36 || crc16(bytes.subarray(0, 34)) !== ((bytes[34]! << 8) | bytes[35]!)) return null;\n const wc = bytes[1] === 0xff ? -1 : bytes[1]!;\n return `${wc}:${Array.from(bytes.subarray(2, 34), (b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n","/**\n * Which stage of a swap failed: configuration, input validation, quote, execution, an unsupported\n * operation, a fee ceiling, or status tracking.\n */\nexport type Swap2ErrorCode =\n | \"CONFIGURATION\"\n | \"VALIDATION\"\n | \"QUOTE\"\n | \"EXECUTION\"\n | \"UNSUPPORTED_OPERATION\"\n | \"FEE_LIMIT\"\n | \"STATUS\";\n\n/** Public, machine-readable error base shared by every contribution package. */\nexport class Swap2Error extends Error {\n constructor(message: string, readonly code: Swap2ErrorCode, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport class Swap2ConfigurationError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"CONFIGURATION\", options); }\n}\nexport class Swap2ValidationError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"VALIDATION\", options); }\n}\nexport class Swap2QuoteError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"QUOTE\", options); }\n}\nexport class Swap2ExecutionError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"EXECUTION\", options); }\n}\nexport class Swap2UnsupportedOperationError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"UNSUPPORTED_OPERATION\", options); }\n}\nexport class Swap2FeeLimitError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"FEE_LIMIT\", options); }\n}\nexport class Swap2StatusError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"STATUS\", options); }\n}\n/** An identical swap2() is still running on this account (double tap): nothing was sent for this call. */\nexport class Swap2InFlightError extends Swap2ExecutionError {}\n/** The account cannot pay the source leg's gas (approvals + main call + value); nothing was signed. */\nexport class Swap2InsufficientGasError extends Swap2ExecutionError {}\n/**\n * The source broadcast failed AFTER the transaction may have reached the node\n * (lost response, timeout). Do NOT retry: poll `getSwap2Status(id)` / the\n * chain for `hash`. The approval is left in place (the deposit may spend it).\n */\nexport class Swap2MaybeSentError extends Swap2ExecutionError {\n constructor(message: string, readonly hash?: string, readonly id?: string, options?: ErrorOptions) { super(message, options); }\n}\n","import type {CrossChainProvider, Quote, QuoteParams} from \"./types.js\";\n\n/** Shared quote validator used by both the aggregate and single-provider paths. */\nexport function validQuote(q: Quote, params: QuoteParams, provider: string): boolean {\n try {\n if (q.provider !== provider || q.sourceAmount !== params.amountIn) return false;\n if (typeof q.intentId !== \"string\" || !q.intentId || typeof q.depositAddress !== \"string\" || (q.depositMemo !== null && typeof q.depositMemo !== \"string\")) return false;\n if (![q.sourceAmount, q.destAmount, q.minDestAmount].every((value) => /^[0-9]+$/.test(value))) return false;\n const source = BigInt(q.sourceAmount);\n const dest = BigInt(q.destAmount);\n const min = BigInt(q.minDestAmount);\n if (source <= 0n || dest <= 0n || min <= 0n || min > dest) return false;\n if (params.minAmountOut !== undefined) {\n if (!/^[0-9]+$/.test(params.minAmountOut) || BigInt(params.minAmountOut) <= 0n || min < BigInt(params.minAmountOut)) return false;\n }\n if (params.slippageBps !== undefined) {\n if (!Number.isInteger(params.slippageBps) || params.slippageBps < 0 || params.slippageBps >= 10_000) return false;\n // Providers round the floor DOWN (1Click, LI.FI: floor(dest × (1 − s))).\n // A ceil here refused nearly every slippage-bounded quote by one base unit.\n const required = (dest * BigInt(10_000 - params.slippageBps)) / 10_000n;\n if (min < required) return false;\n }\n if (!Number.isFinite(q.etaSeconds) || q.etaSeconds < 0) return false;\n if (!Number.isFinite(q.reliability) || q.reliability < 0 || q.reliability > 1) return false;\n if (!Number.isFinite(q.feeUsd) || q.feeUsd < 0) return false;\n if (q.fees && (!Array.isArray(q.fees) || !q.fees.every((fee) =>\n [\"network\", \"protocol\", \"affiliate\", \"other\"].includes(fee.type) &&\n /^[0-9]+$/.test(fee.amount) &&\n typeof fee.token === \"string\" && fee.token.length > 0 &&\n typeof fee.included === \"boolean\" &&\n (fee.description === undefined || typeof fee.description === \"string\")\n ))) return false;\n if (q.providerData && (Array.isArray(q.providerData) || typeof q.providerData !== \"object\" || !Object.values(q.providerData).every((value) => typeof value === \"string\"))) return false;\n const tx = q.txRequest;\n if (tx) {\n if (tx.value !== undefined && !/^[0-9]+$/.test(tx.value)) return false;\n if (tx.gasLimit !== undefined && !/^[0-9]+$/.test(tx.gasLimit)) return false;\n if (tx.chainId !== undefined && (!Number.isSafeInteger(tx.chainId) || tx.chainId <= 0)) return false;\n if ([tx.to, tx.data, tx.approvalAddress, tx.serializedTx].some((value) => value !== undefined && typeof value !== \"string\")) return false;\n }\n // Execution is always re-quoted. An unknown/zero expiry cannot prove that\n // the transaction is still safe to sign, so contribution packages reject it.\n if (!Number.isFinite(q.validUntilMs) || q.validUntilMs <= Date.now()) return false;\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Why a remote provider's quote cannot execute in this app, or null: its EVM transaction calls or\n * approves an address the app did not pin (`remoteProvider` `callTargets` / `spenders`), or it pays\n * an address the backend named — a deposit address or a plain value send — on a stub the app did not\n * open to such routes (`depositAddressRoutes`, scan 2026-10-28 F9). The router and the\n * single-provider path drop such a quote with this reason, so the auction never picks a route\n * execution would refuse (scan 2026-10-27 modules, F8/F9/F16); execution checks the build again, in\n * full. Local providers are not judged here.\n */\nexport function remotePinRefusal(provider: Pick<CrossChainProvider, \"name\" | \"remote\" | \"callTargets\" | \"spenders\" | \"depositAddressRoutes\">, q: Quote, chain: string): string | null {\n if (provider.remote !== true) return null;\n const tx = q.txRequest;\n const plain = tx ? tx.data === undefined && tx.serializedTx === undefined : typeof q.depositAddress === \"string\" && q.depositAddress !== \"\";\n if (plain && provider.depositAddressRoutes !== true) {\n return `${provider.name}: the route pays ${tx?.to || q.depositAddress}, an address the backend named, and the app did not allow deposit-address routes for this provider (remoteProvider depositAddressRoutes)`;\n }\n if (!chain.startsWith(\"eip155:\")) return null;\n if (!tx || tx.serializedTx !== undefined) return null;\n const pinned = (list: readonly string[] | undefined, address: string) =>\n (list ?? []).some((a) => typeof a === \"string\" && a.toLowerCase() === address.toLowerCase());\n if (tx.approvalAddress && !pinned(provider.spenders?.(chain), tx.approvalAddress)) {\n return `${provider.name}: the route approves ${tx.approvalAddress}, which the app did not pin as a spender on ${chain} (remoteProvider spenders)`;\n }\n if (tx.data !== undefined && tx.to && !pinned(provider.callTargets?.(chain), tx.to)) {\n return `${provider.name}: the route calls ${tx.to}, which the app did not pin as a call target on ${chain} (remoteProvider callTargets)`;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,kBAA4B;AAC5B,kBAA6C;AAC7C,4BAAyB;AAkBzB,IAAAA,uBASO;;;ACvCP,0BAAyC;AA0FzC,IAAM,MAAM;AAEL,SAAS,YAAY,MAAiC;AAC3D,QAAM,IAAI,KAAK,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG,EAAE,QAAQ,OAAO,EAAE;AACtE,MAAI,CAAC,mBAAmB,KAAK,CAAC,KAAK,EAAE,SAAS,MAAM,EAAG,QAAO;AAC9D,QAAM,MAAM,IAAI,WAAW,KAAK,MAAO,EAAE,SAAS,IAAK,CAAC,CAAC;AACzD,MAAI,OAAO,GAAG,MAAM,GAAG,IAAI;AAC3B,aAAW,MAAM,GAAG;AAClB,UAAO,OAAO,IAAK,IAAI,QAAQ,EAAE;AACjC,YAAQ;AACR,QAAI,QAAQ,GAAG;AAAE,cAAQ;AAAG,UAAI,GAAG,IAAK,OAAO,OAAQ;AAAA,IAAM;AAAA,EAC/D;AACA,SAAO,IAAI,SAAS,GAAG,CAAC;AAC1B;AAGA,SAAS,MAAM,OAA2B;AACxC,MAAI,MAAM;AACV,aAAW,KAAK,OAAO;AACrB,WAAO,KAAK;AACZ,aAAS,IAAI,GAAG,IAAI,GAAG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AC,KAAK,SAAS,cAAc,MAAM,EAAE,EAAG,QAAO;AAC/E,UAAI,SAAS,gBAAgB,SAAS,aAAa,KAAK,SAAS,sBAAsB,KAAM,QAAO;AACpG,YAAM,QAAQ,MAAM,KAAK,SAAS,SAAS,QAAQ;AACnD,UAAI,CAAC,MAAO,QAAO;AACnB,UAAI,CAAC,WAAW,OAAO,UAAU,IAAI,GAAG;AACtC,aAAK,gBAAgB,GAAG,IAAI,qCAAqC,MAAM,aAAa,aAAa,SAAS,gBAAgB,GAAG;AAC7H,eAAO;AAAA,MACT;AACA,YAAM,WAAW,iBAAiB,KAAK,UAAU,OAAO,SAAS,WAAW;AAC5E,UAAI,UAAU;AACZ,aAAK,gBAAgB;AACrB,eAAO;AAAA,MACT;AACA,aAAO,EAAC,GAAG,OAAO,UAAU,KAAI;AAAA,IAClC,SAAS,KAAK;AACZ,WAAK,gBAAgB,GAAG,IAAI,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,GAAG,MAAM,GAAG,GAAG,CAAC;AACjG,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EACmB,gBAAwB;AACzC,WAAO,KAAK,YAAY,MAAM,GAAG,GAAG;AAAA,EACtC;AAAA,EACU,YAAY,MAA8C;AAClE,WAAO,SAAS,KAAK,SAAS,OAAO,KAAK,WAAW;AAAA,EACvD;AAAA;AAAA,EAES,iBAAiB,IAAa,KAAmD;AACxF,WAAO,KAAK,SAAS,mBAAmB,IAAI,GAAG,KAAK;AAAA,EACtD;AAAA,EACmB,kBAA2B;AAC5C,QAAI;AAAE,aAAO,KAAK,SAAS,QAAQ;AAAA,IAAG,QAAQ;AAAE,aAAO;AAAA,IAAO;AAAA,EAChE;AAAA,EACA,QAAc;AACZ,SAAK,SAAS,QAAQ;AAAA,EACxB;AACF;","names":["import_swap2_assets","sent"]}
1
+ {"version":3,"sources":["../../src/swap2/single.ts","../../src/swap2/base.ts","../../src/util.ts","../../src/validate.ts","../../src/errors.ts"],"sourcesContent":["import type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {BaseSwap2Protocol} from \"./base.js\";\nimport type {CrossChainProvider, Quote, QuoteParams} from \"../types.js\";\nimport {remotePinRefusal, validQuote} from \"../validate.js\";\n\n/** A single-provider swap2: quoting/tracking route through one solver. The\n * per-provider packages subclass this — the contribution unit shape. */\nexport abstract class SingleProviderSwap2 extends BaseSwap2Protocol {\n protected abstract readonly provider: CrossChainProvider;\n /** Why the last resolveQuote came back empty — the provider's own reason, like the router's. */\n private lastRefusal = \"\";\n protected async resolveQuote(params: QuoteParams): Promise<Quote | null> {\n this.lastRefusal = \"\";\n const name = this.provider.name;\n const outer = params.onRefusal;\n const snapshot = Object.freeze({...params, onRefusal: (reason: string) => {\n this.lastRefusal ||= reason.startsWith(`${name}:`) ? reason : `${name}: ${reason}`;\n try { outer?.(reason); } catch { /* diagnostics only */ }\n }});\n const from = Object.freeze({chain: snapshot.sourceChain, token: snapshot.sourceToken});\n const to = Object.freeze({chain: snapshot.destChain, token: snapshot.destToken});\n try {\n // Standalone contribution classes must enforce the same dark flag,\n // capability and quote-integrity boundary as the aggregator. Previously\n // they called getQuote directly, so `enabled: false` was advisory only.\n if (!this.provider.enabled() || !this.provider.supportsRoute(from, to)) return null;\n if (snapshot.sourceChain === snapshot.destChain && this.provider.supportsSameChain !== true) return null;\n const quote = await this.provider.getQuote(snapshot);\n if (!quote) return null;\n if (!validQuote(quote, snapshot, name)) {\n this.lastRefusal ||= `${name}: rejected by validation (minDest=${quote.minDestAmount} vs floor=${snapshot.minAmountOut ?? \"-\"})`;\n return null;\n }\n const unpinned = remotePinRefusal(this.provider, quote, snapshot.sourceChain);\n if (unpinned) {\n this.lastRefusal ||= unpinned;\n return null;\n }\n return {...quote, provider: name};\n } catch (err) {\n this.lastRefusal ||= `${name}: ${(err instanceof Error ? err.message : String(err)).slice(0, 160)}`;\n return null;\n }\n }\n protected override noRouteDetail(): string {\n return this.lastRefusal.slice(0, 400);\n }\n protected providerFor(name: string): CrossChainProvider | undefined {\n return name === this.provider.name ? this.provider : undefined;\n }\n /** Activity recognition lives on the provider (shared with the router); null when it has none. */\n override describeActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n return this.provider.describeActivity?.(tx, ctx) ?? null;\n }\n protected override protocolEnabled(): boolean {\n try { return this.provider.enabled(); } catch { return false; }\n }\n close(): void {\n this.provider.close?.();\n }\n}\n","/**\n * `Swap2Protocol` adapter over the cross-chain engine.\n *\n * The engine speaks in symbols + CAIP-2 chain ids and a deposit-address /\n * calldata execution model; core's `Swap2Protocol` speaks in provider token ids\n * bound to an account whose chain is the source. This base bridges the two:\n * it maps `Swap2Options` → the engine's `QuoteParams`, delegates quoting to a\n * provider (or the router, in the aggregator), and executes the source leg\n * through the bound account. Subclasses only supply \"which provider(s)\".\n */\nimport {Swap2Protocol} from \"@anywalletkit/core\";\nimport {encodeFunctionData, getAddress} from \"viem\";\nimport {decodeCall} from \"@anywalletkit/tx-preview-evm\";\nimport type {\n Swap2Options,\n Swap2Quote,\n Swap2Result,\n Swap2StatusOptions,\n Swap2StatusResult,\n Swap2Status,\n Swap2Fee,\n Swap2ProtocolConfig,\n Swap2SupportedChain,\n Swap2SupportedToken,\n Swap2SupportedTokensOptions,\n BridgeOptions,\n BridgeResult,\n SwapOptions,\n SwapResult,\n} from \"@anywalletkit/core\";\nimport {\n CC_SOURCE_CHAINS,\n ccAsset,\n ccAssetByToken,\n isTokenAddress,\n isUnlisted,\n resolveAsset,\n type CcAsset,\n type CcChain,\n} from \"@anywalletkit/swap2-assets\";\nimport type {CrossChainProvider, IntentStatus, QuoteParams, Quote, UnsignedTx} from \"../types.js\";\nimport {tonRawAddress} from \"../util.js\";\nimport {SLIPPAGE_ROUNDING_BPS} from \"../validate.js\";\nimport {\n Swap2ConfigurationError,\n Swap2ExecutionError,\n Swap2FeeLimitError,\n Swap2InFlightError,\n Swap2InsufficientGasError,\n Swap2MaybeSentError,\n Swap2QuoteError,\n Swap2StatusError,\n Swap2UnsupportedOperationError,\n Swap2ValidationError,\n} from \"../errors.js\";\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nconst ERC20_TRANSFER_ABI = [\n {\n type: \"function\",\n name: \"transfer\",\n stateMutability: \"nonpayable\",\n inputs: [\n {name: \"to\", type: \"address\"},\n {name: \"amount\", type: \"uint256\"},\n ],\n outputs: [{type: \"bool\"}],\n },\n] as const;\nconst ERC20_APPROVE_ABI = [\n {type: \"function\", name: \"approve\", stateMutability: \"nonpayable\", inputs: [{name: \"spender\", type: \"address\"}, {name: \"amount\", type: \"uint256\"}], outputs: [{type: \"bool\"}]},\n] as const;\nconst approveData = (spender: string, amount: bigint) =>\n encodeFunctionData({abi: ERC20_APPROVE_ABI, functionName: \"approve\", args: [spender as `0x${string}`, amount]});\n\n/** swap2() calls running per account object, keyed by their options: a double tap must not run two swaps. */\nconst IN_FLIGHT = new WeakMap<object, Set<string>>();\nconst inFlightKey = (fromChain: string, o: Swap2Options) =>\n JSON.stringify([fromChain, o.fromToken, o.toToken, o.toChain, o.recipient, o.refundAddress, o.fromTokenAmount, o.toTokenAmount, o.minAmountOut, o.slippage],\n (_k, v) => (typeof v === \"bigint\" ? v.toString() : v));\n\n/** A lost transport answer, in a message, an error code or an error name (Node / undici / React Native / browsers). */\nconst LOST_ANSWER = /socket hang up|ECONNRESET|ECONNABORTED|ETIMEDOUT|EPIPE|ENETUNREACH|EHOSTUNREACH|EAI_AGAIN|UND_ERR_[A-Z_]+|timed? ?out|TimeoutError|request aborted|AbortError|connection (?:closed|reset)|fetch failed|failed to fetch|network request failed|other side closed/i;\n\n/**\n * Did a failed broadcast possibly reach the node? Every chain package says so on its error\n * (`BroadcastUnknownError`: `maybeSent` + the locally computed `hash`), anywhere in the cause\n * chain. A node's explicit refusal (`answered: true`) is a clean failure. Otherwise a lost\n * transport answer — in the message, code or name of any error in the chain (`fetch failed` with\n * an `UND_ERR_*` cause, React Native's `Network request failed`, `ECONNRESET`, a `TimeoutError`) —\n * is treated as possibly sent (round 3, M12). A refusal before signing is a clean failure.\n */\nfunction maybeSent(error: unknown): {hash?: string} | null {\n const chain: Array<{maybeSent?: unknown; hash?: unknown; answered?: unknown; message?: unknown; code?: unknown; name?: unknown}> = [];\n for (let e = error as {cause?: unknown} | undefined, i = 0; e && typeof e === \"object\" && i < 6; e = e.cause as typeof e, i++) chain.push(e as never);\n for (const e of chain) if (e.maybeSent === true) return typeof e.hash === \"string\" && e.hash ? {hash: e.hash} : {};\n if (chain.some((e) => e.answered === true)) return null;\n const texts = chain.length ? chain.map((e) => [e.message, e.code, e.name].filter((x) => typeof x === \"string\").join(\" \")) : [String(error)];\n return texts.some((t) => LOST_ANSWER.test(t)) ? {} : null;\n}\n\n/** Our config adds the account's source chain (CAIP-2) the base type omits. */\n/**\n * Where an execution is, for progress UIs. A source leg can spend a minute\n * before anything is signed (two awaited ERC-20 approvals for USDT), so\n * \"signing\" alone reads as hung. \"requoting\": the mined approvals outlived\n * the quote's TTL and the engine is fetching a fresh quote for the same\n * spender and amount (the allowance is kept, not revoked). Diagnostics only:\n * a throwing observer can never change the outcome.\n */\n/**\n * Most native coin a route may charge on top of the input (bridge messaging\n * fees), base units per chain. Above this the quote is refused even though it\n * declared the fee — a provider bug or a hostile backend must not turn a\n * token swap into a native drain.\n */\n/**\n * Base-unit precision of a chain's native coin — what `value`, `eth_getBalance`\n * and a declared `nativeFee` are counted in. Every EVM chain the engine knows\n * accounts for gas in 18-decimal units, Arc included: Arc's gas token is USDC,\n * but its native accounting is 18-decimal (\"the native USDC gas token uses 18\n * decimals of precision, while the USDC ERC-20 interface uses 6\" —\n * docs.arc.network, gas-and-fees / contract-addresses, 2026-10-14). Arc is\n * pinned here so the 6-decimal ERC-20 view can never leak into a ceiling:\n * 10 USDC of fee headroom is 10 × 10^18 base units, not 10 × 10^6. A chain\n * whose native accounting is genuinely not 18-decimal gets its own row and\n * every cap below, declared in whole coins, scales with it.\n */\nexport const NATIVE_DECIMALS: Readonly<Record<string, number>> = Object.freeze({\n \"eip155:5042\": 18, // Arc — USDC gas token, 18-decimal native accounting (ERC-20 view at 0x3600… is 6)\n});\nconst DEFAULT_NATIVE_DECIMALS = 18;\n/** Decimals of `chain`'s native coin in base units (18 unless the chain says otherwise). */\nexport function nativeDecimals(chain: string): number {\n return NATIVE_DECIMALS[chain] ?? DEFAULT_NATIVE_DECIMALS;\n}\n/** `whole` native coins (an integer, or a decimal string such as \"0.005\") in `chain`'s base units. */\nexport function nativeUnits(chain: string, whole: number | string): bigint {\n const text = String(whole);\n if (!/^\\d+(\\.\\d+)?$/.test(text)) throw new Error(`swap2: malformed native amount '${text}'`);\n const [int, frac = \"\"] = text.split(\".\") as [string, string?];\n const decimals = nativeDecimals(chain);\n if (frac.length > decimals) throw new Error(`swap2: '${text}' has more than ${decimals} fractional digits for ${chain}`);\n return BigInt(int + frac.padEnd(decimals, \"0\"));\n}\nconst NATIVE_FEE_CAP: Readonly<Record<string, bigint>> = Object.freeze({\n \"eip155:1\": 5_000_000_000_000_000n, // 0.005 ETH\n \"eip155:137\": 20_000_000_000_000_000_000n, // 20 POL\n \"eip155:56\": 5_000_000_000_000_000n, // 0.005 BNB\n \"eip155:43114\": 100_000_000_000_000_000n, // 0.1 AVAX\n \"eip155:999\": 100_000_000_000_000_000n, // 0.1 HYPE\n // Non-ETH natives, ~$10-12 each at 2026-10-13 prices (0.005 ETH ≈ $12.6).\n \"eip155:100\": 10_000_000_000_000_000_000n, // 10 xDAI\n \"eip155:143\": 400_000_000_000_000_000_000n, // 400 MON\n \"eip155:146\": 200_000_000_000_000_000_000n, // 200 S\n \"eip155:9745\": 150_000_000_000_000_000_000n, // 150 XPL\n \"eip155:42220\": 100_000_000_000_000_000_000n, // 100 CELO\n \"eip155:80094\": 50_000_000_000_000_000_000n, // 50 BERA\n \"eip155:1329\": 200_000_000_000_000_000_000n, // 200 SEI\n \"eip155:98866\": 500_000_000_000_000_000_000n, // 500 PLUME\n \"eip155:196\": 100_000_000_000_000_000n, // 0.1 OKB\n // 2026-10-14 batch, ~$10 each at 2026-10-14 prices; declared in whole coins so the chain's native decimals apply.\n \"eip155:5000\": nativeUnits(\"eip155:5000\", 20), // 20 MNT (≈ $0.53 each)\n \"eip155:14\": nativeUnits(\"eip155:14\", 1500), // 1500 FLR (≈ $0.0067 each)\n \"eip155:5042\": nativeUnits(\"eip155:5042\", 10), // 10 USDC — Arc's gas token, in its 18-decimal native units\n // Katana and Morph are ETH-denominated: the 0.005 ETH default applies.\n});\nconst DEFAULT_NATIVE_FEE_CAP = 5_000_000_000_000_000n; // 0.005 of an ETH-denominated L2\n\nfunction declaredNativeFee(q: {txRequest?: {nativeFee?: string}}, chain: string): bigint {\n const raw = q.txRequest?.nativeFee;\n if (raw === undefined) return 0n;\n if (!/^\\d+$/.test(raw)) throw new Error(\"swap2: quote declares a malformed native fee\");\n const fee = BigInt(raw);\n const cap = NATIVE_FEE_CAP[chain] ?? DEFAULT_NATIVE_FEE_CAP;\n if (fee > cap) throw new Error(`swap2: quoted native fee ${fee} exceeds the cap ${cap} for ${chain}`);\n return fee;\n}\n\nexport type Swap2ExecutionPhase = \"approving\" | \"requoting\" | \"preflight\" | \"signing\" | \"broadcast\";\nexport interface Swap2ExecutionPhaseDetail {\n /** approving: which approval of how many (USDT on Ethereum needs two). */\n index?: number;\n total?: number;\n /** broadcast: the source transaction hash. */\n hash?: string;\n}\n\n/** A bigint chain id as a number, or undefined outside the safe range (checked before converting: Hermes mis-converts above 2^63). */\nconst safeChainId = (v: bigint): number | undefined => (v >= 0n && v <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(v.toString()) : undefined);\n\n/** EIP-712 domain with `chainId` as a number whatever notation the provider used. */\nexport function normalizeTypedDomain(domain: unknown): unknown {\n if (!domain || typeof domain !== \"object\") return domain;\n const raw = (domain as {chainId?: unknown}).chainId;\n let chainId: number | undefined;\n if (typeof raw === \"number\") chainId = raw;\n else if (typeof raw === \"bigint\") chainId = safeChainId(raw);\n else if (typeof raw === \"string\" && /^\\d+$/.test(raw)) chainId = Number(raw);\n else if (typeof raw === \"string\" && /^0x[0-9a-fA-F]+$/.test(raw)) chainId = safeChainId(BigInt(raw));\n return chainId === undefined || !Number.isSafeInteger(chainId) ? domain : {...(domain as object), chainId};\n}\n\n/**\n * Bind a provider's EIP-712 payload to the swap before anything is approved or signed (scan 2026-10-27 modules, F4):\n * only a Limit Order Protocol `Order` for the settlement contract the swap approves, on the source chain, from this\n * account, selling exactly the swap's input of the source token. A `Permit*` or any other typed message a backend\n * chose — an allowance to anyone, signed off-chain — is refused.\n */\nfunction assertTypedOrder(typedData: string, approvalAddress: string | undefined, e: {self: string; token: string | undefined; amount: string; chainId: number | null}): void {\n const fail = (why: string) => new Swap2ValidationError(`swap2: typed order refused — ${why}`);\n let parsed: unknown;\n try { parsed = JSON.parse(typedData); } catch { throw fail(\"the typed data is not JSON\"); }\n if (!parsed || typeof parsed !== \"object\") throw fail(\"the typed data is not an object\");\n const td = parsed as {domain?: {verifyingContract?: unknown}; types?: Record<string, unknown>; primaryType?: unknown; message?: Record<string, unknown>};\n const primary = td.primaryType;\n if (typeof primary !== \"string\" || !primary) throw fail(\"it names no primaryType\");\n if (/^permit/i.test(primary)) throw fail(`${primary} is a token approval, not an order`);\n if (primary !== \"Order\") throw fail(`primaryType ${primary} is not an order this engine signs`);\n const fields = td.types?.Order;\n const has = (name: string, type: string) => Array.isArray(fields) && fields.some((f: {name?: unknown; type?: unknown} | null) => f?.name === name && f?.type === type);\n if (!has(\"maker\", \"address\") || !has(\"makerAsset\", \"address\") || !has(\"makingAmount\", \"uint256\")) throw fail(\"the Order type has no maker / makerAsset / makingAmount\");\n const verifying = td.domain?.verifyingContract;\n if (!approvalAddress || typeof verifying !== \"string\" || verifying.toLowerCase() !== approvalAddress.toLowerCase()) {\n throw fail(`verifyingContract ${String(verifying)} is not the settlement contract the swap approves`);\n }\n if (e.chainId !== null && (normalizeTypedDomain(td.domain) as {chainId?: unknown} | undefined)?.chainId !== e.chainId) throw fail(\"the domain chainId is not the source chain\");\n const m = td.message ?? {};\n if (String(m.maker ?? \"\").toLowerCase() !== e.self.toLowerCase()) throw fail(\"the maker is not this account\");\n if (!e.token || String(m.makerAsset ?? \"\").toLowerCase() !== e.token.toLowerCase()) throw fail(\"the makerAsset is not the source token\");\n // uint256 fields come as decimal or 0x-hex strings (Omniston sends hex, live 2026-10-16).\n const raw = m.makingAmount;\n const making = typeof raw === \"string\" && /^(?:0x[0-9a-fA-F]{1,64}|[0-9]{1,78})$/.test(raw) ? BigInt(raw) : typeof raw === \"number\" && Number.isSafeInteger(raw) ? BigInt(raw) : null;\n if (making === null || making !== BigInt(e.amount)) throw fail(`makingAmount ${String(raw)} is not the swap's ${e.amount}`);\n}\n\nexport interface Swap2EngineConfig extends Swap2ProtocolConfig {\n /** CAIP-2 of the chain the bound account lives on (the swap2 source). */\n fromChain: string;\n /** Progress observer, see {@link Swap2ExecutionPhase}. */\n onExecutionPhase?: (phase: Swap2ExecutionPhase, detail?: Swap2ExecutionPhaseDetail) => void;\n /** Explicit escape hatch for adapters that can prove chain binding elsewhere. */\n skipAccountChainCheck?: boolean;\n /** Optional account chain identity when the account does not expose a provider. */\n accountChain?: string;\n /**\n * Decodes a base64 BoC into a TON `Cell` for deposits that carry a cell body\n * (e.g. Omniston escrow payloads). The package deliberately does not depend on\n * `@ton/core`; the caller supplies e.g. `(b) => Cell.fromBase64(b)`. Without\n * it, cell-body deposits fail closed — a TON account treats a string body\n * as a TEXT COMMENT, which would strand the swap.\n */\n decodeTonBody?: (bocBase64: string) => unknown;\n /**\n * Provider-SERIALIZED legs (a swap aggregator's fully built Solana\n * transaction): how much native coin, in base units, the account may lose\n * on top of the swap input — rent for a destination token account, wrapped\n * SOL juggling, priority fees. Default 20 000 000 lamports (0.02 SOL).\n */\n serializedNativeAllowance?: bigint | number | string;\n /**\n * The most nanoTON a TON cell-body deposit may attach as gas: on top of the input for a native source, the whole\n * attached value for a jetton source (default 1 TON; live Omniston swaps attach 0.1–0.4). A build attaching more is\n * refused (scan 2026-10-27 modules, F7).\n */\n tonGasCeiling?: bigint | number | string;\n /**\n * Review gate: called once the live quote is built and every payload/value\n * check has passed, BEFORE any approval or signature. It receives a copy of\n * exactly what will be signed; throwing (the user cancelled) aborts with\n * nothing sent. A quote that expires while the gate is open is refused\n * before the first approval. When the quote expires while the engine's own\n * approval is being mined, the engine re-quotes once; if the fresh quote\n * differs from the reviewed one (payload, gas, a worse output) the gate is\n * called again with `requoted: true`, and throwing then revokes the allowance.\n */\n reviewExecution?: (plan: Swap2ExecutionPlan) => Promise<void> | void;\n /**\n * Accept tokens the swap catalog does not list, named by their contract (EVM) or mint (Solana):\n * tokens the user added at their own risk. Off by default. The source token's decimals are read\n * with the account's `getTokenInfo` (a `fromTokenDecimals` that disagrees is refused); an account\n * without it must be given `fromTokenDecimals`. Only providers that trade any token (LI.FI,\n * Uniswap, Balancer, Fynd, Jupiter) quote them, and they have no USD value: the router cannot\n * judge their price, so show the user the amounts.\n */\n allowUnlistedTokens?: boolean;\n}\n\n/** What a TON cell body does, as the engine read it before signing (scan 2026-10-27 modules, F13): its op, and the jetton transfer it is. */\nexport interface TonBodySummary {\n op: number | null;\n /** TEP-74 transfer from the account's own jetton wallet: amount, where it goes, where the excess returns, the TON forwarded. */\n jettonTransfer?: {amount: bigint; destination: string | null; responseDestination: string | null; forwardTon: bigint};\n}\n\n/** What `swap2()` is about to sign, handed to {@link Swap2EngineConfig.reviewExecution}. */\nexport interface Swap2ExecutionPlan {\n provider: string;\n fromChain: string;\n destChain: string;\n destToken: string;\n recipient: string;\n refundAddress: string;\n sourceAmount: bigint;\n destAmount: bigint;\n minDestAmount: bigint;\n feeUsd: number;\n etaSeconds: number;\n validUntilMs: number;\n /** ERC-20 approvals sent first, in order (USDT on Ethereum resets to 0 first). */\n approvals: {token: string; spender: string; amount: bigint; chainId?: number}[];\n /**\n * `true` on a second review: the first quote expired while its approval was being mined, and\n * the fresh one differs from what was reviewed (another payload, a worse output). The allowance\n * is already in place, so `approvals` is empty; cancelling revokes it.\n */\n requoted?: true;\n /** The source leg exactly as the account will receive it. */\n source:\n | {kind: \"call\"; to: string; data?: string; value: bigint; chainId?: number; gasLimit?: bigint; memo?: string; memoEncoding?: \"utf8\" | \"hex\"; cellBody?: boolean; cellBodyDecoded?: TonBodySummary}\n | {kind: \"token-transfer\"; token: string; recipient: string; amount: bigint; memo?: string; memoEncoding?: \"utf8\" | \"hex\"}\n | {kind: \"serialized\"; serializedTx: string}\n | {kind: \"typed-order\"; typedData: string};\n}\n\n/**\n * What a provider-serialized transaction is allowed to do with the bound\n * account's balances; derived from the validated quote and handed to the\n * account's `sendSerializedTransaction` hook, which must prove it (simulate\n * with post-state balances) before signing. Amounts are base-unit strings.\n */\nexport interface SerializedExecutionExpectation {\n /** Most native coin the account may lose, fee excluded: swap input (native source) + allowance. */\n maxValueOut: string;\n /** Same-chain swaps: the token the account must receive and the quoted minimum (zero address = native). */\n tokenIn?: {token: string; minAmount: string};\n /** Token sources: the token the account may send and the exact swap input. */\n source?: {token: string; maxAmount: string};\n /**\n * Bridges: the destination chain (CAIP-2) and the reviewed recipient there. Value leaving the account may only go into\n * the bridge (plus the provider's declared fee), and a bridge instruction whose recipient the account can read must\n * name this one; an account that cannot prove where the funds go refuses the transaction. The engine also names the\n * reviewed destination token (zero address = native), the quoted minimum in its base units with its decimals (the\n * catalog's, else the caller's verified `toTokenDecimals`; never the quote's alone), and the slippage the plan allows, so a bridge\n * order's own token and minimum can be held to them.\n * Set on every cross-chain serialized leg. A Solana account maps the whole expectation with wallet-solana's\n * `serializedGuardFromExecution`; a hand mapping that drops `bridgeOut` leaves the leg checked against the SOL ceiling only.\n */\n bridgeOut?: {destChain: string; recipient: string; destToken: string; minAmountOut: string; destDecimals?: number; slippageBps?: number};\n}\n\nconst DEFAULT_SERIALIZED_NATIVE_ALLOWANCE = 20_000_000n;\nconst DEFAULT_TON_GAS_CEILING = 1_000_000_000n;\nconst JETTON_TRANSFER_OP = 0x0f8a7ea5;\n\n/** A TON cell body read as a TEP-74 jetton transfer, duck-typed over the Cell `decodeTonBody` returned (@ton/core); null when it is not one. */\nfunction readTonBody(cell: unknown): TonBodySummary {\n type Slice = {loadUint(n: number): number; loadUintBig(n: number): bigint; loadCoins(): bigint; loadAddress(): unknown; loadMaybeAddress(): unknown; loadMaybeRef(): unknown};\n let s: Slice;\n try { s = (cell as {beginParse(): Slice}).beginParse(); } catch { return {op: null}; }\n let op: number;\n try { op = s.loadUint(32); } catch { return {op: null}; }\n if (op !== JETTON_TRANSFER_OP) return {op};\n try {\n s.loadUintBig(64); // query_id\n const amount = s.loadCoins();\n const destination = tonRawAddress(s.loadAddress());\n const response = s.loadMaybeAddress();\n s.loadMaybeRef(); // custom_payload\n const forwardTon = s.loadCoins();\n return {op, jettonTransfer: {amount, destination, responseDestination: response == null ? null : tonRawAddress(response), forwardTon}};\n } catch {\n return {op};\n }\n}\n\n/**\n * A bound wallet account, accepted opaquely: the write surface we need is\n * reached through {@link Swap2Signer}. Passing `undefined` builds a quote-only\n * protocol (no `swap2()` execution).\n */\nexport type Swap2Account = unknown;\n\n/** Minimal write surface we need off the bound account to send the leg. */\ninterface Swap2Signer {\n getAddress(): Promise<string> | string;\n sendTransaction(tx: {\n to?: string;\n data?: string;\n value?: bigint;\n chainId?: number;\n gasLimit?: bigint;\n /** TON message body: a text comment (string) or a decoded Cell. */\n body?: string | unknown;\n /** Tron: swap memo the account must place in `raw_data.data`. */\n memo?: string;\n /** Tron: 'hex' = `memo` is a binary payload in 0x-hex (default 'utf8'). */\n memoEncoding?: \"utf8\" | \"hex\";\n }): Promise<{hash?: string}>;\n /** The account's token-transfer surface, used by TON/Solana/Tron accounts. */\n transfer?: (options: {\n token: string;\n recipient: string;\n amount: bigint;\n /** Tron TRC-20: memo in `raw_data.data` next to the TriggerSmartContract. */\n memo?: string;\n /** Tron: 'hex' = `memo` is a binary payload in 0x-hex (default 'utf8'). */\n memoEncoding?: \"utf8\" | \"hex\";\n }) => Promise<{hash?: string}>;\n signTypedData?: (args: {domain: unknown; types: unknown; primaryType?: string; message: unknown}) => Promise<string>;\n /** TON: this account's jetton wallet for a jetton master — a jetton-source cell body must be sent to it. */\n getJettonWalletAddress?: (token: string) => Promise<unknown>;\n /**\n * Execute a provider-built transaction the account cannot rebuild (a swap\n * aggregator's serialized Solana tx). The account owns the proof: it must\n * refuse anything beyond `expect` before signing. Behind the kit's policies it also receives\n * `{ maxFee }` (the policy fee cap), to hold the transaction it signs to.\n */\n sendSerializedTransaction?: (serializedTx: string, expect: SerializedExecutionExpectation, options?: {maxFee?: bigint | number}) => Promise<{hash?: string}>;\n /**\n * Wait until a transaction this account sent is INCLUDED (and succeeded).\n * Used between an ERC-20 approval and the deposit that spends it: a signer\n * that returns on broadcast leaves the deposit's gas estimate looking at a\n * block where the allowance is still zero (or, for USDT's approve(0) →\n * approve(n) dance, still non-zero) — \"execution reverted\" before any\n * funds move. Accounts without it keep the fire-and-forget behaviour.\n */\n waitForTransaction?: (hash: string) => Promise<void>;\n /**\n * Current ERC-20 allowance of this account for `spender`. With it the\n * engine sends only the approvals the chain needs: none when the exact\n * allowance is already live, a single approve(n) for mainnet USDT when the\n * current allowance is 0 (its reset rule only bites non-zero → non-zero).\n * Without it (or when the read fails) the engine assumes the worst and\n * resets USDT every time.\n */\n getAllowance?: (token: string, spender: string) => Promise<bigint | number | string>;\n /** EVM gas pre-check before approvals: native balance and a fee upper bound per tx. */\n getBalance?: () => Promise<bigint | number | string>;\n quoteSendTransaction?: (tx: {to: string; data?: string; value?: bigint; chainId?: number; gasLimit?: bigint}) => Promise<{fee: bigint}>;\n /** CAIP-2 id of a @anywalletkit/core account. */\n chain?: string;\n getChainId?: () => Promise<number | bigint> | number | bigint;\n getNetwork?: () => Promise<{chainId?: number | bigint} | string> | {chainId?: number | bigint} | string;\n chainId?: number | bigint;\n _provider?: {getNetwork?: () => Promise<{chainId?: number | bigint}>};\n provider?: {getNetwork?: () => Promise<{chainId?: number | bigint}>};\n}\n\n/**\n * An exact allowance the first execution pass mined before its quote\n * expired, handed to the re-quote pass (SDK-128). The pass that adopts it\n * owns its cleanup; until then the first pass revokes on any failure.\n */\ninterface CarriedAllowance {\n token: string;\n spender: string;\n amount: bigint;\n revoke: () => Promise<void>;\n adopted: boolean;\n /** What the first pass's `reviewExecution` approved; the re-quote is reviewed again if it differs. */\n reviewed?: Swap2ExecutionPlan;\n}\n\n/**\n * What a reviewer committed to, minus what a re-quote may refresh without asking again: the\n * timing, fee estimate and ETA, the approvals (already mined), and the expected output, which is\n * compared separately (only a worse one asks again).\n */\nfunction reviewedIdentity(plan: Swap2ExecutionPlan): string {\n const {feeUsd: _fee, etaSeconds: _eta, validUntilMs: _valid, approvals: _approvals, destAmount: _dest, requoted: _requoted, ...pinned} = plan;\n return JSON.stringify(pinned, (_k, v: unknown) => (typeof v === \"bigint\" ? v.toString() : v));\n}\n\n/** Swap2 status ids are `awk1.<provider>.<intent>[.<sourceTxHash>]` (URI-encoded segments). */\nexport const SWAP2_ID_PREFIX = \"awk1\";\n\n/** Versioned provider/intent/source-hash id for durable status tracking. */\n/**\n * `awk1.<provider>.<intentId>[.<sourceTxHash>[.<destTxHash>[.ok]]]`. The destination claim's hash\n * rides in the id `claimSwap2` returns, and `.ok` after it when the account saw the claim included\n * and succeed: a provider without a destination RPC can take that as the delivery (round 3, M27).\n */\nconst CONFIRMED_SEGMENT = \"ok\";\nfunction encodeId(provider: string, intentId: string, sourceTxHash?: string, destTxHash?: string, destTxConfirmed = false): string {\n // encodeURIComponent leaves \".\" unescaped, which would shift decodeId's\n // split — escape it explicitly so segments are dot-safe.\n const enc = (v: string) => encodeURIComponent(v).replace(/\\./g, \"%2E\");\n const dest = destTxHash != null ? [destTxHash, ...(destTxConfirmed ? [CONFIRMED_SEGMENT] : [])] : [];\n const parts = [provider, intentId, ...(sourceTxHash != null ? [sourceTxHash, ...dest] : [])];\n return `${SWAP2_ID_PREFIX}.${parts.map(enc).join(\".\")}`;\n}\nfunction decodeId(id: string): {provider: string; intentId: string; sourceTxHash?: string; destTxHash?: string; destTxConfirmed?: true} {\n try {\n if (!id.startsWith(`${SWAP2_ID_PREFIX}.`)) throw new Error(\"unsupported id version\");\n const parts = id.slice(SWAP2_ID_PREFIX.length + 1).split(\".\");\n if (parts.length < 2 || parts.length > 5 || !parts[0] || !parts[1]) throw new Error(\"invalid id shape\");\n const provider = decodeURIComponent(parts[0]);\n const intentId = decodeURIComponent(parts[1]);\n const sourceTxHash = parts[2] ? decodeURIComponent(parts[2]) : undefined;\n const destTxHash = parts[3] ? decodeURIComponent(parts[3]) : undefined;\n if (!/^[A-Za-z0-9_-]+$/.test(provider) || !intentId || (parts[2] !== undefined && !sourceTxHash) || (parts[3] !== undefined && !destTxHash)) {\n throw new Error(\"invalid id contents\");\n }\n if (parts[4] !== undefined && parts[4] !== CONFIRMED_SEGMENT) throw new Error(\"invalid id contents\");\n return {provider, intentId, ...(sourceTxHash ? {sourceTxHash} : {}), ...(destTxHash ? {destTxHash} : {}), ...(parts[4] !== undefined ? {destTxConfirmed: true as const} : {})};\n } catch {\n throw new Swap2ValidationError(\"swap2: malformed swap2 status id\");\n }\n}\n\nasync function readAccountChain(signer: Swap2Signer, configured?: string): Promise<string | number | bigint | undefined> {\n if (configured) return configured;\n // @anywalletkit/core accounts carry their CAIP-2 id directly.\n if (typeof signer.chain === \"string\" && signer.chain && !signer.chain.endsWith(\":unknown\")) return signer.chain;\n if (typeof signer.getChainId === \"function\") return await signer.getChainId();\n if (typeof signer.getNetwork === \"function\") {\n const network = await signer.getNetwork();\n return typeof network === \"string\" ? network : network?.chainId;\n }\n if (signer.chainId != null) return signer.chainId;\n for (const provider of [signer._provider, signer.provider]) {\n if (provider?.getNetwork) {\n const network = await provider.getNetwork();\n if (network?.chainId != null) return network.chainId;\n }\n }\n return undefined;\n}\n\n/** CAIP-2 → the coarse VM family Swap2SupportedChain.type expects. */\nfunction chainType(caip2: string): string {\n const ns = caip2.split(\":\")[0] ?? \"\";\n if (ns === \"eip155\") return \"evm\";\n if (ns === \"solana\") return \"svm\";\n if (ns === \"tron\") return \"tvm\";\n if ([\"bitcoin\", \"litecoin\", \"doge\", \"bch\", \"zcash\"].includes(ns)) return \"utxo\";\n return ns;\n}\n\n/**\n * The wallet packages name non-EVM chains by genesis hash (CAIP-2 proper:\n * `account.chain` of a Solana account is `solana:5eykt…`), while the swap2\n * catalog and every provider use the short ids. The engine takes either.\n */\nexport const SWAP2_CHAIN_ALIASES: Readonly<Record<string, string>> = Object.freeze({\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\": \"solana:mainnet\",\n \"tron:0x2b6653dc\": \"tron:728126428\",\n \"bip122:000000000019d6689c085ae165831e93\": \"bitcoin:mainnet\",\n});\n/** The swap2 id for `chain` (itself when it has no alias). */\nexport const swap2ChainId = (chain: string): string => SWAP2_CHAIN_ALIASES[chain] ?? chain;\n\n/** Normalize a `toChain` (number chainId | CAIP-2 | numeric string) to CAIP-2. */\nfunction toCaip2(chain: string | number | undefined, fallback: string): string {\n if (chain == null || chain === \"\") return fallback;\n if (typeof chain === \"number\") {\n if (!Number.isSafeInteger(chain) || chain <= 0) throw new Swap2ValidationError(\"swap2: chain id must be a positive safe integer\");\n return `eip155:${chain}`;\n }\n if (/^\\d+$/.test(chain)) {\n const id = Number(chain);\n if (!Number.isSafeInteger(id) || id <= 0) throw new Swap2ValidationError(\"swap2: chain id must be a positive safe integer\");\n return `eip155:${id}`;\n }\n if (!/^[a-z0-9]{3,8}:[-_A-Za-z0-9]{1,32}$/.test(chain)) {\n throw new Swap2ValidationError(\"swap2: chain must be a valid CAIP-2 identifier\");\n }\n return swap2ChainId(chain);\n}\n\n/** An empty token ref would resolve to the native coin (round 3, M25): it is refused instead. */\nfunction nonEmptyRef(ref: string, side: string): string {\n if (typeof ref !== \"string\" || ref.trim() === \"\") throw new Swap2ValidationError(`swap2: ${side} token must not be empty (pass the symbol or the contract address)`);\n return ref;\n}\n\n/** Resolve a token ref (symbol OR on-chain address) to the engine's symbol. */\nfunction toSymbol(caip2: string, ref: string): string {\n nonEmptyRef(ref, \"source\");\n const byToken = ref.startsWith(\"0x\") || ref.length > 20 ? ccAssetByToken(caip2, ref) : undefined;\n if (byToken) return byToken.symbol;\n if (ccAsset(caip2, ref)) return ref; // already a symbol we know\n return ref;\n}\n\n/** Resolve a dest token ref to the engine's dest address (zero = native). */\nfunction toDestAddress(caip2: string, ref: string, allowUnlisted = false): string {\n nonEmptyRef(ref, \"destination\");\n if (ref.startsWith(\"0x\")) return ref;\n const asset = ccAssetByToken(caip2, ref) ?? ccAsset(caip2, ref);\n if (!asset) {\n if (allowUnlisted && isTokenAddress(caip2, ref)) return ref;\n throw new Error(`swap2: unknown destination token '${ref}' on ${caip2}`);\n }\n return asset.contract ?? ZERO;\n}\n\nfunction snapshotOptions(options: Swap2Options): Swap2Options {\n return Object.freeze({...options});\n}\n\nfunction snapshotConfig(config?: Swap2ProtocolConfig): Swap2ProtocolConfig | undefined {\n return config ? Object.freeze({...config}) : undefined;\n}\n\nfunction snapshotQuote<T extends Quote>(quote: T): T {\n return Object.freeze({\n ...quote,\n ...(quote.txRequest ? {txRequest: Object.freeze({...quote.txRequest})} : {}),\n ...(quote.providerData ? {providerData: Object.freeze({...quote.providerData})} : {}),\n ...(quote.fees ? {fees: Object.freeze(quote.fees.map((fee) => Object.freeze({...fee})))} : {}),\n }) as T;\n}\n\nfunction exactPositiveAmount(value: number | bigint, name: string): bigint {\n if (typeof value === \"number\") {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new Swap2ValidationError(`swap2: ${name} must be a positive safe integer or bigint`);\n }\n return BigInt(value);\n }\n if (value <= 0n) throw new Swap2ValidationError(`swap2: ${name} must be a positive safe integer or bigint`);\n return value;\n}\n\n/**\n * floor(x × scale) that forgives binary representation error: a caller's\n * 0.0029 is 29 bps, though 0.0029 × 10 000 is 28.999…96 in floating point\n * (573 of the 10 001 whole-bps decimals land one short with a plain floor).\n */\nfunction floorScaled(x: number, scale: number): number {\n const v = x * scale;\n const nearest = Math.round(v);\n return Math.abs(v - nearest) < 1e-6 ? nearest : Math.floor(v);\n}\n\nfunction callerConstraints(options: Swap2Options): {minAmountOut?: bigint; slippageBps?: number} {\n let minAmountOut: bigint | undefined;\n if (options.minAmountOut !== undefined) {\n try {\n minAmountOut = BigInt(options.minAmountOut);\n } catch {\n throw new Error(\"swap2: minAmountOut must be a positive integer\");\n }\n if (minAmountOut <= 0n) throw new Error(\"swap2: minAmountOut must be a positive integer\");\n }\n let slippageBps: number | undefined;\n if (options.slippage !== undefined) {\n if (!Number.isFinite(options.slippage) || options.slippage < 0 || options.slippage >= 1) {\n throw new Error(\"swap2: slippage must be a finite decimal in [0, 1)\");\n }\n // Providers accept whole bps. Round down so their on-chain/API tolerance\n // can never be wider than the caller requested; the exact decimal is also\n // checked against the returned quote below.\n slippageBps = floorScaled(options.slippage, 10_000);\n }\n return {\n ...(minAmountOut !== undefined ? {minAmountOut} : {}),\n ...(slippageBps !== undefined ? {slippageBps} : {}),\n };\n}\n\nfunction assertQuoteConstraints(q: Quote, options: Swap2Options): void {\n const {minAmountOut} = callerConstraints(options);\n const nominal = BigInt(q.destAmount);\n const guaranteed = BigInt(q.minDestAmount);\n if (minAmountOut !== undefined && guaranteed < minAmountOut) {\n throw new Error(`swap2: quoted minimum ${guaranteed} is below caller minAmountOut ${minAmountOut}`);\n }\n if (options.slippage !== undefined) {\n const scale = 1_000_000_000n;\n // The caller's slippage plus the providers' rounding (SLIPPAGE_ROUNDING_BPS), floored like\n // the providers compute their minimum (see validQuote).\n const permitted = BigInt(floorScaled(options.slippage, 1_000_000_000)) + BigInt(SLIPPAGE_ROUNDING_BPS) * 100_000n;\n const required = permitted >= scale ? 0n : (nominal * (scale - permitted)) / scale;\n if (guaranteed < required) {\n throw new Error(`swap2: quote exceeds caller slippage (${options.slippage})`);\n }\n }\n}\n\n/** The bridge leg's reviewed terms for {@link SerializedExecutionExpectation.bridgeOut}. */\nfunction bridgeOutOf(params: QuoteParams, q: Quote, toTokenDecimals: number | undefined): NonNullable<SerializedExecutionExpectation[\"bridgeOut\"]> {\n // The catalog's decimals, else the app's verified `toTokenDecimals` for a token the catalog does not list. The quote's\n // own `destDecimals` is the provider's word: it never stands in alone (an account refuses a bridge order it cannot\n // hold to a minimum), and one that disagrees with the app's is refused.\n let decimals = resolveAsset(params.destChain, params.destToken)?.decimals;\n if (decimals === undefined && toTokenDecimals !== undefined) {\n if (q.destDecimals !== undefined && q.destDecimals !== toTokenDecimals) {\n throw new Swap2ValidationError(`swap2: the quote's destDecimals ${q.destDecimals} do not match toTokenDecimals ${toTokenDecimals}`);\n }\n decimals = toTokenDecimals;\n }\n return {\n destChain: params.destChain, recipient: params.destAddress, destToken: params.destToken, minAmountOut: q.minDestAmount,\n ...(decimals !== undefined ? {destDecimals: decimals} : {}),\n ...(params.slippageBps !== undefined ? {slippageBps: params.slippageBps} : {}),\n };\n}\n\nfunction requireExecutionFloor(options: Swap2Options): void {\n if (options.minAmountOut === undefined) {\n throw new Error(\"swap2: swap2() requires caller-supplied minAmountOut\");\n }\n callerConstraints(options);\n}\n\nfunction mapStatus(s: IntentStatus): Swap2StatusResult {\n const status: Swap2Status =\n s.state === \"completed\"\n ? \"completed\"\n : s.state === \"action-required\"\n ? \"action-required\"\n : s.state === \"refund-pending\"\n ? \"refund-pending\"\n : s.state === \"partial\"\n ? \"partial\"\n : s.state === \"failed\"\n ? \"failed\"\n : s.state === \"refunded\"\n ? \"refunded\"\n : s.state === \"cancelled\"\n ? \"cancelled\"\n : s.state === \"expired\"\n ? \"expired\"\n : \"pending\";\n return s.destTxHash\n ? {status, transactions: [{hash: s.destTxHash, type: \"destination\"}]}\n : {status};\n}\n\n/** `\"\"` / whitespace → undefined: an empty input field names no address. */\nfunction blankToUndefined(v: string | undefined): string | undefined {\n return typeof v === \"string\" && v.trim() === \"\" ? undefined : v;\n}\n\n/** The options with blank `recipient` / `refundAddress` dropped (they default to the account). */\nfunction withoutBlankAddresses(o: Swap2Options): Swap2Options {\n const {recipient, refundAddress, ...rest} = o;\n const r = blankToUndefined(recipient);\n const f = blankToUndefined(refundAddress);\n return {...rest, ...(r !== undefined ? {recipient: r} : {}), ...(f !== undefined ? {refundAddress: f} : {})} as Swap2Options;\n}\n\n/**\n * Abstract swap2 protocol backed by the engine. Concrete subclasses bind\n * either a single provider (contribution-shaped) or the router (aggregator).\n */\nexport abstract class BaseSwap2Protocol extends Swap2Protocol {\n protected readonly fromChain: string;\n\n constructor(account: Swap2Account | undefined, config: Swap2EngineConfig) {\n const fromChain = toCaip2(config.fromChain, \"\");\n if (!fromChain) throw new Swap2ValidationError(\"swap2: fromChain is required\");\n const configSnapshot = Object.freeze({...config, fromChain});\n super(account as never, configSnapshot);\n this.fromChain = fromChain;\n }\n\n /** Quote the route (single provider, or best across the router). */\n protected abstract resolveQuote(params: QuoteParams): Promise<Quote | null>;\n\n /** Why the last resolveQuote came back empty (venue names + reasons), or \"\".\n * Rides inside the no-route error so execution failures are diagnosable\n * from the surface that shows them. */\n protected noRouteDetail(): string {\n return \"\";\n }\n /** Look up a provider by name to resume/track an in-flight swap2. */\n protected abstract providerFor(name: string): CrossChainProvider | undefined;\n /** Whether this protocol can route a chain at all (for support discovery). */\n protected abstract chainSupported(caip2: string): boolean;\n\n /** Report an execution phase; an observer that throws is ignored. */\n protected emitPhase(phase: Swap2ExecutionPhase, detail?: Swap2ExecutionPhaseDetail): void {\n const observer = (this._config as Swap2EngineConfig).onExecutionPhase;\n if (!observer) return;\n try {\n observer(phase, detail);\n } catch {\n /* diagnostics only */\n }\n }\n /** Runtime availability used by the public discovery methods. */\n protected protocolEnabled(): boolean { return true; }\n /** Pair-level capability used when discovery specifies both endpoints. */\n protected pairSupported(fromChain: string, toChain: string): boolean {\n return this.chainSupported(fromChain) && this.chainSupported(toChain);\n }\n\n private unlistedAllowed(): boolean {\n return (this._config as Swap2EngineConfig).allowUnlistedTokens === true;\n }\n\n /** The source asset the options name: the catalog's, or (allowUnlistedTokens) an unlisted one with its decimals. */\n protected sourceAsset(options: Swap2Options): CcAsset | undefined {\n const decimals = options.fromTokenDecimals;\n return resolveAsset(this.fromChain, toSymbol(this.fromChain, options.fromToken), {\n allowUnlisted: this.unlistedAllowed(),\n ...(decimals !== undefined ? {decimals} : {}),\n });\n }\n\n private readonly unlistedDecimals = new Map<string, number>();\n\n /**\n * Options ready to quote: with `allowUnlistedTokens`, an unlisted source token gets its decimals,\n * read from the chain through the account (cached per token) — a caller's `fromTokenDecimals` that\n * disagrees is refused. Listed tokens and every option otherwise pass through unchanged.\n */\n protected async prepareOptions(options: Swap2Options): Promise<Swap2Options> {\n if (!this.unlistedAllowed()) return options;\n const ref = toSymbol(this.fromChain, options.fromToken);\n if (resolveAsset(this.fromChain, ref) || !isTokenAddress(this.fromChain, ref)) return options;\n const key = ref.startsWith(\"0x\") ? ref.toLowerCase() : ref;\n let decimals = this.unlistedDecimals.get(key);\n if (decimals === undefined) {\n const reader = this._account as {getTokenInfo?: (token: string) => Promise<{decimals: number}>} | undefined;\n if (typeof reader?.getTokenInfo !== \"function\") {\n if (options.fromTokenDecimals === undefined) {\n throw new Swap2ValidationError(`swap2: '${ref}' is not in the catalog — pass fromTokenDecimals, or use an account that can read token info`);\n }\n return options;\n }\n decimals = (await reader.getTokenInfo(ref)).decimals;\n this.unlistedDecimals.set(key, decimals);\n }\n if (options.fromTokenDecimals !== undefined && options.fromTokenDecimals !== decimals) {\n throw new Swap2ValidationError(`swap2: fromTokenDecimals ${options.fromTokenDecimals} does not match the token's ${decimals}`);\n }\n return snapshotOptions({...options, fromTokenDecimals: decimals});\n }\n\n /** Swap2Options → the engine's QuoteParams (exact-in only). */\n protected toParams(given: Swap2Options, dry: boolean): QuoteParams {\n const options = withoutBlankAddresses(given);\n if (options.fromTokenAmount == null) {\n throw new Swap2UnsupportedOperationError(\"swap2: exact-out swap2 is not supported by the engine\");\n }\n const destChain = toCaip2(options.toChain, this.fromChain);\n const constraints = callerConstraints(options);\n const toDecimals = options.toTokenDecimals;\n if (toDecimals !== undefined && (!Number.isInteger(toDecimals) || toDecimals < 0 || toDecimals > 36)) {\n throw new Swap2ValidationError(\"swap2: toTokenDecimals must be whole decimals in 0..36\");\n }\n const amountIn = exactPositiveAmount(options.fromTokenAmount, \"fromTokenAmount\");\n const source = this.sourceAsset(options);\n const params: QuoteParams = {\n sourceChain: this.fromChain,\n sourceToken: isUnlisted(source) ? source.contract : toSymbol(this.fromChain, options.fromToken),\n ...(isUnlisted(source) ? {sourceDecimals: source.decimals} : {}),\n destChain,\n destToken: toDestAddress(destChain, options.toToken, this.unlistedAllowed()),\n amountIn: amountIn.toString(),\n destAddress: options.recipient ?? \"\",\n dry,\n ...(constraints.minAmountOut !== undefined ? {minAmountOut: constraints.minAmountOut.toString()} : {}),\n ...(constraints.slippageBps !== undefined ? {slippageBps: constraints.slippageBps} : {}),\n };\n return options.refundAddress ? {...params, refundAddress: options.refundAddress} : params;\n }\n\n private async assertAccountChain(signer: Swap2Signer): Promise<void> {\n const config = this._config as Swap2EngineConfig;\n if (config.skipAccountChainCheck) return;\n const actual = await readAccountChain(signer, config.accountChain);\n if (actual == null) {\n throw new Error(`swap2: account chain identity is unavailable for ${this.fromChain}; set accountChain or explicitly opt out with skipAccountChainCheck`);\n }\n const expected = this.fromChain;\n const expectedId = expected.startsWith(\"eip155:\") ? expected.slice(\"eip155:\".length) : expected;\n const actualText = swap2ChainId(typeof actual === \"string\" ? actual : String(actual));\n const actualId = actualText.startsWith(\"eip155:\") ? actualText.slice(\"eip155:\".length) : actualText;\n if (actualId !== expectedId) {\n throw new Error(`swap2: account is bound to ${actualText}, but fromChain is ${expected}`);\n }\n }\n\n protected assertFeeConfig(config?: Swap2ProtocolConfig): void {\n const configured = {...(this._config as Swap2ProtocolConfig), ...(config ?? {})};\n for (const [name, value] of [[\"maxNetworkFeeBps\", configured.maxNetworkFeeBps], [\"maxProtocolFeeBps\", configured.maxProtocolFeeBps]] as const) {\n if (value === undefined) continue;\n const bps = typeof value === \"bigint\" ? value : Number.isSafeInteger(value) ? BigInt(value) : -1n;\n if (bps < 0n || bps > 10_000n) throw new Swap2ConfigurationError(`swap2: ${name} must be an integer between 0 and 10000`);\n }\n }\n\n protected assertFeeCaps(\n fees: readonly Swap2Fee[] | undefined,\n sourceAmount: bigint,\n sourceToken: string,\n config?: Swap2ProtocolConfig,\n ): void {\n this.assertFeeConfig(config);\n const configured = {...(this._config as Swap2ProtocolConfig), ...(config ?? {})};\n const caps = [\n [\"network\", configured.maxNetworkFeeBps],\n [\"protocol\", configured.maxProtocolFeeBps],\n ] as const;\n if (!caps.some(([, cap]) => cap !== undefined)) return;\n if (!fees) throw new Swap2FeeLimitError(\"swap2: fee caps require an itemized provider fee breakdown\");\n const normalizedSource = sourceToken.toLowerCase();\n for (const [type, cap] of caps) {\n if (cap === undefined) continue;\n const matching = fees.filter((fee) => fee.type === type);\n if (matching.some((fee) => fee.token.toLowerCase() !== normalizedSource)) {\n throw new Swap2FeeLimitError(`swap2: cannot apply ${type} fee cap across different fee tokens`);\n }\n const total = matching.reduce((sum, fee) => sum + fee.amount, 0n);\n const bps = typeof cap === \"bigint\" ? cap : BigInt(cap);\n if (total * 10_000n > sourceAmount * bps) {\n throw new Swap2FeeLimitError(`swap2: ${type} fee exceeds configured cap`);\n }\n }\n }\n\n protected assertQuoteFeeCaps(q: Quote, options: Swap2Options, config?: Swap2ProtocolConfig): void {\n const source = this.sourceAsset(options);\n if (!source) throw new Error(`swap2: unknown source token '${options.fromToken}' on ${this.fromChain}`);\n const token = source.contract ?? source.assetId;\n const fees = q.fees?.map((fee) => ({...fee, amount: BigInt(fee.amount)} as Swap2Fee));\n this.assertFeeCaps(fees, BigInt(q.sourceAmount), token, config);\n }\n\n protected toQuote(q: Quote, options: Swap2Options): Swap2Quote {\n // Never fabricate a zero-valued fee. Providers that expose base-unit fee\n // amounts map them precisely; otherwise the net guaranteed output remains\n // authoritative and the itemized list is honestly empty.\n const fees: Swap2Fee[] = (q.fees ?? []).map((fee) => ({\n type: fee.type,\n amount: BigInt(fee.amount),\n token: fee.token,\n included: fee.included,\n ...(fee.description ? {description: fee.description} : {}),\n }));\n return {\n fromTokenAmount: BigInt(q.sourceAmount),\n toTokenAmount: BigInt(q.destAmount),\n toTokenAmountMin: BigInt(q.minDestAmount),\n fees,\n ...(q.etaSeconds ? {estimatedDuration: q.etaSeconds} : {}),\n ...(q.validUntilMs ? {expiry: Math.floor(q.validUntilMs / 1000)} : {}),\n };\n }\n\n /** A frozen, validated copy of caller options (what every engine path works from). */\n protected snapshotOf(options: Swap2Options): Swap2Options {\n return snapshotOptions(options);\n }\n\n /** A dry route the auction already validated → the public quote, or null when the caller's floor / fee caps refuse it. */\n protected routeQuote(q: Quote, options: Swap2Options): Swap2Quote | null {\n try {\n assertQuoteConstraints(q, options);\n this.assertQuoteFeeCaps(q, options);\n return this.toQuote(q, options);\n } catch {\n return null;\n }\n }\n\n /**\n * Ask for a quote and check it against the request (amounts, slippage floor, fee ceilings in the\n * protocol config). Works on a read-only account.\n *\n * @throws {@link Swap2QuoteError} when no route answers, with the provider's own reason when it\n * gave one.\n */\n override async quoteSwap2(options: Swap2Options): Promise<Swap2Quote> {\n const snapshot = await this.prepareOptions(snapshotOptions(options));\n const q = await this.resolveQuote(this.toParams(snapshot, true));\n if (!q) {\n const detail = this.noRouteDetail();\n throw new Swap2QuoteError(`swap2: no route available for the requested pair${detail ? ` :: ${detail}` : \"\"}`);\n }\n assertQuoteConstraints(q, snapshot);\n this.assertQuoteFeeCaps(q, snapshot);\n return this.toQuote(q, snapshot);\n }\n\n /**\n * Re-quote, check the quote, show it to `reviewExecution` when configured, send any approvals,\n * then sign and broadcast the source leg. An identical call already in flight on the same account\n * is refused.\n *\n * @throws {@link Swap2ExecutionError} for a read-only account, {@link Swap2InFlightError} for a\n * double tap, {@link Swap2MaybeSentError} when the broadcast outcome is unknown (do not retry;\n * track `hash`).\n */\n override async swap2(options: Swap2Options, config?: Swap2ProtocolConfig): Promise<Swap2Result> {\n // Account first: a read-only or missing account is refused before any option is\n // validated or any network call is made (SDK protocol conformance).\n const signerCandidate = this._account as Partial<Swap2Signer> | undefined;\n if (!signerCandidate || typeof signerCandidate.sendTransaction !== \"function\") {\n throw new Swap2ExecutionError(\"swap2: swap2() requires a signing account (read-only accounts can only quote)\");\n }\n const snapshot = snapshotOptions(options);\n requireExecutionFloor(snapshot);\n // A double tap re-quotes and would run a second complete swap: refuse it\n // while the identical call is still in flight on this account.\n const key = inFlightKey(this.fromChain, snapshot);\n const running = IN_FLIGHT.get(signerCandidate) ?? new Set<string>();\n if (running.has(key)) throw new Swap2InFlightError(\"swap2: an identical swap is already in progress on this account — wait for its result\");\n running.add(key);\n IN_FLIGHT.set(signerCandidate, running);\n try {\n return await this.executeSwap2(signerCandidate as Swap2Signer, snapshot, config);\n } finally {\n running.delete(key);\n }\n }\n\n private async executeSwap2(signer: Swap2Signer, snapshot: Swap2Options, config?: Swap2ProtocolConfig, carried?: CarriedAllowance): Promise<Swap2Result> {\n const configSnapshot = snapshotConfig(config);\n this.assertFeeConfig(configSnapshot);\n await this.assertAccountChain(signer);\n // Refunds land on the SOURCE chain, so the only safe default is the bound\n // account's own address — never the recipient, which may be a dest-chain\n // address (a TON-source swap with an EVM recipient would otherwise hand the\n // provider an EVM string as the TON refund/trader wallet).\n const selfAddress = await signer.getAddress();\n // A blank field (\"\" from an empty input) is no address at all: this account, never a provider's placeholder (round 3, H8).\n const recipient = blankToUndefined(snapshot.recipient) ?? selfAddress;\n const refundAddress = blankToUndefined(snapshot.refundAddress) ?? selfAddress;\n const executionOptions = await this.prepareOptions(snapshotOptions({...snapshot, recipient, refundAddress}));\n const params = this.toParams(executionOptions, false);\n const resolved = await this.resolveQuote(params);\n if (!resolved) {\n const detail = this.noRouteDetail();\n throw new Swap2QuoteError(`swap2: no route available for the requested pair${detail ? ` :: ${detail}` : \"\"}`);\n }\n const q = snapshotQuote(resolved);\n assertQuoteConstraints(q, executionOptions);\n this.assertQuoteFeeCaps(q, executionOptions, configSnapshot);\n\n const provider = this.providerFor(q.provider);\n if (!provider) throw new Error(`swap2: provider '${q.provider}' is not registered`);\n let providerEnabled = false;\n try { providerEnabled = provider.enabled(); } catch { /* fail closed below */ }\n if (!providerEnabled) throw new Error(`swap2: provider '${q.provider}' is disabled`);\n let unsigned: UnsignedTx = Object.freeze({...await provider.buildDeposit(q)});\n\n const serialized = unsigned.serializedTx !== undefined;\n if (serialized) {\n if (!unsigned.serializedTx) throw new Error(\"swap2: provider returned an empty serialized transaction\");\n if (unsigned.data !== undefined || unsigned.bodyBoc !== undefined || unsigned.typedData !== undefined || unsigned.memo !== undefined || unsigned.approvalAddress !== undefined) {\n throw new Error(\"swap2: provider returned ambiguous execution payloads\");\n }\n if (typeof signer.sendSerializedTransaction !== \"function\") {\n throw new Swap2ExecutionError(`swap2: ${this.fromChain} serialized execution requires account.sendSerializedTransaction`);\n }\n }\n if (unsigned.chain && unsigned.chain !== this.fromChain) {\n throw new Error(`swap2: provider transaction chain ${unsigned.chain} does not match ${this.fromChain}`);\n }\n if (unsigned.stateInitBoc !== undefined) {\n throw new Error(\"swap2: deposit requires a stateInit the generic account cannot attach\");\n }\n // A remote build response is not a new authority. For ordinary calldata and\n // deposit-address providers the validated quote already commits every\n // execution field; require buildDeposit to reproduce it exactly.\n if (q.txRequest) {\n const tx = q.txRequest;\n const sameAddress = (a: string | undefined, b: string | undefined) =>\n a === b || (!!a && !!b && a.startsWith(\"0x\") && b.startsWith(\"0x\") && a.toLowerCase() === b.toLowerCase());\n if (\n !sameAddress(unsigned.to, tx.to ?? \"\") ||\n unsigned.data !== tx.data ||\n unsigned.value !== (tx.value ?? \"0\") ||\n unsigned.chainId !== tx.chainId ||\n unsigned.gasLimit !== tx.gasLimit ||\n !sameAddress(unsigned.approvalAddress, tx.approvalAddress) ||\n unsigned.serializedTx !== tx.serializedTx\n ) {\n throw new Error(\"swap2: provider build does not match the validated quote transaction\");\n }\n } else if (!unsigned.bodyBoc && !unsigned.typedData) {\n // A deposit-address quote commits the address and the memo only: the build may not add\n // calldata, a spender or a serialized transaction the quote never had (round 3, L15).\n if (!q.depositAddress || unsigned.to !== q.depositAddress || (unsigned.memo ?? null) !== q.depositMemo ||\n unsigned.data !== undefined || unsigned.approvalAddress !== undefined || unsigned.serializedTx !== undefined) {\n throw new Error(\"swap2: provider build does not match the validated quote deposit\");\n }\n }\n const executionModels = [unsigned.data !== undefined, unsigned.bodyBoc !== undefined, unsigned.typedData !== undefined]\n .filter(Boolean).length;\n if (executionModels > 1 || (unsigned.memo !== undefined && (unsigned.bodyBoc !== undefined || unsigned.typedData !== undefined)) ||\n (unsigned.orderExtension !== undefined && unsigned.typedData === undefined)) {\n throw new Error(\"swap2: provider returned ambiguous execution payloads\");\n }\n if (unsigned.approvalAddress && !unsigned.data && !unsigned.typedData) {\n throw new Error(\"swap2: approval is only valid for calldata or typed-order execution\");\n }\n // A remote stub's build that pays an address its backend named — a deposit address, a plain value send — skips\n // every pin below; it runs only on a stub the app opened to such routes (scan 2026-10-28, F9).\n if (provider.remote === true && provider.depositAddressRoutes !== true &&\n unsigned.data === undefined && unsigned.bodyBoc === undefined && unsigned.typedData === undefined && !serialized) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' sends the input to ${unsigned.to}, an address its backend named, and the app did not allow deposit-address routes for it (remoteProvider depositAddressRoutes) — refused`);\n }\n // Memo'd deposits: TON carries it as the message body, Tron in\n // raw_data.data (both TRX and TRC-20 — bifrost reads that field for\n // either contract type). Every other chain would silently drop it.\n const tronSource = this.fromChain.startsWith(\"tron:\");\n // NEAR: a NEP-141 `ft_transfer` carries `memo`; a native transfer cannot\n // (the account refuses a memo it would otherwise drop).\n const nearSource = this.fromChain.startsWith(\"near:\");\n if (unsigned.memo && !this.fromChain.startsWith(\"ton:\") && !tronSource && !nearSource) {\n throw new Error(`swap2: deposit memo execution is not implemented for ${this.fromChain}`);\n }\n if (unsigned.data !== undefined && !this.fromChain.startsWith(\"eip155:\")) {\n throw new Error(`swap2: calldata execution is not implemented for ${this.fromChain}`);\n }\n // Cell-body deposits (Omniston escrow): the body MUST be decoded to a Cell —\n // a TON account renders a string body as a text comment, stranding the\n // swap. Fail closed unless the caller supplied `decodeTonBody`.\n let cellBody: unknown;\n if (unsigned.bodyBoc !== undefined) {\n if (!unsigned.bodyBoc) throw new Error(\"swap2: cell-body deposit has an empty body\");\n if (!this.fromChain.startsWith(\"ton:\")) {\n throw new Error(`swap2: cell-body execution is not implemented for ${this.fromChain}`);\n }\n const decode = (this._config as Swap2EngineConfig).decodeTonBody;\n if (!decode) {\n throw new Error(\"swap2: cell-body deposit needs config.decodeTonBody (e.g. Cell.fromBase64)\");\n }\n cellBody = decode(unsigned.bodyBoc);\n if (cellBody == null) {\n throw new Error(\"swap2: config.decodeTonBody returned no Cell\");\n }\n }\n if (unsigned.chainId !== undefined && this.fromChain.startsWith(\"eip155:\") && String(unsigned.chainId) !== this.fromChain.slice(\"eip155:\".length)) {\n throw new Error(`swap2: provider transaction chain ${unsigned.chainId} does not match ${this.fromChain}`);\n }\n\n // TOKEN-asset sources on deposit-address routes need token-transfer\n // semantics: a bare {to, value} would move the NATIVE coin with the\n // token's base-unit amount (audit C1 — e.g. USDT source via a 1Click\n // deposit address would have sent ETH wei). EVM sources are rewritten\n // into an ERC-20 transfer(depositAddress, amount); supported non-EVM\n // sources use the account's transfer() token surface below.\n let tokenId: string | undefined;\n // The deposit-address transfer the engine writes itself (source token, quoted amount, quoted deposit address).\n let engineTransfer = false;\n if (!unsigned.data && !unsigned.bodyBoc && !unsigned.typedData && !serialized) {\n const src = this.sourceAsset(executionOptions);\n if (src?.contract) {\n if (this.fromChain.startsWith(\"eip155:\")) {\n engineTransfer = true;\n unsigned = {\n ...unsigned,\n to: src.contract,\n data: encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: \"transfer\",\n args: [unsigned.to as `0x${string}`, BigInt(q.sourceAmount)],\n }),\n value: \"0\",\n };\n } else if (\n this.fromChain.startsWith(\"solana:\") ||\n this.fromChain.startsWith(\"ton:\") ||\n this.fromChain.startsWith(\"tron:\") ||\n nearSource\n ) {\n // Solana SPL / TON jetton / Tron TRC-20 / NEAR NEP-141 source. These\n // accounts expose token movement through `transfer()`; their\n // `sendTransaction({to,value})` surface is a NATIVE transfer and does\n // not recognize custom token metadata.\n tokenId = src.contract;\n } else {\n throw new Error(\n `swap2: token deposit-address execution is not implemented for ${this.fromChain} — only cell-body/calldata providers can move non-native assets here`,\n );\n }\n }\n }\n\n // A TON jetton transfer carries the memo as its forward-payload comment: the\n // account's `transfer({memo})` surface places it there (TEP-74), exactly as\n // Tron puts it in raw_data.data and NEAR in the ft_transfer memo.\n const tonSource = this.fromChain.startsWith(\"ton:\");\n if (tokenId && (cellBody !== undefined || (unsigned.memo !== undefined && !tronSource && !nearSource && !tonSource))) {\n throw new Error(\"swap2: token deposit with memo/cell payload is not implemented\");\n }\n\n // Bind the value presented to the signer to the already validated quote.\n // Native deposits and the amount handed to transfer() must carry the exact\n // input amount; EVM token execution must never attach native value.\n const source = this.sourceAsset(executionOptions);\n if (!source) throw new Error(`swap2: unknown source token '${executionOptions.fromToken}' on ${this.fromChain}`);\n const executionValue = BigInt(unsigned.value);\n if (serialized) {\n // The native coin leaves through the serialized tx itself; `value` only\n // declares what the account may let it take: the input for a native\n // source, nothing for a token source.\n if (executionValue !== (source.contract ? 0n : BigInt(q.sourceAmount))) {\n throw new Error(\"swap2: provider execution amount does not match the validated quote\");\n }\n } else if (source.contract && this.fromChain.startsWith(\"eip155:\")) {\n // Only a fee the sealed quote declared, and only up to the chain's cap.\n const declared = declaredNativeFee(q, this.fromChain);\n if (executionValue !== declared) {\n throw new Error(declared === 0n\n ? \"swap2: token execution attempted to attach native value\"\n : `swap2: token execution value ${executionValue} does not match the quoted native fee ${declared}`);\n }\n } else if (!unsigned.typedData && !unsigned.bodyBoc && executionValue !== BigInt(q.sourceAmount) + declaredNativeFee(q, this.fromChain)) {\n throw new Error(\"swap2: provider execution amount does not match the validated quote\");\n }\n\n // A TON cell body is bound like every other build (scan 2026-10-27 modules, F7/F13/F18/F19): the TON it attaches is\n // the input (native source) plus gas up to `tonGasCeiling`; a jetton source's body is a TEP-74 transfer of exactly\n // the input from this account's own jetton wallet, its excess returning here. A remote stub's cell body also needs\n // the app's own validator (`remoteProvider` `verifyBuild`, e.g. Omniston's `omnistonVerifyBuild`).\n let tonBody: TonBodySummary | undefined;\n if (cellBody !== undefined) {\n const refuse = (why: string): never => { throw new Swap2ValidationError(`swap2: TON cell-body build refused — ${why}`); };\n const raw = (this._config as Swap2EngineConfig).tonGasCeiling;\n const ceiling = raw === undefined ? DEFAULT_TON_GAS_CEILING : BigInt(raw);\n if (ceiling < 0n) throw new Swap2ConfigurationError(\"swap2: tonGasCeiling must be non-negative\");\n if (provider.remote === true && provider.verifiesBuilds !== true) refuse(\"a remote provider's cell body needs the app's own validator (remoteProvider verifyBuild)\");\n tonBody = readTonBody(cellBody);\n const input = BigInt(q.sourceAmount);\n if (source.contract) {\n if (executionValue > ceiling) refuse(`it attaches ${executionValue} nanoTON to a jetton transfer, more than the ${ceiling} gas ceiling`);\n const t = tonBody.jettonTransfer;\n if (!t) refuse(\"a jetton-source body must be a jetton transfer\");\n if (t!.amount !== input) refuse(`the jetton transfer moves ${t!.amount}, not the swap's ${input}`);\n if (!t!.responseDestination || t!.responseDestination !== tonRawAddress(selfAddress)) refuse(\"the jetton transfer returns its excess to another wallet\");\n if (t!.forwardTon >= executionValue) refuse(\"the jetton transfer forwards more TON than the message carries\");\n const own = typeof signer.getJettonWalletAddress === \"function\" ? tonRawAddress(await signer.getJettonWalletAddress(source.contract)) : null;\n if (!own) refuse(\"the account cannot name its own jetton wallet (getJettonWalletAddress), so the target cannot be checked\");\n if (tonRawAddress(unsigned.to) !== own) refuse(`it is sent to ${unsigned.to}, not this account's ${source.symbol ?? \"source\"} jetton wallet`);\n } else {\n if (executionValue < input || executionValue - input > ceiling) refuse(`it attaches ${executionValue} nanoTON for a ${input} input, more than the ${ceiling} gas ceiling on top`);\n // A remote native-source body goes to a contract the app pinned, when it pins any (DEX pools are too many to\n // pin: then the app's verifyBuild, required above, checks the target).\n const pinned = provider.remote === true ? [...(provider.callTargets?.(this.fromChain) ?? []), ...(q.depositAddress ? [q.depositAddress] : [])].map(tonRawAddress).filter((a): a is string => !!a) : [];\n if (pinned.length && !pinned.includes(tonRawAddress(unsigned.to) ?? \"\")) refuse(`remote provider '${q.provider}' sends it to ${unsigned.to}, which the app did not pin (remoteProvider callTargets)`);\n }\n }\n\n // The engine binds the build to the quote; also bind what the quote's own calldata hands out\n // (scan 2026-10-27 modules, F8/F9/F16). A token call may only move the SOURCE token, at most the\n // swap amount, to this account, the deposit address of a deposit-address route, or a declared\n // spender; operator and Permit2 approvals are never a swap's main call. For a remote provider the\n // addresses come only from the app's pins (`callTargets` / `spenders`): the backend that wrote\n // `to`, `approvalAddress` and `depositAddress` is not the authority over them. Aggregator calldata\n // (a LI.FI diamond, a THORChain router) is not decoded here — its target is pinned, and the\n // provider's own checks and the review screen cover what it does.\n const remote = provider.remote === true;\n const pins = (list: readonly string[] | undefined) => (list ?? []).filter((a) => typeof a === \"string\" && /^0x[0-9a-fA-F]{40}$/.test(a)).map((a) => a.toLowerCase());\n const pinnedTargets = remote ? pins(provider.callTargets?.(this.fromChain)) : [];\n const pinnedSpenders = remote ? pins(provider.spenders?.(this.fromChain)) : [];\n if (remote && unsigned.approvalAddress && !pinnedSpenders.includes(unsigned.approvalAddress.toLowerCase())) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' asks to approve ${unsigned.approvalAddress} on ${this.fromChain}, which the app did not pin as a spender (remoteProvider spenders) — refused`);\n }\n if (unsigned.typedData !== undefined) {\n // The engine binds the domain, the maker and the input; the price, the receiver, the traits and the extension\n // are the provider's to check. A remote stub's order is signed only after the app's own validator ran on it\n // (`remoteProvider` `verifyBuild`, e.g. `omnistonVerifyBuild`), as for cell bodies (scan 2026-10-28, F6).\n if (remote && provider.verifiesBuilds !== true) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' asks to sign a typed order, which needs the app's own validator (remoteProvider verifyBuild) — refused`);\n }\n const chainId = this.fromChain.startsWith(\"eip155:\") ? Number(this.fromChain.slice(\"eip155:\".length)) : null;\n assertTypedOrder(unsigned.typedData, unsigned.approvalAddress, {self: selfAddress, token: source.contract ?? undefined, amount: q.sourceAmount, chainId});\n }\n if (unsigned.data !== undefined && this.fromChain.startsWith(\"eip155:\")) {\n const call = decodeCall({to: unsigned.to, data: unsigned.data, value: executionValue});\n // Calldata that is not hex bytes cannot be judged: refused, not passed as a plain call (scan 2026-10-27 modules F3).\n if (call.undecodable) throw new Swap2ValidationError(\"swap2: quote calldata is not hex bytes — refused\");\n if (call.approval && call.approval.kind !== \"erc20\") {\n throw new Swap2ValidationError(`swap2: quote calldata is ${call.approval.kind === \"operator\" ? \"an operator approval (setApprovalForAll)\" : \"a Permit2 approval\"} — never a swap's main call; refused`);\n }\n if (call.transfer || call.approval) {\n // A token call: the token is the call's target.\n if (!source.contract || unsigned.to.toLowerCase() !== source.contract.toLowerCase()) {\n throw new Swap2ValidationError(`swap2: quote calldata (${call.method}) moves ${getAddress(unsigned.to)}, not the source token — refused`);\n }\n if (call.method === \"transferFrom\") throw new Swap2ValidationError(\"swap2: quote calldata pulls the source token with transferFrom — refused\");\n const amount = call.transfer?.amount ?? call.approval?.amount ?? null;\n if (amount === null || amount > BigInt(q.sourceAmount)) {\n throw new Swap2ValidationError(`swap2: quote calldata (${call.method}) covers ${amount === null ? \"an unlimited amount\" : amount} of the source token, more than the swap's ${q.sourceAmount} — refused`);\n }\n const named = (call.transfer?.to ?? call.approval!.spender).toLowerCase();\n const allowed = engineTransfer\n ? [q.depositAddress]\n : remote\n ? [selfAddress, ...pinnedTargets, ...pinnedSpenders]\n : [selfAddress, q.depositAddress, unsigned.approvalAddress];\n if (!allowed.filter((a): a is string => !!a).map((a) => a.toLowerCase()).includes(named)) {\n throw new Swap2ValidationError(`swap2: quote calldata (${call.method}) names ${getAddress(named)}, which is not this account, the deposit address or ${remote ? \"a spender the app pinned\" : \"the declared spender\"} — refused`);\n }\n } else if (remote && !pinnedTargets.includes(unsigned.to.toLowerCase())) {\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' calls ${getAddress(unsigned.to)} on ${this.fromChain}, which the app did not pin as a call target (remoteProvider callTargets) — refused`);\n } else if (remote && provider.verifiesQuotes !== true && provider.verifiesBuilds !== true) {\n // A pinned contract executes whatever its arguments say — recipient, domain, minimum (scan 2026-10-30, F3): the\n // app's own decode of the call (the provider's `verifyQuote`, or `verifyBuild`) must have run on it.\n throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' calls ${getAddress(unsigned.to)} with calldata the app does not check (remoteProvider verifyQuote / verifyBuild) — refused`);\n }\n }\n\n // ERC-20 calldata/typed-order routes need an exact allowance. Decide the\n // approvals now (the reviewer sees exactly what will be sent) but send\n // them only after every local payload/value check, so a malformed build\n // cannot leave an allowance behind before failing validation.\n const needsApproval = !!unsigned.approvalAddress && !!source.contract;\n const approvalAmount = needsApproval ? BigInt(executionOptions.fromTokenAmount!) : 0n;\n const sameHex = (a: string, b: string) => a.toLowerCase() === b.toLowerCase();\n let approvalAmounts: bigint[] = [];\n let revokeApproval: (() => Promise<void>) | undefined;\n if (carried && !needsApproval) {\n // The fresh quote no longer spends through an allowance: the one the\n // first pass mined would outlive this swap with nobody to revoke it.\n carried.adopted = true;\n await carried.revoke().catch(() => {});\n throw new Swap2QuoteError(\"swap2: the fresh quote no longer spends through an allowance — aborted, the allowance was revoked\");\n }\n if (needsApproval && carried) {\n // Re-quote pass: the allowance must fit the fresh quote exactly;\n // otherwise it is revoked and the swap aborts (the caller may retry).\n if (!sameHex(carried.token, source.contract!) || !sameHex(carried.spender, unsigned.approvalAddress!) || carried.amount !== approvalAmount) {\n carried.adopted = true;\n await carried.revoke().catch(() => {});\n throw new Swap2QuoteError(`swap2: the fresh quote moved the spender to ${unsigned.approvalAddress} — aborted, the allowance for ${carried.spender} was revoked`);\n }\n carried.adopted = true;\n revokeApproval = carried.revoke;\n } else if (needsApproval) {\n // Mainnet USDT refuses non-zero → non-zero; every other token\n // overwrites. The live allowance decides what is actually needed: the\n // reset only when USDT holds a non-zero value, nothing at all when the\n // exact amount is already in place (an allowance this engine did not\n // create is left alone on failure). A failed read assumes the worst.\n const usdtMainnet = this.fromChain === \"eip155:1\" && source.symbol.toUpperCase() === \"USDT\";\n let current: bigint | undefined;\n if (typeof signer.getAllowance === \"function\") {\n try {\n current = BigInt(await signer.getAllowance(source.contract!, unsigned.approvalAddress!));\n } catch {\n current = undefined;\n }\n }\n approvalAmounts = current === approvalAmount ? [] : [...(usdtMainnet && current !== 0n ? [0n] : []), approvalAmount];\n }\n\n // The re-quote pass is reviewed again only when it differs from what the\n // reviewer approved: source amount, spender and the caller's floor are\n // pinned by construction, but the payload (calldata, deposit, memo, gas)\n // and the output come fresh from the provider.\n const review = (this._config as Swap2EngineConfig).reviewExecution;\n let reviewed: Swap2ExecutionPlan | undefined;\n if (review && (!carried || carried.reviewed)) {\n const chainId = unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {};\n const approvals: Swap2ExecutionPlan[\"approvals\"] = approvalAmounts.map((amount) =>\n ({token: source.contract!, spender: unsigned.approvalAddress!, amount, ...chainId}));\n const plan: Swap2ExecutionPlan = {\n provider: q.provider,\n fromChain: this.fromChain,\n destChain: params.destChain,\n destToken: params.destToken,\n recipient,\n refundAddress,\n sourceAmount: BigInt(q.sourceAmount),\n destAmount: BigInt(q.destAmount),\n minDestAmount: BigInt(q.minDestAmount),\n feeUsd: q.feeUsd,\n etaSeconds: q.etaSeconds,\n validUntilMs: q.validUntilMs,\n approvals,\n source: serialized\n ? {kind: \"serialized\", serializedTx: unsigned.serializedTx!}\n : unsigned.typedData\n ? {kind: \"typed-order\", typedData: unsigned.typedData}\n : tokenId\n ? {kind: \"token-transfer\", token: tokenId, recipient: unsigned.to, amount: BigInt(q.sourceAmount), ...(unsigned.memo ? {memo: unsigned.memo, ...(unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : {})}\n : {\n kind: \"call\",\n to: unsigned.to,\n ...(unsigned.data ? {data: unsigned.data} : {}),\n value: BigInt(unsigned.value),\n ...(unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {}),\n ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {}),\n ...(unsigned.memo ? {memo: unsigned.memo, ...(unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : {}),\n ...(cellBody !== undefined ? {cellBody: true, ...(tonBody ? {cellBodyDecoded: tonBody} : {})} : {}),\n },\n };\n const previous = carried?.reviewed;\n if (!previous || reviewedIdentity(previous) !== reviewedIdentity(plan) || plan.destAmount < previous.destAmount) {\n try {\n // A frozen deep copy: nothing the reviewer does reaches the payload sent below.\n reviewed = deepFreeze(structuredCloneSafe(previous ? {...plan, requoted: true as const} : plan));\n await review(reviewed);\n if (q.validUntilMs > 0 && q.validUntilMs <= Date.now()) {\n throw new Swap2QuoteError(`swap2: quote expired during review — ${previous ? \"the allowance was revoked\" : \"nothing was signed\"}`);\n }\n } catch (error) {\n // Second review: the allowance is ours and already adopted by this pass.\n if (previous) await revokeApproval?.().catch(() => {});\n throw error;\n }\n }\n }\n\n try {\n await this.assertNativeGas(signer, unsigned, approvalAmounts, source.contract ?? undefined, !!unsigned.typedData || serialized || !!tokenId);\n } catch (error) {\n // Re-quote pass: the allowance is adopted here, nobody else revokes it.\n if (carried) await revokeApproval?.().catch(() => {});\n throw error;\n }\n\n if (approvalAmounts.length) {\n const approve = async (amount: bigint) => {\n const sent = await signer.sendTransaction({\n to: source.contract!,\n data: approveData(unsigned.approvalAddress!, amount),\n value: 0n,\n ...(unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {}),\n });\n // The next step (a second approve, or the deposit's gas estimate)\n // reads on-chain allowance: it must see this approval mined.\n if (sent.hash && typeof signer.waitForTransaction === \"function\") await signer.waitForTransaction(sent.hash);\n return sent;\n };\n // Install cleanup BEFORE broadcasting approval. An RPC can lose the\n // response after the transaction was accepted; treating that exception\n // as \"nothing happened\" would leave a live allowance with no callback.\n revokeApproval = async () => { await approve(0n); };\n try {\n for (const [i, amount] of approvalAmounts.entries()) {\n this.emitPhase(\"approving\", {index: i + 1, total: approvalAmounts.length});\n await approve(amount);\n }\n } catch (error) {\n await revokeApproval().catch(() => {});\n throw error;\n }\n }\n\n // The quote/build step can be separated from the actual send by an ERC-20\n // approval. Recheck rotating/halt-sensitive provider state only now.\n if (q.validUntilMs > 0 && q.validUntilMs <= Date.now()) {\n // The mined approvals outlived the quote (mainnet USDT: 50–108 s of\n // approvals against a 55 s LI.FI / 45 s Omniston TTL, SDK-128). The\n // allowance is exact and ours: quote once more and spend it, instead of\n // revoking it (a third tx) and making the caller pay for the approvals\n // again. The second pass is bound to the same spender and amount, held\n // to the caller's floor like the first, and never re-quotes itself.\n if (!carried && approvalAmounts.length && revokeApproval) {\n this.emitPhase(\"requoting\");\n const handoff: CarriedAllowance = {token: source.contract!, spender: unsigned.approvalAddress!, amount: approvalAmount, revoke: revokeApproval, adopted: false, ...(reviewed ? {reviewed} : {})};\n try {\n return await this.executeSwap2(signer, snapshot, config, handoff);\n } catch (error) {\n if (!handoff.adopted) await revokeApproval().catch(() => {});\n throw error;\n }\n }\n await revokeApproval?.().catch(() => {});\n throw new Swap2QuoteError(\"swap2: quote expired before source broadcast\");\n }\n try {\n let providerStillEnabled = false;\n try { providerStillEnabled = provider.enabled(); } catch { /* fail closed below */ }\n if (!providerStillEnabled) throw new Error(`swap2: provider '${q.provider}' was disabled before source broadcast`);\n if (provider.preflightDeposit) this.emitPhase(\"preflight\");\n await provider.preflightDeposit?.(q, unsigned);\n } catch (error) {\n await revokeApproval?.().catch(() => {});\n throw error;\n }\n\n // GASLESS typed-order execution (Omniston EVM-source): sign the EIP-712\n // payload and register it with the provider — there is no source tx.\n if (unsigned.typedData) {\n try {\n if (!signer.signTypedData) {\n throw new Error(\"swap2: typed-order execution needs an account with signTypedData\");\n }\n if (!provider.registerSignedOrder) {\n throw new Error(`swap2: provider '${q.provider}' cannot register signed orders`);\n }\n const td = JSON.parse(unsigned.typedData) as {\n domain: unknown;\n types: Record<string, unknown>;\n primaryType?: string;\n message: unknown;\n };\n if (!td || typeof td !== \"object\" || !td.domain || !td.types || typeof td.types !== \"object\" || !td.message) {\n throw new Error(\"swap2: provider returned malformed typed data\");\n }\n // ethers and the account infer the domain type and reject an explicit\n // EIP712Domain entry as an ambiguous primary type.\n const {EIP712Domain: _domain, ...types} = td.types;\n // Providers may send the domain chainId as a hex string (\"0x89\");\n // signers that build the EIP712Domain type from value types (viem)\n // would then drop chainId from the domain and produce a signature the\n // verifying contract rejects (Omniston order, 2026-10-16). Sign with a number.\n const signature = await signer.signTypedData({\n domain: normalizeTypedDomain(td.domain),\n types,\n ...(td.primaryType ? {primaryType: td.primaryType} : {}),\n message: td.message,\n });\n await provider.registerSignedOrder(q.intentId, signature);\n return {\n id: encodeId(q.provider, q.intentId),\n fees: this.toQuote(q, executionOptions).fees,\n fromTokenAmount: BigInt(q.sourceAmount),\n toTokenAmount: BigInt(q.destAmount),\n toTokenAmountMin: BigInt(q.minDestAmount),\n };\n } catch (error) {\n // Any failed validation/sign/registration must not leave a reusable\n // exact allowance behind. If the RPC response was lost after\n // registration, revocation safely prevents execution.\n await revokeApproval?.().catch(() => {});\n throw error;\n }\n }\n\n // Execute the source leg through the bound account. Non-EVM token deposits\n // MUST use the account's transfer({token,recipient,amount}); passing token metadata\n // to sendTransaction would be ignored and send native SOL/TON/TRX instead.\n let sent: {hash?: string};\n this.emitPhase(\"signing\");\n try {\n if (serialized) {\n const allowanceRaw = (this._config as Swap2EngineConfig).serializedNativeAllowance;\n const allowance = allowanceRaw === undefined ? DEFAULT_SERIALIZED_NATIVE_ALLOWANCE : BigInt(allowanceRaw);\n if (allowance < 0n) throw new Swap2ConfigurationError(\"swap2: serializedNativeAllowance must be non-negative\");\n const expect: SerializedExecutionExpectation = {\n maxValueOut: ((source.contract ? 0n : BigInt(q.sourceAmount)) + allowance).toString(),\n // Only a same-chain swap lands in this account; a bridge delivers elsewhere.\n ...(params.destChain === this.fromChain ? {tokenIn: {token: params.destToken, minAmount: q.minDestAmount}} : {}),\n ...(source.contract ? {source: {token: source.contract, maxAmount: q.sourceAmount}} : {}),\n ...(params.destChain !== this.fromChain ? {bridgeOut: bridgeOutOf(params, q, executionOptions.toTokenDecimals)} : {}),\n };\n sent = await signer.sendSerializedTransaction!(unsigned.serializedTx!, expect);\n } else if (tokenId) {\n if (typeof signer.transfer !== \"function\") {\n throw new Swap2ExecutionError(\n `swap2: ${this.fromChain} token execution requires account.transfer({token, recipient, amount})`,\n );\n }\n sent = await signer.transfer({\n token: tokenId,\n recipient: unsigned.to,\n amount: BigInt(q.sourceAmount),\n ...((tronSource || nearSource || tonSource) && unsigned.memo ? {memo: unsigned.memo, ...(tronSource && unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : {}),\n });\n } else {\n sent = await signer.sendTransaction({\n to: unsigned.to,\n ...(unsigned.data ? {data: unsigned.data} : {}),\n value: BigInt(unsigned.value),\n ...(unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {}),\n ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {}),\n ...(cellBody !== undefined\n ? {body: cellBody}\n : unsigned.memo\n ? (tronSource ? {memo: unsigned.memo, ...(unsigned.memoEncoding ? {memoEncoding: unsigned.memoEncoding} : {})} : nearSource ? {memo: unsigned.memo} : {body: unsigned.memo})\n : {}),\n });\n }\n if (!sent.hash) throw new Swap2ExecutionError(\"swap2: account did not return a source transaction hash\");\n this.emitPhase(\"broadcast\", {hash: sent.hash});\n } catch (error) {\n // The deposit may be in the mempool: revoking would race it, and a\n // \"clean\" error invites a retry that sends a second deposit.\n const unknown = maybeSent(error);\n if (unknown) {\n throw new Swap2MaybeSentError(\n `swap2: the source transaction may have been broadcast (${error instanceof Error ? error.message.slice(0, 160) : String(error).slice(0, 160)}) — do not retry; ${unknown.hash ? `poll the status of ${unknown.hash}` : \"check the account's recent transactions\"}`,\n unknown.hash,\n unknown.hash ? encodeId(q.provider, q.intentId, unknown.hash) : undefined,\n {cause: error},\n );\n }\n await revokeApproval?.().catch(() => {});\n throw error;\n }\n\n if (provider.notifyDeposit) {\n await provider.notifyDeposit(q.intentId, sent.hash).catch(() => {});\n }\n\n const fees = this.toQuote(q, executionOptions).fees;\n return {\n id: encodeId(q.provider, q.intentId, sent.hash),\n fees,\n fromTokenAmount: BigInt(q.sourceAmount),\n toTokenAmount: BigInt(q.destAmount),\n toTokenAmountMin: BigInt(q.minDestAmount),\n ...(sent.hash ? {hash: sent.hash, transactions: [{hash: sent.hash, type: \"source\"}]} : {}),\n };\n }\n\n /**\n * EVM: refuse before the first approval when the native balance cannot pay\n * every approval, the main call and its value. Fees are the account's own\n * upper bound (`quoteSendTransaction`: gas × max fee). The main call's gas\n * comes from the quote's gas limit; without one it is estimated, which a\n * not-yet-approved call cannot do — then only approvals + value count.\n * Accounts without `getBalance`/`quoteSendTransaction` (and non-EVM chains,\n * whose accounts check their own fee at send) are not checked here.\n */\n private async assertNativeGas(signer: Swap2Signer, unsigned: UnsignedTx, approvalAmounts: bigint[], token: string | undefined, noMainCall: boolean): Promise<void> {\n if (!this.fromChain.startsWith(\"eip155:\") || typeof signer.getBalance !== \"function\" || typeof signer.quoteSendTransaction !== \"function\") return;\n const chainId = unsigned.chainId !== undefined ? {chainId: unsigned.chainId} : {};\n const fees = await Promise.all(approvalAmounts.map(async (amount) =>\n (await signer.quoteSendTransaction!({to: token!, data: approveData(unsigned.approvalAddress!, amount), value: 0n, ...chainId})).fee));\n const value = noMainCall ? 0n : BigInt(unsigned.value);\n if (!noMainCall) {\n const main = {to: unsigned.to, ...(unsigned.data ? {data: unsigned.data} : {}), value, ...chainId, ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {})};\n fees.push(await signer.quoteSendTransaction(main).then((r) => r.fee, (error) => {\n if (approvalAmounts.length) return 0n; // estimation needs the allowance the approval creates\n throw error;\n }));\n }\n const need = fees.reduce((a, b) => a + b, 0n) + value;\n const balance = BigInt(await signer.getBalance());\n if (balance < need) {\n throw new Swap2InsufficientGasError(`swap2: native balance ${balance} cannot pay this swap's gas: need ${need} (${fees.length} transaction${fees.length === 1 ? \"\" : \"s\"}${value ? ` + value ${value}` : \"\"}) — nothing was signed`);\n }\n }\n\n /** Status of a swap by the id `swap2()` returned, asked from the provider that executed it. */\n override async getSwap2Status(id: string, _options?: Swap2StatusOptions): Promise<Swap2StatusResult> {\n const {provider: name, intentId, sourceTxHash, destTxHash, destTxConfirmed} = decodeId(id);\n const provider = this.providerFor(name);\n if (!provider) throw new Error(`swap2: no swap2 found for id '${id}'`);\n return mapStatus(await provider.trackIntent({intentId, ...(sourceTxHash != null ? {sourceTxHash} : {}), ...(destTxHash != null ? {destTxHash, ...(destTxConfirmed ? {destTxConfirmed} : {})} : {})}));\n }\n\n /**\n * Two-phase routes (CCTP-style burn-and-mint): once `getSwap2Status` reports\n * \"action-required\", the delivery needs a second transaction on the\n * DESTINATION chain, signed there and paid in that chain's gas. `account` is\n * the destination-chain account (the bound source account is not reused:\n * the chains differ). The provider builds the claim from the attestation; it\n * is refused when not ready, when it names another chain than the account,\n * or when it is anything but plain EVM calldata. Returns the claim hash and\n * the status id to keep polling with.\n */\n async claimSwap2(id: string, account: Swap2Account): Promise<{hash: string; chain: string; id: string}> {\n const {provider: name, intentId, sourceTxHash} = decodeId(id);\n const provider = this.providerFor(name);\n if (!provider) throw new Error(`swap2: no swap2 found for id '${id}'`);\n if (typeof provider.buildClaim !== \"function\") {\n throw new Swap2UnsupportedOperationError(`swap2: provider '${name}' has no claim step`);\n }\n const signerCandidate = account as Partial<Swap2Signer> | undefined;\n if (!signerCandidate || typeof signerCandidate.sendTransaction !== \"function\") {\n throw new Swap2ExecutionError(\"swap2: claimSwap2() requires a signing account on the destination chain\");\n }\n const signer = signerCandidate as Swap2Signer;\n let providerEnabled = false;\n try { providerEnabled = provider.enabled(); } catch { /* fail closed below */ }\n if (!providerEnabled) throw new Error(`swap2: provider '${name}' is disabled`);\n const unsigned = await provider.buildClaim(sourceTxHash == null ? {intentId} : {intentId, sourceTxHash});\n if (!unsigned) throw new Swap2StatusError(\"swap2: the claim is not ready yet (attestation pending) — poll the status and retry\");\n if (!unsigned.chain || !unsigned.chain.startsWith(\"eip155:\")) {\n throw new Swap2UnsupportedOperationError(`swap2: claim execution is only implemented for EVM destinations (got '${unsigned.chain || \"?\"}')`);\n }\n if (!unsigned.to || !unsigned.data || !/^0x(?:[0-9a-fA-F]{2})+$/.test(unsigned.data)) {\n throw new Error(\"swap2: provider returned a malformed claim transaction\");\n }\n if (unsigned.serializedTx !== undefined || unsigned.bodyBoc !== undefined || unsigned.typedData !== undefined || unsigned.memo !== undefined || unsigned.approvalAddress !== undefined) {\n throw new Error(\"swap2: claim must be plain calldata\");\n }\n if (unsigned.value !== undefined && unsigned.value !== \"0\") throw new Error(\"swap2: a claim must not carry native value\");\n const expectedId = unsigned.chain.slice(\"eip155:\".length);\n if (unsigned.chainId !== undefined && String(unsigned.chainId) !== expectedId) {\n throw new Error(`swap2: claim chainId ${unsigned.chainId} does not match ${unsigned.chain}`);\n }\n // Only a contract the provider declares for this chain, and nothing that moves this account's\n // tokens or grants an allowance (the source leg's decodeCall refusals) — round 3, M24.\n if (typeof provider.claimTargets !== \"function\") {\n throw new Swap2UnsupportedOperationError(`swap2: provider '${name}' declares no claimTargets — a claim may only call contracts the provider names for its chain`);\n }\n const targets = provider.claimTargets(unsigned.chain).map((a) => a.toLowerCase());\n if (!targets.includes(unsigned.to.toLowerCase())) {\n throw new Swap2ValidationError(`swap2: claim target ${unsigned.to} is not a contract '${name}' declares for ${unsigned.chain} — refused`);\n }\n const claimCall = decodeCall({to: unsigned.to, data: unsigned.data, value: 0n});\n if (claimCall.undecodable) throw new Swap2ValidationError(\"swap2: claim calldata is not hex bytes — refused\");\n if (claimCall.transfer || claimCall.approval) {\n throw new Swap2ValidationError(`swap2: claim calldata (${claimCall.method}) moves tokens or grants an allowance — refused`);\n }\n const actual = await readAccountChain(signer);\n if (actual == null) throw new Error(`swap2: destination account chain identity is unavailable for ${unsigned.chain}`);\n const actualText = typeof actual === \"string\" ? actual : String(actual);\n const actualId = actualText.startsWith(\"eip155:\") ? actualText.slice(\"eip155:\".length) : actualText;\n if (actualId !== expectedId) throw new Error(`swap2: claim is on ${unsigned.chain}, but the account is bound to ${actualText}`);\n this.emitPhase(\"signing\");\n const sent = await signer.sendTransaction({\n to: unsigned.to,\n data: unsigned.data,\n value: 0n,\n chainId: Number(expectedId),\n ...(unsigned.gasLimit ? {gasLimit: BigInt(unsigned.gasLimit)} : {}),\n });\n if (!sent.hash) throw new Swap2ExecutionError(\"swap2: account did not return a claim transaction hash\");\n this.emitPhase(\"broadcast\", {hash: sent.hash});\n // A claim the account saw included and succeed is marked confirmed in the id: a provider that cannot read the\n // destination may take that as the delivery. A claim the account saw revert gets no id with its hash. Any other\n // wait failure (a timeout, the RPC), or an account without the wait, proves nothing: the hash is kept unmarked\n // and the provider's status decides.\n let confirmed = false;\n if (typeof signer.waitForTransaction === \"function\") {\n try {\n await signer.waitForTransaction(sent.hash);\n confirmed = true;\n } catch (e) {\n const err = e as {name?: unknown; message?: unknown; code?: unknown} | null;\n const timedOut = /timeout|timed out/i.test(String(err?.name ?? \"\")) || /timed out|timeout/i.test(String(err?.message ?? \"\"));\n const reverted = err?.code === \"reverted\" || (!timedOut && /\\breverted\\b/i.test(String(err?.message ?? \"\")));\n if (reverted) {\n throw new Swap2ExecutionError(`swap2: the claim transaction ${sent.hash} on ${unsigned.chain} reverted — poll the status of '${id}' and claim again if it is still action-required`, {cause: e});\n }\n }\n }\n // The id to keep polling names the claim (and that it succeeded), so the status can complete without a\n // destination RPC (round 3, M27).\n return {hash: sent.hash, chain: unsigned.chain, id: encodeId(name, intentId, sourceTxHash, sent.hash, confirmed)};\n }\n\n /** The inherited bridge() has no floor field: quote first, then bind execution\n * to that quote's minimum so the inherited convenience API stays safe. */\n override async bridge(options: BridgeOptions): Promise<BridgeResult> {\n const amount = exactPositiveAmount(options.amount, \"amount\");\n const swap2Options: Swap2Options = {\n fromToken: options.token,\n toToken: options.token,\n toChain: options.targetChain,\n recipient: options.recipient,\n fromTokenAmount: amount,\n };\n const quote = await this.quoteSwap2(swap2Options);\n const result = await this.swap2({...swap2Options, minAmountOut: quote.toTokenAmountMin});\n const fee = result.fees.filter((f) => f.type === \"network\").reduce((sum, f) => sum + f.amount, 0n);\n const bridgeFee = result.fees.filter((f) => f.type === \"protocol\").reduce((sum, f) => sum + f.amount, 0n);\n return {hash: result.id, fee, bridgeFee};\n }\n\n /** Same protection for legacy exact-in swap() calls whose min is optional. */\n override async swap(options: SwapOptions): Promise<SwapResult> {\n if (options.tokenInAmount === undefined) {\n throw new Swap2UnsupportedOperationError(\"swap2: exact-out swap is not supported by the engine\");\n }\n const amount = exactPositiveAmount(options.tokenInAmount, \"tokenInAmount\");\n const swap2Options: Swap2Options = {\n fromToken: options.tokenIn,\n toToken: options.tokenOut,\n fromTokenAmount: amount,\n // `to` is optional on the legacy API: omit the key rather than passing\n // undefined, so swap2() falls back to the bound account's own address.\n ...(options.to !== undefined ? {recipient: options.to} : {}),\n ...(options.minAmountOut !== undefined ? {minAmountOut: options.minAmountOut} : {}),\n };\n const floor = options.minAmountOut ?? (await this.quoteSwap2(swap2Options)).toTokenAmountMin;\n const result = await this.swap2({...swap2Options, minAmountOut: floor});\n const fee = result.fees.reduce((sum, item) => sum + item.amount, 0n);\n return {hash: result.id, fee, tokenInAmount: result.fromTokenAmount, tokenOutAmount: result.toTokenAmount};\n }\n\n /** Source chains this protocol can swap from. */\n override async getSupportedChains(): Promise<Swap2SupportedChain[]> {\n if (!this.protocolEnabled()) return [];\n return CC_SOURCE_CHAINS.filter((c: CcChain) => this.chainSupported(c.caip2)).map((c) => ({\n id: c.caip2,\n name: c.label,\n type: chainType(c.caip2),\n nativeToken: c.assets[0]?.symbol ?? \"\",\n }));\n }\n\n /** Tokens of the asset catalog on the supported chains, optionally narrowed. */\n override async getSupportedTokens(options?: Swap2SupportedTokensOptions): Promise<Swap2SupportedToken[]> {\n const wantFrom = options?.fromChain != null ? toCaip2(options.fromChain, \"\") : undefined;\n const wantTo = options?.toChain != null ? toCaip2(options.toChain, \"\") : undefined;\n if (!this.protocolEnabled() || (wantFrom && wantTo && !this.pairSupported(wantFrom, wantTo))) return [];\n const out: Swap2SupportedToken[] = [];\n for (const c of CC_SOURCE_CHAINS) {\n if (!this.chainSupported(c.caip2)) continue;\n if ((wantFrom || wantTo) && c.caip2 !== wantFrom && c.caip2 !== wantTo) continue;\n for (const a of c.assets) {\n out.push({\n // What quoteSwap2 takes back: the contract, or the symbol of the native coin — never the\n // provider-specific assetId, which is \"\" for most catalog entries (round 3, M25).\n token: a.contract ?? a.symbol,\n chain: c.caip2,\n symbol: a.symbol,\n decimals: a.decimals,\n ...(a.contract ? {address: a.contract} : {}),\n });\n }\n }\n return out;\n }\n}\n\nfunction structuredCloneSafe<T>(value: T): T {\n if (value === null || typeof value !== \"object\") return value;\n if (Array.isArray(value)) return value.map((v) => structuredCloneSafe(v)) as T;\n const out: Record<string, unknown> = {};\n // An own \"__proto__\" key assigned would set the copy's prototype: define it as a plain key.\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (k === \"__proto__\") Object.defineProperty(out, k, {value: structuredCloneSafe(v), writable: true, enumerable: true, configurable: true});\n else out[k] = structuredCloneSafe(v);\n }\n return out as T;\n}\n\nfunction deepFreeze<T>(value: T): T {\n if (value && typeof value === \"object\") {\n for (const v of Object.values(value as Record<string, unknown>)) deepFreeze(v);\n Object.freeze(value);\n }\n return value;\n}\n","import {resolveAsset, type CcAsset} from \"@anywalletkit/swap2-assets\";\nimport type {QuoteParams} from \"./types.js\";\n/** Shared CAIP-2 helpers. Contribution packages never read deployment env. */\nexport function namespace(chain: string): string {\n return chain.split(\":\")[0] ?? \"\";\n}\n/** True for an `eip155:` chain id. */\nexport function isEvm(chain: string): boolean {\n return namespace(chain) === \"eip155\";\n}\n/** Numeric chain id of an `eip155:<id>` CAIP-2 id. */\nexport function evmRef(chain: string): number {\n return Number(chain.split(\":\")[1] ?? \"0\");\n}\n\n/**\n * `AbortSignal.timeout`, portably: Hermes (React Native) ships AbortController\n * but not the static helpers, and the unguarded call threw\n * \"AbortSignal.timeout is not a function\" on every remote execution — which\n * the auction then read as \"no route\". Falls back to a manual controller.\n */\nexport function timeoutSignal(ms: number): AbortSignal {\n const native = (AbortSignal as unknown as {timeout?: (ms: number) => AbortSignal}).timeout;\n if (typeof native === \"function\") return native.call(AbortSignal, ms);\n const ctrl = new AbortController();\n setTimeout(() => ctrl.abort(), ms);\n return ctrl.signal;\n}\n\n/** `AbortSignal.any`, portably (see timeoutSignal). */\nexport function anySignal(signals: readonly AbortSignal[]): AbortSignal {\n const native = (AbortSignal as unknown as {any?: (s: readonly AbortSignal[]) => AbortSignal}).any;\n if (typeof native === \"function\") return native.call(AbortSignal, signals);\n const ctrl = new AbortController();\n for (const s of signals) {\n if (s.aborted) {\n ctrl.abort();\n break;\n }\n s.addEventListener(\"abort\", () => ctrl.abort(), {once: true});\n }\n return ctrl.signal;\n}\n\n/** Longest URL scheme taken out (`https`, `wss`, `git+ssh`…): a letter and up to 31 of `[A-Za-z0-9+.-]`. */\nconst SCHEME_MAX = 32;\nconst isLetter = (c: number): boolean => (c >= 97 && c <= 122) || (c >= 65 && c <= 90);\nconst isSchemeChar = (c: number): boolean => isLetter(c) || (c >= 48 && c <= 57) || c === 43 || c === 45 || c === 46;\n/** What ends a URL in text: `\\s` as regexes define it, and `\"` `'` `<` `>`. */\nconst endsUrl = (c: number): boolean =>\n c === 34 || c === 39 || c === 60 || c === 62 || (c >= 9 && c <= 13) || c === 32 || c === 0xa0 || c === 0x1680 ||\n (c >= 0x2000 && c <= 0x200a) || c === 0x2028 || c === 0x2029 || c === 0x202f || c === 0x205f || c === 0x3000 || c === 0xfeff;\n\n/**\n * Remove URLs from text that may travel to a client (a refusal reason, a build error):\n * transport errors carry the endpoint — and with a keyed RPC (QuickNode, Alchemy,\n * Infura…) the key sits in its path (scan 2026-10-23 F8). What `/[a-z][a-z0-9+.-]{0,31}:\\/\\/[^\\s\"'<>]+/gi`\n * would replace, found from each `://` instead of tried at every position: linear in the length of\n * `text` whatever an API or a client puts in it (\"a.a.a…\" made the regex this replaced quadratic;\n * scan 2026-10-27 modules, F34). A URL glued to a word loses its last 32 scheme characters and the rest.\n */\nexport function redactUrls(text: string): string {\n let out = \"\";\n let done = 0; // text[0, done) is in `out`\n for (let at = text.indexOf(\"://\"); at !== -1; at = text.indexOf(\"://\", at + 3)) {\n let start = at;\n while (start > done && at - start < SCHEME_MAX && isSchemeChar(text.charCodeAt(start - 1))) start--;\n while (start < at && !isLetter(text.charCodeAt(start))) start++;\n if (start === at) continue; // no scheme: not a URL (and its tail is not scanned, so \"://://…\" stays linear)\n let end = at + 3;\n while (end < text.length && !endsUrl(text.charCodeAt(end))) end++;\n if (end === at + 3) continue; // nothing after \"://\"\n out += `${text.slice(done, start)}<url>`;\n done = end;\n at = end - 3;\n }\n return done === 0 ? text : out + text.slice(done);\n}\n\n/**\n * The source asset a provider is asked to sell: the catalog's entry for `params.sourceToken`, or —\n * only when the engine sent `sourceDecimals` (an unlisted token the user added) — an unlisted asset\n * named by its contract / mint. Providers that can trade any token use this instead of the catalog\n * lookup; the others keep refusing what the catalog does not list.\n */\nexport function sourceAssetOf(params: Pick<QuoteParams, \"sourceChain\" | \"sourceToken\" | \"sourceDecimals\">): CcAsset | undefined {\n const decimals = params.sourceDecimals;\n return resolveAsset(params.sourceChain, params.sourceToken, decimals === undefined ? {} : {allowUnlisted: true, decimals});\n}\n\nconst B64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n/** Standard or URL-safe base64 → bytes, without Buffer or atob (Hermes); null for anything else. */\nexport function base64Bytes(text: string): Uint8Array | null {\n const s = text.replace(/-/g, \"+\").replace(/_/g, \"/\").replace(/=+$/, \"\");\n if (!/^[A-Za-z0-9+/]*$/.test(s) || s.length % 4 === 1) return null;\n const out = new Uint8Array(Math.floor((s.length * 3) / 4));\n let bits = 0, acc = 0, n = 0;\n for (const ch of s) {\n acc = (acc << 6) | B64.indexOf(ch);\n bits += 6;\n if (bits >= 8) { bits -= 8; out[n++] = (acc >> bits) & 0xff; }\n }\n return out.subarray(0, n);\n}\n\n/** CRC16-XMODEM, the checksum of a user-friendly TON address. */\nfunction crc16(bytes: Uint8Array): number {\n let crc = 0;\n for (const b of bytes) {\n crc ^= b << 8;\n for (let i = 0; i < 8; i++) crc = crc & 0x8000 ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;\n }\n return crc;\n}\n\n/**\n * A TON address in raw form (`<workchain>:<64 hex>`, lowercase) from a raw string, a user-friendly one (bounceable or\n * not, checksum verified), or an address object (`toRawString()` / `workChain` + `hash`); null for anything else. Two\n * spellings of one address compare equal in this form.\n */\nexport function tonRawAddress(address: unknown): string | null {\n if (address && typeof address === \"object\") {\n const o = address as {toRawString?: () => string; workChain?: unknown; hash?: unknown};\n if (typeof o.toRawString === \"function\") { try { return tonRawAddress(o.toRawString()); } catch { return null; } }\n if (typeof o.workChain === \"number\" && o.hash instanceof Uint8Array && o.hash.length === 32) {\n return `${o.workChain}:${Array.from(o.hash, (b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`;\n }\n return null;\n }\n if (typeof address !== \"string\") return null;\n const raw = /^(-?[0-9]{1,3}):([0-9a-fA-F]{64})$/.exec(address.trim());\n if (raw) return `${Number(raw[1])}:${raw[2]!.toLowerCase()}`;\n if (!/^[A-Za-z0-9+/_-]{48}$/.test(address.trim())) return null;\n const bytes = base64Bytes(address.trim());\n if (!bytes || bytes.length !== 36 || crc16(bytes.subarray(0, 34)) !== ((bytes[34]! << 8) | bytes[35]!)) return null;\n const wc = bytes[1] === 0xff ? -1 : bytes[1]!;\n return `${wc}:${Array.from(bytes.subarray(2, 34), (b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n","import type {CrossChainProvider, Quote, QuoteParams} from \"./types.js\";\n\n/**\n * How far past the requested slippage a quote's minimum may sit and still count as \"at\" it. Providers derive the\n * minimum with their own rounding: LI.FI's Mayan answers land a few base units under an exact floor on 18-decimal\n * outputs (50.0000000001 bps at a requested 50, live 2026-11-02), which refused half of them. A minimum that is more\n * than this past the request is still refused.\n */\nexport const SLIPPAGE_ROUNDING_BPS = 1;\n\n/** The lowest minimum a quote of `dest` may carry at `slippageBps`: floor(dest × (10 000 − slippageBps − {@link SLIPPAGE_ROUNDING_BPS}) / 10 000). */\nexport function slippageFloor(dest: bigint, slippageBps: number): bigint {\n const keep = 10_000 - slippageBps - SLIPPAGE_ROUNDING_BPS;\n return keep <= 0 ? 0n : (dest * BigInt(keep)) / 10_000n;\n}\n\n/** Shared quote validator used by both the aggregate and single-provider paths. */\nexport function validQuote(q: Quote, params: QuoteParams, provider: string): boolean {\n try {\n if (q.provider !== provider || q.sourceAmount !== params.amountIn) return false;\n if (typeof q.intentId !== \"string\" || !q.intentId || typeof q.depositAddress !== \"string\" || (q.depositMemo !== null && typeof q.depositMemo !== \"string\")) return false;\n if (![q.sourceAmount, q.destAmount, q.minDestAmount].every((value) => /^[0-9]+$/.test(value))) return false;\n const source = BigInt(q.sourceAmount);\n const dest = BigInt(q.destAmount);\n const min = BigInt(q.minDestAmount);\n if (source <= 0n || dest <= 0n || min <= 0n || min > dest) return false;\n if (params.minAmountOut !== undefined) {\n if (!/^[0-9]+$/.test(params.minAmountOut) || BigInt(params.minAmountOut) <= 0n || min < BigInt(params.minAmountOut)) return false;\n }\n if (params.slippageBps !== undefined) {\n if (!Number.isInteger(params.slippageBps) || params.slippageBps < 0 || params.slippageBps >= 10_000) return false;\n // Providers round the floor DOWN (1Click, LI.FI: floor(dest × (1 − s))), some through\n // floats. A ceil here refused nearly every slippage-bounded quote by one base unit.\n if (min < slippageFloor(dest, params.slippageBps)) return false;\n }\n if (!Number.isFinite(q.etaSeconds) || q.etaSeconds < 0) return false;\n if (!Number.isFinite(q.reliability) || q.reliability < 0 || q.reliability > 1) return false;\n if (!Number.isFinite(q.feeUsd) || q.feeUsd < 0) return false;\n if (q.fees && (!Array.isArray(q.fees) || !q.fees.every((fee) =>\n [\"network\", \"protocol\", \"affiliate\", \"other\"].includes(fee.type) &&\n /^[0-9]+$/.test(fee.amount) &&\n typeof fee.token === \"string\" && fee.token.length > 0 &&\n typeof fee.included === \"boolean\" &&\n (fee.description === undefined || typeof fee.description === \"string\")\n ))) return false;\n if (q.providerData && (Array.isArray(q.providerData) || typeof q.providerData !== \"object\" || !Object.values(q.providerData).every((value) => typeof value === \"string\"))) return false;\n const tx = q.txRequest;\n if (tx) {\n if (tx.value !== undefined && !/^[0-9]+$/.test(tx.value)) return false;\n if (tx.gasLimit !== undefined && !/^[0-9]+$/.test(tx.gasLimit)) return false;\n if (tx.chainId !== undefined && (!Number.isSafeInteger(tx.chainId) || tx.chainId <= 0)) return false;\n if ([tx.to, tx.data, tx.approvalAddress, tx.serializedTx].some((value) => value !== undefined && typeof value !== \"string\")) return false;\n }\n // Execution is always re-quoted. An unknown/zero expiry cannot prove that\n // the transaction is still safe to sign, so contribution packages reject it.\n if (!Number.isFinite(q.validUntilMs) || q.validUntilMs <= Date.now()) return false;\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Why a remote provider's quote cannot execute in this app, or null: its EVM transaction calls or\n * approves an address the app did not pin (`remoteProvider` `callTargets` / `spenders`), or it pays\n * an address the backend named — a deposit address or a plain value send — on a stub the app did not\n * open to such routes (`depositAddressRoutes`, scan 2026-10-28 F9), or it is EVM calldata on a stub without the\n * app's own check of what that calldata does (`verifyQuote` / `verifyBuild`, scan 2026-10-30 F3). The router and the\n * single-provider path drop such a quote with this reason, so the auction never picks a route\n * execution would refuse (scan 2026-10-27 modules, F8/F9/F16); execution checks the build again, in\n * full. Local providers are not judged here.\n */\nexport function remotePinRefusal(provider: Pick<CrossChainProvider, \"name\" | \"remote\" | \"callTargets\" | \"spenders\" | \"depositAddressRoutes\" | \"verifiesQuotes\" | \"verifiesBuilds\">, q: Quote, chain: string): string | null {\n if (provider.remote !== true) return null;\n const tx = q.txRequest;\n const plain = tx ? tx.data === undefined && tx.serializedTx === undefined : typeof q.depositAddress === \"string\" && q.depositAddress !== \"\";\n if (plain && provider.depositAddressRoutes !== true) {\n return `${provider.name}: the route pays ${tx?.to || q.depositAddress}, an address the backend named, and the app did not allow deposit-address routes for this provider (remoteProvider depositAddressRoutes)`;\n }\n if (!chain.startsWith(\"eip155:\")) return null;\n if (!tx || tx.serializedTx !== undefined) return null;\n const pinned = (list: readonly string[] | undefined, address: string) =>\n (list ?? []).some((a) => typeof a === \"string\" && a.toLowerCase() === address.toLowerCase());\n if (tx.approvalAddress && !pinned(provider.spenders?.(chain), tx.approvalAddress)) {\n return `${provider.name}: the route approves ${tx.approvalAddress}, which the app did not pin as a spender on ${chain} (remoteProvider spenders)`;\n }\n if (tx.data !== undefined && tx.to && !pinned(provider.callTargets?.(chain), tx.to)) {\n return `${provider.name}: the route calls ${tx.to}, which the app did not pin as a call target on ${chain} (remoteProvider callTargets)`;\n }\n if (tx.data !== undefined && provider.verifiesQuotes !== true && provider.verifiesBuilds !== true) {\n return `${provider.name}: the route's calldata is not checked by the app (remoteProvider verifyQuote / verifyBuild) — a pinned target alone does not say whom it pays`;\n }\n return null;\n}\n","/**\n * Which stage of a swap failed: configuration, input validation, quote, execution, an unsupported\n * operation, a fee ceiling, or status tracking.\n */\nexport type Swap2ErrorCode =\n | \"CONFIGURATION\"\n | \"VALIDATION\"\n | \"QUOTE\"\n | \"EXECUTION\"\n | \"UNSUPPORTED_OPERATION\"\n | \"FEE_LIMIT\"\n | \"STATUS\";\n\n/** Public, machine-readable error base shared by every contribution package. */\nexport class Swap2Error extends Error {\n constructor(message: string, readonly code: Swap2ErrorCode, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport class Swap2ConfigurationError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"CONFIGURATION\", options); }\n}\nexport class Swap2ValidationError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"VALIDATION\", options); }\n}\nexport class Swap2QuoteError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"QUOTE\", options); }\n}\nexport class Swap2ExecutionError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"EXECUTION\", options); }\n}\nexport class Swap2UnsupportedOperationError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"UNSUPPORTED_OPERATION\", options); }\n}\nexport class Swap2FeeLimitError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"FEE_LIMIT\", options); }\n}\nexport class Swap2StatusError extends Swap2Error {\n constructor(message: string, options?: ErrorOptions) { super(message, \"STATUS\", options); }\n}\n/** An identical swap2() is still running on this account (double tap): nothing was sent for this call. */\nexport class Swap2InFlightError extends Swap2ExecutionError {}\n/** The account cannot pay the source leg's gas (approvals + main call + value); nothing was signed. */\nexport class Swap2InsufficientGasError extends Swap2ExecutionError {}\n/**\n * The source broadcast failed AFTER the transaction may have reached the node\n * (lost response, timeout). Do NOT retry: poll `getSwap2Status(id)` / the\n * chain for `hash`. The approval is left in place (the deposit may spend it).\n */\nexport class Swap2MaybeSentError extends Swap2ExecutionError {\n constructor(message: string, readonly hash?: string, readonly id?: string, options?: ErrorOptions) { super(message, options); }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,kBAA4B;AAC5B,kBAA6C;AAC7C,4BAAyB;AAkBzB,IAAAA,uBASO;;;ACvCP,0BAAyC;AA0FzC,IAAM,MAAM;AAEL,SA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