@glacislabs/stablegenie-zerodelta 4.18.1 → 4.19.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.
@@ -1,4 +1,4 @@
1
- import { CHAIN_DISPLAY_NAMES, EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, complianceView, complianceTagOf, symbolKey, normalizeDecimalText, findToken, laneLimitFor, laneLimitSymbol, tokenTicker, exceedsLaneLimit, assetDecimals, parseUnitsDecimal, counterpartTokens, assetClassOf, brokenLaneFor, brokenLaneReason, destinationAvailability, laneLimitHint, tickerOn, laneLimitError, routeNativeValue, formatNative, nativeSymbol, isSolanaChainId, isSellableRwa, formatUnits, amountFieldError, solanaQuoteCompliance, directComplianceFromScreens, SUPPORTED_CHAIN_IDS, complianceChecks, DIRECT_CHECK_IDS, isSolanaAddress, createEngine, isAddress, checkNativeFee, nativeFeeShortLabel, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, TRACKING, mergeHistory, solanaPlanNeedsPreparation, SOLANA_CHAIN_ID, unattributedComplianceReasons, distinctScreenedWallets, formatJurisdiction, humanizeComplianceReason, DIRECT_SCOPE_NOTE, categoryLabel, SCREENING_BUCKETS, BUNDLED_RPC, foldTicker } from './chunk-NXEWSGMY.js';
1
+ import { CHAIN_DISPLAY_NAMES, EXECUTABLE_STABLE_ASSETS, STABLE_ASSETS, SUPPORTED_ASSETS, complianceView, complianceTagOf, symbolKey, normalizeDecimalText, findToken, laneLimitFor, laneLimitSymbol, tokenTicker, exceedsLaneLimit, assetDecimals, parseUnitsDecimal, counterpartTokens, assetClassOf, brokenLaneFor, brokenLaneReason, destinationAvailability, laneLimitHint, tickerOn, laneLimitError, routeNativeValue, formatNative, nativeSymbol, isSolanaChainId, isSellableRwa, formatUnits, amountFieldError, solanaQuoteCompliance, directComplianceFromScreens, SUPPORTED_CHAIN_IDS, complianceChecks, DIRECT_CHECK_IDS, isSolanaAddress, createEngine, isAddress, checkNativeFee, nativeFeeShortLabel, nativeFeeShortMessage, zdHeavyExpected, preflightZdHeavyPlan, allowanceCovers, validatePlannedTransaction, priceCompareOptions, parity, pickForWait, cornerTags, extraVsFastest, proposedWait, visibleOptions, promotionFor, estimateBonus, pairPromotionsInto, promotedAssets, TRACKING, mergeHistory, hasValidChecksum, solanaPlanNeedsPreparation, SOLANA_CHAIN_ID, unattributedComplianceReasons, distinctScreenedWallets, formatJurisdiction, humanizeComplianceReason, DIRECT_SCOPE_NOTE, categoryLabel, SCREENING_BUCKETS, BUNDLED_RPC, foldTicker } from './chunk-NLXQVXZ5.js';
2
2
  import { createContext, useState, useRef, useMemo, useEffect, useCallback, useId, useLayoutEffect, createElement, useContext, useSyncExternalStore, useReducer } from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -19,11 +19,15 @@ function useDelivery(engine, hash) {
19
19
  let alive = true;
20
20
  let timer2;
21
21
  let answered = false;
22
+ let waitsOnOwner = false;
22
23
  let unanswered = 0;
23
24
  const started2 = Date.now();
24
25
  setState({ hash, value: TRACKING });
25
26
  const schedule = () => {
26
- if (Date.now() - started2 > DELIVERY_GIVE_UP_MS) return setState({ hash, value: UNAVAILABLE });
27
+ if (Date.now() - started2 > DELIVERY_GIVE_UP_MS) {
28
+ if (waitsOnOwner) return;
29
+ return setState({ hash, value: UNAVAILABLE });
30
+ }
27
31
  timer2 = setTimeout(tick, deliveryPollDelay(Date.now() - started2));
28
32
  };
29
33
  const tick = async () => {
@@ -36,6 +40,7 @@ function useDelivery(engine, hash) {
36
40
  return schedule();
37
41
  }
38
42
  answered = true;
43
+ waitsOnOwner = next.phase === "attention";
39
44
  setState({ hash, value: next });
40
45
  if (next.phase === "delivered" || next.phase === "failed") return;
41
46
  schedule();
@@ -60,7 +65,15 @@ var STEP_LABEL = {
60
65
  arrived: "Arrived",
61
66
  filled: "Filled",
62
67
  outbound_bridging: "Bridging",
63
- delivered: "Delivered"
68
+ delivered: "Delivered",
69
+ // ZD Heavy (core/delivery.ts; mirrors zd-dapp src/lib/zdHeavyTimeline.ts). How the order was filled
70
+ // (netted, partly netted, swapped) is the protocol's business, so the holder reads one "Filled".
71
+ route_completed: "Filled",
72
+ route: "Filled",
73
+ cancellation_requested: "Cancellation requested",
74
+ refunded: "Refunded",
75
+ ready_to_claim: "Ready to claim",
76
+ claimed: "Claimed"
64
77
  };
65
78
  var label = (name) => STEP_LABEL[name] ?? name.replace(/_/g, " ");
66
79
  function deliveryHeadline(delivery, sourceConfirmed, direct = false) {
@@ -69,12 +82,14 @@ function deliveryHeadline(delivery, sourceConfirmed, direct = false) {
69
82
  case "delivered":
70
83
  return "Delivered";
71
84
  case "failed":
85
+ if (delivery.status === "cancelled" && delivery.refunded) return "Cancelled \u2014 refunded to the owner";
72
86
  return delivery.status === "cancelled" ? "Cancelled \u2014 not delivered" : `Not delivered (${delivery.status.replace(/_/g, " ")}) \u2014 open the transaction for details`;
73
87
  case "attention":
74
88
  return delivery.status === "cancel_pending" ? "Being cancelled \u2014 not delivered" : "Waiting to be claimed \u2014 open the transaction";
75
89
  case "in-progress": {
76
90
  if (delivery.status === "continuing") return "On its way \u2014 final leg next";
77
91
  const next = delivery.steps.find((s) => !s.done);
92
+ if (next?.name === "route") return "On its way";
78
93
  return next ? `On its way \u2014 ${label(next.name).toLowerCase()} next` : "On its way";
79
94
  }
80
95
  case "unavailable":
@@ -486,7 +501,13 @@ function useFlow(args) {
486
501
  statusRef.current = status;
487
502
  const { idle: idle2, returnedAt: returnedAt2 } = useUserPresence();
488
503
  const routes = plan?.routes ?? [];
489
- const selected = useMemo(() => routes.find((r) => r.id === selectedId) ?? routes.find((r) => r.recommended) ?? routes[0] ?? null, [routes, selectedId]);
504
+ const baseSelected = useMemo(() => routes.find((r) => r.id === selectedId) ?? routes.find((r) => r.recommended) ?? routes[0] ?? null, [routes, selectedId]);
505
+ const [pickedOptionId, setPickedOptionId] = useState(null);
506
+ const selected = useMemo(() => {
507
+ if (!baseSelected || !pickedOptionId || pickedOptionId === baseSelected.selectedOptionId) return baseSelected;
508
+ const alt = baseSelected.alternatives?.find((r) => r.selectedOptionId === pickedOptionId);
509
+ return alt ? { ...alt, recommended: baseSelected.recommended } : baseSelected;
510
+ }, [baseSelected, pickedOptionId]);
490
511
  const reload = useCallback(() => setNonce((n) => n + 1), []);
491
512
  const addRoute = useCallback((route) => {
492
513
  setPlan((p) => p ? { ...p, routes: [...p.routes.filter((r) => r.id !== route.id), route] } : p);
@@ -609,6 +630,8 @@ function useFlow(args) {
609
630
  throw new Error(nativeFeeShortMessage(check2, nativeSymbol(Number(sourceChainId), chains), route.source.chainName));
610
631
  }
611
632
  }
633
+ const heavyExpected = route.zdHeavy ? zdHeavyExpected(route, account, recipient, ...await Promise.all([engine.fetchTokens(), engine.fetchRoutes()])) : void 0;
634
+ if (heavyExpected) await preflightZdHeavyPlan(route, heavyExpected, engine.verifier.readZdHeavySubmitFee);
612
635
  const minNonce = await engine.payerNonceBaseline(Number(sourceChainId), account);
613
636
  const txs = route.transactions;
614
637
  let settleHash = "";
@@ -624,7 +647,7 @@ function useFlow(args) {
624
647
  patch(tx.id, "done");
625
648
  continue;
626
649
  }
627
- if (!validatePlannedTransaction(tx, route, recipient)) {
650
+ if (!validatePlannedTransaction(tx, route, recipient, heavyExpected ? { ...heavyExpected, nowSec: Math.floor(Date.now() / 1e3) } : void 0)) {
628
651
  throw new Error(`Refusing to sign a ${tx.kind} that does not match the reviewed plan.`);
629
652
  }
630
653
  patch(tx.id, "active");
@@ -695,6 +718,98 @@ function useFlow(args) {
695
718
  busyRef.current = false;
696
719
  }
697
720
  }, [selected, wallet.provider, wallet.account, engine, kind, recipientFor, onSuccess, onError]);
721
+ const [prices, setPrices] = useState(null);
722
+ const priceKey = baseSelected?.options?.length ? `${baseSelected.source.asset}|${baseSelected.receive.asset}` : "";
723
+ useEffect(() => {
724
+ if (!priceKey || typeof engine.fetchPrices !== "function") return;
725
+ let alive = true;
726
+ const [from, to] = priceKey.split("|");
727
+ (async () => {
728
+ try {
729
+ const p = await engine.fetchPrices([from, to]);
730
+ const next = { key: priceKey, from: p[from.toUpperCase()], to: p[to.toUpperCase()] };
731
+ if (alive) setPrices((prev) => prev && prev.key === next.key && prev.from === next.from && prev.to === next.to ? prev : next);
732
+ } catch {
733
+ }
734
+ })();
735
+ return () => {
736
+ alive = false;
737
+ };
738
+ }, [engine, priceKey]);
739
+ const compare = useMemo(() => {
740
+ const base = baseSelected;
741
+ if (!base?.options?.length) return null;
742
+ const priced = prices?.key === priceKey ? prices : null;
743
+ const inputAmount = Number(base.source.payAmount || base.source.amount);
744
+ const fromUsd = priced?.from && Number.isFinite(inputAmount) ? inputAmount * priced.from : null;
745
+ const options = priceCompareOptions(base.options, fromUsd);
746
+ const selectedOptionId = selected?.selectedOptionId ?? null;
747
+ const parityState = parity(options, fromUsd, priced?.to ?? null);
748
+ return {
749
+ options,
750
+ visibleOptions: visibleOptions(options, proposedWait(options), selectedOptionId),
751
+ selectedId: selectedOptionId,
752
+ proposedWait: proposedWait(options),
753
+ parity: parityState,
754
+ extraVsFastest: extraVsFastest(options, selectedOptionId),
755
+ tags: Object.fromEntries(options.map((o) => [o.id, cornerTags(options, o, parityState)])),
756
+ pickForWait: (waitSec) => pickForWait(options, waitSec)
757
+ };
758
+ }, [baseSelected, selected, prices, priceKey]);
759
+ const selectOption = useCallback(
760
+ (optionId) => {
761
+ if (busyRef.current || !baseSelected) return false;
762
+ const signable = optionId === baseSelected.selectedOptionId || !!baseSelected.alternatives?.some((r) => r.selectedOptionId === optionId);
763
+ if (!signable) return false;
764
+ setPickedOptionId(optionId === baseSelected.selectedOptionId ? null : optionId);
765
+ return true;
766
+ },
767
+ [baseSelected]
768
+ );
769
+ const [promotionList, setPromotionList] = useState([]);
770
+ useEffect(() => {
771
+ if (!enabled) return;
772
+ let alive = true;
773
+ (async () => {
774
+ try {
775
+ if (typeof engine.fetchPromotions !== "function") return;
776
+ const read = await engine.fetchPromotions();
777
+ const list = Array.isArray(read) ? read : [];
778
+ if (alive) setPromotionList((prev) => JSON.stringify(prev) === JSON.stringify(list) ? prev : list);
779
+ } catch {
780
+ }
781
+ })();
782
+ return () => {
783
+ alive = false;
784
+ };
785
+ }, [engine, enabled]);
786
+ const promotions = useMemo(() => {
787
+ const route = selected;
788
+ const toAddress = route?.receive.tokenAddress;
789
+ const forSelection = route && toAddress ? promotionFor(promotionList, {
790
+ fromChainId: Number(route.source.chainId),
791
+ ...route.source.tokenAddress ? { fromAddress: route.source.tokenAddress } : {},
792
+ toChainId: Number(route.receive.chainId),
793
+ toAddress
794
+ }) : void 0;
795
+ let bonusEstimateRaw = null;
796
+ if (forSelection && route) {
797
+ const pickedRow = route.options?.find((o) => o.id === route.selectedOptionId);
798
+ try {
799
+ const delivered = pickedRow ? BigInt(pickedRow.amountRaw) : parseUnitsDecimal(route.receive.amount, Number(route.receive.decimals));
800
+ bonusEstimateRaw = estimateBonus(delivered, forSelection).toString();
801
+ } catch {
802
+ bonusEstimateRaw = null;
803
+ }
804
+ }
805
+ return {
806
+ all: promotionList,
807
+ promotedAssets: promotedAssets(promotionList),
808
+ forSelection,
809
+ pairsInto: route && toAddress ? pairPromotionsInto(promotionList, Number(route.receive.chainId), toAddress) : [],
810
+ bonusEstimateRaw
811
+ };
812
+ }, [promotionList, selected]);
698
813
  const quoteReady = status === "ready" && !!plan;
699
814
  const quotePaused = quoteReady && idle2;
700
815
  const quoteStale = quoteReady && (idle2 || planAt < returnedAt2);
@@ -716,7 +831,10 @@ function useFlow(args) {
716
831
  quoteStale,
717
832
  submit,
718
833
  reload,
719
- addRoute
834
+ addRoute,
835
+ compare,
836
+ selectOption,
837
+ promotions
720
838
  };
721
839
  }
722
840
  var RETRY_DELAYS_MS = [800, 2400, 6e3];
@@ -3301,6 +3419,7 @@ function useWalletHistory(engine, wallets) {
3301
3419
  if (!engine || !key) return;
3302
3420
  let alive = true;
3303
3421
  let timer2;
3422
+ let started2 = Date.now();
3304
3423
  const read = async () => {
3305
3424
  if (timer2) clearTimeout(timer2);
3306
3425
  timer2 = void 0;
@@ -3310,10 +3429,14 @@ function useWalletHistory(engine, wallets) {
3310
3429
  if (next) setEntries(next);
3311
3430
  if (!travelling(next)) return;
3312
3431
  }
3432
+ if (Date.now() - started2 > DELIVERY_GIVE_UP_MS) return;
3313
3433
  timer2 = setTimeout(read, WALLET_HISTORY_REFRESH_MS);
3314
3434
  };
3315
3435
  void read();
3316
- const onRecorded = () => void read();
3436
+ const onRecorded = () => {
3437
+ started2 = Date.now();
3438
+ void read();
3439
+ };
3317
3440
  if (typeof window !== "undefined") window.addEventListener(TX_HISTORY_EVENT, onRecorded);
3318
3441
  return () => {
3319
3442
  alive = false;
@@ -3934,82 +4057,6 @@ function useRecipient(destinationChainId, hostRecipient, opts = {}) {
3934
4057
  const recipientFor = (account) => required ? recipient || "" : hostRecipient || custom.evm || account;
3935
4058
  return { recipientFamily, recipientChainId: destinationChainId, recipient, shown, typed, recipientFor, managed, missing, error, wallet, familyWallet, wallets, open: open && managed, show: () => setOpen(true), close, selectAddress, connect, triggerRef };
3936
4059
  }
3937
-
3938
- // src/core/checksum.ts
3939
- var RC = [
3940
- 0x0000000000000001n,
3941
- 0x0000000000008082n,
3942
- 0x800000000000808an,
3943
- 0x8000000080008000n,
3944
- 0x000000000000808bn,
3945
- 0x0000000080000001n,
3946
- 0x8000000080008081n,
3947
- 0x8000000000008009n,
3948
- 0x000000000000008an,
3949
- 0x0000000000000088n,
3950
- 0x0000000080008009n,
3951
- 0x000000008000000an,
3952
- 0x000000008000808bn,
3953
- 0x800000000000008bn,
3954
- 0x8000000000008089n,
3955
- 0x8000000000008003n,
3956
- 0x8000000000008002n,
3957
- 0x8000000000000080n,
3958
- 0x000000000000800an,
3959
- 0x800000008000000an,
3960
- 0x8000000080008081n,
3961
- 0x8000000000008080n,
3962
- 0x0000000080000001n,
3963
- 0x8000000080008008n
3964
- ];
3965
- var ROT = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14];
3966
- var MASK = (1n << 64n) - 1n;
3967
- var rotl = (x, n) => n === 0 ? x : (x << BigInt(n) | x >> BigInt(64 - n)) & MASK;
3968
- function keccakF(s) {
3969
- for (let round = 0; round < 24; round++) {
3970
- const c = [0, 1, 2, 3, 4].map((x) => s[x] ^ s[x + 5] ^ s[x + 10] ^ s[x + 15] ^ s[x + 20]);
3971
- for (let x = 0; x < 5; x++) {
3972
- const d = c[(x + 4) % 5] ^ rotl(c[(x + 1) % 5], 1);
3973
- for (let y = 0; y < 25; y += 5) s[y + x] = s[y + x] ^ d;
3974
- }
3975
- const b = new Array(25);
3976
- for (let x = 0; x < 5; x++) for (let y = 0; y < 5; y++) b[y + 5 * ((2 * x + 3 * y) % 5)] = rotl(s[x + 5 * y], ROT[x + 5 * y]);
3977
- for (let x = 0; x < 5; x++) for (let y = 0; y < 25; y += 5) s[y + x] = b[y + x] ^ ~b[y + (x + 1) % 5] & MASK & b[y + (x + 2) % 5];
3978
- s[0] = s[0] ^ RC[round];
3979
- }
3980
- }
3981
- function keccak256Hex(bytes) {
3982
- const rate = 136;
3983
- const padded = new Uint8Array(Math.ceil((bytes.length + 1) / rate) * rate);
3984
- padded.set(bytes);
3985
- padded[bytes.length] = padded[bytes.length] ^ 1;
3986
- padded[padded.length - 1] = padded[padded.length - 1] ^ 128;
3987
- const s = new Array(25).fill(0n);
3988
- for (let off = 0; off < padded.length; off += rate) {
3989
- for (let i = 0; i < rate / 8; i++) {
3990
- let lane = 0n;
3991
- for (let j = 7; j >= 0; j--) lane = lane << 8n | BigInt(padded[off + i * 8 + j]);
3992
- s[i] = s[i] ^ lane;
3993
- }
3994
- keccakF(s);
3995
- }
3996
- let out = "";
3997
- for (let i = 0; i < 4; i++) for (let j = 0; j < 8; j++) out += Number(s[i] >> BigInt(8 * j) & 0xffn).toString(16).padStart(2, "0");
3998
- return out;
3999
- }
4000
- function toChecksumAddress(address) {
4001
- const lower = address.slice(2).toLowerCase();
4002
- const hash = keccak256Hex(new TextEncoder().encode(lower));
4003
- let out = "0x";
4004
- for (let i = 0; i < 40; i++) out += Number.parseInt(hash[i], 16) >= 8 ? lower[i].toUpperCase() : lower[i];
4005
- return out;
4006
- }
4007
- function hasValidChecksum(address) {
4008
- if (!/^0x[0-9a-fA-F]{40}$/.test(address)) return false;
4009
- const body = address.slice(2);
4010
- if (body === body.toLowerCase() || body === body.toUpperCase()) return true;
4011
- return toChecksumAddress(address) === address;
4012
- }
4013
4060
  function ArrowLeft() {
4014
4061
  return /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
4015
4062
  /* @__PURE__ */ jsx("path", { d: "M6.38 3.95312L2.33333 7.99979L6.38 12.0465", stroke: "currentColor", strokeWidth: "1.2", strokeMiterlimit: "10", strokeLinecap: "round", strokeLinejoin: "round" }),