@glacislabs/stablegenie-zerodelta 4.20.1 → 4.22.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.
@@ -1633,6 +1633,7 @@ function hubDeliverableSymbols(tokens, execution) {
1633
1633
  function isSourceToken(token, ctx) {
1634
1634
  const chainId = Number(token.chainId);
1635
1635
  if (!ctx.sourceChains.has(chainId)) return false;
1636
+ if (ctx.zdHeavySources?.has(tokenKey(chainId, token.address))) return true;
1636
1637
  return ctx.execution.has(chainId) || !isKnownUnbridgeable(token.bridge) && ctx.source.has(tokenKey(chainId, token.address));
1637
1638
  }
1638
1639
  function directLaneOK(token, source, lanes) {
@@ -1651,6 +1652,7 @@ function laneLimitFor(token, source, limitedLanes2) {
1651
1652
  }
1652
1653
  function destinationAvailability(token, ctx, source) {
1653
1654
  if (brokenLaneFor(token, source ?? void 0, ctx.brokenLanes)) return "unreachable";
1655
+ if (source && ctx.zdHeavyLanes?.has(laneKey(source.chainId, source.address, token.chainId, token.address))) return "available";
1654
1656
  if (directLaneOK(token, source ?? void 0, ctx.lanes)) {
1655
1657
  if (ctx.execution.has(Number(token.chainId))) return "available";
1656
1658
  if (token.isChainedDestination === true) return "available";
@@ -1669,6 +1671,7 @@ function hasReachableDestination(source, catalogue, ctx) {
1669
1671
  }
1670
1672
  function buildCatalogue(input) {
1671
1673
  const { chains, tokens, routes, supportedChainIds, brokenLanes } = input;
1674
+ const zdHeavy = (input.zdHeavyRoutes ?? []).filter((r) => !!r && typeof r === "object" && !Array.isArray(r) && r.isEnabled !== false && r.isQuotable === true);
1672
1675
  const product = input.product ?? "stable";
1673
1676
  const universe = productAssets(product);
1674
1677
  const allowedAssets = input.allowedAssets ? new Set([...input.allowedAssets].filter((a) => universe.has(a))) : universe;
@@ -1676,7 +1679,10 @@ function buildCatalogue(input) {
1676
1679
  const registryChainIds = new Set(enabledChains.map((c) => Number(c.chainId)));
1677
1680
  const sourceChains = new Set([...registryChainIds].filter((id) => supportedChainIds.has(id)));
1678
1681
  const execution = executionChainIds(enabledChains);
1679
- const projected = product === "rwa" ? routes.filter((route) => route.isEnabled !== false) : executableRoutes(routes);
1682
+ const projected = [...product === "rwa" ? routes.filter((route) => route.isEnabled !== false) : executableRoutes(routes), ...zdHeavy];
1683
+ const zdHeavyLanes = laneKeys(zdHeavy);
1684
+ const zdHeavySources = sourceKeys(zdHeavy);
1685
+ const zdHeavyKeys = /* @__PURE__ */ new Set([...zdHeavySources, ...destinationKeys(zdHeavy)]);
1680
1686
  const source = sourceKeys(projected);
1681
1687
  const destination = destinationKeys(projected);
1682
1688
  const lanes = laneKeys(projected);
@@ -1691,14 +1697,15 @@ function buildCatalogue(input) {
1691
1697
  if (!chainIds.has(chainId)) return false;
1692
1698
  if (product === "rwa") return true;
1693
1699
  if (execution.has(chainId) || token.isChainedDestination === true) return true;
1694
- if (!isExecutableBridge(token)) return false;
1695
1700
  const key2 = tokenKey(token.chainId, token.address);
1701
+ if (zdHeavyKeys.has(key2)) return true;
1702
+ if (!isExecutableBridge(token)) return false;
1696
1703
  return source.has(key2) || destination.has(key2);
1697
1704
  });
1698
1705
  const ready = chains.length > 0 && routes.length > 0 && projectedCatalogue.length > 0;
1699
1706
  const catalogue = ready ? projectedCatalogue : allowed;
1700
1707
  const hubSymbols = hubDeliverableSymbols(catalogue, execution);
1701
- const ctx = { source, destination, lanes, execution, sourceChains, hubSymbols, ...brokenLanes ? { brokenLanes } : {} };
1708
+ const ctx = { source, destination, lanes, execution, sourceChains, hubSymbols, ...zdHeavy.length ? { zdHeavyLanes, zdHeavySources } : {}, ...brokenLanes ? { brokenLanes } : {} };
1702
1709
  const sellable = (token) => product !== "rwa" || isSellableRwa(token);
1703
1710
  const sources = ready ? catalogue.filter((token) => sellable(token) && isSourceToken(token, ctx) && hasReachableDestination(token, catalogue, ctx)) : (
1704
1711
  // Unprojected: the only rule we can still apply with confidence is the escrow-chain bound,
@@ -2345,13 +2352,22 @@ var MAX_STEPS = 8;
2345
2352
  function isZdHeavy(r, steps) {
2346
2353
  return r.protocol === "zdheavy" || steps.some((s) => Number(s.stepNumber ?? 0) >= ZDH_FIRST_STEP);
2347
2354
  }
2355
+ var FILL_EVIDENCE = /* @__PURE__ */ new Set(["filled", "consumed", "step_executed", "paid_out", "delivered"]);
2356
+ function ownerCancelServedAsDeliveryFailure(steps) {
2357
+ const txHash = (s) => typeof s.txHash === "string" && /^0x[0-9a-fA-F]{64}$/.test(s.txHash);
2358
+ const anyTx = (s) => typeof s.txHash === "string" && s.txHash.length > 0;
2359
+ const cancelTx = steps.some((s) => s.stepName === "cancelled" && txHash(s));
2360
+ const refunded = steps.some((s) => s.stepName === "refunded" && word(s.stepStatus) === "recovered" && txHash(s));
2361
+ const filled = steps.some((s) => FILL_EVIDENCE.has(String(s.stepName)) && word(s.stepStatus) === "completed" && anyTx(s));
2362
+ return cancelTx && refunded && !filled;
2363
+ }
2348
2364
  function zdHeavyDelivery(own, rawSteps) {
2349
2365
  const named = rawSteps.filter((s) => s && typeof s === "object" && typeof s.stepName === "string");
2350
2366
  const lite = (name) => named.some((s) => Number(s.stepNumber ?? 0) < ZDH_FIRST_STEP && s.stepName === name && s.stepStatus === "completed");
2351
2367
  const events = named.map((s, i) => ({ s, i })).filter(({ s }) => Number(s.stepNumber ?? 0) >= ZDH_FIRST_STEP).sort((a, b) => (Date.parse(String(a.s.blockTimestamp ?? "")) || 0) - (Date.parse(String(b.s.blockTimestamp ?? "")) || 0) || a.i - b.i).map(({ s }) => s);
2352
2368
  const has = (name) => events.some((e) => e.stepName === name);
2353
2369
  const cancelled = has("cancelled");
2354
- const status = PROGRESS.has(own) && has("paid_out") && !cancelled ? "delivered" : own;
2370
+ const status = own === "delivery_failed" && ownerCancelServedAsDeliveryFailure(named) ? "cancelled" : PROGRESS.has(own) && has("paid_out") && !cancelled ? "delivered" : own;
2355
2371
  const steps = [];
2356
2372
  const push = (name, done) => {
2357
2373
  const last = steps[steps.length - 1];
@@ -2453,7 +2469,10 @@ function historyEntryFromOrder(raw2, tokens) {
2453
2469
  const toAsset = (to?.symbol ?? (str(r.finalToTokenSymbol) || str(r.toTokenSymbol))).slice(0, 10);
2454
2470
  const payAmount = amountOf(str(r.fromTokenRawAmount), from, r.fromTokenDecimals, str(r.fromTokenAmount));
2455
2471
  const receiveAmount = str(r.finalToTokenRawAmount) ? amountOf(str(r.finalToTokenRawAmount), to, r.finalToTokenDecimals, str(r.finalToTokenAmount)) : amountOf(str(r.toTokenRawAmount), to, r.toTokenDecimals, str(r.toTokenAmount));
2456
- const delivery = normalizeDelivery(r).phase;
2472
+ const tracked = normalizeDelivery(r);
2473
+ const delivery = tracked.phase;
2474
+ const protocol = str(r.protocol);
2475
+ const orderId = str(r.orderId);
2457
2476
  const wallet = str(r.wallet);
2458
2477
  const receiver = str(r.destinationReceiver);
2459
2478
  const at = str(r.createdAt) || str(r.submittedAt);
@@ -2475,6 +2494,11 @@ function historyEntryFromOrder(raw2, tokens) {
2475
2494
  status: "submitted",
2476
2495
  at: Number.isNaN(Date.parse(at)) ? (/* @__PURE__ */ new Date(0)).toISOString() : new Date(at).toISOString(),
2477
2496
  delivery: delivery === "tracking" || delivery === "unavailable" ? void 0 : delivery,
2497
+ ...tracked.status && delivery !== "tracking" && delivery !== "unavailable" ? { deliveryStatus: tracked.status.slice(0, 32) } : {},
2498
+ .../^[a-z]{1,16}$/.test(protocol) ? { protocol } : {},
2499
+ // Only a router order id (bytes32) is carried: it is the one thing a recovery call puts in a URL.
2500
+ .../^0x[0-9a-fA-F]{64}$/.test(orderId) ? { orderId } : {},
2501
+ ...r.claimable === true ? { claimable: true } : {},
2478
2502
  legs: [
2479
2503
  {
2480
2504
  index: 1,
@@ -2522,7 +2546,17 @@ function mergeHistory(local, remote, limit = WALLET_HISTORY_LIMIT) {
2522
2546
  if (seen.has(key2)) continue;
2523
2547
  seen.add(key2);
2524
2548
  const known = byHash.get(key2);
2525
- out.push(known ? { ...entry, delivery: known.delivery, legs: entry.legs ?? known.legs } : entry);
2549
+ out.push(
2550
+ known ? {
2551
+ ...entry,
2552
+ delivery: known.delivery,
2553
+ legs: entry.legs ?? known.legs,
2554
+ deliveryStatus: known.deliveryStatus,
2555
+ protocol: known.protocol,
2556
+ orderId: known.orderId,
2557
+ claimable: known.claimable
2558
+ } : entry
2559
+ );
2526
2560
  }
2527
2561
  for (const [key2, entry] of byHash) if (!seen.has(key2)) out.push(entry);
2528
2562
  return out.sort((a, b) => Date.parse(b.at) - Date.parse(a.at)).slice(0, limit);
@@ -3115,6 +3149,15 @@ function zdHeavyRouterPinned(chainId, router) {
3115
3149
  }
3116
3150
 
3117
3151
  // src/core/quote-option.ts
3152
+ function gateZdHeavyOptions(response, request, quotableRoutes) {
3153
+ if (!Array.isArray(response?.options)) return response;
3154
+ const matchesToken = (chainId, token, address, symbol) => typeof address === "string" && !!address && chainAddressKey(chainId, token) === chainAddressKey(chainId, address) || typeof symbol === "string" && !!symbolKey(symbol) && symbolKey(token) === symbolKey(symbol);
3155
+ const matchesLane = quotableRoutes.some(
3156
+ (r) => !!r && typeof r === "object" && !Array.isArray(r) && r.isEnabled !== false && r.isQuotable === true && Number(r.fromChainId) === Number(request.inputChain) && Number(r.toChainId) === Number(request.outputChain) && matchesToken(request.inputChain, request.inputToken, r.fromAddress, r.fromSymbol) && matchesToken(request.outputChain, request.outputToken, r.toAddress, r.toSymbol)
3157
+ );
3158
+ if (matchesLane) return response;
3159
+ return { ...response, options: response.options.filter((option) => option?.protocol !== "zdheavy") };
3160
+ }
3118
3161
  function zdHeavyExecutable(q) {
3119
3162
  const order = q.execution?.order;
3120
3163
  const chainId = typeof q.fromChainId === "number" ? q.fromChainId : Number(order?.chainNumber);
@@ -3371,16 +3414,16 @@ function normalizeOrderRequests(requests, payer, destination, fallbackExecutionC
3371
3414
  );
3372
3415
  }
3373
3416
  function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result, tokens = [] }) {
3374
- const list = orders?.length ? orders : [order];
3375
- const sourceOrder = list[0];
3376
- const finalOrder = list[list.length - 1];
3417
+ const list2 = orders?.length ? orders : [order];
3418
+ const sourceOrder = list2[0];
3419
+ const finalOrder = list2[list2.length - 1];
3377
3420
  const now = Math.floor(Date.now() / 1e3);
3378
3421
  const deadline = Number(sourceOrder.deadline || 0);
3379
3422
  const solana = isSolanaChainId(destination.chainId);
3380
3423
  if (solana && solanaDestinationAsset(destinationToken.address)?.symbol !== symbolKey(destinationToken.symbol)) {
3381
3424
  throw new Error("This Solana token is not supported for delivery; refusing to sign.");
3382
3425
  }
3383
- for (const current of list) {
3426
+ for (const current of list2) {
3384
3427
  if (normalizeAddress(current.owner) !== normalizeAddress(payer)) {
3385
3428
  throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
3386
3429
  }
@@ -3431,9 +3474,9 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
3431
3474
  if (!Number.isFinite(deadline) || deadline <= now || deadline > now + maxDeadline + DEADLINE_CLOCK_SKEW_SECONDS) {
3432
3475
  throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
3433
3476
  }
3434
- for (let index = 1; index < list.length; index += 1) {
3435
- const previous = list[index - 1];
3436
- const current = list[index];
3477
+ for (let index = 1; index < list2.length; index += 1) {
3478
+ const previous = list2[index - 1];
3479
+ const current = list2[index];
3437
3480
  if (normalizeAddress(previous.askToken) !== normalizeAddress(current.bidToken)) {
3438
3481
  throw new Error("ZeroDelta chained quote returned disconnected order tokens.");
3439
3482
  }
@@ -3510,10 +3553,10 @@ function keccak256Hex(bytes) {
3510
3553
  return out;
3511
3554
  }
3512
3555
  function toChecksumAddress(address) {
3513
- const lower3 = address.slice(2).toLowerCase();
3514
- const hash2 = keccak256Hex(new TextEncoder().encode(lower3));
3556
+ const lower4 = address.slice(2).toLowerCase();
3557
+ const hash2 = keccak256Hex(new TextEncoder().encode(lower4));
3515
3558
  let out = "0x";
3516
- for (let i = 0; i < 40; i++) out += Number.parseInt(hash2[i], 16) >= 8 ? lower3[i].toUpperCase() : lower3[i];
3559
+ for (let i = 0; i < 40; i++) out += Number.parseInt(hash2[i], 16) >= 8 ? lower4[i].toUpperCase() : lower4[i];
3517
3560
  return out;
3518
3561
  }
3519
3562
  function hasValidChecksum(address) {
@@ -3531,6 +3574,7 @@ var toHex = (v, opts) => "0x" + (typeof v === "bigint" ? v.toString(16).padStart
3531
3574
  var keccak256 = (h2) => "0x" + keccak256Hex(hexToBytes2(h2));
3532
3575
  var STEP_VERSION = 5;
3533
3576
  var MAX_STEPS2 = 8;
3577
+ var ORDER_HEADER_LEN = 76;
3534
3578
  var StepKind = {
3535
3579
  LOCAL_PAYOUT: 1,
3536
3580
  REMOTE_PAYOUT: 2,
@@ -3671,11 +3715,11 @@ function decodeStep(step) {
3671
3715
  r.end();
3672
3716
  return result;
3673
3717
  }
3674
- function routerWord(addr) {
3675
- return concat([toHex(new Uint8Array(12)), checkedHex(addr, 20)]);
3718
+ function routerWord(addr2) {
3719
+ return concat([toHex(new Uint8Array(12)), checkedHex(addr2, 20)]);
3676
3720
  }
3677
- function ownerWord(addr) {
3678
- return routerWord(addr);
3721
+ function ownerWord(addr2) {
3722
+ return routerWord(addr2);
3679
3723
  }
3680
3724
  function encodeOrderHeader(serial, router, ownerType, owner) {
3681
3725
  if (!Number.isInteger(ownerType) || ownerType < 0 || ownerType > 255) throw new ZdHeavyCodecError("Invalid ownerType");
@@ -4041,6 +4085,16 @@ async function allowanceCovers(tx, account, ethCall) {
4041
4085
  }
4042
4086
 
4043
4087
  // src/core/zdheavy-route.ts
4088
+ var ZdHeavyQuoteExpiredError = class extends Error {
4089
+ code = "zdheavy_quote_expired";
4090
+ constructor() {
4091
+ super("This ZD Heavy quote expired before it was signed. A fresh quote is loading \u2014 review it and press Exchange again.");
4092
+ this.name = "ZdHeavyQuoteExpiredError";
4093
+ }
4094
+ };
4095
+ function assertZdHeavyQuoteFresh(order, nowSec) {
4096
+ if (order && (order.expiresAt <= nowSec || order.expiryDate <= nowSec)) throw new ZdHeavyQuoteExpiredError();
4097
+ }
4044
4098
  function zdHeavyExpected(route, owner, receiver, tokens, routes) {
4045
4099
  const heavy = route.zdHeavy;
4046
4100
  if (!heavy) throw new Error("Missing ZD Heavy order.");
@@ -4066,6 +4120,7 @@ function zdHeavyExpected(route, owner, receiver, tokens, routes) {
4066
4120
  };
4067
4121
  }
4068
4122
  function validateZdHeavyPlan(route, expected) {
4123
+ assertZdHeavyQuoteFresh(expected.order, expected.nowSec);
4069
4124
  if (route.transactions.length !== 2 || route.transactions[0].kind !== "approve" || route.transactions[1].kind !== "submitOrder") {
4070
4125
  throw new Error("ZD Heavy requires exactly approve then submitOrder; refusing to sign.");
4071
4126
  }
@@ -4931,7 +4986,7 @@ var CHANNEL_HEADER = "x-zd-channel";
4931
4986
  var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
4932
4987
  var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
4933
4988
  var WIDGET_CHANNEL = "widget";
4934
- var WIDGET_VERSION = "4.20.1" ;
4989
+ var WIDGET_VERSION = "4.22.0" ;
4935
4990
  var MAX_CHANNEL_VERSION_LEN = 32;
4936
4991
  function sanitizeVersion(raw2) {
4937
4992
  const v = String(raw2).trim();
@@ -5055,7 +5110,7 @@ function wait(ms) {
5055
5110
  }
5056
5111
  var PAGE_LIMIT = 500;
5057
5112
  var MAX_PAGES = 10;
5058
- var newRegistryCache = () => ({ chains: null, tokens: null, routes: null, health: null, vaults: null, promotions: null, inflight: /* @__PURE__ */ new Map() });
5113
+ var newRegistryCache = () => ({ chains: null, tokens: null, routes: null, zdHeavy: null, health: null, vaults: null, promotions: null, inflight: /* @__PURE__ */ new Map() });
5059
5114
  var SHARED_REGISTRY = /* @__PURE__ */ new WeakMap();
5060
5115
  function registryCacheFor(scope) {
5061
5116
  if (!scope) return newRegistryCache();
@@ -5132,13 +5187,14 @@ function createApiClient(cfg) {
5132
5187
  const json = await requestJson(path, init);
5133
5188
  return json?.data ?? json;
5134
5189
  }
5135
- async function requestAllPages(path) {
5190
+ async function requestAllPages(path, params = {}) {
5136
5191
  const rows = [];
5137
5192
  let firstRow = "";
5138
5193
  for (let page = 0; page < MAX_PAGES; page += 1) {
5139
- const json = await requestJson(`${path}${toQuery({ limit: PAGE_LIMIT, offset: rows.length || void 0 })}`);
5194
+ const json = await requestJson(`${path}${toQuery({ ...params, limit: PAGE_LIMIT, offset: rows.length || void 0 })}`);
5140
5195
  const envelope = json && !Array.isArray(json) ? json : {};
5141
5196
  const data = Array.isArray(json) ? json : envelope.data;
5197
+ if (params.protocol === "zdheavy" && !Array.isArray(data)) throw apiError(`ZeroDelta returned an unusable list (${path}).`, { code: "bad_response" });
5142
5198
  const pageRows = Array.isArray(data) ? data : [];
5143
5199
  const head = pageRows.length ? JSON.stringify(pageRows[0]) : "";
5144
5200
  if (page === 0) firstRow = head;
@@ -5184,6 +5240,20 @@ function createApiClient(cfg) {
5184
5240
  }
5185
5241
  });
5186
5242
  }
5243
+ function fetchZdHeavyRoutes() {
5244
+ if (nowFresh(cache.zdHeavy)) return Promise.resolve(cache.zdHeavy.value);
5245
+ return once("zdHeavy", async () => {
5246
+ let value = [];
5247
+ try {
5248
+ const rows = await requestAllPages("/routes", { protocol: "zdheavy", isEnabled: true });
5249
+ value = rows.filter((r) => !!r && typeof r === "object" && !Array.isArray(r) && r.isEnabled !== false && r.isQuotable === true);
5250
+ } catch {
5251
+ value = [];
5252
+ }
5253
+ cache.zdHeavy = { at: Date.now(), value };
5254
+ return value;
5255
+ });
5256
+ }
5187
5257
  function fetchRouteHealth() {
5188
5258
  if (nowFresh(cache.health)) return Promise.resolve(cache.health.value);
5189
5259
  return once("health", async () => {
@@ -5262,7 +5332,8 @@ function createApiClient(cfg) {
5262
5332
  for (let attempt = 0; attempt <= retries; attempt += 1) {
5263
5333
  try {
5264
5334
  const quote = await apiRequest("/quote", { method: "POST", headers: { "X-ZD-Shape": "native" }, body: JSON.stringify(request), timeoutMs: 18e3 });
5265
- return normalizeQuoteResponse(quote, request);
5335
+ const gated = Array.isArray(quote?.options) && quote.options.some((option) => option?.protocol === "zdheavy") ? gateZdHeavyOptions(quote, request, await fetchZdHeavyRoutes()) : quote;
5336
+ return normalizeQuoteResponse(gated, request);
5266
5337
  } catch (error) {
5267
5338
  lastError = error;
5268
5339
  if (attempt >= retries || !isTransientQuoteError(error)) throw error;
@@ -5272,24 +5343,24 @@ function createApiClient(cfg) {
5272
5343
  throw lastError;
5273
5344
  }
5274
5345
  async function screenWallet(address, chainId) {
5275
- const addr = String(address || "").trim();
5276
- if (!addr) throw apiError("An address is required to screen a wallet.", { code: "bad_request" });
5277
- const solana = isSolanaChainId(chainId) || isSolanaAddress(addr);
5278
- if (solana && !isSolanaAddress(addr)) throw apiError("Not a valid Solana address.", { code: "bad_request" });
5279
- const key2 = solana ? "solana|" + addr : (/^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr) + "|" + (chainId ?? "");
5346
+ const addr2 = String(address || "").trim();
5347
+ if (!addr2) throw apiError("An address is required to screen a wallet.", { code: "bad_request" });
5348
+ const solana = isSolanaChainId(chainId) || isSolanaAddress(addr2);
5349
+ if (solana && !isSolanaAddress(addr2)) throw apiError("Not a valid Solana address.", { code: "bad_request" });
5350
+ const key2 = solana ? "solana|" + addr2 : (/^0x[0-9a-fA-F]+$/.test(addr2) ? addr2.toLowerCase() : addr2) + "|" + (chainId ?? "");
5280
5351
  const hit = screenCache.get(key2);
5281
5352
  if (hit && Date.now() - hit.at < SCREEN_CACHE_TTL_MS) return hit.value;
5282
5353
  const inflight = screenInflight.get(key2);
5283
5354
  if (inflight) return inflight;
5284
5355
  const request = apiRequest("/screen/wallet", {
5285
5356
  method: "POST",
5286
- body: JSON.stringify(solana ? { address: addr, network: "solana" } : chainId == null ? { address: addr } : { address: addr, chainId }),
5357
+ body: JSON.stringify(solana ? { address: addr2, network: "solana" } : chainId == null ? { address: addr2 } : { address: addr2, chainId }),
5287
5358
  timeoutMs: 12e3
5288
5359
  }).then((screen) => {
5289
5360
  if (!screen || typeof screen !== "object" || typeof screen.blocked !== "boolean") {
5290
5361
  throw apiError("Compliance screening returned an unusable result.", { code: "bad_response" });
5291
5362
  }
5292
- const value = { ...screen, address: screen.address || addr };
5363
+ const value = { ...screen, address: screen.address || addr2 };
5293
5364
  screenCache.set(key2, { at: Date.now(), value });
5294
5365
  return value;
5295
5366
  }).finally(() => {
@@ -5318,7 +5389,7 @@ function createApiClient(cfg) {
5318
5389
  return false;
5319
5390
  }
5320
5391
  }
5321
- return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchPromotions, fetchQuote, screenWallet, reportSubmission, apiBase };
5392
+ return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchZdHeavyRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchPromotions, fetchQuote, screenWallet, reportSubmission, apiBase };
5322
5393
  }
5323
5394
 
5324
5395
  // src/core/plan.ts
@@ -5393,12 +5464,12 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
5393
5464
  const parties = [];
5394
5465
  const seenParty = /* @__PURE__ */ new Set();
5395
5466
  for (const raw2 of [payer, destination.address]) {
5396
- const addr = String(raw2 || "").trim();
5397
- if (!addr) continue;
5398
- const key2 = /^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr;
5467
+ const addr2 = String(raw2 || "").trim();
5468
+ if (!addr2) continue;
5469
+ const key2 = /^0x[0-9a-fA-F]+$/.test(addr2) ? addr2.toLowerCase() : addr2;
5399
5470
  if (seenParty.has(key2)) continue;
5400
5471
  seenParty.add(key2);
5401
- parties.push(addr);
5472
+ parties.push(addr2);
5402
5473
  }
5403
5474
  try {
5404
5475
  const screens = await Promise.all(parties.map((address) => api.screenWallet(address, destination.chainId)));
@@ -5613,6 +5684,322 @@ async function buildSwapPlan(api, swap, payer, wallet = {}) {
5613
5684
  };
5614
5685
  }
5615
5686
 
5687
+ // src/core/zdheavy-cancel.ts
5688
+ var lower3 = (s) => (typeof s === "string" ? s : "").toLowerCase();
5689
+ var ORDER_ID = /^0x[0-9a-fA-F]{64}$/;
5690
+ var EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
5691
+ function isZdHeavyOrderId(v) {
5692
+ return typeof v === "string" && ORDER_ID.test(v);
5693
+ }
5694
+ function zdHeavyRecovery(plan, wallet) {
5695
+ const claims = wallet ? plan.places.flatMap(
5696
+ (p) => p.kind === "router" && p.chainId !== void 0 && p.contract ? p.claimable.filter((c) => lower3(c.payee) === lower3(wallet)).map((c) => ({ chainId: p.chainId, token: c.token, amount: c.amount })) : []
5697
+ ) : [];
5698
+ if (claims.length) return { kind: "claim", claims };
5699
+ if (plan.finished) return { kind: "delivered" };
5700
+ if (plan.state === "refund_complete" && plan.complete) {
5701
+ return { kind: "refunded", refunds: plan.places.flatMap((p) => p.refunds.map((r) => ({ ...r, chainId: p.chainId }))) };
5702
+ }
5703
+ if (plan.ownerType !== "evm") return { kind: "not-owner" };
5704
+ const holding = plan.places.filter(
5705
+ (p) => p.kind === "router" && p.chainId !== void 0 && !!p.contract && p.canCancelInPerson && !p.complete && p.lots.length > 0
5706
+ );
5707
+ if (holding.length) return { kind: "cancel", chains: holding.map((p) => p.chainId), requested: plan.state === "cancel_requested" };
5708
+ if (plan.state === "open" && !plan.complete) return { kind: "cancel", chains: [plan.originChainId], requested: false };
5709
+ return { kind: "waiting" };
5710
+ }
5711
+ var MAX_PLACES = 32;
5712
+ var MAX_ROWS = 64;
5713
+ var DIGITS = /^\d{1,78}$/;
5714
+ var LOT_KEY = /^(?:\d{1,78}|0x[0-9a-fA-F]{1,64})$/;
5715
+ var TX_HASH = /^0x[0-9a-fA-F]{64}$/;
5716
+ var posInt = (v) => typeof v === "number" && Number.isSafeInteger(v) && v > 0 ? v : void 0;
5717
+ var nonNegInt = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
5718
+ var addr = (v) => typeof v === "string" && EVM_ADDRESS.test(v);
5719
+ var list = (v) => v === void 0 || v === null ? [] : Array.isArray(v) && v.length <= MAX_ROWS ? v : null;
5720
+ var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
5721
+ function normalizeCancellationPlan(raw2, orderId) {
5722
+ const r = obj(raw2);
5723
+ if (!r || !isZdHeavyOrderId(orderId) || lower3(r.orderId) !== lower3(orderId)) return null;
5724
+ const ownerType = r.ownerType === "evm" || r.ownerType === "solana" ? r.ownerType : null;
5725
+ const state = r.state === "open" || r.state === "cancel_requested" || r.state === "refund_complete" ? r.state : null;
5726
+ const originChainId = posInt(r.originChainId);
5727
+ if (!ownerType || !state || originChainId === void 0 || typeof r.complete !== "boolean" || typeof r.owner !== "string" || r.owner.length > 64) return null;
5728
+ if (r.finished !== void 0 && typeof r.finished !== "boolean") return null;
5729
+ if (!Array.isArray(r.places) || r.places.length > MAX_PLACES) return null;
5730
+ const places = [];
5731
+ for (const rawPlace of r.places) {
5732
+ const p = obj(rawPlace);
5733
+ if (!p || p.kind !== "router" && p.kind !== "hub" || typeof p.canCancelInPerson !== "boolean" || typeof p.complete !== "boolean") return null;
5734
+ const chainId = p.chainId === void 0 ? void 0 : posInt(p.chainId);
5735
+ if (p.chainId !== void 0 && chainId === void 0) return null;
5736
+ const contract = typeof p.contract === "string" ? p.contract : "";
5737
+ if (contract && !addr(contract)) return null;
5738
+ const lots = list(p.lots);
5739
+ const refunds = list(p.refunds);
5740
+ const claimable = list(p.claimable);
5741
+ if (!lots || !refunds || !claimable) return null;
5742
+ const place = {
5743
+ kind: p.kind,
5744
+ chainId,
5745
+ contract,
5746
+ canCancelInPerson: p.canCancelInPerson,
5747
+ complete: p.complete,
5748
+ lots: [],
5749
+ refunds: [],
5750
+ claimable: []
5751
+ };
5752
+ for (const rawLot of lots) {
5753
+ const l = obj(rawLot);
5754
+ if (!l || !nonNegInt(l.step) || !addr(l.token) || typeof l.amount !== "string" || !DIGITS.test(l.amount) || typeof l.key !== "string" || !LOT_KEY.test(l.key))
5755
+ return null;
5756
+ place.lots.push({ step: l.step, token: l.token, amount: l.amount, key: l.key });
5757
+ }
5758
+ for (const rawRefund of refunds) {
5759
+ const f = obj(rawRefund);
5760
+ if (!f || typeof f.txHash !== "string" || !TX_HASH.test(f.txHash) || !nonNegInt(f.step) || !addr(f.token) || typeof f.amount !== "string" || !DIGITS.test(f.amount) || !addr(f.to))
5761
+ return null;
5762
+ place.refunds.push({ txHash: f.txHash, step: f.step, token: f.token, amount: f.amount, to: f.to });
5763
+ }
5764
+ for (const rawClaim of claimable) {
5765
+ const c = obj(rawClaim);
5766
+ if (!c || !addr(c.payee) || !addr(c.token) || typeof c.amount !== "string" || !DIGITS.test(c.amount)) return null;
5767
+ place.claimable.push({ payee: c.payee, token: c.token, amount: c.amount });
5768
+ }
5769
+ places.push(place);
5770
+ }
5771
+ return {
5772
+ orderId: r.orderId,
5773
+ ownerType,
5774
+ owner: r.owner,
5775
+ originChainId,
5776
+ state,
5777
+ complete: r.complete,
5778
+ ...r.finished !== void 0 ? { finished: r.finished } : {},
5779
+ places
5780
+ };
5781
+ }
5782
+ function zdHeavyOrderPath(orderId, tail) {
5783
+ if (!isZdHeavyOrderId(orderId)) throw new ZdHeavyCodecError("Not a ZD Heavy order id.");
5784
+ return `/orders/${orderId.toLowerCase()}/${tail}`;
5785
+ }
5786
+ async function fetchZdHeavyCancellation(api, orderId) {
5787
+ if (!isZdHeavyOrderId(orderId)) return null;
5788
+ try {
5789
+ return normalizeCancellationPlan(await api.apiRequest(zdHeavyOrderPath(orderId, "cancellation"), { timeoutMs: 1e4 }), orderId);
5790
+ } catch {
5791
+ return null;
5792
+ }
5793
+ }
5794
+ function unsigned(raw2) {
5795
+ const r = obj(raw2);
5796
+ const s = (v) => typeof v === "string" ? v : typeof v === "number" ? String(v) : "";
5797
+ if (!r) return { purpose: "", chainId: "", from: "", to: "", data: "" };
5798
+ return {
5799
+ purpose: s(r.purpose),
5800
+ chainId: s(r.chainId),
5801
+ from: s(r.from),
5802
+ to: s(r.to),
5803
+ data: s(r.data),
5804
+ ...r.value !== void 0 ? { value: s(r.value) } : {}
5805
+ };
5806
+ }
5807
+ async function buildZdHeavyCancelTx(api, orderId, chainId) {
5808
+ return unsigned(
5809
+ await api.apiRequest(zdHeavyOrderPath(orderId, "cancel-tx"), {
5810
+ method: "POST",
5811
+ body: JSON.stringify(chainId === void 0 ? {} : { chainId }),
5812
+ timeoutMs: 15e3
5813
+ })
5814
+ );
5815
+ }
5816
+ async function buildZdHeavyClaimTx(api, orderId, chainId, token) {
5817
+ return unsigned(
5818
+ await api.apiRequest(zdHeavyOrderPath(orderId, "claim-tx"), {
5819
+ method: "POST",
5820
+ body: JSON.stringify({ chainId, token }),
5821
+ timeoutMs: 15e3
5822
+ })
5823
+ );
5824
+ }
5825
+ var ZDHEAVY_CANCEL_SELECTOR = "0xf26bce2c";
5826
+ var ZDHEAVY_CLAIM_SELECTOR = "0x1e83409a";
5827
+ var ZDHEAVY_CLAIM_TO_SELECTOR = "0x21c0b342";
5828
+ var MAX_CANCEL_KEYS = 32;
5829
+ function reader(data, selector) {
5830
+ if (typeof data !== "string" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(data) || data.slice(0, 10).toLowerCase() !== selector) {
5831
+ throw new ZdHeavyCodecError("Unexpected call");
5832
+ }
5833
+ const body = data.slice(10).toLowerCase();
5834
+ const size = body.length / 2;
5835
+ const fail = () => {
5836
+ throw new ZdHeavyCodecError("Invalid calldata");
5837
+ };
5838
+ const word2 = (at, bits = 256) => {
5839
+ if (!Number.isSafeInteger(at) || at < 0 || at + 32 > size) return fail();
5840
+ const n = BigInt(`0x${body.slice(at * 2, (at + 32) * 2)}`);
5841
+ if (bits < 256 && n >= 1n << BigInt(bits)) return fail();
5842
+ return n;
5843
+ };
5844
+ const fixed = (at) => {
5845
+ word2(at);
5846
+ return `0x${body.slice(at * 2, (at + 32) * 2)}`;
5847
+ };
5848
+ const address = (at) => `0x${word2(at, 160).toString(16).padStart(40, "0")}`;
5849
+ const offset = (at, expected) => {
5850
+ if (word2(at) !== BigInt(expected)) fail();
5851
+ };
5852
+ const count = (at, each) => {
5853
+ const n = word2(at);
5854
+ if (n > BigInt(Math.floor((size - at - 32) / each))) return fail();
5855
+ return Number(n);
5856
+ };
5857
+ const bytes = (at) => {
5858
+ const n = word2(at);
5859
+ if (n > BigInt(size - at - 32)) return fail();
5860
+ const length = Number(n);
5861
+ const end = at + 32 + Math.ceil(length / 32) * 32;
5862
+ if (end > size || /[^0]/.test(body.slice((at + 32 + length) * 2, end * 2))) return fail();
5863
+ return { value: `0x${body.slice((at + 32) * 2, (at + 32 + length) * 2)}`, end };
5864
+ };
5865
+ return { size, fail, word: word2, fixed, address, offset, count, bytes };
5866
+ }
5867
+ function decodeZdHeavyCancel(data) {
5868
+ const r = reader(data, ZDHEAVY_CANCEL_SELECTOR);
5869
+ const orderId = r.fixed(0);
5870
+ const P3 = 96;
5871
+ r.offset(32, P3);
5872
+ const expiryDate = r.word(P3, 64);
5873
+ r.offset(P3 + 32, 96);
5874
+ const header = r.bytes(P3 + 96);
5875
+ r.offset(P3 + 64, header.end - P3);
5876
+ const hashesAt = header.end;
5877
+ const n = r.count(hashesAt, 32);
5878
+ const stepHashes = [];
5879
+ for (let i = 0; i < n; i++) stepHashes.push(r.fixed(hashesAt + 32 + i * 32));
5880
+ const keysAt = hashesAt + 32 + n * 32;
5881
+ r.offset(64, keysAt);
5882
+ const k = r.count(keysAt, 32);
5883
+ const keys = [];
5884
+ for (let i = 0; i < k; i++) keys.push(r.word(keysAt + 32 + i * 32));
5885
+ if (keysAt + 32 + k * 32 !== r.size) r.fail();
5886
+ return { orderId, proof: { expiryDate, orderHeader: header.value, stepHashes }, keys };
5887
+ }
5888
+ function decodeZdHeavyClaim(data) {
5889
+ const selector = typeof data === "string" ? data.slice(0, 10).toLowerCase() : "";
5890
+ if (selector === ZDHEAVY_CLAIM_SELECTOR) {
5891
+ const r2 = reader(data, ZDHEAVY_CLAIM_SELECTOR);
5892
+ if (r2.size !== 32) r2.fail();
5893
+ return { token: r2.address(0) };
5894
+ }
5895
+ const r = reader(data, ZDHEAVY_CLAIM_TO_SELECTOR);
5896
+ if (r.size !== 64) r.fail();
5897
+ return { token: r.address(0), to: r.address(32) };
5898
+ }
5899
+ var hexBytes2 = (h2) => Uint8Array.from(h2.slice(2).match(/../g) ?? [], (b) => Number.parseInt(b, 16));
5900
+ var keccak = (h2) => `0x${keccak256Hex(hexBytes2(h2))}`;
5901
+ function orderIdFromProof(expiryDate, header, stepHashes) {
5902
+ const tag = Array.from(new TextEncoder().encode("ZD/ORDER"), (b) => b.toString(16).padStart(2, "0")).join("");
5903
+ return keccak(`0x${tag}${expiryDate.toString(16).padStart(16, "0")}${keccak(header).slice(2)}${stepHashes.map((h2) => h2.slice(2)).join("")}`);
5904
+ }
5905
+ var TX = /^0x[0-9a-fA-F]{64}$/;
5906
+ var succeeded = (receipt) => {
5907
+ const status = obj(receipt)?.status;
5908
+ return typeof status === "string" && /^0x0*1$/.test(status);
5909
+ };
5910
+ async function verifyZdHeavySourceOrder(rpc, chainId, hash2, orderId) {
5911
+ const no = (reason) => ({ ok: false, reason });
5912
+ if (!SUPPORTED_CHAIN_IDS.has(chainId) || typeof hash2 !== "string" || !TX.test(hash2) || !isZdHeavyOrderId(orderId)) return no("not checkable");
5913
+ try {
5914
+ const [tx, receipt] = await Promise.all([rpc(chainId, "eth_getTransactionByHash", [hash2]), rpc(chainId, "eth_getTransactionReceipt", [hash2])]);
5915
+ const t = obj(tx);
5916
+ if (!t || lower3(t.hash) !== lower3(hash2)) return no("source transaction not found");
5917
+ if (!succeeded(receipt) || lower3(obj(receipt)?.transactionHash) !== lower3(hash2)) return no("source transaction not confirmed");
5918
+ const router = checkZdHeavyRouter(chainId, typeof t.to === "string" ? t.to : "");
5919
+ if (!router.ok) return no("source transaction is not to a pinned router");
5920
+ const input = typeof t.input === "string" ? t.input : typeof t.data === "string" ? t.data : "";
5921
+ const { submission } = decodeZdHeavySubmit(input);
5922
+ const id = orderIdOf(submission.expiryDate, encodeOrderHeader(submission.serial, router.address, submission.ownerType, submission.owner), submission.steps);
5923
+ return lower3(id) === lower3(orderId) ? { ok: true } : no("source transaction submitted another order");
5924
+ } catch {
5925
+ return no("source transaction could not be read");
5926
+ }
5927
+ }
5928
+ var refuse2 = (what) => ({ ok: false, reason: `The ${what} does not match this order. Refusing to sign.` });
5929
+ function commonChecks(tx, owner, purpose, chainId) {
5930
+ if (!tx || tx.purpose !== purpose) return refuse2("transaction kind");
5931
+ const chain2 = typeof tx.chainId === "string" && /^\d{1,12}$/.test(tx.chainId) ? Number(tx.chainId) : NaN;
5932
+ if (!Number.isSafeInteger(chain2) || chain2 <= 0) return refuse2("chain");
5933
+ if (chainId !== void 0 && chain2 !== chainId) return refuse2("chain");
5934
+ const router = checkZdHeavyRouter(chain2, tx.to);
5935
+ if (!router.ok) return { ok: false, reason: router.reason };
5936
+ if (!addr(owner) || !addr(tx.from) || lower3(tx.from) !== lower3(owner)) return refuse2("sender");
5937
+ try {
5938
+ if (tx.value !== void 0 && tx.value !== "" && BigInt(tx.value) !== 0n) return refuse2("value");
5939
+ } catch {
5940
+ return refuse2("value");
5941
+ }
5942
+ return { ok: true, chainId: chain2, router: router.address };
5943
+ }
5944
+ var accepted = (chainId, owner, router, data) => ({
5945
+ ok: true,
5946
+ chainId,
5947
+ tx: { from: owner, to: router, data: data.toLowerCase(), value: "0x0" }
5948
+ });
5949
+ function checkZdHeavyCancelTx(tx, e) {
5950
+ const base = commonChecks(tx, e.owner, "cancel", e.chainId);
5951
+ if (!base.ok) return base;
5952
+ let decoded;
5953
+ try {
5954
+ decoded = decodeZdHeavyCancel(tx.data);
5955
+ } catch {
5956
+ return refuse2("call");
5957
+ }
5958
+ const { orderId, proof, keys } = decoded;
5959
+ if (!isZdHeavyOrderId(e.orderId) || lower3(orderId) !== lower3(e.orderId)) return refuse2("order id");
5960
+ if (keys.length > MAX_CANCEL_KEYS) return refuse2("lot keys");
5961
+ const listed = e.lotKeys ? new Set(
5962
+ e.lotKeys.map((k) => {
5963
+ try {
5964
+ return BigInt(k).toString();
5965
+ } catch {
5966
+ return "";
5967
+ }
5968
+ })
5969
+ ) : void 0;
5970
+ const seen = /* @__PURE__ */ new Set();
5971
+ for (const k of keys) {
5972
+ if (listed && !listed.has(k.toString())) return refuse2("lot keys");
5973
+ const step = k >> 160n;
5974
+ const tokenBits = k & (1n << 160n) - 1n;
5975
+ if (step >= BigInt(proof.stepHashes.length) || tokenBits === 0n || seen.has(k.toString())) return refuse2("lot keys");
5976
+ seen.add(k.toString());
5977
+ }
5978
+ if (proof.stepHashes.length < 1 || proof.stepHashes.length > 8) return refuse2("order proof");
5979
+ if (lower3(orderIdFromProof(proof.expiryDate, proof.orderHeader, proof.stepHashes)) !== lower3(orderId)) return refuse2("order proof");
5980
+ const h2 = proof.orderHeader;
5981
+ if (h2.length !== 2 + ORDER_HEADER_LEN * 2) return refuse2("order proof");
5982
+ const routerWordHex = `0x${h2.slice(2 + 11 * 2, 2 + 43 * 2)}`;
5983
+ const ownerType = Number.parseInt(h2.slice(2 + 43 * 2, 2 + 44 * 2), 16);
5984
+ const ownerWordHex = `0x${h2.slice(2 + 44 * 2)}`;
5985
+ if (lower3(routerWordHex) !== lower3(ownerWord(base.router))) return refuse2("router");
5986
+ if (ownerType !== 1 || lower3(ownerWordHex) !== lower3(ownerWord(e.owner))) return refuse2("owner");
5987
+ return accepted(base.chainId, e.owner, base.router, tx.data);
5988
+ }
5989
+ function checkZdHeavyClaimTx(tx, e) {
5990
+ const base = commonChecks(tx, e.owner, "claim", e.chainId);
5991
+ if (!base.ok) return base;
5992
+ let decoded;
5993
+ try {
5994
+ decoded = decodeZdHeavyClaim(tx.data);
5995
+ } catch {
5996
+ return refuse2("call");
5997
+ }
5998
+ if (!addr(e.token) || lower3(decoded.token) !== lower3(e.token)) return refuse2("token");
5999
+ if (decoded.to !== void 0 && lower3(decoded.to) !== lower3(e.owner)) return refuse2("recipient");
6000
+ return accepted(base.chainId, e.owner, base.router, tx.data);
6001
+ }
6002
+
5616
6003
  // src/core/intent-schema.ts
5617
6004
  var STABLEGENIE_INTENT_VERSION = 1;
5618
6005
  var STABLEGENIE_INTENT_TTL_MS = 5 * 60 * 1e3;
@@ -5886,7 +6273,13 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
5886
6273
  return void 0;
5887
6274
  }
5888
6275
  }
5889
- return { payerNonceBaseline, verifySubmittedTx, readBalances, readNativeBalance, readZdHeavySubmitFee };
6276
+ async function bundledRpc(chainId, method, params) {
6277
+ const override = rpcOverrides[Number(chainId)];
6278
+ const rpc = override && /^https?:\/\//i.test(override) ? override : BUNDLED_RPC[Number(chainId)];
6279
+ if (!rpc) throw new Error("No bundled RPC for this chain");
6280
+ return rpcCall(rpc, method, params);
6281
+ }
6282
+ return { payerNonceBaseline, verifySubmittedTx, readBalances, readNativeBalance, readZdHeavySubmitFee, bundledRpc };
5890
6283
  }
5891
6284
 
5892
6285
  // src/core/config.ts
@@ -6009,10 +6402,11 @@ function createEngine(config = {}) {
6009
6402
  fetchPrices: (symbols) => api.fetchPrices ? api.fetchPrices(symbols) : Promise.resolve({}),
6010
6403
  fetchPromotions: () => api.fetchPromotions ? api.fetchPromotions() : Promise.resolve([]),
6011
6404
  fetchCatalogue: async (allowedAssets, product, options) => {
6012
- const [chains, registryTokens, routes, health, vaults] = await Promise.all([
6405
+ const [chains, registryTokens, routes, zdHeavyRoutes, health, vaults] = await Promise.all([
6013
6406
  api.fetchChains().catch(() => []),
6014
6407
  api.fetchTokens().catch(() => []),
6015
6408
  api.fetchRoutes().catch(() => []),
6409
+ api.fetchZdHeavyRoutes(),
6016
6410
  api.fetchRouteHealth(),
6017
6411
  api.fetchRwaVaults()
6018
6412
  ]);
@@ -6023,6 +6417,7 @@ function createEngine(config = {}) {
6023
6417
  chains,
6024
6418
  tokens,
6025
6419
  routes,
6420
+ zdHeavyRoutes,
6026
6421
  product,
6027
6422
  ...allowed ? { allowedAssets: allowed } : {},
6028
6423
  // Solana is a SOURCE only for a surface that can pay from it (the exchange card, through the
@@ -6044,6 +6439,10 @@ function createEngine(config = {}) {
6044
6439
  executeSolanaPlanStaged: (input) => executeSolanaPlanStaged({ ...input, rpc: input.rpc ?? solanaRpc }),
6045
6440
  previewSolanaSource: (input) => previewSolanaSource(api, input),
6046
6441
  trackDelivery: (hash2) => fetchDelivery(api, hash2),
6442
+ fetchZdHeavyCancellation: (orderId) => fetchZdHeavyCancellation(api, orderId),
6443
+ buildZdHeavyCancelTx: (orderId, chainId) => buildZdHeavyCancelTx(api, orderId, chainId),
6444
+ buildZdHeavyClaimTx: (orderId, chainId, tokenAddress) => buildZdHeavyClaimTx(api, orderId, chainId, tokenAddress),
6445
+ verifyZdHeavySourceOrder: (chainId, hash2, orderId) => verifyZdHeavySourceOrder(verifier.bundledRpc, chainId, hash2, orderId),
6047
6446
  fetchWalletHistory: (wallets) => fetchWalletHistory(api, wallets),
6048
6447
  readSolanaBalance: (owner, mint) => readSolanaBalance(solanaRpc, owner, mint),
6049
6448
  simulateSolanaCost: (plan) => simulateSolanaCost(solanaRpc, plan),
@@ -6091,6 +6490,7 @@ exports.ERC20_TRANSFER_SELECTOR = ERC20_TRANSFER_SELECTOR;
6091
6490
  exports.EXECUTABLE_STABLE_ASSETS = EXECUTABLE_STABLE_ASSETS;
6092
6491
  exports.FLOOR_CATEGORIES = FLOOR_CATEGORIES;
6093
6492
  exports.LZ_FEE_BUFFER_BPS = LZ_FEE_BUFFER_BPS;
6493
+ exports.MAX_CANCEL_KEYS = MAX_CANCEL_KEYS;
6094
6494
  exports.MAX_LZ_MSG_VALUE_WEI = MAX_LZ_MSG_VALUE_WEI;
6095
6495
  exports.MAX_LZ_MSG_VALUE_WEI_BY_CHAIN = MAX_LZ_MSG_VALUE_WEI_BY_CHAIN;
6096
6496
  exports.MAX_QUOTE_CANDIDATES = MAX_QUOTE_CANDIDATES;
@@ -6126,6 +6526,9 @@ exports.WAIT_MIN_SEC = WAIT_MIN_SEC;
6126
6526
  exports.WAIT_POSITIONS = WAIT_POSITIONS;
6127
6527
  exports.WAIT_STEP_SEC = WAIT_STEP_SEC;
6128
6528
  exports.WALLET_HISTORY_LIMIT = WALLET_HISTORY_LIMIT;
6529
+ exports.ZDHEAVY_CANCEL_SELECTOR = ZDHEAVY_CANCEL_SELECTOR;
6530
+ exports.ZDHEAVY_CLAIM_SELECTOR = ZDHEAVY_CLAIM_SELECTOR;
6531
+ exports.ZDHEAVY_CLAIM_TO_SELECTOR = ZDHEAVY_CLAIM_TO_SELECTOR;
6129
6532
  exports.ZD_HEAVY_KEY_PREFIX = ZD_HEAVY_KEY_PREFIX;
6130
6533
  exports.ZERO_ADDRESS = ZERO_ADDRESS;
6131
6534
  exports.addressWord = addressWord;
@@ -6157,6 +6560,8 @@ exports.buildPayOptions = buildPayOptions;
6157
6560
  exports.buildRoute = buildRoute;
6158
6561
  exports.buildSolanaSourcePlan = buildSolanaSourcePlan;
6159
6562
  exports.buildSwapPlan = buildSwapPlan;
6563
+ exports.buildZdHeavyCancelTx = buildZdHeavyCancelTx;
6564
+ exports.buildZdHeavyClaimTx = buildZdHeavyClaimTx;
6160
6565
  exports.bytes32Word = bytes32Word;
6161
6566
  exports.bytesEqual = bytesEqual;
6162
6567
  exports.bytesPayload = bytesPayload;
@@ -6173,6 +6578,8 @@ exports.checkSolanaPlan = checkSolanaPlan;
6173
6578
  exports.checkSolanaProgram = checkSolanaProgram;
6174
6579
  exports.checkSolanaReceiver = checkSolanaReceiver;
6175
6580
  exports.checkSolanaRouteBuffer = checkSolanaRouteBuffer;
6581
+ exports.checkZdHeavyCancelTx = checkZdHeavyCancelTx;
6582
+ exports.checkZdHeavyClaimTx = checkZdHeavyClaimTx;
6176
6583
  exports.clampWait = clampWait;
6177
6584
  exports.classifyQuoteError = classifyQuoteError;
6178
6585
  exports.compareAmount = compareAmount;
@@ -6198,6 +6605,8 @@ exports.createVerifier = createVerifier;
6198
6605
  exports.decodeSolanaSubmitOrder = decodeSolanaSubmitOrder;
6199
6606
  exports.decodeSubmitOrder = decodeSolanaSubmitOrder;
6200
6607
  exports.decodeSubmitOrderCalldata = decodeSubmitOrderCalldata;
6608
+ exports.decodeZdHeavyCancel = decodeZdHeavyCancel;
6609
+ exports.decodeZdHeavyClaim = decodeZdHeavyClaim;
6201
6610
  exports.deriveSolanaEvent = deriveSolanaEvent;
6202
6611
  exports.destinationAvailability = destinationAvailability;
6203
6612
  exports.destinationKeys = destinationKeys;
@@ -6221,6 +6630,7 @@ exports.fastestOption = fastestOption;
6221
6630
  exports.fetchDelivery = fetchDelivery;
6222
6631
  exports.fetchPaymentPlan = fetchPaymentPlan;
6223
6632
  exports.fetchWalletHistory = fetchWalletHistory;
6633
+ exports.fetchZdHeavyCancellation = fetchZdHeavyCancellation;
6224
6634
  exports.finalOf = finalOf;
6225
6635
  exports.findProgramAddress = findProgramAddress;
6226
6636
  exports.findToken = findToken;
@@ -6253,6 +6663,7 @@ exports.isSolanaAddress = isSolanaAddress;
6253
6663
  exports.isSolanaChainId = isSolanaChainId;
6254
6664
  exports.isSourceToken = isSourceToken;
6255
6665
  exports.isSubmitOrder = isSubmitOrder;
6666
+ exports.isZdHeavyOrderId = isZdHeavyOrderId;
6256
6667
  exports.laneAvailabilityState = laneAvailabilityState;
6257
6668
  exports.laneKey = laneKey;
6258
6669
  exports.laneKeys = laneKeys;
@@ -6269,10 +6680,12 @@ exports.nativeFeeShortLabel = nativeFeeShortLabel;
6269
6680
  exports.nativeFeeShortMessage = nativeFeeShortMessage;
6270
6681
  exports.nativeSymbol = nativeSymbol;
6271
6682
  exports.normalizeAddress = normalizeAddress;
6683
+ exports.normalizeCancellationPlan = normalizeCancellationPlan;
6272
6684
  exports.normalizeDecimalText = normalizeDecimalText;
6273
6685
  exports.normalizeDelivery = normalizeDelivery;
6274
6686
  exports.normalizeOrderRequest = normalizeOrderRequest;
6275
6687
  exports.normalizeOrderRequests = normalizeOrderRequests;
6688
+ exports.orderIdFromProof = orderIdFromProof;
6276
6689
  exports.overwriteBlockhash = overwriteBlockhash;
6277
6690
  exports.pairPromotionsInto = pairPromotionsInto;
6278
6691
  exports.parity = parity;
@@ -6351,6 +6764,7 @@ exports.verifySolanaSubmit = verifySolanaSubmit;
6351
6764
  exports.verifySolanaTransaction = verifySolanaTransaction;
6352
6765
  exports.verifySubmit = verifySolanaSubmit;
6353
6766
  exports.verifyTransaction = verifySolanaTransaction;
6767
+ exports.verifyZdHeavySourceOrder = verifyZdHeavySourceOrder;
6354
6768
  exports.visibleOptions = visibleOptions;
6355
6769
  exports.waitFraction = waitFraction;
6356
6770
  exports.waitFromFraction = waitFromFraction;
@@ -6358,4 +6772,5 @@ exports.waitLabel = waitLabel;
6358
6772
  exports.waitScaleFor = waitScaleFor;
6359
6773
  exports.withVaultArtwork = withVaultArtwork;
6360
6774
  exports.zdHeavyOptionKey = zdHeavyOptionKey;
6775
+ exports.zdHeavyRecovery = zdHeavyRecovery;
6361
6776
  exports.zdHeavyUnavailableStatus = zdHeavyUnavailableStatus;