-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
intent.go
158 lines (109 loc) · 4.2 KB
/
intent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package state
import (
"fmt"
"math/big"
"strings"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
"github.com/ethereum/go-ethereum/common"
)
var emptyAddress common.Address
type Intent struct {
L1ChainID uint64 `json:"l1ChainID" toml:"l1ChainID"`
SuperchainRoles SuperchainRoles `json:"superchainRoles" toml:"-"`
FundDevAccounts bool `json:"fundDevAccounts" toml:"fundDevAccounts"`
ContractArtifactsURL *ArtifactsURL `json:"contractArtifactsURL" toml:"contractArtifactsURL"`
ContractsRelease string `json:"contractsRelease" toml:"contractsRelease"`
Chains []*ChainIntent `json:"chains" toml:"chains"`
GlobalDeployOverrides map[string]any `json:"globalDeployOverrides" toml:"globalDeployOverrides"`
}
func (c *Intent) L1ChainIDBig() *big.Int {
return big.NewInt(int64(c.L1ChainID))
}
func (c *Intent) Check() error {
if c.L1ChainID == 0 {
return fmt.Errorf("l1ChainID must be set")
}
if c.ContractsRelease == "dev" {
return c.checkDev()
}
return c.checkProd()
}
func (c *Intent) Chain(id common.Hash) (*ChainIntent, error) {
for i := range c.Chains {
if c.Chains[i].ID == id {
return c.Chains[i], nil
}
}
return nil, fmt.Errorf("chain %d not found", id)
}
func (c *Intent) WriteToFile(path string) error {
return jsonutil.WriteTOML(c, ioutil.ToAtomicFile(path, 0o755))
}
func (c *Intent) checkDev() error {
if c.SuperchainRoles.ProxyAdminOwner == emptyAddress {
return fmt.Errorf("proxyAdminOwner must be set")
}
if c.SuperchainRoles.ProtocolVersionsOwner == emptyAddress {
c.SuperchainRoles.ProtocolVersionsOwner = c.SuperchainRoles.ProxyAdminOwner
}
if c.SuperchainRoles.Guardian == emptyAddress {
c.SuperchainRoles.Guardian = c.SuperchainRoles.ProxyAdminOwner
}
if c.ContractArtifactsURL == nil {
return fmt.Errorf("contractArtifactsURL must be set in dev mode")
}
return nil
}
func (c *Intent) checkProd() error {
if !strings.HasPrefix(c.ContractsRelease, "op-contracts/") {
return fmt.Errorf("contractsVersion must be either the literal \"dev\" or start with \"op-contracts/\"")
}
return nil
}
type SuperchainRoles struct {
ProxyAdminOwner common.Address `json:"proxyAdminOwner" toml:"proxyAdminOwner"`
ProtocolVersionsOwner common.Address `json:"protocolVersionsOwner" toml:"protocolVersionsOwner"`
Guardian common.Address `json:"guardian" toml:"guardian"`
}
type ChainIntent struct {
ID common.Hash `json:"id" toml:"id"`
BaseFeeVaultRecipient common.Address `json:"baseFeeVaultRecipient" toml:"baseFeeVaultRecipient"`
L1FeeVaultRecipient common.Address `json:"l1FeeVaultRecipient" toml:"l1FeeVaultRecipient"`
SequencerFeeVaultRecipient common.Address `json:"sequencerFeeVaultRecipient" toml:"sequencerFeeVaultRecipient"`
Eip1559Denominator uint64 `json:"eip1559Denominator" toml:"eip1559Denominator"`
Eip1559Elasticity uint64 `json:"eip1559Elasticity" toml:"eip1559Elasticity"`
Roles ChainRoles `json:"roles" toml:"roles"`
DeployOverrides map[string]any `json:"deployOverrides" toml:"deployOverrides"`
}
type ChainRoles struct {
ProxyAdminOwner common.Address `json:"proxyAdminOwner" toml:"proxyAdminOwner"`
SystemConfigOwner common.Address `json:"systemConfigOwner" toml:"systemConfigOwner"`
GovernanceTokenOwner common.Address `json:"governanceTokenOwner" toml:"governanceTokenOwner"`
UnsafeBlockSigner common.Address `json:"unsafeBlockSigner" toml:"unsafeBlockSigner"`
Batcher common.Address `json:"batcher" toml:"batcher"`
Proposer common.Address `json:"proposer" toml:"proposer"`
Challenger common.Address `json:"challenger" toml:"challenger"`
}
func (c *ChainIntent) Check() error {
var emptyHash common.Hash
if c.ID == emptyHash {
return fmt.Errorf("id must be set")
}
if c.Roles.ProxyAdminOwner == emptyAddress {
return fmt.Errorf("proxyAdminOwner must be set")
}
if c.Roles.SystemConfigOwner == emptyAddress {
c.Roles.SystemConfigOwner = c.Roles.ProxyAdminOwner
}
if c.Roles.GovernanceTokenOwner == emptyAddress {
c.Roles.GovernanceTokenOwner = c.Roles.ProxyAdminOwner
}
if c.Roles.UnsafeBlockSigner == emptyAddress {
return fmt.Errorf("unsafeBlockSigner must be set")
}
if c.Roles.Batcher == emptyAddress {
return fmt.Errorf("batcher must be set")
}
return nil
}