@glacislabs/stablegenie-zerodelta 3.2.0 → 3.4.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.
@@ -1,7 +1,27 @@
1
1
  // src/core/constants.ts
2
2
  var DEFAULT_WIDGET_API_BASE = "/api/widget/v1";
3
3
  var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866]);
4
- var SUPPORTED_ASSETS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE", "XAUT"]);
4
+ var EXECUTABLE_STABLE_ASSETS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE", "USDTB", "AUSD", "PYUSD", "USDG"]);
5
+ var STABLE_ASSETS = /* @__PURE__ */ new Set([...EXECUTABLE_STABLE_ASSETS, "USD1", "WM", "USDS", "DAI", "RLUSD"]);
6
+ var TRADEABLE_RWA_ASSETS = /* @__PURE__ */ new Set([
7
+ "XAUT",
8
+ // Nest vault shares — chained delivery on Plume, sellable from their Ethereum deployment.
9
+ "NALPHA",
10
+ "NTBILL",
11
+ "NBASIS",
12
+ "NCREDIT",
13
+ "NOPAL",
14
+ "NWISDOM",
15
+ "NACRDX",
16
+ "NLCRD",
17
+ "NAXI",
18
+ "NCLOA",
19
+ "NFALCON",
20
+ // Centrifuge deRWA pair — chained asks on Base.
21
+ "DEJAAA",
22
+ "DESPXA"
23
+ ]);
24
+ var SUPPORTED_ASSETS = /* @__PURE__ */ new Set([...STABLE_ASSETS, ...TRADEABLE_RWA_ASSETS]);
5
25
  var API_CACHE_TTL_MS = 6e4;
6
26
  var MAX_QUOTE_CANDIDATES = 8;
7
27
  var QUOTE_BUFFER_BPS = 50;
@@ -14,7 +34,41 @@ var ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
14
34
  var ERC20_BALANCEOF_SELECTOR = "0x70a08231";
15
35
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
16
36
  var PREVIEW_OWNER = "0x1111111111111111111111111111111111111111";
17
- var CANONICAL_DECIMALS = { USDC: 6, USDT: 6, USDE: 18, XAUT: 6 };
37
+ var CANONICAL_DECIMALS = {
38
+ USDC: 6,
39
+ USDT: 6,
40
+ USDE: 18,
41
+ XAUT: 6,
42
+ // Added 2026-09-08 with the dapp-parity asset expansion. Every value below was read from the
43
+ // token contract itself — `eth_call decimals()` against each deployment the registry lists on the
44
+ // nine escrow chains — and each symbol answered the SAME number on every chain it is deployed on.
45
+ // The set is a deliberate mix of 6 and 18, and a copy-pasted row is wrong by a factor of 1e12
46
+ // while still looking entirely plausible in review; that is the bug this pin exists to prevent.
47
+ USDTB: 18,
48
+ AUSD: 6,
49
+ PYUSD: 6,
50
+ USDG: 6,
51
+ // The wider stable list — the bid side of an RWA trade.
52
+ DAI: 18,
53
+ RLUSD: 18,
54
+ USD1: 18,
55
+ USDS: 18,
56
+ WM: 6,
57
+ // Real-world assets. Every Nest vault share is 6; the Centrifuge pair is 18.
58
+ NALPHA: 6,
59
+ NTBILL: 6,
60
+ NBASIS: 6,
61
+ NCREDIT: 6,
62
+ NOPAL: 6,
63
+ NWISDOM: 6,
64
+ NACRDX: 6,
65
+ NLCRD: 6,
66
+ NAXI: 6,
67
+ NCLOA: 6,
68
+ NFALCON: 6,
69
+ DEJAAA: 18,
70
+ DESPXA: 18
71
+ };
18
72
  var CANONICAL_ESCROW = Object.freeze({
19
73
  1: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
20
74
  // Ethereum
@@ -44,9 +98,40 @@ var CANONICAL_INBOUND_BRIDGE = {
44
98
  USDC: "cctp",
45
99
  USDT: "layerzero",
46
100
  USDE: "layerzero",
47
- XAUT: "layerzero"
101
+ XAUT: "layerzero",
102
+ // 2026-09-08: the four assets added for dapp parity are all LayerZero V2 OFTs on every chain the
103
+ // registry lists them on (`standard: "LayerZeroV2OFT"`, verified against dev and prod /tokens).
104
+ // USDC remains the only CCTP asset.
105
+ USDTB: "layerzero",
106
+ AUSD: "layerzero",
107
+ PYUSD: "layerzero",
108
+ USDG: "layerzero",
109
+ // `"none"` is a POSITIVE statement, not a gap: these assets have no inbound bridge adapter at all
110
+ // (the registry says `bridge: "None"`, or ships no bridge field at all), so they can only ever be
111
+ // bid on the chain the order already executes on and can never legitimately owe a native
112
+ // LayerZero fee. Pinning them matters because the fallback for an UNpinned asset is the label
113
+ // sniff, and a hostile quote controls the label — `bridge: "layerzero"` on one of these would
114
+ // otherwise let it attach msg.value to an order that forwards none, stranding it in the escrow.
115
+ DAI: "none",
116
+ RLUSD: "none",
117
+ USD1: "none",
118
+ USDS: "none",
119
+ WM: "none",
120
+ NALPHA: "none",
121
+ NTBILL: "none",
122
+ NBASIS: "none",
123
+ NCREDIT: "none",
124
+ NOPAL: "none",
125
+ NWISDOM: "none",
126
+ NACRDX: "none",
127
+ NLCRD: "none",
128
+ NAXI: "none",
129
+ NCLOA: "none",
130
+ NFALCON: "none",
131
+ DEJAAA: "none",
132
+ DESPXA: "none"
48
133
  };
49
- var SAME_CLASS_STABLE = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
134
+ var SAME_CLASS_STABLE = new Set(STABLE_ASSETS);
50
135
  var MAX_SAME_CLASS_PAY_BPS = 30000n;
51
136
  var BUNDLED_NATIVE_SYMBOL = {
52
137
  1: "ETH",
@@ -69,6 +154,55 @@ var BUNDLED_RPC = {
69
154
  42161: "https://arb1.arbitrum.io/rpc",
70
155
  98866: "https://rpc.plume.org"
71
156
  };
157
+ var CHAIN_DISPLAY_NAMES = Object.freeze({
158
+ 1: "Ethereum",
159
+ 10: "Optimism",
160
+ 14: "Flare",
161
+ 30: "Rootstock",
162
+ 50: "XDC Network",
163
+ 56: "BNB Chain",
164
+ 88: "Viction",
165
+ 130: "Unichain",
166
+ 137: "Polygon",
167
+ 143: "Monad",
168
+ 146: "Sonic",
169
+ 151: "Redbelly Network",
170
+ 169: "Manta Pacific",
171
+ 196: "X Layer",
172
+ 252: "Fraxtal",
173
+ 324: "zkSync Era",
174
+ 480: "World Chain",
175
+ 988: "Stable",
176
+ 999: "HyperEVM",
177
+ 1030: "Conflux eSpace",
178
+ 1088: "Metis",
179
+ 1135: "Lisk",
180
+ 1329: "Sei",
181
+ 1776: "Injective EVM",
182
+ 1868: "Soneium",
183
+ 1923: "Swellchain",
184
+ 2222: "Kava",
185
+ 2818: "Morph",
186
+ 3343: "EDGE",
187
+ 4326: "MegaETH",
188
+ 5e3: "Mantle",
189
+ 8453: "Base",
190
+ 9745: "Plasma",
191
+ 34443: "Mode",
192
+ 42161: "Arbitrum One",
193
+ 43114: "Avalanche C-Chain",
194
+ 48900: "Zircuit",
195
+ 57073: "Ink",
196
+ 59144: "Linea",
197
+ 80094: "Berachain",
198
+ 81224: "Codex",
199
+ 81457: "Blast",
200
+ 98866: "Plume",
201
+ 534352: "Scroll",
202
+ 747474: "Katana",
203
+ 7777777: "Zora",
204
+ 21e6: "Corn"
205
+ });
72
206
 
73
207
  // src/core/address.ts
74
208
  function symbolKey(value) {
@@ -333,10 +467,129 @@ function applyLayerZeroBuffer(quote, option = {}) {
333
467
  return gas * (10000n + LZ_FEE_BUFFER_BPS) / 10000n;
334
468
  }
335
469
 
470
+ // src/core/availability.ts
471
+ function assetClassOf(symbol) {
472
+ const key = symbolKey(symbol);
473
+ if (TRADEABLE_RWA_ASSETS.has(key)) return "rwa";
474
+ if (STABLE_ASSETS.has(key)) return "stable";
475
+ return null;
476
+ }
477
+ function productAssets(product) {
478
+ return product === "rwa" ? /* @__PURE__ */ new Set([...STABLE_ASSETS, ...TRADEABLE_RWA_ASSETS]) : EXECUTABLE_STABLE_ASSETS;
479
+ }
480
+ function counterpartTokens(tokens, selected) {
481
+ const want = assetClassOf(selected?.symbol) === "rwa" ? "stable" : "rwa";
482
+ return tokens.filter((token) => assetClassOf(token.symbol) === want);
483
+ }
484
+ function tokenKey(chainId, address) {
485
+ return `${Number(chainId)}:${String(address || "").toLowerCase()}`;
486
+ }
487
+ function laneKey(fromChainId, fromAddress, toChainId, toAddress) {
488
+ return `${tokenKey(fromChainId, fromAddress)}>${tokenKey(toChainId, toAddress)}`;
489
+ }
490
+ function isExecutableBridge(descriptor) {
491
+ const bridge = descriptor?.bridge?.trim().toLowerCase();
492
+ const standard = descriptor?.standard?.replace(/[\s_-]/g, "").toLowerCase();
493
+ return (bridge === "circle" || bridge === "cctp") && standard === "cctpv2" || bridge === "layerzero" && standard === "layerzerov2oft";
494
+ }
495
+ function isKnownUnbridgeable(bridge) {
496
+ return typeof bridge === "string" && bridge.trim().toLowerCase() === "none";
497
+ }
498
+ function executableRoutes(routes) {
499
+ return routes.filter((route) => route.isEnabled !== false && isExecutableBridge(route));
500
+ }
501
+ function sourceKeys(routes) {
502
+ return new Set(routes.filter((r) => r.isEnabled !== false).map((r) => tokenKey(r.fromChainId, r.fromAddress ?? "")));
503
+ }
504
+ function destinationKeys(routes) {
505
+ return new Set(routes.filter((r) => r.isEnabled !== false).map((r) => tokenKey(r.toChainId, r.toAddress ?? "")));
506
+ }
507
+ function laneKeys(routes) {
508
+ return new Set(routes.filter((r) => r.isEnabled !== false).map((r) => laneKey(r.fromChainId, r.fromAddress ?? "", r.toChainId, r.toAddress ?? "")));
509
+ }
510
+ function executionChainIds(chains) {
511
+ return new Set(chains.filter((c) => c.isEnabled !== false && c.isExecutionChain === true).map((c) => Number(c.chainId)));
512
+ }
513
+ function hubDeliverableSymbols(tokens, execution) {
514
+ return new Set(tokens.filter((t) => execution.has(Number(t.chainId))).map((t) => symbolKey(t.symbol)));
515
+ }
516
+ function isSourceToken(token, ctx) {
517
+ const chainId = Number(token.chainId);
518
+ if (!ctx.sourceChains.has(chainId)) return false;
519
+ return ctx.execution.has(chainId) || !isKnownUnbridgeable(token.bridge) && ctx.source.has(tokenKey(chainId, token.address));
520
+ }
521
+ function directLaneOK(token, source, lanes) {
522
+ if (!source || !lanes) return true;
523
+ if (symbolKey(source.symbol) !== symbolKey(token.symbol)) return true;
524
+ if (Number(source.chainId) === Number(token.chainId)) return true;
525
+ return lanes.has(laneKey(source.chainId, source.address, token.chainId, token.address));
526
+ }
527
+ function brokenLaneFor(token, source, brokenLanes) {
528
+ if (!source || !brokenLanes) return void 0;
529
+ return brokenLanes.get(laneKey(source.chainId, source.address, token.chainId, token.address));
530
+ }
531
+ function destinationAvailability(token, ctx, source) {
532
+ if (brokenLaneFor(token, source ?? void 0, ctx.brokenLanes)) return "unreachable";
533
+ if (ctx.execution.has(Number(token.chainId))) return "available";
534
+ if (token.isChainedDestination === true) return "available";
535
+ if (!isKnownUnbridgeable(token.bridge) && ctx.destination.has(tokenKey(token.chainId, token.address)) && directLaneOK(token, source ?? void 0, ctx.lanes)) {
536
+ return "available";
537
+ }
538
+ return ctx.hubSymbols.has(symbolKey(token.symbol)) ? "hub-only" : "unreachable";
539
+ }
540
+ function hasReachableDestination(source, catalogue, ctx) {
541
+ if (catalogue.length === 0) return true;
542
+ const from = tokenKey(source.chainId, source.address);
543
+ for (const candidate of catalogue) {
544
+ if (tokenKey(candidate.chainId, candidate.address) === from) continue;
545
+ if (destinationAvailability(candidate, ctx, source) === "available") return true;
546
+ }
547
+ return false;
548
+ }
549
+ function buildCatalogue(input) {
550
+ const { chains, tokens, routes, supportedChainIds, brokenLanes } = input;
551
+ const product = input.product ?? "stable";
552
+ const universe = productAssets(product);
553
+ const allowedAssets = input.allowedAssets ? new Set([...input.allowedAssets].filter((a) => universe.has(a))) : universe;
554
+ const enabledChains = chains.filter((c) => c.isEnabled !== false);
555
+ const registryChainIds = new Set(enabledChains.map((c) => Number(c.chainId)));
556
+ const sourceChains = new Set([...registryChainIds].filter((id) => supportedChainIds.has(id)));
557
+ const execution = executionChainIds(enabledChains);
558
+ const projected = product === "rwa" ? routes.filter((route) => route.isEnabled !== false) : executableRoutes(routes);
559
+ const source = sourceKeys(projected);
560
+ const destination = destinationKeys(projected);
561
+ const lanes = laneKeys(projected);
562
+ const chainIds = new Set(sourceChains);
563
+ for (const route of projected) {
564
+ const id = Number(route.toChainId);
565
+ if (Number.isSafeInteger(id) && id > 0) chainIds.add(id);
566
+ }
567
+ const allowed = tokens.filter((token) => token.isEnabled !== false && allowedAssets.has(symbolKey(token.symbol)));
568
+ const projectedCatalogue = allowed.filter((token) => {
569
+ if (!chainIds.has(Number(token.chainId))) return false;
570
+ if (product === "rwa") return true;
571
+ if (!isExecutableBridge(token)) return false;
572
+ const key = tokenKey(token.chainId, token.address);
573
+ return source.has(key) || destination.has(key) || execution.has(Number(token.chainId));
574
+ });
575
+ const ready = chains.length > 0 && routes.length > 0 && projectedCatalogue.length > 0;
576
+ const catalogue = ready ? projectedCatalogue : allowed;
577
+ const hubSymbols = hubDeliverableSymbols(catalogue, execution);
578
+ const ctx = { source, destination, lanes, execution, sourceChains, hubSymbols, ...brokenLanes ? { brokenLanes } : {} };
579
+ const sources = ready ? catalogue.filter((token) => isSourceToken(token, ctx) && hasReachableDestination(token, catalogue, ctx)) : (
580
+ // Unprojected: the only rule we can still apply with confidence is the escrow-chain bound,
581
+ // which comes from this build's own pins rather than from the registry.
582
+ catalogue.filter((token) => sourceChains.has(Number(token.chainId)))
583
+ );
584
+ const byId = new Map(enabledChains.map((c) => [Number(c.chainId), c]));
585
+ for (const id of chainIds) if (!byId.has(id)) byId.set(id, { chainId: id, isEnabled: true });
586
+ return { ...ctx, product, tokens: catalogue, sources, chainIds, chains: [...byId.values()], ready };
587
+ }
588
+
336
589
  // src/core/options.ts
337
590
  function chainNameOf(chainId, chains) {
338
591
  const chain = chains.find((item) => Number(item.chainId) === Number(chainId));
339
- return chain?.displayName || chain?.name || `Chain ${chainId}`;
592
+ return chain?.displayName || chain?.name || CHAIN_DISPLAY_NAMES[Number(chainId)] || `Chain ${chainId}`;
340
593
  }
341
594
  function chainById(chains, chainId) {
342
595
  return chains.find((chain) => Number(chain.chainId) === Number(chainId)) || null;
@@ -357,45 +610,57 @@ function findToken(tokens, chainId, symbol) {
357
610
  const key = symbolKey(symbol);
358
611
  return tokens.find((token) => tokenEnabled(token) && Number(token.chainId) === Number(chainId) && symbolKey(token.symbol) === key) || null;
359
612
  }
360
- function buildPayOptions({ invoiceAsset, invoiceChainId, tokens, routes, chains, walletChainId }) {
613
+ function buildPayOptions({ invoiceAsset, invoiceChainId, tokens, routes, chains, walletChainId, catalogue }) {
361
614
  const invoiceKey = symbolKey(invoiceAsset);
362
- const tokenBySymbolAndChain = /* @__PURE__ */ new Map();
363
- for (const token of tokens) {
364
- if (!tokenEnabled(token)) continue;
365
- const key = symbolKey(token.symbol);
366
- if (!tokenBySymbolAndChain.has(key)) tokenBySymbolAndChain.set(key, /* @__PURE__ */ new Map());
367
- tokenBySymbolAndChain.get(key).set(Number(token.chainId), token);
368
- }
615
+ const invoiceChain = Number(invoiceChainId);
616
+ const live = catalogue?.ready ? catalogue : null;
617
+ const destinationToken = findToken(tokens, invoiceChain, invoiceKey);
369
618
  const routeBridge = /* @__PURE__ */ new Map();
370
619
  for (const route of routes || []) {
371
- if (route.isEnabled === false || Number(route.toChainId) !== Number(invoiceChainId)) continue;
620
+ if (route.isEnabled === false || Number(route.toChainId) !== invoiceChain) continue;
372
621
  routeBridge.set(`${symbolKey(route.tokenName || route.tokenId)}:${Number(route.fromChainId)}`, route.bridge);
373
622
  routeBridge.set(`${symbolKey(route.tokenId)}:${Number(route.fromChainId)}`, route.bridge);
374
623
  }
375
- const receiveDeliverable = isDeliverable(invoiceKey, invoiceChainId);
376
- const options = [];
377
- for (const [payKey, byChain] of tokenBySymbolAndChain.entries()) {
378
- if (!byChain.has(Number(invoiceChainId))) continue;
379
- for (const [chainId, token] of byChain.entries()) {
380
- const chain = chainById(chains, chainId);
381
- if (!chainSelectable(chain, chainId)) continue;
382
- const direct = chainId === Number(invoiceChainId) && payKey === invoiceKey;
383
- if (!direct && payKey === invoiceKey) continue;
384
- if (!direct && (!receiveDeliverable || !isDeliverable(payKey, chainId))) continue;
385
- options.push({
386
- symbol: token.symbol,
387
- symbolKey: payKey,
388
- name: token.name || token.symbol,
389
- chainId,
390
- chainName: chainNameOf(chainId, chains),
391
- address: token.address,
392
- decimals: assetDecimals(token),
393
- logoUrl: token.logoUrl,
394
- bridge: routeBridge.get(`${payKey}:${chainId}`) || token.bridge,
395
- sameChain: chainId === Number(invoiceChainId),
396
- direct
397
- });
624
+ const knownLanes = live?.lanes && live.lanes.size > 0 ? live.lanes : null;
625
+ function refusal(token) {
626
+ const sameSymbol = symbolKey(token.symbol) === invoiceKey;
627
+ const sameChain = Number(token.chainId) === invoiceChain;
628
+ if (sameSymbol && sameChain) return null;
629
+ if (live && destinationToken && brokenLaneFor(destinationToken, token, live.brokenLanes)) return "measured";
630
+ if (live && !isSourceToken(token, live)) return "not-a-source";
631
+ if (sameSymbol && knownLanes && !knownLanes.has(laneKey(token.chainId, token.address, invoiceChain, destinationToken?.address ?? ""))) {
632
+ return "no-direct-lane";
398
633
  }
634
+ if (live && destinationToken && destinationAvailability(destinationToken, live, token) !== "available") return "undeliverable";
635
+ return null;
636
+ }
637
+ const options = [];
638
+ const seen = /* @__PURE__ */ new Set();
639
+ const universe = live ? live.tokens : tokens;
640
+ for (const token of universe) {
641
+ if (!tokenEnabled(token)) continue;
642
+ const chainId = Number(token.chainId);
643
+ const chain = chainById(chains, chainId);
644
+ if (!chainSelectable(chain, chainId)) continue;
645
+ const key = tokenKey(chainId, token.address);
646
+ if (seen.has(key)) continue;
647
+ if (refusal(token)) continue;
648
+ seen.add(key);
649
+ const payKey = symbolKey(token.symbol);
650
+ const direct = chainId === invoiceChain && payKey === invoiceKey;
651
+ options.push({
652
+ symbol: token.symbol,
653
+ symbolKey: payKey,
654
+ name: token.name || token.symbol,
655
+ chainId,
656
+ chainName: chainNameOf(chainId, chains),
657
+ address: token.address,
658
+ decimals: assetDecimals(token),
659
+ logoUrl: token.logoUrl,
660
+ bridge: routeBridge.get(`${payKey}:${chainId}`) || token.bridge,
661
+ sameChain: chainId === invoiceChain,
662
+ direct
663
+ });
399
664
  }
400
665
  options.sort((a, b) => {
401
666
  const walletChain = Number(walletChainId || 0);
@@ -454,6 +719,36 @@ function nativeFeeShortMessage(check, symbol, chainName) {
454
719
  return `This route bridges via LayerZero, which charges a ${need} ${symbol} network fee paid as part of the transaction. Your wallet holds ${have} ${symbol}${where}. Add ${symbol}${where} and try again \u2014 gas is owed on top of this fee.`;
455
720
  }
456
721
 
722
+ // src/core/route-health.ts
723
+ var EMPTY = /* @__PURE__ */ new Map();
724
+ function suppressedLanes(health) {
725
+ if (health?.mode !== "enforce" || !Array.isArray(health.lanes)) return EMPTY;
726
+ const out = /* @__PURE__ */ new Map();
727
+ for (const lane of health.lanes) {
728
+ if (lane?.status !== "broken") continue;
729
+ const key = typeof lane.laneKey === "string" ? lane.laneKey.toLowerCase() : "";
730
+ if (!key) continue;
731
+ out.set(key, {
732
+ route: typeof lane.route === "string" ? lane.route : "",
733
+ code: typeof lane.code === "string" ? lane.code : "",
734
+ message: typeof lane.message === "string" ? lane.message : "",
735
+ ...typeof lane.kind === "string" ? { kind: lane.kind } : {}
736
+ });
737
+ }
738
+ return out;
739
+ }
740
+ function brokenLaneReason(lane) {
741
+ if (!lane) return "";
742
+ switch (lane.kind) {
743
+ case "bridge-throttled":
744
+ return "The issuer's bridge for this pair is closed right now.";
745
+ case "vault-closed":
746
+ return "This vault is not accepting deposits right now.";
747
+ default:
748
+ return "ZeroDelta could not price this pair in its latest check.";
749
+ }
750
+ }
751
+
457
752
  // src/core/solve.ts
458
753
  async function solveExactOut({ option, destination, destinationToken, payer, fetchQuote }) {
459
754
  const destDecimals = assetDecimals(destinationToken);
@@ -896,7 +1191,8 @@ function createApiClient(cfg) {
896
1191
  const cache = {
897
1192
  chains: null,
898
1193
  tokens: null,
899
- routes: null
1194
+ routes: null,
1195
+ health: null
900
1196
  };
901
1197
  const apiBase = cfg.apiBase.replace(/\/$/, "");
902
1198
  async function apiRequest(path, init = {}) {
@@ -966,6 +1262,18 @@ function createApiClient(cfg) {
966
1262
  return [];
967
1263
  }
968
1264
  }
1265
+ async function fetchRouteHealth() {
1266
+ if (nowFresh(cache.health)) return cache.health.value;
1267
+ let value = null;
1268
+ try {
1269
+ const health = await apiRequest("/route-health", { timeoutMs: 8e3 });
1270
+ value = health && typeof health === "object" && !Array.isArray(health) ? health : null;
1271
+ } catch {
1272
+ value = null;
1273
+ }
1274
+ cache.health = { at: Date.now(), value };
1275
+ return value;
1276
+ }
969
1277
  async function fetchQuote(body, retries = 1) {
970
1278
  let lastError;
971
1279
  for (let attempt = 0; attempt <= retries; attempt += 1) {
@@ -980,7 +1288,7 @@ function createApiClient(cfg) {
980
1288
  }
981
1289
  throw lastError;
982
1290
  }
983
- return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchQuote, apiBase };
1291
+ return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchQuote, apiBase };
984
1292
  }
985
1293
 
986
1294
  // src/core/plan.ts
@@ -998,7 +1306,7 @@ function validateDestination(destination) {
998
1306
  assertAddress(destination.address, "Destination address");
999
1307
  const chainId = Number(destination.chainId);
1000
1308
  const asset = symbolKey(destination.asset);
1001
- if (!SUPPORTED_CHAIN_IDS.has(chainId)) throw new Error("Unsupported destination chain.");
1309
+ if (!Number.isSafeInteger(chainId) || chainId <= 0) throw new Error("Unsupported destination chain.");
1002
1310
  if (!SUPPORTED_ASSETS.has(asset)) throw new Error("Unsupported destination asset.");
1003
1311
  const normalizedAmount = normalizeDecimalText(destination.amount);
1004
1312
  if (!/^\d+(\.\d+)?$/.test(normalizedAmount)) throw new Error("Could not detect a valid payment amount.");
@@ -1012,7 +1320,15 @@ function planErrorSummary(errors) {
1012
1320
  async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances) {
1013
1321
  validateDestination(request);
1014
1322
  assertAddress(payer, "Payer wallet");
1015
- const [chains, tokens, routes] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes()]);
1323
+ const [chains, tokens, routes, health] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes(), api.fetchRouteHealth()]);
1324
+ const catalogue = buildCatalogue({
1325
+ chains,
1326
+ tokens,
1327
+ routes,
1328
+ product: "stable",
1329
+ supportedChainIds: SUPPORTED_CHAIN_IDS,
1330
+ brokenLanes: suppressedLanes(health)
1331
+ });
1016
1332
  const destination = {
1017
1333
  ...request,
1018
1334
  chainId: Number(request.chainId),
@@ -1027,7 +1343,8 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
1027
1343
  tokens,
1028
1344
  routes,
1029
1345
  chains,
1030
- walletChainId: wallet?.chainId
1346
+ walletChainId: wallet?.chainId,
1347
+ catalogue
1031
1348
  }).filter((option) => option.direct || !allowedFunding || allowedFunding.has(option.symbolKey));
1032
1349
  if (!options.length) throw new Error(`No enabled ZeroDelta funding assets can settle ${destination.asset} on ${chainNameOf(destination.chainId, chains)}.`);
1033
1350
  const balanceTargets = [];
@@ -1109,7 +1426,8 @@ function validateSwap(swap = {}) {
1109
1426
  const toChainId = Number(swap.toChainId);
1110
1427
  const fromToken = symbolKey(swap.fromToken);
1111
1428
  const toToken = symbolKey(swap.toToken);
1112
- if (!SUPPORTED_CHAIN_IDS.has(fromChainId) || !SUPPORTED_CHAIN_IDS.has(toChainId)) throw new Error("Unsupported swap chain.");
1429
+ if (!SUPPORTED_CHAIN_IDS.has(fromChainId)) throw new Error("Unsupported swap chain.");
1430
+ if (!Number.isSafeInteger(toChainId) || toChainId <= 0) throw new Error("Unsupported swap chain.");
1113
1431
  if (!SUPPORTED_ASSETS.has(fromToken) || !SUPPORTED_ASSETS.has(toToken)) throw new Error("Unsupported swap asset.");
1114
1432
  const amountIn = normalizeDecimalText(swap.amountIn);
1115
1433
  if (!/^\d+(\.\d+)?$/.test(amountIn) || Number(amountIn) <= 0 || Number(amountIn) > 1e9) throw new Error("Enter a valid swap amount.");
@@ -1271,7 +1589,7 @@ async function allowanceCovers(tx, account, ethCall) {
1271
1589
  var STABLEGENIE_INTENT_VERSION = 1;
1272
1590
  var STABLEGENIE_INTENT_TTL_MS = 5 * 60 * 1e3;
1273
1591
  var STABLEGENIE_SUPPORTED_CHAIN_IDS = Object.freeze([1, 10, 130, 146, 8453, 9745, 57073, 42161, 98866]);
1274
- var STABLEGENIE_SUPPORTED_ASSETS = Object.freeze(["USDC", "USDE", "USDT", "XAUT"]);
1592
+ var STABLEGENIE_SUPPORTED_ASSETS = Object.freeze(["USDC", "USDT", "USDE", "USDTB", "AUSD", "PYUSD", "USDG", "USD1", "WM", "USDS", "DAI", "RLUSD", "XAUT", "NALPHA", "NTBILL", "NBASIS", "NCREDIT", "NOPAL", "NWISDOM", "NACRDX", "NLCRD", "NAXI", "NCLOA", "NFALCON", "DEJAAA", "DESPXA"]);
1275
1593
  var stableGenieIntentSchema = {
1276
1594
  type: "object",
1277
1595
  additionalProperties: false,
@@ -1301,7 +1619,10 @@ var stableGenieIntentSchema = {
1301
1619
  required: ["address", "chainId", "asset", "amount"],
1302
1620
  properties: {
1303
1621
  address: { type: "string", pattern: "^0x[a-fA-F0-9]{40}$" },
1304
- chainId: { type: "integer", enum: STABLEGENIE_SUPPORTED_CHAIN_IDS },
1622
+ // A DESTINATION chain, so it is bounded by shape, not by the escrow-chain list: a payment may
1623
+ // be delivered on any chain the gateway publishes a route to (~31 of them), while only the
1624
+ // nine escrow chains can SEND one. See validateDestination in plan.ts.
1625
+ chainId: { type: "integer", minimum: 1 },
1305
1626
  chainName: { type: "string", maxLength: 64 },
1306
1627
  asset: { type: "string", enum: STABLEGENIE_SUPPORTED_ASSETS },
1307
1628
  amount: { type: "string", pattern: "^(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$" }
@@ -1607,7 +1928,26 @@ function createEngine(config = {}) {
1607
1928
  fetchChains: api.fetchChains,
1608
1929
  fetchTokens: api.fetchTokens,
1609
1930
  fetchRoutes: api.fetchRoutes,
1931
+ fetchRouteHealth: api.fetchRouteHealth,
1610
1932
  fetchQuote: api.fetchQuote,
1933
+ fetchCatalogue: async (allowedAssets, product) => {
1934
+ const [chains, tokens, routes, health] = await Promise.all([
1935
+ api.fetchChains().catch(() => []),
1936
+ api.fetchTokens().catch(() => []),
1937
+ api.fetchRoutes().catch(() => []),
1938
+ api.fetchRouteHealth()
1939
+ ]);
1940
+ const allowed = allowedAssets?.length ? new Set([...allowedAssets].map(symbolKey).filter((a) => SUPPORTED_ASSETS.has(a))) : void 0;
1941
+ return buildCatalogue({
1942
+ chains,
1943
+ tokens,
1944
+ routes,
1945
+ product,
1946
+ ...allowed ? { allowedAssets: allowed } : {},
1947
+ supportedChainIds: SUPPORTED_CHAIN_IDS,
1948
+ brokenLanes: suppressedLanes(health)
1949
+ });
1950
+ },
1611
1951
  fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet, verifier.readBalances),
1612
1952
  quoteSwapPreview: (swap, owner) => quoteSwapPreview(api, swap, owner),
1613
1953
  buildSwapPlan: (swap, payer, wallet) => buildSwapPlan(api, swap, payer, wallet),
@@ -1626,4 +1966,4 @@ function createEngine(config = {}) {
1626
1966
  };
1627
1967
  }
1628
1968
 
1629
- export { API_CACHE_TTL_MS, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, isAddress, isDeliverable, isHexAddress, isHexData, isHexQuantity, isLayerZeroRoute, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, normalizeOrderRequests, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, txMatchesPlan, uint64Word, uintWord, validateDestination, validatePlannedTransaction, validateSwap };
1969
+ export { API_CACHE_TTL_MS, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CHAIN_DISPLAY_NAMES, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, STABLE_ASSETS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetClassOf, assetDecimals, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, counterpartTokens, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, destinationAvailability, destinationKeys, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, executableRoutes, executionChainIds, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, hasReachableDestination, hubDeliverableSymbols, isAddress, isDeliverable, isExecutableBridge, isHexAddress, isHexData, isHexQuantity, isKnownUnbridgeable, isLayerZeroRoute, isSourceToken, laneKey, laneKeys, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, normalizeOrderRequests, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, productAssets, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, toHexQuantity, tokenEnabled, tokenKey, txMatchesPlan, uint64Word, uintWord, validateDestination, validatePlannedTransaction, validateSwap };