From e87dde77b4fd497baa8174daee3d5895c0aff951 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Thu, 2 Nov 2023 16:24:04 +0500 Subject: [PATCH] fix address checksum & gas price reported by etH_estimateUserOp --- packages/executor/src/entities/MempoolEntry.ts | 6 ++++-- packages/executor/src/executor.ts | 15 ++++++++------- packages/executor/src/modules/eth.ts | 18 +++++------------- .../executor/src/services/BundlingService.ts | 3 +-- .../executor/src/services/MempoolService.ts | 1 + packages/params/src/utils/userOp.ts | 7 ++++--- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/packages/executor/src/entities/MempoolEntry.ts b/packages/executor/src/entities/MempoolEntry.ts index 57b7da77..ed0576ff 100644 --- a/packages/executor/src/entities/MempoolEntry.ts +++ b/packages/executor/src/entities/MempoolEntry.ts @@ -1,5 +1,5 @@ import { BigNumber, BigNumberish, ethers } from "ethers"; -import { hexValue } from "ethers/lib/utils"; +import { getAddress, hexValue } from "ethers/lib/utils"; import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes"; import RpcError from "types/lib/api/errors/rpc-error"; import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint"; @@ -111,6 +111,8 @@ export class MempoolEntry implements IMempoolEntry { validateAndTransformUserOp(): void { try { + this.userOp.sender = getAddress(this.userOp.sender); + this.entryPoint = getAddress(this.entryPoint); this.prefund = BigNumber.from(this.prefund); this.userOp.nonce = BigNumber.from(this.userOp.nonce); this.userOp.callGasLimit = BigNumber.from(this.userOp.callGasLimit); @@ -133,7 +135,7 @@ export class MempoolEntry implements IMempoolEntry { return { chainId: this.chainId, userOp: { - sender: this.userOp.sender, + sender: getAddress(this.userOp.sender), nonce: hexValue(this.userOp.nonce), initCode: this.userOp.initCode, callData: this.userOp.callData, diff --git a/packages/executor/src/executor.ts b/packages/executor/src/executor.ts index a928b8df..3c57716c 100644 --- a/packages/executor/src/executor.ts +++ b/packages/executor/src/executor.ts @@ -105,11 +105,19 @@ export class Executor { this.mempoolService, this.reputationService ); + this.skandha = new Skandha( + this.networkName, + this.chainId, + this.provider, + this.config, + this.logger + ); this.eth = new Eth( this.chainId, this.provider, this.userOpValidationService, this.mempoolService, + this.skandha, this.networkConfig, this.logger, this.nodeApi @@ -121,13 +129,6 @@ export class Executor { this.config, this.logger ); - this.skandha = new Skandha( - this.networkName, - this.chainId, - this.provider, - this.config, - this.logger - ); if (this.config.testingMode || options.bundlingMode == "manual") { this.bundlingService.setBundlingMode("manual"); diff --git a/packages/executor/src/modules/eth.ts b/packages/executor/src/modules/eth.ts index 4808691d..6114d4e3 100644 --- a/packages/executor/src/modules/eth.ts +++ b/packages/executor/src/modules/eth.ts @@ -29,6 +29,7 @@ import { EstimateUserOperationGasArgs, SendUserOperationGasArgs, } from "./interfaces"; +import { Skandha } from "./skandha"; export class Eth { private pvgEstimator: IPVGEstimator | null = null; @@ -38,6 +39,7 @@ export class Eth { private provider: ethers.providers.JsonRpcProvider, private userOpValidationService: UserOpValidationService, private mempoolService: MempoolService, + private skandhaModule: Skandha, private config: NetworkConfig, private logger: Logger, private nodeApi?: INodeAPI @@ -190,21 +192,11 @@ export class Eth { callGasLimit, }; - const gasFee = await getGasFee( - this.chainId, - this.provider, - this.config.etherscanApiKey, - { - entryPoint, - userOp: userOpToEstimate, - } - ); + const gasFee = await this.skandhaModule.getGasPrice(); if (this.pvgEstimator) { - userOpComplemented.maxFeePerGas = - gasFee.maxFeePerGas ?? gasFee.gasPrice ?? 1; - userOpComplemented.maxPriorityFeePerGas = - gasFee.maxPriorityFeePerGas ?? gasFee.gasPrice ?? 1; + userOpComplemented.maxFeePerGas = gasFee.maxFeePerGas; + userOpComplemented.maxPriorityFeePerGas = gasFee.maxPriorityFeePerGas; preVerificationGas = await this.pvgEstimator( entryPoint, userOpComplemented, diff --git a/packages/executor/src/services/BundlingService.ts b/packages/executor/src/services/BundlingService.ts index da4fb5b6..22f5e100 100644 --- a/packages/executor/src/services/BundlingService.ts +++ b/packages/executor/src/services/BundlingService.ts @@ -148,8 +148,7 @@ export class BundlingService { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { gasLimit, ...txWithoutGasLimit } = tx; // some chains, like Bifrost, don't allow setting gasLimit in estimateGas - const estimatedGasLimit = await wallet.estimateGas(txWithoutGasLimit); - tx.gasLimit = estimatedGasLimit; + await wallet.estimateGas(txWithoutGasLimit); } catch (err) { this.logger.error(err); for (const entry of entries) { diff --git a/packages/executor/src/services/MempoolService.ts b/packages/executor/src/services/MempoolService.ts index eb64ff3f..c319cd2d 100644 --- a/packages/executor/src/services/MempoolService.ts +++ b/packages/executor/src/services/MempoolService.ts @@ -3,6 +3,7 @@ import { IDbController } from "types/lib"; import RpcError from "types/lib/api/errors/rpc-error"; import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes"; import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint"; +import { getAddress } from "ethers/lib/utils"; import { getAddr, now } from "../utils"; import { MempoolEntry } from "../entities/MempoolEntry"; import { IMempoolEntry, MempoolEntrySerialized } from "../entities/interfaces"; diff --git a/packages/params/src/utils/userOp.ts b/packages/params/src/utils/userOp.ts index c161951d..5a676f8a 100644 --- a/packages/params/src/utils/userOp.ts +++ b/packages/params/src/utils/userOp.ts @@ -3,6 +3,7 @@ import { Bytes32, UintBn256 } from "types/lib/primitive/sszTypes"; import { fromHex, toHex } from "utils/lib"; import { BigNumber, BigNumberish } from "ethers"; import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint"; +import { getAddress } from "ethers/lib/utils"; const bigintToBigNumber = (bn: bigint): BigNumberish => { return BigNumber.from(UintBn256.fromJson(bn) as unknown as string); @@ -23,7 +24,7 @@ export const userOpHashToString = (hash: ts.Bytes32): string => { // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export const deserializeUserOp = (userOp: ts.UserOp) => { const dUserOp = { - sender: toHex(userOp.sender), + sender: getAddress(toHex(userOp.sender)), nonce: bigintToBigNumber(userOp.nonce), initCode: toHex(userOp.initCode), callData: toHex(userOp.callData), @@ -59,7 +60,7 @@ export const deserializeUserOpsWithEP = ( export const serializeUserOp = (userOp: UserOperationStruct): ts.UserOp => { return { - sender: fromHex(userOp.sender), + sender: fromHex(getAddress(userOp.sender)), nonce: bigNumberishToBigint(userOp.nonce), initCode: fromHex(userOp.initCode.toString()), callData: fromHex(userOp.callData.toString()), @@ -80,7 +81,7 @@ export const toUserOpsWithEP = ( blockHash: string ): ts.UserOpsWithEntryPoint => { return { - entry_point_contract: fromHex(entryPoint), + entry_point_contract: fromHex(getAddress(entryPoint)), chain_id: bigNumberishToBigint(chainId), user_operations: userOps.map((userOp) => serializeUserOp(userOp)), verified_at_block_hash: bigNumberishToBigint(blockHash),