@glacislabs/stablegenie-zerodelta 4.18.1 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{chunk-NXEWSGMY.js → chunk-NLXQVXZ5.js} +1513 -182
- package/dist/{chunk-MB7R66M7.js → chunk-NS444RZM.js} +130 -83
- package/dist/core/index.cjs +1547 -181
- package/dist/core/index.d.cts +26 -5
- package/dist/core/index.d.ts +26 -5
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +1598 -353
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/{mount-BdxMZC70.d.ts → mount-A24qHOI0.d.ts} +1 -1
- package/dist/{mount-BSXfSSP2.d.cts → mount-BsoZvwCl.d.cts} +1 -1
- package/dist/mount.cjs +1598 -353
- 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 +9 -9
- package/dist/{verify-BBREdvIM.d.cts → verify-BzTQQMc8.d.cts} +466 -2
- package/dist/{verify-BBREdvIM.d.ts → verify-BzTQQMc8.d.ts} +466 -2
- package/package.json +1 -1
|
@@ -197,7 +197,7 @@ var CHAIN_DISPLAY_NAMES = Object.freeze({
|
|
|
197
197
|
8453: "Base",
|
|
198
198
|
9745: "Plasma",
|
|
199
199
|
34443: "Mode",
|
|
200
|
-
42161: "Arbitrum
|
|
200
|
+
42161: "Arbitrum",
|
|
201
201
|
// "Avalanche", as the dApp prints it since zd-dapp#582 (from ZD Heavy's /chains). The widget's
|
|
202
202
|
// registry read lists no row for a payout-only chain, so this table is what names it here.
|
|
203
203
|
43114: "Avalanche",
|
|
@@ -273,8 +273,8 @@ var SOLANA_DESTINATION_ASSETS = Object.freeze({
|
|
|
273
273
|
AymATz4TCL9sWNEEV9Kvyz45CHVhDZ6kUgjTJPzLpU9P: pin("XAUT", 6, "layerzero", TOKEN_PROGRAM)
|
|
274
274
|
});
|
|
275
275
|
function solanaDestinationAsset(mint) {
|
|
276
|
-
const
|
|
277
|
-
return Object.prototype.hasOwnProperty.call(SOLANA_DESTINATION_ASSETS,
|
|
276
|
+
const key2 = typeof mint === "string" ? mint.trim() : "";
|
|
277
|
+
return Object.prototype.hasOwnProperty.call(SOLANA_DESTINATION_ASSETS, key2) ? SOLANA_DESTINATION_ASSETS[key2] : null;
|
|
278
278
|
}
|
|
279
279
|
function solanaBridgeOf(token) {
|
|
280
280
|
const pinned = solanaDestinationAsset(token.address);
|
|
@@ -648,9 +648,9 @@ function hexBytes(hex) {
|
|
|
648
648
|
if (h.length % 2 || !/^[a-fA-F0-9]*$/.test(h)) throw new Error("Invalid hex bytes.");
|
|
649
649
|
return Uint8Array.from(h.match(/../g) || [], (v) => Number.parseInt(v, 16));
|
|
650
650
|
}
|
|
651
|
-
function solanaKeyBytes(
|
|
652
|
-
if (!isSolanaAddress(
|
|
653
|
-
return base58Decode(
|
|
651
|
+
function solanaKeyBytes(key2) {
|
|
652
|
+
if (!isSolanaAddress(key2) || key2 !== key2.trim()) throw new Error("Invalid Solana public key.");
|
|
653
|
+
return base58Decode(key2);
|
|
654
654
|
}
|
|
655
655
|
var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
656
656
|
function base64Decode(text) {
|
|
@@ -1002,16 +1002,16 @@ function tokenTicker(token) {
|
|
|
1002
1002
|
}
|
|
1003
1003
|
function tickerOn(tokens, chainId, symbol) {
|
|
1004
1004
|
if (!symbol || !chainId || !tokens?.length) return symbol;
|
|
1005
|
-
const
|
|
1006
|
-
const deployment = tokens.find((t) => Number(t.chainId) === Number(chainId) && symbolKey(t.symbol) ===
|
|
1005
|
+
const key2 = symbolKey(symbol);
|
|
1006
|
+
const deployment = tokens.find((t) => Number(t.chainId) === Number(chainId) && symbolKey(t.symbol) === key2);
|
|
1007
1007
|
return deployment ? tokenTicker(deployment) : symbol;
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
1010
|
// src/core/availability.ts
|
|
1011
1011
|
function assetClassOf(symbol) {
|
|
1012
|
-
const
|
|
1013
|
-
if (TRADEABLE_RWA_ASSETS.has(
|
|
1014
|
-
if (STABLE_ASSETS.has(
|
|
1012
|
+
const key2 = symbolKey(symbol);
|
|
1013
|
+
if (TRADEABLE_RWA_ASSETS.has(key2)) return "rwa";
|
|
1014
|
+
if (STABLE_ASSETS.has(key2)) return "stable";
|
|
1015
1015
|
return null;
|
|
1016
1016
|
}
|
|
1017
1017
|
var NEST_VAULT_SHARES = /* @__PURE__ */ new Set(["NALPHA", "NTBILL", "NBASIS", "NCREDIT", "NOPAL", "NWISDOM", "NACRDX", "NLCRD", "NAXI", "NCLOA", "NFALCON"]);
|
|
@@ -1120,8 +1120,8 @@ function buildCatalogue(input) {
|
|
|
1120
1120
|
if (product === "rwa") return true;
|
|
1121
1121
|
if (execution.has(chainId) || token.isChainedDestination === true) return true;
|
|
1122
1122
|
if (!isExecutableBridge(token)) return false;
|
|
1123
|
-
const
|
|
1124
|
-
return source.has(
|
|
1123
|
+
const key2 = tokenKey(token.chainId, token.address);
|
|
1124
|
+
return source.has(key2) || destination.has(key2);
|
|
1125
1125
|
});
|
|
1126
1126
|
const ready = chains.length > 0 && routes.length > 0 && projectedCatalogue.length > 0;
|
|
1127
1127
|
const catalogue = ready ? projectedCatalogue : allowed;
|
|
@@ -1169,8 +1169,8 @@ function tokenEnabled(token) {
|
|
|
1169
1169
|
return token?.isEnabled !== false && isChainAddress(token?.chainId, token?.address) && Number.isFinite(Number(token?.chainId));
|
|
1170
1170
|
}
|
|
1171
1171
|
function findToken(tokens, chainId, symbol) {
|
|
1172
|
-
const
|
|
1173
|
-
return tokens.find((token) => tokenEnabled(token) && Number(token.chainId) === Number(chainId) && symbolKey(token.symbol) ===
|
|
1172
|
+
const key2 = symbolKey(symbol);
|
|
1173
|
+
return tokens.find((token) => tokenEnabled(token) && Number(token.chainId) === Number(chainId) && symbolKey(token.symbol) === key2) || null;
|
|
1174
1174
|
}
|
|
1175
1175
|
function buildPayOptions({ invoiceAsset, invoiceChainId, tokens, routes, chains, walletChainId, catalogue }) {
|
|
1176
1176
|
const invoiceKey = symbolKey(invoiceAsset);
|
|
@@ -1204,10 +1204,10 @@ function buildPayOptions({ invoiceAsset, invoiceChainId, tokens, routes, chains,
|
|
|
1204
1204
|
const chainId = Number(token.chainId);
|
|
1205
1205
|
const chain2 = chainById(chains, chainId);
|
|
1206
1206
|
if (!chainSelectable(chain2, chainId)) continue;
|
|
1207
|
-
const
|
|
1208
|
-
if (seen.has(
|
|
1207
|
+
const key2 = tokenKey(chainId, token.address);
|
|
1208
|
+
if (seen.has(key2)) continue;
|
|
1209
1209
|
if (refusal(token)) continue;
|
|
1210
|
-
seen.add(
|
|
1210
|
+
seen.add(key2);
|
|
1211
1211
|
const payKey = symbolKey(token.symbol);
|
|
1212
1212
|
const direct2 = chainId === invoiceChain && payKey === invoiceKey;
|
|
1213
1213
|
options.push({
|
|
@@ -1393,7 +1393,7 @@ function normalizePreview(request, quote, to, amount) {
|
|
|
1393
1393
|
async function quoteSolanaSource(api, input) {
|
|
1394
1394
|
const { from, to, amount } = selections(input, await api.fetchTokens());
|
|
1395
1395
|
const request = makeRequest(input, from, to, amount);
|
|
1396
|
-
const quote = await api.apiRequest("/quote", { method: "POST", body: JSON.stringify(request), timeoutMs: 18e3 });
|
|
1396
|
+
const quote = await api.apiRequest("/quote", { method: "POST", headers: { "X-ZD-Shape": "native" }, body: JSON.stringify(request), timeoutMs: 18e3 });
|
|
1397
1397
|
const preview = normalizePreview(request, quote, to, input.amountIn);
|
|
1398
1398
|
quoteRequests.set(preview, { api, request: clone(request) });
|
|
1399
1399
|
return preview;
|
|
@@ -1407,7 +1407,7 @@ async function previewSolanaSource(api, input) {
|
|
|
1407
1407
|
raw(amount, "input amount", true);
|
|
1408
1408
|
const body = { inputChain: SOLANA_CHAIN_ID, outputChain: input.toChainId, inputToken: from.symbol, outputToken: to.symbol, inputAmount: amount };
|
|
1409
1409
|
const request = body;
|
|
1410
|
-
const quote = await api.apiRequest("/quote", { method: "POST", body: JSON.stringify(request), timeoutMs: 18e3 });
|
|
1410
|
+
const quote = await api.apiRequest("/quote", { method: "POST", headers: { "X-ZD-Shape": "native" }, body: JSON.stringify(request), timeoutMs: 18e3 });
|
|
1411
1411
|
const option = quote?.options?.[0];
|
|
1412
1412
|
if (!option) throw new Error("Native quote returned no options.");
|
|
1413
1413
|
const receive = raw(option.finalAmount, "quoted output", true);
|
|
@@ -1755,12 +1755,64 @@ async function simulateSolanaCost(rpc, plan) {
|
|
|
1755
1755
|
}
|
|
1756
1756
|
|
|
1757
1757
|
// src/core/delivery.ts
|
|
1758
|
-
var FAILED = /* @__PURE__ */ new Set(["cancelled", "fill_failed", "delivery_failed", "
|
|
1759
|
-
var ATTENTION = /* @__PURE__ */ new Set(["cancel_pending", "awaiting_claim"]);
|
|
1758
|
+
var FAILED = /* @__PURE__ */ new Set(["cancelled", "fill_failed", "delivery_failed", "failed"]);
|
|
1759
|
+
var ATTENTION = /* @__PURE__ */ new Set(["cancel_pending", "awaiting_claim", "expired"]);
|
|
1760
1760
|
var TRACKING = Object.freeze({ phase: "tracking", status: "", steps: [] });
|
|
1761
1761
|
var word = (v) => typeof v === "string" ? v.trim().toLowerCase() : "";
|
|
1762
1762
|
var STEP_ORDER = { submitted: 0, arrived: 1, filled: 2, delivered: 3 };
|
|
1763
1763
|
var STATUS_REACHED = { in_progress: 1, outbound_bridging: 2, delivery_failed: 2, delivered: 3 };
|
|
1764
|
+
var ZDH_FIRST_STEP = 20;
|
|
1765
|
+
var ZDH_STEP = {
|
|
1766
|
+
paid_out: "delivered",
|
|
1767
|
+
cancelled: "cancellation_requested",
|
|
1768
|
+
refunded: "refunded"
|
|
1769
|
+
};
|
|
1770
|
+
var ROUTE_MECHANICS = /* @__PURE__ */ new Set(["consumed", "step_executed", "step_filled", "returned"]);
|
|
1771
|
+
var PROGRESS = /* @__PURE__ */ new Set(["pending", "in_progress", "outbound_bridging"]);
|
|
1772
|
+
var MAX_STEPS = 8;
|
|
1773
|
+
function isZdHeavy(r, steps) {
|
|
1774
|
+
return r.protocol === "zdheavy" || steps.some((s) => Number(s.stepNumber ?? 0) >= ZDH_FIRST_STEP);
|
|
1775
|
+
}
|
|
1776
|
+
function zdHeavyDelivery(own, rawSteps) {
|
|
1777
|
+
const named = rawSteps.filter((s) => s && typeof s === "object" && typeof s.stepName === "string");
|
|
1778
|
+
const lite = (name) => named.some((s) => Number(s.stepNumber ?? 0) < ZDH_FIRST_STEP && s.stepName === name && s.stepStatus === "completed");
|
|
1779
|
+
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);
|
|
1780
|
+
const has = (name) => events.some((e) => e.stepName === name);
|
|
1781
|
+
const cancelled = has("cancelled");
|
|
1782
|
+
const status = PROGRESS.has(own) && has("paid_out") && !cancelled ? "delivered" : own;
|
|
1783
|
+
const steps = [];
|
|
1784
|
+
const push = (name, done) => {
|
|
1785
|
+
const last = steps[steps.length - 1];
|
|
1786
|
+
if (last && last.name === name && last.done === done) return;
|
|
1787
|
+
steps.push({ name, done });
|
|
1788
|
+
};
|
|
1789
|
+
if (lite("submitted")) push("submitted", true);
|
|
1790
|
+
const terminal = cancelled || FAILED.has(status) || ATTENTION.has(status) || status === "delivered";
|
|
1791
|
+
if (!cancelled && !FAILED.has(status) && !ATTENTION.has(status)) {
|
|
1792
|
+
if (status === "delivered") {
|
|
1793
|
+
push("route_completed", true);
|
|
1794
|
+
} else {
|
|
1795
|
+
push("route", false);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
for (const e of events) {
|
|
1799
|
+
const name = String(e.stepName);
|
|
1800
|
+
if (ROUTE_MECHANICS.has(name)) continue;
|
|
1801
|
+
if (name === "refund_parked") {
|
|
1802
|
+
push(e.stepStatus === "recovered" ? "claimed" : "ready_to_claim", e.stepStatus === "recovered");
|
|
1803
|
+
continue;
|
|
1804
|
+
}
|
|
1805
|
+
push(ZDH_STEP[name] ?? name.slice(0, 32), true);
|
|
1806
|
+
}
|
|
1807
|
+
if (!terminal) push("delivered", false);
|
|
1808
|
+
const capped = steps.length > MAX_STEPS ? [...steps.slice(0, MAX_STEPS - 1), steps[steps.length - 1]] : steps;
|
|
1809
|
+
const refunded = cancelled && has("refunded");
|
|
1810
|
+
if (!status) return TRACKING;
|
|
1811
|
+
if (FAILED.has(status)) return { phase: "failed", status, steps: capped, ...refunded ? { refunded } : {} };
|
|
1812
|
+
if (ATTENTION.has(status)) return { phase: "attention", status, steps: capped };
|
|
1813
|
+
if (status === "delivered") return { phase: "delivered", status, steps: capped };
|
|
1814
|
+
return { phase: "in-progress", status, steps: capped };
|
|
1815
|
+
}
|
|
1764
1816
|
function normalizeDelivery(raw2) {
|
|
1765
1817
|
const row = raw2 && typeof raw2 === "object" && !Array.isArray(raw2) ? raw2.data ?? raw2 : null;
|
|
1766
1818
|
if (!row || typeof row !== "object" || Array.isArray(row)) return TRACKING;
|
|
@@ -1770,6 +1822,7 @@ function normalizeDelivery(raw2) {
|
|
|
1770
1822
|
const own = word(r.status);
|
|
1771
1823
|
const status = journey || own;
|
|
1772
1824
|
const rawSteps = Array.isArray(r.steps) ? r.steps : [];
|
|
1825
|
+
if (isZdHeavy(r, rawSteps) && !chained) return zdHeavyDelivery(own, rawSteps);
|
|
1773
1826
|
const listed = rawSteps.filter((s) => s && typeof s === "object" && typeof s.stepName === "string").sort((a, b) => Number(a.stepNumber ?? 0) - Number(b.stepNumber ?? 0)).slice(0, 8).map((s) => ({ name: String(s.stepName).slice(0, 32), done: s.stepStatus === "completed" }));
|
|
1774
1827
|
const reached = Math.max(STATUS_REACHED[own] ?? -1, ...listed.filter((s) => s.done).map((s) => STEP_ORDER[s.name] ?? -1));
|
|
1775
1828
|
const steps = listed.map((s) => (STEP_ORDER[s.name] ?? Infinity) <= reached ? { ...s, done: true } : s);
|
|
@@ -1806,8 +1859,8 @@ function historyKey(value) {
|
|
|
1806
1859
|
var str = (v) => typeof v === "string" ? v : typeof v === "number" ? String(v) : "";
|
|
1807
1860
|
function tokenAt(tokens, chainId, address) {
|
|
1808
1861
|
if (!address) return void 0;
|
|
1809
|
-
const
|
|
1810
|
-
return tokens.find((t) => Number(t.chainId) === chainId && historyKey(String(t.address)) ===
|
|
1862
|
+
const key2 = historyKey(address);
|
|
1863
|
+
return tokens.find((t) => Number(t.chainId) === chainId && historyKey(String(t.address)) === key2);
|
|
1811
1864
|
}
|
|
1812
1865
|
function amountOf(raw2, token, rowDecimals, rowAmount) {
|
|
1813
1866
|
const decimals = token ? Number(token.decimals) : Number(rowDecimals);
|
|
@@ -1893,13 +1946,13 @@ function mergeHistory(local, remote, limit = WALLET_HISTORY_LIMIT) {
|
|
|
1893
1946
|
const out = [];
|
|
1894
1947
|
const seen = /* @__PURE__ */ new Set();
|
|
1895
1948
|
for (const entry of local) {
|
|
1896
|
-
const
|
|
1897
|
-
if (seen.has(
|
|
1898
|
-
seen.add(
|
|
1899
|
-
const known = byHash.get(
|
|
1949
|
+
const key2 = historyKey(entry.hash);
|
|
1950
|
+
if (seen.has(key2)) continue;
|
|
1951
|
+
seen.add(key2);
|
|
1952
|
+
const known = byHash.get(key2);
|
|
1900
1953
|
out.push(known ? { ...entry, delivery: known.delivery, legs: entry.legs ?? known.legs } : entry);
|
|
1901
1954
|
}
|
|
1902
|
-
for (const [
|
|
1955
|
+
for (const [key2, entry] of byHash) if (!seen.has(key2)) out.push(entry);
|
|
1903
1956
|
return out.sort((a, b) => Date.parse(b.at) - Date.parse(a.at)).slice(0, limit);
|
|
1904
1957
|
}
|
|
1905
1958
|
|
|
@@ -2010,12 +2063,12 @@ function suppressedLanes(health) {
|
|
|
2010
2063
|
const out = /* @__PURE__ */ new Map();
|
|
2011
2064
|
for (const lane of health.lanes) {
|
|
2012
2065
|
if (!lane || typeof lane !== "object" || !isSuppressed(lane)) continue;
|
|
2013
|
-
const
|
|
2014
|
-
if (!
|
|
2066
|
+
const key2 = healthLaneKey(lane.laneKey);
|
|
2067
|
+
if (!key2) continue;
|
|
2015
2068
|
const availability = laneAvailabilityState(lane) ? lane.availability : void 0;
|
|
2016
2069
|
const code = typeof availability?.code === "string" && availability.code ? availability.code : lane.code;
|
|
2017
2070
|
const message = typeof availability?.message === "string" && availability.message ? availability.message : lane.message;
|
|
2018
|
-
out.set(
|
|
2071
|
+
out.set(key2, {
|
|
2019
2072
|
route: typeof lane.route === "string" ? lane.route : "",
|
|
2020
2073
|
code: typeof code === "string" ? code : "",
|
|
2021
2074
|
message: typeof message === "string" ? message : "",
|
|
@@ -2030,15 +2083,15 @@ function limitedLanes(health) {
|
|
|
2030
2083
|
const out = /* @__PURE__ */ new Map();
|
|
2031
2084
|
for (const lane of health.lanes) {
|
|
2032
2085
|
if (!lane || typeof lane !== "object" || laneAvailabilityState(lane) !== "limited") continue;
|
|
2033
|
-
const
|
|
2086
|
+
const key2 = healthLaneKey(lane.laneKey);
|
|
2034
2087
|
const limit = lane.availability?.limit;
|
|
2035
|
-
if (!
|
|
2088
|
+
if (!key2 || !limit || typeof limit !== "object") continue;
|
|
2036
2089
|
const side = limit.side === "bid" || limit.side === "ask" ? limit.side : null;
|
|
2037
2090
|
const maxAmount = typeof limit.maxAmount === "string" ? limit.maxAmount.trim() : "";
|
|
2038
2091
|
const decimals = limit.decimals;
|
|
2039
2092
|
if (!side || !BASE_UNITS.test(maxAmount) || typeof decimals !== "number" || !Number.isInteger(decimals) || decimals < 0 || decimals > 36) continue;
|
|
2040
2093
|
const code = lane.availability?.code;
|
|
2041
|
-
out.set(
|
|
2094
|
+
out.set(key2, {
|
|
2042
2095
|
side,
|
|
2043
2096
|
token: typeof limit.token === "string" ? limit.token : "",
|
|
2044
2097
|
fromChainId: Number(limit.fromChainId) || 0,
|
|
@@ -2101,10 +2154,10 @@ function resolveVaultIcon(apiBase, iconPath) {
|
|
|
2101
2154
|
function vaultIconsBySymbol(apiBase, vaults) {
|
|
2102
2155
|
const out = /* @__PURE__ */ new Map();
|
|
2103
2156
|
for (const vault of vaults) {
|
|
2104
|
-
const
|
|
2105
|
-
if (!
|
|
2157
|
+
const key2 = symbolKey(vault?.symbol);
|
|
2158
|
+
if (!key2 || out.has(key2)) continue;
|
|
2106
2159
|
const url = resolveVaultIcon(apiBase, vault?.iconMiniUrl) ?? resolveVaultIcon(apiBase, vault?.iconUrl);
|
|
2107
|
-
if (url) out.set(
|
|
2160
|
+
if (url) out.set(key2, url);
|
|
2108
2161
|
}
|
|
2109
2162
|
return out;
|
|
2110
2163
|
}
|
|
@@ -2201,7 +2254,7 @@ var CATEGORY_PHRASES = {
|
|
|
2201
2254
|
UNKNOWN: "an unrecognized risk"
|
|
2202
2255
|
};
|
|
2203
2256
|
function categoryLabel(code) {
|
|
2204
|
-
const
|
|
2257
|
+
const key2 = code.trim().toUpperCase();
|
|
2205
2258
|
const LABELS = {
|
|
2206
2259
|
SANCTIONS: "Sanctions",
|
|
2207
2260
|
TERRORISM_FINANCING: "Terrorist financing",
|
|
@@ -2216,7 +2269,7 @@ function categoryLabel(code) {
|
|
|
2216
2269
|
UNCLASSIFIED: "Unclassified risk",
|
|
2217
2270
|
UNKNOWN: "Unclassified risk"
|
|
2218
2271
|
};
|
|
2219
|
-
return LABELS[
|
|
2272
|
+
return LABELS[key2] ?? key2.toLowerCase().replace(/_/g, " ");
|
|
2220
2273
|
}
|
|
2221
2274
|
function cleanJurisdiction(code) {
|
|
2222
2275
|
return code.replace(/^(OFAC|TIER\d+|SANCTIONED)_/i, "").trim();
|
|
@@ -2329,9 +2382,9 @@ function distinctScreenedWallets(compliance) {
|
|
|
2329
2382
|
for (const raw2 of compliance?.screenedWallets ?? []) {
|
|
2330
2383
|
const address = raw2?.trim();
|
|
2331
2384
|
if (!address) continue;
|
|
2332
|
-
const
|
|
2333
|
-
if (seen.has(
|
|
2334
|
-
seen.add(
|
|
2385
|
+
const key2 = /^0x[0-9a-fA-F]+$/.test(address) ? address.toLowerCase() : address;
|
|
2386
|
+
if (seen.has(key2)) continue;
|
|
2387
|
+
seen.add(key2);
|
|
2335
2388
|
wallets.push(address);
|
|
2336
2389
|
}
|
|
2337
2390
|
return wallets;
|
|
@@ -2458,9 +2511,9 @@ var TUNED_OUTCOMES = {
|
|
|
2458
2511
|
UNCLASSIFIED: "flagged"
|
|
2459
2512
|
};
|
|
2460
2513
|
function screeningOutcomeOf(category) {
|
|
2461
|
-
const
|
|
2462
|
-
if (FLOOR_CATEGORIES.includes(
|
|
2463
|
-
return TUNED_OUTCOMES[
|
|
2514
|
+
const key2 = category.trim().toUpperCase();
|
|
2515
|
+
if (FLOOR_CATEGORIES.includes(key2)) return "always-blocked";
|
|
2516
|
+
return TUNED_OUTCOMES[key2] ?? null;
|
|
2464
2517
|
}
|
|
2465
2518
|
var labelsFor = (outcome) => [...FLOOR_CATEGORIES, ...TUNABLE_CATEGORIES].filter((c) => screeningOutcomeOf(c) === outcome).map(categoryLabel);
|
|
2466
2519
|
var SCREENING_BUCKETS = [
|
|
@@ -2469,6 +2522,91 @@ var SCREENING_BUCKETS = [
|
|
|
2469
2522
|
{ outcome: "flagged", title: "Flagged", detail: "A warning is shown.", categories: labelsFor("flagged") }
|
|
2470
2523
|
];
|
|
2471
2524
|
|
|
2525
|
+
// src/core/zdheavy-routers.ts
|
|
2526
|
+
var ZDHEAVY_ROUTER_TEST05 = "0x94c5cC7f4689AD7B0Abd0975F4C8E159e4633251";
|
|
2527
|
+
var ZDHEAVY_ROUTER_TEST04 = "0x72EA420DCE5BE939062E527b49388479d7171379";
|
|
2528
|
+
var ZDHEAVY_ROUTER_DEV = "0xD813690937324417cFBE12E742dD53054F90dF04";
|
|
2529
|
+
var ZDHEAVY_ROUTER_DEV_V6 = "0xa6155b1505378e6C9871483c55375dcBBB16f897";
|
|
2530
|
+
var ZDHEAVY_ROUTER_PROD = "0x7D50305f2855Bf2225FE51E15858b4BA0C0844e1";
|
|
2531
|
+
var ZDHEAVY_DEV_CHAINS = [1, 10, 56, 130, 137, 143, 146, 1329, 1672, 4663, 5e3, 8453, 9745, 42161, 43114, 57073, 98866];
|
|
2532
|
+
var ZDHEAVY_SANDBOX_CHAINS = [8453, 9745, 42161];
|
|
2533
|
+
var ZDHEAVY_ROUTER_ADDRESSES = Object.fromEntries(
|
|
2534
|
+
ZDHEAVY_DEV_CHAINS.map((id) => [
|
|
2535
|
+
id,
|
|
2536
|
+
ZDHEAVY_SANDBOX_CHAINS.includes(id) ? [ZDHEAVY_ROUTER_TEST05, ZDHEAVY_ROUTER_TEST04, ZDHEAVY_ROUTER_DEV, ZDHEAVY_ROUTER_DEV_V6, ZDHEAVY_ROUTER_PROD] : [ZDHEAVY_ROUTER_DEV, ZDHEAVY_ROUTER_DEV_V6, ZDHEAVY_ROUTER_PROD]
|
|
2537
|
+
])
|
|
2538
|
+
);
|
|
2539
|
+
function zdHeavyRouterPinned(chainId, router) {
|
|
2540
|
+
if (typeof router !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(router)) return false;
|
|
2541
|
+
const want = router.toLowerCase();
|
|
2542
|
+
return (ZDHEAVY_ROUTER_ADDRESSES[chainId] ?? []).some((a) => a.toLowerCase() === want);
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
// src/core/quote-option.ts
|
|
2546
|
+
function zdHeavyExecutable(q) {
|
|
2547
|
+
const order = q.execution?.order;
|
|
2548
|
+
const chainId = typeof q.fromChainId === "number" ? q.fromChainId : Number(order?.chainNumber);
|
|
2549
|
+
return q.protocol === "zdheavy" && q.payloadStatus === "resolved-offchain-signed" && !!order && !!q.rootHash && Array.isArray(q.txData) && q.txData.some((tx) => (tx.actionType === "submit" || tx.actionType === "submitOrder") && typeof tx.to === "string" && typeof tx.data === "string") && zdHeavyRouterPinned(chainId, order.router);
|
|
2550
|
+
}
|
|
2551
|
+
function liteExecutable(q) {
|
|
2552
|
+
return q.protocol !== "zdheavy" && Array.isArray(q.orderRequests) && q.orderRequests.length > 0;
|
|
2553
|
+
}
|
|
2554
|
+
function selectQuoteOption(quote) {
|
|
2555
|
+
if (!Array.isArray(quote.options)) return quote;
|
|
2556
|
+
const option = quote.options.find(zdHeavyExecutable) ?? quote.options.find((q) => q.protocol !== "zdheavy" && !!q.orderRequests?.length);
|
|
2557
|
+
if (!option) throw new Error("ZeroDelta quote has no executable option.");
|
|
2558
|
+
const gatewayOptions = [];
|
|
2559
|
+
let gatewayOptionIndex = -1;
|
|
2560
|
+
for (const o of quote.options) {
|
|
2561
|
+
if (!o || typeof o !== "object" || Array.isArray(o)) continue;
|
|
2562
|
+
if (o === option) gatewayOptionIndex = gatewayOptions.length;
|
|
2563
|
+
gatewayOptions.push(projectOption(quote, o));
|
|
2564
|
+
}
|
|
2565
|
+
return { ...projectOption(quote, option), gatewayOptions, gatewayOptionIndex };
|
|
2566
|
+
}
|
|
2567
|
+
function projectOption(quote, option) {
|
|
2568
|
+
const { fromChainId, toChainId, fromToken, toToken: toToken2, fromAmount } = quote;
|
|
2569
|
+
const last = option.orderRequests?.[option.orderRequests.length - 1];
|
|
2570
|
+
const { entersNetting, gasSponsored, gatewayOptions: _g, gatewayOptionIndex: _i, ...rest } = option;
|
|
2571
|
+
return {
|
|
2572
|
+
...rest,
|
|
2573
|
+
...entersNetting === true ? { entersNetting: true } : {},
|
|
2574
|
+
...gasSponsored === true ? { gasSponsored: true } : {},
|
|
2575
|
+
fromChainId,
|
|
2576
|
+
toChainId,
|
|
2577
|
+
fromToken,
|
|
2578
|
+
toToken: toToken2,
|
|
2579
|
+
fromAmount,
|
|
2580
|
+
quoteId: quote.quoteId,
|
|
2581
|
+
toAmount: String(last?.askTokenAmount ?? option.outputAmount ?? option.toAmount ?? ""),
|
|
2582
|
+
finalAmount: String(option.finalAmount || last?.askTokenAmount || option.outputAmount || ""),
|
|
2583
|
+
compliance: complianceDecision(quote),
|
|
2584
|
+
estimatedDuration: option.estimatedTimeSec ?? option.estimatedDuration
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
function complianceDecision(quote) {
|
|
2588
|
+
const decision = quote.complianceDecision ?? quote.compliance;
|
|
2589
|
+
return decision && typeof decision === "object" && !Array.isArray(decision) ? decision : void 0;
|
|
2590
|
+
}
|
|
2591
|
+
function normalizeQuoteResponse(response, request) {
|
|
2592
|
+
const quote = Array.isArray(response?.options) ? selectQuoteOption({
|
|
2593
|
+
...response,
|
|
2594
|
+
fromChainId: request.inputChain,
|
|
2595
|
+
toChainId: request.outputChain,
|
|
2596
|
+
fromToken: request.inputToken,
|
|
2597
|
+
toToken: request.outputToken,
|
|
2598
|
+
fromAmount: request.inputAmount
|
|
2599
|
+
}) : response;
|
|
2600
|
+
if (quote?.gatewayOptions) quote.gatewayOptions = quote.gatewayOptions.map(numericExecutionChain);
|
|
2601
|
+
return numericExecutionChain(quote);
|
|
2602
|
+
}
|
|
2603
|
+
function numericExecutionChain(quote) {
|
|
2604
|
+
return quote && quote.executionChainId != null ? { ...quote, executionChainId: Number(quote.executionChainId) } : quote;
|
|
2605
|
+
}
|
|
2606
|
+
function deliveredAmount(quote, solanaDestination) {
|
|
2607
|
+
return BigInt(quote.protocol === "zdheavy" || solanaDestination ? quote.finalAmount || quote.toAmount || "0" : quote.toAmount || "0");
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2472
2610
|
// src/core/solve.ts
|
|
2473
2611
|
async function solveExactOut({ option, destination, destinationToken, payer, fetchQuote }) {
|
|
2474
2612
|
const destDecimals = assetDecimals(destinationToken);
|
|
@@ -2515,7 +2653,7 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
|
|
|
2515
2653
|
let bestGuess = guess;
|
|
2516
2654
|
for (let i = 0; i < 3; i += 1) {
|
|
2517
2655
|
const guessSent = guess;
|
|
2518
|
-
const quote = await fetchQuote({
|
|
2656
|
+
const quote = selectQuoteOption(await fetchQuote({
|
|
2519
2657
|
fromChainId: option.chainId,
|
|
2520
2658
|
toChainId: Number(destination.chainId),
|
|
2521
2659
|
fromToken: option.symbol,
|
|
@@ -2523,11 +2661,11 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
|
|
|
2523
2661
|
fromAmount: guessSent.toString(),
|
|
2524
2662
|
owner: payer,
|
|
2525
2663
|
destinationReceiver: destination.address
|
|
2526
|
-
});
|
|
2664
|
+
}));
|
|
2527
2665
|
if (BigInt(quote?.fromAmount || "0") !== guessSent) {
|
|
2528
2666
|
throw new Error("ZeroDelta echoed a different input amount than requested.");
|
|
2529
2667
|
}
|
|
2530
|
-
const guaranteed = isSolanaChainId(destination.chainId)
|
|
2668
|
+
const guaranteed = deliveredAmount(quote, isSolanaChainId(destination.chainId));
|
|
2531
2669
|
const final = finalOf(quote);
|
|
2532
2670
|
if (final > bestFinal) {
|
|
2533
2671
|
bestFinal = final;
|
|
@@ -2564,7 +2702,7 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
|
|
|
2564
2702
|
directTransfer: false,
|
|
2565
2703
|
quote: best,
|
|
2566
2704
|
youPayRaw: bestGuess.toString(),
|
|
2567
|
-
recipientReceivesRaw: (isSolanaChainId(destination.chainId)
|
|
2705
|
+
recipientReceivesRaw: deliveredAmount(best, isSolanaChainId(destination.chainId)).toString(),
|
|
2568
2706
|
targetRaw: targetRaw.toString(),
|
|
2569
2707
|
overageBps: targetRaw > 0n ? Number((bestFinal - targetRaw) * 10000n / targetRaw) : 0,
|
|
2570
2708
|
meetsTarget: bestFinal >= targetRaw,
|
|
@@ -2574,7 +2712,7 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
|
|
|
2574
2712
|
async function solveExactIn({ option, destination, destinationToken, payer, fetchQuote, amountInRaw }) {
|
|
2575
2713
|
const fromRaw = BigInt(amountInRaw || "0");
|
|
2576
2714
|
if (fromRaw <= 0n) throw new Error("Swap amount must be greater than zero.");
|
|
2577
|
-
const quote = await fetchQuote({
|
|
2715
|
+
const quote = selectQuoteOption(await fetchQuote({
|
|
2578
2716
|
fromChainId: option.chainId,
|
|
2579
2717
|
toChainId: Number(destination.chainId),
|
|
2580
2718
|
fromToken: option.symbol,
|
|
@@ -2582,11 +2720,11 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
|
|
|
2582
2720
|
fromAmount: fromRaw.toString(),
|
|
2583
2721
|
owner: payer,
|
|
2584
2722
|
destinationReceiver: destination.address
|
|
2585
|
-
});
|
|
2723
|
+
}));
|
|
2586
2724
|
if (BigInt(quote?.fromAmount || "0") !== fromRaw) {
|
|
2587
2725
|
throw new Error("ZeroDelta echoed a different input amount than requested.");
|
|
2588
2726
|
}
|
|
2589
|
-
const guaranteed = isSolanaChainId(destination.chainId)
|
|
2727
|
+
const guaranteed = deliveredAmount(quote, isSolanaChainId(destination.chainId));
|
|
2590
2728
|
if (guaranteed <= 0n) throw new Error("ZeroDelta could not price this swap.");
|
|
2591
2729
|
return {
|
|
2592
2730
|
directTransfer: false,
|
|
@@ -2599,6 +2737,24 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
|
|
|
2599
2737
|
iterations: 1
|
|
2600
2738
|
};
|
|
2601
2739
|
}
|
|
2740
|
+
function resultForOption(result, option, mode, destinationChainId) {
|
|
2741
|
+
if (result.directTransfer) throw new Error("A direct transfer has no other option.");
|
|
2742
|
+
if (BigInt(option.fromAmount || "0") !== BigInt(result.youPayRaw)) throw new Error("ZeroDelta echoed a different input amount than requested.");
|
|
2743
|
+
const guaranteed = deliveredAmount(option, isSolanaChainId(destinationChainId));
|
|
2744
|
+
if (mode === "exact-in") {
|
|
2745
|
+
if (guaranteed <= 0n) throw new Error("ZeroDelta could not price this swap.");
|
|
2746
|
+
return { ...result, quote: option, recipientReceivesRaw: guaranteed.toString(), targetRaw: guaranteed.toString(), overageBps: 0, meetsTarget: true };
|
|
2747
|
+
}
|
|
2748
|
+
const targetRaw = BigInt(result.targetRaw);
|
|
2749
|
+
const final = finalOf(option);
|
|
2750
|
+
return {
|
|
2751
|
+
...result,
|
|
2752
|
+
quote: option,
|
|
2753
|
+
recipientReceivesRaw: guaranteed.toString(),
|
|
2754
|
+
overageBps: targetRaw > 0n ? Number((final - targetRaw) * 10000n / targetRaw) : 0,
|
|
2755
|
+
meetsTarget: final >= targetRaw
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2602
2758
|
|
|
2603
2759
|
// src/core/order.ts
|
|
2604
2760
|
var DEFAULT_DEADLINE_SECONDS = 1800;
|
|
@@ -2718,6 +2874,1020 @@ function assertQuoteMatchesSelection({ quote, order, orders, option, destination
|
|
|
2718
2874
|
}
|
|
2719
2875
|
}
|
|
2720
2876
|
|
|
2877
|
+
// src/core/checksum.ts
|
|
2878
|
+
var RC = [
|
|
2879
|
+
0x0000000000000001n,
|
|
2880
|
+
0x0000000000008082n,
|
|
2881
|
+
0x800000000000808an,
|
|
2882
|
+
0x8000000080008000n,
|
|
2883
|
+
0x000000000000808bn,
|
|
2884
|
+
0x0000000080000001n,
|
|
2885
|
+
0x8000000080008081n,
|
|
2886
|
+
0x8000000000008009n,
|
|
2887
|
+
0x000000000000008an,
|
|
2888
|
+
0x0000000000000088n,
|
|
2889
|
+
0x0000000080008009n,
|
|
2890
|
+
0x000000008000000an,
|
|
2891
|
+
0x000000008000808bn,
|
|
2892
|
+
0x800000000000008bn,
|
|
2893
|
+
0x8000000000008089n,
|
|
2894
|
+
0x8000000000008003n,
|
|
2895
|
+
0x8000000000008002n,
|
|
2896
|
+
0x8000000000000080n,
|
|
2897
|
+
0x000000000000800an,
|
|
2898
|
+
0x800000008000000an,
|
|
2899
|
+
0x8000000080008081n,
|
|
2900
|
+
0x8000000000008080n,
|
|
2901
|
+
0x0000000080000001n,
|
|
2902
|
+
0x8000000080008008n
|
|
2903
|
+
];
|
|
2904
|
+
var ROT = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14];
|
|
2905
|
+
var MASK = (1n << 64n) - 1n;
|
|
2906
|
+
var rotl = (x, n) => n === 0 ? x : (x << BigInt(n) | x >> BigInt(64 - n)) & MASK;
|
|
2907
|
+
function keccakF(s) {
|
|
2908
|
+
for (let round = 0; round < 24; round++) {
|
|
2909
|
+
const c = [0, 1, 2, 3, 4].map((x) => s[x] ^ s[x + 5] ^ s[x + 10] ^ s[x + 15] ^ s[x + 20]);
|
|
2910
|
+
for (let x = 0; x < 5; x++) {
|
|
2911
|
+
const d = c[(x + 4) % 5] ^ rotl(c[(x + 1) % 5], 1);
|
|
2912
|
+
for (let y = 0; y < 25; y += 5) s[y + x] = s[y + x] ^ d;
|
|
2913
|
+
}
|
|
2914
|
+
const b = new Array(25);
|
|
2915
|
+
for (let x = 0; x < 5; x++) for (let y = 0; y < 5; y++) b[y + 5 * ((2 * x + 3 * y) % 5)] = rotl(s[x + 5 * y], ROT[x + 5 * y]);
|
|
2916
|
+
for (let x = 0; x < 5; x++) for (let y = 0; y < 25; y += 5) s[y + x] = b[y + x] ^ ~b[y + (x + 1) % 5] & MASK & b[y + (x + 2) % 5];
|
|
2917
|
+
s[0] = s[0] ^ RC[round];
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
function keccak256Hex(bytes) {
|
|
2921
|
+
const rate = 136;
|
|
2922
|
+
const padded = new Uint8Array(Math.ceil((bytes.length + 1) / rate) * rate);
|
|
2923
|
+
padded.set(bytes);
|
|
2924
|
+
padded[bytes.length] = padded[bytes.length] ^ 1;
|
|
2925
|
+
padded[padded.length - 1] = padded[padded.length - 1] ^ 128;
|
|
2926
|
+
const s = new Array(25).fill(0n);
|
|
2927
|
+
for (let off = 0; off < padded.length; off += rate) {
|
|
2928
|
+
for (let i = 0; i < rate / 8; i++) {
|
|
2929
|
+
let lane = 0n;
|
|
2930
|
+
for (let j = 7; j >= 0; j--) lane = lane << 8n | BigInt(padded[off + i * 8 + j]);
|
|
2931
|
+
s[i] = s[i] ^ lane;
|
|
2932
|
+
}
|
|
2933
|
+
keccakF(s);
|
|
2934
|
+
}
|
|
2935
|
+
let out = "";
|
|
2936
|
+
for (let i = 0; i < 4; i++) for (let j = 0; j < 8; j++) out += Number(s[i] >> BigInt(8 * j) & 0xffn).toString(16).padStart(2, "0");
|
|
2937
|
+
return out;
|
|
2938
|
+
}
|
|
2939
|
+
function toChecksumAddress(address) {
|
|
2940
|
+
const lower3 = address.slice(2).toLowerCase();
|
|
2941
|
+
const hash = keccak256Hex(new TextEncoder().encode(lower3));
|
|
2942
|
+
let out = "0x";
|
|
2943
|
+
for (let i = 0; i < 40; i++) out += Number.parseInt(hash[i], 16) >= 8 ? lower3[i].toUpperCase() : lower3[i];
|
|
2944
|
+
return out;
|
|
2945
|
+
}
|
|
2946
|
+
function hasValidChecksum(address) {
|
|
2947
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) return false;
|
|
2948
|
+
const body = address.slice(2);
|
|
2949
|
+
if (body === body.toLowerCase() || body === body.toUpperCase()) return true;
|
|
2950
|
+
return toChecksumAddress(address) === address;
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
// src/core/zdheavy-codec.ts
|
|
2954
|
+
var concat = (parts) => "0x" + parts.map((p) => p.slice(2)).join("");
|
|
2955
|
+
var hexToBytes = (h) => Uint8Array.from(h.slice(2).match(/../g) ?? [], (b) => Number.parseInt(b, 16));
|
|
2956
|
+
var toBytes = (s) => new TextEncoder().encode(s);
|
|
2957
|
+
var toHex = (v, opts) => "0x" + (typeof v === "bigint" ? v.toString(16).padStart((opts?.size ?? 0) * 2, "0") : Array.from(v, (b) => b.toString(16).padStart(2, "0")).join(""));
|
|
2958
|
+
var keccak256 = (h) => "0x" + keccak256Hex(hexToBytes(h));
|
|
2959
|
+
var STEP_VERSION = 5;
|
|
2960
|
+
var MAX_STEPS2 = 8;
|
|
2961
|
+
var StepKind = {
|
|
2962
|
+
LOCAL_PAYOUT: 1,
|
|
2963
|
+
REMOTE_PAYOUT: 2,
|
|
2964
|
+
SEND: 3,
|
|
2965
|
+
SWAP: 4,
|
|
2966
|
+
EXECUTE: 5,
|
|
2967
|
+
NET: 6,
|
|
2968
|
+
SUBSIDY: 7
|
|
2969
|
+
};
|
|
2970
|
+
var ZdHeavyCodecError = class extends Error {
|
|
2971
|
+
constructor(message) {
|
|
2972
|
+
super(message);
|
|
2973
|
+
this.name = "ZdHeavyCodecError";
|
|
2974
|
+
}
|
|
2975
|
+
};
|
|
2976
|
+
function checkedHex(value, length) {
|
|
2977
|
+
if (typeof value !== "string" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(value) || length !== void 0 && value.length !== 2 + length * 2) {
|
|
2978
|
+
throw new ZdHeavyCodecError(`Expected ${length === void 0 ? "byte-aligned" : length + "-byte"} hex`);
|
|
2979
|
+
}
|
|
2980
|
+
return value.toLowerCase();
|
|
2981
|
+
}
|
|
2982
|
+
function uint(value, bytes) {
|
|
2983
|
+
if (typeof value !== "bigint" || value < 0n || value >= 1n << BigInt(bytes * 8)) {
|
|
2984
|
+
throw new ZdHeavyCodecError(`Value outside uint${bytes * 8}`);
|
|
2985
|
+
}
|
|
2986
|
+
return toHex(value, { size: bytes });
|
|
2987
|
+
}
|
|
2988
|
+
var Reader2 = class {
|
|
2989
|
+
bytes;
|
|
2990
|
+
offset = 0;
|
|
2991
|
+
constructor(step) {
|
|
2992
|
+
this.bytes = hexToBytes(checkedHex(step));
|
|
2993
|
+
}
|
|
2994
|
+
take(n) {
|
|
2995
|
+
if (this.offset + n > this.bytes.length) throw new ZdHeavyCodecError("Short step");
|
|
2996
|
+
const result = this.bytes.slice(this.offset, this.offset + n);
|
|
2997
|
+
this.offset += n;
|
|
2998
|
+
return result;
|
|
2999
|
+
}
|
|
3000
|
+
hex(n) {
|
|
3001
|
+
return toHex(this.take(n));
|
|
3002
|
+
}
|
|
3003
|
+
uint(n) {
|
|
3004
|
+
let result = 0n;
|
|
3005
|
+
for (const byte of this.take(n)) result = result << 8n | BigInt(byte);
|
|
3006
|
+
return result;
|
|
3007
|
+
}
|
|
3008
|
+
number(n) {
|
|
3009
|
+
return Number(this.uint(n));
|
|
3010
|
+
}
|
|
3011
|
+
address() {
|
|
3012
|
+
const n = this.number(1);
|
|
3013
|
+
if (n === 0 || n > 64) throw new ZdHeavyCodecError("Address length must be 1..64");
|
|
3014
|
+
return this.hex(n);
|
|
3015
|
+
}
|
|
3016
|
+
bytes16() {
|
|
3017
|
+
return this.hex(this.number(2));
|
|
3018
|
+
}
|
|
3019
|
+
adapters() {
|
|
3020
|
+
const count = this.number(1);
|
|
3021
|
+
if (count > 8) throw new ZdHeavyCodecError("Too many bridge adapters");
|
|
3022
|
+
return Array.from({ length: count }, () => this.number(2));
|
|
3023
|
+
}
|
|
3024
|
+
end() {
|
|
3025
|
+
if (this.offset !== this.bytes.length) throw new ZdHeavyCodecError("Trailing step bytes");
|
|
3026
|
+
}
|
|
3027
|
+
};
|
|
3028
|
+
function decodeStep(step) {
|
|
3029
|
+
const r = new Reader2(step);
|
|
3030
|
+
if (r.number(1) !== STEP_VERSION) throw new ZdHeavyCodecError("Unsupported step version");
|
|
3031
|
+
const kind = r.number(2);
|
|
3032
|
+
if (kind < 1 || kind > 7) throw new ZdHeavyCodecError("Unknown step kind");
|
|
3033
|
+
const chainId = r.uint(8);
|
|
3034
|
+
const count = r.number(1);
|
|
3035
|
+
if (kind !== StepKind.SWAP && count !== 0) throw new ZdHeavyCodecError("Unexpected allowances");
|
|
3036
|
+
const allowances = Array.from({ length: count }, () => ({
|
|
3037
|
+
pathwayId: r.number(1),
|
|
3038
|
+
maxShareBps: r.number(2),
|
|
3039
|
+
params: r.bytes16()
|
|
3040
|
+
}));
|
|
3041
|
+
const base = { chainId, allowances };
|
|
3042
|
+
let result;
|
|
3043
|
+
switch (kind) {
|
|
3044
|
+
case StepKind.LOCAL_PAYOUT:
|
|
3045
|
+
result = { ...base, kind: "LOCAL_PAYOUT", token: r.address(), receiver: r.address(), minAmountOut: r.uint(16) };
|
|
3046
|
+
break;
|
|
3047
|
+
case StepKind.REMOTE_PAYOUT:
|
|
3048
|
+
result = {
|
|
3049
|
+
...base,
|
|
3050
|
+
kind: "REMOTE_PAYOUT",
|
|
3051
|
+
token: r.address(),
|
|
3052
|
+
receiverChainId: r.uint(8),
|
|
3053
|
+
receiver: r.address(),
|
|
3054
|
+
bridgeAdapters: r.adapters(),
|
|
3055
|
+
maxFee: r.uint(16),
|
|
3056
|
+
minAmountOut: r.uint(16)
|
|
3057
|
+
};
|
|
3058
|
+
break;
|
|
3059
|
+
case StepKind.SEND:
|
|
3060
|
+
result = {
|
|
3061
|
+
...base,
|
|
3062
|
+
kind: "SEND",
|
|
3063
|
+
token: r.address(),
|
|
3064
|
+
dstChainId: r.uint(8),
|
|
3065
|
+
bridgeAdapters: r.adapters(),
|
|
3066
|
+
maxFee: r.uint(16),
|
|
3067
|
+
inUnit: r.uint(16),
|
|
3068
|
+
outUnit: r.uint(16)
|
|
3069
|
+
};
|
|
3070
|
+
break;
|
|
3071
|
+
case StepKind.SWAP:
|
|
3072
|
+
result = { ...base, kind: "SWAP", tokenIn: r.address(), tokenOut: r.address(), expectedIn: r.uint(16), minOut: r.uint(16) };
|
|
3073
|
+
break;
|
|
3074
|
+
case StepKind.EXECUTE:
|
|
3075
|
+
result = { ...base, kind: "EXECUTE", token: r.address(), receiver: r.address(), minAmountOut: r.uint(16), gasLimit: r.uint(8), data: r.bytes16() };
|
|
3076
|
+
break;
|
|
3077
|
+
case StepKind.NET: {
|
|
3078
|
+
const token = r.address(), pathwayId = r.number(1), arriveStep = r.number(1);
|
|
3079
|
+
const params = r.hex(78);
|
|
3080
|
+
const t = new Reader2(params);
|
|
3081
|
+
const terms = {
|
|
3082
|
+
nettingDeadline: t.uint(8),
|
|
3083
|
+
dstDomain: t.number(4),
|
|
3084
|
+
dstAsset: t.hex(32),
|
|
3085
|
+
inUnit: t.uint(16),
|
|
3086
|
+
outUnit: t.uint(16),
|
|
3087
|
+
complianceClass: t.number(2)
|
|
3088
|
+
};
|
|
3089
|
+
result = { chainId, allowances: [{ pathwayId, maxShareBps: 0, params }], kind: "NET", token, pathwayId, arriveStep, terms };
|
|
3090
|
+
break;
|
|
3091
|
+
}
|
|
3092
|
+
case StepKind.SUBSIDY:
|
|
3093
|
+
result = { ...base, kind: "SUBSIDY", token: r.address(), minIn: r.uint(16), amountOut: r.uint(16) };
|
|
3094
|
+
break;
|
|
3095
|
+
default:
|
|
3096
|
+
throw new ZdHeavyCodecError("Unknown step kind");
|
|
3097
|
+
}
|
|
3098
|
+
r.end();
|
|
3099
|
+
return result;
|
|
3100
|
+
}
|
|
3101
|
+
function routerWord(addr) {
|
|
3102
|
+
return concat([toHex(new Uint8Array(12)), checkedHex(addr, 20)]);
|
|
3103
|
+
}
|
|
3104
|
+
function ownerWord(addr) {
|
|
3105
|
+
return routerWord(addr);
|
|
3106
|
+
}
|
|
3107
|
+
function encodeOrderHeader(serial, router, ownerType, owner) {
|
|
3108
|
+
if (!Number.isInteger(ownerType) || ownerType < 0 || ownerType > 255) throw new ZdHeavyCodecError("Invalid ownerType");
|
|
3109
|
+
return concat(["0x050000", uint(serial, 8), routerWord(router), uint(BigInt(ownerType), 1), checkedHex(owner, 32)]);
|
|
3110
|
+
}
|
|
3111
|
+
function orderIdOf(expiryDate, header, steps) {
|
|
3112
|
+
if (steps.length < 1 || steps.length > MAX_STEPS2) throw new ZdHeavyCodecError("Step count must be 1..8");
|
|
3113
|
+
return keccak256(
|
|
3114
|
+
concat([toHex(toBytes("ZD/ORDER")), uint(expiryDate, 8), keccak256(checkedHex(header)), ...steps.map((step) => keccak256(checkedHex(step)))])
|
|
3115
|
+
);
|
|
3116
|
+
}
|
|
3117
|
+
var ZDHEAVY_SUBMIT_SELECTOR = "0x1a579a0c";
|
|
3118
|
+
var ZDHEAVY_PARTNER_SUBMIT_SELECTOR = "0xdd3d9749";
|
|
3119
|
+
var ZDHEAVY_QUOTE_SELECTOR = "0x3cfc3141";
|
|
3120
|
+
function decodeZdHeavySubmit(data) {
|
|
3121
|
+
const hex = checkedHex(data);
|
|
3122
|
+
const selector = hex.slice(0, 10);
|
|
3123
|
+
if (selector !== ZDHEAVY_SUBMIT_SELECTOR && selector !== ZDHEAVY_PARTNER_SUBMIT_SELECTOR) {
|
|
3124
|
+
throw new ZdHeavyCodecError("Expected submitOrder");
|
|
3125
|
+
}
|
|
3126
|
+
const body = hex.slice(10);
|
|
3127
|
+
const size = body.length / 2;
|
|
3128
|
+
const fail = () => {
|
|
3129
|
+
throw new ZdHeavyCodecError("Invalid submitOrder calldata");
|
|
3130
|
+
};
|
|
3131
|
+
const word2 = (at, bits = 256) => {
|
|
3132
|
+
if (!Number.isSafeInteger(at) || at < 0 || at + 32 > size) return fail();
|
|
3133
|
+
const n2 = BigInt(`0x${body.slice(at * 2, (at + 32) * 2)}`);
|
|
3134
|
+
if (n2 >= 1n << BigInt(bits)) return fail();
|
|
3135
|
+
return n2;
|
|
3136
|
+
};
|
|
3137
|
+
const fixed = (at) => {
|
|
3138
|
+
word2(at);
|
|
3139
|
+
return `0x${body.slice(at * 2, (at + 32) * 2)}`;
|
|
3140
|
+
};
|
|
3141
|
+
const offset = (at, expected) => {
|
|
3142
|
+
if (word2(at) !== BigInt(expected)) fail();
|
|
3143
|
+
};
|
|
3144
|
+
const bytes = (at) => {
|
|
3145
|
+
const n2 = word2(at);
|
|
3146
|
+
if (n2 > BigInt(size - at - 32)) return fail();
|
|
3147
|
+
const length = Number(n2);
|
|
3148
|
+
const end = at + 32 + Math.ceil(length / 32) * 32;
|
|
3149
|
+
if (end > size || /[^0]/.test(body.slice((at + 32 + length) * 2, end * 2))) return fail();
|
|
3150
|
+
return { value: `0x${body.slice((at + 32) * 2, (at + 32 + length) * 2)}`, end };
|
|
3151
|
+
};
|
|
3152
|
+
const base = selector === ZDHEAVY_SUBMIT_SELECTOR ? 32 : 64;
|
|
3153
|
+
offset(0, base);
|
|
3154
|
+
const partnerId = base === 64 ? fixed(32) : null;
|
|
3155
|
+
const serial = word2(base, 64);
|
|
3156
|
+
const ownerType = Number(word2(base + 32, 8));
|
|
3157
|
+
const owner = fixed(base + 64);
|
|
3158
|
+
const expiryDate = word2(base + 160, 64);
|
|
3159
|
+
offset(base + 96, 224);
|
|
3160
|
+
const ownerSignature = bytes(base + 224);
|
|
3161
|
+
offset(base + 128, ownerSignature.end - base);
|
|
3162
|
+
const array = ownerSignature.end;
|
|
3163
|
+
const count = word2(array);
|
|
3164
|
+
if (count > BigInt(Math.floor((size - array - 32) / 32))) return fail();
|
|
3165
|
+
const n = Number(count);
|
|
3166
|
+
const arrayBase = array + 32;
|
|
3167
|
+
let next = arrayBase + n * 32;
|
|
3168
|
+
const steps = [];
|
|
3169
|
+
for (let i = 0; i < n; i++) {
|
|
3170
|
+
offset(arrayBase + i * 32, next - arrayBase);
|
|
3171
|
+
const step = bytes(next);
|
|
3172
|
+
steps.push(step.value);
|
|
3173
|
+
next = step.end;
|
|
3174
|
+
}
|
|
3175
|
+
offset(base + 192, next - base);
|
|
3176
|
+
const q = next;
|
|
3177
|
+
const amountIn = word2(q, 128);
|
|
3178
|
+
const fee = { input: word2(q + 32, 128), native: word2(q + 64, 128) };
|
|
3179
|
+
const quoteId = fixed(q + 96);
|
|
3180
|
+
const requestId = fixed(q + 128);
|
|
3181
|
+
const expiresAt = word2(q + 160, 64);
|
|
3182
|
+
offset(q + 192, 224);
|
|
3183
|
+
const signature = bytes(q + 224);
|
|
3184
|
+
if (signature.end !== size) return fail();
|
|
3185
|
+
return {
|
|
3186
|
+
submission: {
|
|
3187
|
+
serial,
|
|
3188
|
+
ownerType,
|
|
3189
|
+
owner,
|
|
3190
|
+
ownerSignature: ownerSignature.value,
|
|
3191
|
+
steps,
|
|
3192
|
+
expiryDate,
|
|
3193
|
+
quote: { amountIn, fee, quoteId, requestId, expiresAt, signature: signature.value }
|
|
3194
|
+
},
|
|
3195
|
+
partnerId
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
function quoteSubmitCalldata(data) {
|
|
3199
|
+
decodeZdHeavySubmit(data);
|
|
3200
|
+
const tuple = data.slice(data.slice(0, 10).toLowerCase() === ZDHEAVY_SUBMIT_SELECTOR ? 74 : 138);
|
|
3201
|
+
return `${ZDHEAVY_QUOTE_SELECTOR}${uintWord(32)}${tuple}`;
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
// src/core/zdheavy-check.ts
|
|
3205
|
+
var isAddress2 = hasValidChecksum;
|
|
3206
|
+
var getAddress = (s) => toChecksumAddress(s);
|
|
3207
|
+
var refuse = (what) => ({
|
|
3208
|
+
ok: false,
|
|
3209
|
+
reason: `The ZD Heavy order the gateway built does not match the order shown (${what}) \u2014 refusing to sign.`
|
|
3210
|
+
});
|
|
3211
|
+
var lower = (v) => typeof v === "string" ? v.toLowerCase() : "";
|
|
3212
|
+
function big(v) {
|
|
3213
|
+
if (v === void 0 || v === null || v === "") return null;
|
|
3214
|
+
try {
|
|
3215
|
+
return BigInt(v);
|
|
3216
|
+
} catch {
|
|
3217
|
+
return null;
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
var sameBig = (a, b) => big(b) === a;
|
|
3221
|
+
var sameAddr = (a, b) => !!b && lower(a) === lower(b);
|
|
3222
|
+
function checkZdHeavyRouter(chainId, router) {
|
|
3223
|
+
if (!router || !isAddress2(router)) return { ok: false, reason: "No valid ZD Heavy router address for this chain \u2014 refusing to sign." };
|
|
3224
|
+
const address = getAddress(router);
|
|
3225
|
+
const pinned = (ZDHEAVY_ROUTER_ADDRESSES[chainId] ?? []).map((a) => getAddress(a));
|
|
3226
|
+
if (!pinned.includes(address)) {
|
|
3227
|
+
return { ok: false, reason: `Router ${address} is not a trusted ZD Heavy router on this chain \u2014 refusing to sign.` };
|
|
3228
|
+
}
|
|
3229
|
+
return { ok: true, address };
|
|
3230
|
+
}
|
|
3231
|
+
function checkZdHeavyValue(txValue, quotedSubmit) {
|
|
3232
|
+
if (quotedSubmit === void 0) return { ok: false, reason: "The router\u2019s submit fee could not be read \u2014 refusing to sign." };
|
|
3233
|
+
if (big(txValue) !== quotedSubmit) return { ok: false, reason: "The transaction carries a native value the router did not quote \u2014 refusing to sign." };
|
|
3234
|
+
return { ok: true };
|
|
3235
|
+
}
|
|
3236
|
+
function sameAllowances(d, j) {
|
|
3237
|
+
if (d.kind !== "SWAP") return true;
|
|
3238
|
+
const want = j.allowances ?? [];
|
|
3239
|
+
if (want.length !== d.allowances.length) return false;
|
|
3240
|
+
return d.allowances.every((a, i) => {
|
|
3241
|
+
const w = want[i];
|
|
3242
|
+
return a.pathwayId === w.pathwayId && a.maxShareBps === w.maxShareBps && lower(a.params) === lower(w.params && w.params !== "" ? w.params : "0x");
|
|
3243
|
+
});
|
|
3244
|
+
}
|
|
3245
|
+
function sameAdapters(a, b) {
|
|
3246
|
+
const w = b ?? [];
|
|
3247
|
+
return a.length === w.length && a.every((x, i) => x === w[i]);
|
|
3248
|
+
}
|
|
3249
|
+
function sameStep(d, j) {
|
|
3250
|
+
if (d.kind !== String(j.kind).toUpperCase()) return false;
|
|
3251
|
+
if (!sameBig(d.chainId, j.chainId)) return false;
|
|
3252
|
+
if (!sameAllowances(d, j)) return false;
|
|
3253
|
+
switch (d.kind) {
|
|
3254
|
+
case "SWAP":
|
|
3255
|
+
return sameAddr(d.tokenIn, j.tokenIn) && sameAddr(d.tokenOut, j.tokenOut) && sameBig(d.expectedIn, j.expectedIn) && sameBig(d.minOut, j.minOut);
|
|
3256
|
+
case "LOCAL_PAYOUT":
|
|
3257
|
+
return sameAddr(d.token, j.token) && sameAddr(d.receiver, j.receiver) && sameBig(d.minAmountOut, j.minAmountOut);
|
|
3258
|
+
case "REMOTE_PAYOUT":
|
|
3259
|
+
return sameAddr(d.token, j.token) && sameBig(d.receiverChainId, j.receiverChainId) && sameAddr(d.receiver, j.receiver) && sameAdapters(d.bridgeAdapters, j.bridgeAdapters) && sameBig(d.maxFee, j.maxFee) && sameBig(d.minAmountOut, j.minAmountOut);
|
|
3260
|
+
case "SEND":
|
|
3261
|
+
return sameAddr(d.token, j.token) && sameBig(d.dstChainId, j.dstChainId) && sameAdapters(d.bridgeAdapters, j.bridgeAdapters) && sameBig(d.maxFee, j.maxFee) && sameBig(d.inUnit, j.inUnit) && sameBig(d.outUnit, j.outUnit);
|
|
3262
|
+
case "SUBSIDY":
|
|
3263
|
+
return sameAddr(d.token, j.token) && sameBig(d.minIn, j.minIn) && sameBig(d.amountOut, j.amountOut);
|
|
3264
|
+
case "NET": {
|
|
3265
|
+
const t = j.terms;
|
|
3266
|
+
if (!t) return false;
|
|
3267
|
+
const domainOfAsset = Number(BigInt(t.dstAsset) >> 224n);
|
|
3268
|
+
return sameAddr(d.token, j.token) && d.pathwayId === j.pathwayId && d.arriveStep === j.arriveStep && sameBig(d.terms.nettingDeadline, t.nettingDeadline) && d.terms.dstDomain === domainOfAsset && lower(d.terms.dstAsset) === lower(t.dstAsset) && sameBig(d.terms.inUnit, t.inUnit) && sameBig(d.terms.outUnit, t.outUnit);
|
|
3269
|
+
}
|
|
3270
|
+
default:
|
|
3271
|
+
return false;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
function checkSubmit(tx, e) {
|
|
3275
|
+
if (tx.chainId !== String(e.chainId)) return refuse("chain");
|
|
3276
|
+
if (!sameAddr(e.router, tx.to)) return refuse("router");
|
|
3277
|
+
let decoded;
|
|
3278
|
+
try {
|
|
3279
|
+
decoded = decodeZdHeavySubmit(tx.data);
|
|
3280
|
+
} catch {
|
|
3281
|
+
return refuse("not a router submitOrder");
|
|
3282
|
+
}
|
|
3283
|
+
const { submission: s, partnerId } = decoded;
|
|
3284
|
+
const order = e.order;
|
|
3285
|
+
if (!order) return refuse("no order");
|
|
3286
|
+
const wantPartner = typeof e.partnerId === "string" && /^0x[0-9a-fA-F]{64}$/.test(e.partnerId) ? lower(e.partnerId) : null;
|
|
3287
|
+
if ((partnerId ? lower(partnerId) : null) !== wantPartner) return refuse("partner id");
|
|
3288
|
+
if (!isAddress2(e.owner)) return refuse("owner");
|
|
3289
|
+
if (s.ownerType !== 1 || lower(s.owner) !== lower(ownerWord(e.owner))) return refuse("owner");
|
|
3290
|
+
if (s.ownerSignature !== "0x") return refuse("owner signature");
|
|
3291
|
+
if (!s.quote.signature || s.quote.signature === "0x") return refuse("no API signature");
|
|
3292
|
+
if (order.chainNumber !== e.chainId || !sameAddr(e.router, order.router)) return refuse("router");
|
|
3293
|
+
if (s.steps.length < 1 || s.steps.length > MAX_STEPS2 || s.steps.length !== order.steps.length) return refuse("number of steps");
|
|
3294
|
+
const steps = [];
|
|
3295
|
+
for (let i = 0; i < s.steps.length; i++) {
|
|
3296
|
+
let d;
|
|
3297
|
+
try {
|
|
3298
|
+
d = decodeStep(s.steps[i]);
|
|
3299
|
+
} catch {
|
|
3300
|
+
return refuse(`step ${i} encoding`);
|
|
3301
|
+
}
|
|
3302
|
+
if (d.kind === "EXECUTE") return refuse(`step ${i} kind EXECUTE`);
|
|
3303
|
+
if (!sameStep(d, order.steps[i])) return refuse(`step ${i}`);
|
|
3304
|
+
steps.push(d);
|
|
3305
|
+
}
|
|
3306
|
+
const first = steps[0];
|
|
3307
|
+
if (first.chainId !== BigInt(e.chainId)) return refuse("source chain");
|
|
3308
|
+
const firstToken = first.kind === "SWAP" ? first.tokenIn : "token" in first ? first.token : "";
|
|
3309
|
+
if (!sameAddr(e.fromToken, firstToken) || !sameAddr(e.fromToken, order.tokenIn)) return refuse("source token");
|
|
3310
|
+
const last = steps[steps.length - 1];
|
|
3311
|
+
if (steps.slice(0, -1).some((d) => d.kind === "LOCAL_PAYOUT" || d.kind === "REMOTE_PAYOUT")) return refuse("payout before the last step");
|
|
3312
|
+
if (last.kind !== "LOCAL_PAYOUT" && last.kind !== "REMOTE_PAYOUT") return refuse("no payout");
|
|
3313
|
+
const deliveryChain = last.kind === "LOCAL_PAYOUT" ? last.chainId : last.receiverChainId;
|
|
3314
|
+
if (deliveryChain !== BigInt(e.toChainId)) return refuse("destination chain");
|
|
3315
|
+
if (last.kind === "LOCAL_PAYOUT") {
|
|
3316
|
+
if (!sameAddr(e.toToken, last.token)) return refuse("destination token");
|
|
3317
|
+
} else {
|
|
3318
|
+
if (!e.remotePayoutToken?.(last.token, Number(last.chainId))) return refuse("destination token of a cross-chain payout");
|
|
3319
|
+
}
|
|
3320
|
+
if (!sameAddr(e.receiver, last.receiver)) return refuse("receiver");
|
|
3321
|
+
const amountIn = big(order.amountIn);
|
|
3322
|
+
const feeInput = big(order.fee.input);
|
|
3323
|
+
const feeNative = big(order.fee.native);
|
|
3324
|
+
if (amountIn === null || feeInput === null || feeNative === null) return refuse("amount");
|
|
3325
|
+
if (s.quote.amountIn !== amountIn || s.quote.fee.input !== feeInput || s.quote.fee.native !== feeNative) return refuse("amount");
|
|
3326
|
+
if (amountIn + feeInput !== e.amountRaw || big(order.grossIn) !== e.amountRaw) return refuse("amount");
|
|
3327
|
+
if (s.expiryDate !== BigInt(order.expiryDate) || s.quote.expiresAt !== BigInt(order.expiresAt)) return refuse("expiry");
|
|
3328
|
+
if (s.expiryDate <= BigInt(e.nowSec) || s.quote.expiresAt <= BigInt(e.nowSec)) return refuse("expired");
|
|
3329
|
+
if (last.kind === "REMOTE_PAYOUT" && last.maxFee >= last.minAmountOut) return refuse("minimum out");
|
|
3330
|
+
const floor = last.kind === "REMOTE_PAYOUT" ? last.minAmountOut - last.maxFee : last.minAmountOut;
|
|
3331
|
+
if (floor <= 0n || floor !== e.finalAmount) return refuse("minimum out");
|
|
3332
|
+
let orderId;
|
|
3333
|
+
try {
|
|
3334
|
+
orderId = orderIdOf(s.expiryDate, encodeOrderHeader(s.serial, getAddress(e.router), 1, s.owner), s.steps);
|
|
3335
|
+
} catch {
|
|
3336
|
+
return refuse("order id");
|
|
3337
|
+
}
|
|
3338
|
+
if (!e.rootHash || lower(orderId) !== lower(e.rootHash)) return refuse("order id");
|
|
3339
|
+
return { ok: true, floor, orderId };
|
|
3340
|
+
}
|
|
3341
|
+
function checkZdHeavySubmit(tx, e) {
|
|
3342
|
+
try {
|
|
3343
|
+
return checkSubmit(tx, e);
|
|
3344
|
+
} catch {
|
|
3345
|
+
return refuse("malformed order");
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
// src/core/asset-identity.ts
|
|
3350
|
+
function key(chainId, address) {
|
|
3351
|
+
const id = Number(chainId);
|
|
3352
|
+
return Number.isSafeInteger(id) && id > 0 && typeof address === "string" && isChainAddress(id, address) ? tokenKey(id, address) : null;
|
|
3353
|
+
}
|
|
3354
|
+
function sameAssetDeployment(tokens, routes, a, b) {
|
|
3355
|
+
const ka = key(a.chainId, a.address);
|
|
3356
|
+
const kb = key(b.chainId, b.address);
|
|
3357
|
+
if (!ka || !kb) return false;
|
|
3358
|
+
const parent = /* @__PURE__ */ new Map();
|
|
3359
|
+
const find = (k) => {
|
|
3360
|
+
const p = parent.get(k);
|
|
3361
|
+
if (p === void 0) {
|
|
3362
|
+
parent.set(k, k);
|
|
3363
|
+
return k;
|
|
3364
|
+
}
|
|
3365
|
+
if (p === k) return k;
|
|
3366
|
+
const root = find(p);
|
|
3367
|
+
parent.set(k, root);
|
|
3368
|
+
return root;
|
|
3369
|
+
};
|
|
3370
|
+
const join = (x, y) => {
|
|
3371
|
+
if (x && y) parent.set(find(y), find(x));
|
|
3372
|
+
};
|
|
3373
|
+
for (const r of routes) {
|
|
3374
|
+
if (r.isEnabled === false) continue;
|
|
3375
|
+
const from = key(r.fromChainId, r.fromAddress);
|
|
3376
|
+
const to = key(r.toChainId, r.toAddress);
|
|
3377
|
+
join(from, to);
|
|
3378
|
+
const home = key(r.homeChainId, r.homeTokenAddress);
|
|
3379
|
+
join(from, home);
|
|
3380
|
+
join(to, home);
|
|
3381
|
+
}
|
|
3382
|
+
for (const t of tokens) join(key(t.chainId, t.address), key(t.homeChainId, t.homeTokenAddress));
|
|
3383
|
+
return parent.has(ka) && parent.has(kb) && find(ka) === find(kb);
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
// src/core/validate-tx.ts
|
|
3387
|
+
var lower2 = (v) => String(v || "").toLowerCase();
|
|
3388
|
+
function isHexAddress(value) {
|
|
3389
|
+
return /^0x[a-fA-F0-9]{40}$/.test(String(value || ""));
|
|
3390
|
+
}
|
|
3391
|
+
function isHexData(value) {
|
|
3392
|
+
return /^0x(?:[a-fA-F0-9]{2})*$/.test(String(value || "0x"));
|
|
3393
|
+
}
|
|
3394
|
+
function isHexQuantity(value) {
|
|
3395
|
+
return /^0x[0-9a-fA-F]+$/.test(String(value || "0x0"));
|
|
3396
|
+
}
|
|
3397
|
+
function dataWord(data, index) {
|
|
3398
|
+
const word2 = String(data || "").slice(10 + index * 64, 10 + (index + 1) * 64);
|
|
3399
|
+
return /^[a-fA-F0-9]{64}$/.test(word2) ? word2 : "";
|
|
3400
|
+
}
|
|
3401
|
+
function dataAddress(data, index) {
|
|
3402
|
+
const word2 = dataWord(data, index);
|
|
3403
|
+
return word2 ? `0x${word2.slice(24)}` : "";
|
|
3404
|
+
}
|
|
3405
|
+
function dataUint(data, index) {
|
|
3406
|
+
const word2 = dataWord(data, index);
|
|
3407
|
+
return word2 ? BigInt(`0x${word2}`) : null;
|
|
3408
|
+
}
|
|
3409
|
+
function rawEquals(value, expected) {
|
|
3410
|
+
try {
|
|
3411
|
+
return value === BigInt(expected || "0");
|
|
3412
|
+
} catch {
|
|
3413
|
+
return false;
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
function planMsgValueHex(route) {
|
|
3417
|
+
try {
|
|
3418
|
+
const raw2 = route?.quote?.msgValue;
|
|
3419
|
+
if (raw2 === void 0 || raw2 === null || raw2 === "") return "0x0";
|
|
3420
|
+
return "0x" + BigInt(raw2).toString(16);
|
|
3421
|
+
} catch {
|
|
3422
|
+
return null;
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
function validatePlannedTransaction(tx, route, expectedRecipient, heavyExpected) {
|
|
3426
|
+
if (!tx || tx.mock) return true;
|
|
3427
|
+
if (!isHexAddress(tx.to) || !isHexData(tx.data || "0x") || !isHexQuantity(tx.value || "0x0")) return false;
|
|
3428
|
+
const data = String(tx.data || "0x").toLowerCase();
|
|
3429
|
+
const selector = data.slice(0, 10);
|
|
3430
|
+
const value = lower2(tx.value || "0x0");
|
|
3431
|
+
if (tx.kind === "transfer") {
|
|
3432
|
+
if (value !== "0x0") return false;
|
|
3433
|
+
return selector === "0xa9059cbb" && isHexAddress(tx.token) && lower2(tx.to) === lower2(tx.token) && lower2(dataAddress(data, 0)) === lower2(expectedRecipient) && rawEquals(dataUint(data, 1), tx.amountRaw);
|
|
3434
|
+
}
|
|
3435
|
+
if (tx.kind === "approve") {
|
|
3436
|
+
if (route.zdHeavy) {
|
|
3437
|
+
return !!heavyExpected && tx.chainId === heavyExpected.chainId && lower2(tx.to) === lower2(heavyExpected.fromToken) && lower2(data) === lower2(encodeApprove(heavyExpected.router, heavyExpected.amountRaw)) && BigInt(value) === 0n;
|
|
3438
|
+
}
|
|
3439
|
+
if (value !== "0x0") return false;
|
|
3440
|
+
return selector === "0x095ea7b3" && isHexAddress(tx.token) && isHexAddress(tx.spender) && lower2(tx.to) === lower2(tx.token) && lower2(dataAddress(data, 0)) === lower2(tx.spender) && rawEquals(dataUint(data, 1), tx.amountRaw);
|
|
3441
|
+
}
|
|
3442
|
+
if (tx.kind === "submitOrder") {
|
|
3443
|
+
if (route.zdHeavy) {
|
|
3444
|
+
const expectedValue = planMsgValueHex(route);
|
|
3445
|
+
return expectedValue !== null && value === lower2(expectedValue) && !!heavyExpected && checkZdHeavySubmit({ ...tx, chainId: String(tx.chainId) }, heavyExpected).ok;
|
|
3446
|
+
}
|
|
3447
|
+
const expected = planMsgValueHex(route);
|
|
3448
|
+
if (expected === null || value !== lower2(expected)) return false;
|
|
3449
|
+
if (selector !== SUBMIT_ORDER_SELECTOR || !isHexAddress(tx.escrow) || lower2(tx.to) !== lower2(tx.escrow)) return false;
|
|
3450
|
+
const decoded = decodeSubmitOrderCalldata(data);
|
|
3451
|
+
if (!decoded) return false;
|
|
3452
|
+
const first = decoded.orders[0];
|
|
3453
|
+
const last = decoded.orders[decoded.orders.length - 1];
|
|
3454
|
+
return decoded.partnerId === lower2(route.quote?.partnerId || NO_PARTNER_ID) && lower2(first.bidToken) === lower2(route.source.tokenAddress) && rawEquals(first.bidTokenAmount, tx.amountRaw) && lower2(last.askToken) === lower2(isSolanaChainId(route.receive.chainId) ? solanaKeyHex(route.receive.tokenAddress || "") : route.receive.tokenAddress) && Number(last.destinationChainId) === Number(route.receive.chainId) && (isSolanaChainId(route.receive.chainId) ? solanaDeliveryMatches(last.destinationReceiver, expectedRecipient, route.receive.tokenAddress) : lower2(last.destinationReceiver) === lower2(expectedRecipient));
|
|
3455
|
+
}
|
|
3456
|
+
return false;
|
|
3457
|
+
}
|
|
3458
|
+
function solanaDeliveryMatches(encoded, recipient2, mint) {
|
|
3459
|
+
try {
|
|
3460
|
+
return lower2(encoded) === expectedSolanaDelivery(recipient2, mint || "");
|
|
3461
|
+
} catch {
|
|
3462
|
+
return false;
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3465
|
+
async function allowanceCovers(tx, account, ethCall) {
|
|
3466
|
+
if (tx?.kind !== "approve" || !tx.token || !tx.spender || !tx.amountRaw || !account) return false;
|
|
3467
|
+
try {
|
|
3468
|
+
const raw2 = await ethCall(tx.token, encodeAllowance(account, tx.spender));
|
|
3469
|
+
return BigInt(raw2 || "0x0") >= BigInt(tx.amountRaw || "0");
|
|
3470
|
+
} catch {
|
|
3471
|
+
return false;
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
// src/core/zdheavy-route.ts
|
|
3476
|
+
function zdHeavyExpected(route, owner, receiver, tokens, routes) {
|
|
3477
|
+
const heavy = route.zdHeavy;
|
|
3478
|
+
if (!heavy) throw new Error("Missing ZD Heavy order.");
|
|
3479
|
+
const pin2 = checkZdHeavyRouter(route.source.chainId, heavy.order.router);
|
|
3480
|
+
if (!pin2.ok) throw new Error(pin2.reason);
|
|
3481
|
+
if (route.source.amount !== formatUnits(heavy.amountRaw, route.source.decimals) || route.source.payAmount !== route.source.amount || route.receive.amount !== formatUnits(heavy.finalAmount, route.receive.decimals))
|
|
3482
|
+
throw new Error("ZD Heavy display amount mismatch.");
|
|
3483
|
+
return {
|
|
3484
|
+
chainId: route.source.chainId,
|
|
3485
|
+
router: pin2.address,
|
|
3486
|
+
owner,
|
|
3487
|
+
receiver,
|
|
3488
|
+
fromToken: route.source.tokenAddress,
|
|
3489
|
+
toToken: route.receive.tokenAddress,
|
|
3490
|
+
toChainId: route.receive.chainId,
|
|
3491
|
+
amountRaw: BigInt(heavy.amountRaw),
|
|
3492
|
+
finalAmount: BigInt(heavy.finalAmount),
|
|
3493
|
+
order: heavy.order,
|
|
3494
|
+
rootHash: heavy.rootHash,
|
|
3495
|
+
partnerId: route.quote.partnerId,
|
|
3496
|
+
nowSec: Math.floor(Date.now() / 1e3),
|
|
3497
|
+
remotePayoutToken: (token, chainId) => sameAssetDeployment(tokens, routes, { chainId, address: token }, { chainId: route.receive.chainId, address: route.receive.tokenAddress })
|
|
3498
|
+
};
|
|
3499
|
+
}
|
|
3500
|
+
function validateZdHeavyPlan(route, expected) {
|
|
3501
|
+
if (route.transactions.length !== 2 || route.transactions[0].kind !== "approve" || route.transactions[1].kind !== "submitOrder") {
|
|
3502
|
+
throw new Error("ZD Heavy requires exactly approve then submitOrder; refusing to sign.");
|
|
3503
|
+
}
|
|
3504
|
+
for (const tx of route.transactions) {
|
|
3505
|
+
if (tx.mock || tx.chainId !== expected.chainId || !validatePlannedTransaction(tx, route, expected.receiver, expected)) {
|
|
3506
|
+
throw new Error("ZD Heavy transaction does not match the reviewed plan; refusing to sign.");
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
const submit = route.transactions[1];
|
|
3510
|
+
const checked = checkZdHeavySubmit({ ...submit, chainId: String(submit.chainId) }, expected);
|
|
3511
|
+
if (!checked.ok) throw new Error(checked.reason);
|
|
3512
|
+
return checked.floor;
|
|
3513
|
+
}
|
|
3514
|
+
async function preflightZdHeavyPlan(route, expected, readFee) {
|
|
3515
|
+
validateZdHeavyPlan(route, expected);
|
|
3516
|
+
const tx = route.transactions[1];
|
|
3517
|
+
const value = checkZdHeavyValue(tx.value, await readFee(expected.chainId, expected.router, tx.data));
|
|
3518
|
+
if (!value.ok) throw new Error(value.reason);
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
// src/core/zdheavy-build.ts
|
|
3522
|
+
function buildZdHeavyRoute(ctx) {
|
|
3523
|
+
const { option, destination, destinationToken, chains, result } = ctx;
|
|
3524
|
+
const q = result.quote;
|
|
3525
|
+
if (!zdHeavyExecutable(q)) throw new Error("ZD Heavy quote is not signed and executable.");
|
|
3526
|
+
const order = q.execution.order;
|
|
3527
|
+
const sourceAmount = formatUnits(result.youPayRaw, option.decimals);
|
|
3528
|
+
const decimals = assetDecimals(destinationToken);
|
|
3529
|
+
const receiveAmount = formatUnits(result.recipientReceivesRaw, decimals);
|
|
3530
|
+
const partnerId = typeof q.partnerId === "string" && /^0x[0-9a-fA-F]{64}$/.test(q.partnerId) ? q.partnerId : void 0;
|
|
3531
|
+
const route = {
|
|
3532
|
+
id: `zdh-${option.chainId}-${option.symbolKey}-${destination.chainId}-${destinationToken.symbol}`,
|
|
3533
|
+
recommended: false,
|
|
3534
|
+
state: result.meetsTarget ? "ROUTE" : "SHORT",
|
|
3535
|
+
source: {
|
|
3536
|
+
asset: option.symbol,
|
|
3537
|
+
ticker: option.ticker || option.symbol,
|
|
3538
|
+
chainId: option.chainId,
|
|
3539
|
+
chainName: option.chainName,
|
|
3540
|
+
tokenAddress: option.address,
|
|
3541
|
+
decimals: option.decimals,
|
|
3542
|
+
amount: sourceAmount,
|
|
3543
|
+
payAmount: sourceAmount
|
|
3544
|
+
},
|
|
3545
|
+
receive: {
|
|
3546
|
+
asset: destinationToken.symbol,
|
|
3547
|
+
ticker: tokenTicker(destinationToken),
|
|
3548
|
+
chainId: Number(destination.chainId),
|
|
3549
|
+
chainName: chainNameOf(Number(destination.chainId), chains),
|
|
3550
|
+
tokenAddress: destinationToken.address,
|
|
3551
|
+
decimals,
|
|
3552
|
+
amount: receiveAmount
|
|
3553
|
+
},
|
|
3554
|
+
routeLabel: "Settle on ZeroDelta via ZD Heavy.",
|
|
3555
|
+
deltaLabel: result.meetsTarget ? "~0" : "Below requested amount",
|
|
3556
|
+
legs: [
|
|
3557
|
+
{
|
|
3558
|
+
index: 1,
|
|
3559
|
+
fromAsset: option.symbol,
|
|
3560
|
+
fromTicker: option.ticker || option.symbol,
|
|
3561
|
+
fromChainId: option.chainId,
|
|
3562
|
+
fromChainName: option.chainName,
|
|
3563
|
+
fromAmount: sourceAmount,
|
|
3564
|
+
toAsset: destinationToken.symbol,
|
|
3565
|
+
toTicker: tokenTicker(destinationToken),
|
|
3566
|
+
toChainId: Number(destination.chainId),
|
|
3567
|
+
toChainName: chainNameOf(Number(destination.chainId), chains),
|
|
3568
|
+
toAmount: receiveAmount,
|
|
3569
|
+
executionChainId: option.chainId,
|
|
3570
|
+
executionChainName: option.chainName
|
|
3571
|
+
}
|
|
3572
|
+
],
|
|
3573
|
+
transactions: q.txData.map((tx, i) => {
|
|
3574
|
+
const submit = tx.actionType === "submit" || tx.actionType === "submitOrder";
|
|
3575
|
+
if (tx.actionType !== "approve" && !submit) throw new Error("Unexpected ZD Heavy transaction action.");
|
|
3576
|
+
if (typeof tx.value !== "string" || !/^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(tx.value)) throw new Error("Invalid ZD Heavy native value.");
|
|
3577
|
+
return {
|
|
3578
|
+
id: submit ? "submit-order" : `approve-${i}`,
|
|
3579
|
+
kind: submit ? "submitOrder" : "approve",
|
|
3580
|
+
label: submit ? "Submit ZeroDelta order" : `Approve ${option.ticker || option.symbol}`,
|
|
3581
|
+
chainId: Number(tx.chainId),
|
|
3582
|
+
to: tx.to,
|
|
3583
|
+
data: tx.data,
|
|
3584
|
+
// The gateway publishes decimal wei; EIP-1193 requires a hex quantity.
|
|
3585
|
+
// Calldata and targets remain the gateway's exact bytes.
|
|
3586
|
+
value: toHexQuantity(tx.value),
|
|
3587
|
+
token: option.address,
|
|
3588
|
+
spender: order.router,
|
|
3589
|
+
amountRaw: result.youPayRaw
|
|
3590
|
+
};
|
|
3591
|
+
}),
|
|
3592
|
+
quote: {
|
|
3593
|
+
bridge: q.bridge,
|
|
3594
|
+
feeBps: q.feeBps,
|
|
3595
|
+
estimatedDuration: q.estimatedDuration,
|
|
3596
|
+
gasCostSource: q.gasCostSource,
|
|
3597
|
+
iterations: result.iterations,
|
|
3598
|
+
compliance: q.compliance,
|
|
3599
|
+
partnerId,
|
|
3600
|
+
zeroDeltaFeeCentibips: q.zeroDeltaFeeCentibips,
|
|
3601
|
+
zeroDeltaFeeNative: q.zeroDeltaFeeNative
|
|
3602
|
+
},
|
|
3603
|
+
zdHeavy: { order, rootHash: q.rootHash, amountRaw: result.youPayRaw, finalAmount: result.recipientReceivesRaw, floor: "" }
|
|
3604
|
+
};
|
|
3605
|
+
if (route.transactions.length === 2) route.quote.msgValue = BigInt(route.transactions[1].value).toString();
|
|
3606
|
+
const expected = zdHeavyExpected(route, ctx.payer, destination.address, ctx.tokens, ctx.routes);
|
|
3607
|
+
route.zdHeavy.floor = validateZdHeavyPlan(route, expected).toString();
|
|
3608
|
+
return route;
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
// src/core/quote-compare.ts
|
|
3612
|
+
var WAIT_MIN_SEC = 180;
|
|
3613
|
+
var WAIT_MAX_SEC = 7200;
|
|
3614
|
+
var WAIT_STEP_SEC = 60;
|
|
3615
|
+
function clampWait(sec) {
|
|
3616
|
+
if (!Number.isFinite(sec)) return WAIT_MIN_SEC;
|
|
3617
|
+
return Math.min(WAIT_MAX_SEC, Math.max(WAIT_MIN_SEC, sec));
|
|
3618
|
+
}
|
|
3619
|
+
var WAIT_POINTS = [
|
|
3620
|
+
[WAIT_MIN_SEC, 0],
|
|
3621
|
+
[1800, 0.295],
|
|
3622
|
+
[2700, 0.4725],
|
|
3623
|
+
[WAIT_MAX_SEC, 1]
|
|
3624
|
+
];
|
|
3625
|
+
var FIGMA_TRAVEL_PX = 400;
|
|
3626
|
+
function waitScaleFor(travelPx) {
|
|
3627
|
+
if (!Number.isFinite(travelPx) || travelPx >= FIGMA_TRAVEL_PX || travelPx < 200) return WAIT_POINTS;
|
|
3628
|
+
return WAIT_POINTS.map(
|
|
3629
|
+
([sec, fraction], i) => i === 0 || i === WAIT_POINTS.length - 1 ? [sec, fraction] : [sec, fraction * FIGMA_TRAVEL_PX / travelPx]
|
|
3630
|
+
);
|
|
3631
|
+
}
|
|
3632
|
+
var WAIT_POSITIONS = 1e3;
|
|
3633
|
+
function waitFraction(sec, points = WAIT_POINTS) {
|
|
3634
|
+
const s = clampWait(sec);
|
|
3635
|
+
for (let i = 1; i < points.length; i++) {
|
|
3636
|
+
const [s1, f1] = points[i];
|
|
3637
|
+
if (s <= s1) {
|
|
3638
|
+
const [s0, f0] = points[i - 1];
|
|
3639
|
+
return f0 + (s - s0) / (s1 - s0) * (f1 - f0);
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
return 1;
|
|
3643
|
+
}
|
|
3644
|
+
function waitFromFraction(fraction, points = WAIT_POINTS) {
|
|
3645
|
+
const f = Number.isFinite(fraction) ? Math.min(1, Math.max(0, fraction)) : 0;
|
|
3646
|
+
for (let i = 1; i < points.length; i++) {
|
|
3647
|
+
const [s1, f1] = points[i];
|
|
3648
|
+
if (f <= f1) {
|
|
3649
|
+
const [s0, f0] = points[i - 1];
|
|
3650
|
+
return s0 + (f - f0) / (f1 - f0) * (s1 - s0);
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
return WAIT_MAX_SEC;
|
|
3654
|
+
}
|
|
3655
|
+
function snapWait(sec) {
|
|
3656
|
+
return clampWait(Math.round(sec / WAIT_STEP_SEC) * WAIT_STEP_SEC);
|
|
3657
|
+
}
|
|
3658
|
+
function waitLabel(sec) {
|
|
3659
|
+
const min = Math.round(clampWait(sec) / 60);
|
|
3660
|
+
if (min >= 60 && min % 60 === 0) return `Up to ${min / 60} ${min === 60 ? "hour" : "hours"}`;
|
|
3661
|
+
return `Up to ${min} min`;
|
|
3662
|
+
}
|
|
3663
|
+
var hasTime = (o) => Number.isFinite(o.estimatedDuration) && o.estimatedDuration > 0;
|
|
3664
|
+
function selectableOptions(options) {
|
|
3665
|
+
return options.filter((o) => !o.unavailable);
|
|
3666
|
+
}
|
|
3667
|
+
function bestOutputOption(options) {
|
|
3668
|
+
return selectableOptions(options).reduce((best, o) => !best || o.amount > best.amount ? o : best, void 0);
|
|
3669
|
+
}
|
|
3670
|
+
function fastestOption(options) {
|
|
3671
|
+
const selectable = selectableOptions(options);
|
|
3672
|
+
const labelled = selectable.find((o) => o.label?.toLowerCase() === "fastest");
|
|
3673
|
+
if (labelled) return labelled;
|
|
3674
|
+
return selectable.filter(hasTime).reduce((f, o) => !f || o.estimatedDuration < f.estimatedDuration ? o : f, void 0);
|
|
3675
|
+
}
|
|
3676
|
+
function proposedWait(options) {
|
|
3677
|
+
const best = bestOutputOption(options);
|
|
3678
|
+
return clampWait(best && hasTime(best) ? best.estimatedDuration : WAIT_MIN_SEC);
|
|
3679
|
+
}
|
|
3680
|
+
function pickForWait(options, waitSec) {
|
|
3681
|
+
const within = selectableOptions(options).filter((o) => hasTime(o) && o.estimatedDuration <= waitSec);
|
|
3682
|
+
return bestOutputOption(within) ?? fastestOption(options);
|
|
3683
|
+
}
|
|
3684
|
+
var MAX_QUOTE_CARDS = 3;
|
|
3685
|
+
function visibleOptions(options, waitSec, selectedId) {
|
|
3686
|
+
if (options.length <= MAX_QUOTE_CARDS) return [...options];
|
|
3687
|
+
const selectable = selectableOptions(options);
|
|
3688
|
+
if (selectable.length === 0) return options.slice(0, MAX_QUOTE_CARDS);
|
|
3689
|
+
const chosen = selectable.find((o) => o.id === selectedId) ?? pickForWait(options, waitSec);
|
|
3690
|
+
const gasless = bestOutputOption(selectable.filter((o) => o.gasSponsored));
|
|
3691
|
+
const netting = bestOutputOption(selectable.filter((o) => o.entersNetting));
|
|
3692
|
+
const ids = new Set([chosen?.id, fastestOption(options)?.id, gasless?.id, netting?.id].filter((id) => !!id));
|
|
3693
|
+
const keep = new Set([...ids].slice(0, MAX_QUOTE_CARDS));
|
|
3694
|
+
return options.filter((o) => keep.has(o.id));
|
|
3695
|
+
}
|
|
3696
|
+
function compareDuration(seconds) {
|
|
3697
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return "--";
|
|
3698
|
+
if (seconds < 60) return `~${Math.round(seconds)} s`;
|
|
3699
|
+
return `~${Math.round(seconds / 60)} min`;
|
|
3700
|
+
}
|
|
3701
|
+
function parity(options, inputUsd, toUnitUsd) {
|
|
3702
|
+
const priced = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
3703
|
+
if (!priced(inputUsd) || !priced(toUnitUsd)) return { kind: "unknown" };
|
|
3704
|
+
const reaching = selectableOptions(options).filter((o) => hasTime(o) && o.amount * toUnitUsd >= inputUsd);
|
|
3705
|
+
const earliest = reaching.reduce(
|
|
3706
|
+
(e, o) => !e || o.estimatedDuration < e.estimatedDuration || o.estimatedDuration === e.estimatedDuration && o.amount > e.amount ? o : e,
|
|
3707
|
+
void 0
|
|
3708
|
+
);
|
|
3709
|
+
return earliest ? { kind: "at", option: earliest, timeSec: earliest.estimatedDuration } : { kind: "unavailable" };
|
|
3710
|
+
}
|
|
3711
|
+
function extraVsFastest(options, selectedId) {
|
|
3712
|
+
const selected = selectableOptions(options).find((o) => o.id === selectedId);
|
|
3713
|
+
const fastest = fastestOption(options);
|
|
3714
|
+
if (!selected || !fastest) return null;
|
|
3715
|
+
const extra = selected.amount - fastest.amount;
|
|
3716
|
+
return extra > 1e-9 ? extra : null;
|
|
3717
|
+
}
|
|
3718
|
+
function routeBadges(options) {
|
|
3719
|
+
const field = options.filter((o) => !o.unavailable);
|
|
3720
|
+
const out = /* @__PURE__ */ new Map();
|
|
3721
|
+
if (field.length < 2) return out;
|
|
3722
|
+
const best = (pick, better) => field.reduce((acc, o) => {
|
|
3723
|
+
const value = pick(o);
|
|
3724
|
+
if (value === null) return acc;
|
|
3725
|
+
const accValue = acc ? pick(acc) : null;
|
|
3726
|
+
return accValue === null || better(value, accValue) ? o : acc;
|
|
3727
|
+
}, null);
|
|
3728
|
+
const bestReturn = best(
|
|
3729
|
+
(o) => o.amount,
|
|
3730
|
+
(a, b) => a > b
|
|
3731
|
+
);
|
|
3732
|
+
const fastest = best(
|
|
3733
|
+
(o) => o.estimatedDuration,
|
|
3734
|
+
(a, b) => a < b
|
|
3735
|
+
);
|
|
3736
|
+
const lowestFee = best(
|
|
3737
|
+
(o) => o.feeUsd,
|
|
3738
|
+
(a, b) => a < b
|
|
3739
|
+
);
|
|
3740
|
+
if (bestReturn) out.set(bestReturn.id, "Best return");
|
|
3741
|
+
if (fastest && !out.has(fastest.id)) out.set(fastest.id, "Fastest");
|
|
3742
|
+
if (lowestFee && !out.has(lowestFee.id)) out.set(lowestFee.id, "Lowest fee");
|
|
3743
|
+
return out;
|
|
3744
|
+
}
|
|
3745
|
+
function routeShapeLabel(option) {
|
|
3746
|
+
if (!option) return null;
|
|
3747
|
+
if (option.kind === "transfer") return "Transfer";
|
|
3748
|
+
const middle = option.hops.slice(1, -1);
|
|
3749
|
+
if (middle.length === 0) return "Direct";
|
|
3750
|
+
return `Via ${middle.map((h) => h.ticker).join(" \xB7 ")}`;
|
|
3751
|
+
}
|
|
3752
|
+
function cornerTags(options, option, parityState) {
|
|
3753
|
+
if (option.unavailable) return [];
|
|
3754
|
+
if (option.kind === "transfer") return [{ text: "Transfer", tone: "brand" }];
|
|
3755
|
+
const tags = [];
|
|
3756
|
+
const labelledFastest = selectableOptions(options).some((o) => o.label?.toLowerCase() === "fastest");
|
|
3757
|
+
if (parityState.kind === "at" && parityState.option.id === option.id) tags.push({ text: "Target 1:1", tone: "brand" });
|
|
3758
|
+
else if (option.entersNetting) tags.push({ text: "Potential best return", tone: "brand" });
|
|
3759
|
+
else if (option.label?.toLowerCase() === "fastest") tags.push({ text: "Fastest", tone: "brand" });
|
|
3760
|
+
else if (option.gasSponsored) tags.push({ text: "Gasless", tone: "purple" });
|
|
3761
|
+
else {
|
|
3762
|
+
const badge = routeBadges(options).get(option.id);
|
|
3763
|
+
const text = badge === "Fastest" && labelledFastest ? void 0 : badge ?? routeShapeLabel(option) ?? void 0;
|
|
3764
|
+
if (text) tags.push({ text, tone: "brand" });
|
|
3765
|
+
}
|
|
3766
|
+
if (option.entersNetting) tags.push({ text: "Netting", tone: "green" });
|
|
3767
|
+
return tags;
|
|
3768
|
+
}
|
|
3769
|
+
function humanAmount(n, maxFrac = 6) {
|
|
3770
|
+
if (!Number.isFinite(n)) return String(n);
|
|
3771
|
+
if (n === 0) return "0";
|
|
3772
|
+
const digits = Math.min(Math.max(0, Math.trunc(maxFrac)), 8);
|
|
3773
|
+
const fixed = n.toFixed(digits);
|
|
3774
|
+
const out = fixed.includes(".") ? fixed.replace(/\.?0+$/, "") : fixed;
|
|
3775
|
+
if (Number(out) === 0) return `<${digits > 0 ? `0.${"0".repeat(digits - 1)}1` : "1"}`;
|
|
3776
|
+
const match = out.match(/^([+-]?)(\d+)(\.\d+)?$/);
|
|
3777
|
+
return match ? `${match[1]}${match[2].replace(/\B(?=(\d{3})+(?!\d))/g, ",")}${match[3] ?? ""}` : out;
|
|
3778
|
+
}
|
|
3779
|
+
function compareAmount(value) {
|
|
3780
|
+
const text = humanAmount(value, 6);
|
|
3781
|
+
if (text.startsWith("<")) return text;
|
|
3782
|
+
const [whole, fraction = ""] = text.split(".");
|
|
3783
|
+
return fraction.length >= 2 ? text : `${whole}.${fraction.padEnd(2, "0")}`;
|
|
3784
|
+
}
|
|
3785
|
+
function compareFeeUsd(option, fromUsd) {
|
|
3786
|
+
const centibips = option.feeCentibips;
|
|
3787
|
+
if (centibips === void 0 || option.feeNative) return null;
|
|
3788
|
+
if (centibips === 0) return 0;
|
|
3789
|
+
return typeof fromUsd === "number" && Number.isFinite(fromUsd) && fromUsd > 0 ? fromUsd * centibips / 1e6 : null;
|
|
3790
|
+
}
|
|
3791
|
+
function priceCompareOptions(options, fromUsd) {
|
|
3792
|
+
return options.map((o) => ({ ...o, feeUsd: compareFeeUsd(o, fromUsd) }));
|
|
3793
|
+
}
|
|
3794
|
+
var ZD_HEAVY_KEY_PREFIX = "zdheavy:";
|
|
3795
|
+
function zdHeavyOptionKey(q) {
|
|
3796
|
+
return q.label ? `${ZD_HEAVY_KEY_PREFIX}${q.label}:${String(q.escrowAddress ?? "").toLowerCase()}` : `${ZD_HEAVY_KEY_PREFIX}id:${q.optionId ?? ""}`;
|
|
3797
|
+
}
|
|
3798
|
+
function zdHeavyUnavailableStatus(q) {
|
|
3799
|
+
return zdHeavyExecutable(q) ? void 0 : typeof q.payloadStatus === "string" && q.payloadStatus ? q.payloadStatus : "unknown";
|
|
3800
|
+
}
|
|
3801
|
+
function tokenAt2(tokens, chainId, address) {
|
|
3802
|
+
const key2 = isSolanaChainId(chainId) ? hexToSolanaKey(address) || address : address;
|
|
3803
|
+
const wanted = isChainAddress(chainId, key2) ? chainAddressKey(chainId, key2) : null;
|
|
3804
|
+
if (!wanted || !tokens?.length) return void 0;
|
|
3805
|
+
return tokens.find((t) => Number(t.chainId) === Number(chainId) && chainAddressKey(chainId, t.address) === wanted);
|
|
3806
|
+
}
|
|
3807
|
+
function hopFor(tokens, address, chainId, fallback) {
|
|
3808
|
+
const token = tokenAt2(tokens, chainId, address);
|
|
3809
|
+
return { address, chainId, ticker: token ? tokenTicker(token) : fallback ?? "Unknown" };
|
|
3810
|
+
}
|
|
3811
|
+
function compareHops(quote, ctx) {
|
|
3812
|
+
if (quote.protocol === "zdheavy") {
|
|
3813
|
+
const order = quote.execution?.order;
|
|
3814
|
+
if (!order || !Array.isArray(order.steps) || !order.steps.length) return [];
|
|
3815
|
+
const first = order.steps[0];
|
|
3816
|
+
const hops2 = [hopFor(ctx.tokens, String(first.tokenIn ?? first.token ?? order.tokenIn ?? ""), Number(order.chainNumber), ctx.from.ticker)];
|
|
3817
|
+
const push = (address, chainId, fallback) => {
|
|
3818
|
+
if (!address || chainId === void 0) return;
|
|
3819
|
+
const previous = hops2[hops2.length - 1];
|
|
3820
|
+
if (previous.address.toLowerCase() === address.toLowerCase() && previous.chainId === Number(chainId)) return;
|
|
3821
|
+
hops2.push(hopFor(ctx.tokens, address, Number(chainId), fallback));
|
|
3822
|
+
};
|
|
3823
|
+
order.steps.forEach((s, i) => {
|
|
3824
|
+
const n = order.steps[i + 1];
|
|
3825
|
+
const p = hops2[hops2.length - 1];
|
|
3826
|
+
if (s.kind === "SWAP") push(s.tokenOut, s.chainId);
|
|
3827
|
+
else if (s.kind === "SEND") push(n?.tokenIn ?? n?.token, s.dstChainId, p.ticker);
|
|
3828
|
+
else if (s.kind === "LOCAL_PAYOUT") push(s.token, s.chainId, ctx.to.ticker);
|
|
3829
|
+
else if (s.kind === "REMOTE_PAYOUT") push(ctx.to.address, s.receiverChainId, ctx.to.ticker);
|
|
3830
|
+
});
|
|
3831
|
+
return hops2;
|
|
3832
|
+
}
|
|
3833
|
+
const requests = Array.isArray(quote.orderRequests) ? quote.orderRequests : [];
|
|
3834
|
+
if (!requests.length) return [];
|
|
3835
|
+
const hops = [hopFor(ctx.tokens, String(requests[0].bidToken ?? ""), Number(quote.fromChainId), ctx.from.ticker)];
|
|
3836
|
+
requests.forEach((request, i) => {
|
|
3837
|
+
const last = i === requests.length - 1;
|
|
3838
|
+
hops.push(hopFor(ctx.tokens, String(request.askToken ?? ""), Number(request.destinationChainId || quote.toChainId), last ? ctx.to.ticker : void 0));
|
|
3839
|
+
});
|
|
3840
|
+
return hops;
|
|
3841
|
+
}
|
|
3842
|
+
var shortAddress2 = (address) => address.slice(0, 10).toLowerCase();
|
|
3843
|
+
function compareOptionOf(quote, ctx) {
|
|
3844
|
+
const heavy = quote.protocol === "zdheavy";
|
|
3845
|
+
if (!heavy && !liteExecutable(quote)) return null;
|
|
3846
|
+
const hops = compareHops(quote, ctx);
|
|
3847
|
+
if (hops.length < 2 && !heavy) return null;
|
|
3848
|
+
let amountRaw;
|
|
3849
|
+
let amount;
|
|
3850
|
+
try {
|
|
3851
|
+
amountRaw = BigInt(quote.finalAmount || quote.toAmount || "");
|
|
3852
|
+
amount = Number(formatUnits(amountRaw, ctx.to.decimals, ctx.to.decimals));
|
|
3853
|
+
} catch {
|
|
3854
|
+
return null;
|
|
3855
|
+
}
|
|
3856
|
+
const centibips = quote.zeroDeltaFeeCentibips;
|
|
3857
|
+
const native = quote.zeroDeltaFeeNative;
|
|
3858
|
+
const feeNative = typeof native === "string" && /^\d+$/.test(native) && BigInt(native) > 0n;
|
|
3859
|
+
const feeCentibips = typeof centibips === "number" && Number.isSafeInteger(centibips) && centibips >= 0 ? centibips : void 0;
|
|
3860
|
+
const unavailable = heavy ? zdHeavyUnavailableStatus(quote) : void 0;
|
|
3861
|
+
const option = {
|
|
3862
|
+
// The path, not the amount: the amount moves on every re-quote, and a key that changes would drop a pick.
|
|
3863
|
+
id: heavy ? zdHeavyOptionKey(quote) : hops.map((h) => `${h.chainId}:${shortAddress2(h.address)}`).join(">"),
|
|
3864
|
+
...typeof quote.label === "string" && quote.label ? { label: quote.label } : {},
|
|
3865
|
+
...unavailable ? { unavailable } : {},
|
|
3866
|
+
amount,
|
|
3867
|
+
amountRaw: amountRaw.toString(),
|
|
3868
|
+
estimatedDuration: Number(quote.estimatedDuration) || 0,
|
|
3869
|
+
feeUsd: null,
|
|
3870
|
+
...feeCentibips !== void 0 ? { feeCentibips } : {},
|
|
3871
|
+
...feeNative ? { feeNative: true } : {},
|
|
3872
|
+
hops,
|
|
3873
|
+
...quote.entersNetting === true ? { entersNetting: true } : {},
|
|
3874
|
+
...quote.gasSponsored === true ? { gasSponsored: true } : {}
|
|
3875
|
+
};
|
|
3876
|
+
option.feeUsd = compareFeeUsd(option);
|
|
3877
|
+
return option;
|
|
3878
|
+
}
|
|
3879
|
+
function compareOptionsOf(quote, ctx) {
|
|
3880
|
+
const all = quote.gatewayOptions?.length ? quote.gatewayOptions : [quote];
|
|
3881
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3882
|
+
const byIndex = all.map((q) => {
|
|
3883
|
+
const row = compareOptionOf(q, ctx);
|
|
3884
|
+
if (!row || seen.has(row.id)) return null;
|
|
3885
|
+
seen.add(row.id);
|
|
3886
|
+
return row;
|
|
3887
|
+
});
|
|
3888
|
+
return { options: byIndex.filter((o) => !!o), byIndex };
|
|
3889
|
+
}
|
|
3890
|
+
|
|
2721
3891
|
// src/core/route.ts
|
|
2722
3892
|
function routeDeltaLabel(result, quote) {
|
|
2723
3893
|
if (result.directTransfer) return "~0";
|
|
@@ -2738,9 +3908,9 @@ function routeLabelFor(option, destinationToken, result) {
|
|
|
2738
3908
|
const bridge = result.quote.bridge ? ` via ${result.quote.bridge}` : "";
|
|
2739
3909
|
return `Swap ${optionTicker(option)} to ${tokenTicker(destinationToken)} and settle on ZeroDelta${bridge}.`;
|
|
2740
3910
|
}
|
|
2741
|
-
function
|
|
2742
|
-
const
|
|
2743
|
-
const wanted = isChainAddress(chainId,
|
|
3911
|
+
function tokenAt3(tokens, chainId, address) {
|
|
3912
|
+
const key2 = isSolanaChainId(chainId) ? hexToSolanaKey(address) || address : address;
|
|
3913
|
+
const wanted = isChainAddress(chainId, key2) ? chainAddressKey(chainId, key2) : null;
|
|
2744
3914
|
if (!wanted || !tokens?.length) return void 0;
|
|
2745
3915
|
return tokens.find((t) => Number(t.chainId) === Number(chainId) && chainAddressKey(chainId, t.address) === wanted);
|
|
2746
3916
|
}
|
|
@@ -2762,7 +3932,7 @@ function buildLegs(orders, ctx) {
|
|
|
2762
3932
|
const order = orders[index];
|
|
2763
3933
|
const isLast = index === orders.length - 1;
|
|
2764
3934
|
const toChainId = Number(order.destinationChainId);
|
|
2765
|
-
const askToken = isLast ? ctx.destinationToken :
|
|
3935
|
+
const askToken = isLast ? ctx.destinationToken : tokenAt3(ctx.tokens, toChainId, order.askToken);
|
|
2766
3936
|
const toAsset = isLast ? ctx.destinationToken.symbol : askToken?.symbol ?? "";
|
|
2767
3937
|
const toTicker = askToken ? tokenTicker(askToken) : "";
|
|
2768
3938
|
const toDecimals = askToken ? assetDecimals(askToken) : void 0;
|
|
@@ -2789,19 +3959,42 @@ function buildLegs(orders, ctx) {
|
|
|
2789
3959
|
}
|
|
2790
3960
|
return legs;
|
|
2791
3961
|
}
|
|
2792
|
-
async function buildRoute({
|
|
2793
|
-
option,
|
|
2794
|
-
|
|
2795
|
-
destinationToken,
|
|
2796
|
-
chains,
|
|
2797
|
-
tokens,
|
|
2798
|
-
payer,
|
|
2799
|
-
fetchQuote,
|
|
2800
|
-
solve = solveExactOut,
|
|
2801
|
-
amountInRaw,
|
|
2802
|
-
compliance
|
|
2803
|
-
}) {
|
|
3962
|
+
async function buildRoute(args) {
|
|
3963
|
+
const { option, destination, destinationToken, payer, fetchQuote, amountInRaw } = args;
|
|
3964
|
+
const solve = args.solve ?? solveExactOut;
|
|
2804
3965
|
const result = await solve({ option, destination, destinationToken, payer, fetchQuote, amountInRaw });
|
|
3966
|
+
const route = routeFromResult(args, result);
|
|
3967
|
+
return result.directTransfer ? route : withQuoteOptions(route, args, result, solve === solveExactIn ? "exact-in" : "exact-out");
|
|
3968
|
+
}
|
|
3969
|
+
function withQuoteOptions(route, args, result, mode) {
|
|
3970
|
+
const { option, destination, destinationToken } = args;
|
|
3971
|
+
const quote = result.quote;
|
|
3972
|
+
const { byIndex } = compareOptionsOf(quote, {
|
|
3973
|
+
tokens: args.tokens,
|
|
3974
|
+
from: { chainId: option.chainId, address: option.address, ticker: optionTicker(option) },
|
|
3975
|
+
to: { chainId: Number(destination.chainId), address: destinationToken.address, ticker: tokenTicker(destinationToken), decimals: assetDecimals(destinationToken) }
|
|
3976
|
+
});
|
|
3977
|
+
const selectedIndex = quote.gatewayOptions?.length ? quote.gatewayOptionIndex ?? -1 : 0;
|
|
3978
|
+
const built = [];
|
|
3979
|
+
const refused = /* @__PURE__ */ new Set();
|
|
3980
|
+
(quote.gatewayOptions ?? []).forEach((candidate, index) => {
|
|
3981
|
+
const row = byIndex[index];
|
|
3982
|
+
if (!row || row.unavailable || index === selectedIndex) return;
|
|
3983
|
+
try {
|
|
3984
|
+
built.push({ index, route: routeFromResult(args, resultForOption(result, candidate, mode, destination.chainId)) });
|
|
3985
|
+
} catch {
|
|
3986
|
+
refused.add(index);
|
|
3987
|
+
}
|
|
3988
|
+
});
|
|
3989
|
+
const options = [];
|
|
3990
|
+
byIndex.forEach((row, index) => {
|
|
3991
|
+
if (row) options.push(refused.has(index) ? { ...row, unavailable: "refused-by-widget" } : row);
|
|
3992
|
+
});
|
|
3993
|
+
const selectedOptionId = byIndex[selectedIndex]?.id;
|
|
3994
|
+
const alternatives = built.map(({ index, route: alt }) => ({ ...alt, id: route.id, options, selectedOptionId: byIndex[index].id }));
|
|
3995
|
+
return { ...route, options, ...selectedOptionId ? { selectedOptionId } : {}, ...alternatives.length ? { alternatives } : {} };
|
|
3996
|
+
}
|
|
3997
|
+
function routeFromResult({ option, destination, destinationToken, chains, tokens, routes, payer, compliance }, result) {
|
|
2805
3998
|
const quote = result.quote;
|
|
2806
3999
|
const destDecimals = assetDecimals(destinationToken);
|
|
2807
4000
|
const receiveAmount = formatUnits(result.recipientReceivesRaw, destDecimals);
|
|
@@ -2876,6 +4069,9 @@ async function buildRoute({
|
|
|
2876
4069
|
}
|
|
2877
4070
|
};
|
|
2878
4071
|
}
|
|
4072
|
+
if (quote.protocol === "zdheavy") {
|
|
4073
|
+
return buildZdHeavyRoute({ option, destination, destinationToken, chains, tokens: tokens ?? [], routes: routes ?? [], payer, result });
|
|
4074
|
+
}
|
|
2879
4075
|
const requestList = quote.orderRequests?.length ? quote.orderRequests : quote.orderRequest ? [quote.orderRequest] : [];
|
|
2880
4076
|
if (!requestList.length) throw new Error("ZeroDelta quote did not include an order request.");
|
|
2881
4077
|
const sourceChain = chainById(chains, option.chainId);
|
|
@@ -2977,12 +4173,201 @@ async function buildRoute({
|
|
|
2977
4173
|
};
|
|
2978
4174
|
}
|
|
2979
4175
|
|
|
4176
|
+
// src/core/promotions.ts
|
|
4177
|
+
var CENTIBIPS_PER_UNIT = 1e6;
|
|
4178
|
+
function toToken(raw2) {
|
|
4179
|
+
if (!raw2 || typeof raw2 !== "object") return void 0;
|
|
4180
|
+
const r = raw2;
|
|
4181
|
+
const chainId = Number(r.chainId);
|
|
4182
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0) return void 0;
|
|
4183
|
+
if (typeof r.address !== "string" || !r.address) return void 0;
|
|
4184
|
+
if (typeof r.symbol !== "string" || !r.symbol) return void 0;
|
|
4185
|
+
return { chainId, address: r.address, symbol: r.symbol };
|
|
4186
|
+
}
|
|
4187
|
+
function parsePromotion(raw2, now = Date.now()) {
|
|
4188
|
+
if (!raw2 || typeof raw2 !== "object") return void 0;
|
|
4189
|
+
const r = raw2;
|
|
4190
|
+
if (typeof r.id !== "string" || !r.id) return void 0;
|
|
4191
|
+
if (r.kind !== "token" && r.kind !== "pair") return void 0;
|
|
4192
|
+
const destination = toToken(r.destination);
|
|
4193
|
+
if (!destination) return void 0;
|
|
4194
|
+
const source = r.kind === "pair" ? toToken(r.source) : void 0;
|
|
4195
|
+
if (r.kind === "pair" && !source) return void 0;
|
|
4196
|
+
const bonusCentibips = Number(r.bonusCentibips);
|
|
4197
|
+
if (!Number.isSafeInteger(bonusCentibips) || bonusCentibips <= 0) return void 0;
|
|
4198
|
+
if (r.fundedBy !== "issuer" && r.fundedBy !== "zerodelta") return void 0;
|
|
4199
|
+
if (typeof r.startsAt !== "string" || typeof r.endsAt !== "string") return void 0;
|
|
4200
|
+
const starts = Date.parse(r.startsAt);
|
|
4201
|
+
const ends = Date.parse(r.endsAt);
|
|
4202
|
+
if (!Number.isFinite(starts) || !Number.isFinite(ends) || !(starts <= now && now < ends)) return void 0;
|
|
4203
|
+
let maxBonusAmount;
|
|
4204
|
+
if (r.maxBonusAmount !== void 0) {
|
|
4205
|
+
if (typeof r.maxBonusAmount !== "string" || !/^[1-9]\d*$/.test(r.maxBonusAmount)) return void 0;
|
|
4206
|
+
maxBonusAmount = r.maxBonusAmount;
|
|
4207
|
+
}
|
|
4208
|
+
return {
|
|
4209
|
+
id: r.id,
|
|
4210
|
+
kind: r.kind,
|
|
4211
|
+
destination,
|
|
4212
|
+
...source ? { source } : {},
|
|
4213
|
+
bonusCentibips,
|
|
4214
|
+
...maxBonusAmount ? { maxBonusAmount } : {},
|
|
4215
|
+
fundedBy: r.fundedBy,
|
|
4216
|
+
...typeof r.funderName === "string" && r.funderName ? { funderName: r.funderName } : {},
|
|
4217
|
+
startsAt: r.startsAt,
|
|
4218
|
+
endsAt: r.endsAt
|
|
4219
|
+
};
|
|
4220
|
+
}
|
|
4221
|
+
function parsePromotions(rows, now = Date.now()) {
|
|
4222
|
+
if (!Array.isArray(rows)) return [];
|
|
4223
|
+
return rows.map((row) => parsePromotion(row, now)).filter((p) => !!p);
|
|
4224
|
+
}
|
|
4225
|
+
function bonusPercentLabel(centibips) {
|
|
4226
|
+
const pct = centibips / 1e4;
|
|
4227
|
+
return `${Number(pct.toFixed(4)).toString()}%`;
|
|
4228
|
+
}
|
|
4229
|
+
function sameAddress(a, b) {
|
|
4230
|
+
return a.startsWith("0x") && b.startsWith("0x") ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
4231
|
+
}
|
|
4232
|
+
function sameToken(t, chainId, address) {
|
|
4233
|
+
return t.chainId === chainId && sameAddress(t.address, address);
|
|
4234
|
+
}
|
|
4235
|
+
function promotedAssets(promotions) {
|
|
4236
|
+
const bySymbol = /* @__PURE__ */ new Map();
|
|
4237
|
+
for (const p of promotions) {
|
|
4238
|
+
if (p.kind !== "token") continue;
|
|
4239
|
+
const key2 = p.destination.symbol.toUpperCase();
|
|
4240
|
+
const asset = bySymbol.get(key2) ?? { symbol: p.destination.symbol, maxCentibips: 0, networks: [], fundedBy: p.fundedBy };
|
|
4241
|
+
asset.networks.push({ promotion: p, chainId: p.destination.chainId, address: p.destination.address, bonusCentibips: p.bonusCentibips });
|
|
4242
|
+
if (p.bonusCentibips > asset.maxCentibips) {
|
|
4243
|
+
asset.maxCentibips = p.bonusCentibips;
|
|
4244
|
+
asset.fundedBy = p.fundedBy;
|
|
4245
|
+
}
|
|
4246
|
+
bySymbol.set(key2, asset);
|
|
4247
|
+
}
|
|
4248
|
+
const assets = [...bySymbol.values()];
|
|
4249
|
+
for (const a of assets) a.networks.sort((x, y) => y.bonusCentibips - x.bonusCentibips || x.chainId - y.chainId);
|
|
4250
|
+
return assets.sort((a, b) => b.maxCentibips - a.maxCentibips || a.symbol.localeCompare(b.symbol));
|
|
4251
|
+
}
|
|
4252
|
+
function promotionFor(promotions, ends) {
|
|
4253
|
+
let best;
|
|
4254
|
+
for (const p of promotions) {
|
|
4255
|
+
if (!sameToken(p.destination, ends.toChainId, ends.toAddress)) continue;
|
|
4256
|
+
if (p.kind === "pair") {
|
|
4257
|
+
if (!p.source || ends.fromChainId === void 0 || !ends.fromAddress) continue;
|
|
4258
|
+
if (!sameToken(p.source, ends.fromChainId, ends.fromAddress)) continue;
|
|
4259
|
+
}
|
|
4260
|
+
if (!best || p.bonusCentibips > best.bonusCentibips) best = p;
|
|
4261
|
+
}
|
|
4262
|
+
return best;
|
|
4263
|
+
}
|
|
4264
|
+
function pairPromotionsInto(promotions, chainId, address) {
|
|
4265
|
+
return promotions.filter((p) => p.kind === "pair" && sameToken(p.destination, chainId, address));
|
|
4266
|
+
}
|
|
4267
|
+
function estimateBonus(amount, promotion) {
|
|
4268
|
+
if (amount <= 0n) return 0n;
|
|
4269
|
+
const bonus = amount * BigInt(promotion.bonusCentibips) / BigInt(CENTIBIPS_PER_UNIT);
|
|
4270
|
+
if (promotion.maxBonusAmount) {
|
|
4271
|
+
const cap = BigInt(promotion.maxBonusAmount);
|
|
4272
|
+
return bonus > cap ? cap : bonus;
|
|
4273
|
+
}
|
|
4274
|
+
return bonus;
|
|
4275
|
+
}
|
|
4276
|
+
function fundedByLabel(p) {
|
|
4277
|
+
if (p.fundedBy === "zerodelta") return "Funded by ZeroDelta";
|
|
4278
|
+
return p.funderName ? `Funded by ${p.funderName}` : "Issuer-funded bonus";
|
|
4279
|
+
}
|
|
4280
|
+
function parseBonusUnits(value, decimals) {
|
|
4281
|
+
if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value)) throw new Error("Invalid bonus amount");
|
|
4282
|
+
let [integer = "", fraction = "0"] = value.split(".");
|
|
4283
|
+
const negative = integer.startsWith("-");
|
|
4284
|
+
if (negative) integer = integer.slice(1);
|
|
4285
|
+
fraction = fraction.replace(/(0+)$/, "");
|
|
4286
|
+
if (decimals === 0) {
|
|
4287
|
+
if (Math.round(Number(`.${fraction}`)) === 1) integer = `${BigInt(integer) + 1n}`;
|
|
4288
|
+
fraction = "";
|
|
4289
|
+
} else if (fraction.length > decimals) {
|
|
4290
|
+
const left = fraction.slice(0, decimals - 1);
|
|
4291
|
+
const unit = fraction.slice(decimals - 1, decimals);
|
|
4292
|
+
const right = fraction.slice(decimals);
|
|
4293
|
+
const rounded = Math.round(Number(`${unit}.${right}`));
|
|
4294
|
+
if (rounded > 9) fraction = `${BigInt(left) + 1n}0`.padStart(left.length + 1, "0");
|
|
4295
|
+
else fraction = `${left}${rounded}`;
|
|
4296
|
+
if (fraction.length > decimals) {
|
|
4297
|
+
fraction = fraction.slice(1);
|
|
4298
|
+
integer = `${BigInt(integer) + 1n}`;
|
|
4299
|
+
}
|
|
4300
|
+
fraction = fraction.slice(0, decimals);
|
|
4301
|
+
} else {
|
|
4302
|
+
fraction = fraction.padEnd(decimals, "0");
|
|
4303
|
+
}
|
|
4304
|
+
return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
|
|
4305
|
+
}
|
|
4306
|
+
var PROMOTION_STABLES = /* @__PURE__ */ new Set([...STABLE_ASSETS, "GHO", "USD0", "USDF"]);
|
|
4307
|
+
function usdStablePair(a, b) {
|
|
4308
|
+
return !!a && !!b && PROMOTION_STABLES.has(a.toUpperCase()) && PROMOTION_STABLES.has(b.toUpperCase());
|
|
4309
|
+
}
|
|
4310
|
+
function decimalString(value, decimals) {
|
|
4311
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
4312
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
4313
|
+
return typeof value === "string" && /^\d*\.?\d+$|^\d+\.?$/.test(value) ? value : n.toFixed(Math.min(decimals, 18));
|
|
4314
|
+
}
|
|
4315
|
+
function bonusFigure(promotion, inputs) {
|
|
4316
|
+
const { destination, quote, typed } = inputs;
|
|
4317
|
+
let base = null;
|
|
4318
|
+
if (quote) {
|
|
4319
|
+
const same2 = quote.chainId === destination.chainId && sameAddress(quote.address, destination.address);
|
|
4320
|
+
if (same2 || usdStablePair(quote.symbol, destination.symbol)) base = decimalString(quote.amount, destination.decimals);
|
|
4321
|
+
}
|
|
4322
|
+
if (base === null && typed && usdStablePair(typed.symbol, destination.symbol)) base = decimalString(typed.amount, destination.decimals);
|
|
4323
|
+
if (base === null) return null;
|
|
4324
|
+
try {
|
|
4325
|
+
const bonus = estimateBonus(parseBonusUnits(base, destination.decimals), promotion);
|
|
4326
|
+
return bonus > 0n ? bonus : null;
|
|
4327
|
+
} catch {
|
|
4328
|
+
return null;
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
function insteadFigures(promotion, destination, typed, selectedAmount) {
|
|
4332
|
+
if (!typed) return null;
|
|
4333
|
+
const bonus = bonusFigure(promotion, { destination, typed });
|
|
4334
|
+
const sent = Number(typed.amount);
|
|
4335
|
+
if (bonus === null || !Number.isFinite(sent) || sent <= 0) return null;
|
|
4336
|
+
const total = sent + Number(formatUnits(bonus, destination.decimals, destination.decimals));
|
|
4337
|
+
const more = selectedAmount === null ? null : total - selectedAmount;
|
|
4338
|
+
return { bonus, total, more: more !== null && more > 5e-3 ? more : null };
|
|
4339
|
+
}
|
|
4340
|
+
|
|
4341
|
+
// src/core/quote-request.ts
|
|
4342
|
+
function nativeQuoteRequest(body) {
|
|
4343
|
+
const inputChain = Number(body.fromChainId);
|
|
4344
|
+
const owner = typeof body.owner === "string" && body.owner ? body.owner : void 0;
|
|
4345
|
+
const destinationWallet = typeof body.destinationReceiver === "string" && body.destinationReceiver ? body.destinationReceiver : void 0;
|
|
4346
|
+
const owners = owner ? isSolanaChainId(inputChain) && isSolanaAddress(owner) ? { svm: owner } : { evm: owner } : void 0;
|
|
4347
|
+
const sender = typeof body.sender === "string" ? body.sender : !isSolanaChainId(inputChain) ? owner : void 0;
|
|
4348
|
+
return {
|
|
4349
|
+
inputChain,
|
|
4350
|
+
outputChain: Number(body.toChainId),
|
|
4351
|
+
inputToken: String(body.fromToken ?? ""),
|
|
4352
|
+
outputToken: String(body.toToken ?? ""),
|
|
4353
|
+
inputAmount: String(body.fromAmount ?? ""),
|
|
4354
|
+
...owners ? { owners } : {},
|
|
4355
|
+
...destinationWallet ? { destinationWallet } : {},
|
|
4356
|
+
...sender && owners && destinationWallet ? { sender } : {},
|
|
4357
|
+
// No new deadline, latency limit or subject is invented for EVM quoting. The
|
|
4358
|
+
// gateway derives the subject from owners when this caller has no explicit one.
|
|
4359
|
+
...body.deadline !== void 0 ? { deadline: String(body.deadline) } : {},
|
|
4360
|
+
...typeof body.maxTimeSec === "number" ? { maxTimeSec: body.maxTimeSec } : {},
|
|
4361
|
+
...typeof body.subjectId === "string" ? { subjectId: body.subjectId } : {}
|
|
4362
|
+
};
|
|
4363
|
+
}
|
|
4364
|
+
|
|
2980
4365
|
// src/core/channel.ts
|
|
2981
4366
|
var CHANNEL_HEADER = "x-zd-channel";
|
|
2982
4367
|
var CHANNEL_VERSION_HEADER = "x-zd-channel-version";
|
|
2983
4368
|
var CHANNEL_ORIGIN_HEADER = "x-zd-channel-origin";
|
|
2984
4369
|
var WIDGET_CHANNEL = "widget";
|
|
2985
|
-
var WIDGET_VERSION = "4.
|
|
4370
|
+
var WIDGET_VERSION = "4.19.0" ;
|
|
2986
4371
|
var MAX_CHANNEL_VERSION_LEN = 32;
|
|
2987
4372
|
function sanitizeVersion(raw2) {
|
|
2988
4373
|
const v = String(raw2).trim();
|
|
@@ -3074,7 +4459,7 @@ function classifyQuoteError(error) {
|
|
|
3074
4459
|
function amountFieldError(error) {
|
|
3075
4460
|
const fieldErrors = error?.fieldErrors;
|
|
3076
4461
|
if (!Array.isArray(fieldErrors)) return null;
|
|
3077
|
-
const entry = fieldErrors.find((e) => e && typeof e === "object" && e.field === "fromAmount" && typeof e.message === "string");
|
|
4462
|
+
const entry = fieldErrors.find((e) => e && typeof e === "object" && (e.field === "fromAmount" || e.field === "inputAmount") && typeof e.message === "string");
|
|
3078
4463
|
const message = entry ? sanitizeMessage(entry.message, "") : "";
|
|
3079
4464
|
return message || null;
|
|
3080
4465
|
}
|
|
@@ -3090,7 +4475,7 @@ function wait(ms) {
|
|
|
3090
4475
|
}
|
|
3091
4476
|
var PAGE_LIMIT = 500;
|
|
3092
4477
|
var MAX_PAGES = 10;
|
|
3093
|
-
var newRegistryCache = () => ({ chains: null, tokens: null, routes: null, health: null, vaults: null, inflight: /* @__PURE__ */ new Map() });
|
|
4478
|
+
var newRegistryCache = () => ({ chains: null, tokens: null, routes: null, health: null, vaults: null, promotions: null, inflight: /* @__PURE__ */ new Map() });
|
|
3094
4479
|
var SHARED_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
3095
4480
|
function registryCacheFor(scope) {
|
|
3096
4481
|
if (!scope) return newRegistryCache();
|
|
@@ -3247,6 +4632,20 @@ function createApiClient(cfg) {
|
|
|
3247
4632
|
return value;
|
|
3248
4633
|
});
|
|
3249
4634
|
}
|
|
4635
|
+
function fetchPromotions() {
|
|
4636
|
+
if (nowFresh(cache.promotions)) return Promise.resolve(parsePromotions(cache.promotions.value));
|
|
4637
|
+
return once("promotions", async () => {
|
|
4638
|
+
let value = [];
|
|
4639
|
+
try {
|
|
4640
|
+
const rows = await apiRequest("/promotions", { timeoutMs: 8e3 });
|
|
4641
|
+
value = Array.isArray(rows) ? rows : [];
|
|
4642
|
+
} catch {
|
|
4643
|
+
value = [];
|
|
4644
|
+
}
|
|
4645
|
+
cache.promotions = { at: Date.now(), value };
|
|
4646
|
+
return parsePromotions(value);
|
|
4647
|
+
});
|
|
4648
|
+
}
|
|
3250
4649
|
const priceCache = /* @__PURE__ */ new Map();
|
|
3251
4650
|
async function fetchPrices(symbols) {
|
|
3252
4651
|
const wanted = [...new Set(symbols.map((s) => String(s || "").toUpperCase()).filter((s) => /^[A-Z0-9]{1,16}$/.test(s)))];
|
|
@@ -3277,11 +4676,12 @@ function createApiClient(cfg) {
|
|
|
3277
4676
|
return out;
|
|
3278
4677
|
}
|
|
3279
4678
|
async function fetchQuote(body, retries = 1) {
|
|
4679
|
+
const request = nativeQuoteRequest(body);
|
|
3280
4680
|
let lastError;
|
|
3281
4681
|
for (let attempt = 0; attempt <= retries; attempt += 1) {
|
|
3282
4682
|
try {
|
|
3283
|
-
const quote = await apiRequest("/quote", { method: "POST", body: JSON.stringify(
|
|
3284
|
-
return quote
|
|
4683
|
+
const quote = await apiRequest("/quote", { method: "POST", headers: { "X-ZD-Shape": "native" }, body: JSON.stringify(request), timeoutMs: 18e3 });
|
|
4684
|
+
return normalizeQuoteResponse(quote, request);
|
|
3285
4685
|
} catch (error) {
|
|
3286
4686
|
lastError = error;
|
|
3287
4687
|
if (attempt >= retries || !isTransientQuoteError(error)) throw error;
|
|
@@ -3295,10 +4695,10 @@ function createApiClient(cfg) {
|
|
|
3295
4695
|
if (!addr) throw apiError("An address is required to screen a wallet.", { code: "bad_request" });
|
|
3296
4696
|
const solana = isSolanaChainId(chainId) || isSolanaAddress(addr);
|
|
3297
4697
|
if (solana && !isSolanaAddress(addr)) throw apiError("Not a valid Solana address.", { code: "bad_request" });
|
|
3298
|
-
const
|
|
3299
|
-
const hit = screenCache.get(
|
|
4698
|
+
const key2 = solana ? "solana|" + addr : (/^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr) + "|" + (chainId ?? "");
|
|
4699
|
+
const hit = screenCache.get(key2);
|
|
3300
4700
|
if (hit && Date.now() - hit.at < SCREEN_CACHE_TTL_MS) return hit.value;
|
|
3301
|
-
const inflight = screenInflight.get(
|
|
4701
|
+
const inflight = screenInflight.get(key2);
|
|
3302
4702
|
if (inflight) return inflight;
|
|
3303
4703
|
const request = apiRequest("/screen/wallet", {
|
|
3304
4704
|
method: "POST",
|
|
@@ -3309,12 +4709,12 @@ function createApiClient(cfg) {
|
|
|
3309
4709
|
throw apiError("Compliance screening returned an unusable result.", { code: "bad_response" });
|
|
3310
4710
|
}
|
|
3311
4711
|
const value = { ...screen, address: screen.address || addr };
|
|
3312
|
-
screenCache.set(
|
|
4712
|
+
screenCache.set(key2, { at: Date.now(), value });
|
|
3313
4713
|
return value;
|
|
3314
4714
|
}).finally(() => {
|
|
3315
|
-
screenInflight.delete(
|
|
4715
|
+
screenInflight.delete(key2);
|
|
3316
4716
|
});
|
|
3317
|
-
screenInflight.set(
|
|
4717
|
+
screenInflight.set(key2, request);
|
|
3318
4718
|
return request;
|
|
3319
4719
|
}
|
|
3320
4720
|
async function reportSubmission(report) {
|
|
@@ -3337,7 +4737,7 @@ function createApiClient(cfg) {
|
|
|
3337
4737
|
return false;
|
|
3338
4738
|
}
|
|
3339
4739
|
}
|
|
3340
|
-
return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchQuote, screenWallet, reportSubmission, apiBase };
|
|
4740
|
+
return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchRwaVaults, fetchPrices, fetchPromotions, fetchQuote, screenWallet, reportSubmission, apiBase };
|
|
3341
4741
|
}
|
|
3342
4742
|
|
|
3343
4743
|
// src/core/plan.ts
|
|
@@ -3400,9 +4800,9 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
|
|
|
3400
4800
|
const balanceTargets = [];
|
|
3401
4801
|
const seenTargets = /* @__PURE__ */ new Set();
|
|
3402
4802
|
for (const option of options) {
|
|
3403
|
-
const
|
|
3404
|
-
if (seenTargets.has(
|
|
3405
|
-
seenTargets.add(
|
|
4803
|
+
const key2 = optionBalanceKey(option);
|
|
4804
|
+
if (seenTargets.has(key2)) continue;
|
|
4805
|
+
seenTargets.add(key2);
|
|
3406
4806
|
balanceTargets.push({ chainId: option.chainId, tokenAddress: option.address, decimals: option.decimals });
|
|
3407
4807
|
}
|
|
3408
4808
|
const walletBalances = readBalances ? await readBalances(payer, balanceTargets).catch(() => ({})) : {};
|
|
@@ -3414,9 +4814,9 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
|
|
|
3414
4814
|
for (const raw2 of [payer, destination.address]) {
|
|
3415
4815
|
const addr = String(raw2 || "").trim();
|
|
3416
4816
|
if (!addr) continue;
|
|
3417
|
-
const
|
|
3418
|
-
if (seenParty.has(
|
|
3419
|
-
seenParty.add(
|
|
4817
|
+
const key2 = /^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr;
|
|
4818
|
+
if (seenParty.has(key2)) continue;
|
|
4819
|
+
seenParty.add(key2);
|
|
3420
4820
|
parties.push(addr);
|
|
3421
4821
|
}
|
|
3422
4822
|
try {
|
|
@@ -3463,6 +4863,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
|
|
|
3463
4863
|
destinationToken,
|
|
3464
4864
|
chains,
|
|
3465
4865
|
tokens,
|
|
4866
|
+
routes,
|
|
3466
4867
|
payer,
|
|
3467
4868
|
fetchQuote: api.fetchQuote,
|
|
3468
4869
|
compliance: option.direct ? directCompliance ?? void 0 : void 0
|
|
@@ -3523,7 +4924,7 @@ async function quotePayOption(api, request, payer, picked, wallet = {}) {
|
|
|
3523
4924
|
(o) => !o.direct && Number(o.chainId) === Number(picked.chainId) && chainAddressKey(o.chainId, o.address) === chainAddressKey(picked.chainId, picked.address) && (!allowedFunding || allowedFunding.has(o.symbolKey))
|
|
3524
4925
|
);
|
|
3525
4926
|
if (!option) throw new Error("That funding option is not available for this payment right now.");
|
|
3526
|
-
return buildRoute({ option, destination, destinationToken, chains, tokens, payer, fetchQuote: api.fetchQuote });
|
|
4927
|
+
return buildRoute({ option, destination, destinationToken, chains, tokens, routes, payer, fetchQuote: api.fetchQuote });
|
|
3527
4928
|
}
|
|
3528
4929
|
|
|
3529
4930
|
// src/core/swap.ts
|
|
@@ -3531,13 +4932,13 @@ function validateSwap(swap = {}) {
|
|
|
3531
4932
|
const fromChainId = Number(swap.fromChainId);
|
|
3532
4933
|
const toChainId = Number(swap.toChainId);
|
|
3533
4934
|
const fromToken = symbolKey(swap.fromToken);
|
|
3534
|
-
const
|
|
4935
|
+
const toToken2 = symbolKey(swap.toToken);
|
|
3535
4936
|
if (!SUPPORTED_CHAIN_IDS.has(fromChainId)) throw new Error("Unsupported swap chain.");
|
|
3536
4937
|
if (!Number.isSafeInteger(toChainId) || toChainId <= 0) throw new Error("Unsupported swap chain.");
|
|
3537
|
-
if (!SUPPORTED_ASSETS.has(fromToken) || !SUPPORTED_ASSETS.has(
|
|
4938
|
+
if (!SUPPORTED_ASSETS.has(fromToken) || !SUPPORTED_ASSETS.has(toToken2)) throw new Error("Unsupported swap asset.");
|
|
3538
4939
|
const amountIn = normalizeDecimalText(swap.amountIn);
|
|
3539
4940
|
if (!/^\d+(\.\d+)?$/.test(amountIn) || Number(amountIn) <= 0 || Number(amountIn) > 1e9) throw new Error("Enter a valid swap amount.");
|
|
3540
|
-
return { fromChainId, toChainId, fromToken, toToken, amountIn };
|
|
4941
|
+
return { fromChainId, toChainId, fromToken, toToken: toToken2, amountIn };
|
|
3541
4942
|
}
|
|
3542
4943
|
function viaOf(quote, tokens) {
|
|
3543
4944
|
const orders = Array.isArray(quote.orderRequests) ? quote.orderRequests : [];
|
|
@@ -3587,7 +4988,7 @@ async function quoteSwapPreview(api, swap, owner) {
|
|
|
3587
4988
|
async function buildSwapPlan(api, swap, payer, wallet = {}) {
|
|
3588
4989
|
const v = validateSwap(swap);
|
|
3589
4990
|
const account = assertAddress(payer, "Swap wallet");
|
|
3590
|
-
const [chains, tokens] = await Promise.all([api.fetchChains(), api.fetchTokens()]);
|
|
4991
|
+
const [chains, tokens, routes] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes()]);
|
|
3591
4992
|
const sourceToken = findToken(tokens, v.fromChainId, v.fromToken);
|
|
3592
4993
|
const destToken = findToken(tokens, v.toChainId, v.toToken);
|
|
3593
4994
|
if (!sourceToken) throw new Error(`${v.fromToken} is not enabled on ${chainNameOf(v.fromChainId, chains)}.`);
|
|
@@ -3610,7 +5011,7 @@ async function buildSwapPlan(api, swap, payer, wallet = {}) {
|
|
|
3610
5011
|
direct: false
|
|
3611
5012
|
};
|
|
3612
5013
|
const destination = { address: receiver, chainId: v.toChainId, asset: destToken.symbol };
|
|
3613
|
-
const route = await buildRoute({ option, destination, destinationToken: destToken, chains, tokens, payer: account, fetchQuote: api.fetchQuote, solve: solveExactIn, amountInRaw });
|
|
5014
|
+
const route = await buildRoute({ option, destination, destinationToken: destToken, chains, tokens, routes, payer: account, fetchQuote: api.fetchQuote, solve: solveExactIn, amountInRaw });
|
|
3614
5015
|
if (route.state === "SHORT") throw new Error("ZeroDelta could not price this swap right now.");
|
|
3615
5016
|
route.recommended = true;
|
|
3616
5017
|
return {
|
|
@@ -3631,88 +5032,6 @@ async function buildSwapPlan(api, swap, payer, wallet = {}) {
|
|
|
3631
5032
|
};
|
|
3632
5033
|
}
|
|
3633
5034
|
|
|
3634
|
-
// src/core/validate-tx.ts
|
|
3635
|
-
var lower = (v) => String(v || "").toLowerCase();
|
|
3636
|
-
function isHexAddress(value) {
|
|
3637
|
-
return /^0x[a-fA-F0-9]{40}$/.test(String(value || ""));
|
|
3638
|
-
}
|
|
3639
|
-
function isHexData(value) {
|
|
3640
|
-
return /^0x(?:[a-fA-F0-9]{2})*$/.test(String(value || "0x"));
|
|
3641
|
-
}
|
|
3642
|
-
function isHexQuantity(value) {
|
|
3643
|
-
return /^0x[0-9a-fA-F]+$/.test(String(value || "0x0"));
|
|
3644
|
-
}
|
|
3645
|
-
function dataWord(data, index) {
|
|
3646
|
-
const word2 = String(data || "").slice(10 + index * 64, 10 + (index + 1) * 64);
|
|
3647
|
-
return /^[a-fA-F0-9]{64}$/.test(word2) ? word2 : "";
|
|
3648
|
-
}
|
|
3649
|
-
function dataAddress(data, index) {
|
|
3650
|
-
const word2 = dataWord(data, index);
|
|
3651
|
-
return word2 ? `0x${word2.slice(24)}` : "";
|
|
3652
|
-
}
|
|
3653
|
-
function dataUint(data, index) {
|
|
3654
|
-
const word2 = dataWord(data, index);
|
|
3655
|
-
return word2 ? BigInt(`0x${word2}`) : null;
|
|
3656
|
-
}
|
|
3657
|
-
function rawEquals(value, expected) {
|
|
3658
|
-
try {
|
|
3659
|
-
return value === BigInt(expected || "0");
|
|
3660
|
-
} catch {
|
|
3661
|
-
return false;
|
|
3662
|
-
}
|
|
3663
|
-
}
|
|
3664
|
-
function planMsgValueHex(route) {
|
|
3665
|
-
try {
|
|
3666
|
-
const raw2 = route?.quote?.msgValue;
|
|
3667
|
-
if (raw2 === void 0 || raw2 === null || raw2 === "") return "0x0";
|
|
3668
|
-
return "0x" + BigInt(raw2).toString(16);
|
|
3669
|
-
} catch {
|
|
3670
|
-
return null;
|
|
3671
|
-
}
|
|
3672
|
-
}
|
|
3673
|
-
function validatePlannedTransaction(tx, route, expectedRecipient) {
|
|
3674
|
-
if (!tx || tx.mock) return true;
|
|
3675
|
-
if (!isHexAddress(tx.to) || !isHexData(tx.data || "0x") || !isHexQuantity(tx.value || "0x0")) return false;
|
|
3676
|
-
const data = String(tx.data || "0x").toLowerCase();
|
|
3677
|
-
const selector = data.slice(0, 10);
|
|
3678
|
-
const value = lower(tx.value || "0x0");
|
|
3679
|
-
if (tx.kind === "transfer") {
|
|
3680
|
-
if (value !== "0x0") return false;
|
|
3681
|
-
return selector === "0xa9059cbb" && isHexAddress(tx.token) && lower(tx.to) === lower(tx.token) && lower(dataAddress(data, 0)) === lower(expectedRecipient) && rawEquals(dataUint(data, 1), tx.amountRaw);
|
|
3682
|
-
}
|
|
3683
|
-
if (tx.kind === "approve") {
|
|
3684
|
-
if (value !== "0x0") return false;
|
|
3685
|
-
return selector === "0x095ea7b3" && isHexAddress(tx.token) && isHexAddress(tx.spender) && lower(tx.to) === lower(tx.token) && lower(dataAddress(data, 0)) === lower(tx.spender) && rawEquals(dataUint(data, 1), tx.amountRaw);
|
|
3686
|
-
}
|
|
3687
|
-
if (tx.kind === "submitOrder") {
|
|
3688
|
-
const expected = planMsgValueHex(route);
|
|
3689
|
-
if (expected === null || value !== lower(expected)) return false;
|
|
3690
|
-
if (selector !== SUBMIT_ORDER_SELECTOR || !isHexAddress(tx.escrow) || lower(tx.to) !== lower(tx.escrow)) return false;
|
|
3691
|
-
const decoded = decodeSubmitOrderCalldata(data);
|
|
3692
|
-
if (!decoded) return false;
|
|
3693
|
-
const first = decoded.orders[0];
|
|
3694
|
-
const last = decoded.orders[decoded.orders.length - 1];
|
|
3695
|
-
return decoded.partnerId === lower(route.quote?.partnerId || NO_PARTNER_ID) && lower(first.bidToken) === lower(route.source.tokenAddress) && rawEquals(first.bidTokenAmount, tx.amountRaw) && lower(last.askToken) === lower(isSolanaChainId(route.receive.chainId) ? solanaKeyHex(route.receive.tokenAddress || "") : route.receive.tokenAddress) && Number(last.destinationChainId) === Number(route.receive.chainId) && (isSolanaChainId(route.receive.chainId) ? solanaDeliveryMatches(last.destinationReceiver, expectedRecipient, route.receive.tokenAddress) : lower(last.destinationReceiver) === lower(expectedRecipient));
|
|
3696
|
-
}
|
|
3697
|
-
return false;
|
|
3698
|
-
}
|
|
3699
|
-
function solanaDeliveryMatches(encoded, recipient2, mint) {
|
|
3700
|
-
try {
|
|
3701
|
-
return lower(encoded) === expectedSolanaDelivery(recipient2, mint || "");
|
|
3702
|
-
} catch {
|
|
3703
|
-
return false;
|
|
3704
|
-
}
|
|
3705
|
-
}
|
|
3706
|
-
async function allowanceCovers(tx, account, ethCall) {
|
|
3707
|
-
if (tx?.kind !== "approve" || !tx.token || !tx.spender || !tx.amountRaw || !account) return false;
|
|
3708
|
-
try {
|
|
3709
|
-
const raw2 = await ethCall(tx.token, encodeAllowance(account, tx.spender));
|
|
3710
|
-
return BigInt(raw2 || "0x0") >= BigInt(tx.amountRaw || "0");
|
|
3711
|
-
} catch {
|
|
3712
|
-
return false;
|
|
3713
|
-
}
|
|
3714
|
-
}
|
|
3715
|
-
|
|
3716
5035
|
// src/core/intent-schema.ts
|
|
3717
5036
|
var STABLEGENIE_INTENT_VERSION = 1;
|
|
3718
5037
|
var STABLEGENIE_INTENT_TTL_MS = 5 * 60 * 1e3;
|
|
@@ -3917,9 +5236,9 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
3917
5236
|
const seen = /* @__PURE__ */ new Set();
|
|
3918
5237
|
for (const target of targets) {
|
|
3919
5238
|
if (!target || !isAddress(target.tokenAddress)) continue;
|
|
3920
|
-
const
|
|
3921
|
-
if (seen.has(
|
|
3922
|
-
seen.add(
|
|
5239
|
+
const key2 = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
5240
|
+
if (seen.has(key2)) continue;
|
|
5241
|
+
seen.add(key2);
|
|
3923
5242
|
const chainId = Number(target.chainId);
|
|
3924
5243
|
const group = groups.get(chainId) || [];
|
|
3925
5244
|
group.push(target);
|
|
@@ -3928,8 +5247,8 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
3928
5247
|
function record(target, hex) {
|
|
3929
5248
|
if (typeof hex !== "string" || !/^0x[0-9a-fA-F]*$/.test(hex)) return false;
|
|
3930
5249
|
const raw2 = BigInt(hex || "0x0").toString();
|
|
3931
|
-
const
|
|
3932
|
-
out[
|
|
5250
|
+
const key2 = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
5251
|
+
out[key2] = { raw: raw2, formatted: formatUnits(raw2, Number(target.decimals)) };
|
|
3933
5252
|
return true;
|
|
3934
5253
|
}
|
|
3935
5254
|
async function readOne(rpcUrl, target) {
|
|
@@ -3975,7 +5294,18 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
3975
5294
|
return null;
|
|
3976
5295
|
}
|
|
3977
5296
|
}
|
|
3978
|
-
|
|
5297
|
+
async function readZdHeavySubmitFee(chainId, to, data) {
|
|
5298
|
+
try {
|
|
5299
|
+
const override = rpcOverrides[Number(chainId)];
|
|
5300
|
+
const rpc = override && /^https?:\/\//i.test(override) ? override : BUNDLED_RPC[Number(chainId)];
|
|
5301
|
+
if (!rpc) return void 0;
|
|
5302
|
+
const result = await rpcCall(rpc, "eth_call", [{ to, data: quoteSubmitCalldata(data) }, "latest"]);
|
|
5303
|
+
return typeof result === "string" && /^0x[0-9a-fA-F]{64}$/.test(result) ? BigInt(result) : void 0;
|
|
5304
|
+
} catch {
|
|
5305
|
+
return void 0;
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
return { payerNonceBaseline, verifySubmittedTx, readBalances, readNativeBalance, readZdHeavySubmitFee };
|
|
3979
5309
|
}
|
|
3980
5310
|
|
|
3981
5311
|
// src/core/config.ts
|
|
@@ -4096,6 +5426,7 @@ function createEngine(config = {}) {
|
|
|
4096
5426
|
fetchRouteHealth: api.fetchRouteHealth,
|
|
4097
5427
|
fetchQuote: api.fetchQuote,
|
|
4098
5428
|
fetchPrices: (symbols) => api.fetchPrices ? api.fetchPrices(symbols) : Promise.resolve({}),
|
|
5429
|
+
fetchPromotions: () => api.fetchPromotions ? api.fetchPromotions() : Promise.resolve([]),
|
|
4099
5430
|
fetchCatalogue: async (allowedAssets, product, options) => {
|
|
4100
5431
|
const [chains, registryTokens, routes, health, vaults] = await Promise.all([
|
|
4101
5432
|
api.fetchChains().catch(() => []),
|
|
@@ -4151,4 +5482,4 @@ function createEngine(config = {}) {
|
|
|
4151
5482
|
};
|
|
4152
5483
|
}
|
|
4153
5484
|
|
|
4154
|
-
export { API_CACHE_TTL_MS, BLOCK_LABEL_DEFAULT, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, BUNDLED_SOLANA_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CANONICAL_SOLANA_PROGRAM, CHAIN_DISPLAY_NAMES, COMPLIANCE_CHECK_ORDER, COMPLIANCE_DENY_LABEL, DEFAULT_WIDGET_API_BASE, DIRECT_CHECK_IDS, DIRECT_SCOPE_NOTE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, FLOOR_CATEGORIES, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, SCREENING_BUCKETS, SCREEN_CACHE_TTL_MS, SOLANA_CHAIN_ID, SOLANA_DESTINATION_ASSETS, SOL_SHORTFALL_MESSAGE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, STABLE_ASSETS, SUBMIT_ORDER_DISCRIMINATOR, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, SolanaSendError, TOKEN_2022_PROGRAM, TOKEN_PROGRAM, TRACKING, TRADEABLE_RWA_ASSETS, TUNABLE_CATEGORIES, WALLET_HISTORY_LIMIT, ZERO_ADDRESS, addressWord, allowanceCovers, amountFieldError, apiError, applyLayerZeroBuffer, askCovers, askTokenDecimals, assertAddress, assertChainAddress, assertQuoteMatchesSelection, assertWalletMessage, assetClassOf, assetDecimals, associatedTokenAddress, base58Decode, base58Encode, base64Decode, base64Encode, blockLabelFor, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSolanaSourcePlan, buildSwapPlan, bytes32Word, bytesEqual, bytesPayload, canAttachApiKey, categoryLabel, chainAddressKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, checkSolanaPlan, checkSolanaProgram, checkSolanaReceiver, checkSolanaRouteBuffer, classifyQuoteError, complianceChecks, complianceControlsEvaluated, complianceControlsLine, complianceReasonHead, complianceReasonTag, complianceTagOf, complianceView, cosignSolanaEvent, counterpartTokens, createApiClient, createEngine, createSolanaRpc, createVerifier, decodeSolanaSubmitOrder, decodeSubmitOrderCalldata, deriveSolanaEvent, destinationAvailability, destinationKeys, directComplianceFromScreens, distinctScreenedWallets, encodeAllowance, encodeApprove, encodeBalanceOf, encodeNextSolanaOrders, encodeSubmitOrder, encodeTransfer, exceedsLaneLimit, executableRoutes, executeSolanaPlan, executeSolanaPlanStaged, executionChainIds, expectedSolanaDelivery, fetchDelivery, fetchPaymentPlan, fetchWalletHistory, finalOf, findProgramAddress, findToken, foldTicker, formatJurisdiction, formatNative, formatUnits, hasReachableDestination, hexBytes, hexToSolanaKey, historyEntryFromOrder, historyKey, hubDeliverableSymbols, humanizeComplianceReason, isAddress, isChainAddress, isDeliverable, isExecutableBridge, isHexAddress, isHexData, isHexQuantity, isKnownUnbridgeable, isLayerZeroRoute, isOnEd25519Curve, isPreparationInstruction, isSellableRwa, isSolanaAddress, isSolanaChainId, isSourceToken, isSubmitOrder, laneAvailabilityState, laneKey, laneKeys, laneLimitAmount, laneLimitError, laneLimitFor, laneLimitHint, laneLimitSymbol, limitedLanes, maxDeadlineSeconds, maxNativeFeeWei, mergeHistory, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeDelivery, normalizeOrderRequest, normalizeOrderRequests, overwriteBlockhash, parseAddressLookupTable, parseAllowedApiBase, parseSolanaTransaction, parseUnitsDecimal, placeSignature, planErrorSummary, planMsgValueHex, pollSolanaConfirmation, previewSolanaSource, productAssets, quotePartnerId, quotePayOption, quoteSolanaSource, quoteSwapPreview, readSolanaBalance, recommendedDeadlineSeconds, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSolanaKeys, resolveSwapReceiver, resolveVaultIcon, routeNativeValue, safeTicker, scaleDecimals, screeningOutcomeOf, serializeSolanaTransaction, sha256, simulateSolanaCost, solanaBridgeOf, solanaDestinationAsset, solanaKeyBytes, solanaKeyHex, solanaLamportShortfall, solanaPlanNeedsPreparation, solanaQuoteCompliance, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, tickerOn, toHexQuantity, tokenEnabled, tokenKey, tokenTicker, txMatchesPlan, uint64Word, uintWord, unattributedComplianceReasons, validateDestination, validatePlannedTransaction, validateSwap, vaultIconsBySymbol, verifySolanaSubmit, verifySolanaTransaction, withVaultArtwork };
|
|
5485
|
+
export { API_CACHE_TTL_MS, BLOCK_LABEL_DEFAULT, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, BUNDLED_SOLANA_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CANONICAL_SOLANA_PROGRAM, CENTIBIPS_PER_UNIT, CHAIN_DISPLAY_NAMES, COMPLIANCE_CHECK_ORDER, COMPLIANCE_DENY_LABEL, DEFAULT_WIDGET_API_BASE, DIRECT_CHECK_IDS, DIRECT_SCOPE_NOTE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, FLOOR_CATEGORIES, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_QUOTE_CARDS, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, SCREENING_BUCKETS, SCREEN_CACHE_TTL_MS, SOLANA_CHAIN_ID, SOLANA_DESTINATION_ASSETS, SOL_SHORTFALL_MESSAGE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, STABLE_ASSETS, SUBMIT_ORDER_DISCRIMINATOR, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, SolanaSendError, TOKEN_2022_PROGRAM, TOKEN_PROGRAM, TRACKING, TRADEABLE_RWA_ASSETS, TUNABLE_CATEGORIES, WAIT_MAX_SEC, WAIT_MIN_SEC, WAIT_POSITIONS, WAIT_STEP_SEC, WALLET_HISTORY_LIMIT, ZD_HEAVY_KEY_PREFIX, ZERO_ADDRESS, addressWord, allowanceCovers, amountFieldError, apiError, applyLayerZeroBuffer, askCovers, askTokenDecimals, assertAddress, assertChainAddress, assertQuoteMatchesSelection, assertWalletMessage, assetClassOf, assetDecimals, associatedTokenAddress, base58Decode, base58Encode, base64Decode, base64Encode, bestOutputOption, blockLabelFor, bonusFigure, bonusPercentLabel, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSolanaSourcePlan, buildSwapPlan, bytes32Word, bytesEqual, bytesPayload, canAttachApiKey, categoryLabel, chainAddressKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, checkSolanaPlan, checkSolanaProgram, checkSolanaReceiver, checkSolanaRouteBuffer, clampWait, classifyQuoteError, compareAmount, compareDuration, compareFeeUsd, compareHops, compareOptionOf, compareOptionsOf, complianceChecks, complianceControlsEvaluated, complianceControlsLine, complianceReasonHead, complianceReasonTag, complianceTagOf, complianceView, cornerTags, cosignSolanaEvent, counterpartTokens, createApiClient, createEngine, createSolanaRpc, createVerifier, decodeSolanaSubmitOrder, decodeSubmitOrderCalldata, deriveSolanaEvent, destinationAvailability, destinationKeys, directComplianceFromScreens, distinctScreenedWallets, encodeAllowance, encodeApprove, encodeBalanceOf, encodeNextSolanaOrders, encodeSubmitOrder, encodeTransfer, estimateBonus, exceedsLaneLimit, executableRoutes, executeSolanaPlan, executeSolanaPlanStaged, executionChainIds, expectedSolanaDelivery, extraVsFastest, fastestOption, fetchDelivery, fetchPaymentPlan, fetchWalletHistory, finalOf, findProgramAddress, findToken, foldTicker, formatJurisdiction, formatNative, formatUnits, fundedByLabel, hasReachableDestination, hasValidChecksum, hexBytes, hexToSolanaKey, historyEntryFromOrder, historyKey, hubDeliverableSymbols, humanizeComplianceReason, insteadFigures, isAddress, isChainAddress, isDeliverable, isExecutableBridge, isHexAddress, isHexData, isHexQuantity, isKnownUnbridgeable, isLayerZeroRoute, isOnEd25519Curve, isPreparationInstruction, isSellableRwa, isSolanaAddress, isSolanaChainId, isSourceToken, isSubmitOrder, laneAvailabilityState, laneKey, laneKeys, laneLimitAmount, laneLimitError, laneLimitFor, laneLimitHint, laneLimitSymbol, limitedLanes, maxDeadlineSeconds, maxNativeFeeWei, mergeHistory, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeDelivery, normalizeOrderRequest, normalizeOrderRequests, overwriteBlockhash, pairPromotionsInto, parity, parseAddressLookupTable, parseAllowedApiBase, parsePromotion, parsePromotions, parseSolanaTransaction, parseUnitsDecimal, pickForWait, placeSignature, planErrorSummary, planMsgValueHex, pollSolanaConfirmation, preflightZdHeavyPlan, previewSolanaSource, priceCompareOptions, productAssets, promotedAssets, promotionFor, proposedWait, quotePartnerId, quotePayOption, quoteSolanaSource, quoteSwapPreview, readSolanaBalance, recommendedDeadlineSeconds, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSolanaKeys, resolveSwapReceiver, resolveVaultIcon, resultForOption, routeBadges, routeNativeValue, routeShapeLabel, safeTicker, sameAddress, scaleDecimals, screeningOutcomeOf, selectableOptions, serializeSolanaTransaction, sha256, simulateSolanaCost, snapWait, solanaBridgeOf, solanaDestinationAsset, solanaKeyBytes, solanaKeyHex, solanaLamportShortfall, solanaPlanNeedsPreparation, solanaQuoteCompliance, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, tickerOn, toHexQuantity, tokenEnabled, tokenKey, tokenTicker, txMatchesPlan, uint64Word, uintWord, unattributedComplianceReasons, usdStablePair, validateDestination, validatePlannedTransaction, validateSwap, vaultIconsBySymbol, verifySolanaSubmit, verifySolanaTransaction, visibleOptions, waitFraction, waitFromFraction, waitLabel, waitScaleFor, withVaultArtwork, zdHeavyExpected, zdHeavyOptionKey, zdHeavyUnavailableStatus };
|