-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-chain-ops: multi L2 deploy progress
- Loading branch information
1 parent
b1ccf4d
commit b97758d
Showing
5 changed files
with
116 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
package genz | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
|
||
"github.com/ethereum-optimism/optimism/op-chain-ops/script" | ||
) | ||
|
||
var deployConfigAddr = common.Address(crypto.Keccak256([]byte("optimism.deployconfig"))[12:]) | ||
var deploymentRegistryAddr = common.Address(crypto.Keccak256([]byte("optimism.deploymentregistry"))[12:]) | ||
|
||
func WithPrecompileAtAddress[E any](h *script.Host, addr common.Address, elem E) (cleanup func(), err error) { | ||
precompile, err := script.NewPrecompile[E](elem) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to construct precompile: %w", err) | ||
} | ||
_ = precompile | ||
// set code to []byte{0} | ||
// override precompile | ||
return // TODO | ||
} | ||
|
||
func WithPrecompile(h *script.Host, precompile any) (addr common.Address, cleanup func()) { | ||
// create tmp addr | ||
// set code to []byte{0} | ||
// override precompile | ||
return // TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package script | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
func checkABI(abiData *abi.ABI, methodSignature string) bool { | ||
for _, m := range abiData.Methods { | ||
if m.Sig == methodSignature { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func WithScript[B any](h *Host, name string, contract string) (b *B, cleanup func(), err error) { | ||
// load contract artifact | ||
artifact, err := h.af.ReadArtifact(name, contract) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("could not load script artifact: %w", err) | ||
} | ||
|
||
// TODO compute address of script contract to be deployed | ||
addr := common.Address{} | ||
|
||
// init bindings (with ABI check) | ||
bindings, err := MakeBindings[B](h.ScriptBackendFn(addr), func(abiDef string) bool { | ||
return checkABI(&artifact.ABI, abiDef) | ||
}) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to make bindings: %w", err) | ||
} | ||
|
||
// TODO deploy the script contract | ||
|
||
// TODO cleanup func to remove script contract | ||
return bindings, nil, errors.New("TODO") | ||
} | ||
|
||
// WithPrecompileAtAddress turns a struct into a precompile, | ||
// and inserts it as override at the given address in the host. | ||
// A cleanup function is returned, to remove the precompile override again. | ||
func WithPrecompileAtAddress[E any](h *Host, addr common.Address, elem E) (cleanup func(), err error) { | ||
if h.HasPrecompileOverride(addr) { | ||
return nil, fmt.Errorf("already have existing precompile override at %s", addr) | ||
} | ||
precompile, err := NewPrecompile[E](elem) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to construct precompile: %w", err) | ||
} | ||
h.SetPrecompile(addr, precompile) | ||
return func() { | ||
h.SetPrecompile(addr, nil) | ||
}, nil | ||
} |