@glacislabs/stablegenie-zerodelta 4.5.0 → 4.6.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.
@@ -1700,7 +1700,7 @@ var CHANNEL_HEADER = "x-zd-channel";
1700
1700
  var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
1701
1701
  var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
1702
1702
  var WIDGET_CHANNEL = "widget";
1703
- var WIDGET_VERSION = "4.5.0" ;
1703
+ var WIDGET_VERSION = "4.6.0" ;
1704
1704
  var MAX_CHANNEL_VERSION_LEN = 32;
1705
1705
  function sanitizeVersion(raw) {
1706
1706
  const v = String(raw).trim();
@@ -1938,6 +1938,33 @@ function createApiClient(cfg) {
1938
1938
  cache.vaults = { at: Date.now(), value };
1939
1939
  return value;
1940
1940
  }
1941
+ const priceCache = /* @__PURE__ */ new Map();
1942
+ async function fetchPrices(symbols) {
1943
+ const wanted = [...new Set(symbols.map((s) => String(s || "").toUpperCase()).filter((s) => /^[A-Z0-9]{1,16}$/.test(s)))];
1944
+ const missing = wanted.filter((s) => !nowFresh(priceCache.get(s) ?? null));
1945
+ if (missing.length) {
1946
+ let prices = {};
1947
+ try {
1948
+ const snapshot = await apiRequest(`/prices?symbols=${encodeURIComponent(missing.join(","))}`, {
1949
+ timeoutMs: 8e3
1950
+ });
1951
+ prices = snapshot && typeof snapshot === "object" && !snapshot.stale && snapshot.prices && typeof snapshot.prices === "object" ? snapshot.prices : {};
1952
+ } catch {
1953
+ prices = {};
1954
+ }
1955
+ const at = Date.now();
1956
+ for (const s of missing) {
1957
+ const n = Number(prices[s]);
1958
+ priceCache.set(s, { at, value: Number.isFinite(n) && n > 0 ? n : null });
1959
+ }
1960
+ }
1961
+ const out = {};
1962
+ for (const s of wanted) {
1963
+ const value = priceCache.get(s)?.value;
1964
+ if (value != null) out[s] = value;
1965
+ }
1966
+ return out;
1967
+ }
1941
1968
  async function fetchQuote(body, retries = 1) {
1942
1969
  let lastError;
1943
1970
  for (let attempt = 0; attempt <= retries; attempt += 1) {
@@ -1997,7 +2024,7 @@ function createApiClient(cfg) {
1997
2024
  return false;
1998
2025
  }
1999
2026
  }
2000
- return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchQuote, screenWallet, reportSubmission, apiBase };
2027
+ return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchQuote, screenWallet, reportSubmission, apiBase };
2001
2028
  }
2002
2029
 
2003
2030
  // src/core/plan.ts
@@ -2180,6 +2207,14 @@ function validateSwap(swap = {}) {
2180
2207
  if (!/^\d+(\.\d+)?$/.test(amountIn) || Number(amountIn) <= 0 || Number(amountIn) > 1e9) throw new Error("Enter a valid swap amount.");
2181
2208
  return { fromChainId, toChainId, fromToken, toToken, amountIn };
2182
2209
  }
2210
+ function viaOf(quote, tokens) {
2211
+ const orders = Array.isArray(quote.orderRequests) ? quote.orderRequests : [];
2212
+ if (orders.length < 2) return null;
2213
+ const first = orders[0];
2214
+ const wanted = normalizeAddress(first?.askToken);
2215
+ const token = wanted ? tokens.find((t) => Number(t.chainId) === Number(first?.destinationChainId) && normalizeAddress(t.address) === wanted) : void 0;
2216
+ return token ? tokenTicker(token) : "";
2217
+ }
2183
2218
  async function quoteSwapPreview(api, swap, owner) {
2184
2219
  const v = validateSwap(swap);
2185
2220
  const tokens = await api.fetchTokens();
@@ -2208,7 +2243,9 @@ async function quoteSwapPreview(api, swap, owner) {
2208
2243
  toToken: destToken.symbol,
2209
2244
  bridge: quote.bridge || "",
2210
2245
  feeBps: Number(quote.feeBps || 0),
2211
- estimatedDuration: Number(quote.estimatedDuration || 0)
2246
+ estimatedDuration: Number(quote.estimatedDuration || 0),
2247
+ via: viaOf(quote, tokens),
2248
+ nativeFeeRaw: /^\d+$/.test(String(quote.gasCostSource ?? "")) ? String(quote.gasCostSource) : "0"
2212
2249
  };
2213
2250
  }
2214
2251
  async function buildSwapPlan(api, swap, payer, wallet = {}) {
@@ -2702,6 +2739,7 @@ function createEngine(config = {}) {
2702
2739
  fetchRoutes: api.fetchRoutes,
2703
2740
  fetchRouteHealth: api.fetchRouteHealth,
2704
2741
  fetchQuote: api.fetchQuote,
2742
+ fetchPrices: (symbols) => api.fetchPrices ? api.fetchPrices(symbols) : Promise.resolve({}),
2705
2743
  fetchCatalogue: async (allowedAssets, product) => {
2706
2744
  const [chains, registryTokens, routes, health, vaults] = await Promise.all([
2707
2745
  api.fetchChains().catch(() => []),