11import { HardhatRuntimeEnvironment } from "hardhat/types" ;
22import { DeployFunction } from "hardhat-deploy/types" ;
33import { BigNumber } from "ethers" ;
4- import getContractAddress from "../deploy-helpers/getContractAddress" ;
5-
6- enum HomeChains {
7- ARBITRUM_ONE = 42161 ,
8- ARBITRUM_GOERLI = 421613 ,
9- HARDHAT = 31337 ,
10- }
4+ import getContractAddress from "./utils/getContractAddress" ;
5+ import { deployUpgradable } from "./utils/deployUpgradable" ;
6+ import { HomeChains , isSkipped } from "./utils" ;
117
128const pnkByChain = new Map < HomeChains , string > ( [
139 [ HomeChains . ARBITRUM_ONE , "0x330bD769382cFc6d50175903434CCC8D206DCAE5" ] ,
@@ -56,43 +52,44 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5652 randomizerByChain . set ( HomeChains [ HomeChains [ chainId ] ] , randomizerMock . address ) ;
5753 }
5854
59- await deploy ( "PolicyRegistry" , {
60- from : deployer ,
61- args : [ deployer ] ,
62- log : true ,
63- } ) ;
55+ await deployUpgradable ( hre , "PolicyRegistry" , { from : deployer , args : [ deployer ] , log : true } ) ;
6456
6557 const randomizer = randomizerByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
66- const rng = await deploy ( "RandomizerRNG" , {
67- skipIfAlreadyDeployed : true ,
68- from : deployer ,
69- args : [ randomizer , deployer ] ,
70- log : true ,
71- } ) ;
58+ const rng = await deployUpgradable ( hre , "RandomizerRNG" , { from : deployer , args : [ randomizer , deployer ] , log : true } ) ;
7259
73- const disputeKit = await deploy ( "DisputeKitClassic" , {
60+ const disputeKit = await deployUpgradable ( hre , "DisputeKitClassic" , {
7461 from : deployer ,
7562 args : [ deployer , AddressZero ] ,
7663 log : true ,
7764 } ) ;
7865
79- const nonce = await ethers . provider . getTransactionCount ( deployer ) ;
80- const KlerosCoreAddress = getContractAddress ( deployer , nonce + 1 ) ;
81- console . log ( "calculated future KlerosCore address for nonce %d: %s" , nonce , KlerosCoreAddress ) ;
66+ let klerosCoreAddress = await deployments . getOrNull ( "KlerosCore" ) . then ( ( deployment ) => deployment ?. address ) ;
67+ if ( ! klerosCoreAddress ) {
68+ const nonce = await ethers . provider . getTransactionCount ( deployer ) ;
69+ klerosCoreAddress = getContractAddress ( deployer , nonce + 3 ) ; // deployed on the 4th tx (nonce+3): SortitionModule Impl tx, SortitionModule Proxy tx, KlerosCore Impl tx, KlerosCore Proxy tx
70+ console . log ( "calculated future KlerosCore address for nonce %d: %s" , nonce + 3 , klerosCoreAddress ) ;
71+ }
8272
83- const sortitionModule = await deploy ( "SortitionModule" , {
73+ const sortitionModule = await deployUpgradable ( hre , "SortitionModule" , {
8474 from : deployer ,
85- args : [ deployer , KlerosCoreAddress , 1800 , 1800 , rng . address , RNG_LOOKAHEAD ] , // minStakingTime, maxFreezingTime
75+ args : [
76+ deployer ,
77+ klerosCoreAddress ,
78+ 1800 , // minStakingTime
79+ 1800 , // maxFreezingTime
80+ rng . address ,
81+ RNG_LOOKAHEAD ,
82+ ] ,
8683 log : true ,
87- } ) ;
84+ } ) ; // nonce (implementation), nonce+1 (proxy)
8885
8986 const pnk = pnkByChain . get ( chainId ) ?? AddressZero ;
9087 const dai = daiByChain . get ( chainId ) ?? AddressZero ;
9188 const weth = wethByChain . get ( chainId ) ?? AddressZero ;
9289 const minStake = BigNumber . from ( 10 ) . pow ( 20 ) . mul ( 2 ) ;
9390 const alpha = 10000 ;
9491 const feeForJuror = BigNumber . from ( 10 ) . pow ( 17 ) ;
95- const klerosCore = await deploy ( "KlerosCore" , {
92+ const klerosCore = await deployUpgradable ( hre , "KlerosCore" , {
9693 from : deployer ,
9794 args : [
9895 deployer ,
@@ -106,7 +103,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
106103 sortitionModule . address ,
107104 ] ,
108105 log : true ,
109- } ) ;
106+ } ) ; // nonce+2 (implementation), nonce+3 (proxy)
110107
111108 // execute DisputeKitClassic.changeCore() only if necessary
112109 const currentCore = await hre . ethers . getContractAt ( "DisputeKitClassic" , disputeKit . address ) . then ( ( dk ) => dk . core ( ) ) ;
@@ -124,12 +121,15 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
124121} ;
125122
126123deployArbitration . tags = [ "Arbitration" ] ;
127- deployArbitration . skip = async ( { getChainId } ) => {
128- const chainId = Number ( await getChainId ( ) ) ;
129- return ! HomeChains [ chainId ] ;
124+ deployArbitration . skip = async ( { network } ) => {
125+ return isSkipped ( network , ! HomeChains [ network . config . chainId ?? 0 ] ) ;
130126} ;
131127
132- const deployERC20AndFaucet = async ( hre : HardhatRuntimeEnvironment , deployer : string , ticker : string ) => {
128+ const deployERC20AndFaucet = async (
129+ hre : HardhatRuntimeEnvironment ,
130+ deployer : string ,
131+ ticker : string
132+ ) : Promise < string > => {
133133 const { deploy } = hre . deployments ;
134134 const erc20 = await deploy ( ticker , {
135135 from : deployer ,
@@ -143,15 +143,14 @@ const deployERC20AndFaucet = async (hre: HardhatRuntimeEnvironment, deployer: st
143143 args : [ erc20 . address ] ,
144144 log : true ,
145145 } ) ;
146- const funding = hre . ethers . utils . parseUnits ( "100000" , "ether" ) ;
146+ const funding = hre . ethers . utils . parseUnits ( "100000" ) ;
147147 const erc20Instance = await hre . ethers . getContract ( ticker ) ;
148- // TODO: skip if already funded
149- await erc20Instance . balanceOf ( deployer ) . then ( ( balance ) => {
150- if ( balance . gte ( funding ) ) {
151- console . log ( "Funding %sFaucet with %d" , ticker , funding ) ;
152- return erc20Instance . transfer ( faucet . address , funding ) ;
153- }
154- } ) ;
148+ const faucetBalance = await erc20Instance . balanceOf ( faucet . address ) ;
149+ const deployerBalance = await erc20Instance . balanceOf ( deployer ) ;
150+ if ( deployerBalance . gte ( funding ) && faucetBalance . isZero ( ) ) {
151+ console . log ( "Funding %sFaucet with %d" , ticker , funding ) ;
152+ await erc20Instance . transfer ( faucet . address , funding ) ;
153+ }
155154 return erc20 . address ;
156155} ;
157156
0 commit comments