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

OP stack: use getL1FeeUpperBound for PVG calculations #397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/gas/pvg.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func CalcOptimismPVGWithEthClient(
if err != nil {
return nil, err
}
ge, err := gaspriceoracle.GetL1FeeMethod.Inputs.Pack(data)
ge, err := gaspriceoracle.GetL1FeeUpperBoundMethod.Inputs.Pack(big.NewInt(int64(len(data))))
if err != nil {
return nil, err
}
Expand All @@ -146,15 +146,15 @@ func CalcOptimismPVGWithEthClient(
req := map[string]any{
"from": common.HexToAddress("0x"),
"to": gaspriceoracle.PrecompileAddress,
"data": hexutil.Encode(append(gaspriceoracle.GetL1FeeMethod.ID, ge...)),
"data": hexutil.Encode(append(gaspriceoracle.GetL1FeeUpperBoundMethod.ID, ge...)),
}
var out any
if err := rpc.Call(&out, "eth_call", &req, "latest"); err != nil {
return nil, err
}

// Get L1Fee and L2Price
l1fee, err := gaspriceoracle.DecodeGetL1FeeMethodOutput(out)
l1fee, err := gaspriceoracle.DecodeGetL1FeeUpperBoundOutput(out)
if err != nil {
return nil, err
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/optimism/gaspriceoracle/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,25 @@ import (
)

var (
bytesT, _ = abi.NewType("bytes", "", nil)
uint256T, _ = abi.NewType("uint256", "", nil)

GetL1FeeMethod = abi.NewMethod(
"getL1Fee",
"getL1Fee",
GetL1FeeUpperBoundMethod = abi.NewMethod(
"getL1FeeUpperBound",
"getL1FeeUpperBound",
abi.Function,
"",
false,
false,
abi.Arguments{
{Name: "data", Type: bytesT},
{Name: "data", Type: uint256T},
},
abi.Arguments{
{Name: "fee", Type: uint256T},
},
)
)

func DecodeGetL1FeeMethodOutput(out any) (*big.Int, error) {
func DecodeGetL1FeeUpperBoundOutput(out any) (*big.Int, error) {
hex, ok := out.(string)
if !ok {
return nil, errors.New("getL1Fee: cannot assert type: hex is not of type string")
Expand All @@ -39,7 +38,7 @@ func DecodeGetL1FeeMethodOutput(out any) (*big.Int, error) {
return nil, fmt.Errorf("getL1Fee: %s", err)
}

args, err := GetL1FeeMethod.Outputs.Unpack(data)
args, err := GetL1FeeUpperBoundMethod.Outputs.Unpack(data)
if err != nil {
return nil, fmt.Errorf("getL1Fee: %s", err)
}
Expand Down
Loading