@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
package/dist/mount.cjs
CHANGED
|
@@ -869,6 +869,16 @@ function createApiClient(cfg) {
|
|
|
869
869
|
}
|
|
870
870
|
|
|
871
871
|
// src/core/plan.ts
|
|
872
|
+
function optionBalanceKey(option) {
|
|
873
|
+
return `${Number(option.chainId)}:${String(option.address || "").toLowerCase()}`;
|
|
874
|
+
}
|
|
875
|
+
function hasPositiveBalance(option, balances) {
|
|
876
|
+
try {
|
|
877
|
+
return BigInt(balances[optionBalanceKey(option)]?.raw ?? "0") > 0n;
|
|
878
|
+
} catch {
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
872
882
|
function validateDestination(destination) {
|
|
873
883
|
assertAddress(destination.address, "Destination address");
|
|
874
884
|
const chainId = Number(destination.chainId);
|
|
@@ -884,7 +894,7 @@ function planErrorSummary(errors) {
|
|
|
884
894
|
const unique = [...new Set(errors.map((error) => error?.message || String(error)).filter(Boolean))].slice(0, 3);
|
|
885
895
|
return unique.length ? unique.join(" | ") : "No ZeroDelta route is currently available for this payment.";
|
|
886
896
|
}
|
|
887
|
-
async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
897
|
+
async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances) {
|
|
888
898
|
validateDestination(request);
|
|
889
899
|
assertAddress(payer, "Payer wallet");
|
|
890
900
|
const [chains, tokens, routes] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes()]);
|
|
@@ -895,6 +905,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
895
905
|
};
|
|
896
906
|
const destinationToken = findToken(tokens, destination.chainId, destination.asset);
|
|
897
907
|
if (!destinationToken) throw new Error(`${destination.asset} is not enabled on ${chainNameOf(destination.chainId, chains)}.`);
|
|
908
|
+
const allowedFunding = wallet.fundingAssets?.length ? new Set(wallet.fundingAssets.map(symbolKey)) : null;
|
|
898
909
|
const options = buildPayOptions({
|
|
899
910
|
invoiceAsset: destination.asset,
|
|
900
911
|
invoiceChainId: destination.chainId,
|
|
@@ -902,14 +913,25 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
902
913
|
routes,
|
|
903
914
|
chains,
|
|
904
915
|
walletChainId: wallet?.chainId
|
|
905
|
-
});
|
|
916
|
+
}).filter((option) => option.direct || !allowedFunding || allowedFunding.has(option.symbolKey));
|
|
906
917
|
if (!options.length) throw new Error(`No enabled ZeroDelta funding assets can settle ${destination.asset} on ${chainNameOf(destination.chainId, chains)}.`);
|
|
918
|
+
const balanceTargets = [];
|
|
919
|
+
const seenTargets = /* @__PURE__ */ new Set();
|
|
920
|
+
for (const option of options) {
|
|
921
|
+
const key = optionBalanceKey(option);
|
|
922
|
+
if (seenTargets.has(key)) continue;
|
|
923
|
+
seenTargets.add(key);
|
|
924
|
+
balanceTargets.push({ chainId: option.chainId, tokenAddress: option.address, decimals: option.decimals });
|
|
925
|
+
}
|
|
926
|
+
const walletBalances = readBalances ? await readBalances(payer, balanceTargets).catch(() => ({})) : {};
|
|
907
927
|
const candidates = options.filter((option) => option.direct);
|
|
928
|
+
const heldOptions = options.filter((option) => !option.direct && hasPositiveBalance(option, walletBalances));
|
|
929
|
+
const heldKeys = new Set(heldOptions.map(optionBalanceKey));
|
|
908
930
|
const seenChains = /* @__PURE__ */ new Set();
|
|
909
931
|
const perChainBest = [];
|
|
910
932
|
const leftovers = [];
|
|
911
933
|
for (const option of options) {
|
|
912
|
-
if (option.direct) continue;
|
|
934
|
+
if (option.direct || heldKeys.has(optionBalanceKey(option))) continue;
|
|
913
935
|
if (seenChains.has(option.chainId)) {
|
|
914
936
|
leftovers.push(option);
|
|
915
937
|
} else {
|
|
@@ -917,7 +939,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
917
939
|
perChainBest.push(option);
|
|
918
940
|
}
|
|
919
941
|
}
|
|
920
|
-
for (const option of [...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
942
|
+
for (const option of [...heldOptions, ...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
921
943
|
candidates.push(option);
|
|
922
944
|
}
|
|
923
945
|
const routeErrors = [];
|
|
@@ -952,6 +974,8 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
952
974
|
expiresAt: new Date(Date.now() + 2 * 60 * 1e3).toISOString(),
|
|
953
975
|
apiBase: api.apiBase,
|
|
954
976
|
routes: routesBuilt,
|
|
977
|
+
fundingBalances: walletBalances,
|
|
978
|
+
fundingAccount: payer.toLowerCase(),
|
|
955
979
|
destination: {
|
|
956
980
|
asset: destinationToken.symbol,
|
|
957
981
|
chainId: destination.chainId,
|
|
@@ -1180,6 +1204,23 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
1180
1204
|
const json = await response.json();
|
|
1181
1205
|
return json?.result ?? null;
|
|
1182
1206
|
}
|
|
1207
|
+
async function rpcBatchCall(rpcUrl, calls) {
|
|
1208
|
+
const response = await fetchImpl(rpcUrl, {
|
|
1209
|
+
method: "POST",
|
|
1210
|
+
headers: { "Content-Type": "application/json" },
|
|
1211
|
+
body: JSON.stringify(calls.map((call, index) => ({ jsonrpc: "2.0", id: index + 1, ...call }))),
|
|
1212
|
+
signal: AbortSignal.timeout(TX_VERIFY_FETCH_MS)
|
|
1213
|
+
});
|
|
1214
|
+
if (!response.ok) throw new Error(`RPC ${response.status}`);
|
|
1215
|
+
const json = await response.json();
|
|
1216
|
+
if (!Array.isArray(json)) throw new Error("RPC batch unsupported");
|
|
1217
|
+
const results = /* @__PURE__ */ new Map();
|
|
1218
|
+
for (const item of json) {
|
|
1219
|
+
const id = Number(item?.id);
|
|
1220
|
+
if (Number.isInteger(id) && Object.hasOwn(item || {}, "result")) results.set(id, item.result);
|
|
1221
|
+
}
|
|
1222
|
+
return results;
|
|
1223
|
+
}
|
|
1183
1224
|
async function payerNonceBaseline(chainId, account) {
|
|
1184
1225
|
if (!isAddress(account)) return null;
|
|
1185
1226
|
const rpcUrl = await chainRpcUrl(chainId);
|
|
@@ -1246,25 +1287,54 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
1246
1287
|
const out = {};
|
|
1247
1288
|
if (!isAddress(account) || !Array.isArray(targets) || !targets.length) return out;
|
|
1248
1289
|
const owner = normalizeAddress(account);
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1290
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1291
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1292
|
+
for (const target of targets) {
|
|
1293
|
+
if (!target || !isAddress(target.tokenAddress)) continue;
|
|
1294
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1295
|
+
if (seen.has(key)) continue;
|
|
1296
|
+
seen.add(key);
|
|
1297
|
+
const chainId = Number(target.chainId);
|
|
1298
|
+
const group = groups.get(chainId) || [];
|
|
1299
|
+
group.push(target);
|
|
1300
|
+
groups.set(chainId, group);
|
|
1301
|
+
}
|
|
1302
|
+
function record(target, hex) {
|
|
1303
|
+
if (typeof hex !== "string" || !/^0x[0-9a-fA-F]*$/.test(hex)) return false;
|
|
1304
|
+
const raw = BigInt(hex || "0x0").toString();
|
|
1305
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1306
|
+
out[key] = { raw, formatted: formatUnits(raw, Number(target.decimals)) };
|
|
1307
|
+
return true;
|
|
1308
|
+
}
|
|
1309
|
+
async function readOne(rpcUrl, target) {
|
|
1310
|
+
try {
|
|
1311
|
+
const hex = await rpcCall(rpcUrl, "eth_call", [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]);
|
|
1312
|
+
record(target, hex);
|
|
1313
|
+
} catch {
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
async function readGroup(chainId, group) {
|
|
1317
|
+
const rpcUrl = await balanceRpcUrl(chainId).catch(() => "");
|
|
1318
|
+
if (!rpcUrl) return;
|
|
1319
|
+
if (group.length === 1) return readOne(rpcUrl, group[0]);
|
|
1320
|
+
try {
|
|
1321
|
+
const results = await rpcBatchCall(
|
|
1322
|
+
rpcUrl,
|
|
1323
|
+
group.map((target) => ({
|
|
1324
|
+
method: "eth_call",
|
|
1325
|
+
params: [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]
|
|
1326
|
+
}))
|
|
1327
|
+
);
|
|
1328
|
+
const missing = [];
|
|
1329
|
+
group.forEach((target, index) => {
|
|
1330
|
+
if (!record(target, results.get(index + 1))) missing.push(target);
|
|
1331
|
+
});
|
|
1332
|
+
await Promise.all(missing.map((target) => readOne(rpcUrl, target)));
|
|
1333
|
+
} catch {
|
|
1334
|
+
await Promise.all(group.map((target) => readOne(rpcUrl, target)));
|
|
1265
1335
|
}
|
|
1266
1336
|
}
|
|
1267
|
-
await Promise.all(
|
|
1337
|
+
await Promise.all([...groups.entries()].map(([chainId, group]) => readGroup(chainId, group)));
|
|
1268
1338
|
return out;
|
|
1269
1339
|
}
|
|
1270
1340
|
async function readNativeBalance(chainId, account) {
|
|
@@ -1366,7 +1436,7 @@ function createEngine(config = {}) {
|
|
|
1366
1436
|
fetchTokens: api.fetchTokens,
|
|
1367
1437
|
fetchRoutes: api.fetchRoutes,
|
|
1368
1438
|
fetchQuote: api.fetchQuote,
|
|
1369
|
-
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet),
|
|
1439
|
+
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet, verifier.readBalances),
|
|
1370
1440
|
quoteSwapPreview: (swap, owner) => quoteSwapPreview(api, swap, owner),
|
|
1371
1441
|
buildSwapPlan: (swap, payer, wallet) => buildSwapPlan(api, swap, payer, wallet),
|
|
1372
1442
|
payerNonceBaseline: verifier.payerNonceBaseline,
|
|
@@ -1875,7 +1945,7 @@ function useFlow(args) {
|
|
|
1875
1945
|
function balanceKey(chainId, tokenAddress) {
|
|
1876
1946
|
return `${Number(chainId)}:${String(tokenAddress || "").toLowerCase()}`;
|
|
1877
1947
|
}
|
|
1878
|
-
function useHoldings(engine, account, routes) {
|
|
1948
|
+
function useHoldings(engine, account, routes, initialBalances) {
|
|
1879
1949
|
const [balances, setBalances] = react.useState({});
|
|
1880
1950
|
const [loading, setLoading] = react.useState(false);
|
|
1881
1951
|
const reqId = react.useRef(0);
|
|
@@ -1900,19 +1970,32 @@ function useHoldings(engine, account, routes) {
|
|
|
1900
1970
|
return;
|
|
1901
1971
|
}
|
|
1902
1972
|
const id = ++reqId.current;
|
|
1973
|
+
const seeded = {};
|
|
1974
|
+
const missing = [];
|
|
1975
|
+
for (const target of targets) {
|
|
1976
|
+
const key = balanceKey(target.chainId, target.tokenAddress);
|
|
1977
|
+
const balance = initialBalances?.[key];
|
|
1978
|
+
if (balance) seeded[key] = balance;
|
|
1979
|
+
else missing.push(target);
|
|
1980
|
+
}
|
|
1981
|
+
setBalances(seeded);
|
|
1982
|
+
if (!missing.length) {
|
|
1983
|
+
setLoading(false);
|
|
1984
|
+
return;
|
|
1985
|
+
}
|
|
1903
1986
|
setLoading(true);
|
|
1904
1987
|
(async () => {
|
|
1905
1988
|
try {
|
|
1906
|
-
const res = await engine.readBalances(account,
|
|
1989
|
+
const res = await engine.readBalances(account, missing);
|
|
1907
1990
|
if (id !== reqId.current) return;
|
|
1908
|
-
setBalances(res);
|
|
1991
|
+
setBalances({ ...seeded, ...res });
|
|
1909
1992
|
} catch {
|
|
1910
|
-
if (id === reqId.current) setBalances(
|
|
1993
|
+
if (id === reqId.current) setBalances(seeded);
|
|
1911
1994
|
} finally {
|
|
1912
1995
|
if (id === reqId.current) setLoading(false);
|
|
1913
1996
|
}
|
|
1914
1997
|
})();
|
|
1915
|
-
}, [engine, account, targetsKey]);
|
|
1998
|
+
}, [engine, account, targetsKey, initialBalances]);
|
|
1916
1999
|
return { balances, loading };
|
|
1917
2000
|
}
|
|
1918
2001
|
|
|
@@ -3051,7 +3134,21 @@ var addrEq = (a, b) => String(a || "").toLowerCase() === String(b || "").toLower
|
|
|
3051
3134
|
var chainName = (id) => id != null ? CHAIN_LABELS[id] || `Chain ${id}` : "";
|
|
3052
3135
|
var STABLES = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
3053
3136
|
function BankGlyph() {
|
|
3054
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3137
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3138
|
+
"svg",
|
|
3139
|
+
{
|
|
3140
|
+
width: "18",
|
|
3141
|
+
height: "18",
|
|
3142
|
+
viewBox: "0 0 24 24",
|
|
3143
|
+
fill: "none",
|
|
3144
|
+
stroke: "currentColor",
|
|
3145
|
+
strokeWidth: "2",
|
|
3146
|
+
strokeLinecap: "round",
|
|
3147
|
+
strokeLinejoin: "round",
|
|
3148
|
+
"aria-hidden": "true",
|
|
3149
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 10h18M5 10v8M10 10v8M14 10v8M19 10v8M3 19h18M12 3 3 8h18Z" })
|
|
3150
|
+
}
|
|
3151
|
+
);
|
|
3055
3152
|
}
|
|
3056
3153
|
function MerchantBankPayout(props) {
|
|
3057
3154
|
const bankName = props.account?.bankName?.trim() || "Bank account";
|
|
@@ -3078,25 +3175,81 @@ function MerchantBankPayout(props) {
|
|
|
3078
3175
|
] }) }) });
|
|
3079
3176
|
}
|
|
3080
3177
|
function CheckGlyph2() {
|
|
3081
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3178
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3179
|
+
"svg",
|
|
3180
|
+
{
|
|
3181
|
+
width: "20",
|
|
3182
|
+
height: "20",
|
|
3183
|
+
viewBox: "0 0 24 24",
|
|
3184
|
+
fill: "none",
|
|
3185
|
+
stroke: "currentColor",
|
|
3186
|
+
strokeWidth: "3",
|
|
3187
|
+
strokeLinecap: "round",
|
|
3188
|
+
strokeLinejoin: "round",
|
|
3189
|
+
"aria-hidden": "true",
|
|
3190
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
3191
|
+
}
|
|
3192
|
+
);
|
|
3082
3193
|
}
|
|
3083
3194
|
function ArrowGlyph() {
|
|
3084
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3195
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3196
|
+
"svg",
|
|
3197
|
+
{
|
|
3198
|
+
width: "14",
|
|
3199
|
+
height: "14",
|
|
3200
|
+
viewBox: "0 0 24 24",
|
|
3201
|
+
fill: "none",
|
|
3202
|
+
stroke: "currentColor",
|
|
3203
|
+
strokeWidth: "2.4",
|
|
3204
|
+
strokeLinecap: "round",
|
|
3205
|
+
strokeLinejoin: "round",
|
|
3206
|
+
"aria-hidden": "true",
|
|
3207
|
+
children: [
|
|
3208
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 12h14" }),
|
|
3209
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m13 6 6 6-6 6" })
|
|
3210
|
+
]
|
|
3211
|
+
}
|
|
3212
|
+
);
|
|
3088
3213
|
}
|
|
3089
3214
|
function ClockGlyph() {
|
|
3090
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3215
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3216
|
+
"svg",
|
|
3217
|
+
{
|
|
3218
|
+
width: "20",
|
|
3219
|
+
height: "20",
|
|
3220
|
+
viewBox: "0 0 24 24",
|
|
3221
|
+
fill: "none",
|
|
3222
|
+
stroke: "currentColor",
|
|
3223
|
+
strokeWidth: "2.2",
|
|
3224
|
+
strokeLinecap: "round",
|
|
3225
|
+
strokeLinejoin: "round",
|
|
3226
|
+
"aria-hidden": "true",
|
|
3227
|
+
children: [
|
|
3228
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
3229
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 7v5l3 2" })
|
|
3230
|
+
]
|
|
3231
|
+
}
|
|
3232
|
+
);
|
|
3094
3233
|
}
|
|
3095
3234
|
function WalletGlyph() {
|
|
3096
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3235
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3236
|
+
"svg",
|
|
3237
|
+
{
|
|
3238
|
+
width: "16",
|
|
3239
|
+
height: "16",
|
|
3240
|
+
viewBox: "0 0 24 24",
|
|
3241
|
+
fill: "none",
|
|
3242
|
+
stroke: "currentColor",
|
|
3243
|
+
strokeWidth: "2",
|
|
3244
|
+
strokeLinecap: "round",
|
|
3245
|
+
strokeLinejoin: "round",
|
|
3246
|
+
"aria-hidden": "true",
|
|
3247
|
+
children: [
|
|
3248
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
|
|
3249
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16 12h.01M3 9h18" })
|
|
3250
|
+
]
|
|
3251
|
+
}
|
|
3252
|
+
);
|
|
3100
3253
|
}
|
|
3101
3254
|
function LinkMenu(props) {
|
|
3102
3255
|
const [open, setOpen] = react.useState(false);
|
|
@@ -3207,7 +3360,13 @@ function IdentityLine(props) {
|
|
|
3207
3360
|
function PaymentIsland(props) {
|
|
3208
3361
|
injectStyles();
|
|
3209
3362
|
const config = useMergedConfig(props);
|
|
3210
|
-
const engine = useEngine({
|
|
3363
|
+
const engine = useEngine({
|
|
3364
|
+
apiBase: config.apiBase,
|
|
3365
|
+
apiKey: config.apiKey,
|
|
3366
|
+
trustedApiOrigin: config.trustedApiOrigin,
|
|
3367
|
+
rpcOverrides: config.rpcOverrides,
|
|
3368
|
+
onTransaction: config.onTransaction
|
|
3369
|
+
});
|
|
3211
3370
|
const wallet = useWallet(config.provider);
|
|
3212
3371
|
const kind = props.kind;
|
|
3213
3372
|
const isPay = kind === "pay";
|
|
@@ -3236,7 +3395,8 @@ function PaymentIsland(props) {
|
|
|
3236
3395
|
const normEx = normalizeDecimalText(exAmount);
|
|
3237
3396
|
const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
|
|
3238
3397
|
const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
|
|
3239
|
-
const
|
|
3398
|
+
const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
|
|
3399
|
+
const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
|
|
3240
3400
|
const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
|
|
3241
3401
|
const flow = useFlow({
|
|
3242
3402
|
engine,
|
|
@@ -3246,7 +3406,20 @@ function PaymentIsland(props) {
|
|
|
3246
3406
|
// quote (and fire onQuote) for a payment whose CTA it never shows.
|
|
3247
3407
|
enabled: isPay ? Boolean(props.recipient && props.amount) && !bankSettlement : exQuotable,
|
|
3248
3408
|
paramsKey: isPay ? payParamsKey : exParamsKey,
|
|
3249
|
-
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
3409
|
+
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
3410
|
+
chainId,
|
|
3411
|
+
fundingAssets: payFundingAssets
|
|
3412
|
+
}) : (e, payer) => e.buildSwapPlan(
|
|
3413
|
+
{
|
|
3414
|
+
fromChainId: exFromChainId,
|
|
3415
|
+
toChainId: exToChainId,
|
|
3416
|
+
fromToken: exFromAsset,
|
|
3417
|
+
toToken: exToAsset,
|
|
3418
|
+
amountIn: normEx,
|
|
3419
|
+
recipient: props.recipient
|
|
3420
|
+
},
|
|
3421
|
+
payer
|
|
3422
|
+
),
|
|
3250
3423
|
recipientFor: (account) => isPay ? props.recipient : props.recipient || account,
|
|
3251
3424
|
onQuote: config.onQuote,
|
|
3252
3425
|
onSuccess: config.onSuccess,
|
|
@@ -3254,15 +3427,14 @@ function PaymentIsland(props) {
|
|
|
3254
3427
|
});
|
|
3255
3428
|
const [method, setMethod] = react.useState("stablecoin");
|
|
3256
3429
|
const parked = isPay && !isLiveMethod(method);
|
|
3257
|
-
const fundingSet = react.useMemo(
|
|
3258
|
-
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
3259
|
-
[props.fundingAssets]
|
|
3260
|
-
);
|
|
3430
|
+
const fundingSet = react.useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
|
|
3261
3431
|
const visibleRoutes = react.useMemo(() => {
|
|
3262
3432
|
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
3263
|
-
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(r.source.asset)) : base;
|
|
3433
|
+
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(symbolKey(r.source.asset))) : base;
|
|
3264
3434
|
}, [flow.routes, fundingSet, isPay, method]);
|
|
3265
|
-
const
|
|
3435
|
+
const paymentPlan = flow.plan;
|
|
3436
|
+
const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
|
|
3437
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
|
|
3266
3438
|
const annotated = react.useMemo(
|
|
3267
3439
|
() => visibleRoutes.map((r) => {
|
|
3268
3440
|
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
@@ -3357,7 +3529,15 @@ function PaymentIsland(props) {
|
|
|
3357
3529
|
if (seen.has(key)) continue;
|
|
3358
3530
|
seen.add(key);
|
|
3359
3531
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
|
|
3360
|
-
list.push(
|
|
3532
|
+
list.push(
|
|
3533
|
+
reg ?? {
|
|
3534
|
+
symbol: r.source.asset,
|
|
3535
|
+
name: r.source.asset,
|
|
3536
|
+
chainId: r.source.chainId,
|
|
3537
|
+
address: r.source.tokenAddress ?? "",
|
|
3538
|
+
decimals: r.source.decimals ?? 18
|
|
3539
|
+
}
|
|
3540
|
+
);
|
|
3361
3541
|
}
|
|
3362
3542
|
return list;
|
|
3363
3543
|
}, [visibleRoutes, registryTokens]);
|
|
@@ -3567,7 +3747,18 @@ function PaymentIsland(props) {
|
|
|
3567
3747
|
if (hist && wallet.account) {
|
|
3568
3748
|
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
3569
3749
|
} else if (isPay && view === "select" && wallet.account) {
|
|
3570
|
-
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3750
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3751
|
+
TokenSelect,
|
|
3752
|
+
{
|
|
3753
|
+
title: "Pay with",
|
|
3754
|
+
chains: fundingChains,
|
|
3755
|
+
tokens: fundingTokens,
|
|
3756
|
+
balances: holdings.balances,
|
|
3757
|
+
optionStates,
|
|
3758
|
+
onBack: () => closeSelector(),
|
|
3759
|
+
onPick: pickFunding
|
|
3760
|
+
}
|
|
3761
|
+
);
|
|
3571
3762
|
} else if (!isPay && (view === "from" || view === "to")) {
|
|
3572
3763
|
const isFrom = view === "from";
|
|
3573
3764
|
const openerRef = isFrom ? exFromTileRef : exToTileRef;
|
|
@@ -3767,22 +3958,66 @@ function PaymentIsland(props) {
|
|
|
3767
3958
|
const islandVars = themeToVars(resolved);
|
|
3768
3959
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-wrap", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-island", "data-sg-mode": resolved.mode, "data-expanded": expanded, "data-status": flow.status, style: islandVars, children: [
|
|
3769
3960
|
pillFace,
|
|
3770
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3961
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3962
|
+
"div",
|
|
3963
|
+
{
|
|
3964
|
+
className: "sg-island-body",
|
|
3965
|
+
id: panelId,
|
|
3966
|
+
ref: regionRef,
|
|
3967
|
+
role: "region",
|
|
3968
|
+
"aria-label": isPay ? "ZeroDelta Link checkout" : `ZeroDelta Link ${verb.present.toLowerCase()}`,
|
|
3969
|
+
tabIndex: -1,
|
|
3970
|
+
children: expanded ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3971
|
+
WidgetShell,
|
|
3972
|
+
{
|
|
3973
|
+
variant: "express",
|
|
3974
|
+
title: "ZeroDelta Link",
|
|
3975
|
+
theme: config.theme,
|
|
3976
|
+
heightPx: props.heightPx,
|
|
3977
|
+
brandSlot,
|
|
3978
|
+
walletSlot,
|
|
3979
|
+
children: [
|
|
3980
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
|
|
3981
|
+
body
|
|
3982
|
+
]
|
|
3983
|
+
}
|
|
3984
|
+
) : null
|
|
3985
|
+
}
|
|
3986
|
+
) }) })
|
|
3774
3987
|
] }) });
|
|
3775
3988
|
}
|
|
3776
3989
|
var STABLES2 = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
3990
|
+
var DEFAULT_FUNDING_ASSETS = ["USDC", "USDT", "USDE"];
|
|
3777
3991
|
function CheckGlyph3() {
|
|
3778
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3992
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3993
|
+
"svg",
|
|
3994
|
+
{
|
|
3995
|
+
width: "20",
|
|
3996
|
+
height: "20",
|
|
3997
|
+
viewBox: "0 0 24 24",
|
|
3998
|
+
fill: "none",
|
|
3999
|
+
stroke: "currentColor",
|
|
4000
|
+
strokeWidth: "3",
|
|
4001
|
+
strokeLinecap: "round",
|
|
4002
|
+
strokeLinejoin: "round",
|
|
4003
|
+
"aria-hidden": "true",
|
|
4004
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
4005
|
+
}
|
|
4006
|
+
);
|
|
3779
4007
|
}
|
|
3780
4008
|
var addrEq2 = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
|
|
3781
4009
|
function StableGeniePay(props) {
|
|
3782
4010
|
const config = useMergedConfig(props);
|
|
3783
|
-
const engine = useEngine({
|
|
4011
|
+
const engine = useEngine({
|
|
4012
|
+
apiBase: config.apiBase,
|
|
4013
|
+
apiKey: config.apiKey,
|
|
4014
|
+
trustedApiOrigin: config.trustedApiOrigin,
|
|
4015
|
+
rpcOverrides: config.rpcOverrides,
|
|
4016
|
+
onTransaction: config.onTransaction
|
|
4017
|
+
});
|
|
3784
4018
|
const wallet = useWallet(config.provider);
|
|
3785
|
-
const
|
|
4019
|
+
const planFundingAssets = props.fundingAssets?.length ? props.fundingAssets : DEFAULT_FUNDING_ASSETS;
|
|
4020
|
+
const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${planFundingAssets.join(",")}`;
|
|
3786
4021
|
const flow = useFlow({
|
|
3787
4022
|
engine,
|
|
3788
4023
|
wallet,
|
|
@@ -3791,22 +4026,24 @@ function StableGeniePay(props) {
|
|
|
3791
4026
|
// network work here, or every quote / balance read fires twice and onQuote/onError double-fire.
|
|
3792
4027
|
enabled: Boolean(props.recipient && props.amount) && props.variant !== "pill",
|
|
3793
4028
|
paramsKey,
|
|
3794
|
-
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
4029
|
+
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
4030
|
+
chainId,
|
|
4031
|
+
fundingAssets: planFundingAssets
|
|
4032
|
+
}),
|
|
3795
4033
|
recipientFor: () => props.recipient,
|
|
3796
4034
|
onQuote: config.onQuote,
|
|
3797
4035
|
onSuccess: config.onSuccess,
|
|
3798
4036
|
onError: config.onError
|
|
3799
4037
|
});
|
|
3800
4038
|
const [method, setMethod] = react.useState("stablecoin");
|
|
3801
|
-
const fundingSet = react.useMemo(
|
|
3802
|
-
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
3803
|
-
[props.fundingAssets]
|
|
3804
|
-
);
|
|
4039
|
+
const fundingSet = react.useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
|
|
3805
4040
|
const visibleRoutes = react.useMemo(() => {
|
|
3806
4041
|
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
3807
|
-
return method === "stablecoin" ? base.filter((r) => STABLES2.has(r.source.asset)) : base;
|
|
4042
|
+
return method === "stablecoin" ? base.filter((r) => STABLES2.has(symbolKey(r.source.asset))) : base;
|
|
3808
4043
|
}, [flow.routes, method, fundingSet]);
|
|
3809
|
-
const
|
|
4044
|
+
const paymentPlan = flow.plan;
|
|
4045
|
+
const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
|
|
4046
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
|
|
3810
4047
|
const annotated = react.useMemo(
|
|
3811
4048
|
() => visibleRoutes.map((r) => {
|
|
3812
4049
|
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
@@ -3880,7 +4117,15 @@ function StableGeniePay(props) {
|
|
|
3880
4117
|
if (seen.has(key)) continue;
|
|
3881
4118
|
seen.add(key);
|
|
3882
4119
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
|
|
3883
|
-
list.push(
|
|
4120
|
+
list.push(
|
|
4121
|
+
reg ?? {
|
|
4122
|
+
symbol: r.source.asset,
|
|
4123
|
+
name: r.source.asset,
|
|
4124
|
+
chainId: r.source.chainId,
|
|
4125
|
+
address: r.source.tokenAddress ?? "",
|
|
4126
|
+
decimals: r.source.decimals ?? 18
|
|
4127
|
+
}
|
|
4128
|
+
);
|
|
3884
4129
|
}
|
|
3885
4130
|
return list;
|
|
3886
4131
|
}, [visibleRoutes, registryTokens]);
|
|
@@ -3962,7 +4207,18 @@ function StableGeniePay(props) {
|
|
|
3962
4207
|
] })
|
|
3963
4208
|
] }) : void 0;
|
|
3964
4209
|
if (props.variant === "pill") return /* @__PURE__ */ jsxRuntime.jsx(PaymentIsland, { kind: "pay", ...props });
|
|
3965
|
-
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4210
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4211
|
+
TokenSelect,
|
|
4212
|
+
{
|
|
4213
|
+
title: "Pay with",
|
|
4214
|
+
chains: fundingChains,
|
|
4215
|
+
tokens: fundingTokens,
|
|
4216
|
+
balances: holdings.balances,
|
|
4217
|
+
optionStates,
|
|
4218
|
+
onBack: closeSelector,
|
|
4219
|
+
onPick: pickFunding
|
|
4220
|
+
}
|
|
4221
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: !wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
3966
4222
|
/* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
|
|
3967
4223
|
wallet.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
3968
4224
|
] }) : flow.status === "success" || flow.status === "pending" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
@@ -4020,7 +4276,15 @@ function StableGeniePay(props) {
|
|
|
4020
4276
|
flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null
|
|
4021
4277
|
] }),
|
|
4022
4278
|
submitting ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { steps: flow.steps }) : null,
|
|
4023
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4279
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4280
|
+
Button,
|
|
4281
|
+
{
|
|
4282
|
+
onClick: parked || !selectedVisible ? void 0 : flow.submit,
|
|
4283
|
+
busy: submitting,
|
|
4284
|
+
disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading",
|
|
4285
|
+
children: payLabel
|
|
4286
|
+
}
|
|
4287
|
+
) })
|
|
4024
4288
|
] }) }) });
|
|
4025
4289
|
}
|
|
4026
4290
|
var chainOptions = SUPPORTED_CHAINS.map((c) => ({ value: c, label: CHAIN_LABELS[c] || `Chain ${c}` }));
|
package/dist/mount.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { M as MountConfig, q as mount } from './mount-
|
|
1
|
+
export { M as MountConfig, q as mount } from './mount-BC5gY1X6.cjs';
|
|
2
2
|
import 'react';
|
|
3
|
-
import './verify-
|
|
3
|
+
import './verify-DFTuQ2g3.cjs';
|
package/dist/mount.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { M as MountConfig, q as mount } from './mount-
|
|
1
|
+
export { M as MountConfig, q as mount } from './mount-8nchcNbL.js';
|
|
2
2
|
import 'react';
|
|
3
|
-
import './verify-
|
|
3
|
+
import './verify-DFTuQ2g3.js';
|
package/dist/mount.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { mount } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { mount } from './chunk-TR2XMP7X.js';
|
|
2
|
+
import './chunk-AZPTL3KD.js';
|