Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 4580464

Browse files
authored
Recalculate final PVG with estimated gas limit values (#150)
1 parent cbb1388 commit 4580464

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pkg/client/client.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,33 @@ func (i *Client) EstimateUserOperationGas(op map[string]any, ep string) (*gas.Ga
162162
hash := userOp.GetUserOpHash(epAddr, i.chainID)
163163
l = l.WithValues("userop_hash", hash)
164164

165+
// Estimate gas limits
165166
vg, cg, err := i.getGasEstimate(epAddr, userOp)
166167
if err != nil {
167168
l.Error(err, "eth_estimateUserOperationGas error")
168169
return nil, err
169170
}
170171

172+
// Create a new op with updated gas limits
173+
data, err := userOp.ToMap()
174+
if err != nil {
175+
l.Error(err, "eth_estimateUserOperationGas error")
176+
return nil, err
177+
}
178+
data["verificationGasLimit"] = hexutil.EncodeBig(big.NewInt(int64(vg)))
179+
data["callGasLimit"] = hexutil.EncodeBig(big.NewInt(int64(cg)))
180+
userOp, err = userop.New(data)
181+
if err != nil {
182+
l.Error(err, "eth_estimateUserOperationGas error")
183+
return nil, err
184+
}
185+
186+
// Return gas values with a PVG calculation that takes into account updated gas limits.
171187
l.Info("eth_estimateUserOperationGas ok")
172188
return &gas.GasEstimates{
173189
PreVerificationGas: gas.NewDefaultOverhead().CalcPreVerificationGas(userOp),
174-
VerificationGas: big.NewInt(int64(vg)),
175-
CallGasLimit: big.NewInt(int64(cg)),
190+
VerificationGas: userOp.VerificationGasLimit,
191+
CallGasLimit: userOp.CallGasLimit,
176192
}, nil
177193
}
178194

0 commit comments

Comments
 (0)