Skip to content

Commit d99def1

Browse files
committed
refactor: removed unnecessary base contract for Stake Controller and Sortition Sum Tree, deploy scripts cleanup
1 parent 0eb3292 commit d99def1

9 files changed

+845
-1105
lines changed

contracts/deploy/00-home-chain-arbitration-v2-neo.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

contracts/deploy/00-home-chain-arbitration-v2.ts

Lines changed: 0 additions & 158 deletions
This file was deleted.

contracts/deploy/00-home-chain-arbitration.ts

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { getContractAddress } from "./utils/getContractAddress";
44
import { deployUpgradable } from "./utils/deployUpgradable";
5-
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
65
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
76
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
87
import { deployERC20AndFaucet } from "./utils/deployTokens";
98
import { ChainlinkRNG, DisputeKitClassic, KlerosCore } from "../typechain-types";
9+
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
1010

1111
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
@@ -29,65 +29,104 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2929

3030
await getContractOrDeployUpgradable(hre, "EvidenceModule", { from: deployer, args: [deployer], log: true });
3131

32-
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassic", {
32+
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassicV2", {
3333
from: deployer,
34-
args: [deployer, ZeroAddress],
34+
contract: "DisputeKitClassic",
35+
args: [
36+
deployer,
37+
ZeroAddress, // Placeholder for KlerosCore address, configured later
38+
],
3539
log: true,
3640
});
3741

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
4468
const devnet = isDevnet(hre.network);
4569
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", {
4973
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+
],
5184
log: true,
52-
}); // nonce (implementation), nonce+1 (proxy)
85+
}); // nonce + 4 (implementation), nonce + 5 (proxy)
5386

5487
const minStake = PNK(200);
5588
const alpha = 10000;
5689
const feeForJuror = ETH(0.1);
5790
const jurorsForCourtJump = 256;
58-
const klerosCore = await deployUpgradable(deployments, "KlerosCore", {
91+
92+
// Deploy KlerosCore
93+
const klerosCoreV2 = await deployUpgradable(deployments, "KlerosCore", {
5994
from: deployer,
6095
args: [
6196
deployer,
6297
deployer,
63-
pnk.target,
64-
ZeroAddress, // KlerosCore is configured later
98+
ZeroAddress, // JurorProsecutionModule, not implemented yet
6599
disputeKit.address,
66100
false,
67101
[minStake, alpha, feeForJuror, jurorsForCourtJump],
68102
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
69103
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
70-
sortitionModule.address,
104+
stakeController.address,
105+
vault.address,
71106
],
72107
log: true,
73-
}); // nonce+2 (implementation), nonce+3 (proxy)
108+
});
109+
110+
// Configure cross-dependencies
111+
console.log("Configuring cross-dependencies...");
74112

75113
// disputeKit.changeCore() only if necessary
76-
const disputeKitContract = (await ethers.getContract("DisputeKitClassic")) as DisputeKitClassic;
114+
const disputeKitContract = await ethers.getContract<DisputeKitClassic>("DisputeKitClassicV2");
77115
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);
81119
}
82120

83121
// 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`.
84123
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);
88127
}
89128

90-
const core = (await hre.ethers.getContract("KlerosCore")) as KlerosCore;
129+
const core = await hre.ethers.getContract<KlerosCore>("KlerosCore");
91130
try {
92131
await changeCurrencyRate(core, await pnk.getAddress(), true, 12225583, 12);
93132
await changeCurrencyRate(core, await dai.getAddress(), true, 60327783, 11);
@@ -98,9 +137,16 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
98137

99138
await deploy("KlerosCoreSnapshotProxy", {
100139
from: deployer,
140+
contract: "KlerosCoreSnapshotProxy",
101141
args: [deployer, core.target],
102142
log: true,
103143
});
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}`);
104150
};
105151

106152
deployArbitration.tags = ["Arbitration"];

0 commit comments

Comments
 (0)