@fluent.xyz/connect 0.6.2-rc.1 → 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 +476 -221
- package/dist/index.js.map +1 -1
- package/docs/api.md +16 -8
- package/docs/errors.md +10 -4
- package/docs/getting-started.md +9 -0
- 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);
|
|
@@ -7053,6 +7052,7 @@ function InlineConnectModal(props) {
|
|
|
7053
7052
|
onClose,
|
|
7054
7053
|
onFluentLogin,
|
|
7055
7054
|
onRetry,
|
|
7055
|
+
onSignerCreationError,
|
|
7056
7056
|
loginError,
|
|
7057
7057
|
wallet,
|
|
7058
7058
|
track,
|
|
@@ -7067,7 +7067,7 @@ function InlineConnectModal(props) {
|
|
|
7067
7067
|
);
|
|
7068
7068
|
const { ready, authenticated, user } = usePrivy2();
|
|
7069
7069
|
const { isOpen: securityPromptOpen } = useModalStatus2();
|
|
7070
|
-
const { wallets
|
|
7070
|
+
const { wallets } = useWallets2();
|
|
7071
7071
|
const { createWallet } = useCreateWallet2();
|
|
7072
7072
|
const { sendCode, loginWithCode } = useLoginWithEmail2();
|
|
7073
7073
|
const { initOAuth, state: oauthState } = useLoginWithOAuth2();
|
|
@@ -7093,7 +7093,16 @@ function InlineConnectModal(props) {
|
|
|
7093
7093
|
const operation = React.useRef(null);
|
|
7094
7094
|
const generation = React.useRef(0);
|
|
7095
7095
|
const attemptedWallet = React.useRef(null);
|
|
7096
|
-
const
|
|
7096
|
+
const [signerError, setSignerError] = React.useState(null);
|
|
7097
|
+
const signerUserId = authenticated && !walletUserPrivySession ? user?.id : void 0;
|
|
7098
|
+
if (attemptedWallet.current?.userId !== signerUserId) attemptedWallet.current = null;
|
|
7099
|
+
const mounted = React.useRef(false);
|
|
7100
|
+
React.useEffect(() => {
|
|
7101
|
+
mounted.current = true;
|
|
7102
|
+
return () => {
|
|
7103
|
+
mounted.current = false;
|
|
7104
|
+
};
|
|
7105
|
+
}, []);
|
|
7097
7106
|
const fluentChosen = React.useRef(false);
|
|
7098
7107
|
const fluentGate = React.useRef(void 0);
|
|
7099
7108
|
const heading = React.useRef(null);
|
|
@@ -7101,9 +7110,9 @@ function InlineConnectModal(props) {
|
|
|
7101
7110
|
const walletList = React.useRef(null);
|
|
7102
7111
|
const active = React.useRef(open);
|
|
7103
7112
|
active.current = open;
|
|
7104
|
-
const connecting = step !== "choice"
|
|
7113
|
+
const connecting = authenticated && (step !== "choice" || !walletUserPrivySession);
|
|
7105
7114
|
const screen = connecting ? "connecting" : step;
|
|
7106
|
-
const shownError = error || captchaError || (connecting ? signInRefusal || loginError : "");
|
|
7115
|
+
const shownError = error || captchaError || (signerError?.attempt === attemptedWallet.current ? signerError?.message : "") || (connecting ? signInRefusal || loginError : "");
|
|
7107
7116
|
React.useEffect(() => {
|
|
7108
7117
|
if (!open || !shownError) return;
|
|
7109
7118
|
const id = toast.add({ type: "error", title: shownError });
|
|
@@ -7162,31 +7171,33 @@ function InlineConnectModal(props) {
|
|
|
7162
7171
|
return () => clearTimeout(timer);
|
|
7163
7172
|
}, [open, connecting, step, walletAttempt]);
|
|
7164
7173
|
React.useEffect(() => {
|
|
7165
|
-
if (!
|
|
7174
|
+
if (!ready || !authenticated || !user?.id || walletUserPrivySession) return;
|
|
7166
7175
|
clearInlineOAuth();
|
|
7167
7176
|
const embedded = (account) => account.walletClientType === "privy" && (!account.chainType || account.chainType === "ethereum");
|
|
7168
7177
|
if (wallets.some(embedded) || user.linkedAccounts?.some(
|
|
7169
7178
|
(account) => account.type === "wallet" && embedded(account)
|
|
7170
7179
|
))
|
|
7171
7180
|
return;
|
|
7172
|
-
if (attemptedWallet.current === user.id) return;
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7181
|
+
if (attemptedWallet.current?.userId === user.id) return;
|
|
7182
|
+
const attempt = { userId: user.id, failed: false };
|
|
7183
|
+
attemptedWallet.current = attempt;
|
|
7184
|
+
setSignerError(null);
|
|
7176
7185
|
void createWallet().catch((failure) => {
|
|
7177
|
-
if (
|
|
7178
|
-
|
|
7179
|
-
|
|
7186
|
+
if (!mounted.current || attemptedWallet.current !== attempt) return;
|
|
7187
|
+
attempt.failed = true;
|
|
7188
|
+
const detail = message(failure);
|
|
7189
|
+
setSignerError({ attempt, message: detail });
|
|
7190
|
+
onSignerCreationError?.();
|
|
7180
7191
|
});
|
|
7181
7192
|
}, [
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
walletsReady,
|
|
7193
|
+
ready,
|
|
7194
|
+
authenticated,
|
|
7185
7195
|
wallets,
|
|
7186
7196
|
user,
|
|
7187
7197
|
createWallet,
|
|
7188
7198
|
walletAttempt,
|
|
7189
|
-
walletUserPrivySession
|
|
7199
|
+
walletUserPrivySession,
|
|
7200
|
+
onSignerCreationError
|
|
7190
7201
|
]);
|
|
7191
7202
|
const run = async (action, needsPrivy = true) => {
|
|
7192
7203
|
if (operation.current || needsPrivy && !ready) return;
|
|
@@ -7342,7 +7353,7 @@ function InlineConnectModal(props) {
|
|
|
7342
7353
|
setStep("choice");
|
|
7343
7354
|
return;
|
|
7344
7355
|
}
|
|
7345
|
-
if (
|
|
7356
|
+
if (attemptedWallet.current?.failed) attemptedWallet.current = null;
|
|
7346
7357
|
setWalletAttempt((value) => value + 1);
|
|
7347
7358
|
onRetry?.();
|
|
7348
7359
|
};
|
|
@@ -8283,7 +8294,7 @@ function depositSwapCopy(state, slow, route) {
|
|
|
8283
8294
|
case "bridging":
|
|
8284
8295
|
return {
|
|
8285
8296
|
heading: "Funds on the way",
|
|
8286
|
-
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.`
|
|
8287
8298
|
};
|
|
8288
8299
|
case "bridge_failed":
|
|
8289
8300
|
return { heading: "The deposit did not land", detail: state.message };
|
|
@@ -8548,9 +8559,12 @@ function groupFluentTransactionHistory(params) {
|
|
|
8548
8559
|
}
|
|
8549
8560
|
function orderOperationMovements(movements) {
|
|
8550
8561
|
return [...movements].sort(
|
|
8551
|
-
(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))
|
|
8552
8563
|
);
|
|
8553
8564
|
}
|
|
8565
|
+
function isNativeMovement(movement) {
|
|
8566
|
+
return movement.tokenIdentity.endsWith(":native");
|
|
8567
|
+
}
|
|
8554
8568
|
function filterFluentTransactionHistory(entries, tokens) {
|
|
8555
8569
|
const listed = new Set(tokens.map((token) => token.identity));
|
|
8556
8570
|
return entries.flatMap((entry) => {
|
|
@@ -8948,6 +8962,20 @@ function formatFluentMovementsUsd(movements, priceOf) {
|
|
|
8948
8962
|
if (figures.every((figure) => figure === void 0)) return void 0;
|
|
8949
8963
|
return figures.map((figure) => figure ?? "\u2014").join(", ");
|
|
8950
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
|
+
}
|
|
8951
8979
|
function ActivityUsd({ usd, failed }) {
|
|
8952
8980
|
if (!usd) return null;
|
|
8953
8981
|
return /* @__PURE__ */ jsx(
|
|
@@ -9164,7 +9192,7 @@ function FluentActivityRow({
|
|
|
9164
9192
|
const movements = entry.kind === "movement" ? [entry] : entry.movements;
|
|
9165
9193
|
const summary = describeFluentTransaction(entry);
|
|
9166
9194
|
const swap = splitFluentSwap(movements);
|
|
9167
|
-
const movement = swap ? swap.received[0] : movements
|
|
9195
|
+
const movement = swap ? swap.received[0] : pickFluentHeadlineMovement(movements, priceOf);
|
|
9168
9196
|
const statusLabel = FLUENT_TRANSACTION_STATUS_LABELS[entry.status];
|
|
9169
9197
|
const detail = swap ? formatFluentSwapPair(swap) : summary.counterparty ? `${summary.direction === "sent" ? "To" : "From"} ${formatAddress(summary.counterparty)}` : `Op ${formatAddress(entry.hash)}`;
|
|
9170
9198
|
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
@@ -9197,16 +9225,16 @@ function FluentActivityRow({
|
|
|
9197
9225
|
secondary: item.direction === "sent"
|
|
9198
9226
|
},
|
|
9199
9227
|
item.id
|
|
9200
|
-
)) :
|
|
9201
|
-
/* @__PURE__ */ jsx(ActivityAmount, { movement
|
|
9228
|
+
)) : movement ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9229
|
+
/* @__PURE__ */ jsx(ActivityAmount, { movement, status: entry.status }),
|
|
9202
9230
|
/* @__PURE__ */ jsx(
|
|
9203
9231
|
ActivityUsd,
|
|
9204
9232
|
{
|
|
9205
|
-
usd: formatActivityUsd(
|
|
9233
|
+
usd: formatActivityUsd(movement.amount, priceOf(movement)),
|
|
9206
9234
|
failed: entry.status === "failed"
|
|
9207
9235
|
}
|
|
9208
9236
|
)
|
|
9209
|
-
] }
|
|
9237
|
+
] }) : null })
|
|
9210
9238
|
]
|
|
9211
9239
|
}
|
|
9212
9240
|
) });
|
|
@@ -9875,6 +9903,334 @@ function convertFluentFeeToGasToken(params) {
|
|
|
9875
9903
|
if (rateWei === 0n) return void 0;
|
|
9876
9904
|
return wei * 10n ** BigInt(feeToken.decimals) / rateWei;
|
|
9877
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
|
+
}
|
|
9878
10234
|
var BRIDGE_AMOUNT_MAX_DECIMALS = 18;
|
|
9879
10235
|
function sanitizeBridgeAmountInput(next, previous = "", decimals = BRIDGE_AMOUNT_MAX_DECIMALS) {
|
|
9880
10236
|
const normalized = next.replace(/,/g, ".").replace(/\s/g, "");
|
|
@@ -10140,13 +10496,18 @@ function SendTokenForm({
|
|
|
10140
10496
|
sponsorshipAvailable = false,
|
|
10141
10497
|
ethValueByToken,
|
|
10142
10498
|
onSend,
|
|
10143
|
-
onSent
|
|
10499
|
+
onSent,
|
|
10500
|
+
retry
|
|
10144
10501
|
}) {
|
|
10145
10502
|
const { chain } = useFluentWidgetNetwork();
|
|
10146
|
-
const [identity, setIdentity] = useState(null);
|
|
10147
|
-
const [gasIdentity, setGasIdentity] = useState(
|
|
10148
|
-
|
|
10149
|
-
|
|
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
|
+
);
|
|
10150
10511
|
const [sending, setSending] = useState(false);
|
|
10151
10512
|
const [sendError, setSendError] = useState(null);
|
|
10152
10513
|
const [picking, setPicking] = useState(false);
|
|
@@ -10178,7 +10539,7 @@ function SendTokenForm({
|
|
|
10178
10539
|
decimals: token.decimals,
|
|
10179
10540
|
balance: rawBalance
|
|
10180
10541
|
}) : null;
|
|
10181
|
-
const balanceNote = token && rawBalance !== null ? `${
|
|
10542
|
+
const balanceNote = token && rawBalance !== null ? `${formatUnits(rawBalance, token.decimals)} ${token.symbol}` : balancesBusy ? "Loading balance..." : "Balance unavailable";
|
|
10182
10543
|
const amountUsd = token ? formatAmountUsd(amount, usdPrices[token.identity]) : void 0;
|
|
10183
10544
|
const fee = feeToken ? checkFluentTransferFee({
|
|
10184
10545
|
feeToken,
|
|
@@ -10206,6 +10567,8 @@ function SendTokenForm({
|
|
|
10206
10567
|
nativeIdentity: nativeToken?.identity
|
|
10207
10568
|
});
|
|
10208
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;
|
|
10209
10572
|
const feeBalanceLabel = (candidate) => {
|
|
10210
10573
|
const entry = balanceByIdentity.get(candidate.identity);
|
|
10211
10574
|
if (entry?.status === "ready" && entry.raw !== null) {
|
|
@@ -10304,14 +10667,7 @@ function SendTokenForm({
|
|
|
10304
10667
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-1 text-sm text-foreground/60", children: [
|
|
10305
10668
|
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", title: amountUsd, children: amountUsd }),
|
|
10306
10669
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1 whitespace-nowrap", children: [
|
|
10307
|
-
/* @__PURE__ */ jsx(
|
|
10308
|
-
"span",
|
|
10309
|
-
{
|
|
10310
|
-
className: "tabular-nums",
|
|
10311
|
-
title: token && rawBalance !== null ? formatUnits(rawBalance, token.decimals) : void 0,
|
|
10312
|
-
children: balanceNote
|
|
10313
|
-
}
|
|
10314
|
-
),
|
|
10670
|
+
/* @__PURE__ */ jsx("span", { className: "tabular-nums", children: balanceNote }),
|
|
10315
10671
|
/* @__PURE__ */ jsx(
|
|
10316
10672
|
"button",
|
|
10317
10673
|
{
|
|
@@ -10423,7 +10779,22 @@ function SendTokenForm({
|
|
|
10423
10779
|
]
|
|
10424
10780
|
}
|
|
10425
10781
|
) : null,
|
|
10426
|
-
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,
|
|
10427
10798
|
/* @__PURE__ */ jsx(Button, { className: "w-full", disabled: !ready, onClick: () => void handleSend(), children: sending ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10428
10799
|
/* @__PURE__ */ jsx(Spinner, { className: "size-4" }),
|
|
10429
10800
|
"Sending\u2026"
|
|
@@ -11707,7 +12078,8 @@ function WalletMenuTokenList({
|
|
|
11707
12078
|
const visual = isFluentDefaultToken(token) ? VISUAL_BY_DEFAULT_SYMBOL[token.symbol] : void 0;
|
|
11708
12079
|
const active = selectedSymbol === symbol && gasTokenIdentities.has(identity);
|
|
11709
12080
|
const refreshing = busy && Boolean(accountAddress);
|
|
11710
|
-
const
|
|
12081
|
+
const fractionDigits = fluentAmountFractionDigits(token.symbol);
|
|
12082
|
+
const formatted = balance?.status === "ready" ? formatFluentGasTokenBalance(balance, fractionDigits) ?? (balance.formatted ? formatFluentLocaleAmount(balance.formatted, fractionDigits) : null) : null;
|
|
11711
12083
|
const usdValueLabel = formatTokenUsdValue(balance, usdPrices[identity]);
|
|
11712
12084
|
const exactBalance = balance?.status === "ready" && balance.formatted?.includes(".") ? balance.formatted : null;
|
|
11713
12085
|
return /* @__PURE__ */ jsxs(
|
|
@@ -12027,6 +12399,7 @@ function WalletMenuActionCard({
|
|
|
12027
12399
|
settingsError = null,
|
|
12028
12400
|
tokenListError = null,
|
|
12029
12401
|
onSendToken,
|
|
12402
|
+
sendRetry,
|
|
12030
12403
|
pendingTransfers,
|
|
12031
12404
|
sentTransfer,
|
|
12032
12405
|
sentDeposits,
|
|
@@ -12383,6 +12756,7 @@ function WalletMenuActionCard({
|
|
|
12383
12756
|
return /* @__PURE__ */ jsx(
|
|
12384
12757
|
SendTokenForm,
|
|
12385
12758
|
{
|
|
12759
|
+
retry: sendRetry?.request,
|
|
12386
12760
|
tokens: displayTokens,
|
|
12387
12761
|
balances,
|
|
12388
12762
|
balancesBusy,
|
|
@@ -12399,7 +12773,8 @@ function WalletMenuActionCard({
|
|
|
12399
12773
|
onTabChange(SENT_TRANSFER_TAB);
|
|
12400
12774
|
onRevealAccount?.();
|
|
12401
12775
|
}
|
|
12402
|
-
}
|
|
12776
|
+
},
|
|
12777
|
+
sendRetry?.key
|
|
12403
12778
|
);
|
|
12404
12779
|
}
|
|
12405
12780
|
if (tab === SENT_TRANSFER_TAB) {
|
|
@@ -15303,165 +15678,6 @@ function encodeBatchCall(call) {
|
|
|
15303
15678
|
})
|
|
15304
15679
|
};
|
|
15305
15680
|
}
|
|
15306
|
-
var FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY = "selfFunded=true";
|
|
15307
|
-
var FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS = 50000n;
|
|
15308
|
-
function getFluentZeroDevErc20PaymasterTokens(network = "testnet") {
|
|
15309
|
-
return Object.fromEntries(
|
|
15310
|
-
getFluentDefaultWidgetGasTokens(network).filter((token) => !isFluentNativeToken(token) && token.address).map((token) => [
|
|
15311
|
-
token.symbol.toUpperCase(),
|
|
15312
|
-
{
|
|
15313
|
-
address: token.address,
|
|
15314
|
-
decimals: token.decimals,
|
|
15315
|
-
symbol: token.symbol
|
|
15316
|
-
}
|
|
15317
|
-
])
|
|
15318
|
-
);
|
|
15319
|
-
}
|
|
15320
|
-
function createFluentZeroDevRpcUrl(params = {}) {
|
|
15321
|
-
const chainId = params.chainId ?? fluentTestnet.id;
|
|
15322
|
-
const projectId = params.projectId ?? getFluentZeroDevProjectId(
|
|
15323
|
-
getFluentWidgetNetworkForChainId(chainId)
|
|
15324
|
-
);
|
|
15325
|
-
const baseUrl = `https://rpc.zerodev.app/api/v3/${projectId}/chain/${chainId}`;
|
|
15326
|
-
return params.selfFunded ? `${baseUrl}?${FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY}` : baseUrl;
|
|
15327
|
-
}
|
|
15328
|
-
function createFluentZeroDevErc20PaymasterRpcUrl(params = {}) {
|
|
15329
|
-
return createFluentZeroDevRpcUrl({ ...params, selfFunded: true });
|
|
15330
|
-
}
|
|
15331
|
-
function createFluentSponsorshipRpcUrl(params) {
|
|
15332
|
-
const base = params.sponsorshipUrl.replace(/\/+$/, "");
|
|
15333
|
-
return `${base}/paymaster/${encodeURIComponent(params.appId)}`;
|
|
15334
|
-
}
|
|
15335
|
-
function createFluentZeroDevSponsoredPaymaster(params) {
|
|
15336
|
-
const paymasterClient = createZeroDevPaymasterClient({
|
|
15337
|
-
chain: params.chain,
|
|
15338
|
-
transport: http(params.rpcUrl, {
|
|
15339
|
-
timeout: FLUENT_RPC_TIMEOUT_MS,
|
|
15340
|
-
fetchOptions: { headers: { Authorization: `Bearer ${params.bearerToken}` } }
|
|
15341
|
-
})
|
|
15342
|
-
});
|
|
15343
|
-
return {
|
|
15344
|
-
getPaymasterData: (userOperation) => paymasterClient.sponsorUserOperation({
|
|
15345
|
-
userOperation: withoutChainMetadata(userOperation)
|
|
15346
|
-
})
|
|
15347
|
-
};
|
|
15348
|
-
}
|
|
15349
|
-
function resolveFluentZeroDevErc20PaymasterToken(token = "BLEND", network = "testnet") {
|
|
15350
|
-
if (typeof token === "object") return token;
|
|
15351
|
-
if (token.startsWith("0x")) return { address: token };
|
|
15352
|
-
const tokens = getFluentZeroDevErc20PaymasterTokens(network);
|
|
15353
|
-
const resolved = tokens[token.toUpperCase()];
|
|
15354
|
-
if (!resolved) {
|
|
15355
|
-
throw new Error(
|
|
15356
|
-
`"${token}" cannot pay gas on ${network}. Paymaster tokens: ${Object.keys(tokens).join(", ") || "none"}`
|
|
15357
|
-
);
|
|
15358
|
-
}
|
|
15359
|
-
return resolved;
|
|
15360
|
-
}
|
|
15361
|
-
function createFluentZeroDevErc20PaymasterClient(params = {}) {
|
|
15362
|
-
const chain = params.chain ?? fluentTestnet;
|
|
15363
|
-
return createZeroDevPaymasterClient({
|
|
15364
|
-
chain,
|
|
15365
|
-
transport: http(
|
|
15366
|
-
params.paymasterRpcUrl ?? createFluentZeroDevErc20PaymasterRpcUrl({ chainId: chain.id }),
|
|
15367
|
-
{ timeout: FLUENT_RPC_TIMEOUT_MS }
|
|
15368
|
-
)
|
|
15369
|
-
});
|
|
15370
|
-
}
|
|
15371
|
-
function createFluentZeroDevErc20Paymaster(params) {
|
|
15372
|
-
const chain = params.chain ?? fluentTestnet;
|
|
15373
|
-
const gasToken = resolveFluentZeroDevErc20PaymasterToken(
|
|
15374
|
-
params.gasToken,
|
|
15375
|
-
params.network
|
|
15376
|
-
);
|
|
15377
|
-
const paymasterClient = params.paymasterClient ?? createFluentZeroDevErc20PaymasterClient({
|
|
15378
|
-
chain,
|
|
15379
|
-
paymasterRpcUrl: params.paymasterRpcUrl
|
|
15380
|
-
});
|
|
15381
|
-
return {
|
|
15382
|
-
getPaymasterData: (userOperation) => {
|
|
15383
|
-
const contextToken = getPaymasterContextToken(userOperation.context);
|
|
15384
|
-
return paymasterClient.sponsorUserOperation({
|
|
15385
|
-
userOperation: withMinimumPostOpGas(withoutChainMetadata(userOperation)),
|
|
15386
|
-
gasToken: contextToken ?? gasToken.address
|
|
15387
|
-
});
|
|
15388
|
-
}
|
|
15389
|
-
};
|
|
15390
|
-
}
|
|
15391
|
-
var FluentGasPaymentError = class extends Error {
|
|
15392
|
-
constructor(code, message2, options) {
|
|
15393
|
-
super(message2, options);
|
|
15394
|
-
this.code = code;
|
|
15395
|
-
this.name = "FluentGasPaymentError";
|
|
15396
|
-
}
|
|
15397
|
-
code;
|
|
15398
|
-
};
|
|
15399
|
-
var erc20PaymasterAddresses = /* @__PURE__ */ new Map();
|
|
15400
|
-
async function readFluentZeroDevErc20PaymasterAddress(params = {}) {
|
|
15401
|
-
const chain = params.chain ?? fluentTestnet;
|
|
15402
|
-
const paymasterRpcUrl = params.paymasterRpcUrl ?? createFluentZeroDevErc20PaymasterRpcUrl({ chainId: chain.id });
|
|
15403
|
-
const cacheKey = params.paymasterClient ? void 0 : paymasterRpcUrl;
|
|
15404
|
-
const known = cacheKey ? erc20PaymasterAddresses.get(cacheKey) : void 0;
|
|
15405
|
-
if (known) return known;
|
|
15406
|
-
const paymasterClient = params.paymasterClient ?? createFluentZeroDevErc20PaymasterClient({ chain, paymasterRpcUrl });
|
|
15407
|
-
const request = paymasterClient.request;
|
|
15408
|
-
let response;
|
|
15409
|
-
try {
|
|
15410
|
-
response = await request({
|
|
15411
|
-
method: "zd_pm_accounts",
|
|
15412
|
-
params: [{ chainId: chain.id, entryPointAddress: getEntryPoint("0.7").address }]
|
|
15413
|
-
});
|
|
15414
|
-
} catch (err) {
|
|
15415
|
-
throw new FluentGasPaymentError(
|
|
15416
|
-
"paymaster_unavailable",
|
|
15417
|
-
`ZeroDev could not name the ERC-20 paymaster for chain ${chain.id}`,
|
|
15418
|
-
{ cause: err }
|
|
15419
|
-
);
|
|
15420
|
-
}
|
|
15421
|
-
const address = Array.isArray(response) ? response[0] : void 0;
|
|
15422
|
-
if (typeof address !== "string" || !isAddress(address)) {
|
|
15423
|
-
throw new FluentGasPaymentError(
|
|
15424
|
-
"paymaster_unavailable",
|
|
15425
|
-
`ZeroDev named no ERC-20 paymaster for chain ${chain.id}`
|
|
15426
|
-
);
|
|
15427
|
-
}
|
|
15428
|
-
const paymaster = getAddress(address);
|
|
15429
|
-
if (cacheKey) erc20PaymasterAddresses.set(cacheKey, paymaster);
|
|
15430
|
-
return paymaster;
|
|
15431
|
-
}
|
|
15432
|
-
function createFluentErc20ApproveCall(params) {
|
|
15433
|
-
return {
|
|
15434
|
-
to: params.gasToken,
|
|
15435
|
-
data: encodeFunctionData({
|
|
15436
|
-
abi: erc20Abi,
|
|
15437
|
-
functionName: "approve",
|
|
15438
|
-
args: [params.spender, params.amount]
|
|
15439
|
-
}),
|
|
15440
|
-
value: 0n
|
|
15441
|
-
};
|
|
15442
|
-
}
|
|
15443
|
-
function getPaymasterContextToken(context) {
|
|
15444
|
-
if (!context || typeof context !== "object") return void 0;
|
|
15445
|
-
const token = context.token;
|
|
15446
|
-
return typeof token === "string" && token.startsWith("0x") ? token : void 0;
|
|
15447
|
-
}
|
|
15448
|
-
function withMinimumPostOpGas(userOperation) {
|
|
15449
|
-
const limit = userOperation.paymasterPostOpGasLimit;
|
|
15450
|
-
if (limit !== void 0 && limit >= FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS) return userOperation;
|
|
15451
|
-
return {
|
|
15452
|
-
...userOperation,
|
|
15453
|
-
paymasterPostOpGasLimit: FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS
|
|
15454
|
-
};
|
|
15455
|
-
}
|
|
15456
|
-
function withoutChainMetadata(userOperation) {
|
|
15457
|
-
const {
|
|
15458
|
-
chain: _chain,
|
|
15459
|
-
context: _context,
|
|
15460
|
-
paymasterContext: _paymasterContext,
|
|
15461
|
-
...cleanUserOperation
|
|
15462
|
-
} = userOperation;
|
|
15463
|
-
return cleanUserOperation;
|
|
15464
|
-
}
|
|
15465
15681
|
var FluentSponsorshipFallbackError = class extends Error {
|
|
15466
15682
|
code;
|
|
15467
15683
|
sponsorshipReason;
|
|
@@ -16572,7 +16788,12 @@ async function sendCalls(context, calls, options, readyAccount) {
|
|
|
16572
16788
|
};
|
|
16573
16789
|
const sponsorshipRefused = !gasToken && options?.gasPayment?.sponsorship === "never";
|
|
16574
16790
|
const sponsorship = context.sponsorshipUrl && context.appId ? { sponsorshipUrl: context.sponsorshipUrl, appId: context.appId } : null;
|
|
16575
|
-
const executionClient = gasToken ? createFluentZeroDevErc20ExecutionClient(
|
|
16791
|
+
const executionClient = gasToken ? createFluentZeroDevErc20ExecutionClient(
|
|
16792
|
+
executionKernel,
|
|
16793
|
+
gasToken,
|
|
16794
|
+
readExecution,
|
|
16795
|
+
options?.gasPayment?.symbol
|
|
16796
|
+
) : executionKernel.client;
|
|
16576
16797
|
const callSponsored = !gasToken && !sponsorshipRefused && sponsorship && !sponsorshipUnavailable.current;
|
|
16577
16798
|
if (execution.receiptSource === "chain") {
|
|
16578
16799
|
inclusionAnchor = await readFluentInclusionAnchor(executionKernel.publicClient);
|
|
@@ -16816,13 +17037,14 @@ async function createFluentZeroDevKernel(params) {
|
|
|
16816
17037
|
signerSource: "privy"
|
|
16817
17038
|
};
|
|
16818
17039
|
}
|
|
16819
|
-
function createFluentZeroDevErc20ExecutionClient(kernel, gasToken, readExecution) {
|
|
17040
|
+
function createFluentZeroDevErc20ExecutionClient(kernel, gasToken, readExecution, gasTokenSymbol) {
|
|
16820
17041
|
return createFluentZeroDevKernelClient({
|
|
16821
17042
|
kernel,
|
|
16822
17043
|
readExecution,
|
|
16823
17044
|
paymaster: createFluentZeroDevErc20Paymaster({
|
|
16824
17045
|
chain: kernel.chain,
|
|
16825
|
-
gasToken
|
|
17046
|
+
gasToken: { address: gasToken, symbol: gasTokenSymbol },
|
|
17047
|
+
publicClient: kernel.publicClient
|
|
16826
17048
|
})
|
|
16827
17049
|
});
|
|
16828
17050
|
}
|
|
@@ -18343,7 +18565,7 @@ function useFluentDepositSwap({
|
|
|
18343
18565
|
commit(key, {
|
|
18344
18566
|
phase: "error",
|
|
18345
18567
|
leg,
|
|
18346
|
-
message: error
|
|
18568
|
+
message: describeFluentExecutionFailure(error, gasSymbol, "The swap was not sent.")
|
|
18347
18569
|
});
|
|
18348
18570
|
track("bridge_deposit_swap_failed", { reason: "execution_failed" });
|
|
18349
18571
|
} finally {
|
|
@@ -18412,7 +18634,7 @@ function useFluentDepositSwap({
|
|
|
18412
18634
|
};
|
|
18413
18635
|
}
|
|
18414
18636
|
function useTokenTransfer(params) {
|
|
18415
|
-
const { widget, track, beginTransfer, settleTransfer, endTransfer } = params;
|
|
18637
|
+
const { widget, track, beginTransfer, settleTransfer, endTransfer, onPayFeeInNative } = params;
|
|
18416
18638
|
return useCallback(
|
|
18417
18639
|
async (request) => {
|
|
18418
18640
|
const { token, to, amount, gasSymbol } = request;
|
|
@@ -18446,11 +18668,21 @@ function useTokenTransfer(params) {
|
|
|
18446
18668
|
return { status: "rejected" };
|
|
18447
18669
|
}
|
|
18448
18670
|
debugError("[FluentWidget] Token transfer failed", error);
|
|
18449
|
-
const message2 =
|
|
18671
|
+
const message2 = describeFluentExecutionFailure(
|
|
18672
|
+
error,
|
|
18673
|
+
gasSymbol,
|
|
18674
|
+
"The transfer was not sent."
|
|
18675
|
+
);
|
|
18450
18676
|
toast.add({
|
|
18451
18677
|
type: "error",
|
|
18452
18678
|
title: `Could not send ${token.symbol}`,
|
|
18453
|
-
description: message2
|
|
18679
|
+
description: message2,
|
|
18680
|
+
...onPayFeeInNative && isFluentInsufficientGasToken(error) ? {
|
|
18681
|
+
actionProps: {
|
|
18682
|
+
children: "Pay the fee in ETH",
|
|
18683
|
+
onClick: () => onPayFeeInNative(request)
|
|
18684
|
+
}
|
|
18685
|
+
} : {}
|
|
18454
18686
|
});
|
|
18455
18687
|
track("wallet_token_send_failed", { reason: "execution_failed" });
|
|
18456
18688
|
return { status: "failed", message: message2 };
|
|
@@ -18458,7 +18690,7 @@ function useTokenTransfer(params) {
|
|
|
18458
18690
|
if (!settled) endTransfer(pendingId);
|
|
18459
18691
|
}
|
|
18460
18692
|
},
|
|
18461
|
-
[beginTransfer, settleTransfer, endTransfer, track, widget]
|
|
18693
|
+
[beginTransfer, settleTransfer, endTransfer, onPayFeeInNative, track, widget]
|
|
18462
18694
|
);
|
|
18463
18695
|
}
|
|
18464
18696
|
var FLUENT_USDNR_MINT_OP_ID = "fluent-mint-usdnr";
|
|
@@ -18521,7 +18753,7 @@ function useUsdnrMint(params) {
|
|
|
18521
18753
|
return { status: "rejected" };
|
|
18522
18754
|
}
|
|
18523
18755
|
debugError("[FluentWidget] USDnr mint failed", error);
|
|
18524
|
-
const message2 = error
|
|
18756
|
+
const message2 = describeFluentExecutionFailure(error, gasSymbol, "The mint was not sent.");
|
|
18525
18757
|
toast.add({
|
|
18526
18758
|
type: "error",
|
|
18527
18759
|
title: `Could not get ${token.symbol}`,
|
|
@@ -20293,6 +20525,7 @@ function FluentWidgetContent({
|
|
|
20293
20525
|
if (!authenticated || !user?.id || directAuthInFlight.current) return;
|
|
20294
20526
|
if (disconnectingRef.current) return;
|
|
20295
20527
|
if (walletUserPrivySession) return;
|
|
20528
|
+
if (!privyReady || embeddedWalletCount === 0) return;
|
|
20296
20529
|
if (session && !directAuthRequested.current && session.user?.id === user.id) return;
|
|
20297
20530
|
if (!identityToken) {
|
|
20298
20531
|
setWalletStatus("Waiting for Privy identity token");
|
|
@@ -20342,6 +20575,8 @@ function FluentWidgetContent({
|
|
|
20342
20575
|
}
|
|
20343
20576
|
}, [
|
|
20344
20577
|
authenticated,
|
|
20578
|
+
privyReady,
|
|
20579
|
+
embeddedWalletCount,
|
|
20345
20580
|
fluentConnect,
|
|
20346
20581
|
identityToken,
|
|
20347
20582
|
resolvedConfig.scopes,
|
|
@@ -20510,12 +20745,24 @@ function FluentWidgetContent({
|
|
|
20510
20745
|
useEffect(() => {
|
|
20511
20746
|
setSentDeposits([]);
|
|
20512
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]);
|
|
20513
20759
|
const sendToken = useTokenTransfer({
|
|
20514
20760
|
widget: widgetApi,
|
|
20515
20761
|
track,
|
|
20516
20762
|
beginTransfer,
|
|
20517
20763
|
settleTransfer,
|
|
20518
|
-
endTransfer
|
|
20764
|
+
endTransfer,
|
|
20765
|
+
onPayFeeInNative: payFeeInNative
|
|
20519
20766
|
});
|
|
20520
20767
|
const { mintUsdnr, mintingUsdnr } = useUsdnrMint({
|
|
20521
20768
|
widget: widgetApi,
|
|
@@ -21021,6 +21268,12 @@ function FluentWidgetContent({
|
|
|
21021
21268
|
const userXDisplayName = displayedPrivyUser?.twitter?.name || void 0;
|
|
21022
21269
|
const userGoogleName = displayedPrivyUser?.google?.name || void 0;
|
|
21023
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
|
+
);
|
|
21024
21277
|
const context = useMemo(
|
|
21025
21278
|
() => ({
|
|
21026
21279
|
session: hostSession,
|
|
@@ -21028,7 +21281,7 @@ function FluentWidgetContent({
|
|
|
21028
21281
|
userXDisplayName,
|
|
21029
21282
|
userGoogleName,
|
|
21030
21283
|
wallet: activeWallet,
|
|
21031
|
-
widget:
|
|
21284
|
+
widget: appWidgetApi,
|
|
21032
21285
|
openConnect,
|
|
21033
21286
|
openAccount: openAccountMenu,
|
|
21034
21287
|
disconnect: requestDisconnect,
|
|
@@ -21044,7 +21297,7 @@ function FluentWidgetContent({
|
|
|
21044
21297
|
userXDisplayName,
|
|
21045
21298
|
userGoogleName,
|
|
21046
21299
|
activeWallet,
|
|
21047
|
-
|
|
21300
|
+
appWidgetApi,
|
|
21048
21301
|
openConnect,
|
|
21049
21302
|
openAccountMenu,
|
|
21050
21303
|
requestDisconnect,
|
|
@@ -21136,6 +21389,7 @@ function FluentWidgetContent({
|
|
|
21136
21389
|
panel: walletMenuPanel,
|
|
21137
21390
|
onPanelChange: setWalletMenuPanel,
|
|
21138
21391
|
onSendToken: sendToken,
|
|
21392
|
+
sendRetry: sendRetry ?? void 0,
|
|
21139
21393
|
pendingTransfers,
|
|
21140
21394
|
sentTransfer: sentTransfer ?? void 0,
|
|
21141
21395
|
sentDeposits,
|
|
@@ -21177,6 +21431,7 @@ function FluentWidgetContent({
|
|
|
21177
21431
|
InlineConnectModal,
|
|
21178
21432
|
{
|
|
21179
21433
|
open: connectOpen,
|
|
21434
|
+
onSignerCreationError: () => setConnectOpen(true),
|
|
21180
21435
|
onClose: () => {
|
|
21181
21436
|
setConnectOpen(false);
|
|
21182
21437
|
setDirectAuthRequested(false);
|