implementations.go 3.7 KB
Newer Older
1
package opcm
2 3 4 5 6 7 8 9 10 11 12

import (
	"fmt"
	"math/big"

	"github.com/ethereum/go-ethereum/common"

	"github.com/ethereum-optimism/optimism/op-chain-ops/script"
)

type DeployImplementationsInput struct {
13
	Salt                            common.Hash
14 15 16 17 18
	WithdrawalDelaySeconds          *big.Int
	MinProposalSizeBytes            *big.Int
	ChallengePeriodSeconds          *big.Int
	ProofMaturityDelaySeconds       *big.Int
	DisputeGameFinalityDelaySeconds *big.Int
19
	MipsVersion                     *big.Int
20
	// Release version to set OPCM implementations for, of the format `op-contracts/vX.Y.Z`.
21 22 23 24
	Release               string
	SuperchainConfigProxy common.Address
	ProtocolVersionsProxy common.Address
	UseInterop            bool // if true, deploy Interop implementations
25

26
	OpcmProxyOwner       common.Address
27
	StandardVersionsToml string // contents of 'standard-versions-mainnet.toml' or 'standard-versions-sepolia.toml' file
28 29 30 31 32 33 34
}

func (input *DeployImplementationsInput) InputSet() bool {
	return true
}

type DeployImplementationsOutput struct {
35 36
	OpcmProxy                        common.Address
	OpcmImpl                         common.Address
37 38 39 40 41 42 43 44 45 46 47 48
	DelayedWETHImpl                  common.Address
	OptimismPortalImpl               common.Address
	PreimageOracleSingleton          common.Address
	MipsSingleton                    common.Address
	SystemConfigImpl                 common.Address
	L1CrossDomainMessengerImpl       common.Address
	L1ERC721BridgeImpl               common.Address
	L1StandardBridgeImpl             common.Address
	OptimismMintableERC20FactoryImpl common.Address
	DisputeGameFactoryImpl           common.Address
}

49
func (output *DeployImplementationsOutput) CheckOutput(input common.Address) error {
50 51 52 53 54 55 56
	return nil
}

type DeployImplementationsScript struct {
	Run func(input, output common.Address) error
}

57 58 59 60 61 62 63
func DeployImplementations(
	host *script.Host,
	input DeployImplementationsInput,
) (DeployImplementationsOutput, error) {
	var output DeployImplementationsOutput
	inputAddr := host.NewScriptAddress()
	outputAddr := host.NewScriptAddress()
64

65
	cleanupInput, err := script.WithPrecompileAtAddress[*DeployImplementationsInput](host, inputAddr, &input)
66
	if err != nil {
67
		return output, fmt.Errorf("failed to insert DeployImplementationsInput precompile: %w", err)
68 69 70
	}
	defer cleanupInput()

71
	cleanupOutput, err := script.WithPrecompileAtAddress[*DeployImplementationsOutput](host, outputAddr, &output,
72 73
		script.WithFieldSetter[*DeployImplementationsOutput])
	if err != nil {
74
		return output, fmt.Errorf("failed to insert DeployImplementationsOutput precompile: %w", err)
75 76 77 78 79 80 81
	}
	defer cleanupOutput()

	implContract := "DeployImplementations"
	if input.UseInterop {
		implContract = "DeployImplementationsInterop"
	}
82
	deployScript, cleanupDeploy, err := script.WithScript[DeployImplementationsScript](host, "DeployImplementations.s.sol", implContract)
83
	if err != nil {
84
		return output, fmt.Errorf("failed to load %s script: %w", implContract, err)
85 86 87
	}
	defer cleanupDeploy()

88
	opcmContract := "OPContractsManager"
89
	if input.UseInterop {
90
		opcmContract = "OPContractsManagerInterop"
91
	}
92 93
	if err := host.RememberOnLabel("OPContractsManager", opcmContract+".sol", opcmContract); err != nil {
		return output, fmt.Errorf("failed to link OPContractsManager label: %w", err)
94 95 96 97 98 99 100
	}

	// So we can see in detail where the SystemConfig interop initializer fails
	sysConfig := "SystemConfig"
	if input.UseInterop {
		sysConfig = "SystemConfigInterop"
	}
101 102
	if err := host.RememberOnLabel("SystemConfigImpl", sysConfig+".sol", sysConfig); err != nil {
		return output, fmt.Errorf("failed to link SystemConfig label: %w", err)
103 104 105
	}

	if err := deployScript.Run(inputAddr, outputAddr); err != nil {
106
		return output, fmt.Errorf("failed to run %s script: %w", implContract, err)
107 108 109 110
	}

	return output, nil
}