1
1
import { HardhatRuntimeEnvironment } from "hardhat/types" ;
2
2
import { DeployFunction } from "hardhat-deploy/types" ;
3
- import { Address } from "ethereumjs-util" ;
4
3
import { ethers } from "hardhat" ;
5
4
6
5
const HOME_CHAIN_IDS = [ 42161 , 421611 , 31337 ] ; // ArbOne, ArbRinkeby, Hardhat
7
6
7
+ // TODO: use deterministic deployments
8
+
8
9
const deployHomeGateway : DeployFunction = async ( hre : HardhatRuntimeEnvironment ) => {
9
10
const { deployments, getNamedAccounts, getChainId } = hre ;
10
11
const { deploy, execute } = deployments ;
@@ -14,35 +15,100 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
14
15
const deployer = ( await getNamedAccounts ( ) ) . deployer ?? ( await hre . ethers . getSigners ( ) ) [ 0 ] . address ;
15
16
console . log ( "deployer: %s" , deployer ) ;
16
17
17
- // The object below is not available when launching the hardhat node.
18
- // TODO: use deterministic deployments
19
- const fastBridgeReceiver =
20
- chainId === 31337
21
- ? await deployments . get ( "FastBridgeReceiverOnEthereum" )
22
- : await hre . companionNetworks . foreign . deployments . get ( "FastBridgeReceiverOnEthereum" ) ;
23
- const fastBridgeSender = await deploy ( "FastBridgeSenderToEthereum" , {
24
- from : deployer ,
25
- args : [ deployer , fastBridgeReceiver . address , ethers . constants . AddressZero ] ,
26
- log : true ,
27
- } ) ; // nonce+0
28
-
29
- const klerosCore = await deployments . get ( "KlerosCore" ) ;
30
- const foreignGateway =
31
- chainId === 31337
32
- ? await deployments . get ( "ForeignGatewayOnEthereum" )
33
- : await hre . companionNetworks . foreign . deployments . get ( "ForeignGatewayOnEthereum" ) ;
34
- const foreignChainId = chainId === 31337 ? 31337 : Number ( await hre . companionNetworks . foreign . getChainId ( ) ) ;
35
- const homeGateway = await deploy ( "HomeGatewayToEthereum" , {
36
- from : deployer ,
37
- args : [ klerosCore . address , fastBridgeSender . address , foreignGateway . address , foreignChainId ] ,
38
- log : true ,
39
- } ) ; // nonce+1
40
-
41
- const fastSender = await hre . ethers
42
- . getContractAt ( "FastBridgeSenderToEthereum" , fastBridgeSender . address )
43
- . then ( ( contract ) => contract . fastBridgeSender ( ) ) ;
44
- if ( fastSender === ethers . constants . AddressZero ) {
45
- await execute ( "FastBridgeSenderToEthereum" , { from : deployer , log : true } , "changeFastSender" , homeGateway . address ) ;
18
+ // ----------------------------------------------------------------------------------------------
19
+ const hardhatDeployer = async ( ) => {
20
+ const fastBridgeReceiver = await deployments . get ( "FastBridgeReceiverOnEthereum" ) ;
21
+ const arbSysMock = await deploy ( "ArbSysMock" , { from : deployer , log : true } ) ;
22
+
23
+ const fastBridgeSender = await deploy ( "FastBridgeSenderToEthereumMock" , {
24
+ from : deployer ,
25
+ args : [ deployer , fastBridgeReceiver . address , ethers . constants . AddressZero , arbSysMock . address ] ,
26
+ log : true ,
27
+ } ) ; // nonce+0
28
+
29
+ const klerosCore = await deployments . get ( "KlerosCore" ) ;
30
+ const foreignGateway = await deployments . get ( "ForeignGatewayOnEthereum" ) ;
31
+ const foreignChainId = 31337 ;
32
+
33
+ const homeGateway = await deploy ( "HomeGatewayToEthereum" , {
34
+ from : deployer ,
35
+ args : [ klerosCore . address , fastBridgeSender . address , foreignGateway . address , foreignChainId ] ,
36
+ log : true ,
37
+ } ) ; // nonce+1
38
+
39
+ const fastSender = await hre . ethers
40
+ . getContractAt ( "FastBridgeSenderToEthereumMock" , fastBridgeSender . address )
41
+ . then ( ( contract ) => contract . fastBridgeSender ( ) ) ;
42
+
43
+ if ( fastSender === ethers . constants . AddressZero ) {
44
+ await execute (
45
+ "FastBridgeSenderToEthereumMock" ,
46
+ {
47
+ from : deployer ,
48
+ log : true ,
49
+ } ,
50
+ "changeFastSender" ,
51
+ homeGateway . address
52
+ ) ;
53
+
54
+ const outbox = await deploy ( "OutboxMock" , {
55
+ from : deployer ,
56
+ args : [ fastBridgeSender . address ] ,
57
+ log : true ,
58
+ } ) ;
59
+
60
+ const bridge = await deploy ( "BridgeMock" , {
61
+ from : deployer ,
62
+ args : [ outbox . address ] ,
63
+ log : true ,
64
+ } ) ;
65
+
66
+ await deploy ( "InboxMock" , {
67
+ from : deployer ,
68
+ args : [ bridge . address ] ,
69
+ log : true ,
70
+ } ) ;
71
+ }
72
+ } ;
73
+
74
+ // ----------------------------------------------------------------------------------------------
75
+ const liveDeployer = async ( ) => {
76
+ const fastBridgeReceiver = await hre . companionNetworks . foreign . deployments . get ( "FastBridgeReceiverOnEthereum" ) ;
77
+
78
+ const fastBridgeSender = await deploy ( "FastBridgeSenderToEthereum" , {
79
+ from : deployer ,
80
+ args : [ deployer , fastBridgeReceiver . address , ethers . constants . AddressZero ] ,
81
+ log : true ,
82
+ } ) ; // nonce+0
83
+
84
+ const klerosCore = await deployments . get ( "KlerosCore" ) ;
85
+ const foreignGateway = await hre . companionNetworks . foreign . deployments . get ( "ForeignGatewayOnEthereum" ) ;
86
+ const foreignChainId = Number ( await hre . companionNetworks . foreign . getChainId ( ) ) ;
87
+ const homeGateway = await deploy ( "HomeGatewayToEthereum" , {
88
+ from : deployer ,
89
+ args : [ klerosCore . address , fastBridgeSender . address , foreignGateway . address , foreignChainId ] ,
90
+ log : true ,
91
+ } ) ; // nonce+1
92
+
93
+ const fastSender = await hre . ethers
94
+ . getContractAt ( "FastBridgeSenderToEthereum" , fastBridgeSender . address )
95
+ . then ( ( contract ) => contract . fastBridgeSender ( ) ) ;
96
+
97
+ if ( fastSender === ethers . constants . AddressZero ) {
98
+ await execute (
99
+ "FastBridgeSenderToEthereum" ,
100
+ { from : deployer , log : true } ,
101
+ "changeFastSender" ,
102
+ homeGateway . address
103
+ ) ;
104
+ }
105
+ } ;
106
+
107
+ // ----------------------------------------------------------------------------------------------
108
+ if ( chainId === 31337 ) {
109
+ await hardhatDeployer ( ) ;
110
+ } else {
111
+ await liveDeployer ( ) ;
46
112
}
47
113
} ;
48
114
0 commit comments