@fluent.xyz/connect 0.6.2 → 0.6.3
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/index.d.ts +18 -9
- package/dist/index.js +445 -207
- package/dist/index.js.map +1 -1
- package/docs/api.md +16 -8
- package/docs/errors.md +10 -4
- package/docs/getting-started.md +4 -2
- package/docs/guides/transactions.md +9 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,6 +20,8 @@ import { coinbaseWallet, baseAccount } from 'wagmi/connectors';
|
|
|
20
20
|
import { Dialog as Dialog$1 } from '@base-ui/react/dialog';
|
|
21
21
|
import { Select as Select$1 } from '@base-ui/react/select';
|
|
22
22
|
import { Tooltip as Tooltip$1 } from '@base-ui/react/tooltip';
|
|
23
|
+
import { createKernelAccount, createKernelAccountClient, createZeroDevPaymasterClient } from '@zerodev/sdk';
|
|
24
|
+
import { getEntryPoint, KERNEL_V3_3 } from '@zerodev/sdk/constants';
|
|
23
25
|
import { Switch as Switch$1 } from '@base-ui/react/switch';
|
|
24
26
|
import { Tabs as Tabs$1 } from '@base-ui/react/tabs';
|
|
25
27
|
import { RainbowKitProvider, darkTheme, useConnectModal } from '@rainbow-me/rainbowkit';
|
|
@@ -27,8 +29,6 @@ import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
|
|
|
27
29
|
import { deserializePermissionAccount } from '@zerodev/permissions';
|
|
28
30
|
import '@zerodev/permissions/policies';
|
|
29
31
|
import { toECDSASigner } from '@zerodev/permissions/signers';
|
|
30
|
-
import { createKernelAccount, createKernelAccountClient, createZeroDevPaymasterClient } from '@zerodev/sdk';
|
|
31
|
-
import { getEntryPoint, KERNEL_V3_3 } from '@zerodev/sdk/constants';
|
|
32
32
|
import { privateKeyToAccount, toAccount } from 'viem/accounts';
|
|
33
33
|
import { WaitForUserOperationReceiptTimeoutError, estimateUserOperationGas, getPaymasterData, getPaymasterStubData } from 'viem/account-abstraction';
|
|
34
34
|
import { getUserOperationGasPrice } from '@zerodev/sdk/actions';
|
|
@@ -5612,7 +5612,7 @@ function createFluentConnectForWidget(config) {
|
|
|
5612
5612
|
}
|
|
5613
5613
|
|
|
5614
5614
|
// package.json
|
|
5615
|
-
var version = "0.6.
|
|
5615
|
+
var version = "0.6.3";
|
|
5616
5616
|
|
|
5617
5617
|
// src/core/analytics.ts
|
|
5618
5618
|
var INSTANCE_NAME = "fluent";
|
|
@@ -6374,9 +6374,8 @@ function formatFluentLocaleAmount(value, maximumFractionDigits = 2) {
|
|
|
6374
6374
|
|
|
6375
6375
|
// src/utils/formatFluentGasTokenBalance.ts
|
|
6376
6376
|
var GAS_BALANCE_MAX_FRACTION_DIGITS = 6;
|
|
6377
|
-
function
|
|
6378
|
-
|
|
6379
|
-
return (raw + discardedScale / 2n) / discardedScale;
|
|
6377
|
+
function truncateToFractionDigits(raw, decimals, digits) {
|
|
6378
|
+
return raw / 10n ** BigInt(decimals - digits);
|
|
6380
6379
|
}
|
|
6381
6380
|
function formatFluentGasTokenBalance(balance, maximumFractionDigits = 1) {
|
|
6382
6381
|
if (balance.raw === null || balance.formatted === null) return null;
|
|
@@ -6391,9 +6390,9 @@ function formatFluentGasTokenBalance(balance, maximumFractionDigits = 1) {
|
|
|
6391
6390
|
Math.min(balance.decimals, GAS_BALANCE_MAX_FRACTION_DIGITS)
|
|
6392
6391
|
);
|
|
6393
6392
|
for (let digits = maximumFractionDigits; digits <= maxDigits; digits += 1) {
|
|
6394
|
-
const
|
|
6395
|
-
if (
|
|
6396
|
-
return formatFluentLocaleAmount(formatUnits(
|
|
6393
|
+
const cut = truncateToFractionDigits(balance.raw, balance.decimals, digits);
|
|
6394
|
+
if (cut > 0n || balance.raw === 0n) {
|
|
6395
|
+
return formatFluentLocaleAmount(formatUnits(cut, digits), digits);
|
|
6397
6396
|
}
|
|
6398
6397
|
}
|
|
6399
6398
|
return formatFluentLocaleAmount(0, maximumFractionDigits);
|
|
@@ -7068,7 +7067,7 @@ function InlineConnectModal(props) {
|
|
|
7068
7067
|
);
|
|
7069
7068
|
const { ready, authenticated, user } = usePrivy2();
|
|
7070
7069
|
const { isOpen: securityPromptOpen } = useModalStatus2();
|
|
7071
|
-
const { wallets
|
|
7070
|
+
const { wallets } = useWallets2();
|
|
7072
7071
|
const { createWallet } = useCreateWallet2();
|
|
7073
7072
|
const { sendCode, loginWithCode } = useLoginWithEmail2();
|
|
7074
7073
|
const { initOAuth, state: oauthState } = useLoginWithOAuth2();
|
|
@@ -7172,7 +7171,7 @@ function InlineConnectModal(props) {
|
|
|
7172
7171
|
return () => clearTimeout(timer);
|
|
7173
7172
|
}, [open, connecting, step, walletAttempt]);
|
|
7174
7173
|
React.useEffect(() => {
|
|
7175
|
-
if (!ready || !authenticated || !
|
|
7174
|
+
if (!ready || !authenticated || !user?.id || walletUserPrivySession) return;
|
|
7176
7175
|
clearInlineOAuth();
|
|
7177
7176
|
const embedded = (account) => account.walletClientType === "privy" && (!account.chainType || account.chainType === "ethereum");
|
|
7178
7177
|
if (wallets.some(embedded) || user.linkedAccounts?.some(
|
|
@@ -7193,7 +7192,6 @@ function InlineConnectModal(props) {
|
|
|
7193
7192
|
}, [
|
|
7194
7193
|
ready,
|
|
7195
7194
|
authenticated,
|
|
7196
|
-
walletsReady,
|
|
7197
7195
|
wallets,
|
|
7198
7196
|
user,
|
|
7199
7197
|
createWallet,
|
|
@@ -8296,7 +8294,7 @@ function depositSwapCopy(state, slow, route) {
|
|
|
8296
8294
|
case "bridging":
|
|
8297
8295
|
return {
|
|
8298
8296
|
heading: "Funds on the way",
|
|
8299
|
-
detail: slow ? "Your deposit
|
|
8297
|
+
detail: slow ? "Your deposit is on its way, but it's taking longer than usual. You can swap as soon as it arrives." : `Your ${state.deposit.from.symbol} is on its way to ${route.destination.name} \u2014 this usually takes a few minutes.`
|
|
8300
8298
|
};
|
|
8301
8299
|
case "bridge_failed":
|
|
8302
8300
|
return { heading: "The deposit did not land", detail: state.message };
|
|
@@ -8561,9 +8559,12 @@ function groupFluentTransactionHistory(params) {
|
|
|
8561
8559
|
}
|
|
8562
8560
|
function orderOperationMovements(movements) {
|
|
8563
8561
|
return [...movements].sort(
|
|
8564
|
-
(left, right) => Number(isFluentDustAmount(left.amount)) - Number(isFluentDustAmount(right.amount))
|
|
8562
|
+
(left, right) => Number(isNativeMovement(right)) - Number(isNativeMovement(left)) || Number(isFluentDustAmount(left.amount)) - Number(isFluentDustAmount(right.amount))
|
|
8565
8563
|
);
|
|
8566
8564
|
}
|
|
8565
|
+
function isNativeMovement(movement) {
|
|
8566
|
+
return movement.tokenIdentity.endsWith(":native");
|
|
8567
|
+
}
|
|
8567
8568
|
function filterFluentTransactionHistory(entries, tokens) {
|
|
8568
8569
|
const listed = new Set(tokens.map((token) => token.identity));
|
|
8569
8570
|
return entries.flatMap((entry) => {
|
|
@@ -8961,6 +8962,20 @@ function formatFluentMovementsUsd(movements, priceOf) {
|
|
|
8961
8962
|
if (figures.every((figure) => figure === void 0)) return void 0;
|
|
8962
8963
|
return figures.map((figure) => figure ?? "\u2014").join(", ");
|
|
8963
8964
|
}
|
|
8965
|
+
function pickFluentHeadlineMovement(movements, priceOf) {
|
|
8966
|
+
let headline;
|
|
8967
|
+
let headlineUsd = -1;
|
|
8968
|
+
for (const movement of movements) {
|
|
8969
|
+
const price = priceOf(movement);
|
|
8970
|
+
const usd = price === void 0 ? 0 : Number(movement.amount) * price;
|
|
8971
|
+
const worth = Number.isFinite(usd) ? usd : 0;
|
|
8972
|
+
if (worth > headlineUsd) {
|
|
8973
|
+
headline = movement;
|
|
8974
|
+
headlineUsd = worth;
|
|
8975
|
+
}
|
|
8976
|
+
}
|
|
8977
|
+
return headline;
|
|
8978
|
+
}
|
|
8964
8979
|
function ActivityUsd({ usd, failed }) {
|
|
8965
8980
|
if (!usd) return null;
|
|
8966
8981
|
return /* @__PURE__ */ jsx(
|
|
@@ -9177,7 +9192,7 @@ function FluentActivityRow({
|
|
|
9177
9192
|
const movements = entry.kind === "movement" ? [entry] : entry.movements;
|
|
9178
9193
|
const summary = describeFluentTransaction(entry);
|
|
9179
9194
|
const swap = splitFluentSwap(movements);
|
|
9180
|
-
const movement = swap ? swap.received[0] : movements
|
|
9195
|
+
const movement = swap ? swap.received[0] : pickFluentHeadlineMovement(movements, priceOf);
|
|
9181
9196
|
const statusLabel = FLUENT_TRANSACTION_STATUS_LABELS[entry.status];
|
|
9182
9197
|
const detail = swap ? formatFluentSwapPair(swap) : summary.counterparty ? `${summary.direction === "sent" ? "To" : "From"} ${formatAddress(summary.counterparty)}` : `Op ${formatAddress(entry.hash)}`;
|
|
9183
9198
|
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
@@ -9210,16 +9225,16 @@ function FluentActivityRow({
|
|
|
9210
9225
|
secondary: item.direction === "sent"
|
|
9211
9226
|
},
|
|
9212
9227
|
item.id
|
|
9213
|
-
)) :
|
|
9214
|
-
/* @__PURE__ */ jsx(ActivityAmount, { movement
|
|
9228
|
+
)) : movement ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9229
|
+
/* @__PURE__ */ jsx(ActivityAmount, { movement, status: entry.status }),
|
|
9215
9230
|
/* @__PURE__ */ jsx(
|
|
9216
9231
|
ActivityUsd,
|
|
9217
9232
|
{
|
|
9218
|
-
usd: formatActivityUsd(
|
|
9233
|
+
usd: formatActivityUsd(movement.amount, priceOf(movement)),
|
|
9219
9234
|
failed: entry.status === "failed"
|
|
9220
9235
|
}
|
|
9221
9236
|
)
|
|
9222
|
-
] }
|
|
9237
|
+
] }) : null })
|
|
9223
9238
|
]
|
|
9224
9239
|
}
|
|
9225
9240
|
) });
|
|
@@ -9888,6 +9903,334 @@ function convertFluentFeeToGasToken(params) {
|
|
|
9888
9903
|
if (rateWei === 0n) return void 0;
|
|
9889
9904
|
return wei * 10n ** BigInt(feeToken.decimals) / rateWei;
|
|
9890
9905
|
}
|
|
9906
|
+
var FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY = "selfFunded=true";
|
|
9907
|
+
var FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS = 50000n;
|
|
9908
|
+
function getFluentZeroDevErc20PaymasterTokens(network = "testnet") {
|
|
9909
|
+
return Object.fromEntries(
|
|
9910
|
+
getFluentDefaultWidgetGasTokens(network).filter((token) => !isFluentNativeToken(token) && token.address).map((token) => [
|
|
9911
|
+
token.symbol.toUpperCase(),
|
|
9912
|
+
{
|
|
9913
|
+
address: token.address,
|
|
9914
|
+
decimals: token.decimals,
|
|
9915
|
+
symbol: token.symbol
|
|
9916
|
+
}
|
|
9917
|
+
])
|
|
9918
|
+
);
|
|
9919
|
+
}
|
|
9920
|
+
function createFluentZeroDevRpcUrl(params = {}) {
|
|
9921
|
+
const chainId = params.chainId ?? fluentTestnet.id;
|
|
9922
|
+
const projectId = params.projectId ?? getFluentZeroDevProjectId(
|
|
9923
|
+
getFluentWidgetNetworkForChainId(chainId)
|
|
9924
|
+
);
|
|
9925
|
+
const baseUrl = `https://rpc.zerodev.app/api/v3/${projectId}/chain/${chainId}`;
|
|
9926
|
+
return params.selfFunded ? `${baseUrl}?${FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY}` : baseUrl;
|
|
9927
|
+
}
|
|
9928
|
+
function createFluentZeroDevErc20PaymasterRpcUrl(params = {}) {
|
|
9929
|
+
return createFluentZeroDevRpcUrl({ ...params, selfFunded: true });
|
|
9930
|
+
}
|
|
9931
|
+
function createFluentSponsorshipRpcUrl(params) {
|
|
9932
|
+
const base = params.sponsorshipUrl.replace(/\/+$/, "");
|
|
9933
|
+
return `${base}/paymaster/${encodeURIComponent(params.appId)}`;
|
|
9934
|
+
}
|
|
9935
|
+
function createFluentZeroDevSponsoredPaymaster(params) {
|
|
9936
|
+
const paymasterClient = createZeroDevPaymasterClient({
|
|
9937
|
+
chain: params.chain,
|
|
9938
|
+
transport: http(params.rpcUrl, {
|
|
9939
|
+
timeout: FLUENT_RPC_TIMEOUT_MS,
|
|
9940
|
+
fetchOptions: { headers: { Authorization: `Bearer ${params.bearerToken}` } }
|
|
9941
|
+
})
|
|
9942
|
+
});
|
|
9943
|
+
return {
|
|
9944
|
+
getPaymasterData: (userOperation) => paymasterClient.sponsorUserOperation({
|
|
9945
|
+
userOperation: withoutChainMetadata(userOperation)
|
|
9946
|
+
})
|
|
9947
|
+
};
|
|
9948
|
+
}
|
|
9949
|
+
function resolveFluentZeroDevErc20PaymasterToken(token = "BLEND", network = "testnet") {
|
|
9950
|
+
if (typeof token === "object") return token;
|
|
9951
|
+
if (token.startsWith("0x")) return { address: token };
|
|
9952
|
+
const tokens = getFluentZeroDevErc20PaymasterTokens(network);
|
|
9953
|
+
const resolved = tokens[token.toUpperCase()];
|
|
9954
|
+
if (!resolved) {
|
|
9955
|
+
throw new Error(
|
|
9956
|
+
`"${token}" cannot pay gas on ${network}. Paymaster tokens: ${Object.keys(tokens).join(", ") || "none"}`
|
|
9957
|
+
);
|
|
9958
|
+
}
|
|
9959
|
+
return resolved;
|
|
9960
|
+
}
|
|
9961
|
+
function createFluentZeroDevErc20PaymasterClient(params = {}) {
|
|
9962
|
+
const chain = params.chain ?? fluentTestnet;
|
|
9963
|
+
return createZeroDevPaymasterClient({
|
|
9964
|
+
chain,
|
|
9965
|
+
transport: http(
|
|
9966
|
+
params.paymasterRpcUrl ?? createFluentZeroDevErc20PaymasterRpcUrl({ chainId: chain.id }),
|
|
9967
|
+
{ timeout: FLUENT_RPC_TIMEOUT_MS }
|
|
9968
|
+
)
|
|
9969
|
+
});
|
|
9970
|
+
}
|
|
9971
|
+
function createFluentZeroDevErc20Paymaster(params) {
|
|
9972
|
+
const chain = params.chain ?? fluentTestnet;
|
|
9973
|
+
const gasToken = resolveFluentZeroDevErc20PaymasterToken(
|
|
9974
|
+
params.gasToken,
|
|
9975
|
+
params.network
|
|
9976
|
+
);
|
|
9977
|
+
const paymasterClient = params.paymasterClient ?? createFluentZeroDevErc20PaymasterClient({
|
|
9978
|
+
chain,
|
|
9979
|
+
paymasterRpcUrl: params.paymasterRpcUrl
|
|
9980
|
+
});
|
|
9981
|
+
return {
|
|
9982
|
+
getPaymasterData: async (userOperation) => {
|
|
9983
|
+
const contextToken = getPaymasterContextToken(userOperation.context);
|
|
9984
|
+
const token = contextToken && contextToken.toLowerCase() !== gasToken.address.toLowerCase() ? { address: contextToken } : gasToken;
|
|
9985
|
+
const prepared = withMinimumPostOpGas(withoutChainMetadata(userOperation));
|
|
9986
|
+
const label = token.symbol ?? token.address;
|
|
9987
|
+
if (params.publicClient) {
|
|
9988
|
+
const shortfall = await readFluentGasTokenShortfall({
|
|
9989
|
+
chain,
|
|
9990
|
+
paymasterClient,
|
|
9991
|
+
publicClient: params.publicClient,
|
|
9992
|
+
gasToken: token.address,
|
|
9993
|
+
userOperation: prepared,
|
|
9994
|
+
entryPointAddress: userOperation.entryPointAddress
|
|
9995
|
+
});
|
|
9996
|
+
if (shortfall) {
|
|
9997
|
+
throw new FluentGasPaymentError(
|
|
9998
|
+
"insufficient_gas_token",
|
|
9999
|
+
`The ${label} balance (${shortfall.balance}) is below the fee the paymaster quotes for this operation (${shortfall.fee}), in ${label}'s smallest unit`
|
|
10000
|
+
);
|
|
10001
|
+
}
|
|
10002
|
+
}
|
|
10003
|
+
try {
|
|
10004
|
+
return await paymasterClient.sponsorUserOperation({
|
|
10005
|
+
userOperation: prepared,
|
|
10006
|
+
gasToken: token.address
|
|
10007
|
+
});
|
|
10008
|
+
} catch (err) {
|
|
10009
|
+
throw toFluentGasPaymentRefusal(err, label);
|
|
10010
|
+
}
|
|
10011
|
+
}
|
|
10012
|
+
};
|
|
10013
|
+
}
|
|
10014
|
+
async function readFluentGasTokenShortfall(params) {
|
|
10015
|
+
const { chain, paymasterClient, publicClient, gasToken, userOperation } = params;
|
|
10016
|
+
const sender = userOperation.sender;
|
|
10017
|
+
if (!sender) return void 0;
|
|
10018
|
+
const request = paymasterClient.request;
|
|
10019
|
+
const [quote, balance] = await Promise.allSettled([
|
|
10020
|
+
request({
|
|
10021
|
+
method: "stackup_getERC20TokenQuotes",
|
|
10022
|
+
params: [{
|
|
10023
|
+
chainId: chain.id,
|
|
10024
|
+
userOp: { initCode: "0x", ...deepHexlify(quotedFields(userOperation)) },
|
|
10025
|
+
tokenAddress: gasToken,
|
|
10026
|
+
entryPointAddress: params.entryPointAddress ?? getEntryPoint("0.7").address
|
|
10027
|
+
}]
|
|
10028
|
+
}),
|
|
10029
|
+
publicClient.readContract({
|
|
10030
|
+
address: gasToken,
|
|
10031
|
+
abi: erc20Abi,
|
|
10032
|
+
functionName: "balanceOf",
|
|
10033
|
+
args: [sender]
|
|
10034
|
+
})
|
|
10035
|
+
]);
|
|
10036
|
+
const fee = quote.status === "fulfilled" ? readQuantity(quote.value, "maxGasCostToken") : void 0;
|
|
10037
|
+
if (fee === void 0 || balance.status !== "fulfilled") {
|
|
10038
|
+
try {
|
|
10039
|
+
debugWarn("[fluent zerodev] Gas token fee check skipped", {
|
|
10040
|
+
gasToken,
|
|
10041
|
+
quote: quote.status === "rejected" ? errorText(quote.reason) : fee?.toString() ?? "unusable",
|
|
10042
|
+
balance: balance.status === "rejected" ? errorText(balance.reason) : "read"
|
|
10043
|
+
});
|
|
10044
|
+
} catch {
|
|
10045
|
+
}
|
|
10046
|
+
return void 0;
|
|
10047
|
+
}
|
|
10048
|
+
return balance.value < fee ? { balance: balance.value, fee } : void 0;
|
|
10049
|
+
}
|
|
10050
|
+
function quotedFields(userOperation) {
|
|
10051
|
+
const {
|
|
10052
|
+
chainId: _chainId,
|
|
10053
|
+
entryPointAddress: _entryPointAddress,
|
|
10054
|
+
...fields
|
|
10055
|
+
} = userOperation;
|
|
10056
|
+
return fields;
|
|
10057
|
+
}
|
|
10058
|
+
function readQuantity(answer, key) {
|
|
10059
|
+
if (!answer || typeof answer !== "object") return void 0;
|
|
10060
|
+
const value = answer[key];
|
|
10061
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return BigInt(value);
|
|
10062
|
+
if (typeof value !== "string" || !/^(0x[\da-f]+|\d+)$/i.test(value)) return void 0;
|
|
10063
|
+
return BigInt(value);
|
|
10064
|
+
}
|
|
10065
|
+
function deepHexlify(value) {
|
|
10066
|
+
if (typeof value === "bigint") return `0x${value.toString(16)}`;
|
|
10067
|
+
if (Array.isArray(value)) return value.map(deepHexlify);
|
|
10068
|
+
if (value && typeof value === "object") {
|
|
10069
|
+
return Object.fromEntries(
|
|
10070
|
+
Object.entries(value).map(([key, entry]) => [key, deepHexlify(entry)])
|
|
10071
|
+
);
|
|
10072
|
+
}
|
|
10073
|
+
return value;
|
|
10074
|
+
}
|
|
10075
|
+
function errorText(err) {
|
|
10076
|
+
return err instanceof Error ? err.message : String(err);
|
|
10077
|
+
}
|
|
10078
|
+
function toFluentGasPaymentRefusal(err, label) {
|
|
10079
|
+
const answered = err instanceof BaseError && err.walk(
|
|
10080
|
+
(inner) => inner instanceof HttpRequestError && inner.status !== void 0 || typeof inner.code === "number"
|
|
10081
|
+
);
|
|
10082
|
+
if (!answered) return err;
|
|
10083
|
+
if (/\bAA50\b|postOp revert/i.test(answerTexts(err).join("\n"))) {
|
|
10084
|
+
return new FluentGasPaymentError(
|
|
10085
|
+
"insufficient_gas_token",
|
|
10086
|
+
`The paymaster could not charge the fee in ${label}: the balance does not cover it`,
|
|
10087
|
+
{ cause: err }
|
|
10088
|
+
);
|
|
10089
|
+
}
|
|
10090
|
+
return new FluentGasPaymentError(
|
|
10091
|
+
"paymaster_rejected",
|
|
10092
|
+
`The paymaster refused to charge the fee in ${label}`,
|
|
10093
|
+
{ cause: err }
|
|
10094
|
+
);
|
|
10095
|
+
}
|
|
10096
|
+
function answerTexts(err) {
|
|
10097
|
+
const texts = [];
|
|
10098
|
+
let current = err;
|
|
10099
|
+
for (let depth = 0; depth < 10 && current instanceof Error; depth += 1) {
|
|
10100
|
+
texts.push(current instanceof BaseError ? current.details : current.message);
|
|
10101
|
+
current = current.cause;
|
|
10102
|
+
}
|
|
10103
|
+
return texts;
|
|
10104
|
+
}
|
|
10105
|
+
var FluentGasPaymentError = class extends Error {
|
|
10106
|
+
constructor(code, message2, options) {
|
|
10107
|
+
super(message2, options);
|
|
10108
|
+
this.code = code;
|
|
10109
|
+
this.name = "FluentGasPaymentError";
|
|
10110
|
+
}
|
|
10111
|
+
code;
|
|
10112
|
+
};
|
|
10113
|
+
var erc20PaymasterAddresses = /* @__PURE__ */ new Map();
|
|
10114
|
+
async function readFluentZeroDevErc20PaymasterAddress(params = {}) {
|
|
10115
|
+
const chain = params.chain ?? fluentTestnet;
|
|
10116
|
+
const paymasterRpcUrl = params.paymasterRpcUrl ?? createFluentZeroDevErc20PaymasterRpcUrl({ chainId: chain.id });
|
|
10117
|
+
const cacheKey = params.paymasterClient ? void 0 : paymasterRpcUrl;
|
|
10118
|
+
const known = cacheKey ? erc20PaymasterAddresses.get(cacheKey) : void 0;
|
|
10119
|
+
if (known) return known;
|
|
10120
|
+
const paymasterClient = params.paymasterClient ?? createFluentZeroDevErc20PaymasterClient({ chain, paymasterRpcUrl });
|
|
10121
|
+
const request = paymasterClient.request;
|
|
10122
|
+
let response;
|
|
10123
|
+
try {
|
|
10124
|
+
response = await request({
|
|
10125
|
+
method: "zd_pm_accounts",
|
|
10126
|
+
params: [{ chainId: chain.id, entryPointAddress: getEntryPoint("0.7").address }]
|
|
10127
|
+
});
|
|
10128
|
+
} catch (err) {
|
|
10129
|
+
throw new FluentGasPaymentError(
|
|
10130
|
+
"paymaster_unavailable",
|
|
10131
|
+
`ZeroDev could not name the ERC-20 paymaster for chain ${chain.id}`,
|
|
10132
|
+
{ cause: err }
|
|
10133
|
+
);
|
|
10134
|
+
}
|
|
10135
|
+
const address = Array.isArray(response) ? response[0] : void 0;
|
|
10136
|
+
if (typeof address !== "string" || !isAddress(address)) {
|
|
10137
|
+
throw new FluentGasPaymentError(
|
|
10138
|
+
"paymaster_unavailable",
|
|
10139
|
+
`ZeroDev named no ERC-20 paymaster for chain ${chain.id}`
|
|
10140
|
+
);
|
|
10141
|
+
}
|
|
10142
|
+
const paymaster = getAddress(address);
|
|
10143
|
+
if (cacheKey) erc20PaymasterAddresses.set(cacheKey, paymaster);
|
|
10144
|
+
return paymaster;
|
|
10145
|
+
}
|
|
10146
|
+
function createFluentErc20ApproveCall(params) {
|
|
10147
|
+
return {
|
|
10148
|
+
to: params.gasToken,
|
|
10149
|
+
data: encodeFunctionData({
|
|
10150
|
+
abi: erc20Abi,
|
|
10151
|
+
functionName: "approve",
|
|
10152
|
+
args: [params.spender, params.amount]
|
|
10153
|
+
}),
|
|
10154
|
+
value: 0n
|
|
10155
|
+
};
|
|
10156
|
+
}
|
|
10157
|
+
function getPaymasterContextToken(context) {
|
|
10158
|
+
if (!context || typeof context !== "object") return void 0;
|
|
10159
|
+
const token = context.token;
|
|
10160
|
+
return typeof token === "string" && token.startsWith("0x") ? token : void 0;
|
|
10161
|
+
}
|
|
10162
|
+
function withMinimumPostOpGas(userOperation) {
|
|
10163
|
+
const limit = userOperation.paymasterPostOpGasLimit;
|
|
10164
|
+
if (limit !== void 0 && limit >= FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS) return userOperation;
|
|
10165
|
+
return {
|
|
10166
|
+
...userOperation,
|
|
10167
|
+
paymasterPostOpGasLimit: FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS
|
|
10168
|
+
};
|
|
10169
|
+
}
|
|
10170
|
+
function withoutChainMetadata(userOperation) {
|
|
10171
|
+
const {
|
|
10172
|
+
chain: _chain,
|
|
10173
|
+
context: _context,
|
|
10174
|
+
paymasterContext: _paymasterContext,
|
|
10175
|
+
...cleanUserOperation
|
|
10176
|
+
} = userOperation;
|
|
10177
|
+
return cleanUserOperation;
|
|
10178
|
+
}
|
|
10179
|
+
|
|
10180
|
+
// src/widget/gasTokenFee.ts
|
|
10181
|
+
function fluentInsufficientGasTokenMessage(symbol) {
|
|
10182
|
+
return `Not enough ${symbol} to pay the network fee. Pay the fee in ETH or add ${symbol}.`;
|
|
10183
|
+
}
|
|
10184
|
+
function isFluentInsufficientGasToken(error) {
|
|
10185
|
+
return error instanceof FluentGasPaymentError && error.code === "insufficient_gas_token";
|
|
10186
|
+
}
|
|
10187
|
+
function describeFluentExecutionFailure(error, gasSymbol, fallback2) {
|
|
10188
|
+
if (isFluentInsufficientGasToken(error)) return fluentInsufficientGasTokenMessage(gasSymbol);
|
|
10189
|
+
return error instanceof Error ? error.message : fallback2;
|
|
10190
|
+
}
|
|
10191
|
+
function withFluentInsufficientGasTokenNotice(api, notify) {
|
|
10192
|
+
return {
|
|
10193
|
+
...api,
|
|
10194
|
+
createBatchOp: (input) => {
|
|
10195
|
+
const operation = api.createBatchOp(input);
|
|
10196
|
+
return {
|
|
10197
|
+
...operation,
|
|
10198
|
+
execute: async (options) => {
|
|
10199
|
+
try {
|
|
10200
|
+
return await operation.execute(options);
|
|
10201
|
+
} catch (error) {
|
|
10202
|
+
if (isFluentInsufficientGasToken(error)) {
|
|
10203
|
+
const symbol = options?.gasPayment?.symbol ?? api.gasPayment.symbol;
|
|
10204
|
+
try {
|
|
10205
|
+
notify(fluentInsufficientGasTokenMessage(symbol));
|
|
10206
|
+
} catch {
|
|
10207
|
+
}
|
|
10208
|
+
}
|
|
10209
|
+
throw error;
|
|
10210
|
+
}
|
|
10211
|
+
}
|
|
10212
|
+
};
|
|
10213
|
+
}
|
|
10214
|
+
};
|
|
10215
|
+
}
|
|
10216
|
+
function useFluentSendRetry(account, open) {
|
|
10217
|
+
const [sendRetry, setSendRetry] = useState(null);
|
|
10218
|
+
const currentAccount = useRef(account);
|
|
10219
|
+
useEffect(() => {
|
|
10220
|
+
currentAccount.current = account;
|
|
10221
|
+
setSendRetry(null);
|
|
10222
|
+
}, [account]);
|
|
10223
|
+
const payFeeInNative = useCallback(
|
|
10224
|
+
(request) => {
|
|
10225
|
+
if (currentAccount.current !== account) return;
|
|
10226
|
+
setSendRetry({ key: Date.now(), request });
|
|
10227
|
+
open();
|
|
10228
|
+
},
|
|
10229
|
+
[account, open]
|
|
10230
|
+
);
|
|
10231
|
+
const clearSendRetry = useCallback(() => setSendRetry(null), []);
|
|
10232
|
+
return { sendRetry, payFeeInNative, clearSendRetry };
|
|
10233
|
+
}
|
|
9891
10234
|
var BRIDGE_AMOUNT_MAX_DECIMALS = 18;
|
|
9892
10235
|
function sanitizeBridgeAmountInput(next, previous = "", decimals = BRIDGE_AMOUNT_MAX_DECIMALS) {
|
|
9893
10236
|
const normalized = next.replace(/,/g, ".").replace(/\s/g, "");
|
|
@@ -10153,13 +10496,18 @@ function SendTokenForm({
|
|
|
10153
10496
|
sponsorshipAvailable = false,
|
|
10154
10497
|
ethValueByToken,
|
|
10155
10498
|
onSend,
|
|
10156
|
-
onSent
|
|
10499
|
+
onSent,
|
|
10500
|
+
retry
|
|
10157
10501
|
}) {
|
|
10158
10502
|
const { chain } = useFluentWidgetNetwork();
|
|
10159
|
-
const [identity, setIdentity] = useState(null);
|
|
10160
|
-
const [gasIdentity, setGasIdentity] = useState(
|
|
10161
|
-
|
|
10162
|
-
|
|
10503
|
+
const [identity, setIdentity] = useState(retry?.token.identity ?? null);
|
|
10504
|
+
const [gasIdentity, setGasIdentity] = useState(
|
|
10505
|
+
retry ? gasTokens.find(isFluentNativeToken)?.identity ?? null : null
|
|
10506
|
+
);
|
|
10507
|
+
const [recipient, setRecipient] = useState(retry?.to ?? "");
|
|
10508
|
+
const [amount, setAmount] = useState(
|
|
10509
|
+
retry ? formatUnits(retry.amount, retry.token.decimals) : ""
|
|
10510
|
+
);
|
|
10163
10511
|
const [sending, setSending] = useState(false);
|
|
10164
10512
|
const [sendError, setSendError] = useState(null);
|
|
10165
10513
|
const [picking, setPicking] = useState(false);
|
|
@@ -10191,7 +10539,7 @@ function SendTokenForm({
|
|
|
10191
10539
|
decimals: token.decimals,
|
|
10192
10540
|
balance: rawBalance
|
|
10193
10541
|
}) : null;
|
|
10194
|
-
const balanceNote = token && rawBalance !== null ? `${
|
|
10542
|
+
const balanceNote = token && rawBalance !== null ? `${formatUnits(rawBalance, token.decimals)} ${token.symbol}` : balancesBusy ? "Loading balance..." : "Balance unavailable";
|
|
10195
10543
|
const amountUsd = token ? formatAmountUsd(amount, usdPrices[token.identity]) : void 0;
|
|
10196
10544
|
const fee = feeToken ? checkFluentTransferFee({
|
|
10197
10545
|
feeToken,
|
|
@@ -10219,6 +10567,8 @@ function SendTokenForm({
|
|
|
10219
10567
|
nativeIdentity: nativeToken?.identity
|
|
10220
10568
|
});
|
|
10221
10569
|
const feeSponsored = Boolean(feeToken && isFluentNativeToken(feeToken) && sponsorshipAvailable);
|
|
10570
|
+
const nativeGasToken = gasTokens.find(isFluentNativeToken);
|
|
10571
|
+
const offerNativeFee = erc20GasAvailable && nativeGasToken && feeToken && !isFluentNativeToken(feeToken) && sendError === fluentInsufficientGasTokenMessage(feeToken.symbol) ? nativeGasToken : void 0;
|
|
10222
10572
|
const feeBalanceLabel = (candidate) => {
|
|
10223
10573
|
const entry = balanceByIdentity.get(candidate.identity);
|
|
10224
10574
|
if (entry?.status === "ready" && entry.raw !== null) {
|
|
@@ -10317,14 +10667,7 @@ function SendTokenForm({
|
|
|
10317
10667
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-1 text-sm text-foreground/60", children: [
|
|
10318
10668
|
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", title: amountUsd, children: amountUsd }),
|
|
10319
10669
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1 whitespace-nowrap", children: [
|
|
10320
|
-
/* @__PURE__ */ jsx(
|
|
10321
|
-
"span",
|
|
10322
|
-
{
|
|
10323
|
-
className: "tabular-nums",
|
|
10324
|
-
title: token && rawBalance !== null ? formatUnits(rawBalance, token.decimals) : void 0,
|
|
10325
|
-
children: balanceNote
|
|
10326
|
-
}
|
|
10327
|
-
),
|
|
10670
|
+
/* @__PURE__ */ jsx("span", { className: "tabular-nums", children: balanceNote }),
|
|
10328
10671
|
/* @__PURE__ */ jsx(
|
|
10329
10672
|
"button",
|
|
10330
10673
|
{
|
|
@@ -10436,7 +10779,22 @@ function SendTokenForm({
|
|
|
10436
10779
|
]
|
|
10437
10780
|
}
|
|
10438
10781
|
) : null,
|
|
10439
|
-
sendError ? /* @__PURE__ */
|
|
10782
|
+
sendError ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-1.5", children: [
|
|
10783
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-destructive", children: sendError }),
|
|
10784
|
+
offerNativeFee ? /* @__PURE__ */ jsx(
|
|
10785
|
+
Button,
|
|
10786
|
+
{
|
|
10787
|
+
type: "button",
|
|
10788
|
+
variant: "secondary",
|
|
10789
|
+
size: "sm",
|
|
10790
|
+
onClick: () => {
|
|
10791
|
+
setSendError(null);
|
|
10792
|
+
setGasIdentity(offerNativeFee.identity);
|
|
10793
|
+
},
|
|
10794
|
+
children: `Pay the fee in ${offerNativeFee.symbol}`
|
|
10795
|
+
}
|
|
10796
|
+
) : null
|
|
10797
|
+
] }) : null,
|
|
10440
10798
|
/* @__PURE__ */ jsx(Button, { className: "w-full", disabled: !ready, onClick: () => void handleSend(), children: sending ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10441
10799
|
/* @__PURE__ */ jsx(Spinner, { className: "size-4" }),
|
|
10442
10800
|
"Sending\u2026"
|
|
@@ -11720,7 +12078,8 @@ function WalletMenuTokenList({
|
|
|
11720
12078
|
const visual = isFluentDefaultToken(token) ? VISUAL_BY_DEFAULT_SYMBOL[token.symbol] : void 0;
|
|
11721
12079
|
const active = selectedSymbol === symbol && gasTokenIdentities.has(identity);
|
|
11722
12080
|
const refreshing = busy && Boolean(accountAddress);
|
|
11723
|
-
const
|
|
12081
|
+
const fractionDigits = fluentAmountFractionDigits(token.symbol);
|
|
12082
|
+
const formatted = balance?.status === "ready" ? formatFluentGasTokenBalance(balance, fractionDigits) ?? (balance.formatted ? formatFluentLocaleAmount(balance.formatted, fractionDigits) : null) : null;
|
|
11724
12083
|
const usdValueLabel = formatTokenUsdValue(balance, usdPrices[identity]);
|
|
11725
12084
|
const exactBalance = balance?.status === "ready" && balance.formatted?.includes(".") ? balance.formatted : null;
|
|
11726
12085
|
return /* @__PURE__ */ jsxs(
|
|
@@ -12040,6 +12399,7 @@ function WalletMenuActionCard({
|
|
|
12040
12399
|
settingsError = null,
|
|
12041
12400
|
tokenListError = null,
|
|
12042
12401
|
onSendToken,
|
|
12402
|
+
sendRetry,
|
|
12043
12403
|
pendingTransfers,
|
|
12044
12404
|
sentTransfer,
|
|
12045
12405
|
sentDeposits,
|
|
@@ -12396,6 +12756,7 @@ function WalletMenuActionCard({
|
|
|
12396
12756
|
return /* @__PURE__ */ jsx(
|
|
12397
12757
|
SendTokenForm,
|
|
12398
12758
|
{
|
|
12759
|
+
retry: sendRetry?.request,
|
|
12399
12760
|
tokens: displayTokens,
|
|
12400
12761
|
balances,
|
|
12401
12762
|
balancesBusy,
|
|
@@ -12412,7 +12773,8 @@ function WalletMenuActionCard({
|
|
|
12412
12773
|
onTabChange(SENT_TRANSFER_TAB);
|
|
12413
12774
|
onRevealAccount?.();
|
|
12414
12775
|
}
|
|
12415
|
-
}
|
|
12776
|
+
},
|
|
12777
|
+
sendRetry?.key
|
|
12416
12778
|
);
|
|
12417
12779
|
}
|
|
12418
12780
|
if (tab === SENT_TRANSFER_TAB) {
|
|
@@ -15316,165 +15678,6 @@ function encodeBatchCall(call) {
|
|
|
15316
15678
|
})
|
|
15317
15679
|
};
|
|
15318
15680
|
}
|
|
15319
|
-
var FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY = "selfFunded=true";
|
|
15320
|
-
var FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS = 50000n;
|
|
15321
|
-
function getFluentZeroDevErc20PaymasterTokens(network = "testnet") {
|
|
15322
|
-
return Object.fromEntries(
|
|
15323
|
-
getFluentDefaultWidgetGasTokens(network).filter((token) => !isFluentNativeToken(token) && token.address).map((token) => [
|
|
15324
|
-
token.symbol.toUpperCase(),
|
|
15325
|
-
{
|
|
15326
|
-
address: token.address,
|
|
15327
|
-
decimals: token.decimals,
|
|
15328
|
-
symbol: token.symbol
|
|
15329
|
-
}
|
|
15330
|
-
])
|
|
15331
|
-
);
|
|
15332
|
-
}
|
|
15333
|
-
function createFluentZeroDevRpcUrl(params = {}) {
|
|
15334
|
-
const chainId = params.chainId ?? fluentTestnet.id;
|
|
15335
|
-
const projectId = params.projectId ?? getFluentZeroDevProjectId(
|
|
15336
|
-
getFluentWidgetNetworkForChainId(chainId)
|
|
15337
|
-
);
|
|
15338
|
-
const baseUrl = `https://rpc.zerodev.app/api/v3/${projectId}/chain/${chainId}`;
|
|
15339
|
-
return params.selfFunded ? `${baseUrl}?${FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY}` : baseUrl;
|
|
15340
|
-
}
|
|
15341
|
-
function createFluentZeroDevErc20PaymasterRpcUrl(params = {}) {
|
|
15342
|
-
return createFluentZeroDevRpcUrl({ ...params, selfFunded: true });
|
|
15343
|
-
}
|
|
15344
|
-
function createFluentSponsorshipRpcUrl(params) {
|
|
15345
|
-
const base = params.sponsorshipUrl.replace(/\/+$/, "");
|
|
15346
|
-
return `${base}/paymaster/${encodeURIComponent(params.appId)}`;
|
|
15347
|
-
}
|
|
15348
|
-
function createFluentZeroDevSponsoredPaymaster(params) {
|
|
15349
|
-
const paymasterClient = createZeroDevPaymasterClient({
|
|
15350
|
-
chain: params.chain,
|
|
15351
|
-
transport: http(params.rpcUrl, {
|
|
15352
|
-
timeout: FLUENT_RPC_TIMEOUT_MS,
|
|
15353
|
-
fetchOptions: { headers: { Authorization: `Bearer ${params.bearerToken}` } }
|
|
15354
|
-
})
|
|
15355
|
-
});
|
|
15356
|
-
return {
|
|
15357
|
-
getPaymasterData: (userOperation) => paymasterClient.sponsorUserOperation({
|
|
15358
|
-
userOperation: withoutChainMetadata(userOperation)
|
|
15359
|
-
})
|
|
15360
|
-
};
|
|
15361
|
-
}
|
|
15362
|
-
function resolveFluentZeroDevErc20PaymasterToken(token = "BLEND", network = "testnet") {
|
|
15363
|
-
if (typeof token === "object") return token;
|
|
15364
|
-
if (token.startsWith("0x")) return { address: token };
|
|
15365
|
-
const tokens = getFluentZeroDevErc20PaymasterTokens(network);
|
|
15366
|
-
const resolved = tokens[token.toUpperCase()];
|
|
15367
|
-
if (!resolved) {
|
|
15368
|
-
throw new Error(
|
|
15369
|
-
`"${token}" cannot pay gas on ${network}. Paymaster tokens: ${Object.keys(tokens).join(", ") || "none"}`
|
|
15370
|
-
);
|
|
15371
|
-
}
|
|
15372
|
-
return resolved;
|
|
15373
|
-
}
|
|
15374
|
-
function createFluentZeroDevErc20PaymasterClient(params = {}) {
|
|
15375
|
-
const chain = params.chain ?? fluentTestnet;
|
|
15376
|
-
return createZeroDevPaymasterClient({
|
|
15377
|
-
chain,
|
|
15378
|
-
transport: http(
|
|
15379
|
-
params.paymasterRpcUrl ?? createFluentZeroDevErc20PaymasterRpcUrl({ chainId: chain.id }),
|
|
15380
|
-
{ timeout: FLUENT_RPC_TIMEOUT_MS }
|
|
15381
|
-
)
|
|
15382
|
-
});
|
|
15383
|
-
}
|
|
15384
|
-
function createFluentZeroDevErc20Paymaster(params) {
|
|
15385
|
-
const chain = params.chain ?? fluentTestnet;
|
|
15386
|
-
const gasToken = resolveFluentZeroDevErc20PaymasterToken(
|
|
15387
|
-
params.gasToken,
|
|
15388
|
-
params.network
|
|
15389
|
-
);
|
|
15390
|
-
const paymasterClient = params.paymasterClient ?? createFluentZeroDevErc20PaymasterClient({
|
|
15391
|
-
chain,
|
|
15392
|
-
paymasterRpcUrl: params.paymasterRpcUrl
|
|
15393
|
-
});
|
|
15394
|
-
return {
|
|
15395
|
-
getPaymasterData: (userOperation) => {
|
|
15396
|
-
const contextToken = getPaymasterContextToken(userOperation.context);
|
|
15397
|
-
return paymasterClient.sponsorUserOperation({
|
|
15398
|
-
userOperation: withMinimumPostOpGas(withoutChainMetadata(userOperation)),
|
|
15399
|
-
gasToken: contextToken ?? gasToken.address
|
|
15400
|
-
});
|
|
15401
|
-
}
|
|
15402
|
-
};
|
|
15403
|
-
}
|
|
15404
|
-
var FluentGasPaymentError = class extends Error {
|
|
15405
|
-
constructor(code, message2, options) {
|
|
15406
|
-
super(message2, options);
|
|
15407
|
-
this.code = code;
|
|
15408
|
-
this.name = "FluentGasPaymentError";
|
|
15409
|
-
}
|
|
15410
|
-
code;
|
|
15411
|
-
};
|
|
15412
|
-
var erc20PaymasterAddresses = /* @__PURE__ */ new Map();
|
|
15413
|
-
async function readFluentZeroDevErc20PaymasterAddress(params = {}) {
|
|
15414
|
-
const chain = params.chain ?? fluentTestnet;
|
|
15415
|
-
const paymasterRpcUrl = params.paymasterRpcUrl ?? createFluentZeroDevErc20PaymasterRpcUrl({ chainId: chain.id });
|
|
15416
|
-
const cacheKey = params.paymasterClient ? void 0 : paymasterRpcUrl;
|
|
15417
|
-
const known = cacheKey ? erc20PaymasterAddresses.get(cacheKey) : void 0;
|
|
15418
|
-
if (known) return known;
|
|
15419
|
-
const paymasterClient = params.paymasterClient ?? createFluentZeroDevErc20PaymasterClient({ chain, paymasterRpcUrl });
|
|
15420
|
-
const request = paymasterClient.request;
|
|
15421
|
-
let response;
|
|
15422
|
-
try {
|
|
15423
|
-
response = await request({
|
|
15424
|
-
method: "zd_pm_accounts",
|
|
15425
|
-
params: [{ chainId: chain.id, entryPointAddress: getEntryPoint("0.7").address }]
|
|
15426
|
-
});
|
|
15427
|
-
} catch (err) {
|
|
15428
|
-
throw new FluentGasPaymentError(
|
|
15429
|
-
"paymaster_unavailable",
|
|
15430
|
-
`ZeroDev could not name the ERC-20 paymaster for chain ${chain.id}`,
|
|
15431
|
-
{ cause: err }
|
|
15432
|
-
);
|
|
15433
|
-
}
|
|
15434
|
-
const address = Array.isArray(response) ? response[0] : void 0;
|
|
15435
|
-
if (typeof address !== "string" || !isAddress(address)) {
|
|
15436
|
-
throw new FluentGasPaymentError(
|
|
15437
|
-
"paymaster_unavailable",
|
|
15438
|
-
`ZeroDev named no ERC-20 paymaster for chain ${chain.id}`
|
|
15439
|
-
);
|
|
15440
|
-
}
|
|
15441
|
-
const paymaster = getAddress(address);
|
|
15442
|
-
if (cacheKey) erc20PaymasterAddresses.set(cacheKey, paymaster);
|
|
15443
|
-
return paymaster;
|
|
15444
|
-
}
|
|
15445
|
-
function createFluentErc20ApproveCall(params) {
|
|
15446
|
-
return {
|
|
15447
|
-
to: params.gasToken,
|
|
15448
|
-
data: encodeFunctionData({
|
|
15449
|
-
abi: erc20Abi,
|
|
15450
|
-
functionName: "approve",
|
|
15451
|
-
args: [params.spender, params.amount]
|
|
15452
|
-
}),
|
|
15453
|
-
value: 0n
|
|
15454
|
-
};
|
|
15455
|
-
}
|
|
15456
|
-
function getPaymasterContextToken(context) {
|
|
15457
|
-
if (!context || typeof context !== "object") return void 0;
|
|
15458
|
-
const token = context.token;
|
|
15459
|
-
return typeof token === "string" && token.startsWith("0x") ? token : void 0;
|
|
15460
|
-
}
|
|
15461
|
-
function withMinimumPostOpGas(userOperation) {
|
|
15462
|
-
const limit = userOperation.paymasterPostOpGasLimit;
|
|
15463
|
-
if (limit !== void 0 && limit >= FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS) return userOperation;
|
|
15464
|
-
return {
|
|
15465
|
-
...userOperation,
|
|
15466
|
-
paymasterPostOpGasLimit: FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS
|
|
15467
|
-
};
|
|
15468
|
-
}
|
|
15469
|
-
function withoutChainMetadata(userOperation) {
|
|
15470
|
-
const {
|
|
15471
|
-
chain: _chain,
|
|
15472
|
-
context: _context,
|
|
15473
|
-
paymasterContext: _paymasterContext,
|
|
15474
|
-
...cleanUserOperation
|
|
15475
|
-
} = userOperation;
|
|
15476
|
-
return cleanUserOperation;
|
|
15477
|
-
}
|
|
15478
15681
|
var FluentSponsorshipFallbackError = class extends Error {
|
|
15479
15682
|
code;
|
|
15480
15683
|
sponsorshipReason;
|
|
@@ -16585,7 +16788,12 @@ async function sendCalls(context, calls, options, readyAccount) {
|
|
|
16585
16788
|
};
|
|
16586
16789
|
const sponsorshipRefused = !gasToken && options?.gasPayment?.sponsorship === "never";
|
|
16587
16790
|
const sponsorship = context.sponsorshipUrl && context.appId ? { sponsorshipUrl: context.sponsorshipUrl, appId: context.appId } : null;
|
|
16588
|
-
const executionClient = gasToken ? createFluentZeroDevErc20ExecutionClient(
|
|
16791
|
+
const executionClient = gasToken ? createFluentZeroDevErc20ExecutionClient(
|
|
16792
|
+
executionKernel,
|
|
16793
|
+
gasToken,
|
|
16794
|
+
readExecution,
|
|
16795
|
+
options?.gasPayment?.symbol
|
|
16796
|
+
) : executionKernel.client;
|
|
16589
16797
|
const callSponsored = !gasToken && !sponsorshipRefused && sponsorship && !sponsorshipUnavailable.current;
|
|
16590
16798
|
if (execution.receiptSource === "chain") {
|
|
16591
16799
|
inclusionAnchor = await readFluentInclusionAnchor(executionKernel.publicClient);
|
|
@@ -16829,13 +17037,14 @@ async function createFluentZeroDevKernel(params) {
|
|
|
16829
17037
|
signerSource: "privy"
|
|
16830
17038
|
};
|
|
16831
17039
|
}
|
|
16832
|
-
function createFluentZeroDevErc20ExecutionClient(kernel, gasToken, readExecution) {
|
|
17040
|
+
function createFluentZeroDevErc20ExecutionClient(kernel, gasToken, readExecution, gasTokenSymbol) {
|
|
16833
17041
|
return createFluentZeroDevKernelClient({
|
|
16834
17042
|
kernel,
|
|
16835
17043
|
readExecution,
|
|
16836
17044
|
paymaster: createFluentZeroDevErc20Paymaster({
|
|
16837
17045
|
chain: kernel.chain,
|
|
16838
|
-
gasToken
|
|
17046
|
+
gasToken: { address: gasToken, symbol: gasTokenSymbol },
|
|
17047
|
+
publicClient: kernel.publicClient
|
|
16839
17048
|
})
|
|
16840
17049
|
});
|
|
16841
17050
|
}
|
|
@@ -18356,7 +18565,7 @@ function useFluentDepositSwap({
|
|
|
18356
18565
|
commit(key, {
|
|
18357
18566
|
phase: "error",
|
|
18358
18567
|
leg,
|
|
18359
|
-
message: error
|
|
18568
|
+
message: describeFluentExecutionFailure(error, gasSymbol, "The swap was not sent.")
|
|
18360
18569
|
});
|
|
18361
18570
|
track("bridge_deposit_swap_failed", { reason: "execution_failed" });
|
|
18362
18571
|
} finally {
|
|
@@ -18425,7 +18634,7 @@ function useFluentDepositSwap({
|
|
|
18425
18634
|
};
|
|
18426
18635
|
}
|
|
18427
18636
|
function useTokenTransfer(params) {
|
|
18428
|
-
const { widget, track, beginTransfer, settleTransfer, endTransfer } = params;
|
|
18637
|
+
const { widget, track, beginTransfer, settleTransfer, endTransfer, onPayFeeInNative } = params;
|
|
18429
18638
|
return useCallback(
|
|
18430
18639
|
async (request) => {
|
|
18431
18640
|
const { token, to, amount, gasSymbol } = request;
|
|
@@ -18459,11 +18668,21 @@ function useTokenTransfer(params) {
|
|
|
18459
18668
|
return { status: "rejected" };
|
|
18460
18669
|
}
|
|
18461
18670
|
debugError("[FluentWidget] Token transfer failed", error);
|
|
18462
|
-
const message2 =
|
|
18671
|
+
const message2 = describeFluentExecutionFailure(
|
|
18672
|
+
error,
|
|
18673
|
+
gasSymbol,
|
|
18674
|
+
"The transfer was not sent."
|
|
18675
|
+
);
|
|
18463
18676
|
toast.add({
|
|
18464
18677
|
type: "error",
|
|
18465
18678
|
title: `Could not send ${token.symbol}`,
|
|
18466
|
-
description: message2
|
|
18679
|
+
description: message2,
|
|
18680
|
+
...onPayFeeInNative && isFluentInsufficientGasToken(error) ? {
|
|
18681
|
+
actionProps: {
|
|
18682
|
+
children: "Pay the fee in ETH",
|
|
18683
|
+
onClick: () => onPayFeeInNative(request)
|
|
18684
|
+
}
|
|
18685
|
+
} : {}
|
|
18467
18686
|
});
|
|
18468
18687
|
track("wallet_token_send_failed", { reason: "execution_failed" });
|
|
18469
18688
|
return { status: "failed", message: message2 };
|
|
@@ -18471,7 +18690,7 @@ function useTokenTransfer(params) {
|
|
|
18471
18690
|
if (!settled) endTransfer(pendingId);
|
|
18472
18691
|
}
|
|
18473
18692
|
},
|
|
18474
|
-
[beginTransfer, settleTransfer, endTransfer, track, widget]
|
|
18693
|
+
[beginTransfer, settleTransfer, endTransfer, onPayFeeInNative, track, widget]
|
|
18475
18694
|
);
|
|
18476
18695
|
}
|
|
18477
18696
|
var FLUENT_USDNR_MINT_OP_ID = "fluent-mint-usdnr";
|
|
@@ -18534,7 +18753,7 @@ function useUsdnrMint(params) {
|
|
|
18534
18753
|
return { status: "rejected" };
|
|
18535
18754
|
}
|
|
18536
18755
|
debugError("[FluentWidget] USDnr mint failed", error);
|
|
18537
|
-
const message2 = error
|
|
18756
|
+
const message2 = describeFluentExecutionFailure(error, gasSymbol, "The mint was not sent.");
|
|
18538
18757
|
toast.add({
|
|
18539
18758
|
type: "error",
|
|
18540
18759
|
title: `Could not get ${token.symbol}`,
|
|
@@ -20526,12 +20745,24 @@ function FluentWidgetContent({
|
|
|
20526
20745
|
useEffect(() => {
|
|
20527
20746
|
setSentDeposits([]);
|
|
20528
20747
|
}, [fluentAccountAddress]);
|
|
20748
|
+
const openSendPage = useCallback(() => {
|
|
20749
|
+
setWalletMenuTab("send");
|
|
20750
|
+
setAccountOpen(true);
|
|
20751
|
+
}, [setAccountOpen, setWalletMenuTab]);
|
|
20752
|
+
const { sendRetry, payFeeInNative, clearSendRetry } = useFluentSendRetry(
|
|
20753
|
+
connectedAddress ?? fluentAccountAddress,
|
|
20754
|
+
openSendPage
|
|
20755
|
+
);
|
|
20756
|
+
useEffect(() => {
|
|
20757
|
+
if (walletMenuTab !== "send" && sendRetry) clearSendRetry();
|
|
20758
|
+
}, [walletMenuTab, sendRetry, clearSendRetry]);
|
|
20529
20759
|
const sendToken = useTokenTransfer({
|
|
20530
20760
|
widget: widgetApi,
|
|
20531
20761
|
track,
|
|
20532
20762
|
beginTransfer,
|
|
20533
20763
|
settleTransfer,
|
|
20534
|
-
endTransfer
|
|
20764
|
+
endTransfer,
|
|
20765
|
+
onPayFeeInNative: payFeeInNative
|
|
20535
20766
|
});
|
|
20536
20767
|
const { mintUsdnr, mintingUsdnr } = useUsdnrMint({
|
|
20537
20768
|
widget: widgetApi,
|
|
@@ -21037,6 +21268,12 @@ function FluentWidgetContent({
|
|
|
21037
21268
|
const userXDisplayName = displayedPrivyUser?.twitter?.name || void 0;
|
|
21038
21269
|
const userGoogleName = displayedPrivyUser?.google?.name || void 0;
|
|
21039
21270
|
const hostSession = useMemo(() => toFluentWidgetSession(session), [session]);
|
|
21271
|
+
const appWidgetApi = useMemo(
|
|
21272
|
+
() => withFluentInsufficientGasTokenNotice(widgetApi, (message2) => {
|
|
21273
|
+
toast.add({ type: "error", title: "Transaction not sent", description: message2 });
|
|
21274
|
+
}),
|
|
21275
|
+
[widgetApi]
|
|
21276
|
+
);
|
|
21040
21277
|
const context = useMemo(
|
|
21041
21278
|
() => ({
|
|
21042
21279
|
session: hostSession,
|
|
@@ -21044,7 +21281,7 @@ function FluentWidgetContent({
|
|
|
21044
21281
|
userXDisplayName,
|
|
21045
21282
|
userGoogleName,
|
|
21046
21283
|
wallet: activeWallet,
|
|
21047
|
-
widget:
|
|
21284
|
+
widget: appWidgetApi,
|
|
21048
21285
|
openConnect,
|
|
21049
21286
|
openAccount: openAccountMenu,
|
|
21050
21287
|
disconnect: requestDisconnect,
|
|
@@ -21060,7 +21297,7 @@ function FluentWidgetContent({
|
|
|
21060
21297
|
userXDisplayName,
|
|
21061
21298
|
userGoogleName,
|
|
21062
21299
|
activeWallet,
|
|
21063
|
-
|
|
21300
|
+
appWidgetApi,
|
|
21064
21301
|
openConnect,
|
|
21065
21302
|
openAccountMenu,
|
|
21066
21303
|
requestDisconnect,
|
|
@@ -21152,6 +21389,7 @@ function FluentWidgetContent({
|
|
|
21152
21389
|
panel: walletMenuPanel,
|
|
21153
21390
|
onPanelChange: setWalletMenuPanel,
|
|
21154
21391
|
onSendToken: sendToken,
|
|
21392
|
+
sendRetry: sendRetry ?? void 0,
|
|
21155
21393
|
pendingTransfers,
|
|
21156
21394
|
sentTransfer: sentTransfer ?? void 0,
|
|
21157
21395
|
sentDeposits,
|