Commit ee5c794d authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-deployer: Clean up to use latest libs (#13257)

parent 0648499c
......@@ -7,8 +7,6 @@ import (
"math/big"
"strings"
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum-optimism/optimism/op-chain-ops/script/forking"
artifacts2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"
......@@ -165,35 +163,18 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
}
host, err := env.DefaultScriptHost(
host, err := env.DefaultForkedScriptHost(
ctx,
bcaster,
lgr,
chainDeployer,
artifactsFS,
script.WithForkHook(func(cfg *script.ForkConfig) (forking.ForkSource, error) {
src, err := forking.RPCSourceByNumber(cfg.URLOrAlias, l1RPC, *cfg.BlockNumber)
if err != nil {
return nil, fmt.Errorf("failed to create RPC fork source: %w", err)
}
return forking.Cache(src), nil
}),
l1RPC,
)
if err != nil {
return fmt.Errorf("failed to create script host: %w", err)
}
latest, err := l1Client.HeaderByNumber(ctx, nil)
if err != nil {
return fmt.Errorf("failed to get latest block: %w", err)
}
if _, err := host.CreateSelectFork(
script.ForkWithURLOrAlias("main"),
script.ForkWithBlockNumberU256(latest.Number),
); err != nil {
return fmt.Errorf("failed to select fork: %w", err)
}
var release string
if cfg.ArtifactsLocator.IsTag() {
release = cfg.ArtifactsLocator.Tag
......
......@@ -6,8 +6,6 @@ import (
"fmt"
"strings"
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum-optimism/optimism/op-chain-ops/script/forking"
artifacts2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"
"github.com/ethereum/go-ethereum/rpc"
......@@ -179,35 +177,18 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
return fmt.Errorf("failed to create broadcaster: %w", err)
}
host, err := env.DefaultScriptHost(
host, err := env.DefaultForkedScriptHost(
ctx,
bcaster,
lgr,
chainDeployer,
artifactsFS,
script.WithForkHook(func(forkCfg *script.ForkConfig) (forking.ForkSource, error) {
src, err := forking.RPCSourceByNumber(forkCfg.URLOrAlias, l1Rpc, *forkCfg.BlockNumber)
if err != nil {
return nil, fmt.Errorf("failed to create RPC fork source: %w", err)
}
return forking.Cache(src), nil
}),
l1Rpc,
)
if err != nil {
return fmt.Errorf("failed to create L1 script host: %w", err)
}
latest, err := l1Client.HeaderByNumber(ctx, nil)
if err != nil {
return fmt.Errorf("failed to get latest block: %w", err)
}
if _, err := host.CreateSelectFork(
script.ForkWithURLOrAlias("main"),
script.ForkWithBlockNumberU256(latest.Number),
); err != nil {
return fmt.Errorf("failed to select fork: %w", err)
}
var release string
if cfg.ArtifactsLocator.IsTag() {
release = cfg.ArtifactsLocator.Tag
......
......@@ -6,6 +6,8 @@ import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/rpc"
artifacts2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"
"github.com/ethereum/go-ethereum/common"
......@@ -123,11 +125,13 @@ func MIPS(ctx context.Context, cfg MIPSConfig) error {
}
}()
l1Client, err := ethclient.Dial(cfg.L1RPCUrl)
l1RPC, err := rpc.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
}
l1Client := ethclient.NewClient(l1RPC)
chainID, err := l1Client.ChainID(ctx)
if err != nil {
return fmt.Errorf("failed to get chain ID: %w", err)
......@@ -147,21 +151,17 @@ func MIPS(ctx context.Context, cfg MIPSConfig) error {
return fmt.Errorf("failed to create broadcaster: %w", err)
}
nonce, err := l1Client.NonceAt(ctx, chainDeployer, nil)
if err != nil {
return fmt.Errorf("failed to get starting nonce: %w", err)
}
host, err := env.DefaultScriptHost(
host, err := env.DefaultForkedScriptHost(
ctx,
bcaster,
lgr,
chainDeployer,
artifactsFS,
l1RPC,
)
if err != nil {
return fmt.Errorf("failed to create script host: %w", err)
}
host.SetNonce(chainDeployer, nonce)
var release string
if cfg.ArtifactsLocator.IsTag() {
......
package opcm
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
......@@ -24,41 +22,9 @@ func (output *DeployAsteriscOutput) CheckOutput(input common.Address) error {
return nil
}
type DeployAsteriscScript struct {
Run func(input, output common.Address) error
}
func DeployAsterisc(
host *script.Host,
input DeployAsteriscInput,
) (DeployAsteriscOutput, error) {
var output DeployAsteriscOutput
inputAddr := host.NewScriptAddress()
outputAddr := host.NewScriptAddress()
cleanupInput, err := script.WithPrecompileAtAddress[*DeployAsteriscInput](host, inputAddr, &input)
if err != nil {
return output, fmt.Errorf("failed to insert DeployAsteriscInput precompile: %w", err)
}
defer cleanupInput()
cleanupOutput, err := script.WithPrecompileAtAddress[*DeployAsteriscOutput](host, outputAddr, &output,
script.WithFieldSetter[*DeployAsteriscOutput])
if err != nil {
return output, fmt.Errorf("failed to insert DeployAsteriscOutput precompile: %w", err)
}
defer cleanupOutput()
implContract := "DeployAsterisc"
deployScript, cleanupDeploy, err := script.WithScript[DeployAsteriscScript](host, "DeployAsterisc.s.sol", implContract)
if err != nil {
return output, fmt.Errorf("failed to load %s script: %w", implContract, err)
}
defer cleanupDeploy()
if err := deployScript.Run(inputAddr, outputAddr); err != nil {
return output, fmt.Errorf("failed to run %s script: %w", implContract, err)
}
return output, nil
return RunBasicScript[DeployAsteriscInput, DeployAsteriscOutput](host, input, "DeployAsterisc.s.sol", "DeployAsterisc")
}
package opcm
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
......@@ -31,41 +30,9 @@ func (output *DeployDelayedWETHOutput) CheckOutput(input common.Address) error {
return nil
}
type DeployDelayedWETHScript struct {
Run func(input, output common.Address) error
}
func DeployDelayedWETH(
host *script.Host,
input DeployDelayedWETHInput,
) (DeployDelayedWETHOutput, error) {
var output DeployDelayedWETHOutput
inputAddr := host.NewScriptAddress()
outputAddr := host.NewScriptAddress()
cleanupInput, err := script.WithPrecompileAtAddress[*DeployDelayedWETHInput](host, inputAddr, &input)
if err != nil {
return output, fmt.Errorf("failed to insert DeployDelayedWETHInput precompile: %w", err)
}
defer cleanupInput()
cleanupOutput, err := script.WithPrecompileAtAddress[*DeployDelayedWETHOutput](host, outputAddr, &output,
script.WithFieldSetter[*DeployDelayedWETHOutput])
if err != nil {
return output, fmt.Errorf("failed to insert DeployDelayedWETHOutput precompile: %w", err)
}
defer cleanupOutput()
implContract := "DeployDelayedWETH"
deployScript, cleanupDeploy, err := script.WithScript[DeployDelayedWETHScript](host, "DeployDelayedWETH.s.sol", implContract)
if err != nil {
return output, fmt.Errorf("failed to load %s script: %w", implContract, err)
}
defer cleanupDeploy()
if err := deployScript.Run(inputAddr, outputAddr); err != nil {
return output, fmt.Errorf("failed to run %s script: %w", implContract, err)
}
return output, nil
return RunBasicScript[DeployDelayedWETHInput, DeployDelayedWETHOutput](host, input, "DeployDelayedWETH.s.sol", "DeployDelayedWETH")
}
package opcm
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
......@@ -46,33 +44,5 @@ func DeployDisputeGame(
host *script.Host,
input DeployDisputeGameInput,
) (DeployDisputeGameOutput, error) {
var output DeployDisputeGameOutput
inputAddr := host.NewScriptAddress()
outputAddr := host.NewScriptAddress()
cleanupInput, err := script.WithPrecompileAtAddress[*DeployDisputeGameInput](host, inputAddr, &input)
if err != nil {
return output, fmt.Errorf("failed to insert DeployDisputeGameInput precompile: %w", err)
}
defer cleanupInput()
cleanupOutput, err := script.WithPrecompileAtAddress[*DeployDisputeGameOutput](host, outputAddr, &output,
script.WithFieldSetter[*DeployDisputeGameOutput])
if err != nil {
return output, fmt.Errorf("failed to insert DeployDisputeGameOutput precompile: %w", err)
}
defer cleanupOutput()
implContract := "DeployDisputeGame"
deployScript, cleanupDeploy, err := script.WithScript[DeployDisputeGameScript](host, "DeployDisputeGame.s.sol", implContract)
if err != nil {
return output, fmt.Errorf("failed to load %s script: %w", implContract, err)
}
defer cleanupDeploy()
if err := deployScript.Run(inputAddr, outputAddr); err != nil {
return output, fmt.Errorf("failed to run %s script: %w", implContract, err)
}
return output, nil
return RunBasicScript[DeployDisputeGameInput, DeployDisputeGameOutput](host, input, "DeployDisputeGame.s.sol", "DeployDisputeGame")
}
package opcm
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
......@@ -33,33 +31,5 @@ func DeployMIPS(
host *script.Host,
input DeployMIPSInput,
) (DeployMIPSOutput, error) {
var output DeployMIPSOutput
inputAddr := host.NewScriptAddress()
outputAddr := host.NewScriptAddress()
cleanupInput, err := script.WithPrecompileAtAddress[*DeployMIPSInput](host, inputAddr, &input)
if err != nil {
return output, fmt.Errorf("failed to insert DeployMIPSInput precompile: %w", err)
}
defer cleanupInput()
cleanupOutput, err := script.WithPrecompileAtAddress[*DeployMIPSOutput](host, outputAddr, &output,
script.WithFieldSetter[*DeployMIPSOutput])
if err != nil {
return output, fmt.Errorf("failed to insert DeployMIPSOutput precompile: %w", err)
}
defer cleanupOutput()
implContract := "DeployMIPS"
deployScript, cleanupDeploy, err := script.WithScript[DeployMIPSScript](host, "DeployMIPS.s.sol", implContract)
if err != nil {
return output, fmt.Errorf("failed to load %s script: %w", implContract, err)
}
defer cleanupDeploy()
if err := deployScript.Run(inputAddr, outputAddr); err != nil {
return output, fmt.Errorf("failed to run %s script: %w", implContract, err)
}
return output, nil
return RunBasicScript[DeployMIPSInput, DeployMIPSOutput](host, input, "DeployMIPS.s.sol", "DeployMIPS")
}
......@@ -88,36 +88,7 @@ func DeployOPChainIsthmus(host *script.Host, input DeployOPChainInputIsthmus) (D
}
func deployOPChain[T any](host *script.Host, input T) (DeployOPChainOutput, error) {
var dco DeployOPChainOutput
inputAddr := host.NewScriptAddress()
outputAddr := host.NewScriptAddress()
cleanupInput, err := script.WithPrecompileAtAddress[*T](host, inputAddr, &input)
if err != nil {
return dco, fmt.Errorf("failed to insert DeployOPChainInput precompile: %w", err)
}
defer cleanupInput()
host.Label(inputAddr, "DeployOPChainInput")
cleanupOutput, err := script.WithPrecompileAtAddress[*DeployOPChainOutput](host, outputAddr, &dco,
script.WithFieldSetter[*DeployOPChainOutput])
if err != nil {
return dco, fmt.Errorf("failed to insert DeployOPChainOutput precompile: %w", err)
}
defer cleanupOutput()
host.Label(outputAddr, "DeployOPChainOutput")
deployScript, cleanupDeploy, err := script.WithScript[DeployOPChainScript](host, "DeployOPChain.s.sol", "DeployOPChain")
if err != nil {
return dco, fmt.Errorf("failed to load DeployOPChain script: %w", err)
}
defer cleanupDeploy()
if err := deployScript.Run(inputAddr, outputAddr); err != nil {
return dco, fmt.Errorf("failed to run DeployOPChain script: %w", err)
}
return dco, nil
return RunBasicScript[T, DeployOPChainOutput](host, input, "DeployOPChain.s.sol", "DeployOPChain")
}
type ReadImplementationAddressesInput struct {
......
......@@ -40,10 +40,7 @@ func DeployOPCM(
host *script.Host,
input DeployOPCMInput,
) (DeployOPCMOutput, error) {
scriptFile := "DeployOPCM.s.sol"
contractName := "DeployOPCM"
out, err := RunBasicScript[DeployOPCMInput, DeployOPCMOutput](host, input, scriptFile, contractName)
out, err := RunBasicScript[DeployOPCMInput, DeployOPCMOutput](host, input, "DeployOPCM.s.sol", "DeployOPCM")
if err != nil {
return DeployOPCMOutput{}, fmt.Errorf("failed to deploy OPCM: %w", err)
}
......
package opcm
import (
"fmt"
"math/big"
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
......@@ -53,37 +52,5 @@ type DeploySuperchainOpts struct {
}
func DeploySuperchain(h *script.Host, input DeploySuperchainInput) (DeploySuperchainOutput, error) {
var dso DeploySuperchainOutput
inputAddr := h.NewScriptAddress()
outputAddr := h.NewScriptAddress()
cleanupInput, err := script.WithPrecompileAtAddress[*DeploySuperchainInput](h, inputAddr, &input)
if err != nil {
return dso, fmt.Errorf("failed to insert DeploySuperchainInput precompile: %w", err)
}
defer cleanupInput()
cleanupOutput, err := script.WithPrecompileAtAddress[*DeploySuperchainOutput](
h,
outputAddr,
&dso,
script.WithFieldSetter[*DeploySuperchainOutput],
)
if err != nil {
return dso, fmt.Errorf("failed to insert DeploySuperchainOutput precompile: %w", err)
}
defer cleanupOutput()
deployScript, cleanupDeploy, err := script.WithScript[DeploySuperchainScript](h, "DeploySuperchain.s.sol", "DeploySuperchain")
if err != nil {
return dso, fmt.Errorf("failed to load DeploySuperchain script: %w", err)
}
defer cleanupDeploy()
if err := deployScript.Run(inputAddr, outputAddr); err != nil {
return dso, fmt.Errorf("failed to run DeploySuperchain script: %w", err)
}
return dso, nil
return RunBasicScript[DeploySuperchainInput, DeploySuperchainOutput](h, input, "DeploySuperchain.s.sol", "DeploySuperchain")
}
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