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

Commit

Permalink
Recalculate final PVG with estimated gas limit values (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j authored Apr 22, 2023
1 parent cbb1388 commit 4580464
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,33 @@ func (i *Client) EstimateUserOperationGas(op map[string]any, ep string) (*gas.Ga
hash := userOp.GetUserOpHash(epAddr, i.chainID)
l = l.WithValues("userop_hash", hash)

// Estimate gas limits
vg, cg, err := i.getGasEstimate(epAddr, userOp)
if err != nil {
l.Error(err, "eth_estimateUserOperationGas error")
return nil, err
}

// Create a new op with updated gas limits
data, err := userOp.ToMap()
if err != nil {
l.Error(err, "eth_estimateUserOperationGas error")
return nil, err
}
data["verificationGasLimit"] = hexutil.EncodeBig(big.NewInt(int64(vg)))
data["callGasLimit"] = hexutil.EncodeBig(big.NewInt(int64(cg)))
userOp, err = userop.New(data)
if err != nil {
l.Error(err, "eth_estimateUserOperationGas error")
return nil, err
}

// Return gas values with a PVG calculation that takes into account updated gas limits.
l.Info("eth_estimateUserOperationGas ok")
return &gas.GasEstimates{
PreVerificationGas: gas.NewDefaultOverhead().CalcPreVerificationGas(userOp),
VerificationGas: big.NewInt(int64(vg)),
CallGasLimit: big.NewInt(int64(cg)),
VerificationGas: userOp.VerificationGasLimit,
CallGasLimit: userOp.CallGasLimit,
}, nil
}

Expand Down

0 comments on commit 4580464

Please sign in to comment.