@@ -5,16 +5,21 @@ import (
5
5
6
6
"github.com/ethereum/go-ethereum/common"
7
7
"github.com/ethereum/go-ethereum/common/hexutil"
8
- "github.com/ethereum/go-ethereum/ethclient "
8
+ "github.com/ethereum/go-ethereum/rpc "
9
9
"github.com/stackup-wallet/stackup-bundler/pkg/entrypoint/execution"
10
- "github.com/stackup-wallet/stackup-bundler/pkg/errors"
11
10
"github.com/stackup-wallet/stackup-bundler/pkg/userop"
12
11
)
13
12
13
+ // CallGasEstimate uses the simulateHandleOp method on the EntryPoint to derive an estimate for callGasLimit.
14
+ //
15
+ // TODO: This function requires an eth_call and a debug_traceCall. It could probably be optimized further by
16
+ // just using a debug_traceCall.
14
17
func CallGasEstimate (
15
- eth * ethclient .Client ,
18
+ rpc * rpc .Client ,
16
19
from common.Address ,
17
20
op * userop.UserOperation ,
21
+ chainID * big.Int ,
22
+ tracer string ,
18
23
) (uint64 , error ) {
19
24
data , err := op .ToMap ()
20
25
if err != nil {
@@ -28,19 +33,20 @@ func CallGasEstimate(
28
33
return 0 , err
29
34
}
30
35
31
- sim , err := execution .SimulateHandleOp (eth , from , simOp , op . Sender , op . CallData )
36
+ sim , err := execution .SimulateHandleOp (rpc , from , simOp , common. Address {}, [] byte {} )
32
37
if err != nil {
33
38
return 0 , err
34
39
}
35
- if ! sim .TargetSuccess {
36
- reason , err := errors .DecodeRevert (sim .TargetResult )
37
- if err != nil {
38
- return 0 , err
39
- }
40
- return 0 , errors .NewRPCError (errors .EXECUTION_REVERTED , reason , reason )
40
+
41
+ if err := execution .TraceSimulateHandleOp (rpc , from , op , chainID , tracer , common.Address {}, []byte {}); err != nil {
42
+ return 0 , err
41
43
}
42
44
43
45
tg := big .NewInt (0 ).Div (sim .Paid , op .MaxFeePerGas )
44
46
cgl := big .NewInt (0 ).Sub (tg , sim .PreOpGas )
45
- return cgl .Uint64 (), nil
47
+ call := NewDefaultOverhead ().NonZeroValueCall ()
48
+ if cgl .Cmp (call ) >= 1 {
49
+ return cgl .Uint64 (), nil
50
+ }
51
+ return call .Uint64 (), nil
46
52
}
0 commit comments