11import { HardhatRuntimeEnvironment } from "hardhat/types" ;
22import { DeployFunction } from "hardhat-deploy/types" ;
3- import { Address } from "ethereumjs-util" ;
43import { ethers } from "hardhat" ;
54
65const HOME_CHAIN_IDS = [ 42161 , 421611 , 31337 ] ; // ArbOne, ArbRinkeby, Hardhat
76
7+ // TODO: use deterministic deployments
8+
89const deployHomeGateway : DeployFunction = async ( hre : HardhatRuntimeEnvironment ) => {
910 const { deployments, getNamedAccounts, getChainId } = hre ;
1011 const { deploy, execute } = deployments ;
@@ -14,35 +15,101 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
1415 const deployer = ( await getNamedAccounts ( ) ) . deployer ?? ( await hre . ethers . getSigners ( ) ) [ 0 ] . address ;
1516 console . log ( "deployer: %s" , deployer ) ;
1617
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+ gasLimit : 4000000 ,
37+ log : true ,
38+ } ) ; // nonce+1
39+
40+ const fastSender = await hre . ethers
41+ . getContractAt ( "FastBridgeSenderToEthereumMock" , fastBridgeSender . address )
42+ . then ( ( contract ) => contract . fastBridgeSender ( ) ) ;
43+
44+ if ( fastSender === ethers . constants . AddressZero ) {
45+ await execute (
46+ "FastBridgeSenderToEthereumMock" ,
47+ {
48+ from : deployer ,
49+ log : true ,
50+ } ,
51+ "changeFastSender" ,
52+ homeGateway . address
53+ ) ;
54+
55+ const outbox = await deploy ( "OutboxMock" , {
56+ from : deployer ,
57+ args : [ fastBridgeSender . address ] ,
58+ log : true ,
59+ } ) ;
60+
61+ const bridge = await deploy ( "BridgeMock" , {
62+ from : deployer ,
63+ args : [ outbox . address ] ,
64+ log : true ,
65+ } ) ;
66+
67+ await deploy ( "InboxMock" , {
68+ from : deployer ,
69+ args : [ bridge . address ] ,
70+ log : true ,
71+ } ) ;
72+ }
73+ } ;
74+
75+ // ----------------------------------------------------------------------------------------------
76+ const liveDeployer = async ( ) => {
77+ const fastBridgeReceiver = await hre . companionNetworks . foreign . deployments . get ( "FastBridgeReceiverOnEthereum" ) ;
78+
79+ const fastBridgeSender = await deploy ( "FastBridgeSenderToEthereum" , {
80+ from : deployer ,
81+ args : [ deployer , fastBridgeReceiver . address , ethers . constants . AddressZero ] ,
82+ log : true ,
83+ } ) ; // nonce+0
84+
85+ const klerosCore = await deployments . get ( "KlerosCore" ) ;
86+ const foreignGateway = await hre . companionNetworks . foreign . deployments . get ( "ForeignGatewayOnEthereum" ) ;
87+ const foreignChainId = Number ( await hre . companionNetworks . foreign . getChainId ( ) ) ;
88+ const homeGateway = await deploy ( "HomeGatewayToEthereum" , {
89+ from : deployer ,
90+ args : [ klerosCore . address , fastBridgeSender . address , foreignGateway . address , foreignChainId ] ,
91+ log : true ,
92+ } ) ; // nonce+1
93+
94+ const fastSender = await hre . ethers
95+ . getContractAt ( "FastBridgeSenderToEthereum" , fastBridgeSender . address )
96+ . then ( ( contract ) => contract . fastBridgeSender ( ) ) ;
97+
98+ if ( fastSender === ethers . constants . AddressZero ) {
99+ await execute (
100+ "FastBridgeSenderToEthereum" ,
101+ { from : deployer , log : true } ,
102+ "changeFastSender" ,
103+ homeGateway . address
104+ ) ;
105+ }
106+ } ;
107+
108+ // ----------------------------------------------------------------------------------------------
109+ if ( chainId === 31337 ) {
110+ await hardhatDeployer ( ) ;
111+ } else {
112+ await liveDeployer ( ) ;
46113 }
47114} ;
48115
0 commit comments