@glacislabs/stablegenie-zerodelta 4.3.0 → 4.5.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
@@ -1363,9 +1363,18 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
1363
1363
  // src/core/order.ts
1364
1364
  var DEFAULT_DEADLINE_SECONDS = 1800;
1365
1365
  var MAX_DEADLINE_SECONDS = 60 * 60;
1366
- function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride) {
1366
+ var ABSOLUTE_MAX_DEADLINE_SECONDS = 24 * 60 * 60;
1367
+ function recommendedDeadlineSeconds(quote) {
1368
+ const recommended = Number(quote?.recommendedDeadlineSeconds);
1369
+ if (!Number.isFinite(recommended) || recommended <= 0) return DEFAULT_DEADLINE_SECONDS;
1370
+ return Math.min(Math.floor(recommended), ABSOLUTE_MAX_DEADLINE_SECONDS);
1371
+ }
1372
+ function maxDeadlineSeconds(quote) {
1373
+ return Math.min(Math.max(MAX_DEADLINE_SECONDS, recommendedDeadlineSeconds(quote)), ABSOLUTE_MAX_DEADLINE_SECONDS);
1374
+ }
1375
+ function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride, lifetimeSeconds = DEFAULT_DEADLINE_SECONDS) {
1367
1376
  const apiDeadline = Number(order.deadline);
1368
- const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + DEFAULT_DEADLINE_SECONDS));
1377
+ const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + lifetimeSeconds));
1369
1378
  const executionChainId = String(order.executionChainId || fallbackExecutionChainId || "0");
1370
1379
  if (!/^\d+$/.test(executionChainId) || BigInt(executionChainId) <= 0n) throw new Error("ZeroDelta quote did not include an execution chain.");
1371
1380
  return {
@@ -1380,10 +1389,10 @@ function normalizeOrderRequest(order, payer, destination, fallbackExecutionChain
1380
1389
  deadline
1381
1390
  };
1382
1391
  }
1383
- function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId) {
1392
+ function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId, lifetimeSeconds = DEFAULT_DEADLINE_SECONDS) {
1384
1393
  if (!requests.length) throw new Error("ZeroDelta quote did not include any order requests.");
1385
1394
  return requests.map(
1386
- (request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
1395
+ (request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, void 0, lifetimeSeconds) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
1387
1396
  );
1388
1397
  }
1389
1398
  function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result }) {
@@ -1433,7 +1442,8 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
1433
1442
  if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
1434
1443
  throw new Error("ZeroDelta order guarantees less than the displayed receive amount.");
1435
1444
  }
1436
- if (!Number.isFinite(deadline) || deadline <= now || deadline > now + MAX_DEADLINE_SECONDS) {
1445
+ const maxDeadline = maxDeadlineSeconds(quote);
1446
+ if (!Number.isFinite(deadline) || deadline <= now || deadline > now + maxDeadline) {
1437
1447
  throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
1438
1448
  }
1439
1449
  for (let index = 1; index < list.length; index += 1) {
@@ -1446,7 +1456,7 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
1446
1456
  throw new Error("ZeroDelta chained quote returned disconnected execution chains.");
1447
1457
  }
1448
1458
  const followupDeadline = Number(current.deadline || 0);
1449
- if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + MAX_DEADLINE_SECONDS)) {
1459
+ if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + maxDeadline)) {
1450
1460
  throw new Error("ZeroDelta chained quote returned an invalid follow-up deadline.");
1451
1461
  }
1452
1462
  }
@@ -1609,7 +1619,7 @@ async function buildRoute({
1609
1619
  if (!requestList.length) throw new Error("ZeroDelta quote did not include an order request.");
1610
1620
  const sourceChain = chainById(chains, option.chainId);
1611
1621
  const escrow = checkEscrow(option.chainId, quote.escrowAddress, sourceChain?.escrowContract);
1612
- const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId);
1622
+ const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId, recommendedDeadlineSeconds(quote));
1613
1623
  const order = orders[0];
1614
1624
  assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result });
1615
1625
  const needsNativeFee = requiresNativeBridgeFee(quote, option);
@@ -1697,6 +1707,48 @@ async function buildRoute({
1697
1707
  };
1698
1708
  }
1699
1709
 
1710
+ // src/core/channel.ts
1711
+ var CHANNEL_HEADER = "x-zd-channel";
1712
+ var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
1713
+ var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
1714
+ var WIDGET_CHANNEL = "widget";
1715
+ var WIDGET_VERSION = "4.5.0" ;
1716
+ var MAX_CHANNEL_VERSION_LEN = 32;
1717
+ function sanitizeVersion(raw) {
1718
+ const v = String(raw).trim();
1719
+ if (!v) return "";
1720
+ const capped = v.length > MAX_CHANNEL_VERSION_LEN ? v.slice(0, MAX_CHANNEL_VERSION_LEN) : v;
1721
+ return /^[\x20-\x7e]+$/.test(capped) ? capped : "";
1722
+ }
1723
+ function embeddingOrigin(loc) {
1724
+ const origin = ((typeof location !== "undefined" ? location : void 0))?.origin;
1725
+ const v = String(origin ?? "").trim();
1726
+ if (!v || v === "null") return "";
1727
+ try {
1728
+ const url = new URL(v);
1729
+ if (url.protocol !== "https:" && url.protocol !== "http:") return "";
1730
+ return url.origin;
1731
+ } catch {
1732
+ return "";
1733
+ }
1734
+ }
1735
+ function channelHeaders(version, loc) {
1736
+ const headers = { [CHANNEL_HEADER]: WIDGET_CHANNEL };
1737
+ const v = sanitizeVersion(version);
1738
+ if (v) headers[CHANNEL_VERSION_HEADER] = v;
1739
+ const origin = embeddingOrigin();
1740
+ if (origin) headers[CHANNEL_ORIGIN_HEADER] = origin;
1741
+ return headers;
1742
+ }
1743
+ function isReportableSubmission(report) {
1744
+ if (!report) return false;
1745
+ const { txHash, chainId, wallet } = report;
1746
+ if (typeof txHash !== "string") return false;
1747
+ if (!/^0x[0-9a-fA-F]{64}$/.test(txHash) && !/^[1-9A-HJ-NP-Za-km-z]{64,90}$/.test(txHash)) return false;
1748
+ if (typeof chainId !== "number" || !Number.isFinite(chainId) || chainId <= 0) return false;
1749
+ return typeof wallet === "string" && /^0x[0-9a-fA-F]{40}$/.test(wallet);
1750
+ }
1751
+
1700
1752
  // src/core/api.ts
1701
1753
  function apiError(message, props = {}) {
1702
1754
  const err = new Error(message);
@@ -1779,9 +1831,14 @@ function createApiClient(cfg) {
1779
1831
  const screenCache = /* @__PURE__ */ new Map();
1780
1832
  const screenInflight = /* @__PURE__ */ new Map();
1781
1833
  const apiBase = cfg.apiBase.replace(/\/$/, "");
1834
+ const channel = channelHeaders(WIDGET_VERSION);
1782
1835
  async function requestJson(path, init = {}) {
1783
1836
  const apiKey = await cfg.getApiKey();
1784
- const headers = { "Content-Type": "application/json", ...init.headers || {} };
1837
+ const headers = {
1838
+ "Content-Type": "application/json",
1839
+ ...channel,
1840
+ ...init.headers || {}
1841
+ };
1785
1842
  if (apiKey) headers["x-api-key"] = apiKey;
1786
1843
  const controller = new AbortController();
1787
1844
  const timeoutId = setTimeout(() => controller.abort(), init.timeoutMs || 15e3);
@@ -1932,7 +1989,27 @@ function createApiClient(cfg) {
1932
1989
  screenInflight.set(key, request);
1933
1990
  return request;
1934
1991
  }
1935
- return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchQuote, screenWallet, apiBase };
1992
+ async function reportSubmission(report) {
1993
+ if (!isReportableSubmission(report)) return false;
1994
+ try {
1995
+ await apiRequest("/submissions", {
1996
+ method: "POST",
1997
+ body: JSON.stringify({
1998
+ txHash: report.txHash,
1999
+ chainId: report.chainId,
2000
+ wallet: report.wallet,
2001
+ // Absent reads as "submitted" at the gateway too; sent explicitly so
2002
+ // a reader of the wire does not have to know that.
2003
+ stage: report.stage ?? "submitted"
2004
+ }),
2005
+ timeoutMs: 5e3
2006
+ });
2007
+ return true;
2008
+ } catch {
2009
+ return false;
2010
+ }
2011
+ }
2012
+ return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchQuote, screenWallet, reportSubmission, apiBase };
1936
2013
  }
1937
2014
 
1938
2015
  // src/core/plan.ts
@@ -2613,6 +2690,7 @@ function createEngine(config = {}) {
2613
2690
  verifySubmittedTx: verifier.verifySubmittedTx,
2614
2691
  readBalances: verifier.readBalances,
2615
2692
  readNativeBalance: verifier.readNativeBalance,
2693
+ reportSubmission: api.reportSubmission,
2616
2694
  recordTransaction: (entry) => {
2617
2695
  const clean = sanitizeTxEntry(entry);
2618
2696
  try {
@@ -2898,6 +2976,13 @@ function appendTxHistory(account, entry, storage2 = defaultStorage()) {
2898
2976
  }
2899
2977
 
2900
2978
  // src/react/hooks/useFlow.ts
2979
+ function reportQuietly(engine, report, stage) {
2980
+ try {
2981
+ void engine.reportSubmission?.({ ...report, stage })?.catch?.(() => {
2982
+ });
2983
+ } catch {
2984
+ }
2985
+ }
2901
2986
  function useFlow(args) {
2902
2987
  const { engine, wallet, kind, enabled, paramsKey, loadPlan, recipientFor, onQuote, onSuccess, onError } = args;
2903
2988
  const [status, setStatus] = react.useState("idle");
@@ -3052,11 +3137,17 @@ function useFlow(args) {
3052
3137
  settleTx = tx;
3053
3138
  }
3054
3139
  }
3140
+ if (settleHash) {
3141
+ reportQuietly(engine, { txHash: settleHash, chainId: Number(sourceChainId), wallet: account }, "submitted");
3142
+ }
3055
3143
  patch("verify", "active");
3056
3144
  const v = settleHash ? await engine.verifySubmittedTx({ chainId: Number(sourceChainId), hash: settleHash, from: account, to: settleTx.to, data: settleTx.data, value: settleTx.value, minNonce: minNonce ?? void 0 }) : { status: "unconfirmed" };
3057
3145
  setVerdict(v);
3058
3146
  setTxHash(settleHash || null);
3059
3147
  patch("verify", v.status === "confirmed" ? "done" : v.status === "mismatch" || v.status === "reverted" ? "error" : "active");
3148
+ if (settleHash && v.status === "confirmed") {
3149
+ reportQuietly(engine, { txHash: settleHash, chainId: Number(sourceChainId), wallet: account }, "confirmed");
3150
+ }
3060
3151
  const entry = engine.recordTransaction({
3061
3152
  kind,
3062
3153
  hash: settleHash,
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-Dw3LvQZi.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-BnAD7hWX.cjs';
2
2
  import * as react from 'react';
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';
3
+ import { C as Compliance } from './verify-D722uRwZ.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-D722uRwZ.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-BX_B0fzO.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-DcbU1gqd.js';
2
2
  import * as react from 'react';
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';
3
+ import { C as Compliance } from './verify-D722uRwZ.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-D722uRwZ.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-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
+ export { CompliancePanel, PaymentIsland, StableGenieExchange, StableGeniePay, StableGenieProvider, StableGenieRwaExchange, StableGenieSwap, darkTheme, lightTheme, mount, resolveTheme } from './chunk-COBXR362.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-447DEZ5S.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-CPaT8Upe.cjs';
3
+ import { P as Plan, V as VerifyResult, h as RouteResult, S as SanitizedTxEntry, f as ExchangeProduct } from './verify-D722uRwZ.cjs';
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-CPaT8Upe.js';
3
+ import { P as Plan, V as VerifyResult, h as RouteResult, S as SanitizedTxEntry, f as ExchangeProduct } from './verify-D722uRwZ.js';
4
4
 
5
5
  interface Eip1193Provider {
6
6
  request(args: {
package/dist/mount.cjs CHANGED
@@ -1344,9 +1344,18 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
1344
1344
  // src/core/order.ts
1345
1345
  var DEFAULT_DEADLINE_SECONDS = 1800;
1346
1346
  var MAX_DEADLINE_SECONDS = 60 * 60;
1347
- function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride) {
1347
+ var ABSOLUTE_MAX_DEADLINE_SECONDS = 24 * 60 * 60;
1348
+ function recommendedDeadlineSeconds(quote) {
1349
+ const recommended = Number(quote?.recommendedDeadlineSeconds);
1350
+ if (!Number.isFinite(recommended) || recommended <= 0) return DEFAULT_DEADLINE_SECONDS;
1351
+ return Math.min(Math.floor(recommended), ABSOLUTE_MAX_DEADLINE_SECONDS);
1352
+ }
1353
+ function maxDeadlineSeconds(quote) {
1354
+ return Math.min(Math.max(MAX_DEADLINE_SECONDS, recommendedDeadlineSeconds(quote)), ABSOLUTE_MAX_DEADLINE_SECONDS);
1355
+ }
1356
+ function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride, lifetimeSeconds = DEFAULT_DEADLINE_SECONDS) {
1348
1357
  const apiDeadline = Number(order.deadline);
1349
- const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + DEFAULT_DEADLINE_SECONDS));
1358
+ const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + lifetimeSeconds));
1350
1359
  const executionChainId = String(order.executionChainId || fallbackExecutionChainId || "0");
1351
1360
  if (!/^\d+$/.test(executionChainId) || BigInt(executionChainId) <= 0n) throw new Error("ZeroDelta quote did not include an execution chain.");
1352
1361
  return {
@@ -1361,10 +1370,10 @@ function normalizeOrderRequest(order, payer, destination, fallbackExecutionChain
1361
1370
  deadline
1362
1371
  };
1363
1372
  }
1364
- function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId) {
1373
+ function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId, lifetimeSeconds = DEFAULT_DEADLINE_SECONDS) {
1365
1374
  if (!requests.length) throw new Error("ZeroDelta quote did not include any order requests.");
1366
1375
  return requests.map(
1367
- (request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
1376
+ (request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, void 0, lifetimeSeconds) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
1368
1377
  );
1369
1378
  }
1370
1379
  function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result }) {
@@ -1414,7 +1423,8 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
1414
1423
  if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
1415
1424
  throw new Error("ZeroDelta order guarantees less than the displayed receive amount.");
1416
1425
  }
1417
- if (!Number.isFinite(deadline) || deadline <= now || deadline > now + MAX_DEADLINE_SECONDS) {
1426
+ const maxDeadline = maxDeadlineSeconds(quote);
1427
+ if (!Number.isFinite(deadline) || deadline <= now || deadline > now + maxDeadline) {
1418
1428
  throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
1419
1429
  }
1420
1430
  for (let index = 1; index < list.length; index += 1) {
@@ -1427,7 +1437,7 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
1427
1437
  throw new Error("ZeroDelta chained quote returned disconnected execution chains.");
1428
1438
  }
1429
1439
  const followupDeadline = Number(current.deadline || 0);
1430
- if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + MAX_DEADLINE_SECONDS)) {
1440
+ if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + maxDeadline)) {
1431
1441
  throw new Error("ZeroDelta chained quote returned an invalid follow-up deadline.");
1432
1442
  }
1433
1443
  }
@@ -1590,7 +1600,7 @@ async function buildRoute({
1590
1600
  if (!requestList.length) throw new Error("ZeroDelta quote did not include an order request.");
1591
1601
  const sourceChain = chainById(chains, option.chainId);
1592
1602
  const escrow = checkEscrow(option.chainId, quote.escrowAddress, sourceChain?.escrowContract);
1593
- const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId);
1603
+ const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId, recommendedDeadlineSeconds(quote));
1594
1604
  const order = orders[0];
1595
1605
  assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result });
1596
1606
  const needsNativeFee = requiresNativeBridgeFee(quote, option);
@@ -1678,6 +1688,48 @@ async function buildRoute({
1678
1688
  };
1679
1689
  }
1680
1690
 
1691
+ // src/core/channel.ts
1692
+ var CHANNEL_HEADER = "x-zd-channel";
1693
+ var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
1694
+ var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
1695
+ var WIDGET_CHANNEL = "widget";
1696
+ var WIDGET_VERSION = "4.5.0" ;
1697
+ var MAX_CHANNEL_VERSION_LEN = 32;
1698
+ function sanitizeVersion(raw) {
1699
+ const v = String(raw).trim();
1700
+ if (!v) return "";
1701
+ const capped = v.length > MAX_CHANNEL_VERSION_LEN ? v.slice(0, MAX_CHANNEL_VERSION_LEN) : v;
1702
+ return /^[\x20-\x7e]+$/.test(capped) ? capped : "";
1703
+ }
1704
+ function embeddingOrigin(loc) {
1705
+ const origin = ((typeof location !== "undefined" ? location : void 0))?.origin;
1706
+ const v = String(origin ?? "").trim();
1707
+ if (!v || v === "null") return "";
1708
+ try {
1709
+ const url = new URL(v);
1710
+ if (url.protocol !== "https:" && url.protocol !== "http:") return "";
1711
+ return url.origin;
1712
+ } catch {
1713
+ return "";
1714
+ }
1715
+ }
1716
+ function channelHeaders(version, loc) {
1717
+ const headers = { [CHANNEL_HEADER]: WIDGET_CHANNEL };
1718
+ const v = sanitizeVersion(version);
1719
+ if (v) headers[CHANNEL_VERSION_HEADER] = v;
1720
+ const origin = embeddingOrigin();
1721
+ if (origin) headers[CHANNEL_ORIGIN_HEADER] = origin;
1722
+ return headers;
1723
+ }
1724
+ function isReportableSubmission(report) {
1725
+ if (!report) return false;
1726
+ const { txHash, chainId, wallet } = report;
1727
+ if (typeof txHash !== "string") return false;
1728
+ if (!/^0x[0-9a-fA-F]{64}$/.test(txHash) && !/^[1-9A-HJ-NP-Za-km-z]{64,90}$/.test(txHash)) return false;
1729
+ if (typeof chainId !== "number" || !Number.isFinite(chainId) || chainId <= 0) return false;
1730
+ return typeof wallet === "string" && /^0x[0-9a-fA-F]{40}$/.test(wallet);
1731
+ }
1732
+
1681
1733
  // src/core/api.ts
1682
1734
  function apiError(message, props = {}) {
1683
1735
  const err = new Error(message);
@@ -1760,9 +1812,14 @@ function createApiClient(cfg) {
1760
1812
  const screenCache = /* @__PURE__ */ new Map();
1761
1813
  const screenInflight = /* @__PURE__ */ new Map();
1762
1814
  const apiBase = cfg.apiBase.replace(/\/$/, "");
1815
+ const channel = channelHeaders(WIDGET_VERSION);
1763
1816
  async function requestJson(path, init = {}) {
1764
1817
  const apiKey = await cfg.getApiKey();
1765
- const headers = { "Content-Type": "application/json", ...init.headers || {} };
1818
+ const headers = {
1819
+ "Content-Type": "application/json",
1820
+ ...channel,
1821
+ ...init.headers || {}
1822
+ };
1766
1823
  if (apiKey) headers["x-api-key"] = apiKey;
1767
1824
  const controller = new AbortController();
1768
1825
  const timeoutId = setTimeout(() => controller.abort(), init.timeoutMs || 15e3);
@@ -1913,7 +1970,27 @@ function createApiClient(cfg) {
1913
1970
  screenInflight.set(key, request);
1914
1971
  return request;
1915
1972
  }
1916
- return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchQuote, screenWallet, apiBase };
1973
+ async function reportSubmission(report) {
1974
+ if (!isReportableSubmission(report)) return false;
1975
+ try {
1976
+ await apiRequest("/submissions", {
1977
+ method: "POST",
1978
+ body: JSON.stringify({
1979
+ txHash: report.txHash,
1980
+ chainId: report.chainId,
1981
+ wallet: report.wallet,
1982
+ // Absent reads as "submitted" at the gateway too; sent explicitly so
1983
+ // a reader of the wire does not have to know that.
1984
+ stage: report.stage ?? "submitted"
1985
+ }),
1986
+ timeoutMs: 5e3
1987
+ });
1988
+ return true;
1989
+ } catch {
1990
+ return false;
1991
+ }
1992
+ }
1993
+ return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchQuote, screenWallet, reportSubmission, apiBase };
1917
1994
  }
1918
1995
 
1919
1996
  // src/core/plan.ts
@@ -2594,6 +2671,7 @@ function createEngine(config = {}) {
2594
2671
  verifySubmittedTx: verifier.verifySubmittedTx,
2595
2672
  readBalances: verifier.readBalances,
2596
2673
  readNativeBalance: verifier.readNativeBalance,
2674
+ reportSubmission: api.reportSubmission,
2597
2675
  recordTransaction: (entry) => {
2598
2676
  const clean = sanitizeTxEntry(entry);
2599
2677
  try {
@@ -2879,6 +2957,13 @@ function appendTxHistory(account, entry, storage2 = defaultStorage()) {
2879
2957
  }
2880
2958
 
2881
2959
  // src/react/hooks/useFlow.ts
2960
+ function reportQuietly(engine, report, stage) {
2961
+ try {
2962
+ void engine.reportSubmission?.({ ...report, stage })?.catch?.(() => {
2963
+ });
2964
+ } catch {
2965
+ }
2966
+ }
2882
2967
  function useFlow(args) {
2883
2968
  const { engine, wallet, kind, enabled, paramsKey, loadPlan, recipientFor, onQuote, onSuccess, onError } = args;
2884
2969
  const [status, setStatus] = react.useState("idle");
@@ -3033,11 +3118,17 @@ function useFlow(args) {
3033
3118
  settleTx = tx;
3034
3119
  }
3035
3120
  }
3121
+ if (settleHash) {
3122
+ reportQuietly(engine, { txHash: settleHash, chainId: Number(sourceChainId), wallet: account }, "submitted");
3123
+ }
3036
3124
  patch("verify", "active");
3037
3125
  const v = settleHash ? await engine.verifySubmittedTx({ chainId: Number(sourceChainId), hash: settleHash, from: account, to: settleTx.to, data: settleTx.data, value: settleTx.value, minNonce: minNonce ?? void 0 }) : { status: "unconfirmed" };
3038
3126
  setVerdict(v);
3039
3127
  setTxHash(settleHash || null);
3040
3128
  patch("verify", v.status === "confirmed" ? "done" : v.status === "mismatch" || v.status === "reverted" ? "error" : "active");
3129
+ if (settleHash && v.status === "confirmed") {
3130
+ reportQuietly(engine, { txHash: settleHash, chainId: Number(sourceChainId), wallet: account }, "confirmed");
3131
+ }
3041
3132
  const entry = engine.recordTransaction({
3042
3133
  kind,
3043
3134
  hash: settleHash,
package/dist/mount.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MountConfig, r as mount } from './mount-Dw3LvQZi.cjs';
1
+ export { M as MountConfig, r as mount } from './mount-BnAD7hWX.cjs';
2
2
  import 'react';
3
- import './verify-CPaT8Upe.cjs';
3
+ import './verify-D722uRwZ.cjs';
package/dist/mount.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MountConfig, r as mount } from './mount-BX_B0fzO.js';
1
+ export { M as MountConfig, r as mount } from './mount-DcbU1gqd.js';
2
2
  import 'react';
3
- import './verify-CPaT8Upe.js';
3
+ import './verify-D722uRwZ.js';
package/dist/mount.js CHANGED
@@ -1,2 +1,2 @@
1
- export { mount } from './chunk-RFBNRCFB.js';
2
- import './chunk-PMVF6A2D.js';
1
+ export { mount } from './chunk-COBXR362.js';
2
+ import './chunk-447DEZ5S.js';