1
1
import { HardhatRuntimeEnvironment } from "hardhat/types" ;
2
2
import { DeployFunction } from "hardhat-deploy/types" ;
3
3
import { 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" ;
11
7
12
8
const pnkByChain = new Map < HomeChains , string > ( [
13
9
[ HomeChains . ARBITRUM_ONE , "0x330bD769382cFc6d50175903434CCC8D206DCAE5" ] ,
@@ -56,43 +52,44 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
56
52
randomizerByChain . set ( HomeChains [ HomeChains [ chainId ] ] , randomizerMock . address ) ;
57
53
}
58
54
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 } ) ;
64
56
65
57
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 } ) ;
72
59
73
- const disputeKit = await deploy ( "DisputeKitClassic" , {
60
+ const disputeKit = await deployUpgradable ( hre , "DisputeKitClassic" , {
74
61
from : deployer ,
75
62
args : [ deployer , AddressZero ] ,
76
63
log : true ,
77
64
} ) ;
78
65
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
+ }
82
72
83
- const sortitionModule = await deploy ( "SortitionModule" , {
73
+ const sortitionModule = await deployUpgradable ( hre , "SortitionModule" , {
84
74
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
+ ] ,
86
83
log : true ,
87
- } ) ;
84
+ } ) ; // nonce (implementation), nonce+1 (proxy)
88
85
89
86
const pnk = pnkByChain . get ( chainId ) ?? AddressZero ;
90
87
const dai = daiByChain . get ( chainId ) ?? AddressZero ;
91
88
const weth = wethByChain . get ( chainId ) ?? AddressZero ;
92
89
const minStake = BigNumber . from ( 10 ) . pow ( 20 ) . mul ( 2 ) ;
93
90
const alpha = 10000 ;
94
91
const feeForJuror = BigNumber . from ( 10 ) . pow ( 17 ) ;
95
- const klerosCore = await deploy ( "KlerosCore" , {
92
+ const klerosCore = await deployUpgradable ( hre , "KlerosCore" , {
96
93
from : deployer ,
97
94
args : [
98
95
deployer ,
@@ -106,7 +103,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
106
103
sortitionModule . address ,
107
104
] ,
108
105
log : true ,
109
- } ) ;
106
+ } ) ; // nonce+2 (implementation), nonce+3 (proxy)
110
107
111
108
// execute DisputeKitClassic.changeCore() only if necessary
112
109
const currentCore = await hre . ethers . getContractAt ( "DisputeKitClassic" , disputeKit . address ) . then ( ( dk ) => dk . core ( ) ) ;
@@ -124,12 +121,15 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
124
121
} ;
125
122
126
123
deployArbitration . 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 ] ) ;
130
126
} ;
131
127
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 > => {
133
133
const { deploy } = hre . deployments ;
134
134
const erc20 = await deploy ( ticker , {
135
135
from : deployer ,
@@ -143,15 +143,14 @@ const deployERC20AndFaucet = async (hre: HardhatRuntimeEnvironment, deployer: st
143
143
args : [ erc20 . address ] ,
144
144
log : true ,
145
145
} ) ;
146
- const funding = hre . ethers . utils . parseUnits ( "100000" , "ether" ) ;
146
+ const funding = hre . ethers . utils . parseUnits ( "100000" ) ;
147
147
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
+ }
155
154
return erc20 . address ;
156
155
} ;
157
156
0 commit comments