Skip to content
Merged
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
20 changes: 11 additions & 9 deletions op-deployer/pkg/deployer/opcm/read_superchain_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import (
)

type ReadSuperchainDeploymentInput struct {
OPCMAddress common.Address `abi:"opcmAddress"`
OPCMAddress common.Address `abi:"opcmAddress"` // TODO(#18612): Remove OPCMAddress field when OPCMv1 gets deprecated
SuperchainConfigProxy common.Address `abi:"superchainConfigProxy"`
}

type ReadSuperchainDeploymentOutput struct {
ProtocolVersionsImpl common.Address
ProtocolVersionsProxy common.Address
SuperchainConfigImpl common.Address
SuperchainConfigProxy common.Address
SuperchainProxyAdmin common.Address

Guardian common.Address
// TODO(#18612): Remove ProtocolVersions fields when OPCMv1 gets deprecated
ProtocolVersionsImpl common.Address
ProtocolVersionsProxy common.Address
ProtocolVersionsOwner common.Address
SuperchainProxyAdminOwner common.Address
RecommendedProtocolVersion [32]byte
RequiredProtocolVersion [32]byte

SuperchainConfigImpl common.Address
SuperchainConfigProxy common.Address
SuperchainProxyAdmin common.Address
Guardian common.Address
SuperchainProxyAdminOwner common.Address
}

type ReadSuperchainDeploymentScript script.DeployScriptWithOutput[ReadSuperchainDeploymentInput, ReadSuperchainDeploymentOutput]
Expand Down
35 changes: 25 additions & 10 deletions op-deployer/pkg/deployer/pipeline/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,37 @@ func InitLiveStrategy(ctx context.Context, env *Env, intent *state.Intent, st *s
}

hasPredeployedOPCM := intent.OPCMAddress != nil
hasSuperchainConfigProxy := intent.SuperchainConfigProxy != nil

if hasPredeployedOPCM {
if intent.SuperchainConfigProxy != nil {
return fmt.Errorf("cannot set superchain config proxy for predeployed OPCM")
if hasPredeployedOPCM || hasSuperchainConfigProxy {
if intent.SuperchainRoles != nil {
return fmt.Errorf("cannot set superchain roles when using predeployed OPCM or SuperchainConfig")
}

if intent.SuperchainRoles != nil {
return fmt.Errorf("cannot set superchain roles for predeployed OPCM")
opcmAddr := common.Address{}
if hasPredeployedOPCM {
opcmAddr = *intent.OPCMAddress
}

superDeployment, superRoles, err := PopulateSuperchainState(env.L1ScriptHost, *intent.OPCMAddress)
superchainConfigAddr := common.Address{}
if hasSuperchainConfigProxy {
superchainConfigAddr = *intent.SuperchainConfigProxy
}

// The ReadSuperchainDeployment script (packages/contracts-bedrock/scripts/deploy/ReadSuperchainDeployment.s.sol)
// uses the OPCM's semver version (>= 7.0.0 indicates v2) to determine how to populate the superchain state:
// - OPCMv1 (< 7.0.0): Queries the OPCM contract to get SuperchainConfig and ProtocolVersions
// - OPCMv2 (>= 7.0.0): Uses the provided SuperchainConfigProxy address; ProtocolVersions is deprecated
superDeployment, superRoles, err := PopulateSuperchainState(env.L1ScriptHost, opcmAddr, superchainConfigAddr)
if err != nil {
return fmt.Errorf("error populating superchain state: %w", err)
}
st.SuperchainDeployment = superDeployment
st.SuperchainRoles = superRoles
if st.ImplementationsDeployment == nil {

if hasPredeployedOPCM && st.ImplementationsDeployment == nil {
st.ImplementationsDeployment = &addresses.ImplementationsContracts{
OpcmImpl: *intent.OPCMAddress,
OpcmImpl: opcmAddr,
}
}
}
Expand Down Expand Up @@ -125,14 +137,17 @@ func immutableErr(field string, was, is any) error {
return fmt.Errorf("%s is immutable: was %v, is %v", field, was, is)
}

func PopulateSuperchainState(host *script.Host, opcmAddr common.Address) (*addresses.SuperchainContracts, *addresses.SuperchainRoles, error) {
// TODO(#18612): Remove OPCMAddress field when OPCMv1 gets deprecated
// TODO(#18612): Remove ProtocolVersions fields when OPCMv1 gets deprecated
func PopulateSuperchainState(host *script.Host, opcmAddr common.Address, superchainConfigProxy common.Address) (*addresses.SuperchainContracts, *addresses.SuperchainRoles, error) {
readScript, err := opcm.NewReadSuperchainDeploymentScript(host)
if err != nil {
return nil, nil, fmt.Errorf("error generating read superchain deployment script: %w", err)
}

out, err := readScript.Run(opcm.ReadSuperchainDeploymentInput{
OPCMAddress: opcmAddr,
OPCMAddress: opcmAddr,
SuperchainConfigProxy: superchainConfigProxy,
})
if err != nil {
return nil, nil, fmt.Errorf("error reading superchain deployment: %w", err)
Expand Down
Loading