@glacislabs/stablegenie-zerodelta 4.2.1 → 4.3.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.
@@ -552,6 +552,10 @@ function brokenLaneFor(token, source, brokenLanes) {
552
552
  if (!source || !brokenLanes) return void 0;
553
553
  return brokenLanes.get(laneKey(source.chainId, source.address, token.chainId, token.address));
554
554
  }
555
+ function laneLimitFor(token, source, limitedLanes2) {
556
+ if (!source || !limitedLanes2) return void 0;
557
+ return limitedLanes2.get(laneKey(source.chainId, source.address, token.chainId, token.address));
558
+ }
555
559
  function destinationAvailability(token, ctx, source) {
556
560
  if (brokenLaneFor(token, source ?? void 0, ctx.brokenLanes)) return "unreachable";
557
561
  if (directLaneOK(token, source ?? void 0, ctx.lanes)) {
@@ -607,7 +611,17 @@ function buildCatalogue(input) {
607
611
  );
608
612
  const byId = new Map(enabledChains.map((c) => [Number(c.chainId), c]));
609
613
  for (const id of chainIds) if (!byId.has(id)) byId.set(id, { chainId: id, isEnabled: true });
610
- return { ...ctx, product, tokens: catalogue, sources, chainIds, chains: [...byId.values()], ready, vaultIcons: input.vaultIcons ?? /* @__PURE__ */ new Map() };
614
+ return {
615
+ ...ctx,
616
+ product,
617
+ tokens: catalogue,
618
+ sources,
619
+ chainIds,
620
+ chains: [...byId.values()],
621
+ ready,
622
+ vaultIcons: input.vaultIcons ?? /* @__PURE__ */ new Map(),
623
+ limitedLanes: input.limitedLanes ?? /* @__PURE__ */ new Map()
624
+ };
611
625
  }
612
626
 
613
627
  // src/core/options.ts
@@ -746,23 +760,89 @@ function nativeFeeShortMessage(check, symbol, chainName) {
746
760
 
747
761
  // src/core/route-health.ts
748
762
  var EMPTY = /* @__PURE__ */ new Map();
763
+ var NO_LIMITS = /* @__PURE__ */ new Map();
764
+ function laneAvailabilityState(lane) {
765
+ const availability = lane?.availability;
766
+ if (!availability || typeof availability !== "object") return null;
767
+ const state = availability.state;
768
+ return state === "available" || state === "limited" || state === "unavailable" ? state : null;
769
+ }
770
+ function isSuppressed(lane) {
771
+ const state = laneAvailabilityState(lane);
772
+ if (state) return state === "unavailable";
773
+ const firewalled = lane.status === "unknown" && lane.kind === "firewalled";
774
+ return lane.status === "broken" || firewalled;
775
+ }
749
776
  function suppressedLanes(health) {
750
777
  if (health?.mode !== "enforce" || !Array.isArray(health.lanes)) return EMPTY;
751
778
  const out = /* @__PURE__ */ new Map();
752
779
  for (const lane of health.lanes) {
753
- const firewalled = lane?.status === "unknown" && lane?.kind === "firewalled";
754
- if (lane?.status !== "broken" && !firewalled) continue;
780
+ if (!lane || typeof lane !== "object" || !isSuppressed(lane)) continue;
755
781
  const key = typeof lane.laneKey === "string" ? lane.laneKey.toLowerCase() : "";
756
782
  if (!key) continue;
783
+ const availability = laneAvailabilityState(lane) ? lane.availability : void 0;
784
+ const code = typeof availability?.code === "string" && availability.code ? availability.code : lane.code;
785
+ const message = typeof availability?.message === "string" && availability.message ? availability.message : lane.message;
757
786
  out.set(key, {
758
787
  route: typeof lane.route === "string" ? lane.route : "",
759
- code: typeof lane.code === "string" ? lane.code : "",
760
- message: typeof lane.message === "string" ? lane.message : "",
788
+ code: typeof code === "string" ? code : "",
789
+ message: typeof message === "string" ? message : "",
761
790
  ...typeof lane.kind === "string" ? { kind: lane.kind } : {}
762
791
  });
763
792
  }
764
793
  return out;
765
794
  }
795
+ var BASE_UNITS = /^\d{1,78}$/;
796
+ function limitedLanes(health) {
797
+ if (health?.mode !== "enforce" || !Array.isArray(health.lanes)) return NO_LIMITS;
798
+ const out = /* @__PURE__ */ new Map();
799
+ for (const lane of health.lanes) {
800
+ if (!lane || typeof lane !== "object" || laneAvailabilityState(lane) !== "limited") continue;
801
+ const key = typeof lane.laneKey === "string" ? lane.laneKey.toLowerCase() : "";
802
+ const limit = lane.availability?.limit;
803
+ if (!key || !limit || typeof limit !== "object") continue;
804
+ const side = limit.side === "bid" || limit.side === "ask" ? limit.side : null;
805
+ const maxAmount = typeof limit.maxAmount === "string" ? limit.maxAmount.trim() : "";
806
+ const decimals = limit.decimals;
807
+ if (!side || !BASE_UNITS.test(maxAmount) || typeof decimals !== "number" || !Number.isInteger(decimals) || decimals < 0 || decimals > 36) continue;
808
+ const code = lane.availability?.code;
809
+ out.set(key, {
810
+ side,
811
+ token: typeof limit.token === "string" ? limit.token : "",
812
+ fromChainId: Number(limit.fromChainId) || 0,
813
+ toChainId: Number(limit.toChainId) || 0,
814
+ maxAmount,
815
+ decimals,
816
+ code: typeof code === "string" ? code : "",
817
+ ...typeof limit.measuredAt === "string" ? { measuredAt: limit.measuredAt } : {}
818
+ });
819
+ }
820
+ return out;
821
+ }
822
+ function exceedsLaneLimit(limit, amount, bidDecimals) {
823
+ if (limit?.side !== "bid" || !BASE_UNITS.test(limit.maxAmount)) return false;
824
+ let raw;
825
+ try {
826
+ raw = parseUnitsDecimal(amount, bidDecimals);
827
+ } catch {
828
+ return false;
829
+ }
830
+ const scale = Math.max(bidDecimals, limit.decimals);
831
+ return scaleDecimals(raw, bidDecimals, scale) > scaleDecimals(BigInt(limit.maxAmount), limit.decimals, scale);
832
+ }
833
+ function laneLimitAmount(limit) {
834
+ return formatUnits(limit.maxAmount, limit.decimals);
835
+ }
836
+ function laneLimitSymbol(limit, bidTicker) {
837
+ if (limit.side === "bid" && bidTicker) return bidTicker;
838
+ return safeTicker(limit.token, limit.token);
839
+ }
840
+ function laneLimitHint(limit, symbol) {
841
+ return `Max ${laneLimitAmount(limit)}${symbol ? ` ${symbol}` : ""} right now`;
842
+ }
843
+ function laneLimitError(limit, symbol) {
844
+ return `Maximum: ${laneLimitAmount(limit)}${symbol ? ` ${symbol}` : ""} right now`;
845
+ }
766
846
  function brokenLaneReason(lane) {
767
847
  if (!lane) return "";
768
848
  switch (lane.kind) {
@@ -1657,10 +1737,18 @@ function classifyQuoteError(error) {
1657
1737
  message: `This payment was blocked by compliance screening \u2014 the recipient is ${label}. Choose a different recipient or connect a different wallet.`
1658
1738
  };
1659
1739
  }
1740
+ function amountFieldError(error) {
1741
+ const fieldErrors = error?.fieldErrors;
1742
+ if (!Array.isArray(fieldErrors)) return null;
1743
+ const entry = fieldErrors.find((e) => e && typeof e === "object" && e.field === "fromAmount" && typeof e.message === "string");
1744
+ const message = entry ? sanitizeMessage(entry.message, "") : "";
1745
+ return message || null;
1746
+ }
1660
1747
  function nowFresh(entry) {
1661
1748
  return !!entry && Date.now() - entry.at < API_CACHE_TTL_MS;
1662
1749
  }
1663
1750
  function isTransientQuoteError(error) {
1751
+ if (error?.code === "BRIDGE_RATE_LIMITED" || Array.isArray(error?.fieldErrors) && error.fieldErrors.length > 0) return false;
1664
1752
  return error?.code === "gateway_timeout" || error?.status === 502 || error?.status === 503 || error?.status === 504 || /failed to get swap quote|timeout|temporar/i.test(error?.message || "");
1665
1753
  }
1666
1754
  function wait(ms) {
@@ -1712,6 +1800,7 @@ function createApiClient(cfg) {
1712
1800
  status: response.status,
1713
1801
  code: json?.error?.code || json?.code || (response.status >= 502 ? "gateway_timeout" : "api_error"),
1714
1802
  fieldErrors: json?.error?.fieldErrors || json?.fieldErrors,
1803
+ limits: json?.error?.limits || json?.limits,
1715
1804
  reasons: json?.error?.reasons || json?.reasons
1716
1805
  });
1717
1806
  }
@@ -2555,6 +2644,8 @@ function createEngine(config = {}) {
2555
2644
  ...allowed ? { allowedAssets: allowed } : {},
2556
2645
  supportedChainIds: SUPPORTED_CHAIN_IDS,
2557
2646
  brokenLanes: suppressedLanes(health),
2647
+ // Same read, same degraded mode: a null health response limits nothing.
2648
+ limitedLanes: limitedLanes(health),
2558
2649
  vaultIcons
2559
2650
  });
2560
2651
  },
@@ -2576,4 +2667,4 @@ function createEngine(config = {}) {
2576
2667
  };
2577
2668
  }
2578
2669
 
2579
- export { API_CACHE_TTL_MS, BLOCK_LABEL_DEFAULT, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CHAIN_DISPLAY_NAMES, COMPLIANCE_CHECK_ORDER, COMPLIANCE_DENY_LABEL, DEFAULT_WIDGET_API_BASE, DIRECT_CHECK_IDS, DIRECT_SCOPE_NOTE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, FLOOR_CATEGORIES, 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, SCREENING_BUCKETS, SCREEN_CACHE_TTL_MS, 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, TUNABLE_CATEGORIES, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetClassOf, assetDecimals, blockLabelFor, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, categoryLabel, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, complianceChecks, complianceControlsEvaluated, complianceControlsLine, complianceReasonHead, complianceReasonTag, complianceTagOf, complianceView, counterpartTokens, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, destinationAvailability, destinationKeys, directComplianceFromScreens, distinctScreenedWallets, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, executableRoutes, executionChainIds, fetchPaymentPlan, finalOf, findToken, foldTicker, formatNative, formatUnits, hasReachableDestination, hubDeliverableSymbols, humanizeComplianceReason, 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, resolveVaultIcon, routeNativeValue, safeTicker, scaleDecimals, screeningOutcomeOf, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, tickerOn, toHexQuantity, tokenEnabled, tokenKey, tokenTicker, txMatchesPlan, uint64Word, uintWord, unattributedComplianceReasons, validateDestination, validatePlannedTransaction, validateSwap, vaultIconsBySymbol, withVaultArtwork };
2670
+ export { API_CACHE_TTL_MS, BLOCK_LABEL_DEFAULT, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CHAIN_DISPLAY_NAMES, COMPLIANCE_CHECK_ORDER, COMPLIANCE_DENY_LABEL, DEFAULT_WIDGET_API_BASE, DIRECT_CHECK_IDS, DIRECT_SCOPE_NOTE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, FLOOR_CATEGORIES, 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, SCREENING_BUCKETS, SCREEN_CACHE_TTL_MS, 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, TUNABLE_CATEGORIES, ZERO_ADDRESS, addressWord, allowanceCovers, amountFieldError, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetClassOf, assetDecimals, blockLabelFor, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, categoryLabel, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, complianceChecks, complianceControlsEvaluated, complianceControlsLine, complianceReasonHead, complianceReasonTag, complianceTagOf, complianceView, counterpartTokens, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, destinationAvailability, destinationKeys, directComplianceFromScreens, distinctScreenedWallets, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, exceedsLaneLimit, executableRoutes, executionChainIds, fetchPaymentPlan, finalOf, findToken, foldTicker, formatNative, formatUnits, hasReachableDestination, hubDeliverableSymbols, humanizeComplianceReason, isAddress, isDeliverable, isExecutableBridge, isHexAddress, isHexData, isHexQuantity, isKnownUnbridgeable, isLayerZeroRoute, isSourceToken, laneAvailabilityState, laneKey, laneKeys, laneLimitAmount, laneLimitError, laneLimitFor, laneLimitHint, laneLimitSymbol, limitedLanes, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, normalizeOrderRequests, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, productAssets, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, resolveVaultIcon, routeNativeValue, safeTicker, scaleDecimals, screeningOutcomeOf, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, tickerOn, toHexQuantity, tokenEnabled, tokenKey, tokenTicker, txMatchesPlan, uint64Word, uintWord, unattributedComplianceReasons, validateDestination, validatePlannedTransaction, validateSwap, vaultIconsBySymbol, withVaultArtwork };
@@ -1,4 +1,4 @@
1
- import { CHAIN_DISPLAY_NAMES, EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, complianceView, complianceChecks, DIRECT_CHECK_IDS, complianceTagOf, symbolKey, normalizeDecimalText, parseUnitsDecimal, assetDecimals, findToken, counterpartTokens, assetClassOf, brokenLaneFor, brokenLaneReason, destinationAvailability, tokenTicker, tickerOn, SUPPORTED_CHAIN_IDS, formatUnits, unattributedComplianceReasons, distinctScreenedWallets, humanizeComplianceReason, DIRECT_SCOPE_NOTE, categoryLabel, SCREENING_BUCKETS, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, foldTicker, BUNDLED_RPC } from './chunk-FDCSZ3OY.js';
1
+ import { CHAIN_DISPLAY_NAMES, EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, complianceView, complianceChecks, DIRECT_CHECK_IDS, complianceTagOf, symbolKey, normalizeDecimalText, findToken, laneLimitFor, laneLimitSymbol, tokenTicker, exceedsLaneLimit, assetDecimals, parseUnitsDecimal, counterpartTokens, assetClassOf, brokenLaneFor, brokenLaneReason, destinationAvailability, laneLimitHint, tickerOn, laneLimitError, amountFieldError, SUPPORTED_CHAIN_IDS, formatUnits, unattributedComplianceReasons, distinctScreenedWallets, humanizeComplianceReason, DIRECT_SCOPE_NOTE, categoryLabel, SCREENING_BUCKETS, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, foldTicker, BUNDLED_RPC } from './chunk-PMVF6A2D.js';
2
2
  import { createContext, useState, useRef, useEffect, useMemo, useCallback, useId, createElement, useContext } from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -290,6 +290,7 @@ function useFlow(args) {
290
290
  const [plan, setPlan] = useState(null);
291
291
  const [selectedId, setSelectedId] = useState(null);
292
292
  const [error, setError] = useState(null);
293
+ const [fieldError, setFieldError] = useState(null);
293
294
  const [insufficient, setInsufficient] = useState(false);
294
295
  const [nativeShortfall, setNativeShortfall] = useState(null);
295
296
  const [steps, setSteps] = useState([]);
@@ -304,6 +305,7 @@ function useFlow(args) {
304
305
  const reload = useCallback(() => setNonce((n) => n + 1), []);
305
306
  useEffect(() => {
306
307
  if (busyRef.current) return;
308
+ setFieldError(null);
307
309
  if (!enabled || !wallet.account) {
308
310
  setStatus("idle");
309
311
  setPlan(null);
@@ -327,6 +329,7 @@ function useFlow(args) {
327
329
  if (id !== reqId.current) return;
328
330
  setPlan(null);
329
331
  setError(e?.message || "Could not price this right now.");
332
+ setFieldError(amountFieldError(e));
330
333
  setStatus("error");
331
334
  onError?.(e instanceof Error ? e : new Error(String(e)));
332
335
  }
@@ -493,6 +496,7 @@ function useFlow(args) {
493
496
  selected,
494
497
  selectRoute: setSelectedId,
495
498
  error,
499
+ fieldError,
496
500
  insufficient,
497
501
  nativeShortfall,
498
502
  steps,
@@ -730,6 +734,10 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
730
734
  .sg-send-row{display:flex;align-items:center;gap:12px}
731
735
  .sg-send-row .sg-amount{flex:1 1 auto;min-width:0}
732
736
  .sg-send-bal{font-size:11px;color:var(--sg-text-muted);margin-top:6px}
737
+ /* the line under the amount: a lane's current size limit (muted), or why the amount is refused (danger) */
738
+ .sg-amount-note{font-size:12px;font-weight:600;line-height:1.35;color:var(--sg-text-muted);margin-top:6px}
739
+ .sg-amount-note[data-tone="error"]{color:var(--sg-danger)}
740
+ .sg-amount[aria-invalid="true"]{color:var(--sg-danger)}
733
741
  .sg-pct-row{display:flex;gap:8px;margin-top:12px}
734
742
  .sg-pct{flex:1 1 0;padding:7px 0;border-radius:var(--sg-radius-cta);border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);font:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
735
743
  .sg-pct:hover:not(:disabled){color:var(--sg-accent);border-color:var(--sg-accent)}
@@ -771,6 +779,8 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
771
779
  .sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
772
780
  .sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
773
781
  .sg-tokrow-hint{display:block;font-size:11px;font-weight:600;color:var(--sg-danger)}
782
+ /* on a row that stays selectable (a limited lane): a caveat, not a refusal */
783
+ .sg-tokrow-hint[data-tone="note"]{color:var(--sg-text-muted)}
774
784
  .sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
775
785
 
776
786
  /* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
@@ -1307,10 +1317,16 @@ function AmountInput(props) {
1307
1317
  placeholder: props.placeholder ?? "0.0",
1308
1318
  value: props.value,
1309
1319
  disabled: props.disabled,
1320
+ "aria-invalid": props.invalid || void 0,
1321
+ "aria-describedby": props.describedBy,
1310
1322
  onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
1311
1323
  }
1312
1324
  );
1313
1325
  }
1326
+ function AmountNote(props) {
1327
+ const error = props.tone === "error";
1328
+ return /* @__PURE__ */ jsx("div", { id: props.id, className: "sg-amount-note", "data-tone": error ? "error" : void 0, role: error ? "alert" : void 0, children: props.children });
1329
+ }
1314
1330
  function StatusPanel(props) {
1315
1331
  const tone = props.tone ?? "neutral";
1316
1332
  return (
@@ -1919,7 +1935,7 @@ function TokenSelect(props) {
1919
1935
  ] }),
1920
1936
  /* @__PURE__ */ jsxs("span", { className: "sg-tokrow-end", children: [
1921
1937
  bal ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
1922
- disabled && st?.hint ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-hint", children: st.hint }) : null,
1938
+ st?.hint ? /* @__PURE__ */ jsx("span", { className: "sg-tokrow-hint", "data-tone": disabled ? void 0 : "note", children: st.hint }) : null,
1923
1939
  /* @__PURE__ */ jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
1924
1940
  ] })
1925
1941
  ]
@@ -2523,7 +2539,40 @@ function PaymentIsland(props) {
2523
2539
  const exToAsset = exTo?.symbol;
2524
2540
  const normEx = normalizeDecimalText(exAmount);
2525
2541
  const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
2526
- const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
2542
+ const [catalogue, setCatalogue] = useState(null);
2543
+ useEffect(() => {
2544
+ if (bankSettlement || !isPay && rampMode) return;
2545
+ let alive = true;
2546
+ engine.fetchCatalogue(isPay ? void 0 : exAllowed, isPay ? "stable" : exProduct).then((next) => {
2547
+ if (alive) setCatalogue(next);
2548
+ });
2549
+ return () => {
2550
+ alive = false;
2551
+ };
2552
+ }, [engine, isPay, rampMode, bankSettlement, exAllowed, exProduct]);
2553
+ const chains = useMemo(() => {
2554
+ const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
2555
+ return [...catalogue?.chains ?? []].sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99) || Number(a.chainId) - Number(b.chainId));
2556
+ }, [catalogue]);
2557
+ const registryTokens = useMemo(() => catalogue?.tokens ?? [], [catalogue]);
2558
+ const exchangeTokens = useMemo(() => isPay ? [] : registryTokens, [isPay, registryTokens]);
2559
+ const exSourceTokens = useMemo(() => isPay ? [] : catalogue?.sources ?? [], [isPay, catalogue]);
2560
+ const exFromToken = useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
2561
+ const exToToken = useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
2562
+ const exLaneLimit = useMemo(
2563
+ () => !isPay && !rampMode && exFromToken && exToToken ? laneLimitFor(exToToken, exFromToken, catalogue?.limitedLanes) : void 0,
2564
+ [isPay, rampMode, catalogue, exFromToken, exToToken]
2565
+ );
2566
+ const exLimitSymbol = exLaneLimit ? laneLimitSymbol(exLaneLimit, exFromToken ? tokenTicker(exFromToken) : void 0) : "";
2567
+ const exOverLimit = useMemo(() => {
2568
+ if (!exLaneLimit || !exFromToken || !exAmountValid) return false;
2569
+ try {
2570
+ return exceedsLaneLimit(exLaneLimit, normEx, assetDecimals(exFromToken));
2571
+ } catch {
2572
+ return false;
2573
+ }
2574
+ }, [exLaneLimit, exFromToken, exAmountValid, normEx]);
2575
+ const exQuotable = !rampMode && exAmountValid && !exOverLimit && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
2527
2576
  const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
2528
2577
  const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
2529
2578
  const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
@@ -2607,24 +2656,6 @@ function PaymentIsland(props) {
2607
2656
  }
2608
2657
  return map;
2609
2658
  }, [annotated, holdings.loading]);
2610
- const [catalogue, setCatalogue] = useState(null);
2611
- useEffect(() => {
2612
- if (bankSettlement || !isPay && rampMode) return;
2613
- let alive = true;
2614
- engine.fetchCatalogue(isPay ? void 0 : exAllowed, isPay ? "stable" : exProduct).then((next) => {
2615
- if (alive) setCatalogue(next);
2616
- });
2617
- return () => {
2618
- alive = false;
2619
- };
2620
- }, [engine, isPay, rampMode, bankSettlement, exAllowed, exProduct]);
2621
- const chains = useMemo(() => {
2622
- const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
2623
- return [...catalogue?.chains ?? []].sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99) || Number(a.chainId) - Number(b.chainId));
2624
- }, [catalogue]);
2625
- const registryTokens = useMemo(() => catalogue?.tokens ?? [], [catalogue]);
2626
- const exchangeTokens = useMemo(() => isPay ? [] : registryTokens, [isPay, registryTokens]);
2627
- const exSourceTokens = useMemo(() => isPay ? [] : catalogue?.sources ?? [], [isPay, catalogue]);
2628
2659
  const [exBalances, setExBalances] = useState({});
2629
2660
  const exBalReq = useRef(0);
2630
2661
  useEffect(() => {
@@ -2644,8 +2675,6 @@ function PaymentIsland(props) {
2644
2675
  if (id === exBalReq.current) setExBalances(res);
2645
2676
  });
2646
2677
  }, [engine, isPay, wallet.account, exchangeTokens]);
2647
- const exFromToken = useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
2648
- const exToToken = useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
2649
2678
  const exFromPicker = useMemo(() => exProduct === "rwa" ? counterpartTokens(exSourceTokens, exToToken) : exSourceTokens, [exProduct, exSourceTokens, exToToken]);
2650
2679
  const exToPicker = useMemo(() => exProduct === "rwa" ? counterpartTokens(exchangeTokens, exFromToken) : exchangeTokens, [exProduct, exchangeTokens, exFromToken]);
2651
2680
  const exRwaSeeded = useRef(false);
@@ -2670,7 +2699,11 @@ function PaymentIsland(props) {
2670
2699
  continue;
2671
2700
  }
2672
2701
  const verdict = destinationAvailability(token, catalogue, exFromToken);
2673
- if (verdict === "available") continue;
2702
+ if (verdict === "available") {
2703
+ const limit = laneLimitFor(token, exFromToken, catalogue.limitedLanes);
2704
+ if (limit) states[key] = { disabled: false, hint: laneLimitHint(limit, laneLimitSymbol(limit, exFromToken ? tokenTicker(exFromToken) : void 0)) };
2705
+ continue;
2706
+ }
2674
2707
  states[key] = {
2675
2708
  disabled: true,
2676
2709
  reason: verdict === "hub-only" ? `${tokenTicker(token)} cannot be delivered on this chain.` : "ZeroDelta cannot deliver this asset here.",
@@ -2786,6 +2819,7 @@ function PaymentIsland(props) {
2786
2819
  const exToTileRef = useRef(null);
2787
2820
  const regionRef = useRef(null);
2788
2821
  const panelId = useId();
2822
+ const exAmountNoteId = useId();
2789
2823
  useEffect(() => setView("main"), [wallet.account, payParamsKey]);
2790
2824
  useEffect(() => setHist(null), [wallet.account]);
2791
2825
  const firstRender = useRef(true);
@@ -2889,6 +2923,9 @@ function PaymentIsland(props) {
2889
2923
  const raw = BigInt(exFromBal.raw);
2890
2924
  setExAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(exFromToken)));
2891
2925
  };
2926
+ const exGatewayAmountError = !isPay && exQuotable && flow.status === "error" && flow.steps.length === 0 ? flow.fieldError : null;
2927
+ const exAmountError = exOverLimit && exLaneLimit ? laneLimitError(exLaneLimit, exLimitSymbol) : exGatewayAmountError;
2928
+ const exAmountNote = exAmountError || (exLaneLimit ? laneLimitHint(exLaneLimit, exLimitSymbol) : null);
2892
2929
  const exchangeControls = /* @__PURE__ */ jsxs(Fragment, { children: [
2893
2930
  /* @__PURE__ */ jsxs("div", { className: "sg-ft", style: { marginTop: 12 }, children: [
2894
2931
  /* @__PURE__ */ jsx(TokenTile, { label: "From", pick: exFrom, token: exFromToken, disabled: submitting, btnRef: exFromTileRef, onClick: () => setView("from") }),
@@ -2899,8 +2936,18 @@ function PaymentIsland(props) {
2899
2936
  /* @__PURE__ */ jsx("div", { className: "sg-label", children: "Send" }),
2900
2937
  /* @__PURE__ */ jsxs("div", { className: "sg-send-row", children: [
2901
2938
  exFrom ? /* @__PURE__ */ jsx(TokenGlyph, { symbol: exFrom.symbol, logoUrl: exFromToken?.logoUrl, chainId: exFrom.chainId, size: "sm" }) : null,
2902
- /* @__PURE__ */ jsx(AmountInput, { value: exAmount, onChange: setExAmount, disabled: submitting })
2939
+ /* @__PURE__ */ jsx(
2940
+ AmountInput,
2941
+ {
2942
+ value: exAmount,
2943
+ onChange: setExAmount,
2944
+ disabled: submitting,
2945
+ invalid: !!exAmountError,
2946
+ describedBy: exAmountNote ? exAmountNoteId : void 0
2947
+ }
2948
+ )
2903
2949
  ] }),
2950
+ exAmountNote ? /* @__PURE__ */ jsx(AmountNote, { id: exAmountNoteId, tone: exAmountError ? "error" : "neutral", children: exAmountNote }) : null,
2904
2951
  exFromBal ? /* @__PURE__ */ jsxs("div", { className: "sg-send-bal sg-mono", children: [
2905
2952
  "Balance: ",
2906
2953
  exFromBal.formatted,
@@ -3032,7 +3079,7 @@ function PaymentIsland(props) {
3032
3079
  lastTxOwned ? /* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
3033
3080
  ] });
3034
3081
  } else {
3035
- const quoteError = flow.status === "error" && flow.steps.length === 0;
3082
+ const quoteError = flow.status === "error" && flow.steps.length === 0 && !exGatewayAmountError;
3036
3083
  const walletError = flow.status === "error" && flow.steps.length > 0;
3037
3084
  body = /* @__PURE__ */ jsxs(Fragment, { children: [
3038
3085
  /* @__PURE__ */ jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
@@ -3703,7 +3750,11 @@ function StableGenieExchange(props) {
3703
3750
  continue;
3704
3751
  }
3705
3752
  const verdict = destinationAvailability(token, catalogue, fromToken);
3706
- if (verdict === "available") continue;
3753
+ if (verdict === "available") {
3754
+ const limit = laneLimitFor(token, fromToken, catalogue.limitedLanes);
3755
+ if (limit) states[key] = { disabled: false, hint: laneLimitHint(limit, laneLimitSymbol(limit, fromToken ? tokenTicker(fromToken) : void 0)) };
3756
+ continue;
3757
+ }
3707
3758
  states[key] = {
3708
3759
  disabled: true,
3709
3760
  reason: verdict === "hub-only" ? `${tokenTicker(token)} cannot be delivered on this chain \u2014 choose an execution chain.` : "ZeroDelta cannot deliver this asset here.",
@@ -3715,9 +3766,23 @@ function StableGenieExchange(props) {
3715
3766
  const normalizedAmount = normalizeDecimalText(amount);
3716
3767
  const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
3717
3768
  const rampMode = mode !== "exchange";
3769
+ const laneLimit = useMemo(
3770
+ () => mode === "exchange" && fromToken && toToken ? laneLimitFor(toToken, fromToken, catalogue?.limitedLanes) : void 0,
3771
+ [mode, catalogue, fromToken, toToken]
3772
+ );
3773
+ const limitSymbol = laneLimit ? laneLimitSymbol(laneLimit, fromTicker) : "";
3774
+ const overLimit = useMemo(() => {
3775
+ if (!laneLimit || !fromToken || !amountValid) return false;
3776
+ try {
3777
+ return exceedsLaneLimit(laneLimit, normalizedAmount, assetDecimals(fromToken));
3778
+ } catch {
3779
+ return false;
3780
+ }
3781
+ }, [laneLimit, fromToken, amountValid, normalizedAmount]);
3782
+ const amountNoteId = useId();
3718
3783
  const inUniverse = (p) => Boolean(p && tokens.some((t) => Number(t.chainId) === p.chainId && symbolKey(t.symbol) === p.symbol));
3719
3784
  const cryptoReady = rampMode ? inUniverse(mode === "onramp" ? to : from) : inUniverse(from) && inUniverse(to);
3720
- const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid;
3785
+ const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid && !overLimit;
3721
3786
  const [balances, setBalances] = useState({});
3722
3787
  const balReq = useRef(0);
3723
3788
  useEffect(() => {
@@ -3765,7 +3830,7 @@ function StableGenieExchange(props) {
3765
3830
  engine.quoteSwapPreview({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }).then((data) => {
3766
3831
  if (id === prevReq.current) setPreview({ status: "ready", data });
3767
3832
  }).catch((e) => {
3768
- if (id === prevReq.current) setPreview({ status: "error", error: e instanceof Error ? e.message : String(e) });
3833
+ if (id === prevReq.current) setPreview({ status: "error", error: e instanceof Error ? e.message : String(e), fieldError: amountFieldError(e) });
3769
3834
  });
3770
3835
  }, 350);
3771
3836
  return () => clearTimeout(timer);
@@ -3775,6 +3840,9 @@ function StableGenieExchange(props) {
3775
3840
  const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
3776
3841
  const quoting = connected ? flow.status === "loading" : preview.status === "loading";
3777
3842
  const quoteError = !quotable ? null : connected ? flow.status === "error" ? flow.error : null : preview.status === "error" ? preview.error ?? "No route." : null;
3843
+ const gatewayAmountError = !quoteError ? null : connected ? flow.fieldError : preview.fieldError ?? null;
3844
+ const amountError = overLimit && laneLimit ? laneLimitError(laneLimit, limitSymbol) : gatewayAmountError;
3845
+ const amountNote = mode === "exchange" ? amountError || (laneLimit ? laneLimitHint(laneLimit, limitSymbol) : null) : null;
3778
3846
  const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
3779
3847
  const meta = connected ? flow.selected ? { bridge: flow.selected.quote.bridge || "ZeroDelta", feeBps: Number(flow.selected.quote.feeBps || 0), duration: Number(flow.selected.quote.estimatedDuration || 0) } : null : preview.data ? { bridge: preview.data.bridge || "ZeroDelta", feeBps: preview.data.feeBps, duration: preview.data.estimatedDuration } : null;
3780
3848
  const pct = (p) => {
@@ -3851,8 +3919,18 @@ function StableGenieExchange(props) {
3851
3919
  /* @__PURE__ */ jsx("div", { className: "sg-label", children: mode === "onramp" ? `You pay (${fiatCurrency})` : "Send" }),
3852
3920
  /* @__PURE__ */ jsxs("div", { className: "sg-send-row", children: [
3853
3921
  mode === "onramp" ? /* @__PURE__ */ jsx("span", { className: "sg-fiat", children: FIAT.find((f) => f.code === fiatCurrency)?.glyph ?? "$" }) : from ? /* @__PURE__ */ jsx(TokenGlyph, { symbol: from.symbol, logoUrl: fromToken?.logoUrl, chainId: from.chainId, size: "sm" }) : null,
3854
- /* @__PURE__ */ jsx(AmountInput, { value: amount, onChange: setAmount, disabled: submitting })
3922
+ /* @__PURE__ */ jsx(
3923
+ AmountInput,
3924
+ {
3925
+ value: amount,
3926
+ onChange: setAmount,
3927
+ disabled: submitting,
3928
+ invalid: !!amountError,
3929
+ describedBy: amountNote ? amountNoteId : void 0
3930
+ }
3931
+ )
3855
3932
  ] }),
3933
+ amountNote ? /* @__PURE__ */ jsx(AmountNote, { id: amountNoteId, tone: amountError ? "error" : "neutral", children: amountNote }) : null,
3856
3934
  mode !== "onramp" && fromBal ? /* @__PURE__ */ jsxs("div", { className: "sg-send-bal sg-mono", children: [
3857
3935
  "Balance: ",
3858
3936
  fromBal.formatted,
@@ -3866,7 +3944,7 @@ function StableGenieExchange(props) {
3866
3944
  ) : null
3867
3945
  ] }),
3868
3946
  rampMode ? /* @__PURE__ */ jsx(StatusPanel, { children: mode === "onramp" ? "Buy supported stablecoins with card or bank transfer \u2014 coming soon. Today the widget settles crypto-to-crypto." : "Cash out supported stablecoins to your bank \u2014 coming soon. Today the widget settles crypto-to-crypto." }) : null,
3869
- !rampMode && quoteError && !wide ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: quoteError }) : null,
3947
+ !rampMode && quoteError && !gatewayAmountError && !wide ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: quoteError }) : null,
3870
3948
  !rampMode && !wide && quotable && !quoteError ? /* @__PURE__ */ jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
3871
3949
  /* @__PURE__ */ jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
3872
3950
  /* @__PURE__ */ jsx("div", { className: "sg-anchor sg-mono", children: quoting ? "\u2026" : receive ? `${receive} ${toTicker}` : "\u2014" }),
@@ -3898,6 +3976,12 @@ function StableGenieExchange(props) {
3898
3976
  /* @__PURE__ */ jsx("div", { className: "sg-noroutes-title", children: soonLabel }),
3899
3977
  /* @__PURE__ */ jsx("div", { className: "sg-noroutes-sub", children: "Fiat rails are on the roadmap. Crypto-to-crypto exchange is live today." })
3900
3978
  ] });
3979
+ } else if (amountError) {
3980
+ side = /* @__PURE__ */ jsxs("div", { className: "sg-noroutes", children: [
3981
+ /* @__PURE__ */ jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsx(RouteGlyph, {}) }),
3982
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-title", children: "Change the amount" }),
3983
+ /* @__PURE__ */ jsx("div", { className: "sg-noroutes-sub", children: amountError })
3984
+ ] });
3901
3985
  } else if (quoting) {
3902
3986
  side = /* @__PURE__ */ jsxs("div", { children: [
3903
3987
  /* @__PURE__ */ jsx("div", { className: "sg-skel" }),