@glacislabs/stablegenie-zerodelta 4.2.0 → 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,15 +1749,25 @@ 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) {
1679
1767
  return new Promise((resolve) => setTimeout(resolve, ms));
1680
1768
  }
1769
+ var PAGE_LIMIT = 500;
1770
+ var MAX_PAGES = 10;
1681
1771
  function createApiClient(cfg) {
1682
1772
  const cache = {
1683
1773
  chains: null,
@@ -1689,7 +1779,7 @@ function createApiClient(cfg) {
1689
1779
  const screenCache = /* @__PURE__ */ new Map();
1690
1780
  const screenInflight = /* @__PURE__ */ new Map();
1691
1781
  const apiBase = cfg.apiBase.replace(/\/$/, "");
1692
- async function apiRequest(path, init = {}) {
1782
+ async function requestJson(path, init = {}) {
1693
1783
  const apiKey = await cfg.getApiKey();
1694
1784
  const headers = { "Content-Type": "application/json", ...init.headers || {} };
1695
1785
  if (apiKey) headers["x-api-key"] = apiKey;
@@ -1722,11 +1812,34 @@ function createApiClient(cfg) {
1722
1812
  status: response.status,
1723
1813
  code: json?.error?.code || json?.code || (response.status >= 502 ? "gateway_timeout" : "api_error"),
1724
1814
  fieldErrors: json?.error?.fieldErrors || json?.fieldErrors,
1815
+ limits: json?.error?.limits || json?.limits,
1725
1816
  reasons: json?.error?.reasons || json?.reasons
1726
1817
  });
1727
1818
  }
1819
+ return json;
1820
+ }
1821
+ async function apiRequest(path, init = {}) {
1822
+ const json = await requestJson(path, init);
1728
1823
  return json?.data ?? json;
1729
1824
  }
1825
+ async function requestAllPages(path) {
1826
+ const rows = [];
1827
+ let firstRow = "";
1828
+ for (let page = 0; page < MAX_PAGES; page += 1) {
1829
+ const json = await requestJson(`${path}${toQuery({ limit: PAGE_LIMIT, offset: rows.length || void 0 })}`);
1830
+ const envelope = json && !Array.isArray(json) ? json : {};
1831
+ const data = Array.isArray(json) ? json : envelope.data;
1832
+ const pageRows = Array.isArray(data) ? data : [];
1833
+ const head = pageRows.length ? JSON.stringify(pageRows[0]) : "";
1834
+ if (page === 0) firstRow = head;
1835
+ else if (head && head === firstRow) throw apiError(`ZeroDelta paging ignored the offset (${path}, offset ${rows.length}).`, { code: "bad_response" });
1836
+ rows.push(...pageRows);
1837
+ const total = envelope.meta?.totalCount;
1838
+ if (!envelope.paging?.next || typeof total === "number" && rows.length >= total) return rows;
1839
+ if (!pageRows.length) throw apiError(`ZeroDelta paging did not advance (${path}, offset ${rows.length}).`, { code: "bad_response" });
1840
+ }
1841
+ throw apiError(`ZeroDelta still had rows after ${MAX_PAGES} pages (${path}).`, { code: "bad_response" });
1842
+ }
1730
1843
  async function fetchChains() {
1731
1844
  if (nowFresh(cache.chains)) return cache.chains.value;
1732
1845
  const chains = await apiRequest(`/chains${toQuery({ enabledOnly: true, limit: 500 })}`);
@@ -1739,16 +1852,15 @@ function createApiClient(cfg) {
1739
1852
  }
1740
1853
  async function fetchTokens() {
1741
1854
  if (nowFresh(cache.tokens)) return cache.tokens.value;
1742
- const tokens = await apiRequest(`/tokens${toQuery({ limit: 500 })}`);
1743
- const normalized = (Array.isArray(tokens) ? tokens : []).map((token) => ({ ...token, chainId: Number(token.chainId) }));
1855
+ const tokens = await requestAllPages("/tokens");
1856
+ const normalized = tokens.map((token) => ({ ...token, chainId: Number(token.chainId) }));
1744
1857
  cache.tokens = { at: Date.now(), value: normalized };
1745
1858
  return normalized;
1746
1859
  }
1747
1860
  async function fetchRoutes() {
1748
1861
  if (nowFresh(cache.routes)) return cache.routes.value;
1749
1862
  try {
1750
- const routes = await apiRequest(`/routes${toQuery({ limit: 500 })}`);
1751
- const normalized = Array.isArray(routes) ? routes : [];
1863
+ const normalized = await requestAllPages("/routes");
1752
1864
  cache.routes = { at: Date.now(), value: normalized };
1753
1865
  return normalized;
1754
1866
  } catch {
@@ -2489,6 +2601,8 @@ function createEngine(config = {}) {
2489
2601
  ...allowed ? { allowedAssets: allowed } : {},
2490
2602
  supportedChainIds: SUPPORTED_CHAIN_IDS,
2491
2603
  brokenLanes: suppressedLanes(health),
2604
+ // Same read, same degraded mode: a null health response limits nothing.
2605
+ limitedLanes: limitedLanes(health),
2492
2606
  vaultIcons
2493
2607
  });
2494
2608
  },
@@ -2790,6 +2904,7 @@ function useFlow(args) {
2790
2904
  const [plan, setPlan] = react.useState(null);
2791
2905
  const [selectedId, setSelectedId] = react.useState(null);
2792
2906
  const [error, setError] = react.useState(null);
2907
+ const [fieldError, setFieldError] = react.useState(null);
2793
2908
  const [insufficient, setInsufficient] = react.useState(false);
2794
2909
  const [nativeShortfall, setNativeShortfall] = react.useState(null);
2795
2910
  const [steps, setSteps] = react.useState([]);
@@ -2804,6 +2919,7 @@ function useFlow(args) {
2804
2919
  const reload = react.useCallback(() => setNonce((n) => n + 1), []);
2805
2920
  react.useEffect(() => {
2806
2921
  if (busyRef.current) return;
2922
+ setFieldError(null);
2807
2923
  if (!enabled || !wallet.account) {
2808
2924
  setStatus("idle");
2809
2925
  setPlan(null);
@@ -2827,6 +2943,7 @@ function useFlow(args) {
2827
2943
  if (id !== reqId.current) return;
2828
2944
  setPlan(null);
2829
2945
  setError(e?.message || "Could not price this right now.");
2946
+ setFieldError(amountFieldError(e));
2830
2947
  setStatus("error");
2831
2948
  onError?.(e instanceof Error ? e : new Error(String(e)));
2832
2949
  }
@@ -2993,6 +3110,7 @@ function useFlow(args) {
2993
3110
  selected,
2994
3111
  selectRoute: setSelectedId,
2995
3112
  error,
3113
+ fieldError,
2996
3114
  insufficient,
2997
3115
  nativeShortfall,
2998
3116
  steps,
@@ -3230,6 +3348,10 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
3230
3348
  .sg-send-row{display:flex;align-items:center;gap:12px}
3231
3349
  .sg-send-row .sg-amount{flex:1 1 auto;min-width:0}
3232
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)}
3233
3355
  .sg-pct-row{display:flex;gap:8px;margin-top:12px}
3234
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}
3235
3357
  .sg-pct:hover:not(:disabled){color:var(--sg-accent);border-color:var(--sg-accent)}
@@ -3271,6 +3393,8 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
3271
3393
  .sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
3272
3394
  .sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
3273
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)}
3274
3398
  .sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
3275
3399
 
3276
3400
  /* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
@@ -3807,10 +3931,16 @@ function AmountInput(props) {
3807
3931
  placeholder: props.placeholder ?? "0.0",
3808
3932
  value: props.value,
3809
3933
  disabled: props.disabled,
3934
+ "aria-invalid": props.invalid || void 0,
3935
+ "aria-describedby": props.describedBy,
3810
3936
  onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
3811
3937
  }
3812
3938
  );
3813
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
+ }
3814
3944
  function StatusPanel(props) {
3815
3945
  const tone = props.tone ?? "neutral";
3816
3946
  return (
@@ -4419,7 +4549,7 @@ function TokenSelect(props) {
4419
4549
  ] }),
4420
4550
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-end", children: [
4421
4551
  bal ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
4422
- 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,
4423
4553
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
4424
4554
  ] })
4425
4555
  ]
@@ -5023,7 +5153,40 @@ function PaymentIsland(props) {
5023
5153
  const exToAsset = exTo?.symbol;
5024
5154
  const normEx = normalizeDecimalText(exAmount);
5025
5155
  const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
5026
- 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);
5027
5190
  const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
5028
5191
  const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
5029
5192
  const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
@@ -5107,24 +5270,6 @@ function PaymentIsland(props) {
5107
5270
  }
5108
5271
  return map;
5109
5272
  }, [annotated, holdings.loading]);
5110
- const [catalogue, setCatalogue] = react.useState(null);
5111
- react.useEffect(() => {
5112
- if (bankSettlement || !isPay && rampMode) return;
5113
- let alive = true;
5114
- engine.fetchCatalogue(isPay ? void 0 : exAllowed, isPay ? "stable" : exProduct).then((next) => {
5115
- if (alive) setCatalogue(next);
5116
- });
5117
- return () => {
5118
- alive = false;
5119
- };
5120
- }, [engine, isPay, rampMode, bankSettlement, exAllowed, exProduct]);
5121
- const chains = react.useMemo(() => {
5122
- const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
5123
- return [...catalogue?.chains ?? []].sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99) || Number(a.chainId) - Number(b.chainId));
5124
- }, [catalogue]);
5125
- const registryTokens = react.useMemo(() => catalogue?.tokens ?? [], [catalogue]);
5126
- const exchangeTokens = react.useMemo(() => isPay ? [] : registryTokens, [isPay, registryTokens]);
5127
- const exSourceTokens = react.useMemo(() => isPay ? [] : catalogue?.sources ?? [], [isPay, catalogue]);
5128
5273
  const [exBalances, setExBalances] = react.useState({});
5129
5274
  const exBalReq = react.useRef(0);
5130
5275
  react.useEffect(() => {
@@ -5144,8 +5289,6 @@ function PaymentIsland(props) {
5144
5289
  if (id === exBalReq.current) setExBalances(res);
5145
5290
  });
5146
5291
  }, [engine, isPay, wallet.account, exchangeTokens]);
5147
- const exFromToken = react.useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
5148
- const exToToken = react.useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
5149
5292
  const exFromPicker = react.useMemo(() => exProduct === "rwa" ? counterpartTokens(exSourceTokens, exToToken) : exSourceTokens, [exProduct, exSourceTokens, exToToken]);
5150
5293
  const exToPicker = react.useMemo(() => exProduct === "rwa" ? counterpartTokens(exchangeTokens, exFromToken) : exchangeTokens, [exProduct, exchangeTokens, exFromToken]);
5151
5294
  const exRwaSeeded = react.useRef(false);
@@ -5170,7 +5313,11 @@ function PaymentIsland(props) {
5170
5313
  continue;
5171
5314
  }
5172
5315
  const verdict = destinationAvailability(token, catalogue, exFromToken);
5173
- 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
+ }
5174
5321
  states[key] = {
5175
5322
  disabled: true,
5176
5323
  reason: verdict === "hub-only" ? `${tokenTicker(token)} cannot be delivered on this chain.` : "ZeroDelta cannot deliver this asset here.",
@@ -5286,6 +5433,7 @@ function PaymentIsland(props) {
5286
5433
  const exToTileRef = react.useRef(null);
5287
5434
  const regionRef = react.useRef(null);
5288
5435
  const panelId = react.useId();
5436
+ const exAmountNoteId = react.useId();
5289
5437
  react.useEffect(() => setView("main"), [wallet.account, payParamsKey]);
5290
5438
  react.useEffect(() => setHist(null), [wallet.account]);
5291
5439
  const firstRender = react.useRef(true);
@@ -5389,6 +5537,9 @@ function PaymentIsland(props) {
5389
5537
  const raw = BigInt(exFromBal.raw);
5390
5538
  setExAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(exFromToken)));
5391
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);
5392
5543
  const exchangeControls = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5393
5544
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-ft", style: { marginTop: 12 }, children: [
5394
5545
  /* @__PURE__ */ jsxRuntime.jsx(TokenTile, { label: "From", pick: exFrom, token: exFromToken, disabled: submitting, btnRef: exFromTileRef, onClick: () => setView("from") }),
@@ -5399,8 +5550,18 @@ function PaymentIsland(props) {
5399
5550
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "Send" }),
5400
5551
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-row", children: [
5401
5552
  exFrom ? /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: exFrom.symbol, logoUrl: exFromToken?.logoUrl, chainId: exFrom.chainId, size: "sm" }) : null,
5402
- /* @__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
+ )
5403
5563
  ] }),
5564
+ exAmountNote ? /* @__PURE__ */ jsxRuntime.jsx(AmountNote, { id: exAmountNoteId, tone: exAmountError ? "error" : "neutral", children: exAmountNote }) : null,
5404
5565
  exFromBal ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-bal sg-mono", children: [
5405
5566
  "Balance: ",
5406
5567
  exFromBal.formatted,
@@ -5532,7 +5693,7 @@ function PaymentIsland(props) {
5532
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
5533
5694
  ] });
5534
5695
  } else {
5535
- const quoteError = flow.status === "error" && flow.steps.length === 0;
5696
+ const quoteError = flow.status === "error" && flow.steps.length === 0 && !exGatewayAmountError;
5536
5697
  const walletError = flow.status === "error" && flow.steps.length > 0;
5537
5698
  body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5538
5699
  /* @__PURE__ */ jsxRuntime.jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
@@ -6203,7 +6364,11 @@ function StableGenieExchange(props) {
6203
6364
  continue;
6204
6365
  }
6205
6366
  const verdict = destinationAvailability(token, catalogue, fromToken);
6206
- 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
+ }
6207
6372
  states[key] = {
6208
6373
  disabled: true,
6209
6374
  reason: verdict === "hub-only" ? `${tokenTicker(token)} cannot be delivered on this chain \u2014 choose an execution chain.` : "ZeroDelta cannot deliver this asset here.",
@@ -6215,9 +6380,23 @@ function StableGenieExchange(props) {
6215
6380
  const normalizedAmount = normalizeDecimalText(amount);
6216
6381
  const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
6217
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();
6218
6397
  const inUniverse = (p) => Boolean(p && tokens.some((t) => Number(t.chainId) === p.chainId && symbolKey(t.symbol) === p.symbol));
6219
6398
  const cryptoReady = rampMode ? inUniverse(mode === "onramp" ? to : from) : inUniverse(from) && inUniverse(to);
6220
- const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid;
6399
+ const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid && !overLimit;
6221
6400
  const [balances, setBalances] = react.useState({});
6222
6401
  const balReq = react.useRef(0);
6223
6402
  react.useEffect(() => {
@@ -6265,7 +6444,7 @@ function StableGenieExchange(props) {
6265
6444
  engine.quoteSwapPreview({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }).then((data) => {
6266
6445
  if (id === prevReq.current) setPreview({ status: "ready", data });
6267
6446
  }).catch((e) => {
6268
- 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) });
6269
6448
  });
6270
6449
  }, 350);
6271
6450
  return () => clearTimeout(timer);
@@ -6275,6 +6454,9 @@ function StableGenieExchange(props) {
6275
6454
  const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
6276
6455
  const quoting = connected ? flow.status === "loading" : preview.status === "loading";
6277
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;
6278
6460
  const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
6279
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;
6280
6462
  const pct = (p) => {
@@ -6351,8 +6533,18 @@ function StableGenieExchange(props) {
6351
6533
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: mode === "onramp" ? `You pay (${fiatCurrency})` : "Send" }),
6352
6534
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-row", children: [
6353
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,
6354
- /* @__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
+ )
6355
6546
  ] }),
6547
+ amountNote ? /* @__PURE__ */ jsxRuntime.jsx(AmountNote, { id: amountNoteId, tone: amountError ? "error" : "neutral", children: amountNote }) : null,
6356
6548
  mode !== "onramp" && fromBal ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-bal sg-mono", children: [
6357
6549
  "Balance: ",
6358
6550
  fromBal.formatted,
@@ -6366,7 +6558,7 @@ function StableGenieExchange(props) {
6366
6558
  ) : null
6367
6559
  ] }),
6368
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,
6369
- !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,
6370
6562
  !rampMode && !wide && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
6371
6563
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
6372
6564
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-anchor sg-mono", children: quoting ? "\u2026" : receive ? `${receive} ${toTicker}` : "\u2014" }),
@@ -6398,6 +6590,12 @@ function StableGenieExchange(props) {
6398
6590
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-title", children: soonLabel }),
6399
6591
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-sub", children: "Fiat rails are on the roadmap. Crypto-to-crypto exchange is live today." })
6400
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
+ ] });
6401
6599
  } else if (quoting) {
6402
6600
  side = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6403
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-KETGKV7Y.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-ZBUK7ULN.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: {