@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.
package/dist/index.cjs CHANGED
@@ -568,6 +568,10 @@ function brokenLaneFor(token, source, brokenLanes) {
568
568
  if (!source || !brokenLanes) return void 0;
569
569
  return brokenLanes.get(laneKey(source.chainId, source.address, token.chainId, token.address));
570
570
  }
571
+ function laneLimitFor(token, source, limitedLanes2) {
572
+ if (!source || !limitedLanes2) return void 0;
573
+ return limitedLanes2.get(laneKey(source.chainId, source.address, token.chainId, token.address));
574
+ }
571
575
  function destinationAvailability(token, ctx, source) {
572
576
  if (brokenLaneFor(token, source ?? void 0, ctx.brokenLanes)) return "unreachable";
573
577
  if (directLaneOK(token, source ?? void 0, ctx.lanes)) {
@@ -623,7 +627,17 @@ function buildCatalogue(input) {
623
627
  );
624
628
  const byId = new Map(enabledChains.map((c) => [Number(c.chainId), c]));
625
629
  for (const id of chainIds) if (!byId.has(id)) byId.set(id, { chainId: id, isEnabled: true });
626
- return { ...ctx, product, tokens: catalogue, sources, chainIds, chains: [...byId.values()], ready, vaultIcons: input.vaultIcons ?? /* @__PURE__ */ new Map() };
630
+ return {
631
+ ...ctx,
632
+ product,
633
+ tokens: catalogue,
634
+ sources,
635
+ chainIds,
636
+ chains: [...byId.values()],
637
+ ready,
638
+ vaultIcons: input.vaultIcons ?? /* @__PURE__ */ new Map(),
639
+ limitedLanes: input.limitedLanes ?? /* @__PURE__ */ new Map()
640
+ };
627
641
  }
628
642
 
629
643
  // src/core/options.ts
@@ -758,23 +772,89 @@ function nativeFeeShortMessage(check, symbol, chainName3) {
758
772
 
759
773
  // src/core/route-health.ts
760
774
  var EMPTY = /* @__PURE__ */ new Map();
775
+ var NO_LIMITS = /* @__PURE__ */ new Map();
776
+ function laneAvailabilityState(lane) {
777
+ const availability = lane?.availability;
778
+ if (!availability || typeof availability !== "object") return null;
779
+ const state = availability.state;
780
+ return state === "available" || state === "limited" || state === "unavailable" ? state : null;
781
+ }
782
+ function isSuppressed(lane) {
783
+ const state = laneAvailabilityState(lane);
784
+ if (state) return state === "unavailable";
785
+ const firewalled = lane.status === "unknown" && lane.kind === "firewalled";
786
+ return lane.status === "broken" || firewalled;
787
+ }
761
788
  function suppressedLanes(health) {
762
789
  if (health?.mode !== "enforce" || !Array.isArray(health.lanes)) return EMPTY;
763
790
  const out = /* @__PURE__ */ new Map();
764
791
  for (const lane of health.lanes) {
765
- const firewalled = lane?.status === "unknown" && lane?.kind === "firewalled";
766
- if (lane?.status !== "broken" && !firewalled) continue;
792
+ if (!lane || typeof lane !== "object" || !isSuppressed(lane)) continue;
767
793
  const key = typeof lane.laneKey === "string" ? lane.laneKey.toLowerCase() : "";
768
794
  if (!key) continue;
795
+ const availability = laneAvailabilityState(lane) ? lane.availability : void 0;
796
+ const code = typeof availability?.code === "string" && availability.code ? availability.code : lane.code;
797
+ const message = typeof availability?.message === "string" && availability.message ? availability.message : lane.message;
769
798
  out.set(key, {
770
799
  route: typeof lane.route === "string" ? lane.route : "",
771
- code: typeof lane.code === "string" ? lane.code : "",
772
- message: typeof lane.message === "string" ? lane.message : "",
800
+ code: typeof code === "string" ? code : "",
801
+ message: typeof message === "string" ? message : "",
773
802
  ...typeof lane.kind === "string" ? { kind: lane.kind } : {}
774
803
  });
775
804
  }
776
805
  return out;
777
806
  }
807
+ var BASE_UNITS = /^\d{1,78}$/;
808
+ function limitedLanes(health) {
809
+ if (health?.mode !== "enforce" || !Array.isArray(health.lanes)) return NO_LIMITS;
810
+ const out = /* @__PURE__ */ new Map();
811
+ for (const lane of health.lanes) {
812
+ if (!lane || typeof lane !== "object" || laneAvailabilityState(lane) !== "limited") continue;
813
+ const key = typeof lane.laneKey === "string" ? lane.laneKey.toLowerCase() : "";
814
+ const limit = lane.availability?.limit;
815
+ if (!key || !limit || typeof limit !== "object") continue;
816
+ const side = limit.side === "bid" || limit.side === "ask" ? limit.side : null;
817
+ const maxAmount = typeof limit.maxAmount === "string" ? limit.maxAmount.trim() : "";
818
+ const decimals = limit.decimals;
819
+ if (!side || !BASE_UNITS.test(maxAmount) || typeof decimals !== "number" || !Number.isInteger(decimals) || decimals < 0 || decimals > 36) continue;
820
+ const code = lane.availability?.code;
821
+ out.set(key, {
822
+ side,
823
+ token: typeof limit.token === "string" ? limit.token : "",
824
+ fromChainId: Number(limit.fromChainId) || 0,
825
+ toChainId: Number(limit.toChainId) || 0,
826
+ maxAmount,
827
+ decimals,
828
+ code: typeof code === "string" ? code : "",
829
+ ...typeof limit.measuredAt === "string" ? { measuredAt: limit.measuredAt } : {}
830
+ });
831
+ }
832
+ return out;
833
+ }
834
+ function exceedsLaneLimit(limit, amount, bidDecimals) {
835
+ if (limit?.side !== "bid" || !BASE_UNITS.test(limit.maxAmount)) return false;
836
+ let raw;
837
+ try {
838
+ raw = parseUnitsDecimal(amount, bidDecimals);
839
+ } catch {
840
+ return false;
841
+ }
842
+ const scale = Math.max(bidDecimals, limit.decimals);
843
+ return scaleDecimals(raw, bidDecimals, scale) > scaleDecimals(BigInt(limit.maxAmount), limit.decimals, scale);
844
+ }
845
+ function laneLimitAmount(limit) {
846
+ return formatUnits(limit.maxAmount, limit.decimals);
847
+ }
848
+ function laneLimitSymbol(limit, bidTicker) {
849
+ if (limit.side === "bid" && bidTicker) return bidTicker;
850
+ return safeTicker(limit.token, limit.token);
851
+ }
852
+ function laneLimitHint(limit, symbol) {
853
+ return `Max ${laneLimitAmount(limit)}${symbol ? ` ${symbol}` : ""} right now`;
854
+ }
855
+ function laneLimitError(limit, symbol) {
856
+ return `Maximum: ${laneLimitAmount(limit)}${symbol ? ` ${symbol}` : ""} right now`;
857
+ }
778
858
  function brokenLaneReason(lane) {
779
859
  if (!lane) return "";
780
860
  switch (lane.kind) {
@@ -1669,10 +1749,18 @@ function classifyQuoteError(error) {
1669
1749
  message: `This payment was blocked by compliance screening \u2014 the recipient is ${label}. Choose a different recipient or connect a different wallet.`
1670
1750
  };
1671
1751
  }
1752
+ function amountFieldError(error) {
1753
+ const fieldErrors = error?.fieldErrors;
1754
+ if (!Array.isArray(fieldErrors)) return null;
1755
+ const entry = fieldErrors.find((e) => e && typeof e === "object" && e.field === "fromAmount" && typeof e.message === "string");
1756
+ const message = entry ? sanitizeMessage(entry.message, "") : "";
1757
+ return message || null;
1758
+ }
1672
1759
  function nowFresh(entry) {
1673
1760
  return !!entry && Date.now() - entry.at < API_CACHE_TTL_MS;
1674
1761
  }
1675
1762
  function isTransientQuoteError(error) {
1763
+ if (error?.code === "BRIDGE_RATE_LIMITED" || Array.isArray(error?.fieldErrors) && error.fieldErrors.length > 0) return false;
1676
1764
  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 || "");
1677
1765
  }
1678
1766
  function wait(ms) {
@@ -1724,6 +1812,7 @@ function createApiClient(cfg) {
1724
1812
  status: response.status,
1725
1813
  code: json?.error?.code || json?.code || (response.status >= 502 ? "gateway_timeout" : "api_error"),
1726
1814
  fieldErrors: json?.error?.fieldErrors || json?.fieldErrors,
1815
+ limits: json?.error?.limits || json?.limits,
1727
1816
  reasons: json?.error?.reasons || json?.reasons
1728
1817
  });
1729
1818
  }
@@ -2512,6 +2601,8 @@ function createEngine(config = {}) {
2512
2601
  ...allowed ? { allowedAssets: allowed } : {},
2513
2602
  supportedChainIds: SUPPORTED_CHAIN_IDS,
2514
2603
  brokenLanes: suppressedLanes(health),
2604
+ // Same read, same degraded mode: a null health response limits nothing.
2605
+ limitedLanes: limitedLanes(health),
2515
2606
  vaultIcons
2516
2607
  });
2517
2608
  },
@@ -2813,6 +2904,7 @@ function useFlow(args) {
2813
2904
  const [plan, setPlan] = react.useState(null);
2814
2905
  const [selectedId, setSelectedId] = react.useState(null);
2815
2906
  const [error, setError] = react.useState(null);
2907
+ const [fieldError, setFieldError] = react.useState(null);
2816
2908
  const [insufficient, setInsufficient] = react.useState(false);
2817
2909
  const [nativeShortfall, setNativeShortfall] = react.useState(null);
2818
2910
  const [steps, setSteps] = react.useState([]);
@@ -2827,6 +2919,7 @@ function useFlow(args) {
2827
2919
  const reload = react.useCallback(() => setNonce((n) => n + 1), []);
2828
2920
  react.useEffect(() => {
2829
2921
  if (busyRef.current) return;
2922
+ setFieldError(null);
2830
2923
  if (!enabled || !wallet.account) {
2831
2924
  setStatus("idle");
2832
2925
  setPlan(null);
@@ -2850,6 +2943,7 @@ function useFlow(args) {
2850
2943
  if (id !== reqId.current) return;
2851
2944
  setPlan(null);
2852
2945
  setError(e?.message || "Could not price this right now.");
2946
+ setFieldError(amountFieldError(e));
2853
2947
  setStatus("error");
2854
2948
  onError?.(e instanceof Error ? e : new Error(String(e)));
2855
2949
  }
@@ -3016,6 +3110,7 @@ function useFlow(args) {
3016
3110
  selected,
3017
3111
  selectRoute: setSelectedId,
3018
3112
  error,
3113
+ fieldError,
3019
3114
  insufficient,
3020
3115
  nativeShortfall,
3021
3116
  steps,
@@ -3253,6 +3348,10 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
3253
3348
  .sg-send-row{display:flex;align-items:center;gap:12px}
3254
3349
  .sg-send-row .sg-amount{flex:1 1 auto;min-width:0}
3255
3350
  .sg-send-bal{font-size:11px;color:var(--sg-text-muted);margin-top:6px}
3351
+ /* the line under the amount: a lane's current size limit (muted), or why the amount is refused (danger) */
3352
+ .sg-amount-note{font-size:12px;font-weight:600;line-height:1.35;color:var(--sg-text-muted);margin-top:6px}
3353
+ .sg-amount-note[data-tone="error"]{color:var(--sg-danger)}
3354
+ .sg-amount[aria-invalid="true"]{color:var(--sg-danger)}
3256
3355
  .sg-pct-row{display:flex;gap:8px;margin-top:12px}
3257
3356
  .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}
3258
3357
  .sg-pct:hover:not(:disabled){color:var(--sg-accent);border-color:var(--sg-accent)}
@@ -3294,6 +3393,8 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
3294
3393
  .sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
3295
3394
  .sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
3296
3395
  .sg-tokrow-hint{display:block;font-size:11px;font-weight:600;color:var(--sg-danger)}
3396
+ /* on a row that stays selectable (a limited lane): a caveat, not a refusal */
3397
+ .sg-tokrow-hint[data-tone="note"]{color:var(--sg-text-muted)}
3297
3398
  .sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
3298
3399
 
3299
3400
  /* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
@@ -3830,10 +3931,16 @@ function AmountInput(props) {
3830
3931
  placeholder: props.placeholder ?? "0.0",
3831
3932
  value: props.value,
3832
3933
  disabled: props.disabled,
3934
+ "aria-invalid": props.invalid || void 0,
3935
+ "aria-describedby": props.describedBy,
3833
3936
  onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
3834
3937
  }
3835
3938
  );
3836
3939
  }
3940
+ function AmountNote(props) {
3941
+ const error = props.tone === "error";
3942
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { id: props.id, className: "sg-amount-note", "data-tone": error ? "error" : void 0, role: error ? "alert" : void 0, children: props.children });
3943
+ }
3837
3944
  function StatusPanel(props) {
3838
3945
  const tone = props.tone ?? "neutral";
3839
3946
  return (
@@ -4442,7 +4549,7 @@ function TokenSelect(props) {
4442
4549
  ] }),
4443
4550
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-end", children: [
4444
4551
  bal ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
4445
- disabled && st?.hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-hint", children: st.hint }) : null,
4552
+ st?.hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-hint", "data-tone": disabled ? void 0 : "note", children: st.hint }) : null,
4446
4553
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
4447
4554
  ] })
4448
4555
  ]
@@ -5046,7 +5153,40 @@ function PaymentIsland(props) {
5046
5153
  const exToAsset = exTo?.symbol;
5047
5154
  const normEx = normalizeDecimalText(exAmount);
5048
5155
  const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
5049
- const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
5156
+ const [catalogue, setCatalogue] = react.useState(null);
5157
+ react.useEffect(() => {
5158
+ if (bankSettlement || !isPay && rampMode) return;
5159
+ let alive = true;
5160
+ engine.fetchCatalogue(isPay ? void 0 : exAllowed, isPay ? "stable" : exProduct).then((next) => {
5161
+ if (alive) setCatalogue(next);
5162
+ });
5163
+ return () => {
5164
+ alive = false;
5165
+ };
5166
+ }, [engine, isPay, rampMode, bankSettlement, exAllowed, exProduct]);
5167
+ const chains = react.useMemo(() => {
5168
+ const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
5169
+ return [...catalogue?.chains ?? []].sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99) || Number(a.chainId) - Number(b.chainId));
5170
+ }, [catalogue]);
5171
+ const registryTokens = react.useMemo(() => catalogue?.tokens ?? [], [catalogue]);
5172
+ const exchangeTokens = react.useMemo(() => isPay ? [] : registryTokens, [isPay, registryTokens]);
5173
+ const exSourceTokens = react.useMemo(() => isPay ? [] : catalogue?.sources ?? [], [isPay, catalogue]);
5174
+ const exFromToken = react.useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
5175
+ const exToToken = react.useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
5176
+ const exLaneLimit = react.useMemo(
5177
+ () => !isPay && !rampMode && exFromToken && exToToken ? laneLimitFor(exToToken, exFromToken, catalogue?.limitedLanes) : void 0,
5178
+ [isPay, rampMode, catalogue, exFromToken, exToToken]
5179
+ );
5180
+ const exLimitSymbol = exLaneLimit ? laneLimitSymbol(exLaneLimit, exFromToken ? tokenTicker(exFromToken) : void 0) : "";
5181
+ const exOverLimit = react.useMemo(() => {
5182
+ if (!exLaneLimit || !exFromToken || !exAmountValid) return false;
5183
+ try {
5184
+ return exceedsLaneLimit(exLaneLimit, normEx, assetDecimals(exFromToken));
5185
+ } catch {
5186
+ return false;
5187
+ }
5188
+ }, [exLaneLimit, exFromToken, exAmountValid, normEx]);
5189
+ const exQuotable = !rampMode && exAmountValid && !exOverLimit && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
5050
5190
  const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
5051
5191
  const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
5052
5192
  const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
@@ -5130,24 +5270,6 @@ function PaymentIsland(props) {
5130
5270
  }
5131
5271
  return map;
5132
5272
  }, [annotated, holdings.loading]);
5133
- const [catalogue, setCatalogue] = react.useState(null);
5134
- react.useEffect(() => {
5135
- if (bankSettlement || !isPay && rampMode) return;
5136
- let alive = true;
5137
- engine.fetchCatalogue(isPay ? void 0 : exAllowed, isPay ? "stable" : exProduct).then((next) => {
5138
- if (alive) setCatalogue(next);
5139
- });
5140
- return () => {
5141
- alive = false;
5142
- };
5143
- }, [engine, isPay, rampMode, bankSettlement, exAllowed, exProduct]);
5144
- const chains = react.useMemo(() => {
5145
- const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
5146
- return [...catalogue?.chains ?? []].sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99) || Number(a.chainId) - Number(b.chainId));
5147
- }, [catalogue]);
5148
- const registryTokens = react.useMemo(() => catalogue?.tokens ?? [], [catalogue]);
5149
- const exchangeTokens = react.useMemo(() => isPay ? [] : registryTokens, [isPay, registryTokens]);
5150
- const exSourceTokens = react.useMemo(() => isPay ? [] : catalogue?.sources ?? [], [isPay, catalogue]);
5151
5273
  const [exBalances, setExBalances] = react.useState({});
5152
5274
  const exBalReq = react.useRef(0);
5153
5275
  react.useEffect(() => {
@@ -5167,8 +5289,6 @@ function PaymentIsland(props) {
5167
5289
  if (id === exBalReq.current) setExBalances(res);
5168
5290
  });
5169
5291
  }, [engine, isPay, wallet.account, exchangeTokens]);
5170
- const exFromToken = react.useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
5171
- const exToToken = react.useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
5172
5292
  const exFromPicker = react.useMemo(() => exProduct === "rwa" ? counterpartTokens(exSourceTokens, exToToken) : exSourceTokens, [exProduct, exSourceTokens, exToToken]);
5173
5293
  const exToPicker = react.useMemo(() => exProduct === "rwa" ? counterpartTokens(exchangeTokens, exFromToken) : exchangeTokens, [exProduct, exchangeTokens, exFromToken]);
5174
5294
  const exRwaSeeded = react.useRef(false);
@@ -5193,7 +5313,11 @@ function PaymentIsland(props) {
5193
5313
  continue;
5194
5314
  }
5195
5315
  const verdict = destinationAvailability(token, catalogue, exFromToken);
5196
- if (verdict === "available") continue;
5316
+ if (verdict === "available") {
5317
+ const limit = laneLimitFor(token, exFromToken, catalogue.limitedLanes);
5318
+ if (limit) states[key] = { disabled: false, hint: laneLimitHint(limit, laneLimitSymbol(limit, exFromToken ? tokenTicker(exFromToken) : void 0)) };
5319
+ continue;
5320
+ }
5197
5321
  states[key] = {
5198
5322
  disabled: true,
5199
5323
  reason: verdict === "hub-only" ? `${tokenTicker(token)} cannot be delivered on this chain.` : "ZeroDelta cannot deliver this asset here.",
@@ -5309,6 +5433,7 @@ function PaymentIsland(props) {
5309
5433
  const exToTileRef = react.useRef(null);
5310
5434
  const regionRef = react.useRef(null);
5311
5435
  const panelId = react.useId();
5436
+ const exAmountNoteId = react.useId();
5312
5437
  react.useEffect(() => setView("main"), [wallet.account, payParamsKey]);
5313
5438
  react.useEffect(() => setHist(null), [wallet.account]);
5314
5439
  const firstRender = react.useRef(true);
@@ -5412,6 +5537,9 @@ function PaymentIsland(props) {
5412
5537
  const raw = BigInt(exFromBal.raw);
5413
5538
  setExAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(exFromToken)));
5414
5539
  };
5540
+ const exGatewayAmountError = !isPay && exQuotable && flow.status === "error" && flow.steps.length === 0 ? flow.fieldError : null;
5541
+ const exAmountError = exOverLimit && exLaneLimit ? laneLimitError(exLaneLimit, exLimitSymbol) : exGatewayAmountError;
5542
+ const exAmountNote = exAmountError || (exLaneLimit ? laneLimitHint(exLaneLimit, exLimitSymbol) : null);
5415
5543
  const exchangeControls = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5416
5544
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-ft", style: { marginTop: 12 }, children: [
5417
5545
  /* @__PURE__ */ jsxRuntime.jsx(TokenTile, { label: "From", pick: exFrom, token: exFromToken, disabled: submitting, btnRef: exFromTileRef, onClick: () => setView("from") }),
@@ -5422,8 +5550,18 @@ function PaymentIsland(props) {
5422
5550
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "Send" }),
5423
5551
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-row", children: [
5424
5552
  exFrom ? /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: exFrom.symbol, logoUrl: exFromToken?.logoUrl, chainId: exFrom.chainId, size: "sm" }) : null,
5425
- /* @__PURE__ */ jsxRuntime.jsx(AmountInput, { value: exAmount, onChange: setExAmount, disabled: submitting })
5553
+ /* @__PURE__ */ jsxRuntime.jsx(
5554
+ AmountInput,
5555
+ {
5556
+ value: exAmount,
5557
+ onChange: setExAmount,
5558
+ disabled: submitting,
5559
+ invalid: !!exAmountError,
5560
+ describedBy: exAmountNote ? exAmountNoteId : void 0
5561
+ }
5562
+ )
5426
5563
  ] }),
5564
+ exAmountNote ? /* @__PURE__ */ jsxRuntime.jsx(AmountNote, { id: exAmountNoteId, tone: exAmountError ? "error" : "neutral", children: exAmountNote }) : null,
5427
5565
  exFromBal ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-bal sg-mono", children: [
5428
5566
  "Balance: ",
5429
5567
  exFromBal.formatted,
@@ -5555,7 +5693,7 @@ function PaymentIsland(props) {
5555
5693
  lastTxOwned ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
5556
5694
  ] });
5557
5695
  } else {
5558
- const quoteError = flow.status === "error" && flow.steps.length === 0;
5696
+ const quoteError = flow.status === "error" && flow.steps.length === 0 && !exGatewayAmountError;
5559
5697
  const walletError = flow.status === "error" && flow.steps.length > 0;
5560
5698
  body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5561
5699
  /* @__PURE__ */ jsxRuntime.jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
@@ -6226,7 +6364,11 @@ function StableGenieExchange(props) {
6226
6364
  continue;
6227
6365
  }
6228
6366
  const verdict = destinationAvailability(token, catalogue, fromToken);
6229
- if (verdict === "available") continue;
6367
+ if (verdict === "available") {
6368
+ const limit = laneLimitFor(token, fromToken, catalogue.limitedLanes);
6369
+ if (limit) states[key] = { disabled: false, hint: laneLimitHint(limit, laneLimitSymbol(limit, fromToken ? tokenTicker(fromToken) : void 0)) };
6370
+ continue;
6371
+ }
6230
6372
  states[key] = {
6231
6373
  disabled: true,
6232
6374
  reason: verdict === "hub-only" ? `${tokenTicker(token)} cannot be delivered on this chain \u2014 choose an execution chain.` : "ZeroDelta cannot deliver this asset here.",
@@ -6238,9 +6380,23 @@ function StableGenieExchange(props) {
6238
6380
  const normalizedAmount = normalizeDecimalText(amount);
6239
6381
  const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
6240
6382
  const rampMode = mode !== "exchange";
6383
+ const laneLimit = react.useMemo(
6384
+ () => mode === "exchange" && fromToken && toToken ? laneLimitFor(toToken, fromToken, catalogue?.limitedLanes) : void 0,
6385
+ [mode, catalogue, fromToken, toToken]
6386
+ );
6387
+ const limitSymbol = laneLimit ? laneLimitSymbol(laneLimit, fromTicker) : "";
6388
+ const overLimit = react.useMemo(() => {
6389
+ if (!laneLimit || !fromToken || !amountValid) return false;
6390
+ try {
6391
+ return exceedsLaneLimit(laneLimit, normalizedAmount, assetDecimals(fromToken));
6392
+ } catch {
6393
+ return false;
6394
+ }
6395
+ }, [laneLimit, fromToken, amountValid, normalizedAmount]);
6396
+ const amountNoteId = react.useId();
6241
6397
  const inUniverse = (p) => Boolean(p && tokens.some((t) => Number(t.chainId) === p.chainId && symbolKey(t.symbol) === p.symbol));
6242
6398
  const cryptoReady = rampMode ? inUniverse(mode === "onramp" ? to : from) : inUniverse(from) && inUniverse(to);
6243
- const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid;
6399
+ const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid && !overLimit;
6244
6400
  const [balances, setBalances] = react.useState({});
6245
6401
  const balReq = react.useRef(0);
6246
6402
  react.useEffect(() => {
@@ -6288,7 +6444,7 @@ function StableGenieExchange(props) {
6288
6444
  engine.quoteSwapPreview({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }).then((data) => {
6289
6445
  if (id === prevReq.current) setPreview({ status: "ready", data });
6290
6446
  }).catch((e) => {
6291
- if (id === prevReq.current) setPreview({ status: "error", error: e instanceof Error ? e.message : String(e) });
6447
+ if (id === prevReq.current) setPreview({ status: "error", error: e instanceof Error ? e.message : String(e), fieldError: amountFieldError(e) });
6292
6448
  });
6293
6449
  }, 350);
6294
6450
  return () => clearTimeout(timer);
@@ -6298,6 +6454,9 @@ function StableGenieExchange(props) {
6298
6454
  const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
6299
6455
  const quoting = connected ? flow.status === "loading" : preview.status === "loading";
6300
6456
  const quoteError = !quotable ? null : connected ? flow.status === "error" ? flow.error : null : preview.status === "error" ? preview.error ?? "No route." : null;
6457
+ const gatewayAmountError = !quoteError ? null : connected ? flow.fieldError : preview.fieldError ?? null;
6458
+ const amountError = overLimit && laneLimit ? laneLimitError(laneLimit, limitSymbol) : gatewayAmountError;
6459
+ const amountNote = mode === "exchange" ? amountError || (laneLimit ? laneLimitHint(laneLimit, limitSymbol) : null) : null;
6301
6460
  const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
6302
6461
  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;
6303
6462
  const pct = (p) => {
@@ -6374,8 +6533,18 @@ function StableGenieExchange(props) {
6374
6533
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: mode === "onramp" ? `You pay (${fiatCurrency})` : "Send" }),
6375
6534
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-row", children: [
6376
6535
  mode === "onramp" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-fiat", children: FIAT.find((f) => f.code === fiatCurrency)?.glyph ?? "$" }) : from ? /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: from.symbol, logoUrl: fromToken?.logoUrl, chainId: from.chainId, size: "sm" }) : null,
6377
- /* @__PURE__ */ jsxRuntime.jsx(AmountInput, { value: amount, onChange: setAmount, disabled: submitting })
6536
+ /* @__PURE__ */ jsxRuntime.jsx(
6537
+ AmountInput,
6538
+ {
6539
+ value: amount,
6540
+ onChange: setAmount,
6541
+ disabled: submitting,
6542
+ invalid: !!amountError,
6543
+ describedBy: amountNote ? amountNoteId : void 0
6544
+ }
6545
+ )
6378
6546
  ] }),
6547
+ amountNote ? /* @__PURE__ */ jsxRuntime.jsx(AmountNote, { id: amountNoteId, tone: amountError ? "error" : "neutral", children: amountNote }) : null,
6379
6548
  mode !== "onramp" && fromBal ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-bal sg-mono", children: [
6380
6549
  "Balance: ",
6381
6550
  fromBal.formatted,
@@ -6389,7 +6558,7 @@ function StableGenieExchange(props) {
6389
6558
  ) : null
6390
6559
  ] }),
6391
6560
  rampMode ? /* @__PURE__ */ jsxRuntime.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,
6392
- !rampMode && quoteError && !wide ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: quoteError }) : null,
6561
+ !rampMode && quoteError && !gatewayAmountError && !wide ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: quoteError }) : null,
6393
6562
  !rampMode && !wide && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
6394
6563
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
6395
6564
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-anchor sg-mono", children: quoting ? "\u2026" : receive ? `${receive} ${toTicker}` : "\u2014" }),
@@ -6421,6 +6590,12 @@ function StableGenieExchange(props) {
6421
6590
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-title", children: soonLabel }),
6422
6591
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-sub", children: "Fiat rails are on the roadmap. Crypto-to-crypto exchange is live today." })
6423
6592
  ] });
6593
+ } else if (amountError) {
6594
+ side = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-noroutes", children: [
6595
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsxRuntime.jsx(RouteGlyph, {}) }),
6596
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-title", children: "Change the amount" }),
6597
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-sub", children: amountError })
6598
+ ] });
6424
6599
  } else if (quoting) {
6425
6600
  side = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6426
6601
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel" }),
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- export { B as BankPayoutAccount, E as Eip1193Provider, a as ExchangeMode, L as LinkIdentity, M as MountConfig, P as PaymentIsland, b as PaymentIslandKind, c as PaymentIslandProps, S as SettlementMethod, d as StableGenieConfig, e as StableGenieExchange, f as StableGenieExchangeProps, g as StableGeniePay, h as StableGeniePayProps, i as StableGenieProvider, j as StableGenieRwaExchange, k as StableGenieSwap, l as StableGenieSwapProps, m as StableGenieTheme, n as SuccessInfo, o as SupportedAsset, p as darkTheme, q as lightTheme, r as mount, s as resolveTheme } from './mount-Dtbtdry1.cjs';
1
+ export { B as BankPayoutAccount, E as Eip1193Provider, a as ExchangeMode, L as LinkIdentity, M as MountConfig, P as PaymentIsland, b as PaymentIslandKind, c as PaymentIslandProps, S as SettlementMethod, d as StableGenieConfig, e as StableGenieExchange, f as StableGenieExchangeProps, g as StableGeniePay, h as StableGeniePayProps, i as StableGenieProvider, j as StableGenieRwaExchange, k as StableGenieSwap, l as StableGenieSwapProps, m as StableGenieTheme, n as SuccessInfo, o as SupportedAsset, p as darkTheme, q as lightTheme, r as mount, s as resolveTheme } from './mount-Dw3LvQZi.cjs';
2
2
  import * as react from 'react';
3
- import { C as Compliance } from './verify-57gjg_dM.cjs';
4
- export { A as Availability, B as BrokenLane, a as Catalogue, b as Chain, c as ComplianceCheck, d as ComplianceTone, e as ComplianceView, E as EngineConfig, f as ExchangeProduct, P as Plan, R as Route, g as RouteLeg, h as RouteResult, S as SanitizedTxEntry, T as Token, i as TxHistoryEntry, V as VerifyResult, W as WalletScreen, j as assetClassOf, k as brokenLaneReason, l as complianceChecks, m as complianceControlsLine, n as complianceView, o as counterpartTokens, p as destinationAvailability, q as humanizeComplianceReason } from './verify-57gjg_dM.cjs';
3
+ import { C as Compliance } from './verify-CPaT8Upe.cjs';
4
+ export { A as Availability, B as BrokenLane, a as Catalogue, b as Chain, c as ComplianceCheck, d as ComplianceTone, e as ComplianceView, E as EngineConfig, f as ExchangeProduct, L as LaneLimit, P as Plan, R as Route, g as RouteLeg, h as RouteResult, S as SanitizedTxEntry, T as Token, i as TxHistoryEntry, V as VerifyResult, W as WalletScreen, j as assetClassOf, k as brokenLaneReason, l as complianceChecks, m as complianceControlsLine, n as complianceView, o as counterpartTokens, p as destinationAvailability, q as humanizeComplianceReason } from './verify-CPaT8Upe.cjs';
5
5
  export { EXECUTABLE_STABLE_ASSETS, Engine, STABLE_ASSETS, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, createEngine, symbolKey } from './core/index.cjs';
6
6
 
7
7
  declare function CompliancePanel(props: {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { B as BankPayoutAccount, E as Eip1193Provider, a as ExchangeMode, L as LinkIdentity, M as MountConfig, P as PaymentIsland, b as PaymentIslandKind, c as PaymentIslandProps, S as SettlementMethod, d as StableGenieConfig, e as StableGenieExchange, f as StableGenieExchangeProps, g as StableGeniePay, h as StableGeniePayProps, i as StableGenieProvider, j as StableGenieRwaExchange, k as StableGenieSwap, l as StableGenieSwapProps, m as StableGenieTheme, n as SuccessInfo, o as SupportedAsset, p as darkTheme, q as lightTheme, r as mount, s as resolveTheme } from './mount-Bver3O2z.js';
1
+ export { B as BankPayoutAccount, E as Eip1193Provider, a as ExchangeMode, L as LinkIdentity, M as MountConfig, P as PaymentIsland, b as PaymentIslandKind, c as PaymentIslandProps, S as SettlementMethod, d as StableGenieConfig, e as StableGenieExchange, f as StableGenieExchangeProps, g as StableGeniePay, h as StableGeniePayProps, i as StableGenieProvider, j as StableGenieRwaExchange, k as StableGenieSwap, l as StableGenieSwapProps, m as StableGenieTheme, n as SuccessInfo, o as SupportedAsset, p as darkTheme, q as lightTheme, r as mount, s as resolveTheme } from './mount-BX_B0fzO.js';
2
2
  import * as react from 'react';
3
- import { C as Compliance } from './verify-57gjg_dM.js';
4
- export { A as Availability, B as BrokenLane, a as Catalogue, b as Chain, c as ComplianceCheck, d as ComplianceTone, e as ComplianceView, E as EngineConfig, f as ExchangeProduct, P as Plan, R as Route, g as RouteLeg, h as RouteResult, S as SanitizedTxEntry, T as Token, i as TxHistoryEntry, V as VerifyResult, W as WalletScreen, j as assetClassOf, k as brokenLaneReason, l as complianceChecks, m as complianceControlsLine, n as complianceView, o as counterpartTokens, p as destinationAvailability, q as humanizeComplianceReason } from './verify-57gjg_dM.js';
3
+ import { C as Compliance } from './verify-CPaT8Upe.js';
4
+ export { A as Availability, B as BrokenLane, a as Catalogue, b as Chain, c as ComplianceCheck, d as ComplianceTone, e as ComplianceView, E as EngineConfig, f as ExchangeProduct, L as LaneLimit, P as Plan, R as Route, g as RouteLeg, h as RouteResult, S as SanitizedTxEntry, T as Token, i as TxHistoryEntry, V as VerifyResult, W as WalletScreen, j as assetClassOf, k as brokenLaneReason, l as complianceChecks, m as complianceControlsLine, n as complianceView, o as counterpartTokens, p as destinationAvailability, q as humanizeComplianceReason } from './verify-CPaT8Upe.js';
5
5
  export { EXECUTABLE_STABLE_ASSETS, Engine, STABLE_ASSETS, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, createEngine, symbolKey } from './core/index.js';
6
6
 
7
7
  declare function CompliancePanel(props: {
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { CompliancePanel, PaymentIsland, StableGenieExchange, StableGeniePay, StableGenieProvider, StableGenieRwaExchange, StableGenieSwap, darkTheme, lightTheme, mount, resolveTheme } from './chunk-OOESQYM3.js';
2
- export { EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, assetClassOf, brokenLaneReason, complianceChecks, complianceControlsLine, complianceView, counterpartTokens, createEngine, destinationAvailability, humanizeComplianceReason, symbolKey } from './chunk-FDCSZ3OY.js';
1
+ export { CompliancePanel, PaymentIsland, StableGenieExchange, StableGeniePay, StableGenieProvider, StableGenieRwaExchange, StableGenieSwap, darkTheme, lightTheme, mount, resolveTheme } from './chunk-RFBNRCFB.js';
2
+ export { EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, assetClassOf, brokenLaneReason, complianceChecks, complianceControlsLine, complianceView, counterpartTokens, createEngine, destinationAvailability, humanizeComplianceReason, symbolKey } from './chunk-PMVF6A2D.js';
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { P as Plan, V as VerifyResult, h as RouteResult, S as SanitizedTxEntry, f as ExchangeProduct } from './verify-57gjg_dM.js';
3
+ import { P as Plan, V as VerifyResult, h as RouteResult, S as SanitizedTxEntry, f as ExchangeProduct } from './verify-CPaT8Upe.js';
4
4
 
5
5
  interface Eip1193Provider {
6
6
  request(args: {
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { P as Plan, V as VerifyResult, h as RouteResult, S as SanitizedTxEntry, f as ExchangeProduct } from './verify-57gjg_dM.cjs';
3
+ import { P as Plan, V as VerifyResult, h as RouteResult, S as SanitizedTxEntry, f as ExchangeProduct } from './verify-CPaT8Upe.cjs';
4
4
 
5
5
  interface Eip1193Provider {
6
6
  request(args: {