Commit 535bcb42 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #7535 from ethereum-optimism/feat/batch-no-calldata

op-chain-ops: option for skipping calldata encoding
parents 1335d991 db56aaa9
...@@ -6,6 +6,7 @@ package safe ...@@ -6,6 +6,7 @@ package safe
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"strings" "strings"
...@@ -19,7 +20,12 @@ import ( ...@@ -19,7 +20,12 @@ import (
) )
// Batch represents a Safe tx-builder transaction. // Batch represents a Safe tx-builder transaction.
// SkipCalldata will skip adding the calldata to the BatchTransaction.
// This is useful for when using the Safe UI because it prefers using
// the raw calldata when both the calldata and ABIs with arguments are
// present.
type Batch struct { type Batch struct {
SkipCalldata bool
Version string `json:"version"` Version string `json:"version"`
ChainID *big.Int `json:"chainId"` ChainID *big.Int `json:"chainId"`
CreatedAt uint64 `json:"createdAt"` CreatedAt uint64 `json:"createdAt"`
...@@ -29,7 +35,10 @@ type Batch struct { ...@@ -29,7 +35,10 @@ type Batch struct {
// AddCall will add a call to the batch. After a series of calls are // AddCall will add a call to the batch. After a series of calls are
// added to the batch, it can be serialized to JSON. // added to the batch, it can be serialized to JSON.
func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []any, iface abi.ABI) error { func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []any, iface *abi.ABI) error {
if iface == nil {
return errors.New("abi cannot be nil")
}
// Attempt to pull out the signature from the top level methods. // Attempt to pull out the signature from the top level methods.
// The abi package uses normalization that we do not want to be // The abi package uses normalization that we do not want to be
// coupled to, so attempt to search for the raw name if the top // coupled to, so attempt to search for the raw name if the top
...@@ -87,10 +96,13 @@ func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []an ...@@ -87,10 +96,13 @@ func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []an
To: to, To: to,
Value: value, Value: value,
Method: contractMethod, Method: contractMethod,
Data: data,
InputValues: inputValues, InputValues: inputValues,
} }
if !b.SkipCalldata {
batchTransaction.Data = data
}
b.Transactions = append(b.Transactions, batchTransaction) b.Transactions = append(b.Transactions, batchTransaction)
return nil return nil
......
...@@ -58,7 +58,7 @@ func TestBatchAddCallFinalizeWithdrawalTransaction(t *testing.T) { ...@@ -58,7 +58,7 @@ func TestBatchAddCallFinalizeWithdrawalTransaction(t *testing.T) {
to := common.Address{19: 0x01} to := common.Address{19: 0x01}
value := big.NewInt(222) value := big.NewInt(222)
require.NoError(t, batch.AddCall(to, value, sig, argument, portalABI)) require.NoError(t, batch.AddCall(to, value, sig, argument, &portalABI))
require.NoError(t, batch.Check()) require.NoError(t, batch.Check())
require.Equal(t, batch.Transactions[0].Signature(), "finalizeWithdrawalTransaction((uint256,address,address,uint256,uint256,bytes))") require.Equal(t, batch.Transactions[0].Signature(), "finalizeWithdrawalTransaction((uint256,address,address,uint256,uint256,bytes))")
...@@ -89,7 +89,7 @@ func TestBatchAddCallDespositTransaction(t *testing.T) { ...@@ -89,7 +89,7 @@ func TestBatchAddCallDespositTransaction(t *testing.T) {
[]byte{}, []byte{},
} }
require.NoError(t, batch.AddCall(to, value, sig, argument, portalABI)) require.NoError(t, batch.AddCall(to, value, sig, argument, &portalABI))
require.NoError(t, batch.Check()) require.NoError(t, batch.Check())
require.Equal(t, batch.Transactions[0].Signature(), "depositTransaction(address,uint256,uint64,bool,bytes)") require.Equal(t, batch.Transactions[0].Signature(), "depositTransaction(address,uint256,uint64,bool,bytes)")
......
...@@ -63,6 +63,7 @@ func L1CrossDomainMessenger(batch *safe.Batch, implementations superchain.Implem ...@@ -63,6 +63,7 @@ func L1CrossDomainMessenger(batch *safe.Batch, implementations superchain.Implem
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(list.L1CrossDomainMessengerProxy.String()), common.HexToAddress(list.L1CrossDomainMessengerProxy.String()),
...@@ -72,7 +73,7 @@ func L1CrossDomainMessenger(batch *safe.Batch, implementations superchain.Implem ...@@ -72,7 +73,7 @@ func L1CrossDomainMessenger(batch *safe.Batch, implementations superchain.Implem
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
...@@ -102,6 +103,7 @@ func L1ERC721Bridge(batch *safe.Batch, implementations superchain.Implementation ...@@ -102,6 +103,7 @@ func L1ERC721Bridge(batch *safe.Batch, implementations superchain.Implementation
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(list.L1ERC721BridgeProxy.String()), common.HexToAddress(list.L1ERC721BridgeProxy.String()),
...@@ -111,7 +113,7 @@ func L1ERC721Bridge(batch *safe.Batch, implementations superchain.Implementation ...@@ -111,7 +113,7 @@ func L1ERC721Bridge(batch *safe.Batch, implementations superchain.Implementation
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
...@@ -141,6 +143,7 @@ func L1StandardBridge(batch *safe.Batch, implementations superchain.Implementati ...@@ -141,6 +143,7 @@ func L1StandardBridge(batch *safe.Batch, implementations superchain.Implementati
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(list.L1StandardBridgeProxy.String()), common.HexToAddress(list.L1StandardBridgeProxy.String()),
...@@ -150,7 +153,7 @@ func L1StandardBridge(batch *safe.Batch, implementations superchain.Implementati ...@@ -150,7 +153,7 @@ func L1StandardBridge(batch *safe.Batch, implementations superchain.Implementati
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
...@@ -219,6 +222,7 @@ func L2OutputOracle(batch *safe.Batch, implementations superchain.Implementation ...@@ -219,6 +222,7 @@ func L2OutputOracle(batch *safe.Batch, implementations superchain.Implementation
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(list.L2OutputOracleProxy.String()), common.HexToAddress(list.L2OutputOracleProxy.String()),
...@@ -228,7 +232,7 @@ func L2OutputOracle(batch *safe.Batch, implementations superchain.Implementation ...@@ -228,7 +232,7 @@ func L2OutputOracle(batch *safe.Batch, implementations superchain.Implementation
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
...@@ -258,6 +262,7 @@ func OptimismMintableERC20Factory(batch *safe.Batch, implementations superchain. ...@@ -258,6 +262,7 @@ func OptimismMintableERC20Factory(batch *safe.Batch, implementations superchain.
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(list.OptimismMintableERC20FactoryProxy.String()), common.HexToAddress(list.OptimismMintableERC20FactoryProxy.String()),
...@@ -267,7 +272,7 @@ func OptimismMintableERC20Factory(batch *safe.Batch, implementations superchain. ...@@ -267,7 +272,7 @@ func OptimismMintableERC20Factory(batch *safe.Batch, implementations superchain.
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
...@@ -315,6 +320,7 @@ func OptimismPortal(batch *safe.Batch, implementations superchain.Implementation ...@@ -315,6 +320,7 @@ func OptimismPortal(batch *safe.Batch, implementations superchain.Implementation
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(list.OptimismPortalProxy.String()), common.HexToAddress(list.OptimismPortalProxy.String()),
...@@ -324,7 +330,7 @@ func OptimismPortal(batch *safe.Batch, implementations superchain.Implementation ...@@ -324,7 +330,7 @@ func OptimismPortal(batch *safe.Batch, implementations superchain.Implementation
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
...@@ -434,6 +440,7 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi ...@@ -434,6 +440,7 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi
if err != nil { if err != nil {
return err return err
} }
calldata = append(initialize.ID, calldata...)
args := []any{ args := []any{
common.HexToAddress(chainConfig.SystemConfigAddr.String()), common.HexToAddress(chainConfig.SystemConfigAddr.String()),
...@@ -443,7 +450,7 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi ...@@ -443,7 +450,7 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi
proxyAdmin := common.HexToAddress(list.ProxyAdmin.String()) proxyAdmin := common.HexToAddress(list.ProxyAdmin.String())
sig := "upgradeAndCall(address,address,bytes)" sig := "upgradeAndCall(address,address,bytes)"
if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, *proxyAdminABI); err != nil { if err := batch.AddCall(proxyAdmin, common.Big0, sig, args, proxyAdminABI); err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment