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