1- import { BigNumber , ethers } from "ethers" ;
1+ import { BigNumber , BigNumberish , ethers } from "ethers" ;
22import { arrayify , hexlify } from "ethers/lib/utils" ;
33import RpcError from "types/lib/api/errors/rpc-error" ;
44import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes" ;
@@ -13,6 +13,9 @@ import {
1313 UserOperationReceipt ,
1414} from "types/lib/api/interfaces" ;
1515import { EntryPoint__factory } from "types/lib/executor/contracts/factories" ;
16+ import { NetworkName } from "types/lib" ;
17+ import { estimateArbitrumPVG } from "params/lib/gas-estimation/arbitrum" ;
18+ import { IPVGEstimator } from "params/lib/types/IPVGEstimator" ;
1619import { NetworkConfig } from "../config" ;
1720import { deepHexlify , packUserOp } from "../utils" ;
1821import { UserOpValidationService , MempoolService } from "../services" ;
@@ -23,13 +26,22 @@ import {
2326} from "./interfaces" ;
2427
2528export class Eth {
29+ private pvgEstimator : IPVGEstimator | null = null ;
30+
2631 constructor (
32+ private networkName : NetworkName ,
2733 private provider : ethers . providers . JsonRpcProvider ,
2834 private userOpValidationService : UserOpValidationService ,
2935 private mempoolService : MempoolService ,
3036 private config : NetworkConfig ,
3137 private logger : Logger
32- ) { }
38+ ) {
39+ if (
40+ [ "arbitrum" , "arbitrumNitro" , "arbitrumNova" ] . includes ( this . networkName )
41+ ) {
42+ this . pvgEstimator = estimateArbitrumPVG ( this . provider ) ;
43+ }
44+ }
3345
3446 /**
3547 *
@@ -86,14 +98,21 @@ export class Eth {
8698 preVerificationGas : 0 ,
8799 ...userOp ,
88100 } ;
89- const preVerificationGas = this . calcPreVerificationGas ( userOp ) ;
101+ let preVerificationGas : BigNumberish = this . calcPreVerificationGas ( userOp ) ;
90102 userOpComplemented . preVerificationGas = preVerificationGas ;
91103
92104 const { returnInfo } =
93105 await this . userOpValidationService . validateForEstimation (
94106 userOpComplemented ,
95107 entryPoint
96108 ) ;
109+ if ( this . pvgEstimator ) {
110+ preVerificationGas = await this . pvgEstimator (
111+ entryPoint ,
112+ userOpComplemented ,
113+ preVerificationGas
114+ ) ;
115+ }
97116
98117 // eslint-disable-next-line prefer-const
99118 let { preOpGas, validAfter, validUntil } = returnInfo ;
@@ -110,7 +129,7 @@ export class Eth {
110129 err . message . match ( / r e a s o n = " ( .* ?) " / ) ?. at ( 1 ) ?? "execution reverted" ;
111130 throw new RpcError ( message , RpcErrorCodes . EXECUTION_REVERTED ) ;
112131 } ) ;
113- // const preVerificationGas = this.calcPreVerificationGas(userOp);
132+
114133 const verificationGas = BigNumber . from ( preOpGas ) . toNumber ( ) ;
115134 validAfter = BigNumber . from ( validAfter ) ;
116135 validUntil = BigNumber . from ( validUntil ) ;
0 commit comments