-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Deploy.s.sol
1813 lines (1582 loc) · 81.5 KB
/
Deploy.s.sol
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Testing
import { VmSafe } from "forge-std/Vm.sol";
import { Script } from "forge-std/Script.sol";
import { console2 as console } from "forge-std/console2.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { AlphabetVM } from "test/mocks/AlphabetVM.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
// Safe
import { GnosisSafe as Safe } from "safe-contracts/GnosisSafe.sol";
import { OwnerManager } from "safe-contracts/base/OwnerManager.sol";
import { GnosisSafeProxyFactory as SafeProxyFactory } from "safe-contracts/proxies/GnosisSafeProxyFactory.sol";
import { Enum as SafeOps } from "safe-contracts/common/Enum.sol";
// Scripts
import { Deployer } from "scripts/deploy/Deployer.sol";
import { Chains } from "scripts/libraries/Chains.sol";
import { Config } from "scripts/libraries/Config.sol";
import { LibStateDiff } from "scripts/libraries/LibStateDiff.sol";
import { Process } from "scripts/libraries/Process.sol";
import { ForgeArtifacts } from "scripts/libraries/ForgeArtifacts.sol";
import { ChainAssertions } from "scripts/deploy/ChainAssertions.sol";
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
// Contracts
import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";
import { AddressManager } from "src/legacy/AddressManager.sol";
import { Proxy } from "src/universal/Proxy.sol";
import { StandardBridge } from "src/universal/StandardBridge.sol";
import { L1ChugSplashProxy } from "src/legacy/L1ChugSplashProxy.sol";
import { ResolvedDelegateProxy } from "src/legacy/ResolvedDelegateProxy.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import { MIPS } from "src/cannon/MIPS.sol";
import { MIPS2 } from "src/cannon/MIPS2.sol";
import { StorageSetter } from "src/universal/StorageSetter.sol";
// Libraries
import { Constants } from "src/libraries/Constants.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Types } from "scripts/libraries/Types.sol";
import "src/dispute/lib/Types.sol";
import { LibClaim, Duration } from "src/dispute/lib/LibUDT.sol";
// Interfaces
import { IOptimismPortal } from "src/L1/interfaces/IOptimismPortal.sol";
import { IOptimismPortal2 } from "src/L1/interfaces/IOptimismPortal2.sol";
import { IOptimismPortalInterop } from "src/L1/interfaces/IOptimismPortalInterop.sol";
import { ICrossDomainMessenger } from "src/universal/interfaces/ICrossDomainMessenger.sol";
import { IL1CrossDomainMessenger } from "src/L1/interfaces/IL1CrossDomainMessenger.sol";
import { IL2OutputOracle } from "src/L1/interfaces/IL2OutputOracle.sol";
import { ISuperchainConfig } from "src/L1/interfaces/ISuperchainConfig.sol";
import { ISystemConfig } from "src/L1/interfaces/ISystemConfig.sol";
import { ISystemConfigInterop } from "src/L1/interfaces/ISystemConfigInterop.sol";
import { IDataAvailabilityChallenge } from "src/L1/interfaces/IDataAvailabilityChallenge.sol";
import { IL1ERC721Bridge } from "src/L1/interfaces/IL1ERC721Bridge.sol";
import { IL1StandardBridge } from "src/L1/interfaces/IL1StandardBridge.sol";
import { IProtocolVersions, ProtocolVersion } from "src/L1/interfaces/IProtocolVersions.sol";
import { IBigStepper } from "src/dispute/interfaces/IBigStepper.sol";
import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";
import { IPermissionedDisputeGame } from "src/dispute/interfaces/IPermissionedDisputeGame.sol";
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol";
import { IOptimismMintableERC20Factory } from "src/universal/interfaces/IOptimismMintableERC20Factory.sol";
/// @title Deploy
/// @notice Script used to deploy a bedrock system. The entire system is deployed within the `run` function.
/// To add a new contract to the system, add a public function that deploys that individual contract.
/// Then add a call to that function inside of `run`. Be sure to call the `save` function after each
/// deployment so that hardhat-deploy style artifacts can be generated using a call to `sync()`.
/// The `CONTRACT_ADDRESSES_PATH` environment variable can be set to a path that contains a JSON file full of
/// contract name to address pairs. That enables this script to be much more flexible in the way it is used.
/// This contract must not have constructor logic because it is set into state using `etch`.
contract Deploy is Deployer {
using stdJson for string;
/// @notice FaultDisputeGameParams is a struct that contains the parameters necessary to call
/// the function _setFaultGameImplementation. This struct exists because the EVM needs
/// to finally adopt PUSHN and get rid of stack too deep once and for all.
/// Someday we will look back and laugh about stack too deep, today is not that day.
struct FaultDisputeGameParams {
IAnchorStateRegistry anchorStateRegistry;
IDelayedWETH weth;
GameType gameType;
Claim absolutePrestate;
IBigStepper faultVm;
uint256 maxGameDepth;
Duration maxClockDuration;
}
////////////////////////////////////////////////////////////////
// Modifiers //
////////////////////////////////////////////////////////////////
/// @notice Modifier that wraps a function in broadcasting.
modifier broadcast() {
vm.startBroadcast(msg.sender);
_;
vm.stopBroadcast();
}
/// @notice Modifier that will only allow a function to be called on devnet.
modifier onlyDevnet() {
uint256 chainid = block.chainid;
if (chainid == Chains.LocalDevnet || chainid == Chains.GethDevnet) {
_;
}
}
/// @notice Modifier that will only allow a function to be called on a public
/// testnet or devnet.
modifier onlyTestnetOrDevnet() {
uint256 chainid = block.chainid;
if (
chainid == Chains.Goerli || chainid == Chains.Sepolia || chainid == Chains.LocalDevnet
|| chainid == Chains.GethDevnet
) {
_;
}
}
/// @notice Modifier that wraps a function with statediff recording.
/// The returned AccountAccess[] array is then written to
/// the `snapshots/state-diff/<name>.json` output file.
modifier stateDiff() {
vm.startStateDiffRecording();
_;
VmSafe.AccountAccess[] memory accesses = vm.stopAndReturnStateDiff();
console.log(
"Writing %d state diff account accesses to snapshots/state-diff/%s.json",
accesses.length,
vm.toString(block.chainid)
);
string memory json = LibStateDiff.encodeAccountAccesses(accesses);
string memory statediffPath =
string.concat(vm.projectRoot(), "/snapshots/state-diff/", vm.toString(block.chainid), ".json");
vm.writeJson({ json: json, path: statediffPath });
}
////////////////////////////////////////////////////////////////
// Accessors //
////////////////////////////////////////////////////////////////
/// @notice The create2 salt used for deployment of the contract implementations.
/// Using this helps to reduce config across networks as the implementation
/// addresses will be the same across networks when deployed with create2.
function _implSalt() internal view returns (bytes32) {
return keccak256(bytes(Config.implSalt()));
}
/// @notice Returns the proxy addresses. If a proxy is not found, it will have address(0).
function _proxies() internal view returns (Types.ContractSet memory proxies_) {
proxies_ = Types.ContractSet({
L1CrossDomainMessenger: mustGetAddress("L1CrossDomainMessengerProxy"),
L1StandardBridge: mustGetAddress("L1StandardBridgeProxy"),
L2OutputOracle: mustGetAddress("L2OutputOracleProxy"),
DisputeGameFactory: mustGetAddress("DisputeGameFactoryProxy"),
DelayedWETH: mustGetAddress("DelayedWETHProxy"),
PermissionedDelayedWETH: mustGetAddress("PermissionedDelayedWETHProxy"),
AnchorStateRegistry: mustGetAddress("AnchorStateRegistryProxy"),
OptimismMintableERC20Factory: mustGetAddress("OptimismMintableERC20FactoryProxy"),
OptimismPortal: mustGetAddress("OptimismPortalProxy"),
OptimismPortal2: mustGetAddress("OptimismPortalProxy"),
SystemConfig: mustGetAddress("SystemConfigProxy"),
L1ERC721Bridge: mustGetAddress("L1ERC721BridgeProxy"),
ProtocolVersions: mustGetAddress("ProtocolVersionsProxy"),
SuperchainConfig: mustGetAddress("SuperchainConfigProxy")
});
}
/// @notice Returns the proxy addresses, not reverting if any are unset.
function _proxiesUnstrict() internal view returns (Types.ContractSet memory proxies_) {
proxies_ = Types.ContractSet({
L1CrossDomainMessenger: getAddress("L1CrossDomainMessengerProxy"),
L1StandardBridge: getAddress("L1StandardBridgeProxy"),
L2OutputOracle: getAddress("L2OutputOracleProxy"),
DisputeGameFactory: getAddress("DisputeGameFactoryProxy"),
DelayedWETH: getAddress("DelayedWETHProxy"),
PermissionedDelayedWETH: getAddress("PermissionedDelayedWETHProxy"),
AnchorStateRegistry: getAddress("AnchorStateRegistryProxy"),
OptimismMintableERC20Factory: getAddress("OptimismMintableERC20FactoryProxy"),
OptimismPortal: getAddress("OptimismPortalProxy"),
OptimismPortal2: getAddress("OptimismPortalProxy"),
SystemConfig: getAddress("SystemConfigProxy"),
L1ERC721Bridge: getAddress("L1ERC721BridgeProxy"),
ProtocolVersions: getAddress("ProtocolVersionsProxy"),
SuperchainConfig: getAddress("SuperchainConfigProxy")
});
}
////////////////////////////////////////////////////////////////
// State Changing Helper Functions //
////////////////////////////////////////////////////////////////
/// @notice Gets the address of the SafeProxyFactory and Safe singleton for use in deploying a new GnosisSafe.
function _getSafeFactory() internal returns (SafeProxyFactory safeProxyFactory_, Safe safeSingleton_) {
if (getAddress("SafeProxyFactory") != address(0)) {
// The SafeProxyFactory is already saved, we can just use it.
safeProxyFactory_ = SafeProxyFactory(getAddress("SafeProxyFactory"));
safeSingleton_ = Safe(getAddress("SafeSingleton"));
return (safeProxyFactory_, safeSingleton_);
}
// These are the standard create2 deployed contracts. First we'll check if they are deployed,
// if not we'll deploy new ones, though not at these addresses.
address safeProxyFactory = 0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2;
address safeSingleton = 0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552;
safeProxyFactory.code.length == 0
? safeProxyFactory_ = new SafeProxyFactory()
: safeProxyFactory_ = SafeProxyFactory(safeProxyFactory);
safeSingleton.code.length == 0 ? safeSingleton_ = new Safe() : safeSingleton_ = Safe(payable(safeSingleton));
save("SafeProxyFactory", address(safeProxyFactory_));
save("SafeSingleton", address(safeSingleton_));
}
/// @notice Make a call from the Safe contract to an arbitrary address with arbitrary data
function _callViaSafe(Safe _safe, address _target, bytes memory _data) internal {
// This is the signature format used when the caller is also the signer.
bytes memory signature = abi.encodePacked(uint256(uint160(msg.sender)), bytes32(0), uint8(1));
_safe.execTransaction({
to: _target,
value: 0,
data: _data,
operation: SafeOps.Operation.Call,
safeTxGas: 0,
baseGas: 0,
gasPrice: 0,
gasToken: address(0),
refundReceiver: payable(address(0)),
signatures: signature
});
}
/// @notice Call from the Safe contract to the Proxy Admin's upgrade and call method
function _upgradeAndCallViaSafe(address _proxy, address _implementation, bytes memory _innerCallData) internal {
address proxyAdmin = mustGetAddress("ProxyAdmin");
bytes memory data =
abi.encodeCall(ProxyAdmin.upgradeAndCall, (payable(_proxy), _implementation, _innerCallData));
Safe safe = Safe(mustGetAddress("SystemOwnerSafe"));
_callViaSafe({ _safe: safe, _target: proxyAdmin, _data: data });
}
/// @notice Transfer ownership of the ProxyAdmin contract to the final system owner
function transferProxyAdminOwnership() public broadcast {
ProxyAdmin proxyAdmin = ProxyAdmin(mustGetAddress("ProxyAdmin"));
address owner = proxyAdmin.owner();
address safe = mustGetAddress("SystemOwnerSafe");
if (owner != safe) {
proxyAdmin.transferOwnership(safe);
console.log("ProxyAdmin ownership transferred to Safe at: %s", safe);
}
}
/// @notice Transfer ownership of a Proxy to the ProxyAdmin contract
/// This is expected to be used in conjusting with deployERC1967ProxyWithOwner after setup actions
/// have been performed on the proxy.
/// @param _name The name of the proxy to transfer ownership of.
function transferProxyToProxyAdmin(string memory _name) public broadcast {
Proxy proxy = Proxy(mustGetAddress(_name));
address proxyAdmin = mustGetAddress("ProxyAdmin");
proxy.changeAdmin(proxyAdmin);
console.log("Proxy %s ownership transferred to ProxyAdmin at: %s", _name, proxyAdmin);
}
////////////////////////////////////////////////////////////////
// SetUp and Run //
////////////////////////////////////////////////////////////////
/// @notice Deploy all of the L1 contracts necessary for a full Superchain with a single Op Chain.
function run() public {
console.log("Deploying a fresh OP Stack including SuperchainConfig");
_run();
}
/// @notice Deploy a new OP Chain using an existing SuperchainConfig and ProtocolVersions
/// @param _superchainConfigProxy Address of the existing SuperchainConfig proxy
/// @param _protocolVersionsProxy Address of the existing ProtocolVersions proxy
/// @param _includeDump Whether to include a state dump after deployment
function runWithSuperchain(
address payable _superchainConfigProxy,
address payable _protocolVersionsProxy,
bool _includeDump
)
public
{
require(_superchainConfigProxy != address(0), "must specify address for superchain config proxy");
require(_protocolVersionsProxy != address(0), "must specify address for protocol versions proxy");
vm.chainId(cfg.l1ChainID());
console.log("Deploying a fresh OP Stack with existing SuperchainConfig and ProtocolVersions");
Proxy scProxy = Proxy(_superchainConfigProxy);
save("SuperchainConfig", scProxy.implementation());
save("SuperchainConfigProxy", _superchainConfigProxy);
Proxy pvProxy = Proxy(_protocolVersionsProxy);
save("ProtocolVersions", pvProxy.implementation());
save("ProtocolVersionsProxy", _protocolVersionsProxy);
_run(false);
if (_includeDump) {
vm.dumpState(Config.stateDumpPath(""));
}
}
function runWithStateDump() public {
vm.chainId(cfg.l1ChainID());
_run();
vm.dumpState(Config.stateDumpPath(""));
}
/// @notice Deploy all L1 contracts and write the state diff to a file.
function runWithStateDiff() public stateDiff {
_run();
}
/// @notice Compatibility function for tests that override _run().
function _run() internal virtual {
_run(true);
}
/// @notice Internal function containing the deploy logic.
function _run(bool _needsSuperchain) internal {
console.log("start of L1 Deploy!");
deploySafe("SystemOwnerSafe");
console.log("deployed Safe!");
// Deploy a new ProxyAdmin and AddressManager
// This proxy will be used on the SuperchainConfig and ProtocolVersions contracts, as well as the contracts
// in the OP Chain system.
setupAdmin();
if (_needsSuperchain) {
setupSuperchain();
console.log("set up superchain!");
}
if (cfg.useAltDA()) {
bytes32 typeHash = keccak256(bytes(cfg.daCommitmentType()));
bytes32 keccakHash = keccak256(bytes("KeccakCommitment"));
if (typeHash == keccakHash) {
setupOpAltDA();
}
}
setupOpChain();
console.log("set up op chain!");
}
////////////////////////////////////////////////////////////////
// High Level Deployment Functions //
////////////////////////////////////////////////////////////////
/// @notice Deploy the address manager and proxy admin contracts.
function setupAdmin() public {
deployAddressManager();
deployProxyAdmin();
transferProxyAdminOwnership();
}
/// @notice Deploy a full system with a new SuperchainConfig
/// The Superchain system has 2 singleton contracts which lie outside of an OP Chain:
/// 1. The SuperchainConfig contract
/// 2. The ProtocolVersions contract
function setupSuperchain() public {
console.log("Setting up Superchain");
// Deploy the SuperchainConfigProxy
deployERC1967Proxy("SuperchainConfigProxy");
deploySuperchainConfig();
initializeSuperchainConfig();
// Deploy the ProtocolVersionsProxy
deployERC1967Proxy("ProtocolVersionsProxy");
deployProtocolVersions();
initializeProtocolVersions();
}
/// @notice Deploy a new OP Chain, with an existing SuperchainConfig provided
function setupOpChain() public {
console.log("Deploying OP Chain");
// Ensure that the requisite contracts are deployed
mustGetAddress("SuperchainConfigProxy");
mustGetAddress("SystemOwnerSafe");
mustGetAddress("AddressManager");
mustGetAddress("ProxyAdmin");
deployImplementations();
deployOpChain();
initializeOpChain();
setAlphabetFaultGameImplementation({ _allowUpgrade: false });
setFastFaultGameImplementation({ _allowUpgrade: false });
setCannonFaultGameImplementation({ _allowUpgrade: false });
setPermissionedCannonFaultGameImplementation({ _allowUpgrade: false });
transferDisputeGameFactoryOwnership();
transferDelayedWETHOwnership();
}
/// @notice Deploy all of the OP Chain specific contracts
function deployOpChain() public {
console.log("Deploying OP Chain contracts");
deployERC1967Proxy("OptimismPortalProxy");
deployERC1967Proxy("SystemConfigProxy");
deployL1StandardBridgeProxy();
deployL1CrossDomainMessengerProxy();
deployERC1967Proxy("OptimismMintableERC20FactoryProxy");
deployERC1967Proxy("L1ERC721BridgeProxy");
// Both the DisputeGameFactory and L2OutputOracle proxies are deployed regardless of whether fault proofs is
// enabled to prevent a nastier refactor to the deploy scripts. In the future, the L2OutputOracle will be
// removed. If fault proofs are not enabled, the DisputeGameFactory proxy will be unused.
deployERC1967Proxy("DisputeGameFactoryProxy");
deployERC1967Proxy("L2OutputOracleProxy");
deployERC1967Proxy("DelayedWETHProxy");
deployERC1967Proxy("PermissionedDelayedWETHProxy");
deployERC1967Proxy("AnchorStateRegistryProxy");
deployAnchorStateRegistry();
transferAddressManagerOwnership(); // to the ProxyAdmin
}
/// @notice Deploy all of the implementations
function deployImplementations() public {
console.log("Deploying implementations");
deployL1CrossDomainMessenger();
deployOptimismMintableERC20Factory();
deploySystemConfig();
deployL1StandardBridge();
deployL1ERC721Bridge();
deployOptimismPortal();
deployL2OutputOracle();
// Fault proofs
deployOptimismPortal2();
deployDisputeGameFactory();
deployDelayedWETH();
deployPreimageOracle();
deployMips();
}
/// @notice Initialize all of the proxies in an OP Chain by upgrading to the correct proxy and calling the
/// initialize function
function initializeOpChain() public {
console.log("Initializing Op Chain proxies");
// Selectively initialize either the original OptimismPortal or the new OptimismPortal2. Since this will upgrade
// the proxy, we cannot initialize both.
if (cfg.useFaultProofs()) {
console.log("Fault proofs enabled. Initializing the OptimismPortal proxy with the OptimismPortal2.");
initializeOptimismPortal2();
} else {
initializeOptimismPortal();
}
initializeSystemConfig();
initializeL1StandardBridge();
initializeL1ERC721Bridge();
initializeOptimismMintableERC20Factory();
initializeL1CrossDomainMessenger();
initializeL2OutputOracle();
initializeDisputeGameFactory();
initializeDelayedWETH();
initializePermissionedDelayedWETH();
initializeAnchorStateRegistry();
}
/// @notice Add AltDA setup to the OP chain
function setupOpAltDA() public {
console.log("Deploying OP AltDA");
deployDataAvailabilityChallengeProxy();
deployDataAvailabilityChallenge();
initializeDataAvailabilityChallenge();
}
////////////////////////////////////////////////////////////////
// Non-Proxied Deployment Functions //
////////////////////////////////////////////////////////////////
/// @notice Deploy the Safe
function deploySafe(string memory _name) public broadcast returns (address addr_) {
address[] memory owners = new address[](0);
addr_ = deploySafe(_name, owners, 1, true);
}
/// @notice Deploy a new Safe contract. If the keepDeployer option is used to enable further setup actions, then
/// the removeDeployerFromSafe() function should be called on that safe after setup is complete.
/// Note this function does not have the broadcast modifier.
/// @param _name The name of the Safe to deploy.
/// @param _owners The owners of the Safe.
/// @param _threshold The threshold of the Safe.
/// @param _keepDeployer Wether or not the deployer address will be added as an owner of the Safe.
function deploySafe(
string memory _name,
address[] memory _owners,
uint256 _threshold,
bool _keepDeployer
)
public
returns (address addr_)
{
bytes32 salt = keccak256(abi.encode(_name, _implSalt()));
console.log("Deploying safe: %s with salt %s", _name, vm.toString(salt));
(SafeProxyFactory safeProxyFactory, Safe safeSingleton) = _getSafeFactory();
if (_keepDeployer) {
address[] memory expandedOwners = new address[](_owners.length + 1);
// By always adding msg.sender first we know that the previousOwner will be SENTINEL_OWNERS, which makes it
// easier to call removeOwner later.
expandedOwners[0] = msg.sender;
for (uint256 i = 0; i < _owners.length; i++) {
expandedOwners[i + 1] = _owners[i];
}
_owners = expandedOwners;
}
bytes memory initData = abi.encodeCall(
Safe.setup, (_owners, _threshold, address(0), hex"", address(0), address(0), 0, payable(address(0)))
);
addr_ = address(safeProxyFactory.createProxyWithNonce(address(safeSingleton), initData, uint256(salt)));
save(_name, addr_);
console.log("New safe: %s deployed at %s\n Note that this safe is owned by the deployer key", _name, addr_);
}
/// @notice If the keepDeployer option was used with deploySafe(), this function can be used to remove the deployer.
/// Note this function does not have the broadcast modifier.
function removeDeployerFromSafe(string memory _name, uint256 _newThreshold) public {
Safe safe = Safe(mustGetAddress(_name));
// The sentinel address is used to mark the start and end of the linked list of owners in the Safe.
address sentinelOwners = address(0x1);
// Because deploySafe() always adds msg.sender first (if keepDeployer is true), we know that the previousOwner
// will be sentinelOwners.
_callViaSafe({
_safe: safe,
_target: address(safe),
_data: abi.encodeCall(OwnerManager.removeOwner, (sentinelOwners, msg.sender, _newThreshold))
});
console.log("Removed deployer owner from ", _name);
}
/// @notice Deploy the AddressManager
function deployAddressManager() public broadcast returns (address addr_) {
console.log("Deploying AddressManager");
AddressManager manager = new AddressManager();
require(manager.owner() == msg.sender);
save("AddressManager", address(manager));
console.log("AddressManager deployed at %s", address(manager));
addr_ = address(manager);
}
/// @notice Deploy the ProxyAdmin
function deployProxyAdmin() public broadcast returns (address addr_) {
console.log("Deploying ProxyAdmin");
ProxyAdmin admin = new ProxyAdmin({ _owner: msg.sender });
require(admin.owner() == msg.sender);
AddressManager addressManager = AddressManager(mustGetAddress("AddressManager"));
if (admin.addressManager() != addressManager) {
admin.setAddressManager(addressManager);
}
require(admin.addressManager() == addressManager);
save("ProxyAdmin", address(admin));
console.log("ProxyAdmin deployed at %s", address(admin));
addr_ = address(admin);
}
/// @notice Deploy the StorageSetter contract, used for upgrades.
function deployStorageSetter() public broadcast returns (address addr_) {
console.log("Deploying StorageSetter");
StorageSetter setter = new StorageSetter{ salt: _implSalt() }();
console.log("StorageSetter deployed at: %s", address(setter));
string memory version = setter.version();
console.log("StorageSetter version: %s", version);
addr_ = address(setter);
}
////////////////////////////////////////////////////////////////
// Proxy Deployment Functions //
////////////////////////////////////////////////////////////////
/// @notice Deploy the L1StandardBridgeProxy using a ChugSplashProxy
function deployL1StandardBridgeProxy() public broadcast returns (address addr_) {
console.log("Deploying proxy for L1StandardBridge");
address proxyAdmin = mustGetAddress("ProxyAdmin");
L1ChugSplashProxy proxy = new L1ChugSplashProxy(proxyAdmin);
require(EIP1967Helper.getAdmin(address(proxy)) == proxyAdmin);
save("L1StandardBridgeProxy", address(proxy));
console.log("L1StandardBridgeProxy deployed at %s", address(proxy));
addr_ = address(proxy);
}
/// @notice Deploy the L1CrossDomainMessengerProxy using a ResolvedDelegateProxy
function deployL1CrossDomainMessengerProxy() public broadcast returns (address addr_) {
console.log("Deploying proxy for L1CrossDomainMessenger");
AddressManager addressManager = AddressManager(mustGetAddress("AddressManager"));
ResolvedDelegateProxy proxy = new ResolvedDelegateProxy(addressManager, "OVM_L1CrossDomainMessenger");
save("L1CrossDomainMessengerProxy", address(proxy));
console.log("L1CrossDomainMessengerProxy deployed at %s", address(proxy));
addr_ = address(proxy);
}
/// @notice Deploys an ERC1967Proxy contract with the ProxyAdmin as the owner.
/// @param _name The name of the proxy contract to be deployed.
/// @return addr_ The address of the deployed proxy contract.
function deployERC1967Proxy(string memory _name) public returns (address addr_) {
addr_ = deployERC1967ProxyWithOwner(_name, mustGetAddress("ProxyAdmin"));
}
/// @notice Deploys an ERC1967Proxy contract with a specified owner.
/// @param _name The name of the proxy contract to be deployed.
/// @param _proxyOwner The address of the owner of the proxy contract.
/// @return addr_ The address of the deployed proxy contract.
function deployERC1967ProxyWithOwner(
string memory _name,
address _proxyOwner
)
public
broadcast
returns (address addr_)
{
console.log(string.concat("Deploying ERC1967 proxy for ", _name));
Proxy proxy = new Proxy({ _admin: _proxyOwner });
require(EIP1967Helper.getAdmin(address(proxy)) == _proxyOwner);
save(_name, address(proxy));
console.log(" at %s", address(proxy));
addr_ = address(proxy);
}
/// @notice Deploy the DataAvailabilityChallengeProxy
function deployDataAvailabilityChallengeProxy() public broadcast returns (address addr_) {
console.log("Deploying proxy for DataAvailabilityChallenge");
address proxyAdmin = mustGetAddress("ProxyAdmin");
Proxy proxy = new Proxy({ _admin: proxyAdmin });
require(EIP1967Helper.getAdmin(address(proxy)) == proxyAdmin);
save("DataAvailabilityChallengeProxy", address(proxy));
console.log("DataAvailabilityChallengeProxy deployed at %s", address(proxy));
addr_ = address(proxy);
}
////////////////////////////////////////////////////////////////
// Implementation Deployment Functions //
////////////////////////////////////////////////////////////////
/// @notice Deploy the SuperchainConfig contract
function deploySuperchainConfig() public broadcast {
ISuperchainConfig superchainConfig = ISuperchainConfig(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "SuperchainConfig",
_args: abi.encodeCall(ISuperchainConfig.__constructor__, ())
})
);
require(superchainConfig.guardian() == address(0));
bytes32 initialized = vm.load(address(superchainConfig), bytes32(0));
require(initialized != 0);
}
/// @notice Deploy the L1CrossDomainMessenger
function deployL1CrossDomainMessenger() public broadcast returns (address addr_) {
IL1CrossDomainMessenger messenger = IL1CrossDomainMessenger(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "L1CrossDomainMessenger",
_args: abi.encodeCall(IL1CrossDomainMessenger.__constructor__, ())
})
);
// Override the `L1CrossDomainMessenger` contract to the deployed implementation. This is necessary
// to check the `L1CrossDomainMessenger` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.L1CrossDomainMessenger = address(messenger);
ChainAssertions.checkL1CrossDomainMessenger({ _contracts: contracts, _vm: vm, _isProxy: false });
addr_ = address(messenger);
}
/// @notice Deploy the OptimismPortal
function deployOptimismPortal() public broadcast returns (address addr_) {
if (cfg.useInterop()) {
console.log("Attempting to deploy OptimismPortal with interop, this config is a noop");
}
addr_ = DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "OptimismPortal",
_args: abi.encodeCall(IOptimismPortal.__constructor__, ())
});
// Override the `OptimismPortal` contract to the deployed implementation. This is necessary
// to check the `OptimismPortal` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.OptimismPortal = addr_;
ChainAssertions.checkOptimismPortal({ _contracts: contracts, _cfg: cfg, _isProxy: false });
}
/// @notice Deploy the OptimismPortal2
function deployOptimismPortal2() public broadcast returns (address addr_) {
// Could also verify this inside DeployConfig but doing it here is a bit more reliable.
require(
uint32(cfg.respectedGameType()) == cfg.respectedGameType(), "Deploy: respectedGameType must fit into uint32"
);
if (cfg.useInterop()) {
addr_ = DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "OptimismPortalInterop",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
IOptimismPortalInterop.__constructor__,
(cfg.proofMaturityDelaySeconds(), cfg.disputeGameFinalityDelaySeconds())
)
)
});
save("OptimismPortal2", addr_);
} else {
addr_ = DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "OptimismPortal2",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
IOptimismPortal2.__constructor__,
(cfg.proofMaturityDelaySeconds(), cfg.disputeGameFinalityDelaySeconds())
)
)
});
}
// Override the `OptimismPortal2` contract to the deployed implementation. This is necessary
// to check the `OptimismPortal2` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.OptimismPortal2 = addr_;
ChainAssertions.checkOptimismPortal2({ _contracts: contracts, _cfg: cfg, _isProxy: false });
}
/// @notice Deploy the L2OutputOracle
function deployL2OutputOracle() public broadcast returns (address addr_) {
IL2OutputOracle oracle = IL2OutputOracle(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "L2OutputOracle",
_args: abi.encodeCall(IL2OutputOracle.__constructor__, ())
})
);
// Override the `L2OutputOracle` contract to the deployed implementation. This is necessary
// to check the `L2OutputOracle` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.L2OutputOracle = address(oracle);
ChainAssertions.checkL2OutputOracle({
_contracts: contracts,
_cfg: cfg,
_l2OutputOracleStartingTimestamp: 0,
_isProxy: false
});
addr_ = address(oracle);
}
/// @notice Deploy the OptimismMintableERC20Factory
function deployOptimismMintableERC20Factory() public broadcast returns (address addr_) {
IOptimismMintableERC20Factory factory = IOptimismMintableERC20Factory(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "OptimismMintableERC20Factory",
_args: abi.encodeCall(IOptimismMintableERC20Factory.__constructor__, ())
})
);
// Override the `OptimismMintableERC20Factory` contract to the deployed implementation. This is necessary
// to check the `OptimismMintableERC20Factory` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.OptimismMintableERC20Factory = address(factory);
ChainAssertions.checkOptimismMintableERC20Factory({ _contracts: contracts, _isProxy: false });
addr_ = address(factory);
}
/// @notice Deploy the DisputeGameFactory
function deployDisputeGameFactory() public broadcast returns (address addr_) {
IDisputeGameFactory factory = IDisputeGameFactory(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "DisputeGameFactory",
_args: abi.encodeCall(IDisputeGameFactory.__constructor__, ())
})
);
// Override the `DisputeGameFactory` contract to the deployed implementation. This is necessary to check the
// `DisputeGameFactory` implementation alongside dependent contracts, which are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.DisputeGameFactory = address(factory);
ChainAssertions.checkDisputeGameFactory({ _contracts: contracts, _expectedOwner: address(0) });
addr_ = address(factory);
}
function deployDelayedWETH() public broadcast returns (address addr_) {
IDelayedWETH weth = IDelayedWETH(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "DelayedWETH",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IDelayedWETH.__constructor__, (cfg.faultGameWithdrawalDelay()))
)
})
);
// Override the `DelayedWETH` contract to the deployed implementation. This is necessary
// to check the `DelayedWETH` implementation alongside dependent contracts, which are
// always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.DelayedWETH = address(weth);
ChainAssertions.checkDelayedWETH({
_contracts: contracts,
_cfg: cfg,
_isProxy: false,
_expectedOwner: address(0)
});
addr_ = address(weth);
}
/// @notice Deploy the ProtocolVersions
function deployProtocolVersions() public broadcast returns (address addr_) {
IProtocolVersions versions = IProtocolVersions(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "ProtocolVersions",
_args: abi.encodeCall(IProtocolVersions.__constructor__, ())
})
);
// Override the `ProtocolVersions` contract to the deployed implementation. This is necessary
// to check the `ProtocolVersions` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.ProtocolVersions = address(versions);
ChainAssertions.checkProtocolVersions({ _contracts: contracts, _cfg: cfg, _isProxy: false });
addr_ = address(versions);
}
/// @notice Deploy the PreimageOracle
function deployPreimageOracle() public broadcast returns (address addr_) {
console.log("Deploying PreimageOracle implementation");
PreimageOracle preimageOracle = new PreimageOracle{ salt: _implSalt() }({
_minProposalSize: cfg.preimageOracleMinProposalSize(),
_challengePeriod: cfg.preimageOracleChallengePeriod()
});
save("PreimageOracle", address(preimageOracle));
console.log("PreimageOracle deployed at %s", address(preimageOracle));
addr_ = address(preimageOracle);
}
/// @notice Deploy Mips VM. Deploys either MIPS or MIPS2 depending on the environment
function deployMips() public broadcast returns (address addr_) {
if (Config.useMultithreadedCannon()) {
addr_ = _deployMips2();
} else {
addr_ = _deployMips();
}
save("Mips", address(addr_));
}
/// @notice Deploy MIPS
function _deployMips() internal returns (address addr_) {
console.log("Deploying Mips implementation");
MIPS mips = new MIPS{ salt: _implSalt() }(IPreimageOracle(mustGetAddress("PreimageOracle")));
console.log("MIPS deployed at %s", address(mips));
addr_ = address(mips);
}
/// @notice Deploy MIPS2
function _deployMips2() internal returns (address addr_) {
console.log("Deploying Mips2 implementation");
MIPS2 mips2 = new MIPS2{ salt: _implSalt() }(IPreimageOracle(mustGetAddress("PreimageOracle")));
console.log("MIPS2 deployed at %s", address(mips2));
addr_ = address(mips2);
}
/// @notice Deploy the AnchorStateRegistry
function deployAnchorStateRegistry() public broadcast returns (address addr_) {
IAnchorStateRegistry anchorStateRegistry = IAnchorStateRegistry(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "AnchorStateRegistry",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
IAnchorStateRegistry.__constructor__,
(IDisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy")))
)
)
})
);
addr_ = address(anchorStateRegistry);
}
/// @notice Deploy the SystemConfig
function deploySystemConfig() public broadcast returns (address addr_) {
if (cfg.useInterop()) {
addr_ = DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "SystemConfigInterop",
_args: abi.encodeCall(ISystemConfigInterop.__constructor__, ())
});
save("SystemConfig", addr_);
} else {
addr_ = DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "SystemConfig",
_args: abi.encodeCall(ISystemConfig.__constructor__, ())
});
}
// Override the `SystemConfig` contract to the deployed implementation. This is necessary
// to check the `SystemConfig` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.SystemConfig = addr_;
ChainAssertions.checkSystemConfig({ _contracts: contracts, _cfg: cfg, _isProxy: false });
}
/// @notice Deploy the L1StandardBridge
function deployL1StandardBridge() public broadcast returns (address addr_) {
IL1StandardBridge bridge = IL1StandardBridge(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: "L1StandardBridge",
_args: abi.encodeCall(IL1StandardBridge.__constructor__, ())
})
);
// Override the `L1StandardBridge` contract to the deployed implementation. This is necessary
// to check the `L1StandardBridge` implementation alongside dependent contracts, which
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.L1StandardBridge = address(bridge);
ChainAssertions.checkL1StandardBridge({ _contracts: contracts, _isProxy: false });
addr_ = address(bridge);
}
/// @notice Deploy the L1ERC721Bridge
function deployL1ERC721Bridge() public broadcast returns (address addr_) {
IL1ERC721Bridge bridge = IL1ERC721Bridge(
DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),