1
1
import { HardhatRuntimeEnvironment } from "hardhat/types" ;
2
2
import { DeployFunction } from "hardhat-deploy/types" ;
3
3
4
- const HOME_CHAIN_IDS = [ 42161 , 421611 , 31337 ] ; // ArbOne, ArbRinkeby, Hardhat
4
+ enum HomeChains {
5
+ ARBITRUM_ONE = 42161 ,
6
+ ARBITRUM_RINKEBY = 421611 ,
7
+ HARDHAT = 31337 ,
8
+ }
9
+
10
+ const pnkByChain = new Map < HomeChains , string > ( [
11
+ [ HomeChains . ARBITRUM_ONE , "0x330bD769382cFc6d50175903434CCC8D206DCAE5" ] ,
12
+ [ HomeChains . ARBITRUM_RINKEBY , "0x364530164a2338cdba211f72c1438eb811b5c639" ] ,
13
+ ] ) ;
5
14
6
15
const deployArbitration : DeployFunction = async ( hre : HardhatRuntimeEnvironment ) => {
7
- const { deployments, getNamedAccounts } = hre ;
16
+ const { deployments, getNamedAccounts, getChainId } = hre ;
8
17
const { deploy, execute } = deployments ;
9
18
const { AddressZero } = hre . ethers . constants ;
10
19
11
20
// fallback to hardhat node signers on local network
12
21
const deployer = ( await getNamedAccounts ( ) ) . deployer ?? ( await hre . ethers . getSigners ( ) ) [ 0 ] . address ;
13
- console . log ( "deployer: %s" , deployer ) ;
22
+ const chainId = Number ( await getChainId ( ) ) ;
23
+ console . log ( "deploying to %s with deployer %s" , HomeChains [ chainId ] , deployer ) ;
14
24
15
25
const rng = await deploy ( "ConstantNG" , {
16
26
from : deployer ,
@@ -29,21 +39,39 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
29
39
log : true ,
30
40
} ) ;
31
41
32
- // TODO: deploy a PNK token if there isn't one already
42
+ if ( chainId === HomeChains . HARDHAT ) {
43
+ pnkByChain . set (
44
+ HomeChains . HARDHAT ,
45
+ (
46
+ await deploy ( "PNK" , {
47
+ from : deployer ,
48
+ log : true ,
49
+ } )
50
+ ) . address
51
+ ) ;
52
+ }
53
+ const pnk = pnkByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
33
54
34
55
const klerosCore = await deploy ( "KlerosCore" , {
35
56
from : deployer ,
36
57
libraries : {
37
58
SortitionSumTreeFactory : sortitionSumTreeLibrary . address ,
38
59
} ,
39
- args : [ deployer , AddressZero , AddressZero , disputeKit . address , false , 200 , 10000 , 100 , 3 , [ 0 , 0 , 0 , 0 ] , 3 ] ,
60
+ args : [ deployer , pnk , AddressZero , disputeKit . address , false , 200 , 10000 , 100 , 3 , [ 0 , 0 , 0 , 0 ] , 3 ] ,
40
61
log : true ,
41
62
} ) ;
42
63
43
- await execute ( "DisputeKitClassic" , { from : deployer , log : true } , "changeCore" , klerosCore . address ) ;
64
+ // execute DisputeKitClassic.changeCore() only if necessary
65
+ const currentCore = await hre . ethers . getContractAt ( "DisputeKitClassic" , disputeKit . address ) . then ( ( dk ) => dk . core ( ) ) ;
66
+ if ( currentCore !== klerosCore . address ) {
67
+ await execute ( "DisputeKitClassic" , { from : deployer , log : true } , "changeCore" , klerosCore . address ) ;
68
+ }
44
69
} ;
45
70
46
71
deployArbitration . tags = [ "HomeChain" , "Arbitration" ] ;
47
- deployArbitration . skip = async ( { getChainId } ) => ! HOME_CHAIN_IDS . includes ( Number ( await getChainId ( ) ) ) ;
72
+ deployArbitration . skip = async ( { getChainId } ) => {
73
+ const chainId = Number ( await getChainId ( ) ) ;
74
+ return ! HomeChains [ chainId ] ;
75
+ } ;
48
76
49
77
export default deployArbitration ;
0 commit comments