@glacislabs/stablegenie-zerodelta 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-VL5MWEY2.js → chunk-AZPTL3KD.js} +92 -22
- package/dist/{chunk-DH7QYQG4.js → chunk-TR2XMP7X.js} +242 -48
- package/dist/core/index.cjs +92 -22
- package/dist/core/index.d.cts +11 -9
- package/dist/core/index.d.ts +11 -9
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +333 -69
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{mount-yTJi4VdA.d.ts → mount-8nchcNbL.d.ts} +1 -1
- package/dist/{mount-yqXrDBLc.d.cts → mount-BC5gY1X6.d.cts} +1 -1
- package/dist/mount.cjs +333 -69
- 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 +8 -8
- package/dist/{verify-CaO0OD4Z.d.cts → verify-DFTuQ2g3.d.cts} +9 -1
- package/dist/{verify-CaO0OD4Z.d.ts → verify-DFTuQ2g3.d.ts} +9 -1
- package/package.json +1 -1
|
@@ -856,6 +856,16 @@ function createApiClient(cfg) {
|
|
|
856
856
|
}
|
|
857
857
|
|
|
858
858
|
// src/core/plan.ts
|
|
859
|
+
function optionBalanceKey(option) {
|
|
860
|
+
return `${Number(option.chainId)}:${String(option.address || "").toLowerCase()}`;
|
|
861
|
+
}
|
|
862
|
+
function hasPositiveBalance(option, balances) {
|
|
863
|
+
try {
|
|
864
|
+
return BigInt(balances[optionBalanceKey(option)]?.raw ?? "0") > 0n;
|
|
865
|
+
} catch {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
859
869
|
function validateDestination(destination) {
|
|
860
870
|
assertAddress(destination.address, "Destination address");
|
|
861
871
|
const chainId = Number(destination.chainId);
|
|
@@ -871,7 +881,7 @@ function planErrorSummary(errors) {
|
|
|
871
881
|
const unique = [...new Set(errors.map((error) => error?.message || String(error)).filter(Boolean))].slice(0, 3);
|
|
872
882
|
return unique.length ? unique.join(" | ") : "No ZeroDelta route is currently available for this payment.";
|
|
873
883
|
}
|
|
874
|
-
async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
884
|
+
async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances) {
|
|
875
885
|
validateDestination(request);
|
|
876
886
|
assertAddress(payer, "Payer wallet");
|
|
877
887
|
const [chains, tokens, routes] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes()]);
|
|
@@ -882,6 +892,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
882
892
|
};
|
|
883
893
|
const destinationToken = findToken(tokens, destination.chainId, destination.asset);
|
|
884
894
|
if (!destinationToken) throw new Error(`${destination.asset} is not enabled on ${chainNameOf(destination.chainId, chains)}.`);
|
|
895
|
+
const allowedFunding = wallet.fundingAssets?.length ? new Set(wallet.fundingAssets.map(symbolKey)) : null;
|
|
885
896
|
const options = buildPayOptions({
|
|
886
897
|
invoiceAsset: destination.asset,
|
|
887
898
|
invoiceChainId: destination.chainId,
|
|
@@ -889,14 +900,25 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
889
900
|
routes,
|
|
890
901
|
chains,
|
|
891
902
|
walletChainId: wallet?.chainId
|
|
892
|
-
});
|
|
903
|
+
}).filter((option) => option.direct || !allowedFunding || allowedFunding.has(option.symbolKey));
|
|
893
904
|
if (!options.length) throw new Error(`No enabled ZeroDelta funding assets can settle ${destination.asset} on ${chainNameOf(destination.chainId, chains)}.`);
|
|
905
|
+
const balanceTargets = [];
|
|
906
|
+
const seenTargets = /* @__PURE__ */ new Set();
|
|
907
|
+
for (const option of options) {
|
|
908
|
+
const key = optionBalanceKey(option);
|
|
909
|
+
if (seenTargets.has(key)) continue;
|
|
910
|
+
seenTargets.add(key);
|
|
911
|
+
balanceTargets.push({ chainId: option.chainId, tokenAddress: option.address, decimals: option.decimals });
|
|
912
|
+
}
|
|
913
|
+
const walletBalances = readBalances ? await readBalances(payer, balanceTargets).catch(() => ({})) : {};
|
|
894
914
|
const candidates = options.filter((option) => option.direct);
|
|
915
|
+
const heldOptions = options.filter((option) => !option.direct && hasPositiveBalance(option, walletBalances));
|
|
916
|
+
const heldKeys = new Set(heldOptions.map(optionBalanceKey));
|
|
895
917
|
const seenChains = /* @__PURE__ */ new Set();
|
|
896
918
|
const perChainBest = [];
|
|
897
919
|
const leftovers = [];
|
|
898
920
|
for (const option of options) {
|
|
899
|
-
if (option.direct) continue;
|
|
921
|
+
if (option.direct || heldKeys.has(optionBalanceKey(option))) continue;
|
|
900
922
|
if (seenChains.has(option.chainId)) {
|
|
901
923
|
leftovers.push(option);
|
|
902
924
|
} else {
|
|
@@ -904,7 +926,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
904
926
|
perChainBest.push(option);
|
|
905
927
|
}
|
|
906
928
|
}
|
|
907
|
-
for (const option of [...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
929
|
+
for (const option of [...heldOptions, ...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
908
930
|
candidates.push(option);
|
|
909
931
|
}
|
|
910
932
|
const routeErrors = [];
|
|
@@ -939,6 +961,8 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
939
961
|
expiresAt: new Date(Date.now() + 2 * 60 * 1e3).toISOString(),
|
|
940
962
|
apiBase: api.apiBase,
|
|
941
963
|
routes: routesBuilt,
|
|
964
|
+
fundingBalances: walletBalances,
|
|
965
|
+
fundingAccount: payer.toLowerCase(),
|
|
942
966
|
destination: {
|
|
943
967
|
asset: destinationToken.symbol,
|
|
944
968
|
chainId: destination.chainId,
|
|
@@ -1219,6 +1243,23 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
1219
1243
|
const json = await response.json();
|
|
1220
1244
|
return json?.result ?? null;
|
|
1221
1245
|
}
|
|
1246
|
+
async function rpcBatchCall(rpcUrl, calls) {
|
|
1247
|
+
const response = await fetchImpl(rpcUrl, {
|
|
1248
|
+
method: "POST",
|
|
1249
|
+
headers: { "Content-Type": "application/json" },
|
|
1250
|
+
body: JSON.stringify(calls.map((call, index) => ({ jsonrpc: "2.0", id: index + 1, ...call }))),
|
|
1251
|
+
signal: AbortSignal.timeout(TX_VERIFY_FETCH_MS)
|
|
1252
|
+
});
|
|
1253
|
+
if (!response.ok) throw new Error(`RPC ${response.status}`);
|
|
1254
|
+
const json = await response.json();
|
|
1255
|
+
if (!Array.isArray(json)) throw new Error("RPC batch unsupported");
|
|
1256
|
+
const results = /* @__PURE__ */ new Map();
|
|
1257
|
+
for (const item of json) {
|
|
1258
|
+
const id = Number(item?.id);
|
|
1259
|
+
if (Number.isInteger(id) && Object.hasOwn(item || {}, "result")) results.set(id, item.result);
|
|
1260
|
+
}
|
|
1261
|
+
return results;
|
|
1262
|
+
}
|
|
1222
1263
|
async function payerNonceBaseline(chainId, account) {
|
|
1223
1264
|
if (!isAddress(account)) return null;
|
|
1224
1265
|
const rpcUrl = await chainRpcUrl(chainId);
|
|
@@ -1285,25 +1326,54 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
1285
1326
|
const out = {};
|
|
1286
1327
|
if (!isAddress(account) || !Array.isArray(targets) || !targets.length) return out;
|
|
1287
1328
|
const owner = normalizeAddress(account);
|
|
1288
|
-
const
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1329
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1330
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1331
|
+
for (const target of targets) {
|
|
1332
|
+
if (!target || !isAddress(target.tokenAddress)) continue;
|
|
1333
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1334
|
+
if (seen.has(key)) continue;
|
|
1335
|
+
seen.add(key);
|
|
1336
|
+
const chainId = Number(target.chainId);
|
|
1337
|
+
const group = groups.get(chainId) || [];
|
|
1338
|
+
group.push(target);
|
|
1339
|
+
groups.set(chainId, group);
|
|
1340
|
+
}
|
|
1341
|
+
function record(target, hex) {
|
|
1342
|
+
if (typeof hex !== "string" || !/^0x[0-9a-fA-F]*$/.test(hex)) return false;
|
|
1343
|
+
const raw = BigInt(hex || "0x0").toString();
|
|
1344
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1345
|
+
out[key] = { raw, formatted: formatUnits(raw, Number(target.decimals)) };
|
|
1346
|
+
return true;
|
|
1347
|
+
}
|
|
1348
|
+
async function readOne(rpcUrl, target) {
|
|
1349
|
+
try {
|
|
1350
|
+
const hex = await rpcCall(rpcUrl, "eth_call", [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]);
|
|
1351
|
+
record(target, hex);
|
|
1352
|
+
} catch {
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
async function readGroup(chainId, group) {
|
|
1356
|
+
const rpcUrl = await balanceRpcUrl(chainId).catch(() => "");
|
|
1357
|
+
if (!rpcUrl) return;
|
|
1358
|
+
if (group.length === 1) return readOne(rpcUrl, group[0]);
|
|
1359
|
+
try {
|
|
1360
|
+
const results = await rpcBatchCall(
|
|
1361
|
+
rpcUrl,
|
|
1362
|
+
group.map((target) => ({
|
|
1363
|
+
method: "eth_call",
|
|
1364
|
+
params: [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]
|
|
1365
|
+
}))
|
|
1366
|
+
);
|
|
1367
|
+
const missing = [];
|
|
1368
|
+
group.forEach((target, index) => {
|
|
1369
|
+
if (!record(target, results.get(index + 1))) missing.push(target);
|
|
1370
|
+
});
|
|
1371
|
+
await Promise.all(missing.map((target) => readOne(rpcUrl, target)));
|
|
1372
|
+
} catch {
|
|
1373
|
+
await Promise.all(group.map((target) => readOne(rpcUrl, target)));
|
|
1304
1374
|
}
|
|
1305
1375
|
}
|
|
1306
|
-
await Promise.all(
|
|
1376
|
+
await Promise.all([...groups.entries()].map(([chainId, group]) => readGroup(chainId, group)));
|
|
1307
1377
|
return out;
|
|
1308
1378
|
}
|
|
1309
1379
|
async function readNativeBalance(chainId, account) {
|
|
@@ -1405,7 +1475,7 @@ function createEngine(config = {}) {
|
|
|
1405
1475
|
fetchTokens: api.fetchTokens,
|
|
1406
1476
|
fetchRoutes: api.fetchRoutes,
|
|
1407
1477
|
fetchQuote: api.fetchQuote,
|
|
1408
|
-
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet),
|
|
1478
|
+
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet, verifier.readBalances),
|
|
1409
1479
|
quoteSwapPreview: (swap, owner) => quoteSwapPreview(api, swap, owner),
|
|
1410
1480
|
buildSwapPlan: (swap, payer, wallet) => buildSwapPlan(api, swap, payer, wallet),
|
|
1411
1481
|
payerNonceBaseline: verifier.payerNonceBaseline,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { symbolKey, normalizeDecimalText, parseUnitsDecimal, SUPPORTED_CHAIN_IDS, tokenEnabled, isDeliverable, assetDecimals, findToken, formatUnits, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, SUPPORTED_ASSETS, BUNDLED_RPC } from './chunk-
|
|
1
|
+
import { symbolKey, normalizeDecimalText, parseUnitsDecimal, SUPPORTED_CHAIN_IDS, tokenEnabled, isDeliverable, assetDecimals, findToken, formatUnits, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, SUPPORTED_ASSETS, BUNDLED_RPC } from './chunk-AZPTL3KD.js';
|
|
2
2
|
import { createContext, useMemo, useState, useEffect, useRef, useCallback, useId, createElement, useContext } from 'react';
|
|
3
3
|
import { createRoot } from 'react-dom/client';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -501,7 +501,7 @@ function useFlow(args) {
|
|
|
501
501
|
function balanceKey(chainId, tokenAddress) {
|
|
502
502
|
return `${Number(chainId)}:${String(tokenAddress || "").toLowerCase()}`;
|
|
503
503
|
}
|
|
504
|
-
function useHoldings(engine, account, routes) {
|
|
504
|
+
function useHoldings(engine, account, routes, initialBalances) {
|
|
505
505
|
const [balances, setBalances] = useState({});
|
|
506
506
|
const [loading, setLoading] = useState(false);
|
|
507
507
|
const reqId = useRef(0);
|
|
@@ -526,19 +526,32 @@ function useHoldings(engine, account, routes) {
|
|
|
526
526
|
return;
|
|
527
527
|
}
|
|
528
528
|
const id = ++reqId.current;
|
|
529
|
+
const seeded = {};
|
|
530
|
+
const missing = [];
|
|
531
|
+
for (const target of targets) {
|
|
532
|
+
const key = balanceKey(target.chainId, target.tokenAddress);
|
|
533
|
+
const balance = initialBalances?.[key];
|
|
534
|
+
if (balance) seeded[key] = balance;
|
|
535
|
+
else missing.push(target);
|
|
536
|
+
}
|
|
537
|
+
setBalances(seeded);
|
|
538
|
+
if (!missing.length) {
|
|
539
|
+
setLoading(false);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
529
542
|
setLoading(true);
|
|
530
543
|
(async () => {
|
|
531
544
|
try {
|
|
532
|
-
const res = await engine.readBalances(account,
|
|
545
|
+
const res = await engine.readBalances(account, missing);
|
|
533
546
|
if (id !== reqId.current) return;
|
|
534
|
-
setBalances(res);
|
|
547
|
+
setBalances({ ...seeded, ...res });
|
|
535
548
|
} catch {
|
|
536
|
-
if (id === reqId.current) setBalances(
|
|
549
|
+
if (id === reqId.current) setBalances(seeded);
|
|
537
550
|
} finally {
|
|
538
551
|
if (id === reqId.current) setLoading(false);
|
|
539
552
|
}
|
|
540
553
|
})();
|
|
541
|
-
}, [engine, account, targetsKey]);
|
|
554
|
+
}, [engine, account, targetsKey, initialBalances]);
|
|
542
555
|
return { balances, loading };
|
|
543
556
|
}
|
|
544
557
|
|
|
@@ -1677,7 +1690,21 @@ var addrEq = (a, b) => String(a || "").toLowerCase() === String(b || "").toLower
|
|
|
1677
1690
|
var chainName = (id) => id != null ? CHAIN_LABELS[id] || `Chain ${id}` : "";
|
|
1678
1691
|
var STABLES = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
1679
1692
|
function BankGlyph() {
|
|
1680
|
-
return /* @__PURE__ */ jsx(
|
|
1693
|
+
return /* @__PURE__ */ jsx(
|
|
1694
|
+
"svg",
|
|
1695
|
+
{
|
|
1696
|
+
width: "18",
|
|
1697
|
+
height: "18",
|
|
1698
|
+
viewBox: "0 0 24 24",
|
|
1699
|
+
fill: "none",
|
|
1700
|
+
stroke: "currentColor",
|
|
1701
|
+
strokeWidth: "2",
|
|
1702
|
+
strokeLinecap: "round",
|
|
1703
|
+
strokeLinejoin: "round",
|
|
1704
|
+
"aria-hidden": "true",
|
|
1705
|
+
children: /* @__PURE__ */ jsx("path", { d: "M3 10h18M5 10v8M10 10v8M14 10v8M19 10v8M3 19h18M12 3 3 8h18Z" })
|
|
1706
|
+
}
|
|
1707
|
+
);
|
|
1681
1708
|
}
|
|
1682
1709
|
function MerchantBankPayout(props) {
|
|
1683
1710
|
const bankName = props.account?.bankName?.trim() || "Bank account";
|
|
@@ -1704,25 +1731,81 @@ function MerchantBankPayout(props) {
|
|
|
1704
1731
|
] }) }) });
|
|
1705
1732
|
}
|
|
1706
1733
|
function CheckGlyph2() {
|
|
1707
|
-
return /* @__PURE__ */ jsx(
|
|
1734
|
+
return /* @__PURE__ */ jsx(
|
|
1735
|
+
"svg",
|
|
1736
|
+
{
|
|
1737
|
+
width: "20",
|
|
1738
|
+
height: "20",
|
|
1739
|
+
viewBox: "0 0 24 24",
|
|
1740
|
+
fill: "none",
|
|
1741
|
+
stroke: "currentColor",
|
|
1742
|
+
strokeWidth: "3",
|
|
1743
|
+
strokeLinecap: "round",
|
|
1744
|
+
strokeLinejoin: "round",
|
|
1745
|
+
"aria-hidden": "true",
|
|
1746
|
+
children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
1747
|
+
}
|
|
1748
|
+
);
|
|
1708
1749
|
}
|
|
1709
1750
|
function ArrowGlyph() {
|
|
1710
|
-
return /* @__PURE__ */ jsxs(
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1751
|
+
return /* @__PURE__ */ jsxs(
|
|
1752
|
+
"svg",
|
|
1753
|
+
{
|
|
1754
|
+
width: "14",
|
|
1755
|
+
height: "14",
|
|
1756
|
+
viewBox: "0 0 24 24",
|
|
1757
|
+
fill: "none",
|
|
1758
|
+
stroke: "currentColor",
|
|
1759
|
+
strokeWidth: "2.4",
|
|
1760
|
+
strokeLinecap: "round",
|
|
1761
|
+
strokeLinejoin: "round",
|
|
1762
|
+
"aria-hidden": "true",
|
|
1763
|
+
children: [
|
|
1764
|
+
/* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
|
|
1765
|
+
/* @__PURE__ */ jsx("path", { d: "m13 6 6 6-6 6" })
|
|
1766
|
+
]
|
|
1767
|
+
}
|
|
1768
|
+
);
|
|
1714
1769
|
}
|
|
1715
1770
|
function ClockGlyph() {
|
|
1716
|
-
return /* @__PURE__ */ jsxs(
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1771
|
+
return /* @__PURE__ */ jsxs(
|
|
1772
|
+
"svg",
|
|
1773
|
+
{
|
|
1774
|
+
width: "20",
|
|
1775
|
+
height: "20",
|
|
1776
|
+
viewBox: "0 0 24 24",
|
|
1777
|
+
fill: "none",
|
|
1778
|
+
stroke: "currentColor",
|
|
1779
|
+
strokeWidth: "2.2",
|
|
1780
|
+
strokeLinecap: "round",
|
|
1781
|
+
strokeLinejoin: "round",
|
|
1782
|
+
"aria-hidden": "true",
|
|
1783
|
+
children: [
|
|
1784
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
1785
|
+
/* @__PURE__ */ jsx("path", { d: "M12 7v5l3 2" })
|
|
1786
|
+
]
|
|
1787
|
+
}
|
|
1788
|
+
);
|
|
1720
1789
|
}
|
|
1721
1790
|
function WalletGlyph() {
|
|
1722
|
-
return /* @__PURE__ */ jsxs(
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1791
|
+
return /* @__PURE__ */ jsxs(
|
|
1792
|
+
"svg",
|
|
1793
|
+
{
|
|
1794
|
+
width: "16",
|
|
1795
|
+
height: "16",
|
|
1796
|
+
viewBox: "0 0 24 24",
|
|
1797
|
+
fill: "none",
|
|
1798
|
+
stroke: "currentColor",
|
|
1799
|
+
strokeWidth: "2",
|
|
1800
|
+
strokeLinecap: "round",
|
|
1801
|
+
strokeLinejoin: "round",
|
|
1802
|
+
"aria-hidden": "true",
|
|
1803
|
+
children: [
|
|
1804
|
+
/* @__PURE__ */ jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
|
|
1805
|
+
/* @__PURE__ */ jsx("path", { d: "M16 12h.01M3 9h18" })
|
|
1806
|
+
]
|
|
1807
|
+
}
|
|
1808
|
+
);
|
|
1726
1809
|
}
|
|
1727
1810
|
function LinkMenu(props) {
|
|
1728
1811
|
const [open, setOpen] = useState(false);
|
|
@@ -1833,7 +1916,13 @@ function IdentityLine(props) {
|
|
|
1833
1916
|
function PaymentIsland(props) {
|
|
1834
1917
|
injectStyles();
|
|
1835
1918
|
const config = useMergedConfig(props);
|
|
1836
|
-
const engine = useEngine({
|
|
1919
|
+
const engine = useEngine({
|
|
1920
|
+
apiBase: config.apiBase,
|
|
1921
|
+
apiKey: config.apiKey,
|
|
1922
|
+
trustedApiOrigin: config.trustedApiOrigin,
|
|
1923
|
+
rpcOverrides: config.rpcOverrides,
|
|
1924
|
+
onTransaction: config.onTransaction
|
|
1925
|
+
});
|
|
1837
1926
|
const wallet = useWallet(config.provider);
|
|
1838
1927
|
const kind = props.kind;
|
|
1839
1928
|
const isPay = kind === "pay";
|
|
@@ -1862,7 +1951,8 @@ function PaymentIsland(props) {
|
|
|
1862
1951
|
const normEx = normalizeDecimalText(exAmount);
|
|
1863
1952
|
const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
|
|
1864
1953
|
const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
|
|
1865
|
-
const
|
|
1954
|
+
const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
|
|
1955
|
+
const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
|
|
1866
1956
|
const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
|
|
1867
1957
|
const flow = useFlow({
|
|
1868
1958
|
engine,
|
|
@@ -1872,7 +1962,20 @@ function PaymentIsland(props) {
|
|
|
1872
1962
|
// quote (and fire onQuote) for a payment whose CTA it never shows.
|
|
1873
1963
|
enabled: isPay ? Boolean(props.recipient && props.amount) && !bankSettlement : exQuotable,
|
|
1874
1964
|
paramsKey: isPay ? payParamsKey : exParamsKey,
|
|
1875
|
-
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
1965
|
+
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
1966
|
+
chainId,
|
|
1967
|
+
fundingAssets: payFundingAssets
|
|
1968
|
+
}) : (e, payer) => e.buildSwapPlan(
|
|
1969
|
+
{
|
|
1970
|
+
fromChainId: exFromChainId,
|
|
1971
|
+
toChainId: exToChainId,
|
|
1972
|
+
fromToken: exFromAsset,
|
|
1973
|
+
toToken: exToAsset,
|
|
1974
|
+
amountIn: normEx,
|
|
1975
|
+
recipient: props.recipient
|
|
1976
|
+
},
|
|
1977
|
+
payer
|
|
1978
|
+
),
|
|
1876
1979
|
recipientFor: (account) => isPay ? props.recipient : props.recipient || account,
|
|
1877
1980
|
onQuote: config.onQuote,
|
|
1878
1981
|
onSuccess: config.onSuccess,
|
|
@@ -1880,15 +1983,14 @@ function PaymentIsland(props) {
|
|
|
1880
1983
|
});
|
|
1881
1984
|
const [method, setMethod] = useState("stablecoin");
|
|
1882
1985
|
const parked = isPay && !isLiveMethod(method);
|
|
1883
|
-
const fundingSet = useMemo(
|
|
1884
|
-
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
1885
|
-
[props.fundingAssets]
|
|
1886
|
-
);
|
|
1986
|
+
const fundingSet = useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
|
|
1887
1987
|
const visibleRoutes = useMemo(() => {
|
|
1888
1988
|
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
1889
|
-
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(r.source.asset)) : base;
|
|
1989
|
+
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(symbolKey(r.source.asset))) : base;
|
|
1890
1990
|
}, [flow.routes, fundingSet, isPay, method]);
|
|
1891
|
-
const
|
|
1991
|
+
const paymentPlan = flow.plan;
|
|
1992
|
+
const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
|
|
1993
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
|
|
1892
1994
|
const annotated = useMemo(
|
|
1893
1995
|
() => visibleRoutes.map((r) => {
|
|
1894
1996
|
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
@@ -1983,7 +2085,15 @@ function PaymentIsland(props) {
|
|
|
1983
2085
|
if (seen.has(key)) continue;
|
|
1984
2086
|
seen.add(key);
|
|
1985
2087
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
|
|
1986
|
-
list.push(
|
|
2088
|
+
list.push(
|
|
2089
|
+
reg ?? {
|
|
2090
|
+
symbol: r.source.asset,
|
|
2091
|
+
name: r.source.asset,
|
|
2092
|
+
chainId: r.source.chainId,
|
|
2093
|
+
address: r.source.tokenAddress ?? "",
|
|
2094
|
+
decimals: r.source.decimals ?? 18
|
|
2095
|
+
}
|
|
2096
|
+
);
|
|
1987
2097
|
}
|
|
1988
2098
|
return list;
|
|
1989
2099
|
}, [visibleRoutes, registryTokens]);
|
|
@@ -2193,7 +2303,18 @@ function PaymentIsland(props) {
|
|
|
2193
2303
|
if (hist && wallet.account) {
|
|
2194
2304
|
body = /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
2195
2305
|
} else if (isPay && view === "select" && wallet.account) {
|
|
2196
|
-
body = /* @__PURE__ */ jsx(
|
|
2306
|
+
body = /* @__PURE__ */ jsx(
|
|
2307
|
+
TokenSelect,
|
|
2308
|
+
{
|
|
2309
|
+
title: "Pay with",
|
|
2310
|
+
chains: fundingChains,
|
|
2311
|
+
tokens: fundingTokens,
|
|
2312
|
+
balances: holdings.balances,
|
|
2313
|
+
optionStates,
|
|
2314
|
+
onBack: () => closeSelector(),
|
|
2315
|
+
onPick: pickFunding
|
|
2316
|
+
}
|
|
2317
|
+
);
|
|
2197
2318
|
} else if (!isPay && (view === "from" || view === "to")) {
|
|
2198
2319
|
const isFrom = view === "from";
|
|
2199
2320
|
const openerRef = isFrom ? exFromTileRef : exToTileRef;
|
|
@@ -2393,22 +2514,66 @@ function PaymentIsland(props) {
|
|
|
2393
2514
|
const islandVars = themeToVars(resolved);
|
|
2394
2515
|
return /* @__PURE__ */ jsx("div", { className: "sg-island-wrap", children: /* @__PURE__ */ jsxs("div", { className: "sg-island", "data-sg-mode": resolved.mode, "data-expanded": expanded, "data-status": flow.status, style: islandVars, children: [
|
|
2395
2516
|
pillFace,
|
|
2396
|
-
/* @__PURE__ */ jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsx(
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2517
|
+
/* @__PURE__ */ jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsx(
|
|
2518
|
+
"div",
|
|
2519
|
+
{
|
|
2520
|
+
className: "sg-island-body",
|
|
2521
|
+
id: panelId,
|
|
2522
|
+
ref: regionRef,
|
|
2523
|
+
role: "region",
|
|
2524
|
+
"aria-label": isPay ? "ZeroDelta Link checkout" : `ZeroDelta Link ${verb.present.toLowerCase()}`,
|
|
2525
|
+
tabIndex: -1,
|
|
2526
|
+
children: expanded ? /* @__PURE__ */ jsxs(
|
|
2527
|
+
WidgetShell,
|
|
2528
|
+
{
|
|
2529
|
+
variant: "express",
|
|
2530
|
+
title: "ZeroDelta Link",
|
|
2531
|
+
theme: config.theme,
|
|
2532
|
+
heightPx: props.heightPx,
|
|
2533
|
+
brandSlot,
|
|
2534
|
+
walletSlot,
|
|
2535
|
+
children: [
|
|
2536
|
+
/* @__PURE__ */ jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
|
|
2537
|
+
body
|
|
2538
|
+
]
|
|
2539
|
+
}
|
|
2540
|
+
) : null
|
|
2541
|
+
}
|
|
2542
|
+
) }) })
|
|
2400
2543
|
] }) });
|
|
2401
2544
|
}
|
|
2402
2545
|
var STABLES2 = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
2546
|
+
var DEFAULT_FUNDING_ASSETS = ["USDC", "USDT", "USDE"];
|
|
2403
2547
|
function CheckGlyph3() {
|
|
2404
|
-
return /* @__PURE__ */ jsx(
|
|
2548
|
+
return /* @__PURE__ */ jsx(
|
|
2549
|
+
"svg",
|
|
2550
|
+
{
|
|
2551
|
+
width: "20",
|
|
2552
|
+
height: "20",
|
|
2553
|
+
viewBox: "0 0 24 24",
|
|
2554
|
+
fill: "none",
|
|
2555
|
+
stroke: "currentColor",
|
|
2556
|
+
strokeWidth: "3",
|
|
2557
|
+
strokeLinecap: "round",
|
|
2558
|
+
strokeLinejoin: "round",
|
|
2559
|
+
"aria-hidden": "true",
|
|
2560
|
+
children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
2561
|
+
}
|
|
2562
|
+
);
|
|
2405
2563
|
}
|
|
2406
2564
|
var addrEq2 = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
|
|
2407
2565
|
function StableGeniePay(props) {
|
|
2408
2566
|
const config = useMergedConfig(props);
|
|
2409
|
-
const engine = useEngine({
|
|
2567
|
+
const engine = useEngine({
|
|
2568
|
+
apiBase: config.apiBase,
|
|
2569
|
+
apiKey: config.apiKey,
|
|
2570
|
+
trustedApiOrigin: config.trustedApiOrigin,
|
|
2571
|
+
rpcOverrides: config.rpcOverrides,
|
|
2572
|
+
onTransaction: config.onTransaction
|
|
2573
|
+
});
|
|
2410
2574
|
const wallet = useWallet(config.provider);
|
|
2411
|
-
const
|
|
2575
|
+
const planFundingAssets = props.fundingAssets?.length ? props.fundingAssets : DEFAULT_FUNDING_ASSETS;
|
|
2576
|
+
const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${planFundingAssets.join(",")}`;
|
|
2412
2577
|
const flow = useFlow({
|
|
2413
2578
|
engine,
|
|
2414
2579
|
wallet,
|
|
@@ -2417,22 +2582,24 @@ function StableGeniePay(props) {
|
|
|
2417
2582
|
// network work here, or every quote / balance read fires twice and onQuote/onError double-fire.
|
|
2418
2583
|
enabled: Boolean(props.recipient && props.amount) && props.variant !== "pill",
|
|
2419
2584
|
paramsKey,
|
|
2420
|
-
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
2585
|
+
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
2586
|
+
chainId,
|
|
2587
|
+
fundingAssets: planFundingAssets
|
|
2588
|
+
}),
|
|
2421
2589
|
recipientFor: () => props.recipient,
|
|
2422
2590
|
onQuote: config.onQuote,
|
|
2423
2591
|
onSuccess: config.onSuccess,
|
|
2424
2592
|
onError: config.onError
|
|
2425
2593
|
});
|
|
2426
2594
|
const [method, setMethod] = useState("stablecoin");
|
|
2427
|
-
const fundingSet = useMemo(
|
|
2428
|
-
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
2429
|
-
[props.fundingAssets]
|
|
2430
|
-
);
|
|
2595
|
+
const fundingSet = useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
|
|
2431
2596
|
const visibleRoutes = useMemo(() => {
|
|
2432
2597
|
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
2433
|
-
return method === "stablecoin" ? base.filter((r) => STABLES2.has(r.source.asset)) : base;
|
|
2598
|
+
return method === "stablecoin" ? base.filter((r) => STABLES2.has(symbolKey(r.source.asset))) : base;
|
|
2434
2599
|
}, [flow.routes, method, fundingSet]);
|
|
2435
|
-
const
|
|
2600
|
+
const paymentPlan = flow.plan;
|
|
2601
|
+
const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
|
|
2602
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
|
|
2436
2603
|
const annotated = useMemo(
|
|
2437
2604
|
() => visibleRoutes.map((r) => {
|
|
2438
2605
|
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
@@ -2506,7 +2673,15 @@ function StableGeniePay(props) {
|
|
|
2506
2673
|
if (seen.has(key)) continue;
|
|
2507
2674
|
seen.add(key);
|
|
2508
2675
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
|
|
2509
|
-
list.push(
|
|
2676
|
+
list.push(
|
|
2677
|
+
reg ?? {
|
|
2678
|
+
symbol: r.source.asset,
|
|
2679
|
+
name: r.source.asset,
|
|
2680
|
+
chainId: r.source.chainId,
|
|
2681
|
+
address: r.source.tokenAddress ?? "",
|
|
2682
|
+
decimals: r.source.decimals ?? 18
|
|
2683
|
+
}
|
|
2684
|
+
);
|
|
2510
2685
|
}
|
|
2511
2686
|
return list;
|
|
2512
2687
|
}, [visibleRoutes, registryTokens]);
|
|
@@ -2588,7 +2763,18 @@ function StableGeniePay(props) {
|
|
|
2588
2763
|
] })
|
|
2589
2764
|
] }) : void 0;
|
|
2590
2765
|
if (props.variant === "pill") return /* @__PURE__ */ jsx(PaymentIsland, { kind: "pay", ...props });
|
|
2591
|
-
return /* @__PURE__ */ jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsx(
|
|
2766
|
+
return /* @__PURE__ */ jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsx(
|
|
2767
|
+
TokenSelect,
|
|
2768
|
+
{
|
|
2769
|
+
title: "Pay with",
|
|
2770
|
+
chains: fundingChains,
|
|
2771
|
+
tokens: fundingTokens,
|
|
2772
|
+
balances: holdings.balances,
|
|
2773
|
+
optionStates,
|
|
2774
|
+
onBack: closeSelector,
|
|
2775
|
+
onPick: pickFunding
|
|
2776
|
+
}
|
|
2777
|
+
) : /* @__PURE__ */ jsx(Fragment, { children: !wallet.account ? /* @__PURE__ */ jsxs("div", { className: "sg-cta-wrap", children: [
|
|
2592
2778
|
/* @__PURE__ */ jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
|
|
2593
2779
|
wallet.error ? /* @__PURE__ */ jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
2594
2780
|
] }) : flow.status === "success" || flow.status === "pending" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -2646,7 +2832,15 @@ function StableGeniePay(props) {
|
|
|
2646
2832
|
flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null
|
|
2647
2833
|
] }),
|
|
2648
2834
|
submitting ? /* @__PURE__ */ jsx(StepList, { steps: flow.steps }) : null,
|
|
2649
|
-
/* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(
|
|
2835
|
+
/* @__PURE__ */ jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsx(
|
|
2836
|
+
Button,
|
|
2837
|
+
{
|
|
2838
|
+
onClick: parked || !selectedVisible ? void 0 : flow.submit,
|
|
2839
|
+
busy: submitting,
|
|
2840
|
+
disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading",
|
|
2841
|
+
children: payLabel
|
|
2842
|
+
}
|
|
2843
|
+
) })
|
|
2650
2844
|
] }) }) });
|
|
2651
2845
|
}
|
|
2652
2846
|
var chainOptions = SUPPORTED_CHAINS.map((c) => ({ value: c, label: CHAIN_LABELS[c] || `Chain ${c}` }));
|