diff --git a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts index 30ca23f9c..a657b6dab 100644 --- a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts +++ b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts @@ -432,6 +432,16 @@ export class Safe4337Pack extends RelayKitBasePack<{ }) if (estimateUserOperationGas) { + if ( + feeEstimator.defaultVerificationGasLimitOverhead != null && + estimateUserOperationGas.verificationGasLimit != null + ) { + estimateUserOperationGas.verificationGasLimit = ( + BigInt(estimateUserOperationGas.verificationGasLimit) + + BigInt(threshold) * feeEstimator.defaultVerificationGasLimitOverhead + ).toString() + } + safeOperation.addEstimations(estimateUserOperationGas) } @@ -446,6 +456,15 @@ export class Safe4337Pack extends RelayKitBasePack<{ }) if (postEstimationData) { + if ( + feeEstimator.defaultVerificationGasLimitOverhead != null && + postEstimationData.verificationGasLimit != null + ) { + postEstimationData.verificationGasLimit = ( + BigInt(postEstimationData.verificationGasLimit) + + BigInt(threshold) * feeEstimator.defaultVerificationGasLimitOverhead + ).toString() + } safeOperation.addEstimations(postEstimationData) } diff --git a/packages/relay-kit/src/packs/safe-4337/estimators/generic/GenericFeeEstimator.ts b/packages/relay-kit/src/packs/safe-4337/estimators/generic/GenericFeeEstimator.ts index 9e315974e..f9ef41097 100644 --- a/packages/relay-kit/src/packs/safe-4337/estimators/generic/GenericFeeEstimator.ts +++ b/packages/relay-kit/src/packs/safe-4337/estimators/generic/GenericFeeEstimator.ts @@ -21,6 +21,8 @@ export class GenericFeeEstimator implements IFeeEstimator { nodeUrl: string chainId: string gasMultiplier: number + defaultVerificationGasLimitOverhead?: bigint + constructor(nodeUrl: string, chainId: string, gasMultiplier: number = 1.5) { this.nodeUrl = nodeUrl this.chainId = chainId @@ -28,6 +30,7 @@ export class GenericFeeEstimator implements IFeeEstimator { throw new Error("gasMultiplier can't be equal or less than 0.") } this.gasMultiplier = gasMultiplier + this.defaultVerificationGasLimitOverhead = 55_000n } async preEstimateUserOperationGas({ diff --git a/packages/relay-kit/src/packs/safe-4337/types.ts b/packages/relay-kit/src/packs/safe-4337/types.ts index 1c60fd547..9b9fad2f6 100644 --- a/packages/relay-kit/src/packs/safe-4337/types.ts +++ b/packages/relay-kit/src/packs/safe-4337/types.ts @@ -156,6 +156,7 @@ export type EstimateFeeFunction = ({ export interface IFeeEstimator { preEstimateUserOperationGas?: EstimateFeeFunction postEstimateUserOperationGas?: EstimateFeeFunction + defaultVerificationGasLimitOverhead?: bigint } export type EstimateFeeProps = {