@@ -2,11 +2,11 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
2
2
import { DeployFunction } from "hardhat-deploy/types" ;
3
3
import { getContractAddress } from "./utils/getContractAddress" ;
4
4
import { deployUpgradable } from "./utils/deployUpgradable" ;
5
- import { changeCurrencyRate } from "./utils/klerosCoreHelper" ;
6
5
import { HomeChains , isSkipped , isDevnet , PNK , ETH } from "./utils" ;
7
6
import { getContractOrDeploy , getContractOrDeployUpgradable } from "./utils/getContractOrDeploy" ;
8
7
import { deployERC20AndFaucet } from "./utils/deployTokens" ;
9
8
import { ChainlinkRNG , DisputeKitClassic , KlerosCore } from "../typechain-types" ;
9
+ import { changeCurrencyRate } from "./utils/klerosCoreHelper" ;
10
10
11
11
const deployArbitration : DeployFunction = async ( hre : HardhatRuntimeEnvironment ) => {
12
12
const { ethers, deployments, getNamedAccounts, getChainId } = hre ;
@@ -29,65 +29,104 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
29
29
30
30
await getContractOrDeployUpgradable ( hre , "EvidenceModule" , { from : deployer , args : [ deployer ] , log : true } ) ;
31
31
32
- const disputeKit = await deployUpgradable ( deployments , "DisputeKitClassic " , {
32
+ const disputeKit = await deployUpgradable ( deployments , "DisputeKitClassicV2 " , {
33
33
from : deployer ,
34
- args : [ deployer , ZeroAddress ] ,
34
+ contract : "DisputeKitClassic" ,
35
+ args : [
36
+ deployer ,
37
+ ZeroAddress , // Placeholder for KlerosCore address, configured later
38
+ ] ,
35
39
log : true ,
36
40
} ) ;
37
41
38
- let klerosCoreAddress = await deployments . getOrNull ( "KlerosCore" ) . then ( ( deployment ) => deployment ?. address ) ;
39
- if ( ! klerosCoreAddress ) {
40
- const nonce = await ethers . provider . getTransactionCount ( deployer ) ;
41
- klerosCoreAddress = getContractAddress ( deployer , nonce + 3 ) ; // deployed on the 4th tx (nonce+3): SortitionModule Impl tx, SortitionModule Proxy tx, KlerosCore Impl tx, KlerosCore Proxy tx
42
- console . log ( "calculated future KlerosCore address for nonce %d: %s" , nonce + 3 , klerosCoreAddress ) ;
43
- }
42
+ // Calculate future addresses for circular dependencies
43
+ const nonce = await ethers . provider . getTransactionCount ( deployer ) ;
44
+
45
+ const vaultAddress = getContractAddress ( deployer , nonce + 1 ) ; // deployed on the 2nd tx (nonce+1): Vault Impl tx, Vault Proxy tx
46
+ console . log ( "calculated future Vault address for nonce %d: %s" , nonce + 1 , vaultAddress ) ;
47
+
48
+ const stakeControllerAddress = getContractAddress ( deployer , nonce + 5 ) ; // deployed on the 6th tx (nonce+5): Vault Impl tx, Vault Proxy tx, SortitionModule Impl tx, SortitionModule Proxy tx,, StakeController Impl tx, StakeController Proxy tx
49
+ console . log ( "calculated future StakeController address for nonce %d: %s" , nonce + 5 , stakeControllerAddress ) ;
50
+
51
+ const klerosCoreAddress = getContractAddress ( deployer , nonce + 7 ) ; // deployed on the 8th tx (nonce+7): Vault Impl tx, Vault Proxy tx, SortitionModule Impl tx, SortitionModule Proxy tx, StakeController Impl tx, StakeController Proxy tx, KlerosCore Impl tx, KlerosCore Proxy tx
52
+ console . log ( "calculated future KlerosCore address for nonce %d: %s" , nonce + 7 , klerosCoreAddress ) ;
53
+
54
+ const vault = await deployUpgradable ( deployments , "Vault" , {
55
+ from : deployer ,
56
+ args : [ deployer , pnk . target , stakeControllerAddress , klerosCoreAddress ] ,
57
+ log : true ,
58
+ } ) ; // nonce (implementation), nonce + 1 (proxy)
59
+
60
+ // Deploy SortitionSumTree
61
+ const sortitionModuleV2 = await deployUpgradable ( deployments , "SortitionSumTree" , {
62
+ from : deployer ,
63
+ args : [ deployer , stakeControllerAddress ] ,
64
+ log : true ,
65
+ } ) ; // nonce + 2 (implementation), nonce + 3 (proxy)
66
+
67
+ // Deploy StakeController
44
68
const devnet = isDevnet ( hre . network ) ;
45
69
const minStakingTime = devnet ? 180 : 1800 ;
46
- const maxFreezingTime = devnet ? 600 : 1800 ;
47
- const rng = ( await ethers . getContract ( "ChainlinkRNG" ) ) as ChainlinkRNG ;
48
- const sortitionModule = await deployUpgradable ( deployments , "SortitionModule " , {
70
+ const maxDrawingTime = devnet ? 600 : 1800 ;
71
+ const rng = await ethers . getContract < ChainlinkRNG > ( "ChainlinkRNG" ) ;
72
+ const stakeController = await deployUpgradable ( deployments , "StakeController " , {
49
73
from : deployer ,
50
- args : [ deployer , klerosCoreAddress , minStakingTime , maxFreezingTime , rng . target , RNG_LOOKAHEAD ] ,
74
+ args : [
75
+ deployer ,
76
+ klerosCoreAddress ,
77
+ vault . address ,
78
+ sortitionModuleV2 . address ,
79
+ rng . target ,
80
+ minStakingTime ,
81
+ maxDrawingTime ,
82
+ RNG_LOOKAHEAD ,
83
+ ] ,
51
84
log : true ,
52
- } ) ; // nonce (implementation), nonce+1 (proxy)
85
+ } ) ; // nonce + 4 (implementation), nonce + 5 (proxy)
53
86
54
87
const minStake = PNK ( 200 ) ;
55
88
const alpha = 10000 ;
56
89
const feeForJuror = ETH ( 0.1 ) ;
57
90
const jurorsForCourtJump = 256 ;
58
- const klerosCore = await deployUpgradable ( deployments , "KlerosCore" , {
91
+
92
+ // Deploy KlerosCore
93
+ const klerosCoreV2 = await deployUpgradable ( deployments , "KlerosCore" , {
59
94
from : deployer ,
60
95
args : [
61
96
deployer ,
62
97
deployer ,
63
- pnk . target ,
64
- ZeroAddress , // KlerosCore is configured later
98
+ ZeroAddress , // JurorProsecutionModule, not implemented yet
65
99
disputeKit . address ,
66
100
false ,
67
101
[ minStake , alpha , feeForJuror , jurorsForCourtJump ] ,
68
102
[ 0 , 0 , 0 , 10 ] , // evidencePeriod, commitPeriod, votePeriod, appealPeriod
69
103
ethers . toBeHex ( 5 ) , // Extra data for sortition module will return the default value of K
70
- sortitionModule . address ,
104
+ stakeController . address ,
105
+ vault . address ,
71
106
] ,
72
107
log : true ,
73
- } ) ; // nonce+2 (implementation), nonce+3 (proxy)
108
+ } ) ;
109
+
110
+ // Configure cross-dependencies
111
+ console . log ( "Configuring cross-dependencies..." ) ;
74
112
75
113
// disputeKit.changeCore() only if necessary
76
- const disputeKitContract = ( await ethers . getContract ( "DisputeKitClassic" ) ) as DisputeKitClassic ;
114
+ const disputeKitContract = await ethers . getContract < DisputeKitClassic > ( "DisputeKitClassicV2" ) ;
77
115
const currentCore = await disputeKitContract . core ( ) ;
78
- if ( currentCore !== klerosCore . address ) {
79
- console . log ( `disputeKit.changeCore(${ klerosCore . address } )` ) ;
80
- await disputeKitContract . changeCore ( klerosCore . address ) ;
116
+ if ( currentCore !== klerosCoreV2 . address ) {
117
+ console . log ( `disputeKit.changeCore(${ klerosCoreV2 . address } )` ) ;
118
+ await disputeKitContract . changeCore ( klerosCoreV2 . address ) ;
81
119
}
82
120
83
121
// rng.changeSortitionModule() only if necessary
122
+ // Note: the RNG's `sortitionModule` variable is misleading, it's only for access control and should be renamed to `consumer`.
84
123
const rngSortitionModule = await rng . sortitionModule ( ) ;
85
- if ( rngSortitionModule !== sortitionModule . address ) {
86
- console . log ( `rng.changeSortitionModule(${ sortitionModule . address } )` ) ;
87
- await rng . changeSortitionModule ( sortitionModule . address ) ;
124
+ if ( rngSortitionModule !== stakeController . address ) {
125
+ console . log ( `rng.changeSortitionModule(${ stakeController . address } )` ) ;
126
+ await rng . changeSortitionModule ( stakeController . address ) ;
88
127
}
89
128
90
- const core = ( await hre . ethers . getContract ( "KlerosCore" ) ) as KlerosCore ;
129
+ const core = await hre . ethers . getContract < KlerosCore > ( "KlerosCore" ) ;
91
130
try {
92
131
await changeCurrencyRate ( core , await pnk . getAddress ( ) , true , 12225583 , 12 ) ;
93
132
await changeCurrencyRate ( core , await dai . getAddress ( ) , true , 60327783 , 11 ) ;
@@ -98,9 +137,16 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
98
137
99
138
await deploy ( "KlerosCoreSnapshotProxy" , {
100
139
from : deployer ,
140
+ contract : "KlerosCoreSnapshotProxy" ,
101
141
args : [ deployer , core . target ] ,
102
142
log : true ,
103
143
} ) ;
144
+
145
+ console . log ( "✅ V2 Architecture deployment completed successfully!" ) ;
146
+ console . log ( `📦 Vault: ${ vault . address } ` ) ;
147
+ console . log ( `🎯 SortitionSumTree: ${ sortitionModuleV2 . address } ` ) ;
148
+ console . log ( `🎮 StakeController: ${ stakeController . address } ` ) ;
149
+ console . log ( `⚖️ KlerosCore: ${ klerosCoreV2 . address } ` ) ;
104
150
} ;
105
151
106
152
deployArbitration . tags = [ "Arbitration" ] ;
0 commit comments