@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.
- package/dist/{chunk-4WBNXYOV.js → chunk-UBSZA63S.js} +504 -50
- package/dist/{chunk-RUHREVDT.js → chunk-UIIH5O6G.js} +439 -40
- package/dist/core/index.cjs +454 -39
- package/dist/core/index.d.cts +196 -3
- package/dist/core/index.d.ts +196 -3
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +970 -117
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/{mount-D2tDkHea.d.cts → mount-DC_JT0cE.d.cts} +1 -1
- package/dist/{mount-DuTF5CQV.d.ts → mount-GOYY_jNr.d.ts} +1 -1
- package/dist/mount.cjs +970 -117
- package/dist/mount.d.cts +2 -2
- package/dist/mount.d.ts +2 -2
- package/dist/mount.js +2 -2
- package/dist/standalone.global.js +15 -8
- package/dist/{verify-UqDjAVxa.d.cts → verify-mpglrU7n.d.cts} +21 -2
- package/dist/{verify-UqDjAVxa.d.ts → verify-mpglrU7n.d.ts} +21 -2
- package/package.json +1 -1
package/dist/mount.cjs
CHANGED
|
@@ -593,13 +593,22 @@ var MAX_STEPS = 8;
|
|
|
593
593
|
function isZdHeavy(r, steps) {
|
|
594
594
|
return r.protocol === "zdheavy" || steps.some((s) => Number(s.stepNumber ?? 0) >= ZDH_FIRST_STEP);
|
|
595
595
|
}
|
|
596
|
+
var FILL_EVIDENCE = /* @__PURE__ */ new Set(["filled", "consumed", "step_executed", "paid_out", "delivered"]);
|
|
597
|
+
function ownerCancelServedAsDeliveryFailure(steps) {
|
|
598
|
+
const txHash = (s) => typeof s.txHash === "string" && /^0x[0-9a-fA-F]{64}$/.test(s.txHash);
|
|
599
|
+
const anyTx = (s) => typeof s.txHash === "string" && s.txHash.length > 0;
|
|
600
|
+
const cancelTx = steps.some((s) => s.stepName === "cancelled" && txHash(s));
|
|
601
|
+
const refunded = steps.some((s) => s.stepName === "refunded" && word(s.stepStatus) === "recovered" && txHash(s));
|
|
602
|
+
const filled = steps.some((s) => FILL_EVIDENCE.has(String(s.stepName)) && word(s.stepStatus) === "completed" && anyTx(s));
|
|
603
|
+
return cancelTx && refunded && !filled;
|
|
604
|
+
}
|
|
596
605
|
function zdHeavyDelivery(own, rawSteps) {
|
|
597
606
|
const named = rawSteps.filter((s) => s && typeof s === "object" && typeof s.stepName === "string");
|
|
598
607
|
const lite = (name) => named.some((s) => Number(s.stepNumber ?? 0) < ZDH_FIRST_STEP && s.stepName === name && s.stepStatus === "completed");
|
|
599
608
|
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);
|
|
600
609
|
const has = (name) => events.some((e) => e.stepName === name);
|
|
601
610
|
const cancelled = has("cancelled");
|
|
602
|
-
const status = PROGRESS.has(own) && has("paid_out") && !cancelled ? "delivered" : own;
|
|
611
|
+
const status = own === "delivery_failed" && ownerCancelServedAsDeliveryFailure(named) ? "cancelled" : PROGRESS.has(own) && has("paid_out") && !cancelled ? "delivered" : own;
|
|
603
612
|
const steps = [];
|
|
604
613
|
const push = (name, done) => {
|
|
605
614
|
const last = steps[steps.length - 1];
|
|
@@ -690,7 +699,7 @@ function useDelivery(engine, hash2) {
|
|
|
690
699
|
let unanswered = 0;
|
|
691
700
|
const started2 = Date.now();
|
|
692
701
|
setState({ hash: hash2, value: TRACKING });
|
|
693
|
-
const
|
|
702
|
+
const schedule2 = () => {
|
|
694
703
|
if (Date.now() - started2 > DELIVERY_GIVE_UP_MS) {
|
|
695
704
|
if (waitsOnOwner) return;
|
|
696
705
|
return setState({ hash: hash2, value: UNAVAILABLE });
|
|
@@ -699,18 +708,18 @@ function useDelivery(engine, hash2) {
|
|
|
699
708
|
};
|
|
700
709
|
const tick = async () => {
|
|
701
710
|
timer2 = void 0;
|
|
702
|
-
if (hidden()) return
|
|
711
|
+
if (hidden()) return schedule2();
|
|
703
712
|
const next = await engine.trackDelivery(hash2);
|
|
704
713
|
if (!alive) return;
|
|
705
714
|
if (next.phase === "tracking") {
|
|
706
715
|
if (!answered && ++unanswered >= UNANSWERED_LIMIT) return setState({ hash: hash2, value: UNAVAILABLE });
|
|
707
|
-
return
|
|
716
|
+
return schedule2();
|
|
708
717
|
}
|
|
709
718
|
answered = true;
|
|
710
719
|
waitsOnOwner = next.phase === "attention";
|
|
711
720
|
setState({ hash: hash2, value: next });
|
|
712
721
|
if (next.phase === "delivered" || next.phase === "failed") return;
|
|
713
|
-
|
|
722
|
+
schedule2();
|
|
714
723
|
};
|
|
715
724
|
const onVisible2 = () => {
|
|
716
725
|
if (!alive || hidden() || !timer2) return;
|
|
@@ -749,8 +758,8 @@ function deliveryHeadline(delivery, sourceConfirmed, direct2 = false) {
|
|
|
749
758
|
case "delivered":
|
|
750
759
|
return "Delivered";
|
|
751
760
|
case "failed":
|
|
752
|
-
if (delivery.status === "cancelled" && delivery.refunded) return "
|
|
753
|
-
return delivery.status === "cancelled" ? "
|
|
761
|
+
if (delivery.status === "cancelled" && delivery.refunded) return "Cancellation and refund reported by ZeroDelta";
|
|
762
|
+
return delivery.status === "cancelled" ? "Cancellation reported \u2014 not delivered" : `Not delivered (${delivery.status.replace(/_/g, " ")}) \u2014 open the transaction for details`;
|
|
754
763
|
case "attention":
|
|
755
764
|
return delivery.status === "cancel_pending" ? "Being cancelled \u2014 not delivered" : "Waiting to be claimed \u2014 open the transaction";
|
|
756
765
|
case "in-progress": {
|
|
@@ -1836,6 +1845,7 @@ function hubDeliverableSymbols(tokens, execution) {
|
|
|
1836
1845
|
function isSourceToken(token, ctx) {
|
|
1837
1846
|
const chainId = Number(token.chainId);
|
|
1838
1847
|
if (!ctx.sourceChains.has(chainId)) return false;
|
|
1848
|
+
if (ctx.zdHeavySources?.has(tokenKey(chainId, token.address))) return true;
|
|
1839
1849
|
return ctx.execution.has(chainId) || !isKnownUnbridgeable(token.bridge) && ctx.source.has(tokenKey(chainId, token.address));
|
|
1840
1850
|
}
|
|
1841
1851
|
function directLaneOK(token, source2, lanes) {
|
|
@@ -1854,6 +1864,7 @@ function laneLimitFor(token, source2, limitedLanes2) {
|
|
|
1854
1864
|
}
|
|
1855
1865
|
function destinationAvailability(token, ctx, source2) {
|
|
1856
1866
|
if (brokenLaneFor(token, source2 ?? void 0, ctx.brokenLanes)) return "unreachable";
|
|
1867
|
+
if (source2 && ctx.zdHeavyLanes?.has(laneKey(source2.chainId, source2.address, token.chainId, token.address))) return "available";
|
|
1857
1868
|
if (directLaneOK(token, source2 ?? void 0, ctx.lanes)) {
|
|
1858
1869
|
if (ctx.execution.has(Number(token.chainId))) return "available";
|
|
1859
1870
|
if (token.isChainedDestination === true) return "available";
|
|
@@ -1872,6 +1883,7 @@ function hasReachableDestination(source2, catalogue, ctx) {
|
|
|
1872
1883
|
}
|
|
1873
1884
|
function buildCatalogue(input) {
|
|
1874
1885
|
const { chains, tokens, routes, supportedChainIds, brokenLanes } = input;
|
|
1886
|
+
const zdHeavy = (input.zdHeavyRoutes ?? []).filter((r) => !!r && typeof r === "object" && !Array.isArray(r) && r.isEnabled !== false && r.isQuotable === true);
|
|
1875
1887
|
const product = input.product ?? "stable";
|
|
1876
1888
|
const universe = productAssets(product);
|
|
1877
1889
|
const allowedAssets = input.allowedAssets ? new Set([...input.allowedAssets].filter((a) => universe.has(a))) : universe;
|
|
@@ -1879,7 +1891,10 @@ function buildCatalogue(input) {
|
|
|
1879
1891
|
const registryChainIds = new Set(enabledChains.map((c) => Number(c.chainId)));
|
|
1880
1892
|
const sourceChains = new Set([...registryChainIds].filter((id) => supportedChainIds.has(id)));
|
|
1881
1893
|
const execution = executionChainIds(enabledChains);
|
|
1882
|
-
const projected = product === "rwa" ? routes.filter((route) => route.isEnabled !== false) : executableRoutes(routes);
|
|
1894
|
+
const projected = [...product === "rwa" ? routes.filter((route) => route.isEnabled !== false) : executableRoutes(routes), ...zdHeavy];
|
|
1895
|
+
const zdHeavyLanes = laneKeys(zdHeavy);
|
|
1896
|
+
const zdHeavySources = sourceKeys(zdHeavy);
|
|
1897
|
+
const zdHeavyKeys = /* @__PURE__ */ new Set([...zdHeavySources, ...destinationKeys(zdHeavy)]);
|
|
1883
1898
|
const source2 = sourceKeys(projected);
|
|
1884
1899
|
const destination = destinationKeys(projected);
|
|
1885
1900
|
const lanes = laneKeys(projected);
|
|
@@ -1894,14 +1909,15 @@ function buildCatalogue(input) {
|
|
|
1894
1909
|
if (!chainIds.has(chainId)) return false;
|
|
1895
1910
|
if (product === "rwa") return true;
|
|
1896
1911
|
if (execution.has(chainId) || token.isChainedDestination === true) return true;
|
|
1897
|
-
if (!isExecutableBridge(token)) return false;
|
|
1898
1912
|
const key2 = tokenKey(token.chainId, token.address);
|
|
1913
|
+
if (zdHeavyKeys.has(key2)) return true;
|
|
1914
|
+
if (!isExecutableBridge(token)) return false;
|
|
1899
1915
|
return source2.has(key2) || destination.has(key2);
|
|
1900
1916
|
});
|
|
1901
1917
|
const ready = chains.length > 0 && routes.length > 0 && projectedCatalogue.length > 0;
|
|
1902
1918
|
const catalogue = ready ? projectedCatalogue : allowed;
|
|
1903
1919
|
const hubSymbols = hubDeliverableSymbols(catalogue, execution);
|
|
1904
|
-
const ctx = { source: source2, destination, lanes, execution, sourceChains, hubSymbols, ...brokenLanes ? { brokenLanes } : {} };
|
|
1920
|
+
const ctx = { source: source2, destination, lanes, execution, sourceChains, hubSymbols, ...zdHeavy.length ? { zdHeavyLanes, zdHeavySources } : {}, ...brokenLanes ? { brokenLanes } : {} };
|
|
1905
1921
|
const sellable = (token) => product !== "rwa" || isSellableRwa(token);
|
|
1906
1922
|
const sources2 = ready ? catalogue.filter((token) => sellable(token) && isSourceToken(token, ctx) && hasReachableDestination(token, catalogue, ctx)) : (
|
|
1907
1923
|
// Unprojected: the only rule we can still apply with confidence is the escrow-chain bound,
|
|
@@ -2557,7 +2573,10 @@ function historyEntryFromOrder(raw2, tokens) {
|
|
|
2557
2573
|
const toAsset = (to?.symbol ?? (str(r.finalToTokenSymbol) || str(r.toTokenSymbol))).slice(0, 10);
|
|
2558
2574
|
const payAmount = amountOf(str(r.fromTokenRawAmount), from, r.fromTokenDecimals, str(r.fromTokenAmount));
|
|
2559
2575
|
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));
|
|
2560
|
-
const
|
|
2576
|
+
const tracked = normalizeDelivery(r);
|
|
2577
|
+
const delivery = tracked.phase;
|
|
2578
|
+
const protocol = str(r.protocol);
|
|
2579
|
+
const orderId = str(r.orderId);
|
|
2561
2580
|
const wallet = str(r.wallet);
|
|
2562
2581
|
const receiver = str(r.destinationReceiver);
|
|
2563
2582
|
const at = str(r.createdAt) || str(r.submittedAt);
|
|
@@ -2579,6 +2598,11 @@ function historyEntryFromOrder(raw2, tokens) {
|
|
|
2579
2598
|
status: "submitted",
|
|
2580
2599
|
at: Number.isNaN(Date.parse(at)) ? (/* @__PURE__ */ new Date(0)).toISOString() : new Date(at).toISOString(),
|
|
2581
2600
|
delivery: delivery === "tracking" || delivery === "unavailable" ? void 0 : delivery,
|
|
2601
|
+
...tracked.status && delivery !== "tracking" && delivery !== "unavailable" ? { deliveryStatus: tracked.status.slice(0, 32) } : {},
|
|
2602
|
+
.../^[a-z]{1,16}$/.test(protocol) ? { protocol } : {},
|
|
2603
|
+
// Only a router order id (bytes32) is carried: it is the one thing a recovery call puts in a URL.
|
|
2604
|
+
.../^0x[0-9a-fA-F]{64}$/.test(orderId) ? { orderId } : {},
|
|
2605
|
+
...r.claimable === true ? { claimable: true } : {},
|
|
2582
2606
|
legs: [
|
|
2583
2607
|
{
|
|
2584
2608
|
index: 1,
|
|
@@ -2626,7 +2650,17 @@ function mergeHistory(local, remote, limit = WALLET_HISTORY_LIMIT) {
|
|
|
2626
2650
|
if (seen.has(key2)) continue;
|
|
2627
2651
|
seen.add(key2);
|
|
2628
2652
|
const known = byHash.get(key2);
|
|
2629
|
-
out.push(
|
|
2653
|
+
out.push(
|
|
2654
|
+
known ? {
|
|
2655
|
+
...entry,
|
|
2656
|
+
delivery: known.delivery,
|
|
2657
|
+
legs: entry.legs ?? known.legs,
|
|
2658
|
+
deliveryStatus: known.deliveryStatus,
|
|
2659
|
+
protocol: known.protocol,
|
|
2660
|
+
orderId: known.orderId,
|
|
2661
|
+
claimable: known.claimable
|
|
2662
|
+
} : entry
|
|
2663
|
+
);
|
|
2630
2664
|
}
|
|
2631
2665
|
for (const [key2, entry] of byHash) if (!seen.has(key2)) out.push(entry);
|
|
2632
2666
|
return out.sort((a, b) => Date.parse(b.at) - Date.parse(a.at)).slice(0, limit);
|
|
@@ -2703,13 +2737,13 @@ function checkNativeFee(route, balance) {
|
|
|
2703
2737
|
const shortfall = required > balance ? required - balance : 0n;
|
|
2704
2738
|
return { required, balance, short: shortfall > 0n, shortfall };
|
|
2705
2739
|
}
|
|
2706
|
-
function nativeFeeShortLabel(
|
|
2707
|
-
if (!
|
|
2708
|
-
return `Need ${formatNative(
|
|
2740
|
+
function nativeFeeShortLabel(check3, symbol) {
|
|
2741
|
+
if (!check3.short) return null;
|
|
2742
|
+
return `Need ${formatNative(check3.required)} ${symbol} for the bridge fee`;
|
|
2709
2743
|
}
|
|
2710
|
-
function nativeFeeShortMessage(
|
|
2711
|
-
const need = formatNative(
|
|
2712
|
-
const have = formatNative(
|
|
2744
|
+
function nativeFeeShortMessage(check3, symbol, chainName3) {
|
|
2745
|
+
const need = formatNative(check3.required);
|
|
2746
|
+
const have = formatNative(check3.balance ?? 0n);
|
|
2713
2747
|
const where = chainName3 ? ` on ${chainName3}` : "";
|
|
2714
2748
|
return `This route bridges via LayerZero, which charges a ${need} ${symbol} network fee paid as part of the transaction. Your wallet holds ${have} ${symbol}${where}. Add ${symbol}${where} and try again \u2014 gas is owed on top of this fee.`;
|
|
2715
2749
|
}
|
|
@@ -3203,6 +3237,15 @@ function zdHeavyRouterPinned(chainId, router) {
|
|
|
3203
3237
|
}
|
|
3204
3238
|
|
|
3205
3239
|
// src/core/quote-option.ts
|
|
3240
|
+
function gateZdHeavyOptions(response, request, quotableRoutes) {
|
|
3241
|
+
if (!Array.isArray(response?.options)) return response;
|
|
3242
|
+
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);
|
|
3243
|
+
const matchesLane = quotableRoutes.some(
|
|
3244
|
+
(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)
|
|
3245
|
+
);
|
|
3246
|
+
if (matchesLane) return response;
|
|
3247
|
+
return { ...response, options: response.options.filter((option) => option?.protocol !== "zdheavy") };
|
|
3248
|
+
}
|
|
3206
3249
|
function zdHeavyExecutable(q) {
|
|
3207
3250
|
const order = q.execution?.order;
|
|
3208
3251
|
const chainId = typeof q.fromChainId === "number" ? q.fromChainId : Number(order?.chainNumber);
|
|
@@ -3459,16 +3502,16 @@ function normalizeOrderRequests(requests, payer, destination, fallbackExecutionC
|
|
|
3459
3502
|
);
|
|
3460
3503
|
}
|
|
3461
3504
|
function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result, tokens = [] }) {
|
|
3462
|
-
const
|
|
3463
|
-
const sourceOrder =
|
|
3464
|
-
const finalOrder =
|
|
3505
|
+
const list2 = orders?.length ? orders : [order];
|
|
3506
|
+
const sourceOrder = list2[0];
|
|
3507
|
+
const finalOrder = list2[list2.length - 1];
|
|
3465
3508
|
const now = Math.floor(Date.now() / 1e3);
|
|
3466
3509
|
const deadline = Number(sourceOrder.deadline || 0);
|
|
3467
3510
|
const solana = isSolanaChainId(destination.chainId);
|
|
3468
3511
|
if (solana && solanaDestinationAsset(destinationToken.address)?.symbol !== symbolKey(destinationToken.symbol)) {
|
|
3469
3512
|
throw new Error("This Solana token is not supported for delivery; refusing to sign.");
|
|
3470
3513
|
}
|
|
3471
|
-
for (const current of
|
|
3514
|
+
for (const current of list2) {
|
|
3472
3515
|
if (normalizeAddress(current.owner) !== normalizeAddress(payer)) {
|
|
3473
3516
|
throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
|
|
3474
3517
|
}
|
|
@@ -3519,9 +3562,9 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
|
|
|
3519
3562
|
if (!Number.isFinite(deadline) || deadline <= now || deadline > now + maxDeadline + DEADLINE_CLOCK_SKEW_SECONDS) {
|
|
3520
3563
|
throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
|
|
3521
3564
|
}
|
|
3522
|
-
for (let index = 1; index <
|
|
3523
|
-
const previous =
|
|
3524
|
-
const current =
|
|
3565
|
+
for (let index = 1; index < list2.length; index += 1) {
|
|
3566
|
+
const previous = list2[index - 1];
|
|
3567
|
+
const current = list2[index];
|
|
3525
3568
|
if (normalizeAddress(previous.askToken) !== normalizeAddress(current.bidToken)) {
|
|
3526
3569
|
throw new Error("ZeroDelta chained quote returned disconnected order tokens.");
|
|
3527
3570
|
}
|
|
@@ -3598,10 +3641,10 @@ function keccak256Hex(bytes) {
|
|
|
3598
3641
|
return out;
|
|
3599
3642
|
}
|
|
3600
3643
|
function toChecksumAddress(address) {
|
|
3601
|
-
const
|
|
3602
|
-
const hash2 = keccak256Hex(new TextEncoder().encode(
|
|
3644
|
+
const lower6 = address.slice(2).toLowerCase();
|
|
3645
|
+
const hash2 = keccak256Hex(new TextEncoder().encode(lower6));
|
|
3603
3646
|
let out = "0x";
|
|
3604
|
-
for (let i = 0; i < 40; i++) out += Number.parseInt(hash2[i], 16) >= 8 ?
|
|
3647
|
+
for (let i = 0; i < 40; i++) out += Number.parseInt(hash2[i], 16) >= 8 ? lower6[i].toUpperCase() : lower6[i];
|
|
3605
3648
|
return out;
|
|
3606
3649
|
}
|
|
3607
3650
|
function hasValidChecksum(address) {
|
|
@@ -3619,6 +3662,7 @@ var toHex = (v, opts) => "0x" + (typeof v === "bigint" ? v.toString(16).padStart
|
|
|
3619
3662
|
var keccak256 = (h2) => "0x" + keccak256Hex(hexToBytes2(h2));
|
|
3620
3663
|
var STEP_VERSION = 5;
|
|
3621
3664
|
var MAX_STEPS2 = 8;
|
|
3665
|
+
var ORDER_HEADER_LEN = 76;
|
|
3622
3666
|
var StepKind = {
|
|
3623
3667
|
LOCAL_PAYOUT: 1,
|
|
3624
3668
|
REMOTE_PAYOUT: 2,
|
|
@@ -3759,11 +3803,11 @@ function decodeStep(step) {
|
|
|
3759
3803
|
r.end();
|
|
3760
3804
|
return result;
|
|
3761
3805
|
}
|
|
3762
|
-
function routerWord(
|
|
3763
|
-
return concat([toHex(new Uint8Array(12)), checkedHex(
|
|
3806
|
+
function routerWord(addr2) {
|
|
3807
|
+
return concat([toHex(new Uint8Array(12)), checkedHex(addr2, 20)]);
|
|
3764
3808
|
}
|
|
3765
|
-
function ownerWord(
|
|
3766
|
-
return routerWord(
|
|
3809
|
+
function ownerWord(addr2) {
|
|
3810
|
+
return routerWord(addr2);
|
|
3767
3811
|
}
|
|
3768
3812
|
function encodeOrderHeader(serial, router, ownerType, owner) {
|
|
3769
3813
|
if (!Number.isInteger(ownerType) || ownerType < 0 || ownerType > 255) throw new ZdHeavyCodecError("Invalid ownerType");
|
|
@@ -4134,6 +4178,16 @@ async function allowanceCovers(tx, account, ethCall2) {
|
|
|
4134
4178
|
}
|
|
4135
4179
|
|
|
4136
4180
|
// src/core/zdheavy-route.ts
|
|
4181
|
+
var ZdHeavyQuoteExpiredError = class extends Error {
|
|
4182
|
+
code = "zdheavy_quote_expired";
|
|
4183
|
+
constructor() {
|
|
4184
|
+
super("This ZD Heavy quote expired before it was signed. A fresh quote is loading \u2014 review it and press Exchange again.");
|
|
4185
|
+
this.name = "ZdHeavyQuoteExpiredError";
|
|
4186
|
+
}
|
|
4187
|
+
};
|
|
4188
|
+
function assertZdHeavyQuoteFresh(order, nowSec) {
|
|
4189
|
+
if (order && (order.expiresAt <= nowSec || order.expiryDate <= nowSec)) throw new ZdHeavyQuoteExpiredError();
|
|
4190
|
+
}
|
|
4137
4191
|
function zdHeavyExpected(route, owner, receiver, tokens, routes) {
|
|
4138
4192
|
const heavy = route.zdHeavy;
|
|
4139
4193
|
if (!heavy) throw new Error("Missing ZD Heavy order.");
|
|
@@ -4159,6 +4213,7 @@ function zdHeavyExpected(route, owner, receiver, tokens, routes) {
|
|
|
4159
4213
|
};
|
|
4160
4214
|
}
|
|
4161
4215
|
function validateZdHeavyPlan(route, expected) {
|
|
4216
|
+
assertZdHeavyQuoteFresh(expected.order, expected.nowSec);
|
|
4162
4217
|
if (route.transactions.length !== 2 || route.transactions[0].kind !== "approve" || route.transactions[1].kind !== "submitOrder") {
|
|
4163
4218
|
throw new Error("ZD Heavy requires exactly approve then submitOrder; refusing to sign.");
|
|
4164
4219
|
}
|
|
@@ -4963,7 +5018,7 @@ var CHANNEL_HEADER = "x-zd-channel";
|
|
|
4963
5018
|
var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
|
|
4964
5019
|
var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
|
|
4965
5020
|
var WIDGET_CHANNEL = "widget";
|
|
4966
|
-
var WIDGET_VERSION = "4.
|
|
5021
|
+
var WIDGET_VERSION = "4.22.0" ;
|
|
4967
5022
|
var MAX_CHANNEL_VERSION_LEN = 32;
|
|
4968
5023
|
function sanitizeVersion(raw2) {
|
|
4969
5024
|
const v = String(raw2).trim();
|
|
@@ -5087,7 +5142,7 @@ function wait(ms) {
|
|
|
5087
5142
|
}
|
|
5088
5143
|
var PAGE_LIMIT = 500;
|
|
5089
5144
|
var MAX_PAGES = 10;
|
|
5090
|
-
var newRegistryCache = () => ({ chains: null, tokens: null, routes: null, health: null, vaults: null, promotions: null, inflight: /* @__PURE__ */ new Map() });
|
|
5145
|
+
var newRegistryCache = () => ({ chains: null, tokens: null, routes: null, zdHeavy: null, health: null, vaults: null, promotions: null, inflight: /* @__PURE__ */ new Map() });
|
|
5091
5146
|
var SHARED_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
5092
5147
|
function registryCacheFor(scope) {
|
|
5093
5148
|
if (!scope) return newRegistryCache();
|
|
@@ -5164,13 +5219,14 @@ function createApiClient(cfg) {
|
|
|
5164
5219
|
const json = await requestJson(path, init);
|
|
5165
5220
|
return json?.data ?? json;
|
|
5166
5221
|
}
|
|
5167
|
-
async function requestAllPages(path) {
|
|
5222
|
+
async function requestAllPages(path, params = {}) {
|
|
5168
5223
|
const rows = [];
|
|
5169
5224
|
let firstRow = "";
|
|
5170
5225
|
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
5171
|
-
const json = await requestJson(`${path}${toQuery({ limit: PAGE_LIMIT, offset: rows.length || void 0 })}`);
|
|
5226
|
+
const json = await requestJson(`${path}${toQuery({ ...params, limit: PAGE_LIMIT, offset: rows.length || void 0 })}`);
|
|
5172
5227
|
const envelope = json && !Array.isArray(json) ? json : {};
|
|
5173
5228
|
const data = Array.isArray(json) ? json : envelope.data;
|
|
5229
|
+
if (params.protocol === "zdheavy" && !Array.isArray(data)) throw apiError(`ZeroDelta returned an unusable list (${path}).`, { code: "bad_response" });
|
|
5174
5230
|
const pageRows = Array.isArray(data) ? data : [];
|
|
5175
5231
|
const head = pageRows.length ? JSON.stringify(pageRows[0]) : "";
|
|
5176
5232
|
if (page === 0) firstRow = head;
|
|
@@ -5216,6 +5272,20 @@ function createApiClient(cfg) {
|
|
|
5216
5272
|
}
|
|
5217
5273
|
});
|
|
5218
5274
|
}
|
|
5275
|
+
function fetchZdHeavyRoutes() {
|
|
5276
|
+
if (nowFresh(cache.zdHeavy)) return Promise.resolve(cache.zdHeavy.value);
|
|
5277
|
+
return once("zdHeavy", async () => {
|
|
5278
|
+
let value = [];
|
|
5279
|
+
try {
|
|
5280
|
+
const rows = await requestAllPages("/routes", { protocol: "zdheavy", isEnabled: true });
|
|
5281
|
+
value = rows.filter((r) => !!r && typeof r === "object" && !Array.isArray(r) && r.isEnabled !== false && r.isQuotable === true);
|
|
5282
|
+
} catch {
|
|
5283
|
+
value = [];
|
|
5284
|
+
}
|
|
5285
|
+
cache.zdHeavy = { at: Date.now(), value };
|
|
5286
|
+
return value;
|
|
5287
|
+
});
|
|
5288
|
+
}
|
|
5219
5289
|
function fetchRouteHealth() {
|
|
5220
5290
|
if (nowFresh(cache.health)) return Promise.resolve(cache.health.value);
|
|
5221
5291
|
return once("health", async () => {
|
|
@@ -5294,7 +5364,8 @@ function createApiClient(cfg) {
|
|
|
5294
5364
|
for (let attempt = 0; attempt <= retries; attempt += 1) {
|
|
5295
5365
|
try {
|
|
5296
5366
|
const quote = await apiRequest("/quote", { method: "POST", headers: { "X-ZD-Shape": "native" }, body: JSON.stringify(request), timeoutMs: 18e3 });
|
|
5297
|
-
|
|
5367
|
+
const gated = Array.isArray(quote?.options) && quote.options.some((option) => option?.protocol === "zdheavy") ? gateZdHeavyOptions(quote, request, await fetchZdHeavyRoutes()) : quote;
|
|
5368
|
+
return normalizeQuoteResponse(gated, request);
|
|
5298
5369
|
} catch (error) {
|
|
5299
5370
|
lastError = error;
|
|
5300
5371
|
if (attempt >= retries || !isTransientQuoteError(error)) throw error;
|
|
@@ -5304,24 +5375,24 @@ function createApiClient(cfg) {
|
|
|
5304
5375
|
throw lastError;
|
|
5305
5376
|
}
|
|
5306
5377
|
async function screenWallet(address, chainId) {
|
|
5307
|
-
const
|
|
5308
|
-
if (!
|
|
5309
|
-
const solana = isSolanaChainId(chainId) || isSolanaAddress(
|
|
5310
|
-
if (solana && !isSolanaAddress(
|
|
5311
|
-
const key2 = solana ? "solana|" +
|
|
5378
|
+
const addr2 = String(address || "").trim();
|
|
5379
|
+
if (!addr2) throw apiError("An address is required to screen a wallet.", { code: "bad_request" });
|
|
5380
|
+
const solana = isSolanaChainId(chainId) || isSolanaAddress(addr2);
|
|
5381
|
+
if (solana && !isSolanaAddress(addr2)) throw apiError("Not a valid Solana address.", { code: "bad_request" });
|
|
5382
|
+
const key2 = solana ? "solana|" + addr2 : (/^0x[0-9a-fA-F]+$/.test(addr2) ? addr2.toLowerCase() : addr2) + "|" + (chainId ?? "");
|
|
5312
5383
|
const hit = screenCache.get(key2);
|
|
5313
5384
|
if (hit && Date.now() - hit.at < SCREEN_CACHE_TTL_MS) return hit.value;
|
|
5314
5385
|
const inflight = screenInflight.get(key2);
|
|
5315
5386
|
if (inflight) return inflight;
|
|
5316
5387
|
const request = apiRequest("/screen/wallet", {
|
|
5317
5388
|
method: "POST",
|
|
5318
|
-
body: JSON.stringify(solana ? { address:
|
|
5389
|
+
body: JSON.stringify(solana ? { address: addr2, network: "solana" } : chainId == null ? { address: addr2 } : { address: addr2, chainId }),
|
|
5319
5390
|
timeoutMs: 12e3
|
|
5320
5391
|
}).then((screen) => {
|
|
5321
5392
|
if (!screen || typeof screen !== "object" || typeof screen.blocked !== "boolean") {
|
|
5322
5393
|
throw apiError("Compliance screening returned an unusable result.", { code: "bad_response" });
|
|
5323
5394
|
}
|
|
5324
|
-
const value = { ...screen, address: screen.address ||
|
|
5395
|
+
const value = { ...screen, address: screen.address || addr2 };
|
|
5325
5396
|
screenCache.set(key2, { at: Date.now(), value });
|
|
5326
5397
|
return value;
|
|
5327
5398
|
}).finally(() => {
|
|
@@ -5350,7 +5421,7 @@ function createApiClient(cfg) {
|
|
|
5350
5421
|
return false;
|
|
5351
5422
|
}
|
|
5352
5423
|
}
|
|
5353
|
-
return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchPromotions, fetchQuote, screenWallet, reportSubmission, apiBase };
|
|
5424
|
+
return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchZdHeavyRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchPromotions, fetchQuote, screenWallet, reportSubmission, apiBase };
|
|
5354
5425
|
}
|
|
5355
5426
|
|
|
5356
5427
|
// src/core/plan.ts
|
|
@@ -5425,12 +5496,12 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
|
|
|
5425
5496
|
const parties = [];
|
|
5426
5497
|
const seenParty = /* @__PURE__ */ new Set();
|
|
5427
5498
|
for (const raw2 of [payer, destination.address]) {
|
|
5428
|
-
const
|
|
5429
|
-
if (!
|
|
5430
|
-
const key2 = /^0x[0-9a-fA-F]+$/.test(
|
|
5499
|
+
const addr2 = String(raw2 || "").trim();
|
|
5500
|
+
if (!addr2) continue;
|
|
5501
|
+
const key2 = /^0x[0-9a-fA-F]+$/.test(addr2) ? addr2.toLowerCase() : addr2;
|
|
5431
5502
|
if (seenParty.has(key2)) continue;
|
|
5432
5503
|
seenParty.add(key2);
|
|
5433
|
-
parties.push(
|
|
5504
|
+
parties.push(addr2);
|
|
5434
5505
|
}
|
|
5435
5506
|
try {
|
|
5436
5507
|
const screens = await Promise.all(parties.map((address) => api.screenWallet(address, destination.chainId)));
|
|
@@ -5645,6 +5716,322 @@ async function buildSwapPlan(api, swap, payer, wallet = {}) {
|
|
|
5645
5716
|
};
|
|
5646
5717
|
}
|
|
5647
5718
|
|
|
5719
|
+
// src/core/zdheavy-cancel.ts
|
|
5720
|
+
var lower3 = (s) => (typeof s === "string" ? s : "").toLowerCase();
|
|
5721
|
+
var ORDER_ID = /^0x[0-9a-fA-F]{64}$/;
|
|
5722
|
+
var EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
5723
|
+
function isZdHeavyOrderId(v) {
|
|
5724
|
+
return typeof v === "string" && ORDER_ID.test(v);
|
|
5725
|
+
}
|
|
5726
|
+
function zdHeavyRecovery(plan, wallet) {
|
|
5727
|
+
const claims = wallet ? plan.places.flatMap(
|
|
5728
|
+
(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 })) : []
|
|
5729
|
+
) : [];
|
|
5730
|
+
if (claims.length) return { kind: "claim", claims };
|
|
5731
|
+
if (plan.finished) return { kind: "delivered" };
|
|
5732
|
+
if (plan.state === "refund_complete" && plan.complete) {
|
|
5733
|
+
return { kind: "refunded", refunds: plan.places.flatMap((p) => p.refunds.map((r) => ({ ...r, chainId: p.chainId }))) };
|
|
5734
|
+
}
|
|
5735
|
+
if (plan.ownerType !== "evm") return { kind: "not-owner" };
|
|
5736
|
+
const holding = plan.places.filter(
|
|
5737
|
+
(p) => p.kind === "router" && p.chainId !== void 0 && !!p.contract && p.canCancelInPerson && !p.complete && p.lots.length > 0
|
|
5738
|
+
);
|
|
5739
|
+
if (holding.length) return { kind: "cancel", chains: holding.map((p) => p.chainId), requested: plan.state === "cancel_requested" };
|
|
5740
|
+
if (plan.state === "open" && !plan.complete) return { kind: "cancel", chains: [plan.originChainId], requested: false };
|
|
5741
|
+
return { kind: "waiting" };
|
|
5742
|
+
}
|
|
5743
|
+
var MAX_PLACES = 32;
|
|
5744
|
+
var MAX_ROWS = 64;
|
|
5745
|
+
var DIGITS = /^\d{1,78}$/;
|
|
5746
|
+
var LOT_KEY = /^(?:\d{1,78}|0x[0-9a-fA-F]{1,64})$/;
|
|
5747
|
+
var TX_HASH = /^0x[0-9a-fA-F]{64}$/;
|
|
5748
|
+
var posInt = (v) => typeof v === "number" && Number.isSafeInteger(v) && v > 0 ? v : void 0;
|
|
5749
|
+
var nonNegInt = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
5750
|
+
var addr = (v) => typeof v === "string" && EVM_ADDRESS.test(v);
|
|
5751
|
+
var list = (v) => v === void 0 || v === null ? [] : Array.isArray(v) && v.length <= MAX_ROWS ? v : null;
|
|
5752
|
+
var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
5753
|
+
function normalizeCancellationPlan(raw2, orderId) {
|
|
5754
|
+
const r = obj(raw2);
|
|
5755
|
+
if (!r || !isZdHeavyOrderId(orderId) || lower3(r.orderId) !== lower3(orderId)) return null;
|
|
5756
|
+
const ownerType = r.ownerType === "evm" || r.ownerType === "solana" ? r.ownerType : null;
|
|
5757
|
+
const state = r.state === "open" || r.state === "cancel_requested" || r.state === "refund_complete" ? r.state : null;
|
|
5758
|
+
const originChainId = posInt(r.originChainId);
|
|
5759
|
+
if (!ownerType || !state || originChainId === void 0 || typeof r.complete !== "boolean" || typeof r.owner !== "string" || r.owner.length > 64) return null;
|
|
5760
|
+
if (r.finished !== void 0 && typeof r.finished !== "boolean") return null;
|
|
5761
|
+
if (!Array.isArray(r.places) || r.places.length > MAX_PLACES) return null;
|
|
5762
|
+
const places = [];
|
|
5763
|
+
for (const rawPlace of r.places) {
|
|
5764
|
+
const p = obj(rawPlace);
|
|
5765
|
+
if (!p || p.kind !== "router" && p.kind !== "hub" || typeof p.canCancelInPerson !== "boolean" || typeof p.complete !== "boolean") return null;
|
|
5766
|
+
const chainId = p.chainId === void 0 ? void 0 : posInt(p.chainId);
|
|
5767
|
+
if (p.chainId !== void 0 && chainId === void 0) return null;
|
|
5768
|
+
const contract = typeof p.contract === "string" ? p.contract : "";
|
|
5769
|
+
if (contract && !addr(contract)) return null;
|
|
5770
|
+
const lots = list(p.lots);
|
|
5771
|
+
const refunds = list(p.refunds);
|
|
5772
|
+
const claimable = list(p.claimable);
|
|
5773
|
+
if (!lots || !refunds || !claimable) return null;
|
|
5774
|
+
const place = {
|
|
5775
|
+
kind: p.kind,
|
|
5776
|
+
chainId,
|
|
5777
|
+
contract,
|
|
5778
|
+
canCancelInPerson: p.canCancelInPerson,
|
|
5779
|
+
complete: p.complete,
|
|
5780
|
+
lots: [],
|
|
5781
|
+
refunds: [],
|
|
5782
|
+
claimable: []
|
|
5783
|
+
};
|
|
5784
|
+
for (const rawLot of lots) {
|
|
5785
|
+
const l = obj(rawLot);
|
|
5786
|
+
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))
|
|
5787
|
+
return null;
|
|
5788
|
+
place.lots.push({ step: l.step, token: l.token, amount: l.amount, key: l.key });
|
|
5789
|
+
}
|
|
5790
|
+
for (const rawRefund of refunds) {
|
|
5791
|
+
const f = obj(rawRefund);
|
|
5792
|
+
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))
|
|
5793
|
+
return null;
|
|
5794
|
+
place.refunds.push({ txHash: f.txHash, step: f.step, token: f.token, amount: f.amount, to: f.to });
|
|
5795
|
+
}
|
|
5796
|
+
for (const rawClaim of claimable) {
|
|
5797
|
+
const c = obj(rawClaim);
|
|
5798
|
+
if (!c || !addr(c.payee) || !addr(c.token) || typeof c.amount !== "string" || !DIGITS.test(c.amount)) return null;
|
|
5799
|
+
place.claimable.push({ payee: c.payee, token: c.token, amount: c.amount });
|
|
5800
|
+
}
|
|
5801
|
+
places.push(place);
|
|
5802
|
+
}
|
|
5803
|
+
return {
|
|
5804
|
+
orderId: r.orderId,
|
|
5805
|
+
ownerType,
|
|
5806
|
+
owner: r.owner,
|
|
5807
|
+
originChainId,
|
|
5808
|
+
state,
|
|
5809
|
+
complete: r.complete,
|
|
5810
|
+
...r.finished !== void 0 ? { finished: r.finished } : {},
|
|
5811
|
+
places
|
|
5812
|
+
};
|
|
5813
|
+
}
|
|
5814
|
+
function zdHeavyOrderPath(orderId, tail) {
|
|
5815
|
+
if (!isZdHeavyOrderId(orderId)) throw new ZdHeavyCodecError("Not a ZD Heavy order id.");
|
|
5816
|
+
return `/orders/${orderId.toLowerCase()}/${tail}`;
|
|
5817
|
+
}
|
|
5818
|
+
async function fetchZdHeavyCancellation(api, orderId) {
|
|
5819
|
+
if (!isZdHeavyOrderId(orderId)) return null;
|
|
5820
|
+
try {
|
|
5821
|
+
return normalizeCancellationPlan(await api.apiRequest(zdHeavyOrderPath(orderId, "cancellation"), { timeoutMs: 1e4 }), orderId);
|
|
5822
|
+
} catch {
|
|
5823
|
+
return null;
|
|
5824
|
+
}
|
|
5825
|
+
}
|
|
5826
|
+
function unsigned(raw2) {
|
|
5827
|
+
const r = obj(raw2);
|
|
5828
|
+
const s = (v) => typeof v === "string" ? v : typeof v === "number" ? String(v) : "";
|
|
5829
|
+
if (!r) return { purpose: "", chainId: "", from: "", to: "", data: "" };
|
|
5830
|
+
return {
|
|
5831
|
+
purpose: s(r.purpose),
|
|
5832
|
+
chainId: s(r.chainId),
|
|
5833
|
+
from: s(r.from),
|
|
5834
|
+
to: s(r.to),
|
|
5835
|
+
data: s(r.data),
|
|
5836
|
+
...r.value !== void 0 ? { value: s(r.value) } : {}
|
|
5837
|
+
};
|
|
5838
|
+
}
|
|
5839
|
+
async function buildZdHeavyCancelTx(api, orderId, chainId) {
|
|
5840
|
+
return unsigned(
|
|
5841
|
+
await api.apiRequest(zdHeavyOrderPath(orderId, "cancel-tx"), {
|
|
5842
|
+
method: "POST",
|
|
5843
|
+
body: JSON.stringify(chainId === void 0 ? {} : { chainId }),
|
|
5844
|
+
timeoutMs: 15e3
|
|
5845
|
+
})
|
|
5846
|
+
);
|
|
5847
|
+
}
|
|
5848
|
+
async function buildZdHeavyClaimTx(api, orderId, chainId, token) {
|
|
5849
|
+
return unsigned(
|
|
5850
|
+
await api.apiRequest(zdHeavyOrderPath(orderId, "claim-tx"), {
|
|
5851
|
+
method: "POST",
|
|
5852
|
+
body: JSON.stringify({ chainId, token }),
|
|
5853
|
+
timeoutMs: 15e3
|
|
5854
|
+
})
|
|
5855
|
+
);
|
|
5856
|
+
}
|
|
5857
|
+
var ZDHEAVY_CANCEL_SELECTOR = "0xf26bce2c";
|
|
5858
|
+
var ZDHEAVY_CLAIM_SELECTOR = "0x1e83409a";
|
|
5859
|
+
var ZDHEAVY_CLAIM_TO_SELECTOR = "0x21c0b342";
|
|
5860
|
+
var MAX_CANCEL_KEYS = 32;
|
|
5861
|
+
function reader(data, selector) {
|
|
5862
|
+
if (typeof data !== "string" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(data) || data.slice(0, 10).toLowerCase() !== selector) {
|
|
5863
|
+
throw new ZdHeavyCodecError("Unexpected call");
|
|
5864
|
+
}
|
|
5865
|
+
const body = data.slice(10).toLowerCase();
|
|
5866
|
+
const size = body.length / 2;
|
|
5867
|
+
const fail = () => {
|
|
5868
|
+
throw new ZdHeavyCodecError("Invalid calldata");
|
|
5869
|
+
};
|
|
5870
|
+
const word2 = (at, bits = 256) => {
|
|
5871
|
+
if (!Number.isSafeInteger(at) || at < 0 || at + 32 > size) return fail();
|
|
5872
|
+
const n = BigInt(`0x${body.slice(at * 2, (at + 32) * 2)}`);
|
|
5873
|
+
if (bits < 256 && n >= 1n << BigInt(bits)) return fail();
|
|
5874
|
+
return n;
|
|
5875
|
+
};
|
|
5876
|
+
const fixed = (at) => {
|
|
5877
|
+
word2(at);
|
|
5878
|
+
return `0x${body.slice(at * 2, (at + 32) * 2)}`;
|
|
5879
|
+
};
|
|
5880
|
+
const address = (at) => `0x${word2(at, 160).toString(16).padStart(40, "0")}`;
|
|
5881
|
+
const offset = (at, expected) => {
|
|
5882
|
+
if (word2(at) !== BigInt(expected)) fail();
|
|
5883
|
+
};
|
|
5884
|
+
const count = (at, each) => {
|
|
5885
|
+
const n = word2(at);
|
|
5886
|
+
if (n > BigInt(Math.floor((size - at - 32) / each))) return fail();
|
|
5887
|
+
return Number(n);
|
|
5888
|
+
};
|
|
5889
|
+
const bytes = (at) => {
|
|
5890
|
+
const n = word2(at);
|
|
5891
|
+
if (n > BigInt(size - at - 32)) return fail();
|
|
5892
|
+
const length = Number(n);
|
|
5893
|
+
const end = at + 32 + Math.ceil(length / 32) * 32;
|
|
5894
|
+
if (end > size || /[^0]/.test(body.slice((at + 32 + length) * 2, end * 2))) return fail();
|
|
5895
|
+
return { value: `0x${body.slice((at + 32) * 2, (at + 32 + length) * 2)}`, end };
|
|
5896
|
+
};
|
|
5897
|
+
return { size, fail, word: word2, fixed, address, offset, count, bytes };
|
|
5898
|
+
}
|
|
5899
|
+
function decodeZdHeavyCancel(data) {
|
|
5900
|
+
const r = reader(data, ZDHEAVY_CANCEL_SELECTOR);
|
|
5901
|
+
const orderId = r.fixed(0);
|
|
5902
|
+
const P3 = 96;
|
|
5903
|
+
r.offset(32, P3);
|
|
5904
|
+
const expiryDate = r.word(P3, 64);
|
|
5905
|
+
r.offset(P3 + 32, 96);
|
|
5906
|
+
const header = r.bytes(P3 + 96);
|
|
5907
|
+
r.offset(P3 + 64, header.end - P3);
|
|
5908
|
+
const hashesAt = header.end;
|
|
5909
|
+
const n = r.count(hashesAt, 32);
|
|
5910
|
+
const stepHashes = [];
|
|
5911
|
+
for (let i = 0; i < n; i++) stepHashes.push(r.fixed(hashesAt + 32 + i * 32));
|
|
5912
|
+
const keysAt = hashesAt + 32 + n * 32;
|
|
5913
|
+
r.offset(64, keysAt);
|
|
5914
|
+
const k = r.count(keysAt, 32);
|
|
5915
|
+
const keys = [];
|
|
5916
|
+
for (let i = 0; i < k; i++) keys.push(r.word(keysAt + 32 + i * 32));
|
|
5917
|
+
if (keysAt + 32 + k * 32 !== r.size) r.fail();
|
|
5918
|
+
return { orderId, proof: { expiryDate, orderHeader: header.value, stepHashes }, keys };
|
|
5919
|
+
}
|
|
5920
|
+
function decodeZdHeavyClaim(data) {
|
|
5921
|
+
const selector = typeof data === "string" ? data.slice(0, 10).toLowerCase() : "";
|
|
5922
|
+
if (selector === ZDHEAVY_CLAIM_SELECTOR) {
|
|
5923
|
+
const r2 = reader(data, ZDHEAVY_CLAIM_SELECTOR);
|
|
5924
|
+
if (r2.size !== 32) r2.fail();
|
|
5925
|
+
return { token: r2.address(0) };
|
|
5926
|
+
}
|
|
5927
|
+
const r = reader(data, ZDHEAVY_CLAIM_TO_SELECTOR);
|
|
5928
|
+
if (r.size !== 64) r.fail();
|
|
5929
|
+
return { token: r.address(0), to: r.address(32) };
|
|
5930
|
+
}
|
|
5931
|
+
var hexBytes2 = (h2) => Uint8Array.from(h2.slice(2).match(/../g) ?? [], (b) => Number.parseInt(b, 16));
|
|
5932
|
+
var keccak = (h2) => `0x${keccak256Hex(hexBytes2(h2))}`;
|
|
5933
|
+
function orderIdFromProof(expiryDate, header, stepHashes) {
|
|
5934
|
+
const tag = Array.from(new TextEncoder().encode("ZD/ORDER"), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
5935
|
+
return keccak(`0x${tag}${expiryDate.toString(16).padStart(16, "0")}${keccak(header).slice(2)}${stepHashes.map((h2) => h2.slice(2)).join("")}`);
|
|
5936
|
+
}
|
|
5937
|
+
var TX = /^0x[0-9a-fA-F]{64}$/;
|
|
5938
|
+
var succeeded = (receipt) => {
|
|
5939
|
+
const status = obj(receipt)?.status;
|
|
5940
|
+
return typeof status === "string" && /^0x0*1$/.test(status);
|
|
5941
|
+
};
|
|
5942
|
+
async function verifyZdHeavySourceOrder(rpc, chainId, hash2, orderId) {
|
|
5943
|
+
const no = (reason) => ({ ok: false, reason });
|
|
5944
|
+
if (!SUPPORTED_CHAIN_IDS.has(chainId) || typeof hash2 !== "string" || !TX.test(hash2) || !isZdHeavyOrderId(orderId)) return no("not checkable");
|
|
5945
|
+
try {
|
|
5946
|
+
const [tx, receipt] = await Promise.all([rpc(chainId, "eth_getTransactionByHash", [hash2]), rpc(chainId, "eth_getTransactionReceipt", [hash2])]);
|
|
5947
|
+
const t = obj(tx);
|
|
5948
|
+
if (!t || lower3(t.hash) !== lower3(hash2)) return no("source transaction not found");
|
|
5949
|
+
if (!succeeded(receipt) || lower3(obj(receipt)?.transactionHash) !== lower3(hash2)) return no("source transaction not confirmed");
|
|
5950
|
+
const router = checkZdHeavyRouter(chainId, typeof t.to === "string" ? t.to : "");
|
|
5951
|
+
if (!router.ok) return no("source transaction is not to a pinned router");
|
|
5952
|
+
const input = typeof t.input === "string" ? t.input : typeof t.data === "string" ? t.data : "";
|
|
5953
|
+
const { submission } = decodeZdHeavySubmit(input);
|
|
5954
|
+
const id = orderIdOf(submission.expiryDate, encodeOrderHeader(submission.serial, router.address, submission.ownerType, submission.owner), submission.steps);
|
|
5955
|
+
return lower3(id) === lower3(orderId) ? { ok: true } : no("source transaction submitted another order");
|
|
5956
|
+
} catch {
|
|
5957
|
+
return no("source transaction could not be read");
|
|
5958
|
+
}
|
|
5959
|
+
}
|
|
5960
|
+
var refuse2 = (what) => ({ ok: false, reason: `The ${what} does not match this order. Refusing to sign.` });
|
|
5961
|
+
function commonChecks(tx, owner, purpose, chainId) {
|
|
5962
|
+
if (!tx || tx.purpose !== purpose) return refuse2("transaction kind");
|
|
5963
|
+
const chain2 = typeof tx.chainId === "string" && /^\d{1,12}$/.test(tx.chainId) ? Number(tx.chainId) : NaN;
|
|
5964
|
+
if (!Number.isSafeInteger(chain2) || chain2 <= 0) return refuse2("chain");
|
|
5965
|
+
if (chainId !== void 0 && chain2 !== chainId) return refuse2("chain");
|
|
5966
|
+
const router = checkZdHeavyRouter(chain2, tx.to);
|
|
5967
|
+
if (!router.ok) return { ok: false, reason: router.reason };
|
|
5968
|
+
if (!addr(owner) || !addr(tx.from) || lower3(tx.from) !== lower3(owner)) return refuse2("sender");
|
|
5969
|
+
try {
|
|
5970
|
+
if (tx.value !== void 0 && tx.value !== "" && BigInt(tx.value) !== 0n) return refuse2("value");
|
|
5971
|
+
} catch {
|
|
5972
|
+
return refuse2("value");
|
|
5973
|
+
}
|
|
5974
|
+
return { ok: true, chainId: chain2, router: router.address };
|
|
5975
|
+
}
|
|
5976
|
+
var accepted = (chainId, owner, router, data) => ({
|
|
5977
|
+
ok: true,
|
|
5978
|
+
chainId,
|
|
5979
|
+
tx: { from: owner, to: router, data: data.toLowerCase(), value: "0x0" }
|
|
5980
|
+
});
|
|
5981
|
+
function checkZdHeavyCancelTx(tx, e) {
|
|
5982
|
+
const base = commonChecks(tx, e.owner, "cancel", e.chainId);
|
|
5983
|
+
if (!base.ok) return base;
|
|
5984
|
+
let decoded;
|
|
5985
|
+
try {
|
|
5986
|
+
decoded = decodeZdHeavyCancel(tx.data);
|
|
5987
|
+
} catch {
|
|
5988
|
+
return refuse2("call");
|
|
5989
|
+
}
|
|
5990
|
+
const { orderId, proof, keys } = decoded;
|
|
5991
|
+
if (!isZdHeavyOrderId(e.orderId) || lower3(orderId) !== lower3(e.orderId)) return refuse2("order id");
|
|
5992
|
+
if (keys.length > MAX_CANCEL_KEYS) return refuse2("lot keys");
|
|
5993
|
+
const listed = e.lotKeys ? new Set(
|
|
5994
|
+
e.lotKeys.map((k) => {
|
|
5995
|
+
try {
|
|
5996
|
+
return BigInt(k).toString();
|
|
5997
|
+
} catch {
|
|
5998
|
+
return "";
|
|
5999
|
+
}
|
|
6000
|
+
})
|
|
6001
|
+
) : void 0;
|
|
6002
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6003
|
+
for (const k of keys) {
|
|
6004
|
+
if (listed && !listed.has(k.toString())) return refuse2("lot keys");
|
|
6005
|
+
const step = k >> 160n;
|
|
6006
|
+
const tokenBits = k & (1n << 160n) - 1n;
|
|
6007
|
+
if (step >= BigInt(proof.stepHashes.length) || tokenBits === 0n || seen.has(k.toString())) return refuse2("lot keys");
|
|
6008
|
+
seen.add(k.toString());
|
|
6009
|
+
}
|
|
6010
|
+
if (proof.stepHashes.length < 1 || proof.stepHashes.length > 8) return refuse2("order proof");
|
|
6011
|
+
if (lower3(orderIdFromProof(proof.expiryDate, proof.orderHeader, proof.stepHashes)) !== lower3(orderId)) return refuse2("order proof");
|
|
6012
|
+
const h2 = proof.orderHeader;
|
|
6013
|
+
if (h2.length !== 2 + ORDER_HEADER_LEN * 2) return refuse2("order proof");
|
|
6014
|
+
const routerWordHex = `0x${h2.slice(2 + 11 * 2, 2 + 43 * 2)}`;
|
|
6015
|
+
const ownerType = Number.parseInt(h2.slice(2 + 43 * 2, 2 + 44 * 2), 16);
|
|
6016
|
+
const ownerWordHex = `0x${h2.slice(2 + 44 * 2)}`;
|
|
6017
|
+
if (lower3(routerWordHex) !== lower3(ownerWord(base.router))) return refuse2("router");
|
|
6018
|
+
if (ownerType !== 1 || lower3(ownerWordHex) !== lower3(ownerWord(e.owner))) return refuse2("owner");
|
|
6019
|
+
return accepted(base.chainId, e.owner, base.router, tx.data);
|
|
6020
|
+
}
|
|
6021
|
+
function checkZdHeavyClaimTx(tx, e) {
|
|
6022
|
+
const base = commonChecks(tx, e.owner, "claim", e.chainId);
|
|
6023
|
+
if (!base.ok) return base;
|
|
6024
|
+
let decoded;
|
|
6025
|
+
try {
|
|
6026
|
+
decoded = decodeZdHeavyClaim(tx.data);
|
|
6027
|
+
} catch {
|
|
6028
|
+
return refuse2("call");
|
|
6029
|
+
}
|
|
6030
|
+
if (!addr(e.token) || lower3(decoded.token) !== lower3(e.token)) return refuse2("token");
|
|
6031
|
+
if (decoded.to !== void 0 && lower3(decoded.to) !== lower3(e.owner)) return refuse2("recipient");
|
|
6032
|
+
return accepted(base.chainId, e.owner, base.router, tx.data);
|
|
6033
|
+
}
|
|
6034
|
+
|
|
5648
6035
|
// src/core/verify.ts
|
|
5649
6036
|
var TX_VERIFY_ATTEMPTS = 5;
|
|
5650
6037
|
var TX_VERIFY_INTERVAL_MS = 2500;
|
|
@@ -5858,7 +6245,13 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
5858
6245
|
return void 0;
|
|
5859
6246
|
}
|
|
5860
6247
|
}
|
|
5861
|
-
|
|
6248
|
+
async function bundledRpc(chainId, method, params) {
|
|
6249
|
+
const override = rpcOverrides[Number(chainId)];
|
|
6250
|
+
const rpc = override && /^https?:\/\//i.test(override) ? override : BUNDLED_RPC[Number(chainId)];
|
|
6251
|
+
if (!rpc) throw new Error("No bundled RPC for this chain");
|
|
6252
|
+
return rpcCall(rpc, method, params);
|
|
6253
|
+
}
|
|
6254
|
+
return { payerNonceBaseline, verifySubmittedTx, readBalances, readNativeBalance, readZdHeavySubmitFee, bundledRpc };
|
|
5862
6255
|
}
|
|
5863
6256
|
|
|
5864
6257
|
// src/core/config.ts
|
|
@@ -5981,10 +6374,11 @@ function createEngine(config = {}) {
|
|
|
5981
6374
|
fetchPrices: (symbols) => api.fetchPrices ? api.fetchPrices(symbols) : Promise.resolve({}),
|
|
5982
6375
|
fetchPromotions: () => api.fetchPromotions ? api.fetchPromotions() : Promise.resolve([]),
|
|
5983
6376
|
fetchCatalogue: async (allowedAssets, product, options) => {
|
|
5984
|
-
const [chains, registryTokens, routes, health, vaults] = await Promise.all([
|
|
6377
|
+
const [chains, registryTokens, routes, zdHeavyRoutes, health, vaults] = await Promise.all([
|
|
5985
6378
|
api.fetchChains().catch(() => []),
|
|
5986
6379
|
api.fetchTokens().catch(() => []),
|
|
5987
6380
|
api.fetchRoutes().catch(() => []),
|
|
6381
|
+
api.fetchZdHeavyRoutes(),
|
|
5988
6382
|
api.fetchRouteHealth(),
|
|
5989
6383
|
api.fetchRwaVaults()
|
|
5990
6384
|
]);
|
|
@@ -5995,6 +6389,7 @@ function createEngine(config = {}) {
|
|
|
5995
6389
|
chains,
|
|
5996
6390
|
tokens,
|
|
5997
6391
|
routes,
|
|
6392
|
+
zdHeavyRoutes,
|
|
5998
6393
|
product,
|
|
5999
6394
|
...allowed ? { allowedAssets: allowed } : {},
|
|
6000
6395
|
// Solana is a SOURCE only for a surface that can pay from it (the exchange card, through the
|
|
@@ -6016,6 +6411,10 @@ function createEngine(config = {}) {
|
|
|
6016
6411
|
executeSolanaPlanStaged: (input) => executeSolanaPlanStaged({ ...input, rpc: input.rpc ?? solanaRpc }),
|
|
6017
6412
|
previewSolanaSource: (input) => previewSolanaSource(api, input),
|
|
6018
6413
|
trackDelivery: (hash2) => fetchDelivery(api, hash2),
|
|
6414
|
+
fetchZdHeavyCancellation: (orderId) => fetchZdHeavyCancellation(api, orderId),
|
|
6415
|
+
buildZdHeavyCancelTx: (orderId, chainId) => buildZdHeavyCancelTx(api, orderId, chainId),
|
|
6416
|
+
buildZdHeavyClaimTx: (orderId, chainId, tokenAddress) => buildZdHeavyClaimTx(api, orderId, chainId, tokenAddress),
|
|
6417
|
+
verifyZdHeavySourceOrder: (chainId, hash2, orderId) => verifyZdHeavySourceOrder(verifier.bundledRpc, chainId, hash2, orderId),
|
|
6019
6418
|
fetchWalletHistory: (wallets) => fetchWalletHistory(api, wallets),
|
|
6020
6419
|
readSolanaBalance: (owner, mint) => readSolanaBalance(solanaRpc, owner, mint),
|
|
6021
6420
|
simulateSolanaCost: (plan) => simulateSolanaCost(solanaRpc, plan),
|
|
@@ -6163,7 +6562,9 @@ function normalizeWalletError(err2, fallback = "Transaction failed.") {
|
|
|
6163
6562
|
async function sendTransaction(provider, tx) {
|
|
6164
6563
|
const hash2 = await provider.request({
|
|
6165
6564
|
method: "eth_sendTransaction",
|
|
6166
|
-
|
|
6565
|
+
// `chainId` only when the caller names one (ZD Heavy recovery writes): the wallet then refuses to
|
|
6566
|
+
// sign on any other chain. The order submit path names none, so its request is unchanged.
|
|
6567
|
+
params: [{ from: tx.from, to: tx.to, data: tx.data, value: tx.value || "0x0", ...tx.chainId ? { chainId: chainHex(tx.chainId) } : {} }]
|
|
6167
6568
|
});
|
|
6168
6569
|
return hash2;
|
|
6169
6570
|
}
|
|
@@ -6394,6 +6795,8 @@ function useUserPresence() {
|
|
|
6394
6795
|
}
|
|
6395
6796
|
|
|
6396
6797
|
// src/react/hooks/useFlow.ts
|
|
6798
|
+
var REFRESH_LEAD_SECONDS = 20;
|
|
6799
|
+
var SIGN_MIN_SECONDS = 15;
|
|
6397
6800
|
function reportQuietly(engine, report, stage) {
|
|
6398
6801
|
try {
|
|
6399
6802
|
void engine.reportSubmission?.({ ...report, stage })?.catch?.(() => {
|
|
@@ -6417,6 +6820,7 @@ function useFlow(args) {
|
|
|
6417
6820
|
const [nonce, setNonce] = react.useState(0);
|
|
6418
6821
|
const reqId = react.useRef(0);
|
|
6419
6822
|
const busyRef = react.useRef(false);
|
|
6823
|
+
const keepExpiryError = react.useRef(false);
|
|
6420
6824
|
const [planAt, setPlanAt] = react.useState(0);
|
|
6421
6825
|
const planAtRef = react.useRef(0);
|
|
6422
6826
|
const statusRef = react.useRef("idle");
|
|
@@ -6446,7 +6850,8 @@ function useFlow(args) {
|
|
|
6446
6850
|
}
|
|
6447
6851
|
const id = ++reqId.current;
|
|
6448
6852
|
setStatus("loading");
|
|
6449
|
-
setError(null);
|
|
6853
|
+
if (!keepExpiryError.current) setError(null);
|
|
6854
|
+
keepExpiryError.current = false;
|
|
6450
6855
|
setVerdict(null);
|
|
6451
6856
|
setTxHash(null);
|
|
6452
6857
|
setLastTxEntry(null);
|
|
@@ -6512,8 +6917,8 @@ function useFlow(args) {
|
|
|
6512
6917
|
engine.fetchChains().catch(() => [])
|
|
6513
6918
|
]);
|
|
6514
6919
|
if (!alive) return;
|
|
6515
|
-
const
|
|
6516
|
-
setNativeShortfall(nativeFeeShortLabel(
|
|
6920
|
+
const check3 = checkNativeFee(selected, balance);
|
|
6921
|
+
setNativeShortfall(nativeFeeShortLabel(check3, nativeSymbol(Number(src.chainId), chains)));
|
|
6517
6922
|
} catch {
|
|
6518
6923
|
}
|
|
6519
6924
|
})();
|
|
@@ -6539,6 +6944,10 @@ function useFlow(args) {
|
|
|
6539
6944
|
setVerdict(null);
|
|
6540
6945
|
const patch = (id, s, hash2) => setSteps((prev) => prev.map((st) => st.id === id ? { ...st, state: s, ...hash2 ? { hash: hash2 } : {} } : st));
|
|
6541
6946
|
try {
|
|
6947
|
+
if (route.zdHeavy) {
|
|
6948
|
+
if (route.zdHeavy.order.expiresAt - Date.now() / 1e3 < SIGN_MIN_SECONDS) throw new ZdHeavyQuoteExpiredError();
|
|
6949
|
+
assertZdHeavyQuoteFresh(route.zdHeavy.order, Math.floor(Date.now() / 1e3));
|
|
6950
|
+
}
|
|
6542
6951
|
const current = await getChainId(provider);
|
|
6543
6952
|
if (current !== Number(sourceChainId)) {
|
|
6544
6953
|
await switchChain(provider, Number(sourceChainId));
|
|
@@ -6546,10 +6955,10 @@ function useFlow(args) {
|
|
|
6546
6955
|
if (after !== Number(sourceChainId)) throw new Error("Wallet did not switch to the source chain.");
|
|
6547
6956
|
}
|
|
6548
6957
|
if (routeNativeValue(route) > 0n) {
|
|
6549
|
-
const
|
|
6550
|
-
if (
|
|
6958
|
+
const check3 = checkNativeFee(route, await nativeBalance(provider, account));
|
|
6959
|
+
if (check3.short) {
|
|
6551
6960
|
const chains = await engine.fetchChains().catch(() => []);
|
|
6552
|
-
throw new Error(nativeFeeShortMessage(
|
|
6961
|
+
throw new Error(nativeFeeShortMessage(check3, nativeSymbol(Number(sourceChainId), chains), route.source.chainName));
|
|
6553
6962
|
}
|
|
6554
6963
|
}
|
|
6555
6964
|
const heavyExpected = route.zdHeavy ? zdHeavyExpected(route, account, recipient2, ...await Promise.all([engine.fetchTokens(), engine.fetchRoutes()])) : void 0;
|
|
@@ -6569,6 +6978,7 @@ function useFlow(args) {
|
|
|
6569
6978
|
patch(tx.id, "done");
|
|
6570
6979
|
continue;
|
|
6571
6980
|
}
|
|
6981
|
+
if (route.zdHeavy && tx.kind === "submitOrder") assertZdHeavyQuoteFresh(route.zdHeavy.order, Math.floor(Date.now() / 1e3));
|
|
6572
6982
|
if (!validatePlannedTransaction(tx, route, recipient2, heavyExpected ? { ...heavyExpected, nowSec: Math.floor(Date.now() / 1e3) } : void 0)) {
|
|
6573
6983
|
throw new Error(`Refusing to sign a ${tx.kind} that does not match the reviewed plan.`);
|
|
6574
6984
|
}
|
|
@@ -6633,13 +7043,17 @@ function useFlow(args) {
|
|
|
6633
7043
|
}
|
|
6634
7044
|
} catch (e) {
|
|
6635
7045
|
setStatus("error");
|
|
6636
|
-
setError(normalizeWalletError(e));
|
|
7046
|
+
setError(e instanceof ZdHeavyQuoteExpiredError ? e.message : normalizeWalletError(e));
|
|
7047
|
+
if (e instanceof ZdHeavyQuoteExpiredError) {
|
|
7048
|
+
keepExpiryError.current = true;
|
|
7049
|
+
reload();
|
|
7050
|
+
}
|
|
6637
7051
|
setSteps((prev) => prev.map((st) => st.state === "active" ? { ...st, state: "error" } : st));
|
|
6638
7052
|
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
6639
7053
|
} finally {
|
|
6640
7054
|
busyRef.current = false;
|
|
6641
7055
|
}
|
|
6642
|
-
}, [selected, wallet.provider, wallet.account, engine, kind, recipientFor, onSuccess, onError]);
|
|
7056
|
+
}, [selected, wallet.provider, wallet.account, engine, kind, recipientFor, onSuccess, onError, reload]);
|
|
6643
7057
|
const [prices, setPrices] = react.useState(null);
|
|
6644
7058
|
const priceKey = baseSelected?.options?.length ? `${baseSelected.source.asset}|${baseSelected.receive.asset}` : "";
|
|
6645
7059
|
react.useEffect(() => {
|
|
@@ -6696,8 +7110,8 @@ function useFlow(args) {
|
|
|
6696
7110
|
try {
|
|
6697
7111
|
if (typeof engine.fetchPromotions !== "function") return;
|
|
6698
7112
|
const read = await engine.fetchPromotions();
|
|
6699
|
-
const
|
|
6700
|
-
if (alive) setPromotionList((prev) => JSON.stringify(prev) === JSON.stringify(
|
|
7113
|
+
const list2 = Array.isArray(read) ? read : [];
|
|
7114
|
+
if (alive) setPromotionList((prev) => JSON.stringify(prev) === JSON.stringify(list2) ? prev : list2);
|
|
6701
7115
|
} catch {
|
|
6702
7116
|
}
|
|
6703
7117
|
})();
|
|
@@ -6735,6 +7149,24 @@ function useFlow(args) {
|
|
|
6735
7149
|
const quoteReady = status === "ready" && !!plan;
|
|
6736
7150
|
const quotePaused = quoteReady && idle2;
|
|
6737
7151
|
const quoteStale = quoteReady && (idle2 || planAt < returnedAt2);
|
|
7152
|
+
react.useEffect(() => {
|
|
7153
|
+
if (!enabled || !selected?.zdHeavy || !quoteReady || quotePaused || busyRef.current) return;
|
|
7154
|
+
let timer2;
|
|
7155
|
+
const schedule2 = () => {
|
|
7156
|
+
clearTimeout(timer2);
|
|
7157
|
+
if (document.visibilityState !== "visible" || busyRef.current) return;
|
|
7158
|
+
const delay = Math.max(3e3, (selected.zdHeavy.order.expiresAt - REFRESH_LEAD_SECONDS) * 1e3 - Date.now());
|
|
7159
|
+
timer2 = setTimeout(() => {
|
|
7160
|
+
if (!busyRef.current && statusRef.current === "ready" && !isUserIdle() && document.visibilityState === "visible") reload();
|
|
7161
|
+
}, delay);
|
|
7162
|
+
};
|
|
7163
|
+
schedule2();
|
|
7164
|
+
document.addEventListener("visibilitychange", schedule2);
|
|
7165
|
+
return () => {
|
|
7166
|
+
clearTimeout(timer2);
|
|
7167
|
+
document.removeEventListener("visibilitychange", schedule2);
|
|
7168
|
+
};
|
|
7169
|
+
}, [enabled, selected, quoteReady, quotePaused, reload]);
|
|
6738
7170
|
return {
|
|
6739
7171
|
status,
|
|
6740
7172
|
plan,
|
|
@@ -6762,7 +7194,7 @@ function useFlow(args) {
|
|
|
6762
7194
|
var RETRY_DELAYS_MS = [800, 2400, 6e3];
|
|
6763
7195
|
var CATALOGUE_REFRESH_MS = 6e4 + 250;
|
|
6764
7196
|
function catalogueSignature(c) {
|
|
6765
|
-
const ids = (
|
|
7197
|
+
const ids = (list2) => list2.map((t) => `${Number(t.chainId)}:${String(t.address).toLowerCase()}`).join(",");
|
|
6766
7198
|
return [ids(c.tokens), ids(c.sources), [...c.source].sort().join(","), [...c.destination].sort().join(","), [...c.lanes ?? []].sort().join(","), [...c.brokenLanes?.keys() ?? []].sort().join(","), [...c.limitedLanes.keys()].sort().join(",")].join("|");
|
|
6767
7199
|
}
|
|
6768
7200
|
function useCatalogue(engine, options = {}) {
|
|
@@ -6827,16 +7259,16 @@ function useHoldings(engine, account, routes, initialBalances) {
|
|
|
6827
7259
|
const reqId = react.useRef(0);
|
|
6828
7260
|
const targets = react.useMemo(() => {
|
|
6829
7261
|
const seen = /* @__PURE__ */ new Set();
|
|
6830
|
-
const
|
|
7262
|
+
const list2 = [];
|
|
6831
7263
|
for (const r of routes) {
|
|
6832
7264
|
const s = r.source;
|
|
6833
7265
|
if (!s?.tokenAddress || s.decimals == null) continue;
|
|
6834
7266
|
const k = balanceKey(s.chainId, s.tokenAddress);
|
|
6835
7267
|
if (seen.has(k)) continue;
|
|
6836
7268
|
seen.add(k);
|
|
6837
|
-
|
|
7269
|
+
list2.push({ chainId: s.chainId, tokenAddress: s.tokenAddress, decimals: s.decimals });
|
|
6838
7270
|
}
|
|
6839
|
-
return
|
|
7271
|
+
return list2;
|
|
6840
7272
|
}, [routes]);
|
|
6841
7273
|
const targetsKey = react.useMemo(() => targets.map((t) => balanceKey(t.chainId, t.tokenAddress)).join("|"), [targets]);
|
|
6842
7274
|
react.useEffect(() => {
|
|
@@ -7315,6 +7747,13 @@ img.sg-tok-badge{width:16px;padding:0;object-fit:cover;background:var(--sg-bg)}
|
|
|
7315
7747
|
/* transaction detail: copyable hash row (no external links \u2014 everything stays in-widget) */
|
|
7316
7748
|
.sg-txd-hash{display:flex;align-items:center;gap:8px;margin-top:12px;font-size:13px}
|
|
7317
7749
|
.sg-txd-hash .sg-mono{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
7750
|
+
.sg-zdh{margin-top:14px;padding:12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface)}
|
|
7751
|
+
.sg-zdh-title{font-size:14px;font-weight:600;line-height:1.25}
|
|
7752
|
+
.sg-zdh-body{margin:4px 0 10px;font-size:12px;line-height:1.45;color:var(--sg-text-muted)}
|
|
7753
|
+
.sg-zdh-actions{display:flex;flex-direction:column;gap:10px}
|
|
7754
|
+
.sg-zdh-action{display:flex;flex-direction:column;gap:6px}
|
|
7755
|
+
.sg-zdh-action .sg-txd-hash{margin-top:0}
|
|
7756
|
+
.sg-zdh-status{margin-top:14px}
|
|
7318
7757
|
.sg-copy{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;width:26px;height:26px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:transparent;color:var(--sg-text-muted);cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
|
|
7319
7758
|
.sg-copy:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
7320
7759
|
|
|
@@ -8620,8 +9059,8 @@ function groupDeployments(deployments, prices) {
|
|
|
8620
9059
|
const members = /* @__PURE__ */ new Map();
|
|
8621
9060
|
for (const d of [...deployments].sort(byDeployment)) {
|
|
8622
9061
|
const key2 = String(d.token.symbol).toUpperCase();
|
|
8623
|
-
const
|
|
8624
|
-
if (
|
|
9062
|
+
const list2 = members.get(key2);
|
|
9063
|
+
if (list2) list2.push(d);
|
|
8625
9064
|
else {
|
|
8626
9065
|
members.set(key2, [d]);
|
|
8627
9066
|
order.push(key2);
|
|
@@ -8635,10 +9074,10 @@ var CHAIN_ALIASES = {
|
|
|
8635
9074
|
43114: ["avax"]
|
|
8636
9075
|
};
|
|
8637
9076
|
function labelForms(label2) {
|
|
8638
|
-
const
|
|
8639
|
-
if (!
|
|
8640
|
-
const compact =
|
|
8641
|
-
return compact && compact !==
|
|
9077
|
+
const lower6 = label2.trim().toLowerCase();
|
|
9078
|
+
if (!lower6) return [];
|
|
9079
|
+
const compact = lower6.replace(/[^a-z0-9]/g, "");
|
|
9080
|
+
return compact && compact !== lower6 ? [lower6, compact] : [lower6];
|
|
8642
9081
|
}
|
|
8643
9082
|
function buildChainSearchTerms(chains) {
|
|
8644
9083
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -9361,22 +9800,22 @@ function TriggerGlyph({ cv }) {
|
|
|
9361
9800
|
if (cv.tone === "blocked" || cv.tone === "warn") return /* @__PURE__ */ jsxRuntime.jsx(CloseCircle, {});
|
|
9362
9801
|
return /* @__PURE__ */ jsxRuntime.jsx(ShieldTick, {});
|
|
9363
9802
|
}
|
|
9364
|
-
function CheckRow({ check:
|
|
9365
|
-
const label2 =
|
|
9366
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "sg-cp-check", "data-ok":
|
|
9803
|
+
function CheckRow({ check: check3, onViewPolicy }) {
|
|
9804
|
+
const label2 = check3.id === "risk" ? check3.ok ? "Risk screening passed" : "Risk screening failed" : check3.label;
|
|
9805
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "sg-cp-check", "data-ok": check3.ok, children: [
|
|
9367
9806
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cp-check-head", children: [
|
|
9368
9807
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-cp-check-label", children: [
|
|
9369
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cp-check-mark", "data-ok":
|
|
9808
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cp-check-mark", "data-ok": check3.ok, children: check3.ok ? /* @__PURE__ */ jsxRuntime.jsx(Tick, {}) : /* @__PURE__ */ jsxRuntime.jsx(Cross, {}) }),
|
|
9370
9809
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: label2 }),
|
|
9371
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", children:
|
|
9810
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", children: check3.ok ? " \u2014 passed" : " \u2014 failed" })
|
|
9372
9811
|
] }),
|
|
9373
|
-
|
|
9812
|
+
check3.id === "risk" ? /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "sg-cp-link", onClick: onViewPolicy, children: [
|
|
9374
9813
|
"View policy",
|
|
9375
9814
|
/* @__PURE__ */ jsxRuntime.jsx(CornerArrow, {})
|
|
9376
9815
|
] }) : null
|
|
9377
9816
|
] }),
|
|
9378
|
-
|
|
9379
|
-
|
|
9817
|
+
check3.note ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cp-check-note", children: check3.note }) : null,
|
|
9818
|
+
check3.reasons.map((reason) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cp-check-reason", children: humanizeComplianceReason(reason) }, reason))
|
|
9380
9819
|
] });
|
|
9381
9820
|
}
|
|
9382
9821
|
function QuoteChecks({
|
|
@@ -9410,7 +9849,7 @@ function QuoteChecks({
|
|
|
9410
9849
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-cp-summary-sub", children: "The gateway returned no compliance decision for this quote, so there is nothing to show. It is not a failed check." })
|
|
9411
9850
|
)
|
|
9412
9851
|
] }),
|
|
9413
|
-
checks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-cp-checks", children: checks.map((
|
|
9852
|
+
checks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-cp-checks", children: checks.map((check3) => /* @__PURE__ */ jsxRuntime.jsx(CheckRow, { check: check3, onViewPolicy }, check3.id)) }) : null,
|
|
9414
9853
|
orphans.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-cp-orphans", children: orphans.map((reason) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: humanizeComplianceReason(reason) }, reason)) }) : null,
|
|
9415
9854
|
direct2 && checks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-cp-scope", children: DIRECT_SCOPE_NOTE }) : null
|
|
9416
9855
|
] }),
|
|
@@ -9604,6 +10043,398 @@ function useWalletHistory(engine, wallets) {
|
|
|
9604
10043
|
}, [engine, key2]);
|
|
9605
10044
|
return entries;
|
|
9606
10045
|
}
|
|
10046
|
+
var lower4 = (s) => (s ?? "").toLowerCase();
|
|
10047
|
+
var ZDH_RECHECK_MS = 15e3;
|
|
10048
|
+
var ZDH_RECHECK_FOR_MS = 30 * 6e4;
|
|
10049
|
+
var inFlight2 = /* @__PURE__ */ new Set();
|
|
10050
|
+
var writes = /* @__PURE__ */ new Map();
|
|
10051
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
10052
|
+
var notify = () => {
|
|
10053
|
+
for (const listener of listeners) listener();
|
|
10054
|
+
};
|
|
10055
|
+
var hidden3 = () => typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
10056
|
+
var unresolved = (w) => !!w && (w.status === "checking" || w.status === "stalled");
|
|
10057
|
+
var lockKey = (account, orderId, chainId, kind, asset) => `${lower4(account)}:${lower4(orderId)}:${chainId}:${kind}:${kind === "claim" ? lower4(asset) : ""}`;
|
|
10058
|
+
function cancelScope(keys) {
|
|
10059
|
+
const norm = keys.map((k) => {
|
|
10060
|
+
try {
|
|
10061
|
+
return BigInt(k).toString();
|
|
10062
|
+
} catch {
|
|
10063
|
+
return k;
|
|
10064
|
+
}
|
|
10065
|
+
});
|
|
10066
|
+
return `cancel:${[...new Set(norm)].sort().join(",")}`;
|
|
10067
|
+
}
|
|
10068
|
+
var claimScope = (asset, amount) => `claim:${lower4(asset)}:${amount ?? ""}`;
|
|
10069
|
+
async function check2(key2) {
|
|
10070
|
+
const w = writes.get(key2);
|
|
10071
|
+
if (!w || w.checking || !unresolved(w)) return;
|
|
10072
|
+
w.checking = true;
|
|
10073
|
+
let status;
|
|
10074
|
+
try {
|
|
10075
|
+
status = (await w.engine.verifySubmittedTx({ chainId: w.chainId, hash: w.hash, ...w.tx, minNonce: w.minNonce ?? 0 })).status;
|
|
10076
|
+
} catch {
|
|
10077
|
+
status = "unconfirmed";
|
|
10078
|
+
}
|
|
10079
|
+
w.checking = false;
|
|
10080
|
+
if (writes.get(key2) !== w) return;
|
|
10081
|
+
if (status === "confirmed" || status === "reverted") {
|
|
10082
|
+
if (w.timer) clearTimeout(w.timer);
|
|
10083
|
+
w.timer = void 0;
|
|
10084
|
+
w.status = status;
|
|
10085
|
+
notify();
|
|
10086
|
+
if (status === "confirmed") {
|
|
10087
|
+
try {
|
|
10088
|
+
window.dispatchEvent(new CustomEvent(TX_HISTORY_EVENT, { detail: { account: lower4(w.tx.from) } }));
|
|
10089
|
+
} catch {
|
|
10090
|
+
}
|
|
10091
|
+
}
|
|
10092
|
+
}
|
|
10093
|
+
}
|
|
10094
|
+
function schedule(key2) {
|
|
10095
|
+
const w = writes.get(key2);
|
|
10096
|
+
if (!w) return;
|
|
10097
|
+
if (w.timer) clearTimeout(w.timer);
|
|
10098
|
+
w.timer = void 0;
|
|
10099
|
+
if (w.status !== "checking") return;
|
|
10100
|
+
if (Date.now() - w.since >= ZDH_RECHECK_FOR_MS) {
|
|
10101
|
+
w.status = "stalled";
|
|
10102
|
+
notify();
|
|
10103
|
+
return;
|
|
10104
|
+
}
|
|
10105
|
+
w.timer = setTimeout(async () => {
|
|
10106
|
+
w.timer = void 0;
|
|
10107
|
+
if (!hidden3()) await check2(key2);
|
|
10108
|
+
schedule(key2);
|
|
10109
|
+
}, ZDH_RECHECK_MS);
|
|
10110
|
+
}
|
|
10111
|
+
function useZdHeavyAction(a) {
|
|
10112
|
+
const [phase, setPhase] = react.useState("idle");
|
|
10113
|
+
const [error, setError] = react.useState(null);
|
|
10114
|
+
const [switching, setSwitching] = react.useState(false);
|
|
10115
|
+
const alive = react.useRef(true);
|
|
10116
|
+
const [, rerender] = react.useReducer((n) => n + 1, 0);
|
|
10117
|
+
react.useEffect(() => {
|
|
10118
|
+
alive.current = true;
|
|
10119
|
+
listeners.add(rerender);
|
|
10120
|
+
return () => {
|
|
10121
|
+
alive.current = false;
|
|
10122
|
+
listeners.delete(rerender);
|
|
10123
|
+
};
|
|
10124
|
+
}, []);
|
|
10125
|
+
const walletEpoch = react.useRef(0);
|
|
10126
|
+
const walletKey = `${lower4(a.account)}:${a.walletChainId ?? ""}`;
|
|
10127
|
+
const lastWalletKey = react.useRef(walletKey);
|
|
10128
|
+
if (lastWalletKey.current !== walletKey) {
|
|
10129
|
+
lastWalletKey.current = walletKey;
|
|
10130
|
+
walletEpoch.current += 1;
|
|
10131
|
+
}
|
|
10132
|
+
const key2 = a.account ? lockKey(a.account, a.orderId, a.chainId, a.kind, a.asset) : "";
|
|
10133
|
+
const write = key2 ? writes.get(key2) : void 0;
|
|
10134
|
+
const scope = a.kind === "cancel" ? cancelScope(a.lotKeys ?? []) : claimScope(a.asset, a.amount);
|
|
10135
|
+
react.useEffect(() => {
|
|
10136
|
+
if (!key2 || !unresolved(writes.get(key2))) return;
|
|
10137
|
+
void check2(key2).then(() => schedule(key2));
|
|
10138
|
+
}, [key2]);
|
|
10139
|
+
const firedFor = react.useRef(null);
|
|
10140
|
+
const onConfirmed = a.onConfirmed;
|
|
10141
|
+
react.useEffect(() => {
|
|
10142
|
+
if (write?.status === "confirmed" && firedFor.current !== write.hash) {
|
|
10143
|
+
firedFor.current = write.hash;
|
|
10144
|
+
onConfirmed?.(write.hash);
|
|
10145
|
+
}
|
|
10146
|
+
});
|
|
10147
|
+
const supported = SUPPORTED_CHAIN_IDS.has(a.chainId);
|
|
10148
|
+
const connected2 = !!a.account && !!a.provider;
|
|
10149
|
+
const isOwner = !!a.account && lower4(a.account) === lower4(a.owner);
|
|
10150
|
+
const onChain = supported && a.walletChainId === a.chainId;
|
|
10151
|
+
const busy = phase === "preparing" || phase === "signing";
|
|
10152
|
+
const done = write?.status === "confirmed" && write.scope === scope;
|
|
10153
|
+
async function run() {
|
|
10154
|
+
const { engine, provider, account } = a;
|
|
10155
|
+
if (!engine || !provider || !account || !supported) return;
|
|
10156
|
+
const key3 = lockKey(account, a.orderId, a.chainId, a.kind, a.asset);
|
|
10157
|
+
const prior = writes.get(key3);
|
|
10158
|
+
if (unresolved(prior) || prior?.status === "confirmed" && prior.scope === scope) {
|
|
10159
|
+
setError(`This ${a.kind} was already sent. Wait for it to confirm.`);
|
|
10160
|
+
return;
|
|
10161
|
+
}
|
|
10162
|
+
if (inFlight2.has(key3)) {
|
|
10163
|
+
setError(`This ${a.kind} is already in progress. Wait for it to finish.`);
|
|
10164
|
+
return;
|
|
10165
|
+
}
|
|
10166
|
+
if (prior) writes.delete(key3);
|
|
10167
|
+
inFlight2.add(key3);
|
|
10168
|
+
const epoch = walletEpoch.current;
|
|
10169
|
+
const signer = account;
|
|
10170
|
+
const stale = () => !alive.current || walletEpoch.current !== epoch;
|
|
10171
|
+
setError(null);
|
|
10172
|
+
setPhase("preparing");
|
|
10173
|
+
try {
|
|
10174
|
+
const unsigned2 = a.kind === "cancel" ? await engine.buildZdHeavyCancelTx(a.orderId, a.chainId) : await engine.buildZdHeavyClaimTx(a.orderId, a.chainId, a.asset ?? "");
|
|
10175
|
+
const checked = a.kind === "cancel" ? checkZdHeavyCancelTx(unsigned2, { orderId: a.orderId, owner: signer, chainId: a.chainId, lotKeys: a.lotKeys }) : checkZdHeavyClaimTx(unsigned2, { owner: signer, chainId: a.chainId, token: a.asset ?? "" });
|
|
10176
|
+
if (!checked.ok) {
|
|
10177
|
+
if (alive.current) {
|
|
10178
|
+
setError(checked.reason);
|
|
10179
|
+
setPhase("idle");
|
|
10180
|
+
}
|
|
10181
|
+
return;
|
|
10182
|
+
}
|
|
10183
|
+
const minNonce = await engine.payerNonceBaseline(checked.chainId, signer);
|
|
10184
|
+
if (stale()) throw new Error(`The wallet changed while the ${a.kind} was prepared. Try again.`);
|
|
10185
|
+
const [walletChain, accounts] = await Promise.all([getChainId(provider), getAccounts(provider)]);
|
|
10186
|
+
if (stale()) throw new Error(`The wallet changed while the ${a.kind} was prepared. Try again.`);
|
|
10187
|
+
if (walletChain !== checked.chainId) throw new Error(`Switch your wallet to ${a.chainName} and try again.`);
|
|
10188
|
+
if (!accounts.some((x) => lower4(x) === lower4(signer))) throw new Error("The connected wallet changed. Try again.");
|
|
10189
|
+
setPhase("signing");
|
|
10190
|
+
const sentScope = a.kind === "cancel" ? cancelScope(decodeZdHeavyCancel(checked.tx.data).keys.map(String)) : claimScope(decodeZdHeavyClaim(checked.tx.data).token, a.amount);
|
|
10191
|
+
const hash2 = await sendTransaction(provider, { ...checked.tx, chainId: checked.chainId });
|
|
10192
|
+
writes.set(key3, {
|
|
10193
|
+
hash: hash2,
|
|
10194
|
+
chainId: checked.chainId,
|
|
10195
|
+
tx: checked.tx,
|
|
10196
|
+
minNonce,
|
|
10197
|
+
engine,
|
|
10198
|
+
scope: sentScope,
|
|
10199
|
+
since: Date.now(),
|
|
10200
|
+
status: "checking",
|
|
10201
|
+
checking: false
|
|
10202
|
+
});
|
|
10203
|
+
notify();
|
|
10204
|
+
if (alive.current) setPhase("idle");
|
|
10205
|
+
await check2(key3);
|
|
10206
|
+
schedule(key3);
|
|
10207
|
+
} catch (e) {
|
|
10208
|
+
if (!alive.current) return;
|
|
10209
|
+
const msg = normalizeWalletError(e, "");
|
|
10210
|
+
setError(msg ? `Could not ${a.kind === "claim" ? "claim" : "cancel"}: ${msg}` : `Could not prepare the ${a.kind}.`);
|
|
10211
|
+
setPhase("idle");
|
|
10212
|
+
} finally {
|
|
10213
|
+
inFlight2.delete(key3);
|
|
10214
|
+
}
|
|
10215
|
+
}
|
|
10216
|
+
function retryCheck() {
|
|
10217
|
+
const w = key2 ? writes.get(key2) : void 0;
|
|
10218
|
+
if (!w || !unresolved(w)) return;
|
|
10219
|
+
w.since = Date.now();
|
|
10220
|
+
w.status = "checking";
|
|
10221
|
+
notify();
|
|
10222
|
+
void check2(key2).then(() => schedule(key2));
|
|
10223
|
+
}
|
|
10224
|
+
const text = !connected2 ? "Connect wallet" : !supported ? `Unsupported network ${a.chainId}` : !isOwner ? a.kind === "claim" ? "Connected wallet is not the refund address" : "Connected wallet is not the order owner" : !onChain ? switching ? "Switching\u2026" : `Switch to ${a.chainName}` : done ? a.kind === "claim" ? "Claimed" : `Cancelled on ${a.chainName}` : phase === "preparing" ? "Preparing\u2026" : phase === "signing" ? "Signing\u2026" : a.label;
|
|
10225
|
+
const disabled = !connected2 ? !a.onConnect : !supported || !isOwner || (!onChain ? switching : busy || done || unresolved(write));
|
|
10226
|
+
function onClick() {
|
|
10227
|
+
if (busy || switching) return;
|
|
10228
|
+
if (!connected2) return a.onConnect?.();
|
|
10229
|
+
if (!onChain && supported && a.provider) {
|
|
10230
|
+
setSwitching(true);
|
|
10231
|
+
setError(null);
|
|
10232
|
+
switchChain(a.provider, a.chainId).catch((e) => alive.current && setError(normalizeWalletError(e, `Could not switch to ${a.chainName}.`))).finally(() => alive.current && setSwitching(false));
|
|
10233
|
+
return;
|
|
10234
|
+
}
|
|
10235
|
+
void run();
|
|
10236
|
+
}
|
|
10237
|
+
const reverted = write?.status === "reverted" ? `The ${a.kind} reverted on-chain. Nothing changed.` : null;
|
|
10238
|
+
return {
|
|
10239
|
+
text,
|
|
10240
|
+
disabled,
|
|
10241
|
+
onClick,
|
|
10242
|
+
retryCheck,
|
|
10243
|
+
sentHash: write?.hash ?? null,
|
|
10244
|
+
done,
|
|
10245
|
+
busy,
|
|
10246
|
+
error: error ?? reverted,
|
|
10247
|
+
pending: write?.status === "checking",
|
|
10248
|
+
stalled: write?.status === "stalled"
|
|
10249
|
+
};
|
|
10250
|
+
}
|
|
10251
|
+
var ZDH_PLAN_REFRESH_MS = 1e4;
|
|
10252
|
+
var hidden4 = () => typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
10253
|
+
var settled = (plan) => plan.complete && (plan.finished === true || plan.state === "refund_complete");
|
|
10254
|
+
function useZdHeavyRecovery(engine, orderId) {
|
|
10255
|
+
const [state, setState] = react.useState({ orderId, value: { status: "loading" } });
|
|
10256
|
+
const readRef = react.useRef(() => {
|
|
10257
|
+
});
|
|
10258
|
+
react.useEffect(() => {
|
|
10259
|
+
setState({ orderId, value: { status: "loading" } });
|
|
10260
|
+
if (!engine || !isZdHeavyOrderId(orderId)) return;
|
|
10261
|
+
let alive = true;
|
|
10262
|
+
let timer2;
|
|
10263
|
+
let shown = false;
|
|
10264
|
+
let started2 = Date.now();
|
|
10265
|
+
const read = async () => {
|
|
10266
|
+
if (timer2) clearTimeout(timer2);
|
|
10267
|
+
timer2 = void 0;
|
|
10268
|
+
if (!hidden4()) {
|
|
10269
|
+
const plan = await engine.fetchZdHeavyCancellation(orderId);
|
|
10270
|
+
if (!alive) return;
|
|
10271
|
+
if (plan) {
|
|
10272
|
+
shown = true;
|
|
10273
|
+
setState({ orderId, value: { status: "ready", plan } });
|
|
10274
|
+
if (settled(plan)) return;
|
|
10275
|
+
} else if (!shown) {
|
|
10276
|
+
setState({ orderId, value: { status: "unavailable" } });
|
|
10277
|
+
}
|
|
10278
|
+
}
|
|
10279
|
+
if (Date.now() - started2 > DELIVERY_GIVE_UP_MS) return;
|
|
10280
|
+
timer2 = setTimeout(read, ZDH_PLAN_REFRESH_MS);
|
|
10281
|
+
};
|
|
10282
|
+
readRef.current = () => {
|
|
10283
|
+
started2 = Date.now();
|
|
10284
|
+
void read();
|
|
10285
|
+
};
|
|
10286
|
+
void read();
|
|
10287
|
+
return () => {
|
|
10288
|
+
alive = false;
|
|
10289
|
+
readRef.current = () => {
|
|
10290
|
+
};
|
|
10291
|
+
if (timer2) clearTimeout(timer2);
|
|
10292
|
+
};
|
|
10293
|
+
}, [engine, orderId]);
|
|
10294
|
+
const refresh = react.useCallback(() => readRef.current(), []);
|
|
10295
|
+
return { state: state.orderId === orderId ? state.value : { status: "loading" }, refresh };
|
|
10296
|
+
}
|
|
10297
|
+
function useZdHeavySourceBinding(engine, chainId, hash2, orderId) {
|
|
10298
|
+
const key2 = `${chainId ?? ""}:${hash2}:${orderId ?? ""}`;
|
|
10299
|
+
const [state, setState] = react.useState({ key: key2, value: "checking" });
|
|
10300
|
+
react.useEffect(() => {
|
|
10301
|
+
setState({ key: key2, value: "checking" });
|
|
10302
|
+
if (!engine || typeof chainId !== "number" || !isZdHeavyOrderId(orderId)) {
|
|
10303
|
+
setState({ key: key2, value: "unbound" });
|
|
10304
|
+
return;
|
|
10305
|
+
}
|
|
10306
|
+
let alive = true;
|
|
10307
|
+
engine.verifyZdHeavySourceOrder(chainId, hash2, orderId).then((r) => alive && setState({ key: key2, value: r.ok ? "bound" : "unbound" })).catch(() => alive && setState({ key: key2, value: "unbound" }));
|
|
10308
|
+
return () => {
|
|
10309
|
+
alive = false;
|
|
10310
|
+
};
|
|
10311
|
+
}, [engine, chainId, hash2, orderId, key2]);
|
|
10312
|
+
return state.key === key2 ? state.value : "checking";
|
|
10313
|
+
}
|
|
10314
|
+
var lower5 = (s) => (s ?? "").toLowerCase();
|
|
10315
|
+
var shortHash = (h2) => `${h2.slice(0, 10)}\u2026${h2.slice(-8)}`;
|
|
10316
|
+
function showsZdHeavyRecovery(entry) {
|
|
10317
|
+
if (entry.protocol !== "zdheavy" || !isZdHeavyOrderId(entry.orderId)) return false;
|
|
10318
|
+
return !(entry.delivery === "delivered" && !entry.claimable);
|
|
10319
|
+
}
|
|
10320
|
+
function ZdHeavyRecovery(props) {
|
|
10321
|
+
const orderId = isZdHeavyOrderId(props.entry.orderId) ? props.entry.orderId : void 0;
|
|
10322
|
+
const binding = useZdHeavySourceBinding(props.engine, props.entry.chainId, props.entry.hash, orderId);
|
|
10323
|
+
const { state, refresh } = useZdHeavyRecovery(props.engine, binding === "bound" ? orderId : void 0);
|
|
10324
|
+
const view = state.status === "ready" ? zdHeavyRecovery(state.plan, props.account) : null;
|
|
10325
|
+
if (!orderId) return null;
|
|
10326
|
+
if (binding === "unbound") {
|
|
10327
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-note sg-zdh-status", role: "status", "data-testid": "zdh-recovery-unbound", children: "This order could not be matched to its transaction on-chain, so it cannot be cancelled or claimed from here." });
|
|
10328
|
+
}
|
|
10329
|
+
if (state.status === "unavailable") {
|
|
10330
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-note sg-zdh-status", role: "status", "aria-live": "polite", "data-testid": "zdh-recovery-unavailable", children: "Cancellation status is unavailable right now. It is checked again in a moment." });
|
|
10331
|
+
}
|
|
10332
|
+
if (binding === "checking" || state.status === "loading" || !view) {
|
|
10333
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-note sg-zdh-status", role: "status", "aria-live": "polite", children: "Checking whether this order can be cancelled\u2026" });
|
|
10334
|
+
}
|
|
10335
|
+
const plan = state.plan;
|
|
10336
|
+
if (view.kind === "delivered" || view.kind === "not-owner") return null;
|
|
10337
|
+
const chainName3 = (id) => CHAIN_LABELS[id] || `Chain ${id}`;
|
|
10338
|
+
const listNames = (ids) => {
|
|
10339
|
+
const names = ids.map(chainName3);
|
|
10340
|
+
return names.length <= 1 ? names[0] ?? "" : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
10341
|
+
};
|
|
10342
|
+
const amountLabel = (chainId, asset, amount) => {
|
|
10343
|
+
const t = (props.tokens ?? []).find((x) => Number(x.chainId) === chainId && lower5(String(x.address)) === lower5(asset));
|
|
10344
|
+
if (!t) return "your funds";
|
|
10345
|
+
try {
|
|
10346
|
+
return `${formatUnits(amount, Number(t.decimals))} ${t.symbol}`;
|
|
10347
|
+
} catch {
|
|
10348
|
+
return t.symbol;
|
|
10349
|
+
}
|
|
10350
|
+
};
|
|
10351
|
+
const bid = props.entry.fromTicker || props.entry.fromAsset || "funds";
|
|
10352
|
+
let headline;
|
|
10353
|
+
let body;
|
|
10354
|
+
let actions = [];
|
|
10355
|
+
let refunds = [];
|
|
10356
|
+
if (view.kind === "claim") {
|
|
10357
|
+
headline = "Ready to claim";
|
|
10358
|
+
body = `The refund could not be sent to your wallet automatically, so it is waiting for you on ${listNames([...new Set(view.claims.map((c) => c.chainId))])}. Confirm the claim in your wallet to receive it.`;
|
|
10359
|
+
actions = view.claims.map((c) => ({
|
|
10360
|
+
// The signer is part of the key: another wallet's claim is another button, not this one's state.
|
|
10361
|
+
key: `claim:${c.chainId}:${c.token}:${props.account ?? ""}`,
|
|
10362
|
+
kind: "claim",
|
|
10363
|
+
chainId: c.chainId,
|
|
10364
|
+
asset: c.token,
|
|
10365
|
+
amount: c.amount,
|
|
10366
|
+
label: `Claim ${amountLabel(c.chainId, c.token, c.amount)}`,
|
|
10367
|
+
// The payee: the claim reads claimable[msg.sender], so only it can send this.
|
|
10368
|
+
owner: props.account ?? ""
|
|
10369
|
+
}));
|
|
10370
|
+
} else if (view.kind === "cancel") {
|
|
10371
|
+
const holding = plan.places.some((p) => p.lots.length > 0);
|
|
10372
|
+
headline = view.requested ? "Finish the cancellation" : "You can cancel this order and reclaim your funds";
|
|
10373
|
+
body = view.requested ? `Part of your ${bid} is still held by the order router on ${listNames(view.chains)}. Cancel there too to have it refunded.` : holding ? view.chains.length > 1 ? `Your ${bid} is held by the order router on ${listNames(view.chains)}. Cancel on each network to have it refunded, one signature per network.` : `Your ${bid} is held by the order router on ${listNames(view.chains)}. Cancel it and the router refunds what it holds in the same transaction.` : `Your ${bid} is on its way between networks. If you cancel, the order stops and the funds are refunded when they land; you may be asked to cancel once more on the network they reach.`;
|
|
10374
|
+
actions = view.chains.map((chainId) => {
|
|
10375
|
+
const lots = plan.places.find((p) => p.kind === "router" && p.chainId === chainId)?.lots ?? [];
|
|
10376
|
+
return {
|
|
10377
|
+
key: `cancel:${chainId}:${props.account ?? ""}`,
|
|
10378
|
+
kind: "cancel",
|
|
10379
|
+
chainId,
|
|
10380
|
+
label: view.chains.length > 1 || view.requested ? `Cancel on ${chainName3(chainId)}` : "Cancel order",
|
|
10381
|
+
owner: plan.owner,
|
|
10382
|
+
lotKeys: lots.length ? lots.map((l) => l.key) : void 0
|
|
10383
|
+
};
|
|
10384
|
+
});
|
|
10385
|
+
} else if (view.kind === "refunded") {
|
|
10386
|
+
headline = "Cancellation reported by ZeroDelta";
|
|
10387
|
+
body = `ZeroDelta reports your ${bid} as refunded. This widget has not checked the refund on-chain.`;
|
|
10388
|
+
refunds = view.refunds.map((r) => r.txHash);
|
|
10389
|
+
} else {
|
|
10390
|
+
headline = "What happens next";
|
|
10391
|
+
body = "Your cancellation is in. Funds still travelling between networks are refunded when they land; this page updates by itself.";
|
|
10392
|
+
}
|
|
10393
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-zdh", "data-testid": "zdh-recovery", "data-zdh-recovery": view.kind, children: [
|
|
10394
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-zdh-title", children: headline }),
|
|
10395
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-zdh-body", children: body }),
|
|
10396
|
+
actions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-zdh-actions", children: actions.map(({ key: key2, ...a }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10397
|
+
ZdHeavyActionButton,
|
|
10398
|
+
{
|
|
10399
|
+
...a,
|
|
10400
|
+
engine: props.engine,
|
|
10401
|
+
provider: props.provider,
|
|
10402
|
+
account: props.account,
|
|
10403
|
+
walletChainId: props.walletChainId,
|
|
10404
|
+
onConnect: props.onConnect,
|
|
10405
|
+
orderId,
|
|
10406
|
+
chainName: chainName3(a.chainId),
|
|
10407
|
+
onConfirmed: refresh
|
|
10408
|
+
},
|
|
10409
|
+
key2
|
|
10410
|
+
)) }) : null,
|
|
10411
|
+
refunds.map((hash2) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-txd-hash", children: [
|
|
10412
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Reported refund tx" }),
|
|
10413
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-mono", children: shortHash(hash2) })
|
|
10414
|
+
] }, hash2))
|
|
10415
|
+
] });
|
|
10416
|
+
}
|
|
10417
|
+
function ZdHeavyActionButton(args) {
|
|
10418
|
+
const a = useZdHeavyAction(args);
|
|
10419
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-zdh-action", children: [
|
|
10420
|
+
a.pending ? (
|
|
10421
|
+
// A write of this wallet for this order is broadcast and its receipt has not decided: no button,
|
|
10422
|
+
// on this mount or any later one, until it does (re-review 2026-12-01, finding 4).
|
|
10423
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-note", role: "status", "aria-live": "polite", "data-testid": "zdh-action-pending", children: "Sent \u2014 confirming" })
|
|
10424
|
+
) : a.stalled ? (
|
|
10425
|
+
// Still undecided after the bounded recheck: say so, and offer another CHECK — never a new send.
|
|
10426
|
+
/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
10427
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-note", role: "status", "data-testid": "zdh-action-stalled", children: "Not confirmed yet \u2014 check the transaction" }),
|
|
10428
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-btn sg-btn-ghost", onClick: a.retryCheck, children: "Retry check" })
|
|
10429
|
+
] })
|
|
10430
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-btn sg-btn-ghost", onClick: a.onClick, disabled: a.disabled, "data-zdh-action": args.kind, children: a.text }),
|
|
10431
|
+
a.error ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-ws-error", role: "alert", "data-testid": "zdh-action-error", children: a.error }) : null,
|
|
10432
|
+
a.sentHash ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-txd-hash", children: [
|
|
10433
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: args.kind === "claim" ? "Claim tx" : "Cancel tx" }),
|
|
10434
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-mono", children: shortHash(a.sentHash) })
|
|
10435
|
+
] }) : null
|
|
10436
|
+
] });
|
|
10437
|
+
}
|
|
9607
10438
|
function BackGlyph() {
|
|
9608
10439
|
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
9609
10440
|
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 12H5" }),
|
|
@@ -9690,6 +10521,7 @@ function TxLegs(props) {
|
|
|
9690
10521
|
function statusBadge(entry) {
|
|
9691
10522
|
if (entry.delivery === "delivered")
|
|
9692
10523
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "ok", children: "Delivered" });
|
|
10524
|
+
if (entry.delivery === "failed" && entry.deliveryStatus === "cancelled") return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", children: "Cancellation reported" });
|
|
9693
10525
|
if (entry.delivery === "failed")
|
|
9694
10526
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "warn", children: "Not delivered" });
|
|
9695
10527
|
if (entry.delivery === "attention")
|
|
@@ -9834,7 +10666,20 @@ function TxDetail(props) {
|
|
|
9834
10666
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Tx hash" }),
|
|
9835
10667
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-mono", children: `${e.hash.slice(0, 10)}\u2026${e.hash.slice(-8)}` }),
|
|
9836
10668
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-copy", onClick: copyHash, "aria-label": copied ? "Copied" : "Copy transaction hash", "aria-live": "polite", title: "Copy transaction hash", children: copied ? /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph, {}) : /* @__PURE__ */ jsxRuntime.jsx(CopyGlyph, {}) })
|
|
9837
|
-
] })
|
|
10669
|
+
] }),
|
|
10670
|
+
props.recovery?.engine && showsZdHeavyRecovery(e) ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
10671
|
+
ZdHeavyRecovery,
|
|
10672
|
+
{
|
|
10673
|
+
entry: e,
|
|
10674
|
+
engine: props.recovery.engine,
|
|
10675
|
+
provider: props.recovery.provider,
|
|
10676
|
+
account: props.recovery.account,
|
|
10677
|
+
walletChainId: props.recovery.walletChainId,
|
|
10678
|
+
onConnect: props.recovery.onConnect,
|
|
10679
|
+
tokens: props.tokens
|
|
10680
|
+
},
|
|
10681
|
+
e.orderId
|
|
10682
|
+
) : null
|
|
9838
10683
|
] });
|
|
9839
10684
|
}
|
|
9840
10685
|
function displayableHistory(entries, account) {
|
|
@@ -9863,7 +10708,15 @@ function TxHistoryPanel(props) {
|
|
|
9863
10708
|
account ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sel-sub sg-mono", children: shortAddress3(account) }) : null
|
|
9864
10709
|
] })
|
|
9865
10710
|
] }),
|
|
9866
|
-
selected ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
10711
|
+
selected ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
10712
|
+
TxDetail,
|
|
10713
|
+
{
|
|
10714
|
+
entry: selected,
|
|
10715
|
+
tokens: props.tokens,
|
|
10716
|
+
vaultIcons: props.vaultIcons,
|
|
10717
|
+
recovery: { engine: props.engine, provider: props.provider, account, walletChainId: props.walletChainId, onConnect: props.onConnect }
|
|
10718
|
+
}
|
|
10719
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(TxHistoryList, { entries, tokens: props.tokens, vaultIcons: props.vaultIcons, onPick: pick })
|
|
9867
10720
|
] });
|
|
9868
10721
|
}
|
|
9869
10722
|
|
|
@@ -9895,7 +10748,7 @@ function registry(win) {
|
|
|
9895
10748
|
const existing = registries.get(win);
|
|
9896
10749
|
if (existing) return existing;
|
|
9897
10750
|
const standard = /* @__PURE__ */ new Set();
|
|
9898
|
-
const
|
|
10751
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
9899
10752
|
let snapshot = EMPTY2;
|
|
9900
10753
|
const read = () => {
|
|
9901
10754
|
const candidates = [...standard].map(solanaWalletInfo);
|
|
@@ -9926,7 +10779,7 @@ function registry(win) {
|
|
|
9926
10779
|
const refresh = () => {
|
|
9927
10780
|
const previous = snapshot;
|
|
9928
10781
|
read();
|
|
9929
|
-
if (previous !== snapshot) for (const cb of
|
|
10782
|
+
if (previous !== snapshot) for (const cb of listeners2) cb();
|
|
9930
10783
|
};
|
|
9931
10784
|
const api = {
|
|
9932
10785
|
register(...wallets) {
|
|
@@ -9940,9 +10793,9 @@ function registry(win) {
|
|
|
9940
10793
|
}
|
|
9941
10794
|
};
|
|
9942
10795
|
const result = { read, watch: (cb) => {
|
|
9943
|
-
|
|
10796
|
+
listeners2.add(cb);
|
|
9944
10797
|
return () => {
|
|
9945
|
-
|
|
10798
|
+
listeners2.delete(cb);
|
|
9946
10799
|
};
|
|
9947
10800
|
} };
|
|
9948
10801
|
registries.set(win, result);
|
|
@@ -11148,13 +12001,13 @@ function PaymentIsland(props) {
|
|
|
11148
12001
|
const exFromBal = exFrom && exFromToken ? exBalances[balanceKey(exFrom.chainId, exFromToken.address)] : void 0;
|
|
11149
12002
|
const fundingTokens = react.useMemo(() => {
|
|
11150
12003
|
const seen = /* @__PURE__ */ new Set();
|
|
11151
|
-
const
|
|
12004
|
+
const list2 = [];
|
|
11152
12005
|
for (const r of visibleRoutes) {
|
|
11153
12006
|
const key2 = balanceKey(r.source.chainId, r.source.tokenAddress);
|
|
11154
12007
|
if (seen.has(key2)) continue;
|
|
11155
12008
|
seen.add(key2);
|
|
11156
12009
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
|
|
11157
|
-
|
|
12010
|
+
list2.push(
|
|
11158
12011
|
reg ?? {
|
|
11159
12012
|
symbol: r.source.asset,
|
|
11160
12013
|
displaySymbol: r.source.ticker,
|
|
@@ -11165,7 +12018,7 @@ function PaymentIsland(props) {
|
|
|
11165
12018
|
}
|
|
11166
12019
|
);
|
|
11167
12020
|
}
|
|
11168
|
-
return
|
|
12021
|
+
return list2;
|
|
11169
12022
|
}, [visibleRoutes, registryTokens]);
|
|
11170
12023
|
const fundingChains = react.useMemo(() => {
|
|
11171
12024
|
const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
|
|
@@ -11173,15 +12026,15 @@ function PaymentIsland(props) {
|
|
|
11173
12026
|
}, [chains, fundingTokens]);
|
|
11174
12027
|
const payableAssets = react.useMemo(() => {
|
|
11175
12028
|
const seen = /* @__PURE__ */ new Set();
|
|
11176
|
-
const
|
|
12029
|
+
const list2 = [];
|
|
11177
12030
|
for (const { route } of held) {
|
|
11178
12031
|
const symbol = symbolKey(route.source.asset);
|
|
11179
12032
|
if (seen.has(symbol)) continue;
|
|
11180
12033
|
seen.add(symbol);
|
|
11181
12034
|
const token = registryTokens.find((t) => Number(t.chainId) === route.source.chainId && addrEq(t.address, route.source.tokenAddress));
|
|
11182
|
-
|
|
12035
|
+
list2.push({ symbol: route.source.asset, logoUrl: token?.logoUrl });
|
|
11183
12036
|
}
|
|
11184
|
-
return
|
|
12037
|
+
return list2;
|
|
11185
12038
|
}, [held, registryTokens]);
|
|
11186
12039
|
const userPicked = react.useRef(false);
|
|
11187
12040
|
const selectRoute = react.useCallback(
|
|
@@ -11399,7 +12252,7 @@ function PaymentIsland(props) {
|
|
|
11399
12252
|
] });
|
|
11400
12253
|
let body;
|
|
11401
12254
|
if (hist && wallet.account) {
|
|
11402
|
-
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
12255
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, provider: wallet.provider, walletChainId: wallet.chainId, onConnect: wallet.connect, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
11403
12256
|
} else if (isPay && view === "select" && wallet.account) {
|
|
11404
12257
|
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
11405
12258
|
TokenSelect,
|
|
@@ -11683,22 +12536,22 @@ function PillLauncher(props) {
|
|
|
11683
12536
|
if (e.key !== "Tab") return;
|
|
11684
12537
|
const root = dialogRef.current;
|
|
11685
12538
|
if (!root) return;
|
|
11686
|
-
const
|
|
12539
|
+
const list2 = Array.from(root.querySelectorAll("a[href],button,input,select,textarea,[tabindex]")).filter(
|
|
11687
12540
|
(el) => el.tabIndex >= 0 && !el.hasAttribute("disabled") && el.getClientRects().length > 0
|
|
11688
12541
|
);
|
|
11689
|
-
if (
|
|
12542
|
+
if (list2.length === 0) {
|
|
11690
12543
|
e.preventDefault();
|
|
11691
12544
|
return;
|
|
11692
12545
|
}
|
|
11693
|
-
const first =
|
|
11694
|
-
const last =
|
|
11695
|
-
const idx =
|
|
12546
|
+
const first = list2[0];
|
|
12547
|
+
const last = list2[list2.length - 1];
|
|
12548
|
+
const idx = list2.indexOf(document.activeElement);
|
|
11696
12549
|
if (e.shiftKey) {
|
|
11697
12550
|
if (idx <= 0) {
|
|
11698
12551
|
e.preventDefault();
|
|
11699
12552
|
last.focus();
|
|
11700
12553
|
}
|
|
11701
|
-
} else if (idx === -1 || idx ===
|
|
12554
|
+
} else if (idx === -1 || idx === list2.length - 1) {
|
|
11702
12555
|
e.preventDefault();
|
|
11703
12556
|
first.focus();
|
|
11704
12557
|
}
|
|
@@ -11871,12 +12724,12 @@ function PayCard(props) {
|
|
|
11871
12724
|
const registryTokens = react.useMemo(() => catalogue?.tokens ?? [], [catalogue]);
|
|
11872
12725
|
const fundingTokens = react.useMemo(() => {
|
|
11873
12726
|
const seen = /* @__PURE__ */ new Set();
|
|
11874
|
-
const
|
|
12727
|
+
const list2 = [];
|
|
11875
12728
|
const push = (chainId, address, fallback) => {
|
|
11876
12729
|
const key2 = balanceKey(chainId, address);
|
|
11877
12730
|
if (seen.has(key2)) return;
|
|
11878
12731
|
seen.add(key2);
|
|
11879
|
-
|
|
12732
|
+
list2.push(registryTokens.find((t) => Number(t.chainId) === chainId && addrEq2(t.address, address)) ?? fallback);
|
|
11880
12733
|
};
|
|
11881
12734
|
for (const r of visibleRoutes) {
|
|
11882
12735
|
push(r.source.chainId, r.source.tokenAddress, {
|
|
@@ -11891,7 +12744,7 @@ function PayCard(props) {
|
|
|
11891
12744
|
for (const o of unquoted) {
|
|
11892
12745
|
push(o.chainId, o.address, { symbol: o.symbol, displaySymbol: o.ticker, name: o.name, chainId: o.chainId, address: o.address, decimals: o.decimals, logoUrl: o.logoUrl });
|
|
11893
12746
|
}
|
|
11894
|
-
return
|
|
12747
|
+
return list2;
|
|
11895
12748
|
}, [visibleRoutes, unquoted, registryTokens]);
|
|
11896
12749
|
const fundingChains = react.useMemo(() => {
|
|
11897
12750
|
const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
|
|
@@ -11997,7 +12850,7 @@ function PayCard(props) {
|
|
|
11997
12850
|
...durationLabel(sel.quote.estimatedDuration) ? [{ label: "Estimated time", value: durationLabel(sel.quote.estimatedDuration) }] : []
|
|
11998
12851
|
] : [];
|
|
11999
12852
|
const loadingPlan = flow.status === "loading" || holdings.loading && !sel || pricing !== null;
|
|
12000
|
-
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, onClose: props.onClose, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
12853
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, onClose: props.onClose, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, provider: wallet.provider, walletChainId: wallet.chainId, onConnect: wallet.connect, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
12001
12854
|
TokenSelect,
|
|
12002
12855
|
{
|
|
12003
12856
|
title: "Pay with",
|
|
@@ -12182,7 +13035,7 @@ function StableGenieSwap(props) {
|
|
|
12182
13035
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-brand", children: "ZeroDelta" })
|
|
12183
13036
|
] }) : void 0;
|
|
12184
13037
|
if (hist && wallet.account) {
|
|
12185
|
-
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory }) });
|
|
13038
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, provider: wallet.provider, walletChainId: wallet.chainId, onConnect: wallet.connect, tokens: registryTokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory }) });
|
|
12186
13039
|
}
|
|
12187
13040
|
if (recipientState.open) return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: /* @__PURE__ */ jsxRuntime.jsx(RecipientSheet, { state: recipientState, symbol: toAsset }) });
|
|
12188
13041
|
if (flow.status === "success" || flow.status === "pending") {
|
|
@@ -12472,16 +13325,16 @@ function Hint({ id, label: label2, text, hint }) {
|
|
|
12472
13325
|
open ? /* @__PURE__ */ jsxRuntime.jsx("span", { role: "tooltip", id: tipId, className: "sg-cd-tip", children: text }) : null
|
|
12473
13326
|
] });
|
|
12474
13327
|
}
|
|
12475
|
-
function CheckRow2({ check:
|
|
12476
|
-
const label2 =
|
|
12477
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "sg-cd-check", "data-ok":
|
|
13328
|
+
function CheckRow2({ check: check3, hideNote }) {
|
|
13329
|
+
const label2 = check3.id === "risk" ? check3.ok ? "Risk screening passed" : "Risk screening failed" : check3.label;
|
|
13330
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "sg-cd-check", "data-ok": check3.ok, children: [
|
|
12478
13331
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-cd-check-line", children: [
|
|
12479
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cd-check-mark", "data-ok":
|
|
13332
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cd-check-mark", "data-ok": check3.ok, children: check3.ok ? /* @__PURE__ */ jsxRuntime.jsx(Tick, { size: 12 }) : /* @__PURE__ */ jsxRuntime.jsx(Cross, { size: 12 }) }),
|
|
12480
13333
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cd-check-label", children: label2 }),
|
|
12481
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", children:
|
|
13334
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", children: check3.ok ? " \u2014 passed" : " \u2014 failed" })
|
|
12482
13335
|
] }),
|
|
12483
|
-
|
|
12484
|
-
|
|
13336
|
+
check3.note && !hideNote ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cd-check-note", children: check3.note }) : null,
|
|
13337
|
+
check3.reasons.map((reason) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cd-check-reason", children: humanizeComplianceReason(reason) }, reason))
|
|
12485
13338
|
] });
|
|
12486
13339
|
}
|
|
12487
13340
|
function Fact2({ label: label2, value, title, mono = false }) {
|
|
@@ -12516,10 +13369,10 @@ function QuoteChecks2(props) {
|
|
|
12516
13369
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-cd-summary-sub", children: "The gateway returned no compliance decision for this quote, so there is nothing to show. It is not a failed check." })
|
|
12517
13370
|
)
|
|
12518
13371
|
] }),
|
|
12519
|
-
checks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-cd-checks", children: checks.map((
|
|
13372
|
+
checks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-cd-checks", children: checks.map((check3) => (
|
|
12520
13373
|
// The Figma row carries no sub-line: with ONE screened wallet the note would repeat the
|
|
12521
13374
|
// address Quote details names two cards down. Any other note (a count of wallets) stays.
|
|
12522
|
-
/* @__PURE__ */ jsxRuntime.jsx(CheckRow2, { check:
|
|
13375
|
+
/* @__PURE__ */ jsxRuntime.jsx(CheckRow2, { check: check3, hideNote: check3.id === "screening" && wallets.length === 1 && hasDetails }, check3.id)
|
|
12523
13376
|
)) }) : null,
|
|
12524
13377
|
orphans.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-cd-orphans", children: orphans.map((reason) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: humanizeComplianceReason(reason) }, reason)) }) : null,
|
|
12525
13378
|
props.direct && checks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "sg-cd-scope", children: DIRECT_SCOPE_NOTE }) : null
|
|
@@ -12974,10 +13827,10 @@ function QuoteCard(props) {
|
|
|
12974
13827
|
const hops = option.hops;
|
|
12975
13828
|
const collapsed = side && hops.length > 3;
|
|
12976
13829
|
const inline = collapsed ? [hops[0], hops[1], "gap", hops[hops.length - 1]] : hops;
|
|
12977
|
-
const
|
|
13830
|
+
const hidden5 = collapsed ? hops.slice(2, -1) : [];
|
|
12978
13831
|
const routeIcons = /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-cq-route-icons", "data-testid": "compare-route-inline", children: inline.map((hop, i) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-cq-hop-inline", children: [
|
|
12979
13832
|
i > 0 ? /* @__PURE__ */ jsxRuntime.jsx(ArrowGlyph2, {}) : null,
|
|
12980
|
-
hop === "gap" ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-cq-gap", title:
|
|
13833
|
+
hop === "gap" ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-cq-gap", title: hidden5.map((h2) => `${h2.ticker} on ${props.chainName(h2.chainId)}`).join(" \u2192 "), "aria-label": `Also via ${hidden5.map((h2) => `${h2.ticker} on ${props.chainName(h2.chainId)}`).join(", ")}`, children: "\u2026" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { title: `${hop.ticker} on ${props.chainName(hop.chainId)}`, children: /* @__PURE__ */ jsxRuntime.jsx(HopMark, { hop, tokens: props.tokens, size: "xxs" }) })
|
|
12981
13834
|
] }, hop === "gap" ? "gap" : `${hop.chainId}-${hop.address}-${i}`)) });
|
|
12982
13835
|
const fee = compareFeeLabel(option.feeUsd);
|
|
12983
13836
|
const tagEl = tags.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { ref: tagRef, className: "sg-cq-tag", "data-kind": nettingTag ? "netting" : purple ? "purple" : "brand", children: tags.map((tag, i) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-cq-tag-item", children: [
|
|
@@ -13700,7 +14553,7 @@ function ExchangeCard(props) {
|
|
|
13700
14553
|
let body;
|
|
13701
14554
|
let takeover = false;
|
|
13702
14555
|
if (hist && connected2) {
|
|
13703
|
-
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, solanaAccount: solanaWallet.address, tokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
14556
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, engine, provider: wallet.provider, walletChainId: wallet.chainId, onConnect: wallet.connect, solanaAccount: solanaWallet.address, tokens, vaultIcons: catalogue?.vaultIcons, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
13704
14557
|
} else if (view === "from" || view === "to") {
|
|
13705
14558
|
const isFrom = view === "from";
|
|
13706
14559
|
body = /* @__PURE__ */ jsxRuntime.jsx(
|