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" ] ,
@@ -63,89 +59,43 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6359 } ) ;
6460
6561 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- } ) ;
72-
73- const disputeKit = await deploy ( "DisputeKitClassic" , {
74- from : deployer ,
75- args : [ deployer , AddressZero ] ,
76- log : true ,
77- } ) ;
62+ const rng = await deployUpgradable ( hre , deployer , "RandomizerRNG" , [ randomizer , deployer ] ) ;
7863
79- let nonce ;
80- let KlerosCoreAddress ;
64+ const disputeKit = await deployUpgradable ( hre , deployer , "DisputeKitClassic" , [ deployer , AddressZero ] ) ;
8165
82- const klerosCoreDeployment = await deployments . getOrNull ( "KlerosCore" ) ;
83- if ( ! klerosCoreDeployment ) {
84- nonce = await ethers . provider . getTransactionCount ( deployer ) ;
85- KlerosCoreAddress = getContractAddress ( deployer , nonce + 3 ) ; // Deploying an upgradeable version of SortionModule requires 2 transactions instead of 1 (implementation then proxy)
86- console . log ( "calculated future KlerosCore address for nonce %d: %s" , nonce , KlerosCoreAddress ) ;
87- } else {
88- KlerosCoreAddress = klerosCoreDeployment . address ;
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 ) ; // Deploying an upgradeable version of SortitionModule requires 2 transactions instead of 1 (implementation then proxy)
70+ console . log ( "calculated future KlerosCore address for nonce %d: %s" , nonce , klerosCoreAddress ) ;
8971 }
9072
91- const sortitionModule = await deploy ( "SortitionModule" , {
92- from : deployer ,
93- proxy : {
94- proxyContract : "UUPSProxy" ,
95- proxyArgs : [ "{implementation}" , "{data}" ] ,
96- checkProxyAdmin : false ,
97- checkABIConflict : false ,
98- execute : {
99- init : {
100- methodName : "initialize" ,
101- args : [ deployer , KlerosCoreAddress , 1800 , 1800 , rng . address , RNG_LOOKAHEAD ] , // minStakingTime, maxFreezingTime
102- } ,
103- onUpgrade : {
104- methodName : "governor" ,
105- args : [ ] ,
106- } ,
107- } ,
108- } ,
109- log : true ,
110- } ) ;
73+ const sortitionModule = await deployUpgradable ( hre , deployer , "SortitionModule" , [
74+ deployer ,
75+ klerosCoreAddress ,
76+ 1800 , // minStakingTime
77+ 1800 , // maxFreezingTime
78+ rng . address ,
79+ RNG_LOOKAHEAD ,
80+ ] ) ;
11181
11282 const pnk = pnkByChain . get ( chainId ) ?? AddressZero ;
11383 const dai = daiByChain . get ( chainId ) ?? AddressZero ;
11484 const weth = wethByChain . get ( chainId ) ?? AddressZero ;
11585 const minStake = BigNumber . from ( 10 ) . pow ( 20 ) . mul ( 2 ) ;
11686 const alpha = 10000 ;
11787 const feeForJuror = BigNumber . from ( 10 ) . pow ( 17 ) ;
118- const klerosCore = await deploy ( "KlerosCore" , {
119- from : deployer ,
120- proxy : {
121- proxyContract : "UUPSProxy" ,
122- proxyArgs : [ "{implementation}" , "{data}" ] ,
123- checkProxyAdmin : false ,
124- checkABIConflict : false ,
125- execute : {
126- init : {
127- methodName : "initialize" ,
128- args : [
129- deployer ,
130- pnk ,
131- AddressZero ,
132- disputeKit . address ,
133- false ,
134- [ minStake , alpha , feeForJuror , 256 ] , // minStake, alpha, feeForJuror, jurorsForCourtJump
135- [ 0 , 0 , 0 , 10 ] , // evidencePeriod, commitPeriod, votePeriod, appealPeriod
136- ethers . utils . hexlify ( 5 ) , // Extra data for sortition module will return the default value of K
137- sortitionModule . address ,
138- ] ,
139- } ,
140- onUpgrade : {
141- methodName : "governor" ,
142- args : [ ] ,
143- } ,
144- } ,
145- } ,
146- args : [ ] ,
147- log : true ,
148- } ) ;
88+ const klerosCore = await deployUpgradable ( hre , deployer , "KlerosCore" , [
89+ deployer ,
90+ pnk ,
91+ AddressZero ,
92+ disputeKit . address ,
93+ false ,
94+ [ minStake , alpha , feeForJuror , 256 ] , // minStake, alpha, feeForJuror, jurorsForCourtJump
95+ [ 0 , 0 , 0 , 10 ] , // evidencePeriod, commitPeriod, votePeriod, appealPeriod
96+ ethers . utils . hexlify ( 5 ) , // Extra data for sortition module will return the default value of K
97+ sortitionModule . address ,
98+ ] ) ;
14999
150100 // execute DisputeKitClassic.changeCore() only if necessary
151101 const currentCore = await hre . ethers . getContractAt ( "DisputeKitClassic" , disputeKit . address ) . then ( ( dk ) => dk . core ( ) ) ;
@@ -163,9 +113,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
163113} ;
164114
165115deployArbitration . tags = [ "Arbitration" ] ;
166- deployArbitration . skip = async ( { getChainId } ) => {
167- const chainId = Number ( await getChainId ( ) ) ;
168- return ! HomeChains [ chainId ] ;
116+ deployArbitration . skip = async ( { network } ) => {
117+ return isSkipped ( network , ! HomeChains [ network . config . chainId ?? 0 ] ) ;
169118} ;
170119
171120const deployERC20AndFaucet = async (
0 commit comments