@glacislabs/stablegenie-zerodelta 4.6.0 → 4.8.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/mount.cjs CHANGED
@@ -1451,6 +1451,10 @@ function routeDeltaLabel(result, quote) {
1451
1451
  if (quote.feeBps) return `${quote.feeBps} bps fee`;
1452
1452
  return "~0";
1453
1453
  }
1454
+ function quotePartnerId(quote) {
1455
+ const raw = quote.partnerId;
1456
+ return typeof raw === "string" && /^0x[0-9a-fA-F]{64}$/.test(raw) ? raw.toLowerCase() : NO_PARTNER_ID;
1457
+ }
1454
1458
  function optionTicker(option) {
1455
1459
  return option.ticker || option.symbol;
1456
1460
  }
@@ -1616,6 +1620,7 @@ async function buildRoute({
1616
1620
  }
1617
1621
  }
1618
1622
  const valueRaw = applyLayerZeroBuffer(quote, option);
1623
+ const partnerId = quotePartnerId(quote);
1619
1624
  if (!needsNativeFee) {
1620
1625
  if (valueRaw !== 0n) throw new Error("Non-LayerZero route requested a non-zero native value; refusing to sign.");
1621
1626
  } else if (valueRaw === 0n && Number(quote.executionChainId) > 0) {
@@ -1666,7 +1671,7 @@ async function buildRoute({
1666
1671
  label: "Submit ZeroDelta order",
1667
1672
  chainId: option.chainId,
1668
1673
  to: escrow,
1669
- data: encodeSubmitOrder(orders),
1674
+ data: encodeSubmitOrder(orders, partnerId),
1670
1675
  value: toHexQuantity(valueRaw),
1671
1676
  escrow,
1672
1677
  amountRaw: order.bidTokenAmount
@@ -1679,6 +1684,7 @@ async function buildRoute({
1679
1684
  gasCostSource: quote.gasCostSource,
1680
1685
  msgValue: valueRaw.toString(),
1681
1686
  deadline: order.deadline,
1687
+ partnerId: partnerId === NO_PARTNER_ID ? void 0 : partnerId,
1682
1688
  iterations: result.iterations,
1683
1689
  // Carried verbatim from the gateway's decision on THIS wallet pair. The projection used to
1684
1690
  // drop it, which is why the widget could show a price with no evidence of the control that
@@ -1693,7 +1699,7 @@ var CHANNEL_HEADER = "x-zd-channel";
1693
1699
  var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
1694
1700
  var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
1695
1701
  var WIDGET_CHANNEL = "widget";
1696
- var WIDGET_VERSION = "4.6.0" ;
1702
+ var WIDGET_VERSION = "4.8.0" ;
1697
1703
  var MAX_CHANNEL_VERSION_LEN = 32;
1698
1704
  function sanitizeVersion(raw) {
1699
1705
  const v = String(raw).trim();
@@ -2349,7 +2355,7 @@ function validatePlannedTransaction(tx, route, expectedRecipient) {
2349
2355
  if (!decoded) return false;
2350
2356
  const first = decoded.orders[0];
2351
2357
  const last = decoded.orders[decoded.orders.length - 1];
2352
- return decoded.partnerId === NO_PARTNER_ID && lower(first.bidToken) === lower(route.source.tokenAddress) && rawEquals(first.bidTokenAmount, tx.amountRaw) && lower(last.askToken) === lower(route.receive.tokenAddress) && Number(last.destinationChainId) === Number(route.receive.chainId) && lower(last.destinationReceiver) === lower(expectedRecipient);
2358
+ return decoded.partnerId === lower(route.quote?.partnerId || NO_PARTNER_ID) && lower(first.bidToken) === lower(route.source.tokenAddress) && rawEquals(first.bidTokenAmount, tx.amountRaw) && lower(last.askToken) === lower(route.receive.tokenAddress) && Number(last.destinationChainId) === Number(route.receive.chainId) && lower(last.destinationReceiver) === lower(expectedRecipient);
2353
2359
  }
2354
2360
  return false;
2355
2361
  }
@@ -3288,6 +3294,83 @@ function useHoldings(engine, account, routes, initialBalances) {
3288
3294
  return { balances, loading };
3289
3295
  }
3290
3296
 
3297
+ // src/react/ui/amount.ts
3298
+ var MAX_FRACTION_DIGITS = 8;
3299
+ function trimFraction(fixed) {
3300
+ return fixed.includes(".") ? fixed.replace(/\.?0+$/, "") : fixed;
3301
+ }
3302
+ function groupDecimal(value) {
3303
+ const match = value.match(/^([+-]?)(\d+)(\.\d+)?$/);
3304
+ if (!match) return value;
3305
+ const integer = match[2].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
3306
+ return `${match[1]}${integer}${match[3] ?? ""}`;
3307
+ }
3308
+ var SIGNIFICANT_DIGITS = 7;
3309
+ var MIN_FRACTION_DIGITS = 4;
3310
+ function formatCalculatedAmount(value, decimals) {
3311
+ let raw = typeof value === "number" ? String(value) : value.trim();
3312
+ if (typeof value === "number") {
3313
+ if (!Number.isFinite(value)) return raw;
3314
+ if (/e/i.test(raw)) {
3315
+ raw = value.toLocaleString("en-US", {
3316
+ useGrouping: false,
3317
+ maximumFractionDigits: 20
3318
+ });
3319
+ }
3320
+ }
3321
+ const match = raw.match(/^([+-]?)(\d*)(?:\.(\d*))?$/);
3322
+ if (!match) return raw;
3323
+ const negative = match[1] === "-";
3324
+ const integer = (match[2] || "0").replace(/^0+(?=\d)/, "");
3325
+ const fraction = match[3] ?? "";
3326
+ const firstNonZero = fraction.search(/[1-9]/);
3327
+ const isZero = integer === "0" && firstNonZero === -1;
3328
+ if (isZero) return "0";
3329
+ if (integer === "0" && firstNonZero >= 6) return `${negative ? "-" : ""}<0.000001`;
3330
+ const cap = decimals === void 0 || !Number.isFinite(decimals) ? MAX_FRACTION_DIGITS : Math.min(MAX_FRACTION_DIGITS, Math.max(0, Math.trunc(decimals)));
3331
+ const places = integer !== "0" ? Math.min(cap, Math.max(MIN_FRACTION_DIGITS, SIGNIFICANT_DIGITS - integer.length)) : (
3332
+ // Below one the leading zeros are not significant, so the count starts
3333
+ // at the first digit that is.
3334
+ Math.min(cap, firstNonZero + SIGNIFICANT_DIGITS)
3335
+ );
3336
+ const scale = 10n ** BigInt(places);
3337
+ const padded = fraction.padEnd(places + 1, "0");
3338
+ const kept = padded.slice(0, places);
3339
+ let rounded = BigInt(integer) * scale + BigInt(kept || "0");
3340
+ if ((padded[places] ?? "0") >= "5") rounded += 1n;
3341
+ const whole = rounded / scale;
3342
+ const remainder = rounded % scale;
3343
+ const fixed = places === 0 ? whole.toString() : `${whole}.${remainder.toString().padStart(places, "0")}`;
3344
+ const out = groupDecimal(trimFraction(fixed));
3345
+ return negative && out !== "0" ? `-${out}` : out;
3346
+ }
3347
+ function exactAmountTitle(raw, shown) {
3348
+ const full = typeof raw === "number" ? String(raw) : raw.trim();
3349
+ if (!full || /e/i.test(full)) return void 0;
3350
+ const normalized = full.includes(".") ? trimFraction(full) : full;
3351
+ const grouped = groupDecimal(normalized);
3352
+ return grouped === shown ? void 0 : grouped;
3353
+ }
3354
+ function sanitizeAmount(raw) {
3355
+ const cleaned = raw.replace(/[^0-9.]/g, "");
3356
+ const first = cleaned.indexOf(".");
3357
+ if (first === -1) return cleaned;
3358
+ return cleaned.slice(0, first + 1) + cleaned.slice(first + 1).replace(/\./g, "");
3359
+ }
3360
+ function groupAmountInput(value) {
3361
+ const point = value.indexOf(".");
3362
+ const whole = point === -1 ? value : value.slice(0, point);
3363
+ return whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (point === -1 ? "" : value.slice(point));
3364
+ }
3365
+ function groupedAmountCaret(grouped, kept) {
3366
+ if (kept <= 0) return 0;
3367
+ let seen = 0;
3368
+ for (let i = 0; i < grouped.length; i++) {
3369
+ if (grouped[i] !== "," && ++seen === kept) return i + 1;
3370
+ }
3371
+ return grouped.length;
3372
+ }
3373
+
3291
3374
  // src/react/styles.ts
3292
3375
  var WIDGET_CSS = `
3293
3376
  /* The card as the ZeroDelta widget design draws it (Figma "Widget Playground", 2026-09-30): no
@@ -4109,6 +4192,53 @@ function BrandMark({ size = 18, mono = false, className, style, title }) {
4109
4192
  }
4110
4193
  );
4111
4194
  }
4195
+ var MIN_FONT_PX = 10;
4196
+ function useFitText(ref, text) {
4197
+ react.useLayoutEffect(() => {
4198
+ const el = ref.current;
4199
+ if (!el) return;
4200
+ const fit = () => {
4201
+ el.style.fontSize = "";
4202
+ const room = el.clientWidth;
4203
+ const needed = el.scrollWidth;
4204
+ if (!room || needed <= room) return;
4205
+ const base = Number.parseFloat(getComputedStyle(el).fontSize);
4206
+ if (!Number.isFinite(base) || base <= 0) return;
4207
+ el.style.fontSize = `${Math.max(MIN_FONT_PX, Math.floor(base * room / needed))}px`;
4208
+ };
4209
+ fit();
4210
+ if (typeof ResizeObserver === "undefined") return;
4211
+ const observer = new ResizeObserver(fit);
4212
+ if (el.parentElement) observer.observe(el.parentElement);
4213
+ return () => observer.disconnect();
4214
+ }, [ref, text]);
4215
+ }
4216
+ function useGroupedAmountInput(amount, onAmount) {
4217
+ const caret = react.useRef(null);
4218
+ const [, rerender] = react.useReducer((n) => n + 1, 0);
4219
+ react.useLayoutEffect(() => {
4220
+ const pending = caret.current;
4221
+ caret.current = null;
4222
+ if (pending === null || pending.input !== document.activeElement) return;
4223
+ const at = groupedAmountCaret(pending.input.value, pending.kept);
4224
+ pending.input.setSelectionRange(at, at);
4225
+ });
4226
+ const onChange = (e) => {
4227
+ const input = e.target;
4228
+ const raw = input.value;
4229
+ caret.current = { input, kept: sanitizeAmount(raw.slice(0, input.selectionEnd ?? raw.length)).length };
4230
+ onAmount(sanitizeAmount(raw));
4231
+ rerender();
4232
+ };
4233
+ const onKeyDown = (e) => {
4234
+ const input = e.currentTarget;
4235
+ const at = input.selectionStart;
4236
+ if (at === null || at !== input.selectionEnd) return;
4237
+ if (e.key === "Backspace" && input.value[at - 1] === ",") input.setSelectionRange(at - 1, at - 1);
4238
+ else if (e.key === "Delete" && input.value[at] === ",") input.setSelectionRange(at + 1, at + 1);
4239
+ };
4240
+ return { value: groupAmountInput(amount), onChange, onKeyDown };
4241
+ }
4112
4242
  var SOURCE_CHAIN_LABELS = {
4113
4243
  1: "Ethereum",
4114
4244
  10: "Optimism",
@@ -4162,17 +4292,22 @@ function Select(props) {
4162
4292
  ] }) });
4163
4293
  }
4164
4294
  function AmountInput(props) {
4295
+ const grouped = useGroupedAmountInput(props.value, props.onChange);
4296
+ const field = react.useRef(null);
4297
+ useFitText(field, grouped.value);
4165
4298
  return /* @__PURE__ */ jsxRuntime.jsx(
4166
4299
  "input",
4167
4300
  {
4301
+ ref: field,
4168
4302
  className: "sg-input sg-amount sg-mono",
4169
4303
  inputMode: "decimal",
4170
4304
  placeholder: props.placeholder ?? "0.0",
4171
- value: props.value,
4305
+ value: grouped.value,
4172
4306
  disabled: props.disabled,
4173
4307
  "aria-invalid": props.invalid || void 0,
4174
4308
  "aria-describedby": props.describedBy,
4175
- onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
4309
+ onChange: grouped.onChange,
4310
+ onKeyDown: grouped.onKeyDown
4176
4311
  }
4177
4312
  );
4178
4313
  }
@@ -4598,11 +4733,11 @@ function QuoteGlyph({ size = 16 }) {
4598
4733
  )
4599
4734
  ] });
4600
4735
  }
4601
- function AmountText({ value, suffix }) {
4602
- const dot = value.indexOf(".");
4736
+ function AmountText({ value, suffix, exact }) {
4737
+ const dot = value.startsWith("<") ? -1 : value.indexOf(".");
4603
4738
  const whole = dot < 0 ? value : value.slice(0, dot + 1);
4604
4739
  const decimals = dot < 0 ? "" : value.slice(dot + 1);
4605
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-amt", children: [
4740
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-amt", title: exact === void 0 ? void 0 : exactAmountTitle(exact, value), children: [
4606
4741
  whole,
4607
4742
  decimals ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-dec", children: decimals }) : null,
4608
4743
  suffix ? ` ${suffix}` : null
@@ -6528,7 +6663,7 @@ function PayCard(props) {
6528
6663
  setSheet(false);
6529
6664
  requestAnimationFrame(() => complianceBtnRef.current?.focus());
6530
6665
  };
6531
- const payLabel = parked ? "Coming soon" : submitting ? "Paying\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${atLeastCents(sel.source.payAmount)} ${sel.source.ticker || sel.source.asset}` : "Pay";
6666
+ const payLabel = parked ? "Coming soon" : submitting ? "Paying\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${groupDecimal(atLeastCents(sel.source.payAmount))} ${sel.source.ticker || sel.source.asset}` : "Pay";
6532
6667
  const walletSlot = wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head-tools", children: [
6533
6668
  /* @__PURE__ */ jsxRuntime.jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
6534
6669
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-wallet", "data-connected": "true", children: [
@@ -6580,7 +6715,7 @@ function PayCard(props) {
6580
6715
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane", "data-kind": "pay", children: [
6581
6716
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pane-label", children: "You pay" }),
6582
6717
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane-mid", children: [
6583
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: loadingPlan ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : sel && selectedVisible ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: atLeastCents(sel.source.payAmount) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
6718
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: loadingPlan ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : sel && selectedVisible ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: groupDecimal(atLeastCents(sel.source.payAmount)) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) }),
6584
6719
  /* @__PURE__ */ jsxRuntime.jsx(
6585
6720
  TokenButton,
6586
6721
  {
@@ -6905,6 +7040,15 @@ function ExchangeCard(props) {
6905
7040
  () => props.defaultToChainId && props.defaultToAsset ? { chainId: props.defaultToChainId, symbol: symbolKey(props.defaultToAsset) } : null
6906
7041
  );
6907
7042
  const [amount, setAmount] = react.useState(props.defaultAmount ?? "");
7043
+ const onInputChange = react.useRef(props.onInputChange);
7044
+ onInputChange.current = props.onInputChange;
7045
+ const fromChainId = from?.chainId ?? null;
7046
+ const fromSymbol = from?.symbol ?? null;
7047
+ const toChainId = to?.chainId ?? null;
7048
+ const toSymbolKey = to?.symbol ?? null;
7049
+ react.useEffect(() => {
7050
+ onInputChange.current?.({ fromChainId, fromAsset: fromSymbol, toChainId, toAsset: toSymbolKey, amount });
7051
+ }, [fromChainId, fromSymbol, toChainId, toSymbolKey, amount]);
6908
7052
  const [fiatCurrency, setFiatCurrency] = react.useState(props.fiatCurrency ?? "EUR");
6909
7053
  const fromToken = react.useMemo(() => from ? findToken(tokens, from.chainId, from.symbol) : null, [tokens, from]);
6910
7054
  const toToken = react.useMemo(() => to ? findToken(tokens, to.chainId, to.symbol) : null, [tokens, to]);
@@ -7042,6 +7186,18 @@ function ExchangeCard(props) {
7042
7186
  const amountError = overLimit && laneLimit ? laneLimitError(laneLimit, limitSymbol) : gatewayAmountError;
7043
7187
  const amountNote = mode === "exchange" ? amountError || (laneLimit ? laneLimitHint(laneLimit, limitSymbol) : null) : null;
7044
7188
  const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
7189
+ const receiveOutRef = react.useRef(null);
7190
+ const receiveSideRef = react.useRef(null);
7191
+ const receiveShown = `${receive ?? ""}|${quoting}|${toTicker}`;
7192
+ useFitText(receiveOutRef, receiveShown);
7193
+ useFitText(receiveSideRef, receiveShown);
7194
+ const toDecimals = react.useMemo(() => {
7195
+ try {
7196
+ return toToken ? assetDecimals(toToken) : void 0;
7197
+ } catch {
7198
+ return void 0;
7199
+ }
7200
+ }, [toToken]);
7045
7201
  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;
7046
7202
  const pct = (p) => {
7047
7203
  if (!fromBal || !fromToken) return;
@@ -7235,7 +7391,7 @@ function ExchangeCard(props) {
7235
7391
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane", "data-kind": "receive", children: [
7236
7392
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-pane-label", children: product === "rwa" ? "You receive (estimated)" : "You receive" }),
7237
7393
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-pane-mid", children: [
7238
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", children: rampMode ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) : quoting ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : receive && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: receive }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "0" }) }),
7394
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-out", "aria-live": "polite", ref: receiveOutRef, children: rampMode ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2014" }) : quoting ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "\u2026" }) : receive && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: formatCalculatedAmount(receive, toDecimals), exact: receive }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-amt-empty", children: "0" }) }),
7239
7395
  receiveToken
7240
7396
  ] }),
7241
7397
  /* @__PURE__ */ jsxRuntime.jsx(PaneFoot, { usd: hasQuote ? toUsd : null })
@@ -7296,7 +7452,7 @@ function ExchangeCard(props) {
7296
7452
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv", children: [
7297
7453
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-line", children: [
7298
7454
  /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: to?.symbol ?? "", logoUrl: toToken?.logoUrl, chainId: to?.chainId, size: "xs" }),
7299
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-recv-amt", children: /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: receive, suffix: toTicker }) })
7455
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-recv-amt", ref: receiveSideRef, children: /* @__PURE__ */ jsxRuntime.jsx(AmountText, { value: formatCalculatedAmount(receive, toDecimals), exact: receive, suffix: toTicker }) })
7300
7456
  ] }),
7301
7457
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-sub", children: [
7302
7458
  "On ",
package/dist/mount.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MountConfig, s as mount } from './mount-DjeyxZcy.cjs';
1
+ export { M as MountConfig, t as mount } from './mount-Dxsc7-Fb.cjs';
2
2
  import 'react';
3
- import './verify-DSCljQtK.cjs';
3
+ import './verify-BEQ8DMvJ.cjs';
package/dist/mount.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MountConfig, s as mount } from './mount-qV6l3ZuG.js';
1
+ export { M as MountConfig, t as mount } from './mount-LkKQjoZU.js';
2
2
  import 'react';
3
- import './verify-DSCljQtK.js';
3
+ import './verify-BEQ8DMvJ.js';
package/dist/mount.js CHANGED
@@ -1,2 +1,2 @@
1
- export { mount } from './chunk-GBV2QVCH.js';
2
- import './chunk-CEBEMZHZ.js';
1
+ export { mount } from './chunk-2TCYBOYW.js';
2
+ import './chunk-F46VMTTL.js';