@anywalletkit/protocol-swap2-fynd 0.2.8 → 0.2.10

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router.ts"],"sourcesContent":["/**\n * TychoRouterV3 — the only contract a Fynd quote may settle through (Fynd\n * License §3: every settlement of a Fynd output goes through the router in\n * Propeller Heads' registry). This file pins the router per chain and checks\n * Fynd's encoded transaction against the request before anything is approved\n * or sent: right contract, right method, the exact input, the requested\n * tokens, the user as receiver, the quoted output and minimum, and no client\n * fee. The route inside `swaps` is opaque and is not inspected here — the\n * router itself reverts below `minAmountOut`.\n */\nimport type {Quote, QuoteParams, RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {refusalNotes, refusalOf, withReason, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {decodeFunctionData, getAddress, parseAbi, toFunctionSelector, type Hex} from \"viem\";\n\n/** Router registry: github.com/propeller-heads/tycho crates/tycho-execution/config/deployment_registry.json (TychoRouterV3, effective 2026-09-01). */\nexport const FYND_CHAINS: Readonly<Record<number, {slug: string; name: string; router: `0x${string}`}>> = Object.freeze({\n 1: {slug: \"ethereum\", name: \"Ethereum\", router: \"0x1644D2477f809cc2C71bCCFd6Dc9497E3F83210d\"},\n 8453: {slug: \"base\", name: \"Base\", router: \"0xAbA5B53b03eAfaD1C5fc8BD5Fc765fC85Bb3de67\"},\n 42161: {slug: \"arbitrum\", name: \"Arbitrum\", router: \"0x924F147c50eA59f5180a26031A8b65B2aA1e81Cd\"},\n 56: {slug: \"bsc\", name: \"BNB Smart Chain\", router: \"0x7f3D12BBaFb8955E51B3ab9588b34c8ad95BDA4e\"},\n 137: {slug: \"polygon\", name: \"Polygon\", router: \"0xbd4e6011F03355C2A377Fd9Af939322A7d0A1bC1\"},\n 130: {slug: \"unichain\", name: \"Unichain\", router: \"0xCba5574597Ad00EA250Fd106DAB4Fc7461949635\"},\n 4663: {slug: \"robinhood\", name: \"Robinhood Chain\", router: \"0x09215a470bD585E59EB3F4B612fBD2678131fF9e\"},\n});\n\n/** The router's native-coin sentinel (lib/NativeETH.sol); Fynd's API uses the zero address instead. */\nexport const ROUTER_NATIVE = \"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE\";\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nconst PARAMS = \"uint256 amountIn, address tokenIn, address tokenOut, uint256 expectedAmountOut, uint256 minAmountOut\";\nconst FEE = \"(uint32 clientFeeBps, address clientFeeReceiver, uint256 maxClientContribution, uint256 deadline, bytes clientSignature) clientFeeParams\";\nconst PERMIT = \"((address token, uint160 amount, uint48 expiration, uint48 nonce) details, address spender, uint256 sigDeadline) permitSingle, bytes signature\";\n\n/** The three entry points a wallet swap uses (plain `transferFrom` from the user). */\nexport const TYCHO_ROUTER_ABI = parseAbi([\n `function singleSwap(${PARAMS}, address receiver, ${FEE}, bytes swapData) payable returns (uint256)`,\n `function sequentialSwap(${PARAMS}, address receiver, ${FEE}, bytes swaps) payable returns (uint256)`,\n `function splitSwap(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps) payable returns (uint256)`,\n]);\n\n/** Every swap entry point of the router (Permit2 and vault variants included) — for recognizing history. */\nexport const TYCHO_ROUTER_SELECTORS: ReadonlySet<string> = new Set(\n [\n `singleSwap(${PARAMS}, address receiver, ${FEE}, bytes swapData)`,\n `sequentialSwap(${PARAMS}, address receiver, ${FEE}, bytes swaps)`,\n `splitSwap(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps)`,\n `singleSwapUsingVault(${PARAMS}, address receiver, ${FEE}, bytes swapData)`,\n `sequentialSwapUsingVault(${PARAMS}, address receiver, ${FEE}, bytes swaps)`,\n `splitSwapUsingVault(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps)`,\n `singleSwapPermit2(${PARAMS}, address receiver, ${FEE}, ${PERMIT}, bytes swapData)`,\n `sequentialSwapPermit2(${PARAMS}, address receiver, ${FEE}, ${PERMIT}, bytes swaps)`,\n `splitSwapPermit2(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, ${PERMIT}, bytes swaps)`,\n ].map((sig) => toFunctionSelector(`function ${sig}`)),\n);\n\nexport class FyndTransactionError extends Error {\n constructor(message: string) {\n super(`fynd: ${message}`);\n this.name = \"FyndTransactionError\";\n }\n}\n/** A {@link FyndTransactionError} tagged with its refusal reason (class, name and text unchanged). */\nconst fail = (message: string, reason: Swap2RefusalReason): FyndTransactionError => withReason(new FyndTransactionError(message), reason);\n/** The reasons of the texts {@link fyndVerifyQuote} returned, for `fyndPins.reasonOf`. */\nconst notes = refusalNotes();\n\nexport interface ExpectedSwap {\n chainId: number;\n /** ERC-20 address, or the zero address for the native coin. */\n tokenIn: string;\n tokenOut: string;\n amountIn: bigint;\n receiver: string;\n /** Fynd's gross `amount_out` (before the router fee and slippage). */\n expectedAmountOut: bigint;\n /** Fynd's `min_amount_received` — what the router enforces on-chain. */\n minAmountOut: bigint;\n}\n\nexport interface EncodedTx {\n to: string;\n value: bigint;\n data: string;\n}\n\nconst sameAddress = (a: string, b: string) => {\n try {\n return getAddress(a) === getAddress(b);\n } catch {\n return false;\n }\n};\nconst routerToken = (t: string) => (sameAddress(t, ZERO) ? ROUTER_NATIVE : t);\n\n/** Refuses (throws {@link FyndTransactionError}) unless `tx` is exactly the swap the wallet asked for. */\nexport function checkFyndTransaction(tx: EncodedTx, expected: ExpectedSwap): {method: \"singleSwap\" | \"sequentialSwap\" | \"splitSwap\"} {\n const chain = FYND_CHAINS[expected.chainId];\n if (!chain) throw fail(`chain ${expected.chainId} has no pinned Tycho router`, \"unsupported_pair\");\n // `tx.to` is the API's: named in the refusal only when it is an address (scan 2026-10-27 modules, F34).\n if (!sameAddress(tx.to, chain.router)) throw fail(`the transaction targets ${/^0x[0-9a-fA-F]{40}$/.test(tx.to) ? tx.to : \"something that is not an address\"}, not the Tycho router on ${chain.name}`, \"vault_mismatch\");\n if (sameAddress(expected.receiver, ZERO) || sameAddress(expected.receiver, chain.router)) throw fail(\"invalid receiver\", \"recipient_mismatch\");\n if (expected.amountIn <= 0n || expected.minAmountOut <= 0n || expected.minAmountOut > expected.expectedAmountOut) {\n throw fail(\"invalid quote amounts\", \"price_check_failed\");\n }\n const nativeIn = sameAddress(expected.tokenIn, ZERO);\n if (tx.value !== (nativeIn ? expected.amountIn : 0n)) throw fail(\"native value does not match the input\", \"price_check_failed\");\n if (!/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw fail(\"malformed calldata\", \"policy_refused\");\n\n let call: ReturnType<typeof decodeFunctionData<typeof TYCHO_ROUTER_ABI>>;\n try {\n call = decodeFunctionData({abi: TYCHO_ROUTER_ABI, data: tx.data as Hex});\n } catch {\n throw fail(\"not a plain singleSwap / sequentialSwap / splitSwap call (Permit2 and vault variants are not used)\", \"policy_refused\");\n }\n const a = call.args;\n const [amountIn, tokenIn, tokenOut, expectedAmountOut, minAmountOut] = a;\n const isSplit = call.functionName === \"splitSwap\";\n const receiver = (isSplit ? a[6] : a[5]) as string;\n const fee = (isSplit ? a[7] : a[6]) as {clientFeeBps: number; clientFeeReceiver: string; maxClientContribution: bigint; deadline: bigint; clientSignature: string};\n const swaps = (isSplit ? a[8] : a[7]) as string;\n if (amountIn !== expected.amountIn) throw fail(`calldata spends ${amountIn}, not ${expected.amountIn}`, \"price_check_failed\");\n if (!sameAddress(tokenIn, routerToken(expected.tokenIn)) || !sameAddress(tokenOut, routerToken(expected.tokenOut))) {\n throw fail(\"calldata swaps other tokens than requested\", \"policy_refused\");\n }\n if (!sameAddress(receiver, expected.receiver)) throw fail(`calldata pays ${receiver}, not ${expected.receiver}`, \"recipient_mismatch\");\n if (expectedAmountOut !== expected.expectedAmountOut || minAmountOut !== expected.minAmountOut) {\n throw fail(\"calldata amounts do not match the quote\", \"price_check_failed\");\n }\n if (fee.clientFeeBps !== 0 || fee.maxClientContribution !== 0n || !sameAddress(fee.clientFeeReceiver, ZERO)) {\n throw fail(\"calldata carries client-fee parameters — this module charges none\", \"policy_refused\");\n }\n if (swaps === \"0x\" || (isSplit && (a[5] as bigint) < 2n)) throw fail(\"empty or invalid route\", \"policy_refused\");\n return {method: call.functionName};\n}\n\n/**\n * {@link checkFyndTransaction} on a remote quote, against the request this app sent: the pinned\n * router, one chain, the exact input, the requested tokens, the app's recipient, the quoted minimum and\n * no client fee. The reason it fails, or null.\n */\nexport function fyndVerifyQuote(params: QuoteParams, quote: Quote): string | null {\n // Fynd swaps on one chain; a source-chain swap must not answer a cross-chain request (reaudit 2026-10-30, #3).\n if (params.sourceChain !== params.destChain) return notes.note(\"same-chain swaps only\", \"unsupported_pair\");\n try {\n const chainId = /^eip155:[0-9]+$/.test(params.sourceChain) ? Number(params.sourceChain.slice(7)) : NaN;\n const src = sourceAssetOf(params);\n if (!src) return notes.note(`unknown source token ${params.sourceToken}`, \"unsupported_pair\");\n const tx = quote.txRequest;\n if (!tx?.to || !tx.data) return notes.note(\"the quote carries no router transaction\", \"policy_refused\");\n checkFyndTransaction({to: tx.to, data: tx.data, value: BigInt(tx.value ?? \"0\")}, {\n chainId,\n tokenIn: src.contract ? getAddress(src.contract) : ZERO,\n tokenOut: /^0x0+$/.test(params.destToken) ? ZERO : getAddress(params.destToken),\n amountIn: BigInt(params.amountIn),\n receiver: getAddress(params.destAddress),\n expectedAmountOut: BigInt(quote.providerData?.gross ?? \"0\"),\n minAmountOut: BigInt(quote.minDestAmount),\n });\n return null;\n } catch (e) {\n const text = e instanceof Error ? e.message.replace(/^fynd: /, \"\") : String(e);\n // checkFyndTransaction's refusals are classified; a request or quote that does not parse is not.\n const info = refusalOf(e);\n return info ? notes.note(text, info) : text;\n }\n}\n\n/**\n * The Tycho router a Fynd swap calls and approves on a chain, and {@link fyndVerifyQuote} — the\n * app's side of `remoteProvider({name: \"fynd\", baseUrl, ...fyndPins})`, so a backend's quote is\n * checked against these routers and the app's own request, never against itself (scan 2026-10-27\n * modules, F9). `reasonOf` classifies the texts `fyndVerifyQuote` returned, so the remote stub's refusal carries a reason.\n */\nexport const fyndPins: RemotePins = Object.freeze({\n callTargets: (chain: string): readonly string[] => fyndRouterFor(chain),\n spenders: (chain: string): readonly string[] => fyndRouterFor(chain),\n verifyQuote: fyndVerifyQuote,\n reasonOf: (refusal: string) => notes.reasonOf(refusal),\n});\nfunction fyndRouterFor(chain: string): readonly string[] {\n const id = /^eip155:[0-9]+$/.test(chain) ? Number(chain.slice(7)) : NaN;\n const c = Object.prototype.hasOwnProperty.call(FYND_CHAINS, id) ? FYND_CHAINS[id] : undefined;\n return c ? [c.router] : [];\n}\n"],"mappings":";AAWA,SAAQ,qBAAoB;AAC5B,SAAQ,cAAc,WAAW,kBAA0C;AAC3E,SAAQ,oBAAoB,YAAY,UAAU,0BAAmC;AAG9E,IAAM,cAA6F,OAAO,OAAO;AAAA,EACtH,GAAG,EAAC,MAAM,YAAY,MAAM,YAAY,QAAQ,6CAA4C;AAAA,EAC5F,MAAM,EAAC,MAAM,QAAQ,MAAM,QAAQ,QAAQ,6CAA4C;AAAA,EACvF,OAAO,EAAC,MAAM,YAAY,MAAM,YAAY,QAAQ,6CAA4C;AAAA,EAChG,IAAI,EAAC,MAAM,OAAO,MAAM,mBAAmB,QAAQ,6CAA4C;AAAA,EAC/F,KAAK,EAAC,MAAM,WAAW,MAAM,WAAW,QAAQ,6CAA4C;AAAA,EAC5F,KAAK,EAAC,MAAM,YAAY,MAAM,YAAY,QAAQ,6CAA4C;AAAA,EAC9F,MAAM,EAAC,MAAM,aAAa,MAAM,mBAAmB,QAAQ,6CAA4C;AACzG,CAAC;AAGM,IAAM,gBAAgB;AAC7B,IAAM,OAAO;AAEb,IAAM,SAAS;AACf,IAAM,MAAM;AACZ,IAAM,SAAS;AAGR,IAAM,mBAAmB,SAAS;AAAA,EACvC,uBAAuB,MAAM,uBAAuB,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AAmB,OAAO,MAAM,cAAc,SAAS,GAAG;AAAA,MAC1D,cAAc,OAAO,MAAM,aAAa;AAAA,IAC1C,CAAC;AACD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,UAAM,OAAO,aAAa,QAAQ,EAAE,QAAQ,QAAQ,WAAW,EAAE,IAAI,OAAO,CAAC;AAE7E,UAAM,OAAO,UAAU,CAAC;AACxB,WAAO,OAAO,MAAM,KAAK,MAAM,IAAI,IAAI;AAAA,EACzC;AACF;AAQO,IAAM,WAAuB,OAAO,OAAO;AAAA,EAChD,aAAa,CAAC,UAAqC,cAAc,KAAK;AAAA,EACtE,UAAU,CAAC,UAAqC,cAAc,KAAK;AAAA,EACnE,aAAa;AAAA,EACb,UAAU,CAAC,YAAoB,MAAM,SAAS,OAAO;AACvD,CAAC;AACD,SAAS,cAAc,OAAkC;AACvD,QAAM,KAAK,kBAAkB,KAAK,KAAK,IAAI,OAAO,MAAM,MAAM,CAAC,CAAC,IAAI;AACpE,QAAM,IAAI,OAAO,UAAU,eAAe,KAAK,aAAa,EAAE,IAAI,YAAY,EAAE,IAAI;AACpF,SAAO,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;AAC3B;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  fyndProvider
3
- } from "./chunk-TZUER4XJ.js";
3
+ } from "./chunk-6AQCGGUZ.js";
4
4
  import {
5
5
  FYND_CHAINS
6
- } from "./chunk-J6XM7WEG.js";
6
+ } from "./chunk-6WSGOEAI.js";
7
7
 
8
8
  // src/protocol.ts
9
9
  import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
@@ -29,4 +29,4 @@ var FyndSwap2Protocol = class extends SingleProviderSwap2 {
29
29
  export {
30
30
  FyndSwap2Protocol
31
31
  };
32
- //# sourceMappingURL=chunk-ZDIAIUX2.js.map
32
+ //# sourceMappingURL=chunk-FTBFWSOY.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FYND_CHAINS,
3
3
  TYCHO_ROUTER_SELECTORS
4
- } from "./chunk-J6XM7WEG.js";
4
+ } from "./chunk-6WSGOEAI.js";
5
5
 
6
6
  // src/activity.ts
7
7
  import { chainLabel, describeSwapLike, matchesCall } from "@anywalletkit/protocol-swap2-core/activity";
@@ -19,4 +19,4 @@ export {
19
19
  FYND_MODULE,
20
20
  describeFyndActivity
21
21
  };
22
- //# sourceMappingURL=chunk-PF2NGOA5.js.map
22
+ //# sourceMappingURL=chunk-O47NHTKT.js.map
package/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(src_exports);
40
40
  // src/provider.ts
41
41
  var import_viem2 = require("viem");
42
42
  var import_util3 = require("@anywalletkit/protocol-swap2-core/util");
43
+ var import_errors2 = require("@anywalletkit/protocol-swap2-core/errors");
43
44
 
44
45
  // src/activity.ts
45
46
  var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
@@ -47,6 +48,7 @@ var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
47
48
 
48
49
  // src/router.ts
49
50
  var import_util = require("@anywalletkit/protocol-swap2-core/util");
51
+ var import_errors = require("@anywalletkit/protocol-swap2-core/errors");
50
52
  var import_viem = require("viem");
51
53
  var FYND_CHAINS = Object.freeze({
52
54
  1: { slug: "ethereum", name: "Ethereum", router: "0x1644D2477f809cc2C71bCCFd6Dc9497E3F83210d" },
@@ -86,6 +88,8 @@ var FyndTransactionError = class extends Error {
86
88
  this.name = "FyndTransactionError";
87
89
  }
88
90
  };
91
+ var fail = (message, reason) => (0, import_errors.withReason)(new FyndTransactionError(message), reason);
92
+ var notes = (0, import_errors.refusalNotes)();
89
93
  var sameAddress = (a, b) => {
90
94
  try {
91
95
  return (0, import_viem.getAddress)(a) === (0, import_viem.getAddress)(b);
@@ -96,20 +100,20 @@ var sameAddress = (a, b) => {
96
100
  var routerToken = (t) => sameAddress(t, ZERO) ? ROUTER_NATIVE : t;
97
101
  function checkFyndTransaction(tx, expected) {
98
102
  const chain = FYND_CHAINS[expected.chainId];
99
- if (!chain) throw new FyndTransactionError(`chain ${expected.chainId} has no pinned Tycho router`);
100
- if (!sameAddress(tx.to, chain.router)) throw new FyndTransactionError(`the transaction targets ${/^0x[0-9a-fA-F]{40}$/.test(tx.to) ? tx.to : "something that is not an address"}, not the Tycho router on ${chain.name}`);
101
- if (sameAddress(expected.receiver, ZERO) || sameAddress(expected.receiver, chain.router)) throw new FyndTransactionError("invalid receiver");
103
+ if (!chain) throw fail(`chain ${expected.chainId} has no pinned Tycho router`, "unsupported_pair");
104
+ if (!sameAddress(tx.to, chain.router)) throw fail(`the transaction targets ${/^0x[0-9a-fA-F]{40}$/.test(tx.to) ? tx.to : "something that is not an address"}, not the Tycho router on ${chain.name}`, "vault_mismatch");
105
+ if (sameAddress(expected.receiver, ZERO) || sameAddress(expected.receiver, chain.router)) throw fail("invalid receiver", "recipient_mismatch");
102
106
  if (expected.amountIn <= 0n || expected.minAmountOut <= 0n || expected.minAmountOut > expected.expectedAmountOut) {
103
- throw new FyndTransactionError("invalid quote amounts");
107
+ throw fail("invalid quote amounts", "price_check_failed");
104
108
  }
105
109
  const nativeIn = sameAddress(expected.tokenIn, ZERO);
106
- if (tx.value !== (nativeIn ? expected.amountIn : 0n)) throw new FyndTransactionError("native value does not match the input");
107
- if (!/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw new FyndTransactionError("malformed calldata");
110
+ if (tx.value !== (nativeIn ? expected.amountIn : 0n)) throw fail("native value does not match the input", "price_check_failed");
111
+ if (!/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw fail("malformed calldata", "policy_refused");
108
112
  let call;
109
113
  try {
110
114
  call = (0, import_viem.decodeFunctionData)({ abi: TYCHO_ROUTER_ABI, data: tx.data });
111
115
  } catch {
112
- throw new FyndTransactionError("not a plain singleSwap / sequentialSwap / splitSwap call (Permit2 and vault variants are not used)");
116
+ throw fail("not a plain singleSwap / sequentialSwap / splitSwap call (Permit2 and vault variants are not used)", "policy_refused");
113
117
  }
114
118
  const a = call.args;
115
119
  const [amountIn, tokenIn, tokenOut, expectedAmountOut, minAmountOut] = a;
@@ -117,28 +121,28 @@ function checkFyndTransaction(tx, expected) {
117
121
  const receiver = isSplit ? a[6] : a[5];
118
122
  const fee = isSplit ? a[7] : a[6];
119
123
  const swaps = isSplit ? a[8] : a[7];
120
- if (amountIn !== expected.amountIn) throw new FyndTransactionError(`calldata spends ${amountIn}, not ${expected.amountIn}`);
124
+ if (amountIn !== expected.amountIn) throw fail(`calldata spends ${amountIn}, not ${expected.amountIn}`, "price_check_failed");
121
125
  if (!sameAddress(tokenIn, routerToken(expected.tokenIn)) || !sameAddress(tokenOut, routerToken(expected.tokenOut))) {
122
- throw new FyndTransactionError("calldata swaps other tokens than requested");
126
+ throw fail("calldata swaps other tokens than requested", "policy_refused");
123
127
  }
124
- if (!sameAddress(receiver, expected.receiver)) throw new FyndTransactionError(`calldata pays ${receiver}, not ${expected.receiver}`);
128
+ if (!sameAddress(receiver, expected.receiver)) throw fail(`calldata pays ${receiver}, not ${expected.receiver}`, "recipient_mismatch");
125
129
  if (expectedAmountOut !== expected.expectedAmountOut || minAmountOut !== expected.minAmountOut) {
126
- throw new FyndTransactionError("calldata amounts do not match the quote");
130
+ throw fail("calldata amounts do not match the quote", "price_check_failed");
127
131
  }
128
132
  if (fee.clientFeeBps !== 0 || fee.maxClientContribution !== 0n || !sameAddress(fee.clientFeeReceiver, ZERO)) {
129
- throw new FyndTransactionError("calldata carries client-fee parameters \u2014 this module charges none");
133
+ throw fail("calldata carries client-fee parameters \u2014 this module charges none", "policy_refused");
130
134
  }
131
- if (swaps === "0x" || isSplit && a[5] < 2n) throw new FyndTransactionError("empty or invalid route");
135
+ if (swaps === "0x" || isSplit && a[5] < 2n) throw fail("empty or invalid route", "policy_refused");
132
136
  return { method: call.functionName };
133
137
  }
134
138
  function fyndVerifyQuote(params, quote) {
135
- if (params.sourceChain !== params.destChain) return "same-chain swaps only";
139
+ if (params.sourceChain !== params.destChain) return notes.note("same-chain swaps only", "unsupported_pair");
136
140
  try {
137
141
  const chainId = /^eip155:[0-9]+$/.test(params.sourceChain) ? Number(params.sourceChain.slice(7)) : NaN;
138
142
  const src = (0, import_util.sourceAssetOf)(params);
139
- if (!src) return `unknown source token ${params.sourceToken}`;
143
+ if (!src) return notes.note(`unknown source token ${params.sourceToken}`, "unsupported_pair");
140
144
  const tx = quote.txRequest;
141
- if (!tx?.to || !tx.data) return "the quote carries no router transaction";
145
+ if (!tx?.to || !tx.data) return notes.note("the quote carries no router transaction", "policy_refused");
142
146
  checkFyndTransaction({ to: tx.to, data: tx.data, value: BigInt(tx.value ?? "0") }, {
143
147
  chainId,
144
148
  tokenIn: src.contract ? (0, import_viem.getAddress)(src.contract) : ZERO,
@@ -150,13 +154,16 @@ function fyndVerifyQuote(params, quote) {
150
154
  });
151
155
  return null;
152
156
  } catch (e) {
153
- return e instanceof Error ? e.message.replace(/^fynd: /, "") : String(e);
157
+ const text = e instanceof Error ? e.message.replace(/^fynd: /, "") : String(e);
158
+ const info = (0, import_errors.refusalOf)(e);
159
+ return info ? notes.note(text, info) : text;
154
160
  }
155
161
  }
156
162
  var fyndPins = Object.freeze({
157
163
  callTargets: (chain) => fyndRouterFor(chain),
158
164
  spenders: (chain) => fyndRouterFor(chain),
159
- verifyQuote: fyndVerifyQuote
165
+ verifyQuote: fyndVerifyQuote,
166
+ reasonOf: (refusal2) => notes.reasonOf(refusal2)
160
167
  });
161
168
  function fyndRouterFor(chain) {
162
169
  const id = /^eip155:[0-9]+$/.test(chain) ? Number(chain.slice(7)) : NaN;
@@ -188,6 +195,15 @@ var QUOTE_FAILURES = {
188
195
  price_check_failed: "the price guard rejected the route",
189
196
  encoding_failed: "could not encode the swap (fees + slippage leave nothing)"
190
197
  };
198
+ var QUOTE_FAILURE_REASONS = {
199
+ no_route_found: "no_route",
200
+ insufficient_liquidity: "insufficient_liquidity",
201
+ timeout: "upstream_unavailable",
202
+ not_ready: "stale_node",
203
+ price_check_failed: "price_check_failed",
204
+ encoding_failed: "amount_too_small"
205
+ };
206
+ var quoteFailureReason = (status) => typeof status === "string" && Object.prototype.hasOwnProperty.call(QUOTE_FAILURE_REASONS, status) ? QUOTE_FAILURE_REASONS[status] : void 0;
191
207
  var ROUTER_ERRORS = (0, import_viem2.parseAbi)([
192
208
  "error TychoRouter__NegativeSlippage(uint256 amount, uint256 minAmount)",
193
209
  "error TychoRouter__FeesExceedOutput(uint256 totalFees, uint256 actualAmountOut)",
@@ -247,7 +263,11 @@ function fyndProvider(config) {
247
263
  for (const url of config.rpcUrls?.[chainId] ?? []) {
248
264
  try {
249
265
  const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }), signal: (0, import_util3.timeoutSignal)(12e3) });
250
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
266
+ if (!res.ok) {
267
+ const error = new Error(`HTTP ${res.status}`);
268
+ const info = (0, import_errors2.httpRefusal)(res.status, res.headers?.get?.("retry-after"));
269
+ throw info ? (0, import_errors2.withReason)(error, info) : error;
270
+ }
251
271
  const body = await res.json();
252
272
  if (body.error) throw Object.assign(new Error(body.error.message ?? "rpc error"), { rpc: true, data: body.error.data });
253
273
  return body.result ?? null;
@@ -256,19 +276,19 @@ function fyndProvider(config) {
256
276
  lastErr = e;
257
277
  }
258
278
  }
259
- throw new Error(`fynd: no RPC answered on chain ${chainId} (${lastErr instanceof Error ? lastErr.message : String(lastErr)})`);
279
+ throw (0, import_errors2.withReason)(new Error(`fynd: no RPC answered on chain ${chainId} (${lastErr instanceof Error ? lastErr.message : String(lastErr)})`), (0, import_errors2.refusalOf)(lastErr) ?? "upstream_unavailable");
260
280
  }
261
281
  async function revertReason(chainId, sender, quoted, e) {
262
282
  const revert = routerRevert(e);
263
283
  if (revert?.name === "TychoRouter__NegativeSlippage") {
264
284
  const [out, min] = revert.args;
265
285
  const pays = typeof out === "bigint" && typeof min === "bigint" ? ` \u2014 the route now pays ${out}, under your minimum ${min}` : "";
266
- return `fynd: the price moved past your minimum${pays}. Nothing was sent; refresh the quote.`;
286
+ return (0, import_errors2.refusal)("price_check_failed", `fynd: the price moved past your minimum${pays}. Nothing was sent; refresh the quote.`);
267
287
  }
268
288
  const short = await inputShortfall(chainId, sender, quoted).catch(() => null);
269
- if (short) return short;
289
+ if (short) return (0, import_errors2.refusal)("simulation_failed", short);
270
290
  const why = revert ? revert.name === "Error" && typeof revert.args[0] === "string" ? revert.args[0].slice(0, 120) : `${revert.name}${revert.args.length ? `(${revert.args.map(String).join(", ").slice(0, 100)})` : ""}` : e instanceof Error ? e.message.slice(0, 120) : "revert";
271
- return `fynd: the swap would revert now (${why}). Nothing was sent; refresh the quote.`;
291
+ return (0, import_errors2.refusal)("simulation_failed", `fynd: the swap would revert now (${why}). Nothing was sent; refresh the quote.`);
272
292
  }
273
293
  async function inputShortfall(chainId, sender, quoted) {
274
294
  const call = (0, import_viem2.decodeFunctionData)({ abi: TYCHO_ROUTER_ABI, data: quoted.data });
@@ -299,23 +319,23 @@ function fyndProvider(config) {
299
319
  supportsChainPair: (from, to) => from === to && chainIdOf(from) !== null,
300
320
  supportsRoute: (from, to) => from.chain === to.chain && chainIdOf(from.chain) !== null,
301
321
  async getQuote(params, signal) {
302
- const refuse = (why) => {
303
- params.onRefusal?.(`fynd: ${why}`);
322
+ const refuse = (why, info) => {
323
+ params.onRefusal?.(`fynd: ${why}`, typeof info === "string" ? { reason: info } : info);
304
324
  return null;
305
325
  };
306
- if (params.flex) return refuse("amount-flexible deposits are not supported");
307
- if (params.sourceChain !== params.destChain) return refuse("same-chain swaps only");
326
+ if (params.flex) return refuse("amount-flexible deposits are not supported", "unsupported_pair");
327
+ if (params.sourceChain !== params.destChain) return refuse("same-chain swaps only", "unsupported_pair");
308
328
  const chainId = chainIdOf(params.sourceChain);
309
- if (chainId === null) return refuse(`Fynd is not configured for ${params.sourceChain}`);
329
+ if (chainId === null) return refuse(`Fynd is not configured for ${params.sourceChain}`, "unsupported_pair");
310
330
  const ep = endpoint(chainId);
311
331
  const src = (0, import_util3.sourceAssetOf)(params);
312
- if (!src) return refuse(`unknown source token ${params.sourceToken}`);
332
+ if (!src) return refuse(`unknown source token ${params.sourceToken}`, "unsupported_pair");
313
333
  const tokenIn = src.contract ? (0, import_viem2.getAddress)(src.contract) : ZERO2;
314
334
  const nativeOut = /^0x0+$/.test(params.destToken);
315
- if (!nativeOut && !/^0x[0-9a-fA-F]{40}$/.test(params.destToken)) return refuse("destination token must be an EVM address");
335
+ if (!nativeOut && !/^0x[0-9a-fA-F]{40}$/.test(params.destToken)) return refuse("destination token must be an EVM address", "unsupported_pair");
316
336
  const tokenOut = nativeOut ? ZERO2 : (0, import_viem2.getAddress)(params.destToken);
317
- if (tokenIn === tokenOut) return refuse("same token in and out");
318
- if (!/^0x[0-9a-fA-F]{40}$/.test(params.destAddress)) return refuse("recipient must be an EVM address");
337
+ if (tokenIn === tokenOut) return refuse("same token in and out", "unsupported_pair");
338
+ if (!/^0x[0-9a-fA-F]{40}$/.test(params.destAddress)) return refuse("recipient must be an EVM address", "recipient_mismatch");
319
339
  const receiver = (0, import_viem2.getAddress)(params.destAddress);
320
340
  const sender = (0, import_viem2.getAddress)(params.refundAddress && /^0x[0-9a-fA-F]{40}$/.test(params.refundAddress) ? params.refundAddress : params.destAddress);
321
341
  let amountIn;
@@ -326,7 +346,7 @@ function fyndProvider(config) {
326
346
  }
327
347
  if (amountIn <= 0n) return refuse("amount must be positive");
328
348
  const bps = params.slippageBps ?? slippageDefault;
329
- if (!Number.isInteger(bps) || bps <= 0 || bps >= 1e4) return refuse("invalid slippage");
349
+ if (!Number.isInteger(bps) || bps <= 0 || bps >= 1e4) return refuse("invalid slippage", "price_check_failed");
330
350
  const body = {
331
351
  orders: [{ token_in: tokenIn, token_out: tokenOut, amount: amountIn.toString(), side: "sell", sender, receiver }],
332
352
  options: {
@@ -339,21 +359,21 @@ function fyndProvider(config) {
339
359
  try {
340
360
  res = await fetch(ep.url, { method: "POST", headers: { "content-type": "application/json", ...ep.headers }, body: JSON.stringify(body), signal: signal ?? (0, import_util3.timeoutSignal)(timeoutMs) });
341
361
  } catch (e) {
342
- return refuse(`API unreachable (${e instanceof Error ? e.name : "error"})`);
362
+ return refuse(`API unreachable (${e instanceof Error ? e.name : "error"})`, signal?.aborted ? void 0 : "upstream_unavailable");
343
363
  }
344
- if (res.status === 401 || res.status === 403) return refuse(`API key rejected (HTTP ${res.status})`);
345
- if (res.status === 429) return refuse("rate limited (HTTP 429)");
346
- if (res.status === 422) return refuse("no route for this pair");
347
- if (!res.ok) return refuse(`API answered HTTP ${res.status}`);
364
+ if (res.status === 401 || res.status === 403) return refuse(`API key rejected (HTTP ${res.status})`, (0, import_errors2.httpRefusal)(res.status));
365
+ if (res.status === 429) return refuse("rate limited (HTTP 429)", (0, import_errors2.httpRefusal)(res.status, res.headers?.get?.("retry-after")));
366
+ if (res.status === 422) return refuse("no route for this pair", "no_route");
367
+ if (!res.ok) return refuse(`API answered HTTP ${res.status}`, (0, import_errors2.httpRefusal)(res.status, res.headers?.get?.("retry-after")));
348
368
  let parsed;
349
369
  try {
350
370
  parsed = await res.json();
351
371
  } catch {
352
- return refuse("malformed API response");
372
+ return refuse("malformed API response", signal?.aborted ? void 0 : "upstream_unavailable");
353
373
  }
354
- if (!Array.isArray(parsed.orders) || parsed.orders.length !== 1) return refuse("malformed API response (order count)");
374
+ if (!Array.isArray(parsed.orders) || parsed.orders.length !== 1) return refuse("malformed API response (order count)", "upstream_unavailable");
355
375
  const q = parsed.orders[0];
356
- if (q.status !== "success") return refuse(QUOTE_FAILURES[q.status ?? ""] ?? `quote status ${String(q.status).slice(0, 40)}`);
376
+ if (q.status !== "success") return refuse(QUOTE_FAILURES[q.status ?? ""] ?? `quote status ${String(q.status).slice(0, 40)}`, quoteFailureReason(q.status));
357
377
  const quotedIn = uint(q.amount_in);
358
378
  const gross = uint(q.amount_out);
359
379
  const routerFee = uint(q.fee_breakdown?.router_fee);
@@ -362,26 +382,26 @@ function fyndProvider(config) {
362
382
  const minOut = uint(q.fee_breakdown?.min_amount_received);
363
383
  const value = uint(q.transaction?.value ?? "");
364
384
  if (quotedIn === null || gross === null || routerFee === null || clientFee === null || maxSlippage === null || minOut === null || value === null) {
365
- return refuse("malformed quote amounts");
385
+ return refuse("malformed quote amounts", "upstream_unavailable");
366
386
  }
367
- if (quotedIn !== amountIn) return refuse(`quoted ${quotedIn}, not the requested ${amountIn}`);
368
- if (clientFee !== 0n) return refuse("the quote carries a client fee");
369
- if (routerFee + clientFee + maxSlippage + minOut !== gross) return refuse("fee breakdown does not add up to the output");
370
- if (params.minAmountOut !== void 0 && minOut < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minOut} < floor=${params.minAmountOut})`);
387
+ if (quotedIn !== amountIn) return refuse(`quoted ${quotedIn}, not the requested ${amountIn}`, "price_check_failed");
388
+ if (clientFee !== 0n) return refuse("the quote carries a client fee", "policy_refused");
389
+ if (routerFee + clientFee + maxSlippage + minOut !== gross) return refuse("fee breakdown does not add up to the output", "price_check_failed");
390
+ if (params.minAmountOut !== void 0 && minOut < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minOut} < floor=${params.minAmountOut})`, "price_check_failed");
371
391
  const tx = { to: q.transaction?.to ?? "", value, data: q.transaction?.data ?? "" };
372
392
  try {
373
393
  checkFyndTransaction(tx, { chainId, tokenIn, tokenOut, amountIn, receiver, expectedAmountOut: gross, minAmountOut: minOut });
374
394
  } catch (e) {
375
- return refuse(e instanceof Error ? e.message.replace(/^fynd: /, "") : String(e));
395
+ return refuse(e instanceof Error ? e.message.replace(/^fynd: /, "") : String(e), (0, import_errors2.refusalOf)(e));
376
396
  }
377
397
  const allProtocols = [...new Set((q.route?.swaps ?? []).map((s) => s.protocol).filter((p) => typeof p === "string"))];
378
398
  const banned = allProtocols.find(isExcluded);
379
- if (banned) return refuse(`the route goes through ${protocolName(banned)}, which this wallet excludes`);
399
+ if (banned) return refuse(`the route goes through ${protocolName(banned)}, which this wallet excludes`, "policy_refused");
380
400
  if (tokenIn === ZERO2 && config.rpcUrls?.[chainId]?.length) {
381
401
  try {
382
402
  await rpc(chainId, "eth_call", [{ from: sender, to: tx.to, data: tx.data, value: `0x${value.toString(16)}` }, "latest", { [sender]: { balance: `0x${(value + 10n ** 18n).toString(16)}` } }]);
383
403
  } catch (e) {
384
- if (e.rpc) return refuse(`the route does not execute on-chain right now (simulation reverted via ${allProtocols.slice(0, 6).map(protocolName).join(", ") || "?"})`);
404
+ if (e.rpc) return refuse(`the route does not execute on-chain right now (simulation reverted via ${allProtocols.slice(0, 6).map(protocolName).join(", ") || "?"})`, "simulation_failed");
385
405
  }
386
406
  }
387
407
  const gas = uint(q.gas_estimate) ?? 0n;
@@ -430,17 +450,17 @@ function fyndProvider(config) {
430
450
  if (!FYND_CHAINS[chainId] || !config.rpcUrls?.[chainId]?.length || !tx.data || !sender) return;
431
451
  const quoted = quote.txRequest;
432
452
  if (!quoted?.to || !quoted.data || !sameText(tx.to, quoted.to) || !sameText(tx.data, quoted.data) || !sameAmount(tx.value || "0", quoted.value ?? "0")) {
433
- throw new Error("fynd: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
453
+ throw (0, import_errors2.refusal)("policy_refused", "fynd: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
434
454
  }
435
455
  try {
436
456
  await rpc(chainId, "eth_call", [{ from: sender, to: quoted.to, data: quoted.data, value: `0x${BigInt(quoted.value ?? "0").toString(16)}` }, "latest"]);
437
457
  } catch (e) {
438
- if (e.rpc) throw new Error(await revertReason(chainId, sender, quoted, e));
458
+ if (e.rpc) throw await revertReason(chainId, sender, quoted, e);
439
459
  }
440
460
  },
441
461
  async buildDeposit(quote) {
442
462
  const tx = quote.txRequest;
443
- if (!tx?.to || !tx.data) throw new Error("swap2: Fynd quote has no transaction request");
463
+ if (!tx?.to || !tx.data) throw (0, import_errors2.refusal)("policy_refused", "swap2: Fynd quote has no transaction request");
444
464
  return { chain: "", to: tx.to, value: tx.value ?? "0", data: tx.data, ...tx.chainId !== void 0 ? { chainId: tx.chainId } : {}, ...tx.gasLimit ? { gasLimit: tx.gasLimit } : {}, ...tx.approvalAddress ? { approvalAddress: tx.approvalAddress } : {} };
445
465
  },
446
466
  async trackIntent(ref) {