-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathopchain.go
110 lines (97 loc) · 3.64 KB
/
opchain.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
package pipeline
import (
"context"
"fmt"
"math/big"
"os"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer/opsm"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer/state"
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum/go-ethereum/common"
)
func DeployOPChain(ctx context.Context, env *Env, intent *state.Intent, st *state.State, chainID common.Hash) error {
lgr := env.Logger.New("stage", "deploy-opchain")
if !shouldDeployOPChain(intent, st, chainID) {
lgr.Info("opchain deployment not needed")
return nil
}
lgr.Info("deploying OP chain", "id", chainID.Hex())
var artifactsFS foundry.StatDirFs
var err error
if intent.ContractArtifactsURL.Scheme == "file" {
fs := os.DirFS(intent.ContractArtifactsURL.Path)
artifactsFS = fs.(foundry.StatDirFs)
} else {
return fmt.Errorf("only file:// artifacts URLs are supported")
}
thisIntent, err := intent.Chain(chainID)
if err != nil {
return fmt.Errorf("failed to get chain intent: %w", err)
}
var dco opsm.DeployOPChainOutput
err = CallScriptBroadcast(
ctx,
CallScriptBroadcastOpts{
L1ChainID: big.NewInt(int64(intent.L1ChainID)),
Logger: lgr,
ArtifactsFS: artifactsFS,
Deployer: env.Deployer,
Signer: env.Signer,
Client: env.L1Client,
Broadcaster: KeyedBroadcaster,
Handler: func(host *script.Host) error {
host.ImportState(st.ImplementationsDeployment.StateDump)
dco, err = opsm.DeployOPChain(
host,
opsm.DeployOPChainInput{
OpChainProxyAdminOwner: thisIntent.Roles.ProxyAdminOwner,
SystemConfigOwner: thisIntent.Roles.SystemConfigOwner,
Batcher: thisIntent.Roles.Batcher,
UnsafeBlockSigner: thisIntent.Roles.UnsafeBlockSigner,
Proposer: thisIntent.Roles.Proposer,
Challenger: thisIntent.Roles.Challenger,
BasefeeScalar: 1368,
BlobBaseFeeScalar: 801949,
L2ChainId: chainID.Big(),
OpsmProxy: st.ImplementationsDeployment.OpsmProxyAddress,
},
)
return err
},
},
)
if err != nil {
return fmt.Errorf("error deploying OP chain: %w", err)
}
st.Chains = append(st.Chains, &state.ChainState{
ID: chainID,
ProxyAdminAddress: dco.OpChainProxyAdmin,
AddressManagerAddress: dco.AddressManager,
L1ERC721BridgeProxyAddress: dco.L1ERC721BridgeProxy,
SystemConfigProxyAddress: dco.SystemConfigProxy,
OptimismMintableERC20FactoryProxyAddress: dco.OptimismMintableERC20FactoryProxy,
L1StandardBridgeProxyAddress: dco.L1StandardBridgeProxy,
L1CrossDomainMessengerProxyAddress: dco.L1CrossDomainMessengerProxy,
OptimismPortalProxyAddress: dco.OptimismPortalProxy,
DisputeGameFactoryProxyAddress: dco.DisputeGameFactoryProxy,
AnchorStateRegistryProxyAddress: dco.AnchorStateRegistryProxy,
AnchorStateRegistryImplAddress: dco.AnchorStateRegistryImpl,
FaultDisputeGameAddress: dco.FaultDisputeGame,
PermissionedDisputeGameAddress: dco.PermissionedDisputeGame,
DelayedWETHPermissionedGameProxyAddress: dco.DelayedWETHPermissionedGameProxy,
DelayedWETHPermissionlessGameProxyAddress: dco.DelayedWETHPermissionlessGameProxy,
})
if err := env.WriteState(st); err != nil {
return err
}
return nil
}
func shouldDeployOPChain(intent *state.Intent, st *state.State, chainID common.Hash) bool {
for _, chain := range st.Chains {
if chain.ID == chainID {
return false
}
}
return true
}