diff --git a/src/cli/config/bundler.ts b/src/cli/config/bundler.ts index 12ef6d55..3fef1a57 100644 --- a/src/cli/config/bundler.ts +++ b/src/cli/config/bundler.ts @@ -74,7 +74,10 @@ export const bundlerArgsSchema = z.object({ "mempool-max-parallel-ops": z.number().int().min(0).default(10), "mempool-max-queued-ops": z.number().int().min(0).default(0), "enforce-unique-senders-per-bundle": z.boolean().default(true), - "max-gas-per-bundle": z.string().transform((val) => BigInt(val)).default("5000000"), + "max-gas-per-bundle": z + .string() + .transform((val) => BigInt(val)) + .default("5000000") }) export const compatibilityArgsSchema = z.object({ @@ -93,6 +96,9 @@ export const compatibilityArgsSchema = z.object({ "balance-override": z.boolean(), "local-gas-limit-calculation": z.boolean(), "flush-stuck-transactions-during-startup": z.boolean(), + "paymaster-gas-limit-multiplier": z + .string() + .transform((val) => BigInt(val)), "fixed-gas-limit-for-estimation": z .string() .transform((val) => BigInt(val)) diff --git a/src/cli/config/options.ts b/src/cli/config/options.ts index 661ddb4b..09a1fee9 100644 --- a/src/cli/config/options.ts +++ b/src/cli/config/options.ts @@ -106,29 +106,32 @@ export const bundlerOptions: CliCommandOptions = { default: "105,110,115" }, "mempool-max-parallel-ops": { - description: "Maximum amount of parallel user ops to keep in the meempool (same sender, different nonce keys)", + description: + "Maximum amount of parallel user ops to keep in the meempool (same sender, different nonce keys)", type: "number", require: false, - default: 10, + default: 10 }, "mempool-max-queued-ops": { - description: "Maximum amount of sequential user ops to keep in the mempool (same sender and nonce key, different nonce values)", + description: + "Maximum amount of sequential user ops to keep in the mempool (same sender and nonce key, different nonce values)", type: "number", require: false, - default: 0, + default: 0 }, "enforce-unique-senders-per-bundle": { - description: "Include user ops with the same sender in the single bundle", + description: + "Include user ops with the same sender in the single bundle", type: "boolean", require: false, - default: true, + default: true }, "max-gas-per-bundle": { description: "Maximum amount of gas per bundle", type: "string", require: false, - default: "5000000", - }, + default: "5000000" + } } export const compatibilityOptions: CliCommandOptions = @@ -186,6 +189,13 @@ export const compatibilityOptions: CliCommandOptions = type: "string", require: false, default: "v1" + }, + "paymaster-gas-limit-multiplier": { + description: + "Amount to multiply the paymaster gas limits fetched from simulations", + type: "string", + require: true, + default: "110" } } diff --git a/src/cli/setupServer.ts b/src/cli/setupServer.ts index 7a00c6e1..cd5d96c8 100644 --- a/src/cli/setupServer.ts +++ b/src/cli/setupServer.ts @@ -326,6 +326,7 @@ const getRpcHandler = ({ gasPriceManager, parsedArgs["gas-price-multipliers"], parsedArgs["chain-type"], + parsedArgs["paymaster-gas-limit-multiplier"], parsedArgs["dangerous-skip-user-operation-validation"] ) } diff --git a/src/rpc/rpcHandler.ts b/src/rpc/rpcHandler.ts index e2db3862..c4e88045 100644 --- a/src/rpc/rpcHandler.ts +++ b/src/rpc/rpcHandler.ts @@ -131,6 +131,7 @@ export class RpcHandler implements IRpcEndpoint { dangerousSkipUserOperationValidation: boolean gasPriceManager: GasPriceManager gasPriceMultipliers: GasPriceMultipliers + paymasterGasLimitMultiplier: bigint constructor( entryPoints: Address[], @@ -152,6 +153,7 @@ export class RpcHandler implements IRpcEndpoint { gasPriceManager: GasPriceManager, gasPriceMultipliers: GasPriceMultipliers, chainType: ChainType, + paymasterGasLimitMultiplier: bigint, dangerousSkipUserOperationValidation = false ) { this.entryPoints = entryPoints @@ -176,6 +178,7 @@ export class RpcHandler implements IRpcEndpoint { this.gasPriceMultipliers = gasPriceMultipliers this.chainType = chainType this.gasPriceManager = gasPriceManager + this.paymasterGasLimitMultiplier = paymasterGasLimitMultiplier } async handleMethod( @@ -368,14 +371,18 @@ export class RpcHandler implements IRpcEndpoint { // maxFeePerGas to maxPriorityFeePerGas userOperation.maxPriorityFeePerGas = userOperation.maxFeePerGas - // Check if the nonce is valid // If the nonce is less than the current nonce, the user operation has already been executed // If the nonce is greater than the current nonce, we may have missing user operations in the mempool - const currentNonceValue = await this.getNonceValue(userOperation, entryPoint) - const [,userOperationNonceValue] = getNonceKeyAndValue(userOperation.nonce) + const currentNonceValue = await this.getNonceValue( + userOperation, + entryPoint + ) + const [, userOperationNonceValue] = getNonceKeyAndValue( + userOperation.nonce + ) - let queuedUserOperations: UserOperation[] = []; + let queuedUserOperations: UserOperation[] = [] if (userOperationNonceValue < currentNonceValue) { throw new RpcError( "UserOperation reverted during simulation with reason: AA25 invalid account nonce", @@ -395,9 +402,12 @@ export class RpcHandler implements IRpcEndpoint { userOperation, entryPoint, currentNonceValue - ); + ) - if (userOperationNonceValue > currentNonceValue + BigInt(queuedUserOperations.length)) { + if ( + userOperationNonceValue > + currentNonceValue + BigInt(queuedUserOperations.length) + ) { throw new RpcError( "UserOperation reverted during simulation with reason: AA25 invalid account nonce", ValidationErrors.InvalidFields @@ -409,7 +419,7 @@ export class RpcHandler implements IRpcEndpoint { userOperation, entryPoint, queuedUserOperations, - stateOverrides, + stateOverrides ) let { verificationGasLimit, callGasLimit } = @@ -436,6 +446,14 @@ export class RpcHandler implements IRpcEndpoint { paymasterPostOpGasLimit = executionResult.data.executionResult.paymasterPostOpGasLimit || 1n + + const multiplier = this.paymasterGasLimitMultiplier + + paymasterVerificationGasLimit = + (paymasterVerificationGasLimit * multiplier) / 100n + + paymasterPostOpGasLimit = + (paymasterPostOpGasLimit * multiplier) / 100n } if ( @@ -980,8 +998,13 @@ export class RpcHandler implements IRpcEndpoint { ) } - const currentNonceValue = await this.getNonceValue(userOperation, entryPoint) - const [,userOperationNonceValue] = getNonceKeyAndValue(userOperation.nonce) + const currentNonceValue = await this.getNonceValue( + userOperation, + entryPoint + ) + const [, userOperationNonceValue] = getNonceKeyAndValue( + userOperation.nonce + ) if (userOperationNonceValue < currentNonceValue) { throw new RpcError( @@ -997,7 +1020,10 @@ export class RpcHandler implements IRpcEndpoint { } let queuedUserOperations: UserOperation[] = [] - if (userOperationNonceValue > currentNonceValue && isVersion07(userOperation)) { + if ( + userOperationNonceValue > currentNonceValue && + isVersion07(userOperation) + ) { queuedUserOperations = await this.mempool.getQueuedUserOperations( userOperation, entryPoint, @@ -1006,7 +1032,8 @@ export class RpcHandler implements IRpcEndpoint { } if ( - userOperationNonceValue === currentNonceValue + BigInt(queuedUserOperations.length) + userOperationNonceValue === + currentNonceValue + BigInt(queuedUserOperations.length) ) { if (this.dangerousSkipUserOperationValidation) { const success = this.mempool.add(op, entryPoint) @@ -1165,10 +1192,7 @@ export class RpcHandler implements IRpcEndpoint { return { inflatedOp, inflatorId } } - async getNonceValue( - userOperation: UserOperation, - entryPoint: Address - ) { + async getNonceValue(userOperation: UserOperation, entryPoint: Address) { const entryPointContract = getContract({ address: entryPoint, abi: isVersion06(userOperation) @@ -1179,7 +1203,7 @@ export class RpcHandler implements IRpcEndpoint { } }) - const [nonceKey,] = getNonceKeyAndValue(userOperation.nonce) + const [nonceKey] = getNonceKeyAndValue(userOperation.nonce) const getNonceResult = await entryPointContract.read.getNonce( [userOperation.sender, nonceKey],