From ca3ccb31b5730f1d6bbbb9d60e1160cb3eb8ff23 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 17 Jun 2024 22:15:02 +0100 Subject: [PATCH 1/6] fix blocktag not supported for gnosis --- src/cli/setupServer.ts | 5 +- src/rpc/EntryPointSimulationsV07.ts | 47 +++++++---- src/rpc/gasEstimation.ts | 111 ++++++++++++++++++-------- src/rpc/nonceQueuer.ts | 7 +- src/rpc/validation/SafeValidator.ts | 2 + src/rpc/validation/UnsafeValidator.ts | 10 ++- 6 files changed, 129 insertions(+), 53 deletions(-) diff --git a/src/cli/setupServer.ts b/src/cli/setupServer.ts index fe51fd9f..09abab70 100644 --- a/src/cli/setupServer.ts +++ b/src/cli/setupServer.ts @@ -78,6 +78,7 @@ const getValidator = ({ metrics, gasPriceManager, parsedArgs["chain-type"], + parsedArgs["block-tag-support-disabled"], parsedArgs["entrypoint-simulation-contract"], parsedArgs["fixed-gas-limit-for-estimation"], parsedArgs.tenderly, @@ -93,6 +94,7 @@ const getValidator = ({ metrics, gasPriceManager, parsedArgs["chain-type"], + parsedArgs["block-tag-support-disabled"], parsedArgs["entrypoint-simulation-contract"], parsedArgs["fixed-gas-limit-for-estimation"], parsedArgs.tenderly, @@ -273,7 +275,8 @@ const getNonceQueuer = ({ parsedArgs["nonce-queuer-log-level"] || parsedArgs["log-level"] } - ) + ), + parsedArgs["block-tag-support-disabled"] ) } diff --git a/src/rpc/EntryPointSimulationsV07.ts b/src/rpc/EntryPointSimulationsV07.ts index 267efc6e..ea85c3ee 100644 --- a/src/rpc/EntryPointSimulationsV07.ts +++ b/src/rpc/EntryPointSimulationsV07.ts @@ -246,6 +246,7 @@ async function callPimlicoEntryPointSimulations( entryPoint: Address, entryPointSimulationsCallData: Hex[], entryPointSimulationsAddress: Address, + disableBlockTagSupport: boolean, stateOverride?: StateOverrides ) { const callData = encodeFunctionData({ @@ -254,18 +255,32 @@ async function callPimlicoEntryPointSimulations( args: [entryPoint, entryPointSimulationsCallData] }) - const result = (await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPointSimulationsAddress, - data: callData - }, - "latest", - // @ts-ignore - stateOverride - ] - })) as Hex + let result: Hex + + if (disableBlockTagSupport) { + result = (await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPointSimulationsAddress, + data: callData + } + ] + })) as Hex + } else { + result = (await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPointSimulationsAddress, + data: callData + }, + "latest", + // @ts-ignore + stateOverride + ] + })) as Hex + } const returnBytes = decodeAbiParameters( [{ name: "ret", type: "bytes[]" }], @@ -283,6 +298,7 @@ export async function simulateHandleOp( targetAddress: Address, targetCallData: Hex, entryPointSimulationsAddress: Address, + disabledBlockTagSupport: boolean, stateOverride: StateOverrides = {} ) { const finalParam = getStateOverrides({ @@ -314,6 +330,7 @@ export async function simulateHandleOp( entryPointSimulationsSimulateTargetCallData ], entryPointSimulationsAddress, + disabledBlockTagSupport, finalParam ) @@ -513,7 +530,8 @@ export async function simulateValidation( queuedUserOperations: UserOperationV07[], entryPoint: Address, publicClient: PublicClient, - entryPointSimulationsAddress: Address + entryPointSimulationsAddress: Address, + disableBlockTagSupport: boolean ) { const userOperations = [...queuedUserOperations, userOperation] const packedUserOperations = userOperations.map((uo) => @@ -530,7 +548,8 @@ export async function simulateValidation( publicClient, entryPoint, [entryPointSimulationsCallData], - entryPointSimulationsAddress + entryPointSimulationsAddress, + disableBlockTagSupport ) return { diff --git a/src/rpc/gasEstimation.ts b/src/rpc/gasEstimation.ts index b215b6e5..18b0c6f5 100644 --- a/src/rpc/gasEstimation.ts +++ b/src/rpc/gasEstimation.ts @@ -82,29 +82,49 @@ export async function simulateHandleOpV06( publicClient: PublicClient, targetAddress: Address, targetCallData: Hex, + disabledBlockTagSupport: boolean, finalParam: StateOverrides | undefined = undefined, fixedGasLimitForEstimation?: bigint ): Promise { try { - await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPoint, - data: encodeFunctionData({ - abi: EntryPointV06Abi, - functionName: "simulateHandleOp", - args: [userOperation, targetAddress, targetCallData] - }), - ...(fixedGasLimitForEstimation !== undefined && { - gas: `0x${fixedGasLimitForEstimation.toString(16)}` - }) - }, - "latest", - // @ts-ignore - ...(finalParam ? [finalParam] : []) - ] - }) + if (disabledBlockTagSupport) { + await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPoint, + data: encodeFunctionData({ + abi: EntryPointV06Abi, + functionName: "simulateHandleOp", + args: [userOperation, targetAddress, targetCallData] + }), + ...(fixedGasLimitForEstimation !== undefined && { + gas: `0x${fixedGasLimitForEstimation.toString(16)}` + }) + } + ] + }) + } else { + await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPoint, + data: encodeFunctionData({ + abi: EntryPointV06Abi, + functionName: "simulateHandleOp", + args: [userOperation, targetAddress, targetCallData] + }), + ...(fixedGasLimitForEstimation !== undefined && { + gas: `0x${fixedGasLimitForEstimation.toString(16)}` + }) + }, + "latest", + // @ts-ignore + ...(finalParam ? [finalParam] : []) + ] + }) + } } catch (e) { const err = e as RpcRequestErrorType @@ -199,6 +219,7 @@ async function callPimlicoEntryPointSimulations( entryPoint: Address, entryPointSimulationsCallData: Hex[], entryPointSimulationsAddress: Address, + disableBlockTagSupport: boolean, stateOverride?: StateOverrides, fixedGasLimitForEstimation?: bigint ) { @@ -208,21 +229,38 @@ async function callPimlicoEntryPointSimulations( args: [entryPoint, entryPointSimulationsCallData] }) - const result = (await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPointSimulationsAddress, - data: callData, - ...(fixedGasLimitForEstimation !== undefined && { - gas: `0x${fixedGasLimitForEstimation.toString(16)}` - }) - }, - "latest", - // @ts-ignore - ...(stateOverride ? [stateOverride] : []) - ] - })) as Hex + let result: Hex + + if (disableBlockTagSupport) { + result = (await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPointSimulationsAddress, + data: callData, + ...(fixedGasLimitForEstimation !== undefined && { + gas: `0x${fixedGasLimitForEstimation.toString(16)}` + }) + } + ] + })) as Hex + } else { + result = (await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPointSimulationsAddress, + data: callData, + ...(fixedGasLimitForEstimation !== undefined && { + gas: `0x${fixedGasLimitForEstimation.toString(16)}` + }) + }, + "latest", + // @ts-ignore + stateOverride + ] + })) as Hex + } const returnBytes = decodeAbiParameters( [{ name: "ret", type: "bytes[]" }], @@ -387,6 +425,7 @@ export async function simulateHandleOpV07( publicClient: PublicClient, entryPointSimulationsAddress: Address, chainId: number, + disabledBlockTagSupport: boolean, finalParam: StateOverrides | undefined = undefined, fixedGasLimitForEstimation?: bigint ): Promise { @@ -522,6 +561,7 @@ export async function simulateHandleOpV07( entryPointSimulationsSimulateTargetCallData ], entryPointSimulationsAddress, + disabledBlockTagSupport, finalParam, fixedGasLimitForEstimation ) @@ -582,6 +622,7 @@ export function simulateHandleOp( targetCallData: Hex, balanceOverrideEnabled: boolean, chainId: number, + disabledBlockTagSupport: boolean, stateOverride: StateOverrides = {}, entryPointSimulationsAddress?: Address, fixedGasLimitForEstimation?: bigint @@ -604,6 +645,7 @@ export function simulateHandleOp( publicClient, targetAddress, targetCallData, + disabledBlockTagSupport, finalStateOverride, // Enable fixed gas limit for estimation only for Vanguard testnet and Vanar mainnet chainId === 2040 || chainId === 78600 @@ -626,6 +668,7 @@ export function simulateHandleOp( publicClient, entryPointSimulationsAddress, chainId, + disabledBlockTagSupport, finalStateOverride, // Enable fixed gas limit for estimation only for Vanguard testnet and Vanar mainnet chainId === 2040 || chainId === 78600 diff --git a/src/rpc/nonceQueuer.ts b/src/rpc/nonceQueuer.ts index 4f0c8a66..90550bbe 100644 --- a/src/rpc/nonceQueuer.ts +++ b/src/rpc/nonceQueuer.ts @@ -36,15 +36,18 @@ export class NonceQueuer { mempool: MemoryMempool publicClient: PublicClient logger: Logger + disableBlockTagSupport: boolean constructor( mempool: MemoryMempool, publicClient: PublicClient, - logger: Logger + logger: Logger, + disableBlockTagSupport: boolean ) { this.mempool = mempool this.publicClient = publicClient this.logger = logger + this.disableBlockTagSupport = disableBlockTagSupport setInterval(() => { this.process() @@ -143,7 +146,7 @@ export class NonceQueuer { args: [userOperation.sender, qop.nonceKey] } }), - blockTag: "latest" + blockTag: this.disableBlockTagSupport ? undefined : "latest" }) } catch (error) { this.logger.error( diff --git a/src/rpc/validation/SafeValidator.ts b/src/rpc/validation/SafeValidator.ts index e4e46be4..7d8eaba2 100644 --- a/src/rpc/validation/SafeValidator.ts +++ b/src/rpc/validation/SafeValidator.ts @@ -68,6 +68,7 @@ export class SafeValidator metrics: Metrics, gasPriceManager: GasPriceManager, chainType: ChainType, + disableBlockTagSupport: boolean, entryPointSimulationsAddress?: Address, fixedGasLimitForEstimation?: bigint, usingTenderly = false, @@ -79,6 +80,7 @@ export class SafeValidator metrics, gasPriceManager, chainType, + disableBlockTagSupport, entryPointSimulationsAddress, fixedGasLimitForEstimation, usingTenderly, diff --git a/src/rpc/validation/UnsafeValidator.ts b/src/rpc/validation/UnsafeValidator.ts index af9775b1..47f14c75 100644 --- a/src/rpc/validation/UnsafeValidator.ts +++ b/src/rpc/validation/UnsafeValidator.ts @@ -65,6 +65,7 @@ export class UnsafeValidator implements InterfaceValidator { entryPointSimulationsAddress?: Address fixedGasLimitForEstimation?: bigint chainType: ChainType + disableBlockTagSupport: boolean constructor( publicClient: PublicClient, @@ -72,6 +73,7 @@ export class UnsafeValidator implements InterfaceValidator { metrics: Metrics, gasPriceManager: GasPriceManager, chainType: ChainType, + disableBlockTagSupport: boolean, entryPointSimulationsAddress?: Address, fixedGasLimitForEstimation?: bigint, usingTenderly = false, @@ -89,6 +91,7 @@ export class UnsafeValidator implements InterfaceValidator { this.entryPointSimulationsAddress = entryPointSimulationsAddress this.fixedGasLimitForEstimation = fixedGasLimitForEstimation this.chainType = chainType + this.disableBlockTagSupport = disableBlockTagSupport } async getSimulationResult( @@ -186,6 +189,7 @@ export class UnsafeValidator implements InterfaceValidator { "0x", this.balanceOverrideEnabled, this.chainId, + this.disableBlockTagSupport, stateOverrides, this.entryPointSimulationsAddress, this.fixedGasLimitForEstimation @@ -233,7 +237,8 @@ export class UnsafeValidator implements InterfaceValidator { entryPoint, this.publicClient, zeroAddress, - "0x" + "0x", + this.disableBlockTagSupport ) const [simulateValidationResult, runtimeValidation] = await Promise.all( @@ -387,7 +392,8 @@ export class UnsafeValidator implements InterfaceValidator { queuedUserOperations, entryPoint, this.publicClient, - this.entryPointSimulationsAddress + this.entryPointSimulationsAddress, + this.disableBlockTagSupport ) if (simulateValidationResult.status === "failed") { From 06b2b70e44974aa9cdf0fc07ec9b84261432c117 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 17 Jun 2024 22:20:33 +0100 Subject: [PATCH 2/6] make the flag positive --- src/cli/config/bundler.ts | 2 +- src/cli/config/options.ts | 4 ++-- src/cli/setupServer.ts | 8 ++++---- src/executor/executor.ts | 12 ++++++------ src/rpc/EntryPointSimulationsV07.ts | 18 +++++++++--------- src/rpc/gasEstimation.ts | 14 +++++++------- src/rpc/nonceQueuer.ts | 8 ++++---- src/rpc/validation/SafeValidator.ts | 4 ++-- src/rpc/validation/UnsafeValidator.ts | 12 ++++++------ 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/cli/config/bundler.ts b/src/cli/config/bundler.ts index c1f0ce80..c07b097d 100644 --- a/src/cli/config/bundler.ts +++ b/src/cli/config/bundler.ts @@ -125,7 +125,7 @@ export const rpcArgsSchema = z.object({ "send-transaction-rpc-url": z.string().url().optional(), "polling-interval": z.number().int().min(0), "max-block-range": z.number().int().min(0).optional(), - "block-tag-support-disabled": z.boolean().optional().default(false) + "block-tag-support": z.boolean().optional().default(true) }) export const bundleCopmressionArgsSchema = z.object({ diff --git a/src/cli/config/options.ts b/src/cli/config/options.ts index 6bbcd2e4..29815c29 100644 --- a/src/cli/config/options.ts +++ b/src/cli/config/options.ts @@ -253,12 +253,12 @@ export const rpcOptions: CliCommandOptions = { type: "number", require: false }, - "block-tag-support-disabled": { + "block-tag-support": { description: "Disable sending block tag when sending eth_estimateGas call", type: "boolean", require: false, - default: false + default: true } } diff --git a/src/cli/setupServer.ts b/src/cli/setupServer.ts index 09abab70..fe9a019b 100644 --- a/src/cli/setupServer.ts +++ b/src/cli/setupServer.ts @@ -78,7 +78,7 @@ const getValidator = ({ metrics, gasPriceManager, parsedArgs["chain-type"], - parsedArgs["block-tag-support-disabled"], + parsedArgs["block-tag-support"], parsedArgs["entrypoint-simulation-contract"], parsedArgs["fixed-gas-limit-for-estimation"], parsedArgs.tenderly, @@ -94,7 +94,7 @@ const getValidator = ({ metrics, gasPriceManager, parsedArgs["chain-type"], - parsedArgs["block-tag-support-disabled"], + parsedArgs["block-tag-support"], parsedArgs["entrypoint-simulation-contract"], parsedArgs["fixed-gas-limit-for-estimation"], parsedArgs.tenderly, @@ -205,7 +205,7 @@ const getExecutor = ({ !parsedArgs.tenderly, parsedArgs["legacy-transactions"], parsedArgs["fixed-gas-limit-for-estimation"], - parsedArgs["block-tag-support-disabled"], + parsedArgs["block-tag-support"], parsedArgs["local-gas-limit-calculation"] ) } @@ -276,7 +276,7 @@ const getNonceQueuer = ({ parsedArgs["log-level"] } ), - parsedArgs["block-tag-support-disabled"] + parsedArgs["block-tag-support"] ) } diff --git a/src/executor/executor.ts b/src/executor/executor.ts index a0249d6b..dcde990a 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -116,7 +116,7 @@ export class Executor { reputationManager: InterfaceReputationManager compressionHandler: CompressionHandler | null gasPriceManager: GasPriceManager - disableBlockTagSupport: boolean + blockTagSupport: boolean mutex: Mutex constructor( @@ -132,7 +132,7 @@ export class Executor { simulateTransaction = false, legacyTransactions = false, fixedGasLimitForEstimation?: bigint, - disableBlockTagSupport = false, + blockTagSupport = false, localGasLimitCalculation = false ) { this.publicClient = publicClient @@ -147,7 +147,7 @@ export class Executor { this.localGasLimitCalculation = localGasLimitCalculation this.compressionHandler = compressionHandler this.gasPriceManager = gasPriceManager - this.disableBlockTagSupport = disableBlockTagSupport + this.blockTagSupport = blockTagSupport this.entryPoints = entryPoints this.mutex = new Mutex() @@ -266,7 +266,7 @@ export class Executor { newRequest.nonce, newRequest.maxFeePerGas, newRequest.maxPriorityFeePerGas, - this.disableBlockTagSupport ? undefined : "latest", + this.blockTagSupport ? "latest" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, @@ -577,7 +577,7 @@ export class Executor { nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, - this.disableBlockTagSupport ? undefined : "pending", + this.blockTagSupport ? "latest" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, @@ -872,7 +872,7 @@ export class Executor { nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, - this.disableBlockTagSupport ? undefined : "pending", + this.blockTagSupport ? "pending" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, diff --git a/src/rpc/EntryPointSimulationsV07.ts b/src/rpc/EntryPointSimulationsV07.ts index ea85c3ee..e0f993db 100644 --- a/src/rpc/EntryPointSimulationsV07.ts +++ b/src/rpc/EntryPointSimulationsV07.ts @@ -246,7 +246,7 @@ async function callPimlicoEntryPointSimulations( entryPoint: Address, entryPointSimulationsCallData: Hex[], entryPointSimulationsAddress: Address, - disableBlockTagSupport: boolean, + blockTagSupport: boolean, stateOverride?: StateOverrides ) { const callData = encodeFunctionData({ @@ -257,14 +257,17 @@ async function callPimlicoEntryPointSimulations( let result: Hex - if (disableBlockTagSupport) { + if (blockTagSupport) { result = (await publicClient.request({ method: "eth_call", params: [ { to: entryPointSimulationsAddress, data: callData - } + }, + "latest", + // @ts-ignore + stateOverride ] })) as Hex } else { @@ -274,10 +277,7 @@ async function callPimlicoEntryPointSimulations( { to: entryPointSimulationsAddress, data: callData - }, - "latest", - // @ts-ignore - stateOverride + } ] })) as Hex } @@ -531,7 +531,7 @@ export async function simulateValidation( entryPoint: Address, publicClient: PublicClient, entryPointSimulationsAddress: Address, - disableBlockTagSupport: boolean + blockTagSupport: boolean ) { const userOperations = [...queuedUserOperations, userOperation] const packedUserOperations = userOperations.map((uo) => @@ -549,7 +549,7 @@ export async function simulateValidation( entryPoint, [entryPointSimulationsCallData], entryPointSimulationsAddress, - disableBlockTagSupport + blockTagSupport ) return { diff --git a/src/rpc/gasEstimation.ts b/src/rpc/gasEstimation.ts index 18b0c6f5..6ebc2503 100644 --- a/src/rpc/gasEstimation.ts +++ b/src/rpc/gasEstimation.ts @@ -219,7 +219,7 @@ async function callPimlicoEntryPointSimulations( entryPoint: Address, entryPointSimulationsCallData: Hex[], entryPointSimulationsAddress: Address, - disableBlockTagSupport: boolean, + blockTagSupport: boolean, stateOverride?: StateOverrides, fixedGasLimitForEstimation?: bigint ) { @@ -231,7 +231,7 @@ async function callPimlicoEntryPointSimulations( let result: Hex - if (disableBlockTagSupport) { + if (blockTagSupport) { result = (await publicClient.request({ method: "eth_call", params: [ @@ -241,7 +241,10 @@ async function callPimlicoEntryPointSimulations( ...(fixedGasLimitForEstimation !== undefined && { gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) - } + }, + "latest", + // @ts-ignore + stateOverride ] })) as Hex } else { @@ -254,10 +257,7 @@ async function callPimlicoEntryPointSimulations( ...(fixedGasLimitForEstimation !== undefined && { gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) - }, - "latest", - // @ts-ignore - stateOverride + } ] })) as Hex } diff --git a/src/rpc/nonceQueuer.ts b/src/rpc/nonceQueuer.ts index 90550bbe..673e857a 100644 --- a/src/rpc/nonceQueuer.ts +++ b/src/rpc/nonceQueuer.ts @@ -36,18 +36,18 @@ export class NonceQueuer { mempool: MemoryMempool publicClient: PublicClient logger: Logger - disableBlockTagSupport: boolean + blockTagSupport: boolean constructor( mempool: MemoryMempool, publicClient: PublicClient, logger: Logger, - disableBlockTagSupport: boolean + blockTagSupport: boolean ) { this.mempool = mempool this.publicClient = publicClient this.logger = logger - this.disableBlockTagSupport = disableBlockTagSupport + this.blockTagSupport = blockTagSupport setInterval(() => { this.process() @@ -146,7 +146,7 @@ export class NonceQueuer { args: [userOperation.sender, qop.nonceKey] } }), - blockTag: this.disableBlockTagSupport ? undefined : "latest" + blockTag: this.blockTagSupport ? "latest" : undefined }) } catch (error) { this.logger.error( diff --git a/src/rpc/validation/SafeValidator.ts b/src/rpc/validation/SafeValidator.ts index 7d8eaba2..b60a39c4 100644 --- a/src/rpc/validation/SafeValidator.ts +++ b/src/rpc/validation/SafeValidator.ts @@ -68,7 +68,7 @@ export class SafeValidator metrics: Metrics, gasPriceManager: GasPriceManager, chainType: ChainType, - disableBlockTagSupport: boolean, + blockTagSupport: boolean, entryPointSimulationsAddress?: Address, fixedGasLimitForEstimation?: bigint, usingTenderly = false, @@ -80,7 +80,7 @@ export class SafeValidator metrics, gasPriceManager, chainType, - disableBlockTagSupport, + blockTagSupport, entryPointSimulationsAddress, fixedGasLimitForEstimation, usingTenderly, diff --git a/src/rpc/validation/UnsafeValidator.ts b/src/rpc/validation/UnsafeValidator.ts index 47f14c75..5de4486f 100644 --- a/src/rpc/validation/UnsafeValidator.ts +++ b/src/rpc/validation/UnsafeValidator.ts @@ -65,7 +65,7 @@ export class UnsafeValidator implements InterfaceValidator { entryPointSimulationsAddress?: Address fixedGasLimitForEstimation?: bigint chainType: ChainType - disableBlockTagSupport: boolean + blockTagSupport: boolean constructor( publicClient: PublicClient, @@ -73,7 +73,7 @@ export class UnsafeValidator implements InterfaceValidator { metrics: Metrics, gasPriceManager: GasPriceManager, chainType: ChainType, - disableBlockTagSupport: boolean, + blockTagSupport: boolean, entryPointSimulationsAddress?: Address, fixedGasLimitForEstimation?: bigint, usingTenderly = false, @@ -91,7 +91,7 @@ export class UnsafeValidator implements InterfaceValidator { this.entryPointSimulationsAddress = entryPointSimulationsAddress this.fixedGasLimitForEstimation = fixedGasLimitForEstimation this.chainType = chainType - this.disableBlockTagSupport = disableBlockTagSupport + this.blockTagSupport = blockTagSupport } async getSimulationResult( @@ -189,7 +189,7 @@ export class UnsafeValidator implements InterfaceValidator { "0x", this.balanceOverrideEnabled, this.chainId, - this.disableBlockTagSupport, + this.blockTagSupport, stateOverrides, this.entryPointSimulationsAddress, this.fixedGasLimitForEstimation @@ -238,7 +238,7 @@ export class UnsafeValidator implements InterfaceValidator { this.publicClient, zeroAddress, "0x", - this.disableBlockTagSupport + this.blockTagSupport ) const [simulateValidationResult, runtimeValidation] = await Promise.all( @@ -393,7 +393,7 @@ export class UnsafeValidator implements InterfaceValidator { entryPoint, this.publicClient, this.entryPointSimulationsAddress, - this.disableBlockTagSupport + this.blockTagSupport ) if (simulateValidationResult.status === "failed") { From 63e9457c81302c3dfa83642317460253c7e6b95c Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 17 Jun 2024 22:25:05 +0100 Subject: [PATCH 3/6] remove all usage of disabledBlockTagSupport --- src/executor/executor.ts | 4 ++-- src/rpc/EntryPointSimulationsV07.ts | 4 ++-- src/rpc/gasEstimation.ts | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/executor/executor.ts b/src/executor/executor.ts index dcde990a..69125ddb 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -132,7 +132,7 @@ export class Executor { simulateTransaction = false, legacyTransactions = false, fixedGasLimitForEstimation?: bigint, - blockTagSupport = false, + blockTagSupport = true, localGasLimitCalculation = false ) { this.publicClient = publicClient @@ -577,7 +577,7 @@ export class Executor { nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, - this.blockTagSupport ? "latest" : undefined, + this.blockTagSupport ? "pending" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, diff --git a/src/rpc/EntryPointSimulationsV07.ts b/src/rpc/EntryPointSimulationsV07.ts index e0f993db..408c7589 100644 --- a/src/rpc/EntryPointSimulationsV07.ts +++ b/src/rpc/EntryPointSimulationsV07.ts @@ -298,7 +298,7 @@ export async function simulateHandleOp( targetAddress: Address, targetCallData: Hex, entryPointSimulationsAddress: Address, - disabledBlockTagSupport: boolean, + blockTagSupport: boolean, stateOverride: StateOverrides = {} ) { const finalParam = getStateOverrides({ @@ -330,7 +330,7 @@ export async function simulateHandleOp( entryPointSimulationsSimulateTargetCallData ], entryPointSimulationsAddress, - disabledBlockTagSupport, + blockTagSupport, finalParam ) diff --git a/src/rpc/gasEstimation.ts b/src/rpc/gasEstimation.ts index 6ebc2503..718b4dd7 100644 --- a/src/rpc/gasEstimation.ts +++ b/src/rpc/gasEstimation.ts @@ -82,12 +82,12 @@ export async function simulateHandleOpV06( publicClient: PublicClient, targetAddress: Address, targetCallData: Hex, - disabledBlockTagSupport: boolean, + blockTagSupport: boolean, finalParam: StateOverrides | undefined = undefined, fixedGasLimitForEstimation?: bigint ): Promise { try { - if (disabledBlockTagSupport) { + if (blockTagSupport) { await publicClient.request({ method: "eth_call", params: [ @@ -101,7 +101,10 @@ export async function simulateHandleOpV06( ...(fixedGasLimitForEstimation !== undefined && { gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) - } + }, + "latest", + // @ts-ignore + ...(finalParam ? [finalParam] : []) ] }) } else { @@ -118,10 +121,7 @@ export async function simulateHandleOpV06( ...(fixedGasLimitForEstimation !== undefined && { gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) - }, - "latest", - // @ts-ignore - ...(finalParam ? [finalParam] : []) + } ] }) } @@ -425,7 +425,7 @@ export async function simulateHandleOpV07( publicClient: PublicClient, entryPointSimulationsAddress: Address, chainId: number, - disabledBlockTagSupport: boolean, + blockTagSupport: boolean, finalParam: StateOverrides | undefined = undefined, fixedGasLimitForEstimation?: bigint ): Promise { @@ -561,7 +561,7 @@ export async function simulateHandleOpV07( entryPointSimulationsSimulateTargetCallData ], entryPointSimulationsAddress, - disabledBlockTagSupport, + blockTagSupport, finalParam, fixedGasLimitForEstimation ) @@ -622,7 +622,7 @@ export function simulateHandleOp( targetCallData: Hex, balanceOverrideEnabled: boolean, chainId: number, - disabledBlockTagSupport: boolean, + blockTagSupport: boolean, stateOverride: StateOverrides = {}, entryPointSimulationsAddress?: Address, fixedGasLimitForEstimation?: bigint @@ -645,7 +645,7 @@ export function simulateHandleOp( publicClient, targetAddress, targetCallData, - disabledBlockTagSupport, + blockTagSupport, finalStateOverride, // Enable fixed gas limit for estimation only for Vanguard testnet and Vanar mainnet chainId === 2040 || chainId === 78600 @@ -668,7 +668,7 @@ export function simulateHandleOp( publicClient, entryPointSimulationsAddress, chainId, - disabledBlockTagSupport, + blockTagSupport, finalStateOverride, // Enable fixed gas limit for estimation only for Vanguard testnet and Vanar mainnet chainId === 2040 || chainId === 78600 From e215f3e38b38e9fff8a1fe86905ec183514f0937 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 17 Jun 2024 22:31:49 +0100 Subject: [PATCH 4/6] enable state override --- src/rpc/EntryPointSimulationsV07.ts | 5 ++++- src/rpc/gasEstimation.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/rpc/EntryPointSimulationsV07.ts b/src/rpc/EntryPointSimulationsV07.ts index 408c7589..a484b8bc 100644 --- a/src/rpc/EntryPointSimulationsV07.ts +++ b/src/rpc/EntryPointSimulationsV07.ts @@ -277,7 +277,10 @@ async function callPimlicoEntryPointSimulations( { to: entryPointSimulationsAddress, data: callData - } + }, + undefined, + // @ts-ignore + stateOverride ] })) as Hex } diff --git a/src/rpc/gasEstimation.ts b/src/rpc/gasEstimation.ts index 718b4dd7..16f716e1 100644 --- a/src/rpc/gasEstimation.ts +++ b/src/rpc/gasEstimation.ts @@ -121,7 +121,10 @@ export async function simulateHandleOpV06( ...(fixedGasLimitForEstimation !== undefined && { gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) - } + }, + undefined, + // @ts-ignore + ...(finalParam ? [finalParam] : []) ] }) } @@ -257,7 +260,10 @@ async function callPimlicoEntryPointSimulations( ...(fixedGasLimitForEstimation !== undefined && { gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) - } + }, + undefined, + // @ts-ignore + stateOverride ] })) as Hex } From ee3e929159d864f0757551166168955cdd406be1 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 17 Jun 2024 22:51:13 +0100 Subject: [PATCH 5/6] send block number --- src/rpc/EntryPointSimulationsV07.ts | 4 +++- src/rpc/gasEstimation.ts | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rpc/EntryPointSimulationsV07.ts b/src/rpc/EntryPointSimulationsV07.ts index a484b8bc..3e103202 100644 --- a/src/rpc/EntryPointSimulationsV07.ts +++ b/src/rpc/EntryPointSimulationsV07.ts @@ -271,6 +271,8 @@ async function callPimlicoEntryPointSimulations( ] })) as Hex } else { + const block = await publicClient.getBlockNumber() + result = (await publicClient.request({ method: "eth_call", params: [ @@ -278,7 +280,7 @@ async function callPimlicoEntryPointSimulations( to: entryPointSimulationsAddress, data: callData }, - undefined, + toHex(block), // @ts-ignore stateOverride ] diff --git a/src/rpc/gasEstimation.ts b/src/rpc/gasEstimation.ts index 16f716e1..ade082ae 100644 --- a/src/rpc/gasEstimation.ts +++ b/src/rpc/gasEstimation.ts @@ -108,6 +108,7 @@ export async function simulateHandleOpV06( ] }) } else { + const block = await publicClient.getBlockNumber() await publicClient.request({ method: "eth_call", params: [ @@ -122,7 +123,7 @@ export async function simulateHandleOpV06( gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) }, - undefined, + toHex(block), // @ts-ignore ...(finalParam ? [finalParam] : []) ] @@ -251,6 +252,7 @@ async function callPimlicoEntryPointSimulations( ] })) as Hex } else { + const block = await publicClient.getBlockNumber() result = (await publicClient.request({ method: "eth_call", params: [ @@ -261,7 +263,7 @@ async function callPimlicoEntryPointSimulations( gas: `0x${fixedGasLimitForEstimation.toString(16)}` }) }, - undefined, + toHex(block), // @ts-ignore stateOverride ] From b894e94ce3a7b176fd58721402b8388e6b71d505 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 17 Jun 2024 23:01:15 +0100 Subject: [PATCH 6/6] don't set null when state override is not present --- src/rpc/EntryPointSimulationsV07.ts | 45 ++++------- src/rpc/gasEstimation.ts | 116 +++++++++------------------- 2 files changed, 52 insertions(+), 109 deletions(-) diff --git a/src/rpc/EntryPointSimulationsV07.ts b/src/rpc/EntryPointSimulationsV07.ts index 3e103202..cec06deb 100644 --- a/src/rpc/EntryPointSimulationsV07.ts +++ b/src/rpc/EntryPointSimulationsV07.ts @@ -255,37 +255,20 @@ async function callPimlicoEntryPointSimulations( args: [entryPoint, entryPointSimulationsCallData] }) - let result: Hex - - if (blockTagSupport) { - result = (await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPointSimulationsAddress, - data: callData - }, - "latest", - // @ts-ignore - stateOverride - ] - })) as Hex - } else { - const block = await publicClient.getBlockNumber() - - result = (await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPointSimulationsAddress, - data: callData - }, - toHex(block), - // @ts-ignore - stateOverride - ] - })) as Hex - } + const result = (await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPointSimulationsAddress, + data: callData + }, + blockTagSupport + ? "latest" + : toHex(await publicClient.getBlockNumber()), + // @ts-ignore + ...(stateOverride ? [stateOverride] : []) + ] + })) as Hex const returnBytes = decodeAbiParameters( [{ name: "ret", type: "bytes[]" }], diff --git a/src/rpc/gasEstimation.ts b/src/rpc/gasEstimation.ts index ade082ae..a57a3d55 100644 --- a/src/rpc/gasEstimation.ts +++ b/src/rpc/gasEstimation.ts @@ -87,48 +87,27 @@ export async function simulateHandleOpV06( fixedGasLimitForEstimation?: bigint ): Promise { try { - if (blockTagSupport) { - await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPoint, - data: encodeFunctionData({ - abi: EntryPointV06Abi, - functionName: "simulateHandleOp", - args: [userOperation, targetAddress, targetCallData] - }), - ...(fixedGasLimitForEstimation !== undefined && { - gas: `0x${fixedGasLimitForEstimation.toString(16)}` - }) - }, - "latest", - // @ts-ignore - ...(finalParam ? [finalParam] : []) - ] - }) - } else { - const block = await publicClient.getBlockNumber() - await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPoint, - data: encodeFunctionData({ - abi: EntryPointV06Abi, - functionName: "simulateHandleOp", - args: [userOperation, targetAddress, targetCallData] - }), - ...(fixedGasLimitForEstimation !== undefined && { - gas: `0x${fixedGasLimitForEstimation.toString(16)}` - }) - }, - toHex(block), - // @ts-ignore - ...(finalParam ? [finalParam] : []) - ] - }) - } + await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPoint, + data: encodeFunctionData({ + abi: EntryPointV06Abi, + functionName: "simulateHandleOp", + args: [userOperation, targetAddress, targetCallData] + }), + ...(fixedGasLimitForEstimation !== undefined && { + gas: `0x${fixedGasLimitForEstimation.toString(16)}` + }) + }, + blockTagSupport + ? "latest" + : toHex(await publicClient.getBlockNumber()), + // @ts-ignore + ...(finalParam ? [finalParam] : []) + ] + }) } catch (e) { const err = e as RpcRequestErrorType @@ -233,42 +212,23 @@ async function callPimlicoEntryPointSimulations( args: [entryPoint, entryPointSimulationsCallData] }) - let result: Hex - - if (blockTagSupport) { - result = (await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPointSimulationsAddress, - data: callData, - ...(fixedGasLimitForEstimation !== undefined && { - gas: `0x${fixedGasLimitForEstimation.toString(16)}` - }) - }, - "latest", - // @ts-ignore - stateOverride - ] - })) as Hex - } else { - const block = await publicClient.getBlockNumber() - result = (await publicClient.request({ - method: "eth_call", - params: [ - { - to: entryPointSimulationsAddress, - data: callData, - ...(fixedGasLimitForEstimation !== undefined && { - gas: `0x${fixedGasLimitForEstimation.toString(16)}` - }) - }, - toHex(block), - // @ts-ignore - stateOverride - ] - })) as Hex - } + const result = (await publicClient.request({ + method: "eth_call", + params: [ + { + to: entryPointSimulationsAddress, + data: callData, + ...(fixedGasLimitForEstimation !== undefined && { + gas: `0x${fixedGasLimitForEstimation.toString(16)}` + }) + }, + blockTagSupport + ? "latest" + : toHex(await publicClient.getBlockNumber()), + // @ts-ignore + ...(stateOverride ? [stateOverride] : []) + ] + })) as Hex const returnBytes = decodeAbiParameters( [{ name: "ret", type: "bytes[]" }],