@lumiapassport/core 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler/index.cjs +60 -14
- package/dist/bundler/index.cjs.map +1 -1
- package/dist/bundler/index.js +60 -14
- package/dist/bundler/index.js.map +1 -1
- package/dist/clients/index.cjs +288 -15
- package/dist/clients/index.cjs.map +1 -1
- package/dist/clients/index.d.cts +226 -1
- package/dist/clients/index.d.ts +226 -1
- package/dist/clients/index.js +286 -16
- package/dist/clients/index.js.map +1 -1
- package/dist/index.cjs +288 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +286 -16
- package/dist/index.js.map +1 -1
- package/dist/internal/error-tracking.cjs +1 -1
- package/dist/internal/error-tracking.js +1 -1
- package/package.json +1 -1
package/dist/bundler/index.cjs
CHANGED
|
@@ -226,8 +226,38 @@ function getEnvVarBool(name) {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
// src/bundler/fee-calculation.ts
|
|
229
|
-
var
|
|
230
|
-
var
|
|
229
|
+
var HARDCODED_FALLBACK_MAX_FEE = 3000000000n;
|
|
230
|
+
var HARDCODED_FALLBACK_PRIORITY_FEE = 3000000000n;
|
|
231
|
+
function getMinMaxFeePerGas() {
|
|
232
|
+
const envValue = getEnvVar("MIN_MAX_FEE_PER_GAS") || getEnvVar("VITE_MIN_MAX_FEE_PER_GAS");
|
|
233
|
+
if (envValue) {
|
|
234
|
+
try {
|
|
235
|
+
return BigInt(envValue);
|
|
236
|
+
} catch {
|
|
237
|
+
console.warn("[Fees] Invalid MIN_MAX_FEE_PER_GAS value:", envValue);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return HARDCODED_FALLBACK_MAX_FEE;
|
|
241
|
+
}
|
|
242
|
+
function getMinPriorityFeePerGas() {
|
|
243
|
+
const envValue = getEnvVar("MIN_PRIORITY_FEE_PER_GAS") || getEnvVar("VITE_MIN_PRIORITY_FEE_PER_GAS");
|
|
244
|
+
if (envValue) {
|
|
245
|
+
try {
|
|
246
|
+
return BigInt(envValue);
|
|
247
|
+
} catch {
|
|
248
|
+
console.warn("[Fees] Invalid MIN_PRIORITY_FEE_PER_GAS value:", envValue);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return HARDCODED_FALLBACK_PRIORITY_FEE;
|
|
252
|
+
}
|
|
253
|
+
function getDefaultMaxFeePerGasHex() {
|
|
254
|
+
return `0x${getMinMaxFeePerGas().toString(16)}`;
|
|
255
|
+
}
|
|
256
|
+
function getDefaultPriorityFeePerGasHex() {
|
|
257
|
+
return `0x${getMinPriorityFeePerGas().toString(16)}`;
|
|
258
|
+
}
|
|
259
|
+
var DEFAULT_FEE_CONFIG = { baseFeeBuffer: 0.5, priorityFeeBuffer: 0.05, fallbackMaxFeePerGas: HARDCODED_FALLBACK_MAX_FEE, fallbackMaxPriorityFeePerGas: HARDCODED_FALLBACK_PRIORITY_FEE };
|
|
260
|
+
var CONSERVATIVE_FEE_CONFIG = { baseFeeBuffer: 1, priorityFeeBuffer: 0.25, fallbackMaxFeePerGas: 5000000000n, fallbackMaxPriorityFeePerGas: 3000000000n };
|
|
231
261
|
function shouldUseLegacyGasForChain() {
|
|
232
262
|
try {
|
|
233
263
|
const legacyChainIds = getEnvVar("VITE_LEGACY_GAS_CHAIN_IDS") || getEnvVar("LEGACY_GAS_CHAIN_IDS") || "";
|
|
@@ -284,6 +314,8 @@ async function getFallbackPriorityFee() {
|
|
|
284
314
|
}
|
|
285
315
|
}
|
|
286
316
|
async function calculateLegacyFees(gasPrice) {
|
|
317
|
+
const minMaxFee = getMinMaxFeePerGas();
|
|
318
|
+
const minPriorityFee = getMinPriorityFeePerGas();
|
|
287
319
|
try {
|
|
288
320
|
let legacyGasPrice;
|
|
289
321
|
if (gasPrice) {
|
|
@@ -293,26 +325,30 @@ async function calculateLegacyFees(gasPrice) {
|
|
|
293
325
|
const gasPriceHex = await publicClient.getGasPrice();
|
|
294
326
|
legacyGasPrice = BigInt(gasPriceHex);
|
|
295
327
|
}
|
|
328
|
+
const effectiveGasPrice = legacyGasPrice < minMaxFee ? minMaxFee : legacyGasPrice;
|
|
296
329
|
const result = {
|
|
297
|
-
maxFeePerGas: `0x${
|
|
298
|
-
maxPriorityFeePerGas: `0x${
|
|
330
|
+
maxFeePerGas: `0x${effectiveGasPrice.toString(16)}`,
|
|
331
|
+
maxPriorityFeePerGas: `0x${effectiveGasPrice.toString(16)}`
|
|
299
332
|
};
|
|
300
333
|
console.log("[Fees] Using legacy gas pricing (avoid BASEFEE opcode):", {
|
|
301
334
|
gasPrice: legacyGasPrice.toString(),
|
|
335
|
+
minFee: minMaxFee.toString(),
|
|
336
|
+
effectiveGasPrice: effectiveGasPrice.toString(),
|
|
302
337
|
maxFeePerGas: result.maxFeePerGas,
|
|
303
338
|
maxPriorityFeePerGas: result.maxPriorityFeePerGas
|
|
304
339
|
});
|
|
305
340
|
return result;
|
|
306
341
|
} catch (error) {
|
|
307
|
-
console.warn("[Fees] Legacy fee calculation failed, using
|
|
308
|
-
const fallbackGasPrice = 1000000000n;
|
|
342
|
+
console.warn("[Fees] Legacy fee calculation failed, using min fee fallback:", error);
|
|
309
343
|
return {
|
|
310
|
-
maxFeePerGas: `0x${
|
|
311
|
-
maxPriorityFeePerGas: `0x${
|
|
344
|
+
maxFeePerGas: `0x${minMaxFee.toString(16)}`,
|
|
345
|
+
maxPriorityFeePerGas: `0x${minPriorityFee.toString(16)}`
|
|
312
346
|
};
|
|
313
347
|
}
|
|
314
348
|
}
|
|
315
349
|
async function calculateDynamicFees(config = DEFAULT_FEE_CONFIG) {
|
|
350
|
+
const minMaxFee = getMinMaxFeePerGas();
|
|
351
|
+
const minPriorityFee = getMinPriorityFeePerGas();
|
|
316
352
|
try {
|
|
317
353
|
const forceLegacy = getEnvVarBool("VITE_FORCE_LEGACY_GAS") || getEnvVarBool("FORCE_LEGACY_GAS");
|
|
318
354
|
const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();
|
|
@@ -324,8 +360,16 @@ async function calculateDynamicFees(config = DEFAULT_FEE_CONFIG) {
|
|
|
324
360
|
const bufferedBaseFee = baseFee + baseFee * BigInt(Math.floor(config.baseFeeBuffer * 1e3)) / 1000n;
|
|
325
361
|
const priorityFee = await getCurrentPriorityFee();
|
|
326
362
|
const bufferedPriorityFee = priorityFee + priorityFee * BigInt(Math.floor(config.priorityFeeBuffer * 1e3)) / 1000n;
|
|
327
|
-
|
|
328
|
-
|
|
363
|
+
let maxFeePerGas = bufferedBaseFee + bufferedPriorityFee;
|
|
364
|
+
let maxPriorityFeePerGas = bufferedPriorityFee;
|
|
365
|
+
if (maxFeePerGas < minMaxFee) {
|
|
366
|
+
console.log("[Fees] Calculated maxFeePerGas below minimum, using minimum:", { calculated: maxFeePerGas.toString(), min: minMaxFee.toString() });
|
|
367
|
+
maxFeePerGas = minMaxFee;
|
|
368
|
+
}
|
|
369
|
+
if (maxPriorityFeePerGas < minPriorityFee) {
|
|
370
|
+
console.log("[Fees] Calculated maxPriorityFeePerGas below minimum, using minimum:", { calculated: maxPriorityFeePerGas.toString(), min: minPriorityFee.toString() });
|
|
371
|
+
maxPriorityFeePerGas = minPriorityFee;
|
|
372
|
+
}
|
|
329
373
|
return { maxFeePerGas: `0x${maxFeePerGas.toString(16)}`, maxPriorityFeePerGas: `0x${maxPriorityFeePerGas.toString(16)}`, baseFee, priorityFee, bufferedBaseFee, bufferedPriorityFee };
|
|
330
374
|
} catch {
|
|
331
375
|
return await calculateLegacyFees();
|
|
@@ -353,7 +397,9 @@ var DUMMY_SIGNATURE = `0x${"00".repeat(65)}`;
|
|
|
353
397
|
function packUserOperationV07(userOp, includeFactory, factoryAddress, factoryData) {
|
|
354
398
|
const initCode = includeFactory && factoryAddress && factoryData ? factoryAddress + factoryData.slice(2) : "0x";
|
|
355
399
|
const accountGasLimits = pack2x128(safeToBigInt(userOp.verificationGasLimit, "0x1e8480"), safeToBigInt(userOp.callGasLimit, "0x0f4240"));
|
|
356
|
-
const
|
|
400
|
+
const defaultMaxFee = getDefaultMaxFeePerGasHex();
|
|
401
|
+
const defaultPriorityFee = getDefaultPriorityFeePerGasHex();
|
|
402
|
+
const gasFees = pack2x128(safeToBigInt(userOp.maxPriorityFeePerGas, defaultPriorityFee), safeToBigInt(userOp.maxFeePerGas, defaultMaxFee));
|
|
357
403
|
let paymasterAndData = "0x";
|
|
358
404
|
if (userOp.paymaster && userOp.paymaster !== "0x") {
|
|
359
405
|
const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
|
|
@@ -373,8 +419,8 @@ function createDummyUserOperation(sender, nonce, callData, includeFactory = fals
|
|
|
373
419
|
// 5,000,000 (bundler max limit)
|
|
374
420
|
preVerificationGas: "0x30d40",
|
|
375
421
|
// 200,000
|
|
376
|
-
maxFeePerGas: customMaxFeePerGas ||
|
|
377
|
-
maxPriorityFeePerGas: customMaxPriorityFeePerGas ||
|
|
422
|
+
maxFeePerGas: customMaxFeePerGas || getDefaultMaxFeePerGasHex(),
|
|
423
|
+
maxPriorityFeePerGas: customMaxPriorityFeePerGas || getDefaultPriorityFeePerGasHex(),
|
|
378
424
|
signature: DUMMY_SIGNATURE
|
|
379
425
|
};
|
|
380
426
|
if (includeFactory && factoryAddress && factoryData) {
|
|
@@ -390,7 +436,7 @@ function createDummyUserOperationV06(sender, nonce, callData, includeFactory = f
|
|
|
390
436
|
const factoryDataClean = factoryData.startsWith("0x") ? factoryData.slice(2) : factoryData;
|
|
391
437
|
initCode = `0x${factoryAddrClean}${factoryDataClean}`;
|
|
392
438
|
}
|
|
393
|
-
return { sender, nonce, initCode, callData, callGasLimit: "0x1E8480", verificationGasLimit: "0x4C4B40", preVerificationGas: "0x30d40", maxFeePerGas: customMaxFeePerGas ||
|
|
439
|
+
return { sender, nonce, initCode, callData, callGasLimit: "0x1E8480", verificationGasLimit: "0x4C4B40", preVerificationGas: "0x30d40", maxFeePerGas: customMaxFeePerGas || getDefaultMaxFeePerGasHex(), maxPriorityFeePerGas: customMaxPriorityFeePerGas || getDefaultPriorityFeePerGasHex(), paymasterAndData: "0x", signature: DUMMY_SIGNATURE };
|
|
394
440
|
}
|
|
395
441
|
async function createUserOperationWithDynamicFees(sender, nonce, callData, includeFactory = false, factoryAddress, factoryData, feeType = "standard") {
|
|
396
442
|
let fees;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundler/constants.ts","../../src/utils/helpers.ts","../../src/bundler/submission.ts","../../src/bundler/client-provider.ts","../../src/utils/env.ts","../../src/bundler/fee-calculation.ts","../../src/bundler/utils.ts","../../src/bundler/gas-estimation.ts","../../src/bundler/simulation.ts"],"names":[],"mappings":";;;AAGO,IAAM,cAAA,GAAiB;AACvB,IAAM,cAAA,GAAiB;AACvB,IAAM,UAAA,GAAa;;;ACI1B,IAAM,iBAAA,GAAqE,uCAAA;AAK3E,SAAS,aAAA,GAAwB;AAI/B,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,IAAgB,UAAA,CAAmB,MAAA,EAAQ;AACnE,IAAA,MAAM,QAAA,GAAa,WAAmB,MAAA,CAAe,kBAAA;AACrD,IAAA,IAAI,UAAU,UAAA,EAAY;AACxB,MAAA,OAAO,QAAA,CAAS,UAAA;AAAA,IAClB;AAAA,EACF;AAGA,EAAuB;AACrB,IAAA,OAAO,iBAAA;AAAA,EACT;AAIF;AA+BO,IAAM,YAAA,GAAe,CAAC,GAAA,EAAU,QAAA,GAAW,KAAA,KAAkB;AAClE,EAAA,IAAI;AACF,IAAA,OAAO,MAAA,CAAO,OAAO,QAAQ,CAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,OAAO,QAAQ,CAAA;AAAA,EACxB;AACF,CAAA;AASO,IAAM,SAAA,GAAY,CAAC,EAAA,EAAY,EAAA,KAAuB;AAC3D,EAAA,OAAQ,EAAA,IAAM,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AA,EACzC;AACF","file":"index.cjs","sourcesContent":["/**\n * ERC-4337 EntryPoint contract addresses\n */\nexport const ENTRYPOINT_V07 = '0x0000000071727De22E5E9d8BAf0edAc6f37da032' as const;\nexport const ENTRYPOINT_V06 = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' as const;\nexport const ENTRYPOINT = ENTRYPOINT_V07;\n","/**\n * Account Abstraction helper utilities\n * Adapted from lumia-passport-ui-kit/src/internal/akHelpers.ts\n */\n\n// Build-time injected URLs (tsup.define)\ndeclare const __LUMIA_BUNDLER_URL__: string;\n\n// Build-time default from .env (will be replaced by tsup define)\nconst BUILD_BUNDLER_URL = (typeof __LUMIA_BUNDLER_URL__ !== 'undefined' && __LUMIA_BUNDLER_URL__) || '';\n\n/**\n * Get bundler URL from runtime config or build-time default\n */\nfunction getBundlerUrl(): string {\n // Priority: window.__LUMIA_SERVICES__ > build-time default > hardcoded fallback\n\n // 1. Browser runtime config from LumiaPassportProvider (window.__LUMIA_SERVICES__)\n if (typeof globalThis !== 'undefined' && (globalThis as any).window) {\n const services = ((globalThis as any).window as any).__LUMIA_SERVICES__;\n if (services?.bundlerUrl) {\n return services.bundlerUrl;\n }\n }\n\n // 2. Build-time injected default (from .env during pnpm build)\n if (BUILD_BUNDLER_URL) {\n return BUILD_BUNDLER_URL;\n }\n\n // 3. Hardcoded fallback\n return 'http://localhost:4337';\n}\n\n/**\n * Precompile address for ecrecover\n * @internal\n */\n// const ECRECOVER_PRECOMPILE = '0x0000000000000000000000000000000000000001' as const;\n\n/**\n * ABI for ecrecover precompile\n * @internal\n */\n// const ECRECOVER_ABI = [\n// {\n// name: 'ecrecover',\n// type: 'function',\n// inputs: [\n// { name: 'hash', type: 'bytes32' },\n// { name: 'v', type: 'uint8' },\n// { name: 'r', type: 'bytes32' },\n// { name: 's', type: 'bytes32' }\n// ],\n// outputs: [{ name: 'addr', type: 'address' }]\n// },\n// ] as const;\n\n/**\n * Safely convert value to BigInt with fallback\n * @param val - Value to convert\n * @param fallback - Fallback value if conversion fails\n */\nexport const safeToBigInt = (val: any, fallback = '0x0'): bigint => {\n try {\n return BigInt(val || fallback);\n } catch {\n return BigInt(fallback);\n }\n};\n\n/**\n * Pack two 128-bit values into single 256-bit value\n * Used for packing gas limits in ERC-4337 v0.7\n * @param hi - High 128 bits\n * @param lo - Low 128 bits\n * @returns Packed 256-bit value as bigint\n */\nexport const pack2x128 = (hi: bigint, lo: bigint): bigint => {\n return (hi << 128n) | (lo & ((1n << 128n) - 1n));\n};\n\n/**\n * Verify signature against expected owner address\n * @param opHash - Operation hash that was signed\n * @param signature - Signature to verify\n * @param expectedOwner - Expected owner address\n */\nexport async function verifySignatureAgainstOwner(\n opHash: `0x${string}`,\n signature: `0x${string}`,\n expectedOwner?: `0x${string}`\n): Promise<void> {\n if (!signature || signature === '0x') return;\n\n try {\n // This will be implemented after we have publicClient from clients module\n // For now, this is a placeholder\n console.log('[AA][sign] Signature verification:', {\n opHash,\n signature,\n expectedOwner,\n });\n } catch (error) {\n console.error('[AA][sign][ERROR] Could not verify signature:', error);\n }\n}\n\n/**\n * Fetch nonce from EntryPoint contract\n * @param account - Account address\n * @param _entryPoint - EntryPoint contract address (unused in placeholder)\n */\nexport async function fetchEntryPointNonce(\n account: `0x${string}`,\n _entryPoint: `0x${string}`\n): Promise<`0x${string}`> {\n // This will be implemented after we have publicClient from clients module\n // For now, return 0x0 as placeholder\n console.log('[AA] fetchEntryPointNonce called for:', account);\n return '0x0';\n}\n\n/**\n * Sanitize UserOperation object by fixing common issues\n * @param userOp - UserOperation to sanitize\n */\nfunction sanitizeUserOperation(userOp: any): any {\n const sanitized = { ...userOp };\n\n // Fix sender field if it's an object (extract address and factory fields)\n if (typeof sanitized.sender === 'object' && sanitized.sender) {\n const senderObj = sanitized.sender;\n\n // Extract the actual sender address\n sanitized.sender = senderObj.sender || senderObj.address || senderObj.smartAccountAddress;\n\n // Extract factory fields if they exist\n if (senderObj.factory) {\n sanitized.factory = senderObj.factory;\n }\n if (senderObj.factoryData) {\n sanitized.factoryData = senderObj.factoryData;\n }\n }\n\n // Ensure all hex fields are valid and properly formatted\n const hexFields = [\n 'sender', 'nonce', 'callData', 'callGasLimit', 'verificationGasLimit',\n 'preVerificationGas', 'maxFeePerGas', 'maxPriorityFeePerGas', 'signature',\n 'factory', 'factoryData', 'paymaster', 'paymasterData',\n 'paymasterVerificationGasLimit', 'paymasterPostOpGasLimit'\n ];\n\n for (const field of hexFields) {\n const value = sanitized[field];\n if (value !== undefined && value !== null) {\n if (typeof value === 'string') {\n if (value === '0x' || value === '') {\n // Convert empty hex to 0x0 for numeric fields, 0x for data fields\n if (['callData', 'factoryData', 'paymasterData', 'signature'].includes(field)) {\n sanitized[field] = '0x';\n } else {\n sanitized[field] = '0x0';\n }\n } else if (field === 'sender' || field === 'factory' || field === 'paymaster') {\n // Address fields should have 0x prefix\n if (!value.startsWith('0x')) {\n sanitized[field] = `0x${value}`;\n }\n } else if (!value.startsWith('0x')) {\n sanitized[field] = `0x${value}`;\n }\n }\n }\n }\n\n // Remove undefined/null fields for v0.7\n Object.keys(sanitized).forEach(key => {\n if (sanitized[key] === undefined || sanitized[key] === null) {\n delete sanitized[key];\n }\n });\n\n // Ensure required fields exist with proper defaults\n if (!sanitized.callData) sanitized.callData = '0x';\n if (!sanitized.signature) sanitized.signature = '0x';\n\n return sanitized;\n}\n\n/**\n * Make RPC call to bundler\n * @param method - RPC method name\n * @param params - RPC method parameters\n * @param bundlerUrl - Bundler URL (will be fetched from config if not provided)\n */\nexport async function bundlerRpc(\n method: string,\n params: any[],\n bundlerUrl?: string\n): Promise<any> {\n // Sanitize UserOperation if this is eth_sendUserOperation\n let cleanParams = params;\n if (method === 'eth_sendUserOperation' && params[0]) {\n cleanParams = [sanitizeUserOperation(params[0]), params[1]];\n }\n\n const body = { jsonrpc: '2.0', id: 1, method, params: cleanParams };\n const bodyStr = JSON.stringify(body, (_k, v) => (typeof v === 'bigint' ? `0x${v.toString(16)}` : v));\n\n console.log('[Bundler][RPC] ->', method, bodyStr);\n\n // Get bundler URL: parameter > runtime config > build-time default > fallback\n const url = bundlerUrl || getBundlerUrl();\n\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: bodyStr\n });\n\n const json: any = await res.json();\n\n if (json.error) {\n console.log('[Bundler][RPC] <- ERROR:', JSON.stringify(json.error));\n const detail = json.error?.data ? ` | data: ${JSON.stringify(json.error.data)}` : '';\n throw new Error((json.error.message || JSON.stringify(json.error)) + detail);\n }\n\n console.log('[Bundler][RPC] <- SUCCESS:', JSON.stringify(json.result));\n return json.result;\n}\n","import { bundlerRpc, fetchEntryPointNonce } from '../utils/helpers';\nimport { ENTRYPOINT_V07, ENTRYPOINT_V06 } from './constants';\nimport type { UserOperationV07, UserOperationV06 } from './types';\n\nexport async function sendUserOperationRaw(userOp: UserOperationV07): Promise<`0x${string}`> {\n const hash = await bundlerRpc('eth_sendUserOperation', [userOp, ENTRYPOINT_V07]);\n return hash;\n}\n\nexport async function sendUserOperationV06Raw(userOp: UserOperationV06): Promise<`0x${string}`> {\n const hash = await bundlerRpc('eth_sendUserOperation', [userOp, ENTRYPOINT_V06]);\n return hash;\n}\n\nexport async function sendUserOperationWithRetry(\n userOp: UserOperationV07,\n resigner: (nonce: `0x${string}`) => Promise<UserOperationV07>,\n maxRetries: number = 1\n): Promise<`0x${string}`> {\n let attempts = 0; let currentUserOp = userOp;\n while (attempts < maxRetries) {\n try { return await sendUserOperationRaw(currentUserOp); }\n catch (error: any) { attempts++; const errorMsg = String(error?.message || error); if (attempts >= maxRetries) throw error; if (/nonce too low|nonce.*invalid/i.test(errorMsg)) { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V07); currentUserOp = await resigner(newNonce); } else if (/replacement.*underpriced/i.test(errorMsg)) { const increasedMaxFeePerGas = `0x${((BigInt(currentUserOp.maxFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; const increasedMaxPriorityFeePerGas = `0x${((BigInt(currentUserOp.maxPriorityFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; currentUserOp = { ...currentUserOp, maxFeePerGas: increasedMaxFeePerGas, maxPriorityFeePerGas: increasedMaxPriorityFeePerGas }; currentUserOp = await resigner(currentUserOp.nonce); } else { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V07); currentUserOp = await resigner(newNonce); } await new Promise(r => setTimeout(r, 1000 * attempts)); }\n }\n throw new Error(`Failed to send UserOperation v0.7 after ${maxRetries} attempts`);\n}\n\nexport async function sendUserOperationV06WithRetry(\n userOp: UserOperationV06,\n resigner: (nonce: `0x${string}`) => Promise<UserOperationV06>,\n maxRetries: number = 1\n): Promise<`0x${string}`> {\n let attempts = 0; let currentUserOp = userOp;\n while (attempts < maxRetries) {\n try { return await sendUserOperationV06Raw(currentUserOp); }\n catch (error: any) { attempts++; const errorMsg = String(error?.message || error); if (attempts >= maxRetries) throw error; if (/nonce too low|nonce.*invalid/i.test(errorMsg)) { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V06); currentUserOp = await resigner(newNonce); } else if (/replacement.*underpriced/i.test(errorMsg)) { const increasedMaxFeePerGas = `0x${((BigInt(currentUserOp.maxFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; const increasedMaxPriorityFeePerGas = `0x${((BigInt(currentUserOp.maxPriorityFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; currentUserOp = { ...currentUserOp, maxFeePerGas: increasedMaxFeePerGas, maxPriorityFeePerGas: increasedMaxPriorityFeePerGas }; currentUserOp = await resigner(currentUserOp.nonce); } else { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V06); currentUserOp = await resigner(newNonce); } await new Promise(r => setTimeout(r, 1000 * attempts)); }\n }\n throw new Error(`Failed to send UserOperation v0.6 after ${maxRetries} attempts`);\n}\n\nexport async function getUserOperationReceipt(userOpHash: `0x${string}`): Promise<any> {\n const receipt = await bundlerRpc('eth_getUserOperationReceipt', [userOpHash]);\n return receipt;\n}\n","/**\n * Provider for viem PublicClient\n * Allows fee-calculation and other modules to access the configured client\n */\n\n// Using 'any' type to avoid direct viem dependency in this file\n// Actual type should be PublicClient from viem\nlet globalPublicClient: any | null = null;\n\n/**\n * Set the global public client for blockchain interactions\n * Should be called during initialization with a viem PublicClient\n */\nexport function setPublicClient(client: any): void {\n globalPublicClient = client;\n}\n\n/**\n * Get the configured public client\n * Throws if not configured\n */\nexport function getPublicClient(): any {\n if (!globalPublicClient) {\n throw new Error(\n '[LumiaPassport] PublicClient not configured. Please provide a publicClient in config ' +\n 'or call setPublicClient() before using fee calculation functions.'\n );\n }\n return globalPublicClient;\n}\n\n/**\n * Check if public client is configured\n */\nexport function hasPublicClient(): boolean {\n return globalPublicClient !== null;\n}\n","/**\n * Universal environment variable access that works in both browser and Node.js\n */\n\ninterface EnvVars {\n [key: string]: string | undefined;\n}\n\n/**\n * Get environment variables from various sources\n * Priority: 1. window.__LUMIA_ENV__ (browser), 2. import.meta.env (Vite), 3. process.env (Node.js)\n */\nfunction getEnvironmentVars(): EnvVars {\n // Try browser environment first (injected by LumiaPassportProvider)\n // @ts-ignore - accessing global window object\n const win = typeof globalThis !== 'undefined' && (globalThis as any).window;\n if (win && win.__LUMIA_ENV__) {\n return win.__LUMIA_ENV__;\n }\n\n // Try import.meta.env (ESM/Vite)\n try {\n // @ts-ignore - import.meta may not be available in all environments\n if (import.meta?.env) {\n // @ts-ignore\n return import.meta.env as EnvVars;\n }\n } catch {\n // import.meta not available in this environment\n }\n\n // Try process.env (Node.js/CJS)\n if (typeof process !== 'undefined' && process.env) {\n return process.env;\n }\n\n // Fallback to empty object\n return {};\n}\n\n/**\n * Get a single environment variable\n * @param name - The environment variable name\n * @returns The environment variable value or undefined\n */\nexport function getEnvVar(name: string): string | undefined {\n const env = getEnvironmentVars();\n return env[name];\n}\n\n/**\n * Get an environment variable as boolean\n * @param name - The environment variable name\n * @returns true if value is 'true' or '1', false otherwise\n */\nexport function getEnvVarBool(name: string): boolean {\n const value = getEnvVar(name);\n return value === 'true' || value === '1';\n}\n\n/**\n * Get an environment variable as array\n * @param name - The environment variable name\n * @param separator - Separator character (default: ',')\n * @returns Array of trimmed non-empty strings\n */\nexport function getEnvVarArray(name: string, separator = ','): string[] {\n const value = getEnvVar(name);\n return value ? value.split(separator).map(s => s.trim()).filter(Boolean) : [];\n}\n\n/**\n * Get all environment variables\n * @returns Object containing all environment variables\n */\nexport function getAllEnvVars(): EnvVars {\n return getEnvironmentVars();\n}\n\n/**\n * Check if running in development mode\n * @returns true if NODE_ENV or MODE is 'development'\n */\nexport function isDevelopment(): boolean {\n const env = getEnvironmentVars();\n return env.NODE_ENV === 'development' || env.MODE === 'development';\n}\n\n/**\n * Check if running in production mode\n * @returns true if NODE_ENV or MODE is 'production'\n */\nexport function isProduction(): boolean {\n const env = getEnvironmentVars();\n return env.NODE_ENV === 'production' || env.MODE === 'production';\n}\n","import { bundlerRpc } from '../utils/helpers';\nimport { getPublicClient } from './client-provider';\nimport { getEnvVar, getEnvVarBool } from '../utils/env';\n\nexport interface FeeConfig {\n baseFeeBuffer: number;\n priorityFeeBuffer: number;\n fallbackMaxFeePerGas?: bigint;\n fallbackMaxPriorityFeePerGas?: bigint;\n}\n\nexport interface CalculatedFees {\n maxFeePerGas: `0x${string}`;\n maxPriorityFeePerGas: `0x${string}`;\n baseFee?: bigint;\n priorityFee?: bigint;\n bufferedBaseFee?: bigint;\n bufferedPriorityFee?: bigint;\n}\n\nexport const DEFAULT_FEE_CONFIG: FeeConfig = { baseFeeBuffer: 0.5, priorityFeeBuffer: 0.05, fallbackMaxFeePerGas: 1_000_000_000n, fallbackMaxPriorityFeePerGas: 1_000_000_000n };\nexport const CONSERVATIVE_FEE_CONFIG: FeeConfig = { baseFeeBuffer: 1.0, priorityFeeBuffer: 0.25, fallbackMaxFeePerGas: 5_000_000_000n, fallbackMaxPriorityFeePerGas: 2_000_000_000n };\n\n/**\n * Check if the current chain requires legacy gas pricing to avoid BASEFEE opcode errors\n */\nfunction shouldUseLegacyGasForChain(): boolean {\n try {\n // Get environment variable for legacy chain IDs (comma-separated list)\n const legacyChainIds = getEnvVar('VITE_LEGACY_GAS_CHAIN_IDS') || getEnvVar('LEGACY_GAS_CHAIN_IDS') || '';\n\n console.log('[Fees] Environment check:', {\n LEGACY_GAS_CHAIN_IDS: legacyChainIds,\n });\n\n // Default to Lumia Beam testnet if no env var is set\n const defaultLegacyChains = '2030232745'; // Lumia Beam testnet\n const chainIdsString = legacyChainIds || defaultLegacyChains;\n\n // Parse chain IDs\n const legacyChains = chainIdsString.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id));\n\n // Get current chain ID from public client\n const publicClient = getPublicClient();\n const currentChainId = publicClient?.chain?.id;\n\n if (!currentChainId) return false;\n\n const shouldUseLegacy = legacyChains.includes(currentChainId);\n\n if (shouldUseLegacy) {\n console.log('[Fees] Chain requires legacy gas pricing:', {\n chainId: currentChainId,\n legacyChains,\n configuredVia: legacyChainIds ? 'LEGACY_GAS_CHAIN_IDS env var' : 'default'\n });\n }\n\n return shouldUseLegacy;\n } catch (error) {\n console.warn('[Fees] Error checking legacy gas chain configuration:', error);\n return false;\n }\n}\n\nexport async function getCurrentBaseFee(): Promise<bigint> {\n const publicClient = getPublicClient();\n const block = await publicClient.getBlock({ blockTag: 'latest' });\n if (block.baseFeePerGas) return block.baseFeePerGas;\n const gasPriceHex = await publicClient.getGasPrice(); const gasPrice = BigInt(gasPriceHex);\n const estimatedBaseFee = (gasPrice * 9n) / 10n; return estimatedBaseFee;\n}\n\nexport async function getCurrentPriorityFee(): Promise<bigint> {\n try { const priorityFeeHex = await bundlerRpc('rundler_maxPriorityFeePerGas', []); const priorityFee = BigInt(priorityFeeHex); if (priorityFee === 0n) return await getFallbackPriorityFee(); return priorityFee; } catch { return await getFallbackPriorityFee(); }\n}\n\nasync function getFallbackPriorityFee(): Promise<bigint> {\n try { const publicClient = getPublicClient(); const gasPriceHex = await publicClient.getGasPrice(); const gasPrice = BigInt(gasPriceHex); return gasPrice / 10n; } catch { return 100_000_000n; }\n}\n\nexport async function calculateLegacyFees(gasPrice?: bigint): Promise<CalculatedFees> {\n try {\n let legacyGasPrice: bigint;\n\n if (gasPrice) {\n legacyGasPrice = gasPrice;\n } else {\n // Get current gas price from network\n const publicClient = getPublicClient();\n const gasPriceHex = await publicClient.getGasPrice();\n legacyGasPrice = BigInt(gasPriceHex);\n }\n\n // For legacy chains, set both maxFeePerGas and maxPriorityFeePerGas to the same value\n // This prevents BASEFEE opcode usage\n const result: CalculatedFees = {\n maxFeePerGas: `0x${legacyGasPrice.toString(16)}`,\n maxPriorityFeePerGas: `0x${legacyGasPrice.toString(16)}`,\n };\n\n console.log('[Fees] Using legacy gas pricing (avoid BASEFEE opcode):', {\n gasPrice: legacyGasPrice.toString(),\n maxFeePerGas: result.maxFeePerGas,\n maxPriorityFeePerGas: result.maxPriorityFeePerGas,\n });\n\n return result;\n } catch (error) {\n console.warn('[Fees] Legacy fee calculation failed, using 1 gwei fallback:', error);\n const fallbackGasPrice = 1_000_000_000n; // 1 gwei\n return {\n maxFeePerGas: `0x${fallbackGasPrice.toString(16)}`,\n maxPriorityFeePerGas: `0x${fallbackGasPrice.toString(16)}`,\n };\n }\n}\n\nexport async function calculateDynamicFees(config: FeeConfig = DEFAULT_FEE_CONFIG): Promise<CalculatedFees> {\n try {\n // Check environment variable for forced legacy mode\n const forceLegacy = getEnvVarBool('VITE_FORCE_LEGACY_GAS') || getEnvVarBool('FORCE_LEGACY_GAS');\n\n // Check if current chain should use legacy gas pricing\n const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();\n\n if (shouldUseLegacy) {\n console.log('[Fees] Using legacy gas pricing', forceLegacy ? '(forced by FORCE_LEGACY_GAS env var)' : '(chain requires legacy gas)');\n return await calculateLegacyFees();\n }\n const baseFee = await getCurrentBaseFee(); const bufferedBaseFee = baseFee + (baseFee * BigInt(Math.floor(config.baseFeeBuffer * 1000))) / 1000n;\n const priorityFee = await getCurrentPriorityFee(); const bufferedPriorityFee = priorityFee + (priorityFee * BigInt(Math.floor(config.priorityFeeBuffer * 1000))) / 1000n;\n const maxFeePerGas = bufferedBaseFee + bufferedPriorityFee; const maxPriorityFeePerGas = bufferedPriorityFee;\n return { maxFeePerGas: `0x${maxFeePerGas.toString(16)}`, maxPriorityFeePerGas: `0x${maxPriorityFeePerGas.toString(16)}`, baseFee, priorityFee, bufferedBaseFee, bufferedPriorityFee };\n } catch { return await calculateLegacyFees(); }\n}\n\nexport async function calculateFastFees(): Promise<CalculatedFees> {\n const forceLegacy = getEnvVarBool('VITE_FORCE_LEGACY_GAS') || getEnvVarBool('FORCE_LEGACY_GAS');\n const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();\n\n if (shouldUseLegacy) return await calculateLegacyFees(3_000_000_000n);\n return calculateDynamicFees({ baseFeeBuffer: 0.75, priorityFeeBuffer: 0.5, fallbackMaxFeePerGas: 3_000_000_000n, fallbackMaxPriorityFeePerGas: 2_000_000_000n });\n}\n\nexport async function calculateEconomyFees(): Promise<CalculatedFees> {\n const forceLegacy = getEnvVarBool('VITE_FORCE_LEGACY_GAS') || getEnvVarBool('FORCE_LEGACY_GAS');\n const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();\n\n if (shouldUseLegacy) return await calculateLegacyFees(500_000_000n);\n return calculateDynamicFees({ baseFeeBuffer: 0.27, priorityFeeBuffer: 0.01, fallbackMaxFeePerGas: 1_000_000_000n, fallbackMaxPriorityFeePerGas: 500_000_000n });\n}\n\nexport async function getFeeEstimates(): Promise<{ economy: CalculatedFees; standard: CalculatedFees; fast: CalculatedFees; }> {\n const [economy, standard, fast] = await Promise.all([ calculateEconomyFees(), calculateDynamicFees(), calculateFastFees() ]);\n return { economy, standard, fast };\n}\n","import { pack2x128, safeToBigInt } from '../utils/helpers';\nimport { calculateDynamicFees, calculateEconomyFees, calculateFastFees } from './fee-calculation';\nimport type { UserOperationV07, UserOperationV06, PackedUserOperationV07 } from './types';\n\nexport const DUMMY_SIGNATURE = `0x${'00'.repeat(65)}` as `0x${string}`;\n\nexport function packUserOperationV07(\n userOp: UserOperationV07,\n includeFactory: boolean,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`\n): PackedUserOperationV07 {\n const initCode = includeFactory && factoryAddress && factoryData ? (((factoryAddress as string) + (factoryData as string).slice(2)) as `0x${string}`) : ('0x' as `0x${string}`);\n const accountGasLimits = pack2x128(safeToBigInt(userOp.verificationGasLimit, '0x1e8480'), safeToBigInt(userOp.callGasLimit, '0x0f4240'));\n const gasFees = pack2x128(safeToBigInt(userOp.maxPriorityFeePerGas, '0x3b9aca00'), safeToBigInt(userOp.maxFeePerGas, '0x3b9aca00'));\n\n // Create paymasterAndData from paymaster and paymasterData fields (V07 format)\n let paymasterAndData: `0x${string}` = '0x';\n if (userOp.paymaster && userOp.paymaster !== '0x') {\n const paymasterAddr = userOp.paymaster.startsWith('0x') ? userOp.paymaster.slice(2) : userOp.paymaster;\n const paymasterData = userOp.paymasterData ? (userOp.paymasterData.startsWith('0x') ? userOp.paymasterData.slice(2) : userOp.paymasterData) : '';\n paymasterAndData = `0x${paymasterAddr}${paymasterData}` as `0x${string}`;\n }\n\n return { sender: userOp.sender, nonce: BigInt(userOp.nonce), initCode, callData: userOp.callData, accountGasLimits, preVerificationGas: safeToBigInt(userOp.preVerificationGas, '0x1d4c0'), gasFees, paymasterAndData, signature: userOp.signature };\n}\n\nexport function createDummyUserOperation(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n customMaxFeePerGas?: `0x${string}`,\n customMaxPriorityFeePerGas?: `0x${string}`\n): UserOperationV07 {\n const userOp: UserOperationV07 = {\n sender,\n nonce,\n callData,\n callGasLimit: '0x1E8480', // 2,000,000 (for factory contracts with CREATE)\n verificationGasLimit: '0x4C4B40', // 5,000,000 (bundler max limit)\n preVerificationGas: '0x30d40', // 200,000\n maxFeePerGas: customMaxFeePerGas || '0x3b9aca00',\n maxPriorityFeePerGas: customMaxPriorityFeePerGas || '0x3b9aca00',\n signature: DUMMY_SIGNATURE,\n };\n if (includeFactory && factoryAddress && factoryData) { userOp.factory = factoryAddress; userOp.factoryData = factoryData; }\n return userOp;\n}\n\nexport function createDummyUserOperationV06(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n customMaxFeePerGas?: `0x${string}`,\n customMaxPriorityFeePerGas?: `0x${string}`\n): UserOperationV06 {\n let initCode: `0x${string}` = '0x';\n if (includeFactory && factoryAddress && factoryData) {\n const factoryAddrClean = factoryAddress.startsWith('0x') ? factoryAddress.slice(2) : factoryAddress;\n const factoryDataClean = factoryData.startsWith('0x') ? factoryData.slice(2) : factoryData;\n initCode = `0x${factoryAddrClean}${factoryDataClean}` as `0x${string}`;\n }\n return { sender, nonce, initCode, callData, callGasLimit: '0x1E8480', verificationGasLimit: '0x4C4B40', preVerificationGas: '0x30d40', maxFeePerGas: customMaxFeePerGas || '0x3b9aca00', maxPriorityFeePerGas: customMaxPriorityFeePerGas || '0x3b9aca00', paymasterAndData: '0x', signature: DUMMY_SIGNATURE };\n}\n\nexport async function createUserOperationWithDynamicFees(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n feeType: 'economy' | 'standard' | 'fast' = 'standard'\n): Promise<UserOperationV07> {\n let fees;\n switch (feeType) {\n case 'economy': fees = await calculateEconomyFees(); break;\n case 'fast': fees = await calculateFastFees(); break;\n default: fees = await calculateDynamicFees();\n }\n return createDummyUserOperation(sender, nonce, callData, includeFactory, factoryAddress, factoryData, fees.maxFeePerGas, fees.maxPriorityFeePerGas);\n}\n\nexport async function createUserOperationV06WithDynamicFees(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n feeType: 'economy' | 'standard' | 'fast' = 'standard'\n): Promise<UserOperationV06> {\n let fees;\n switch (feeType) {\n case 'economy': fees = await calculateEconomyFees(); break;\n case 'fast': fees = await calculateFastFees(); break;\n default: fees = await calculateDynamicFees();\n }\n return createDummyUserOperationV06(sender, nonce, callData, includeFactory, factoryAddress, factoryData, fees.maxFeePerGas, fees.maxPriorityFeePerGas);\n}\n","import { bundlerRpc } from '../utils/helpers';\nimport { ENTRYPOINT_V07 } from './constants';\nimport type { UserOperationV07, GasEstimationResult } from './types';\nimport { DUMMY_SIGNATURE, createUserOperationWithDynamicFees } from './utils';\n\nexport async function estimateUserOperationGas(userOp: UserOperationV07, retryWithoutFactory: boolean = true): Promise<GasEstimationResult> {\n try {\n const gas = await bundlerRpc('eth_estimateUserOperationGas', [userOp, ENTRYPOINT_V07]);\n return gas;\n } catch (error) {\n // Retry without factory if account is already deployed\n if (retryWithoutFactory && (userOp.factory || userOp.factoryData)) {\n const errorMsg = String(error);\n if (/AA10 sender already constructed/i.test(errorMsg) || /sender.*is an existing contract.*but initCode is nonempty/i.test(errorMsg)) {\n const userOpWithoutFactory: UserOperationV07 = { ...userOp };\n delete userOpWithoutFactory.factory;\n delete userOpWithoutFactory.factoryData;\n try {\n const gas = await bundlerRpc('eth_estimateUserOperationGas', [userOpWithoutFactory, ENTRYPOINT_V07]);\n return gas;\n } catch {}\n }\n }\n\n // Fallback to conservative gas estimates\n const isEmptyCallData = !userOp.callData || userOp.callData === '0x';\n // Increased to 2M to handle deep call chains (5+ levels) and contract deployments\n // With 63/64 rule at depth 5, only ~92% reaches the operation\n // Factory contracts like createERC3643 can use 1.6M+ gas with CREATE opcodes\n const minimalCallGas = isEmptyCallData ? '0x0' : '0x1E8480'; // 2,000,000 for non-empty calls\n return { callGasLimit: minimalCallGas, verificationGasLimit: '0x4C4B40', preVerificationGas: '0x30d40' }; // 5,000,000 (bundler max)\n }\n}\n\nexport async function estimateUserOperationGasWithSignature(\n userOp: UserOperationV07,\n _getSignature: (opHash: `0x${string}`) => Promise<`0x${string}` | null>,\n _getUserOpHash: (packedOp: any) => Promise<`0x${string}`>,\n retryWithoutFactory: boolean = true\n): Promise<GasEstimationResult> { const userOpForEstimation: UserOperationV07 = { ...userOp, signature: DUMMY_SIGNATURE }; return estimateUserOperationGas(userOpForEstimation, retryWithoutFactory); }\n\nexport async function estimateUserOperationGasWithDynamicFees(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n feeType: 'economy' | 'standard' | 'fast' = 'standard',\n retryWithoutFactory: boolean = true\n): Promise<GasEstimationResult & { calculatedFees?: any }> {\n const userOp = await createUserOperationWithDynamicFees(sender, nonce, callData, includeFactory, factoryAddress, factoryData, feeType);\n const gasResult = await estimateUserOperationGas(userOp, retryWithoutFactory);\n return { ...gasResult, calculatedFees: { maxFeePerGas: userOp.maxFeePerGas, maxPriorityFeePerGas: userOp.maxPriorityFeePerGas, feeType } };\n}\n","import { bundlerRpc } from '../utils/helpers';\nimport { ENTRYPOINT_V07 } from './constants';\nimport type { UserOperationV07, SimulationResult } from './types';\n\n/**\n * Simulate a UserOperation using Lumia's lumia_simulateUserOperation method\n * Returns asset changes that would occur if the operation is executed\n *\n * @param userOp - The UserOperation to simulate\n * @returns Simulation result with asset changes\n */\nexport async function simulateUserOperation(userOp: UserOperationV07): Promise<SimulationResult> {\n try {\n const result = await bundlerRpc('lumia_simulateUserOperation', [userOp, ENTRYPOINT_V07]);\n return result;\n } catch (error) {\n // If simulation fails, return error in the expected format\n const errorMsg = error instanceof Error ? error.message : String(error);\n return {\n changes: [],\n error: {\n message: errorMsg,\n code: -1\n }\n };\n }\n}\n\n/**\n * Validate a UserOperation by simulating it\n * Returns true if simulation succeeds without errors\n */\nexport async function validateUserOperation(userOp: UserOperationV07): Promise<{ valid: boolean; error?: string }> {\n try {\n const result = await simulateUserOperation(userOp);\n if (result.error) {\n return { valid: false, error: result.error.message };\n }\n return { valid: true };\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error);\n return { valid: false, error: errorMsg };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/bundler/constants.ts","../../src/utils/helpers.ts","../../src/bundler/submission.ts","../../src/bundler/client-provider.ts","../../src/utils/env.ts","../../src/bundler/fee-calculation.ts","../../src/bundler/utils.ts","../../src/bundler/gas-estimation.ts","../../src/bundler/simulation.ts"],"names":[],"mappings":";;;AAGO,IAAM,cAAA,GAAiB;AACvB,IAAM,cAAA,GAAiB;AACvB,IAAM,UAAA,GAAa;;;ACI1B,IAAM,iBAAA,GAAqE,uCAAA;AAK3E,SAAS,aAAA,GAAwB;AAI/B,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,IAAgB,UAAA,CAAmB,MAAA,EAAQ;AACnE,IAAA,MAAM,QAAA,GAAa,WAAmB,MAAA,CAAe,kBAAA;AACrD,IAAA,IAAI,UAAU,UAAA,EAAY;AACxB,MAAA,OAAO,QAAA,CAAS,UAAA;AAAA,IAClB;AAAA,EACF;AAGA,EAAuB;AACrB,IAAA,OAAO,iBAAA;AAAA,EACT;AAIF;AA+BO,IAAM,YAAA,GAAe,CAAC,GAAA,EAAU,QAAA,GAAW,KAAA,KAAkB;AAClE,EAAA,IAAI;AACF,IAAA,OAAO,MAAA,CAAO,OAAO,QAAQ,CAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,OAAO,QAAQ,CAAA;AAAA,EACxB;AACF,CAAA;AASO,IAAM,SAAA,GAAY,CAAC,EAAA,EAAY,EAAA,KAAuB;AAC3D,EAAA,OAAQ,EAAA,IAAM,IAAA,GAAS,EAAA,GAAA,CAAO,EAAA,IAAM,IAAA,IAAQ,EAAA;AAC9C,CAAA;AAiCA,eAAs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AAS,QAAA;AAAA,QACT,IAAA,EAAM;AAAA;AACR,KACF;AAAA,EACF;AACF;AAMA,eAAsB,sBAAsB,MAAA,EAAuE;AACjH,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,MAAM,qBAAA,CAAsB,MAAM,CAAA;AACjD,IAAA,IAAI,OAAO,KAAA,EAAO;AAChB,MAAA,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,MAAA,CAAO,MAAM,OAAA,EAAQ;AAAA,IACrD;AACA,IAAA,OAAO,EAAE,OAAO,IAAA,EAAK;AAAA,EACvB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,WAAW,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AACtE,IAAA,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,QAAA,EAAS;AAAA,EACzC;AACF","file":"index.cjs","sourcesContent":["/**\n * ERC-4337 EntryPoint contract addresses\n */\nexport const ENTRYPOINT_V07 = '0x0000000071727De22E5E9d8BAf0edAc6f37da032' as const;\nexport const ENTRYPOINT_V06 = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' as const;\nexport const ENTRYPOINT = ENTRYPOINT_V07;\n","/**\n * Account Abstraction helper utilities\n * Adapted from lumia-passport-ui-kit/src/internal/akHelpers.ts\n */\n\n// Build-time injected URLs (tsup.define)\ndeclare const __LUMIA_BUNDLER_URL__: string;\n\n// Build-time default from .env (will be replaced by tsup define)\nconst BUILD_BUNDLER_URL = (typeof __LUMIA_BUNDLER_URL__ !== 'undefined' && __LUMIA_BUNDLER_URL__) || '';\n\n/**\n * Get bundler URL from runtime config or build-time default\n */\nfunction getBundlerUrl(): string {\n // Priority: window.__LUMIA_SERVICES__ > build-time default > hardcoded fallback\n\n // 1. Browser runtime config from LumiaPassportProvider (window.__LUMIA_SERVICES__)\n if (typeof globalThis !== 'undefined' && (globalThis as any).window) {\n const services = ((globalThis as any).window as any).__LUMIA_SERVICES__;\n if (services?.bundlerUrl) {\n return services.bundlerUrl;\n }\n }\n\n // 2. Build-time injected default (from .env during pnpm build)\n if (BUILD_BUNDLER_URL) {\n return BUILD_BUNDLER_URL;\n }\n\n // 3. Hardcoded fallback\n return 'http://localhost:4337';\n}\n\n/**\n * Precompile address for ecrecover\n * @internal\n */\n// const ECRECOVER_PRECOMPILE = '0x0000000000000000000000000000000000000001' as const;\n\n/**\n * ABI for ecrecover precompile\n * @internal\n */\n// const ECRECOVER_ABI = [\n// {\n// name: 'ecrecover',\n// type: 'function',\n// inputs: [\n// { name: 'hash', type: 'bytes32' },\n// { name: 'v', type: 'uint8' },\n// { name: 'r', type: 'bytes32' },\n// { name: 's', type: 'bytes32' }\n// ],\n// outputs: [{ name: 'addr', type: 'address' }]\n// },\n// ] as const;\n\n/**\n * Safely convert value to BigInt with fallback\n * @param val - Value to convert\n * @param fallback - Fallback value if conversion fails\n */\nexport const safeToBigInt = (val: any, fallback = '0x0'): bigint => {\n try {\n return BigInt(val || fallback);\n } catch {\n return BigInt(fallback);\n }\n};\n\n/**\n * Pack two 128-bit values into single 256-bit value\n * Used for packing gas limits in ERC-4337 v0.7\n * @param hi - High 128 bits\n * @param lo - Low 128 bits\n * @returns Packed 256-bit value as bigint\n */\nexport const pack2x128 = (hi: bigint, lo: bigint): bigint => {\n return (hi << 128n) | (lo & ((1n << 128n) - 1n));\n};\n\n/**\n * Verify signature against expected owner address\n * @param opHash - Operation hash that was signed\n * @param signature - Signature to verify\n * @param expectedOwner - Expected owner address\n */\nexport async function verifySignatureAgainstOwner(\n opHash: `0x${string}`,\n signature: `0x${string}`,\n expectedOwner?: `0x${string}`\n): Promise<void> {\n if (!signature || signature === '0x') return;\n\n try {\n // This will be implemented after we have publicClient from clients module\n // For now, this is a placeholder\n console.log('[AA][sign] Signature verification:', {\n opHash,\n signature,\n expectedOwner,\n });\n } catch (error) {\n console.error('[AA][sign][ERROR] Could not verify signature:', error);\n }\n}\n\n/**\n * Fetch nonce from EntryPoint contract\n * @param account - Account address\n * @param _entryPoint - EntryPoint contract address (unused in placeholder)\n */\nexport async function fetchEntryPointNonce(\n account: `0x${string}`,\n _entryPoint: `0x${string}`\n): Promise<`0x${string}`> {\n // This will be implemented after we have publicClient from clients module\n // For now, return 0x0 as placeholder\n console.log('[AA] fetchEntryPointNonce called for:', account);\n return '0x0';\n}\n\n/**\n * Sanitize UserOperation object by fixing common issues\n * @param userOp - UserOperation to sanitize\n */\nfunction sanitizeUserOperation(userOp: any): any {\n const sanitized = { ...userOp };\n\n // Fix sender field if it's an object (extract address and factory fields)\n if (typeof sanitized.sender === 'object' && sanitized.sender) {\n const senderObj = sanitized.sender;\n\n // Extract the actual sender address\n sanitized.sender = senderObj.sender || senderObj.address || senderObj.smartAccountAddress;\n\n // Extract factory fields if they exist\n if (senderObj.factory) {\n sanitized.factory = senderObj.factory;\n }\n if (senderObj.factoryData) {\n sanitized.factoryData = senderObj.factoryData;\n }\n }\n\n // Ensure all hex fields are valid and properly formatted\n const hexFields = [\n 'sender', 'nonce', 'callData', 'callGasLimit', 'verificationGasLimit',\n 'preVerificationGas', 'maxFeePerGas', 'maxPriorityFeePerGas', 'signature',\n 'factory', 'factoryData', 'paymaster', 'paymasterData',\n 'paymasterVerificationGasLimit', 'paymasterPostOpGasLimit'\n ];\n\n for (const field of hexFields) {\n const value = sanitized[field];\n if (value !== undefined && value !== null) {\n if (typeof value === 'string') {\n if (value === '0x' || value === '') {\n // Convert empty hex to 0x0 for numeric fields, 0x for data fields\n if (['callData', 'factoryData', 'paymasterData', 'signature'].includes(field)) {\n sanitized[field] = '0x';\n } else {\n sanitized[field] = '0x0';\n }\n } else if (field === 'sender' || field === 'factory' || field === 'paymaster') {\n // Address fields should have 0x prefix\n if (!value.startsWith('0x')) {\n sanitized[field] = `0x${value}`;\n }\n } else if (!value.startsWith('0x')) {\n sanitized[field] = `0x${value}`;\n }\n }\n }\n }\n\n // Remove undefined/null fields for v0.7\n Object.keys(sanitized).forEach(key => {\n if (sanitized[key] === undefined || sanitized[key] === null) {\n delete sanitized[key];\n }\n });\n\n // Ensure required fields exist with proper defaults\n if (!sanitized.callData) sanitized.callData = '0x';\n if (!sanitized.signature) sanitized.signature = '0x';\n\n return sanitized;\n}\n\n/**\n * Make RPC call to bundler\n * @param method - RPC method name\n * @param params - RPC method parameters\n * @param bundlerUrl - Bundler URL (will be fetched from config if not provided)\n */\nexport async function bundlerRpc(\n method: string,\n params: any[],\n bundlerUrl?: string\n): Promise<any> {\n // Sanitize UserOperation if this is eth_sendUserOperation\n let cleanParams = params;\n if (method === 'eth_sendUserOperation' && params[0]) {\n cleanParams = [sanitizeUserOperation(params[0]), params[1]];\n }\n\n const body = { jsonrpc: '2.0', id: 1, method, params: cleanParams };\n const bodyStr = JSON.stringify(body, (_k, v) => (typeof v === 'bigint' ? `0x${v.toString(16)}` : v));\n\n console.log('[Bundler][RPC] ->', method, bodyStr);\n\n // Get bundler URL: parameter > runtime config > build-time default > fallback\n const url = bundlerUrl || getBundlerUrl();\n\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: bodyStr\n });\n\n const json: any = await res.json();\n\n if (json.error) {\n console.log('[Bundler][RPC] <- ERROR:', JSON.stringify(json.error));\n const detail = json.error?.data ? ` | data: ${JSON.stringify(json.error.data)}` : '';\n throw new Error((json.error.message || JSON.stringify(json.error)) + detail);\n }\n\n console.log('[Bundler][RPC] <- SUCCESS:', JSON.stringify(json.result));\n return json.result;\n}\n","import { bundlerRpc, fetchEntryPointNonce } from '../utils/helpers';\nimport { ENTRYPOINT_V07, ENTRYPOINT_V06 } from './constants';\nimport type { UserOperationV07, UserOperationV06 } from './types';\n\nexport async function sendUserOperationRaw(userOp: UserOperationV07): Promise<`0x${string}`> {\n const hash = await bundlerRpc('eth_sendUserOperation', [userOp, ENTRYPOINT_V07]);\n return hash;\n}\n\nexport async function sendUserOperationV06Raw(userOp: UserOperationV06): Promise<`0x${string}`> {\n const hash = await bundlerRpc('eth_sendUserOperation', [userOp, ENTRYPOINT_V06]);\n return hash;\n}\n\nexport async function sendUserOperationWithRetry(\n userOp: UserOperationV07,\n resigner: (nonce: `0x${string}`) => Promise<UserOperationV07>,\n maxRetries: number = 1\n): Promise<`0x${string}`> {\n let attempts = 0; let currentUserOp = userOp;\n while (attempts < maxRetries) {\n try { return await sendUserOperationRaw(currentUserOp); }\n catch (error: any) { attempts++; const errorMsg = String(error?.message || error); if (attempts >= maxRetries) throw error; if (/nonce too low|nonce.*invalid/i.test(errorMsg)) { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V07); currentUserOp = await resigner(newNonce); } else if (/replacement.*underpriced/i.test(errorMsg)) { const increasedMaxFeePerGas = `0x${((BigInt(currentUserOp.maxFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; const increasedMaxPriorityFeePerGas = `0x${((BigInt(currentUserOp.maxPriorityFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; currentUserOp = { ...currentUserOp, maxFeePerGas: increasedMaxFeePerGas, maxPriorityFeePerGas: increasedMaxPriorityFeePerGas }; currentUserOp = await resigner(currentUserOp.nonce); } else { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V07); currentUserOp = await resigner(newNonce); } await new Promise(r => setTimeout(r, 1000 * attempts)); }\n }\n throw new Error(`Failed to send UserOperation v0.7 after ${maxRetries} attempts`);\n}\n\nexport async function sendUserOperationV06WithRetry(\n userOp: UserOperationV06,\n resigner: (nonce: `0x${string}`) => Promise<UserOperationV06>,\n maxRetries: number = 1\n): Promise<`0x${string}`> {\n let attempts = 0; let currentUserOp = userOp;\n while (attempts < maxRetries) {\n try { return await sendUserOperationV06Raw(currentUserOp); }\n catch (error: any) { attempts++; const errorMsg = String(error?.message || error); if (attempts >= maxRetries) throw error; if (/nonce too low|nonce.*invalid/i.test(errorMsg)) { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V06); currentUserOp = await resigner(newNonce); } else if (/replacement.*underpriced/i.test(errorMsg)) { const increasedMaxFeePerGas = `0x${((BigInt(currentUserOp.maxFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; const increasedMaxPriorityFeePerGas = `0x${((BigInt(currentUserOp.maxPriorityFeePerGas) * 110n) / 100n).toString(16)}` as `0x${string}`; currentUserOp = { ...currentUserOp, maxFeePerGas: increasedMaxFeePerGas, maxPriorityFeePerGas: increasedMaxPriorityFeePerGas }; currentUserOp = await resigner(currentUserOp.nonce); } else { const newNonce = await fetchEntryPointNonce(userOp.sender, ENTRYPOINT_V06); currentUserOp = await resigner(newNonce); } await new Promise(r => setTimeout(r, 1000 * attempts)); }\n }\n throw new Error(`Failed to send UserOperation v0.6 after ${maxRetries} attempts`);\n}\n\nexport async function getUserOperationReceipt(userOpHash: `0x${string}`): Promise<any> {\n const receipt = await bundlerRpc('eth_getUserOperationReceipt', [userOpHash]);\n return receipt;\n}\n","/**\n * Provider for viem PublicClient\n * Allows fee-calculation and other modules to access the configured client\n */\n\n// Using 'any' type to avoid direct viem dependency in this file\n// Actual type should be PublicClient from viem\nlet globalPublicClient: any | null = null;\n\n/**\n * Set the global public client for blockchain interactions\n * Should be called during initialization with a viem PublicClient\n */\nexport function setPublicClient(client: any): void {\n globalPublicClient = client;\n}\n\n/**\n * Get the configured public client\n * Throws if not configured\n */\nexport function getPublicClient(): any {\n if (!globalPublicClient) {\n throw new Error(\n '[LumiaPassport] PublicClient not configured. Please provide a publicClient in config ' +\n 'or call setPublicClient() before using fee calculation functions.'\n );\n }\n return globalPublicClient;\n}\n\n/**\n * Check if public client is configured\n */\nexport function hasPublicClient(): boolean {\n return globalPublicClient !== null;\n}\n","/**\n * Universal environment variable access that works in both browser and Node.js\n */\n\ninterface EnvVars {\n [key: string]: string | undefined;\n}\n\n/**\n * Get environment variables from various sources\n * Priority: 1. window.__LUMIA_ENV__ (browser), 2. import.meta.env (Vite), 3. process.env (Node.js)\n */\nfunction getEnvironmentVars(): EnvVars {\n // Try browser environment first (injected by LumiaPassportProvider)\n // @ts-ignore - accessing global window object\n const win = typeof globalThis !== 'undefined' && (globalThis as any).window;\n if (win && win.__LUMIA_ENV__) {\n return win.__LUMIA_ENV__;\n }\n\n // Try import.meta.env (ESM/Vite)\n try {\n // @ts-ignore - import.meta may not be available in all environments\n if (import.meta?.env) {\n // @ts-ignore\n return import.meta.env as EnvVars;\n }\n } catch {\n // import.meta not available in this environment\n }\n\n // Try process.env (Node.js/CJS)\n if (typeof process !== 'undefined' && process.env) {\n return process.env;\n }\n\n // Fallback to empty object\n return {};\n}\n\n/**\n * Get a single environment variable\n * @param name - The environment variable name\n * @returns The environment variable value or undefined\n */\nexport function getEnvVar(name: string): string | undefined {\n const env = getEnvironmentVars();\n return env[name];\n}\n\n/**\n * Get an environment variable as boolean\n * @param name - The environment variable name\n * @returns true if value is 'true' or '1', false otherwise\n */\nexport function getEnvVarBool(name: string): boolean {\n const value = getEnvVar(name);\n return value === 'true' || value === '1';\n}\n\n/**\n * Get an environment variable as array\n * @param name - The environment variable name\n * @param separator - Separator character (default: ',')\n * @returns Array of trimmed non-empty strings\n */\nexport function getEnvVarArray(name: string, separator = ','): string[] {\n const value = getEnvVar(name);\n return value ? value.split(separator).map(s => s.trim()).filter(Boolean) : [];\n}\n\n/**\n * Get all environment variables\n * @returns Object containing all environment variables\n */\nexport function getAllEnvVars(): EnvVars {\n return getEnvironmentVars();\n}\n\n/**\n * Check if running in development mode\n * @returns true if NODE_ENV or MODE is 'development'\n */\nexport function isDevelopment(): boolean {\n const env = getEnvironmentVars();\n return env.NODE_ENV === 'development' || env.MODE === 'development';\n}\n\n/**\n * Check if running in production mode\n * @returns true if NODE_ENV or MODE is 'production'\n */\nexport function isProduction(): boolean {\n const env = getEnvironmentVars();\n return env.NODE_ENV === 'production' || env.MODE === 'production';\n}\n","import { bundlerRpc } from '../utils/helpers';\nimport { getPublicClient } from './client-provider';\nimport { getEnvVar, getEnvVarBool } from '../utils/env';\n\nexport interface FeeConfig {\n baseFeeBuffer: number;\n priorityFeeBuffer: number;\n fallbackMaxFeePerGas?: bigint;\n fallbackMaxPriorityFeePerGas?: bigint;\n}\n\nexport interface CalculatedFees {\n maxFeePerGas: `0x${string}`;\n maxPriorityFeePerGas: `0x${string}`;\n baseFee?: bigint;\n priorityFee?: bigint;\n bufferedBaseFee?: bigint;\n bufferedPriorityFee?: bigint;\n}\n\n// Hardcoded fallback values (used when env vars not set and network calls fail)\nconst HARDCODED_FALLBACK_MAX_FEE = 3_000_000_000n; // 3 gwei\nconst HARDCODED_FALLBACK_PRIORITY_FEE = 3_000_000_000n; // 3 gwei\n\n/**\n * Get minimum maxFeePerGas from environment or use hardcoded fallback\n * Env vars: MIN_MAX_FEE_PER_GAS or VITE_MIN_MAX_FEE_PER_GAS (in wei)\n */\nexport function getMinMaxFeePerGas(): bigint {\n const envValue = getEnvVar('MIN_MAX_FEE_PER_GAS') || getEnvVar('VITE_MIN_MAX_FEE_PER_GAS');\n if (envValue) {\n try {\n return BigInt(envValue);\n } catch {\n console.warn('[Fees] Invalid MIN_MAX_FEE_PER_GAS value:', envValue);\n }\n }\n return HARDCODED_FALLBACK_MAX_FEE;\n}\n\n/**\n * Get minimum maxPriorityFeePerGas from environment or use hardcoded fallback\n * Env vars: MIN_PRIORITY_FEE_PER_GAS or VITE_MIN_PRIORITY_FEE_PER_GAS (in wei)\n */\nexport function getMinPriorityFeePerGas(): bigint {\n const envValue = getEnvVar('MIN_PRIORITY_FEE_PER_GAS') || getEnvVar('VITE_MIN_PRIORITY_FEE_PER_GAS');\n if (envValue) {\n try {\n return BigInt(envValue);\n } catch {\n console.warn('[Fees] Invalid MIN_PRIORITY_FEE_PER_GAS value:', envValue);\n }\n }\n return HARDCODED_FALLBACK_PRIORITY_FEE;\n}\n\n/**\n * Get default maxFeePerGas as hex string (for dummy user operations)\n */\nexport function getDefaultMaxFeePerGasHex(): `0x${string}` {\n return `0x${getMinMaxFeePerGas().toString(16)}`;\n}\n\n/**\n * Get default maxPriorityFeePerGas as hex string (for dummy user operations)\n */\nexport function getDefaultPriorityFeePerGasHex(): `0x${string}` {\n return `0x${getMinPriorityFeePerGas().toString(16)}`;\n}\n\nexport const DEFAULT_FEE_CONFIG: FeeConfig = { baseFeeBuffer: 0.5, priorityFeeBuffer: 0.05, fallbackMaxFeePerGas: HARDCODED_FALLBACK_MAX_FEE, fallbackMaxPriorityFeePerGas: HARDCODED_FALLBACK_PRIORITY_FEE };\nexport const CONSERVATIVE_FEE_CONFIG: FeeConfig = { baseFeeBuffer: 1.0, priorityFeeBuffer: 0.25, fallbackMaxFeePerGas: 5_000_000_000n, fallbackMaxPriorityFeePerGas: 3_000_000_000n };\n\n/**\n * Check if the current chain requires legacy gas pricing to avoid BASEFEE opcode errors\n */\nfunction shouldUseLegacyGasForChain(): boolean {\n try {\n // Get environment variable for legacy chain IDs (comma-separated list)\n const legacyChainIds = getEnvVar('VITE_LEGACY_GAS_CHAIN_IDS') || getEnvVar('LEGACY_GAS_CHAIN_IDS') || '';\n\n console.log('[Fees] Environment check:', {\n LEGACY_GAS_CHAIN_IDS: legacyChainIds,\n });\n\n // Default to Lumia Beam testnet if no env var is set\n const defaultLegacyChains = '2030232745'; // Lumia Beam testnet\n const chainIdsString = legacyChainIds || defaultLegacyChains;\n\n // Parse chain IDs\n const legacyChains = chainIdsString.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id));\n\n // Get current chain ID from public client\n const publicClient = getPublicClient();\n const currentChainId = publicClient?.chain?.id;\n\n if (!currentChainId) return false;\n\n const shouldUseLegacy = legacyChains.includes(currentChainId);\n\n if (shouldUseLegacy) {\n console.log('[Fees] Chain requires legacy gas pricing:', {\n chainId: currentChainId,\n legacyChains,\n configuredVia: legacyChainIds ? 'LEGACY_GAS_CHAIN_IDS env var' : 'default'\n });\n }\n\n return shouldUseLegacy;\n } catch (error) {\n console.warn('[Fees] Error checking legacy gas chain configuration:', error);\n return false;\n }\n}\n\nexport async function getCurrentBaseFee(): Promise<bigint> {\n const publicClient = getPublicClient();\n const block = await publicClient.getBlock({ blockTag: 'latest' });\n if (block.baseFeePerGas) return block.baseFeePerGas;\n const gasPriceHex = await publicClient.getGasPrice(); const gasPrice = BigInt(gasPriceHex);\n const estimatedBaseFee = (gasPrice * 9n) / 10n; return estimatedBaseFee;\n}\n\nexport async function getCurrentPriorityFee(): Promise<bigint> {\n try { const priorityFeeHex = await bundlerRpc('rundler_maxPriorityFeePerGas', []); const priorityFee = BigInt(priorityFeeHex); if (priorityFee === 0n) return await getFallbackPriorityFee(); return priorityFee; } catch { return await getFallbackPriorityFee(); }\n}\n\nasync function getFallbackPriorityFee(): Promise<bigint> {\n try { const publicClient = getPublicClient(); const gasPriceHex = await publicClient.getGasPrice(); const gasPrice = BigInt(gasPriceHex); return gasPrice / 10n; } catch { return 100_000_000n; }\n}\n\nexport async function calculateLegacyFees(gasPrice?: bigint): Promise<CalculatedFees> {\n const minMaxFee = getMinMaxFeePerGas();\n const minPriorityFee = getMinPriorityFeePerGas();\n\n try {\n let legacyGasPrice: bigint;\n\n if (gasPrice) {\n legacyGasPrice = gasPrice;\n } else {\n // Get current gas price from network\n const publicClient = getPublicClient();\n const gasPriceHex = await publicClient.getGasPrice();\n legacyGasPrice = BigInt(gasPriceHex);\n }\n\n // Enforce minimum fee\n const effectiveGasPrice = legacyGasPrice < minMaxFee ? minMaxFee : legacyGasPrice;\n\n // For legacy chains, set both maxFeePerGas and maxPriorityFeePerGas to the same value\n // This prevents BASEFEE opcode usage\n const result: CalculatedFees = {\n maxFeePerGas: `0x${effectiveGasPrice.toString(16)}`,\n maxPriorityFeePerGas: `0x${effectiveGasPrice.toString(16)}`,\n };\n\n console.log('[Fees] Using legacy gas pricing (avoid BASEFEE opcode):', {\n gasPrice: legacyGasPrice.toString(),\n minFee: minMaxFee.toString(),\n effectiveGasPrice: effectiveGasPrice.toString(),\n maxFeePerGas: result.maxFeePerGas,\n maxPriorityFeePerGas: result.maxPriorityFeePerGas,\n });\n\n return result;\n } catch (error) {\n console.warn('[Fees] Legacy fee calculation failed, using min fee fallback:', error);\n return {\n maxFeePerGas: `0x${minMaxFee.toString(16)}`,\n maxPriorityFeePerGas: `0x${minPriorityFee.toString(16)}`,\n };\n }\n}\n\nexport async function calculateDynamicFees(config: FeeConfig = DEFAULT_FEE_CONFIG): Promise<CalculatedFees> {\n const minMaxFee = getMinMaxFeePerGas();\n const minPriorityFee = getMinPriorityFeePerGas();\n\n try {\n // Check environment variable for forced legacy mode\n const forceLegacy = getEnvVarBool('VITE_FORCE_LEGACY_GAS') || getEnvVarBool('FORCE_LEGACY_GAS');\n\n // Check if current chain should use legacy gas pricing\n const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();\n\n if (shouldUseLegacy) {\n console.log('[Fees] Using legacy gas pricing', forceLegacy ? '(forced by FORCE_LEGACY_GAS env var)' : '(chain requires legacy gas)');\n return await calculateLegacyFees();\n }\n const baseFee = await getCurrentBaseFee();\n const bufferedBaseFee = baseFee + (baseFee * BigInt(Math.floor(config.baseFeeBuffer * 1000))) / 1000n;\n const priorityFee = await getCurrentPriorityFee();\n const bufferedPriorityFee = priorityFee + (priorityFee * BigInt(Math.floor(config.priorityFeeBuffer * 1000))) / 1000n;\n\n // Calculate fees\n let maxFeePerGas = bufferedBaseFee + bufferedPriorityFee;\n let maxPriorityFeePerGas = bufferedPriorityFee;\n\n // Enforce minimum fees\n if (maxFeePerGas < minMaxFee) {\n console.log('[Fees] Calculated maxFeePerGas below minimum, using minimum:', { calculated: maxFeePerGas.toString(), min: minMaxFee.toString() });\n maxFeePerGas = minMaxFee;\n }\n if (maxPriorityFeePerGas < minPriorityFee) {\n console.log('[Fees] Calculated maxPriorityFeePerGas below minimum, using minimum:', { calculated: maxPriorityFeePerGas.toString(), min: minPriorityFee.toString() });\n maxPriorityFeePerGas = minPriorityFee;\n }\n\n return { maxFeePerGas: `0x${maxFeePerGas.toString(16)}`, maxPriorityFeePerGas: `0x${maxPriorityFeePerGas.toString(16)}`, baseFee, priorityFee, bufferedBaseFee, bufferedPriorityFee };\n } catch { return await calculateLegacyFees(); }\n}\n\nexport async function calculateFastFees(): Promise<CalculatedFees> {\n const forceLegacy = getEnvVarBool('VITE_FORCE_LEGACY_GAS') || getEnvVarBool('FORCE_LEGACY_GAS');\n const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();\n\n if (shouldUseLegacy) return await calculateLegacyFees(3_000_000_000n);\n return calculateDynamicFees({ baseFeeBuffer: 0.75, priorityFeeBuffer: 0.5, fallbackMaxFeePerGas: 3_000_000_000n, fallbackMaxPriorityFeePerGas: 2_000_000_000n });\n}\n\nexport async function calculateEconomyFees(): Promise<CalculatedFees> {\n const forceLegacy = getEnvVarBool('VITE_FORCE_LEGACY_GAS') || getEnvVarBool('FORCE_LEGACY_GAS');\n const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();\n\n if (shouldUseLegacy) return await calculateLegacyFees(500_000_000n);\n return calculateDynamicFees({ baseFeeBuffer: 0.27, priorityFeeBuffer: 0.01, fallbackMaxFeePerGas: 1_000_000_000n, fallbackMaxPriorityFeePerGas: 500_000_000n });\n}\n\nexport async function getFeeEstimates(): Promise<{ economy: CalculatedFees; standard: CalculatedFees; fast: CalculatedFees; }> {\n const [economy, standard, fast] = await Promise.all([ calculateEconomyFees(), calculateDynamicFees(), calculateFastFees() ]);\n return { economy, standard, fast };\n}\n","import { pack2x128, safeToBigInt } from '../utils/helpers';\nimport { calculateDynamicFees, calculateEconomyFees, calculateFastFees, getDefaultMaxFeePerGasHex, getDefaultPriorityFeePerGasHex } from './fee-calculation';\nimport type { UserOperationV07, UserOperationV06, PackedUserOperationV07 } from './types';\n\nexport const DUMMY_SIGNATURE = `0x${'00'.repeat(65)}` as `0x${string}`;\n\nexport function packUserOperationV07(\n userOp: UserOperationV07,\n includeFactory: boolean,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`\n): PackedUserOperationV07 {\n const initCode = includeFactory && factoryAddress && factoryData ? (((factoryAddress as string) + (factoryData as string).slice(2)) as `0x${string}`) : ('0x' as `0x${string}`);\n const accountGasLimits = pack2x128(safeToBigInt(userOp.verificationGasLimit, '0x1e8480'), safeToBigInt(userOp.callGasLimit, '0x0f4240'));\n const defaultMaxFee = getDefaultMaxFeePerGasHex();\n const defaultPriorityFee = getDefaultPriorityFeePerGasHex();\n const gasFees = pack2x128(safeToBigInt(userOp.maxPriorityFeePerGas, defaultPriorityFee), safeToBigInt(userOp.maxFeePerGas, defaultMaxFee));\n\n // Create paymasterAndData from paymaster and paymasterData fields (V07 format)\n let paymasterAndData: `0x${string}` = '0x';\n if (userOp.paymaster && userOp.paymaster !== '0x') {\n const paymasterAddr = userOp.paymaster.startsWith('0x') ? userOp.paymaster.slice(2) : userOp.paymaster;\n const paymasterData = userOp.paymasterData ? (userOp.paymasterData.startsWith('0x') ? userOp.paymasterData.slice(2) : userOp.paymasterData) : '';\n paymasterAndData = `0x${paymasterAddr}${paymasterData}` as `0x${string}`;\n }\n\n return { sender: userOp.sender, nonce: BigInt(userOp.nonce), initCode, callData: userOp.callData, accountGasLimits, preVerificationGas: safeToBigInt(userOp.preVerificationGas, '0x1d4c0'), gasFees, paymasterAndData, signature: userOp.signature };\n}\n\nexport function createDummyUserOperation(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n customMaxFeePerGas?: `0x${string}`,\n customMaxPriorityFeePerGas?: `0x${string}`\n): UserOperationV07 {\n const userOp: UserOperationV07 = {\n sender,\n nonce,\n callData,\n callGasLimit: '0x1E8480', // 2,000,000 (for factory contracts with CREATE)\n verificationGasLimit: '0x4C4B40', // 5,000,000 (bundler max limit)\n preVerificationGas: '0x30d40', // 200,000\n maxFeePerGas: customMaxFeePerGas || getDefaultMaxFeePerGasHex(),\n maxPriorityFeePerGas: customMaxPriorityFeePerGas || getDefaultPriorityFeePerGasHex(),\n signature: DUMMY_SIGNATURE,\n };\n if (includeFactory && factoryAddress && factoryData) { userOp.factory = factoryAddress; userOp.factoryData = factoryData; }\n return userOp;\n}\n\nexport function createDummyUserOperationV06(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n customMaxFeePerGas?: `0x${string}`,\n customMaxPriorityFeePerGas?: `0x${string}`\n): UserOperationV06 {\n let initCode: `0x${string}` = '0x';\n if (includeFactory && factoryAddress && factoryData) {\n const factoryAddrClean = factoryAddress.startsWith('0x') ? factoryAddress.slice(2) : factoryAddress;\n const factoryDataClean = factoryData.startsWith('0x') ? factoryData.slice(2) : factoryData;\n initCode = `0x${factoryAddrClean}${factoryDataClean}` as `0x${string}`;\n }\n return { sender, nonce, initCode, callData, callGasLimit: '0x1E8480', verificationGasLimit: '0x4C4B40', preVerificationGas: '0x30d40', maxFeePerGas: customMaxFeePerGas || getDefaultMaxFeePerGasHex(), maxPriorityFeePerGas: customMaxPriorityFeePerGas || getDefaultPriorityFeePerGasHex(), paymasterAndData: '0x', signature: DUMMY_SIGNATURE };\n}\n\nexport async function createUserOperationWithDynamicFees(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n feeType: 'economy' | 'standard' | 'fast' = 'standard'\n): Promise<UserOperationV07> {\n let fees;\n switch (feeType) {\n case 'economy': fees = await calculateEconomyFees(); break;\n case 'fast': fees = await calculateFastFees(); break;\n default: fees = await calculateDynamicFees();\n }\n return createDummyUserOperation(sender, nonce, callData, includeFactory, factoryAddress, factoryData, fees.maxFeePerGas, fees.maxPriorityFeePerGas);\n}\n\nexport async function createUserOperationV06WithDynamicFees(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n feeType: 'economy' | 'standard' | 'fast' = 'standard'\n): Promise<UserOperationV06> {\n let fees;\n switch (feeType) {\n case 'economy': fees = await calculateEconomyFees(); break;\n case 'fast': fees = await calculateFastFees(); break;\n default: fees = await calculateDynamicFees();\n }\n return createDummyUserOperationV06(sender, nonce, callData, includeFactory, factoryAddress, factoryData, fees.maxFeePerGas, fees.maxPriorityFeePerGas);\n}\n","import { bundlerRpc } from '../utils/helpers';\nimport { ENTRYPOINT_V07 } from './constants';\nimport type { UserOperationV07, GasEstimationResult } from './types';\nimport { DUMMY_SIGNATURE, createUserOperationWithDynamicFees } from './utils';\n\nexport async function estimateUserOperationGas(userOp: UserOperationV07, retryWithoutFactory: boolean = true): Promise<GasEstimationResult> {\n try {\n const gas = await bundlerRpc('eth_estimateUserOperationGas', [userOp, ENTRYPOINT_V07]);\n return gas;\n } catch (error) {\n // Retry without factory if account is already deployed\n if (retryWithoutFactory && (userOp.factory || userOp.factoryData)) {\n const errorMsg = String(error);\n if (/AA10 sender already constructed/i.test(errorMsg) || /sender.*is an existing contract.*but initCode is nonempty/i.test(errorMsg)) {\n const userOpWithoutFactory: UserOperationV07 = { ...userOp };\n delete userOpWithoutFactory.factory;\n delete userOpWithoutFactory.factoryData;\n try {\n const gas = await bundlerRpc('eth_estimateUserOperationGas', [userOpWithoutFactory, ENTRYPOINT_V07]);\n return gas;\n } catch {}\n }\n }\n\n // Fallback to conservative gas estimates\n const isEmptyCallData = !userOp.callData || userOp.callData === '0x';\n // Increased to 2M to handle deep call chains (5+ levels) and contract deployments\n // With 63/64 rule at depth 5, only ~92% reaches the operation\n // Factory contracts like createERC3643 can use 1.6M+ gas with CREATE opcodes\n const minimalCallGas = isEmptyCallData ? '0x0' : '0x1E8480'; // 2,000,000 for non-empty calls\n return { callGasLimit: minimalCallGas, verificationGasLimit: '0x4C4B40', preVerificationGas: '0x30d40' }; // 5,000,000 (bundler max)\n }\n}\n\nexport async function estimateUserOperationGasWithSignature(\n userOp: UserOperationV07,\n _getSignature: (opHash: `0x${string}`) => Promise<`0x${string}` | null>,\n _getUserOpHash: (packedOp: any) => Promise<`0x${string}`>,\n retryWithoutFactory: boolean = true\n): Promise<GasEstimationResult> { const userOpForEstimation: UserOperationV07 = { ...userOp, signature: DUMMY_SIGNATURE }; return estimateUserOperationGas(userOpForEstimation, retryWithoutFactory); }\n\nexport async function estimateUserOperationGasWithDynamicFees(\n sender: `0x${string}`,\n nonce: `0x${string}`,\n callData: `0x${string}`,\n includeFactory: boolean = false,\n factoryAddress?: `0x${string}`,\n factoryData?: `0x${string}`,\n feeType: 'economy' | 'standard' | 'fast' = 'standard',\n retryWithoutFactory: boolean = true\n): Promise<GasEstimationResult & { calculatedFees?: any }> {\n const userOp = await createUserOperationWithDynamicFees(sender, nonce, callData, includeFactory, factoryAddress, factoryData, feeType);\n const gasResult = await estimateUserOperationGas(userOp, retryWithoutFactory);\n return { ...gasResult, calculatedFees: { maxFeePerGas: userOp.maxFeePerGas, maxPriorityFeePerGas: userOp.maxPriorityFeePerGas, feeType } };\n}\n","import { bundlerRpc } from '../utils/helpers';\nimport { ENTRYPOINT_V07 } from './constants';\nimport type { UserOperationV07, SimulationResult } from './types';\n\n/**\n * Simulate a UserOperation using Lumia's lumia_simulateUserOperation method\n * Returns asset changes that would occur if the operation is executed\n *\n * @param userOp - The UserOperation to simulate\n * @returns Simulation result with asset changes\n */\nexport async function simulateUserOperation(userOp: UserOperationV07): Promise<SimulationResult> {\n try {\n const result = await bundlerRpc('lumia_simulateUserOperation', [userOp, ENTRYPOINT_V07]);\n return result;\n } catch (error) {\n // If simulation fails, return error in the expected format\n const errorMsg = error instanceof Error ? error.message : String(error);\n return {\n changes: [],\n error: {\n message: errorMsg,\n code: -1\n }\n };\n }\n}\n\n/**\n * Validate a UserOperation by simulating it\n * Returns true if simulation succeeds without errors\n */\nexport async function validateUserOperation(userOp: UserOperationV07): Promise<{ valid: boolean; error?: string }> {\n try {\n const result = await simulateUserOperation(userOp);\n if (result.error) {\n return { valid: false, error: result.error.message };\n }\n return { valid: true };\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error);\n return { valid: false, error: errorMsg };\n }\n}\n"]}
|
package/dist/bundler/index.js
CHANGED
|
@@ -224,8 +224,38 @@ function getEnvVarBool(name) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
// src/bundler/fee-calculation.ts
|
|
227
|
-
var
|
|
228
|
-
var
|
|
227
|
+
var HARDCODED_FALLBACK_MAX_FEE = 3000000000n;
|
|
228
|
+
var HARDCODED_FALLBACK_PRIORITY_FEE = 3000000000n;
|
|
229
|
+
function getMinMaxFeePerGas() {
|
|
230
|
+
const envValue = getEnvVar("MIN_MAX_FEE_PER_GAS") || getEnvVar("VITE_MIN_MAX_FEE_PER_GAS");
|
|
231
|
+
if (envValue) {
|
|
232
|
+
try {
|
|
233
|
+
return BigInt(envValue);
|
|
234
|
+
} catch {
|
|
235
|
+
console.warn("[Fees] Invalid MIN_MAX_FEE_PER_GAS value:", envValue);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return HARDCODED_FALLBACK_MAX_FEE;
|
|
239
|
+
}
|
|
240
|
+
function getMinPriorityFeePerGas() {
|
|
241
|
+
const envValue = getEnvVar("MIN_PRIORITY_FEE_PER_GAS") || getEnvVar("VITE_MIN_PRIORITY_FEE_PER_GAS");
|
|
242
|
+
if (envValue) {
|
|
243
|
+
try {
|
|
244
|
+
return BigInt(envValue);
|
|
245
|
+
} catch {
|
|
246
|
+
console.warn("[Fees] Invalid MIN_PRIORITY_FEE_PER_GAS value:", envValue);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return HARDCODED_FALLBACK_PRIORITY_FEE;
|
|
250
|
+
}
|
|
251
|
+
function getDefaultMaxFeePerGasHex() {
|
|
252
|
+
return `0x${getMinMaxFeePerGas().toString(16)}`;
|
|
253
|
+
}
|
|
254
|
+
function getDefaultPriorityFeePerGasHex() {
|
|
255
|
+
return `0x${getMinPriorityFeePerGas().toString(16)}`;
|
|
256
|
+
}
|
|
257
|
+
var DEFAULT_FEE_CONFIG = { baseFeeBuffer: 0.5, priorityFeeBuffer: 0.05, fallbackMaxFeePerGas: HARDCODED_FALLBACK_MAX_FEE, fallbackMaxPriorityFeePerGas: HARDCODED_FALLBACK_PRIORITY_FEE };
|
|
258
|
+
var CONSERVATIVE_FEE_CONFIG = { baseFeeBuffer: 1, priorityFeeBuffer: 0.25, fallbackMaxFeePerGas: 5000000000n, fallbackMaxPriorityFeePerGas: 3000000000n };
|
|
229
259
|
function shouldUseLegacyGasForChain() {
|
|
230
260
|
try {
|
|
231
261
|
const legacyChainIds = getEnvVar("VITE_LEGACY_GAS_CHAIN_IDS") || getEnvVar("LEGACY_GAS_CHAIN_IDS") || "";
|
|
@@ -282,6 +312,8 @@ async function getFallbackPriorityFee() {
|
|
|
282
312
|
}
|
|
283
313
|
}
|
|
284
314
|
async function calculateLegacyFees(gasPrice) {
|
|
315
|
+
const minMaxFee = getMinMaxFeePerGas();
|
|
316
|
+
const minPriorityFee = getMinPriorityFeePerGas();
|
|
285
317
|
try {
|
|
286
318
|
let legacyGasPrice;
|
|
287
319
|
if (gasPrice) {
|
|
@@ -291,26 +323,30 @@ async function calculateLegacyFees(gasPrice) {
|
|
|
291
323
|
const gasPriceHex = await publicClient.getGasPrice();
|
|
292
324
|
legacyGasPrice = BigInt(gasPriceHex);
|
|
293
325
|
}
|
|
326
|
+
const effectiveGasPrice = legacyGasPrice < minMaxFee ? minMaxFee : legacyGasPrice;
|
|
294
327
|
const result = {
|
|
295
|
-
maxFeePerGas: `0x${
|
|
296
|
-
maxPriorityFeePerGas: `0x${
|
|
328
|
+
maxFeePerGas: `0x${effectiveGasPrice.toString(16)}`,
|
|
329
|
+
maxPriorityFeePerGas: `0x${effectiveGasPrice.toString(16)}`
|
|
297
330
|
};
|
|
298
331
|
console.log("[Fees] Using legacy gas pricing (avoid BASEFEE opcode):", {
|
|
299
332
|
gasPrice: legacyGasPrice.toString(),
|
|
333
|
+
minFee: minMaxFee.toString(),
|
|
334
|
+
effectiveGasPrice: effectiveGasPrice.toString(),
|
|
300
335
|
maxFeePerGas: result.maxFeePerGas,
|
|
301
336
|
maxPriorityFeePerGas: result.maxPriorityFeePerGas
|
|
302
337
|
});
|
|
303
338
|
return result;
|
|
304
339
|
} catch (error) {
|
|
305
|
-
console.warn("[Fees] Legacy fee calculation failed, using
|
|
306
|
-
const fallbackGasPrice = 1000000000n;
|
|
340
|
+
console.warn("[Fees] Legacy fee calculation failed, using min fee fallback:", error);
|
|
307
341
|
return {
|
|
308
|
-
maxFeePerGas: `0x${
|
|
309
|
-
maxPriorityFeePerGas: `0x${
|
|
342
|
+
maxFeePerGas: `0x${minMaxFee.toString(16)}`,
|
|
343
|
+
maxPriorityFeePerGas: `0x${minPriorityFee.toString(16)}`
|
|
310
344
|
};
|
|
311
345
|
}
|
|
312
346
|
}
|
|
313
347
|
async function calculateDynamicFees(config = DEFAULT_FEE_CONFIG) {
|
|
348
|
+
const minMaxFee = getMinMaxFeePerGas();
|
|
349
|
+
const minPriorityFee = getMinPriorityFeePerGas();
|
|
314
350
|
try {
|
|
315
351
|
const forceLegacy = getEnvVarBool("VITE_FORCE_LEGACY_GAS") || getEnvVarBool("FORCE_LEGACY_GAS");
|
|
316
352
|
const shouldUseLegacy = forceLegacy || shouldUseLegacyGasForChain();
|
|
@@ -322,8 +358,16 @@ async function calculateDynamicFees(config = DEFAULT_FEE_CONFIG) {
|
|
|
322
358
|
const bufferedBaseFee = baseFee + baseFee * BigInt(Math.floor(config.baseFeeBuffer * 1e3)) / 1000n;
|
|
323
359
|
const priorityFee = await getCurrentPriorityFee();
|
|
324
360
|
const bufferedPriorityFee = priorityFee + priorityFee * BigInt(Math.floor(config.priorityFeeBuffer * 1e3)) / 1000n;
|
|
325
|
-
|
|
326
|
-
|
|
361
|
+
let maxFeePerGas = bufferedBaseFee + bufferedPriorityFee;
|
|
362
|
+
let maxPriorityFeePerGas = bufferedPriorityFee;
|
|
363
|
+
if (maxFeePerGas < minMaxFee) {
|
|
364
|
+
console.log("[Fees] Calculated maxFeePerGas below minimum, using minimum:", { calculated: maxFeePerGas.toString(), min: minMaxFee.toString() });
|
|
365
|
+
maxFeePerGas = minMaxFee;
|
|
366
|
+
}
|
|
367
|
+
if (maxPriorityFeePerGas < minPriorityFee) {
|
|
368
|
+
console.log("[Fees] Calculated maxPriorityFeePerGas below minimum, using minimum:", { calculated: maxPriorityFeePerGas.toString(), min: minPriorityFee.toString() });
|
|
369
|
+
maxPriorityFeePerGas = minPriorityFee;
|
|
370
|
+
}
|
|
327
371
|
return { maxFeePerGas: `0x${maxFeePerGas.toString(16)}`, maxPriorityFeePerGas: `0x${maxPriorityFeePerGas.toString(16)}`, baseFee, priorityFee, bufferedBaseFee, bufferedPriorityFee };
|
|
328
372
|
} catch {
|
|
329
373
|
return await calculateLegacyFees();
|
|
@@ -351,7 +395,9 @@ var DUMMY_SIGNATURE = `0x${"00".repeat(65)}`;
|
|
|
351
395
|
function packUserOperationV07(userOp, includeFactory, factoryAddress, factoryData) {
|
|
352
396
|
const initCode = includeFactory && factoryAddress && factoryData ? factoryAddress + factoryData.slice(2) : "0x";
|
|
353
397
|
const accountGasLimits = pack2x128(safeToBigInt(userOp.verificationGasLimit, "0x1e8480"), safeToBigInt(userOp.callGasLimit, "0x0f4240"));
|
|
354
|
-
const
|
|
398
|
+
const defaultMaxFee = getDefaultMaxFeePerGasHex();
|
|
399
|
+
const defaultPriorityFee = getDefaultPriorityFeePerGasHex();
|
|
400
|
+
const gasFees = pack2x128(safeToBigInt(userOp.maxPriorityFeePerGas, defaultPriorityFee), safeToBigInt(userOp.maxFeePerGas, defaultMaxFee));
|
|
355
401
|
let paymasterAndData = "0x";
|
|
356
402
|
if (userOp.paymaster && userOp.paymaster !== "0x") {
|
|
357
403
|
const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
|
|
@@ -371,8 +417,8 @@ function createDummyUserOperation(sender, nonce, callData, includeFactory = fals
|
|
|
371
417
|
// 5,000,000 (bundler max limit)
|
|
372
418
|
preVerificationGas: "0x30d40",
|
|
373
419
|
// 200,000
|
|
374
|
-
maxFeePerGas: customMaxFeePerGas ||
|
|
375
|
-
maxPriorityFeePerGas: customMaxPriorityFeePerGas ||
|
|
420
|
+
maxFeePerGas: customMaxFeePerGas || getDefaultMaxFeePerGasHex(),
|
|
421
|
+
maxPriorityFeePerGas: customMaxPriorityFeePerGas || getDefaultPriorityFeePerGasHex(),
|
|
376
422
|
signature: DUMMY_SIGNATURE
|
|
377
423
|
};
|
|
378
424
|
if (includeFactory && factoryAddress && factoryData) {
|
|
@@ -388,7 +434,7 @@ function createDummyUserOperationV06(sender, nonce, callData, includeFactory = f
|
|
|
388
434
|
const factoryDataClean = factoryData.startsWith("0x") ? factoryData.slice(2) : factoryData;
|
|
389
435
|
initCode = `0x${factoryAddrClean}${factoryDataClean}`;
|
|
390
436
|
}
|
|
391
|
-
return { sender, nonce, initCode, callData, callGasLimit: "0x1E8480", verificationGasLimit: "0x4C4B40", preVerificationGas: "0x30d40", maxFeePerGas: customMaxFeePerGas ||
|
|
437
|
+
return { sender, nonce, initCode, callData, callGasLimit: "0x1E8480", verificationGasLimit: "0x4C4B40", preVerificationGas: "0x30d40", maxFeePerGas: customMaxFeePerGas || getDefaultMaxFeePerGasHex(), maxPriorityFeePerGas: customMaxPriorityFeePerGas || getDefaultPriorityFeePerGasHex(), paymasterAndData: "0x", signature: DUMMY_SIGNATURE };
|
|
392
438
|
}
|
|
393
439
|
async function createUserOperationWithDynamicFees(sender, nonce, callData, includeFactory = false, factoryAddress, factoryData, feeType = "standard") {
|
|
394
440
|
let fees;
|