Skip to content

Commit f57de75

Browse files
committed
chore: upgradeAll script and initializers
1 parent 069d76b commit f57de75

12 files changed

+192
-31
lines changed

contracts/deploy/upgrade-all.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { prompt, print } from "gluegun";
4+
import { deployUpgradable } from "./utils/deployUpgradable";
5+
import { HomeChains, isSkipped } from "./utils";
6+
import { getContractNamesFromNetwork } from "../scripts/utils/contracts";
7+
8+
const { bold } = print.colors;
9+
10+
const deployUpgradeAll: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
11+
const { deployments, getNamedAccounts, getChainId } = hre;
12+
13+
// fallback to hardhat node signers on local network
14+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
15+
const chainId = Number(await getChainId());
16+
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);
17+
18+
const { disputeKitClassic, disputeTemplateRegistry, evidence, core, policyRegistry, sortition } =
19+
await getContractNamesFromNetwork(hre);
20+
21+
const upgrade = async (contractName: string, initializer: string, args: any[]) => {
22+
try {
23+
print.highlight(`💣 Upgrading ${bold(contractName)}`);
24+
const { confirm } = await prompt.ask({
25+
type: "confirm",
26+
name: "confirm",
27+
message: "Are you sure you want to proceed?",
28+
});
29+
if (!confirm) {
30+
console.log("Operation cancelled by user.");
31+
return;
32+
}
33+
print.info(`Upgrading ${contractName}...`);
34+
35+
// await deployUpgradable(deployments, contractName, {
36+
// newImplementation: contractName,
37+
// initializer,
38+
// from: deployer,
39+
// args, // Warning: do not reinitialize existing state variables, only the new ones
40+
// });
41+
} catch (err) {
42+
console.error(err);
43+
throw err;
44+
}
45+
};
46+
47+
await upgrade(disputeKitClassic, "initializer2", []);
48+
await upgrade(disputeTemplateRegistry, "initialize2", []);
49+
await upgrade(evidence, "initialize2", []);
50+
await upgrade(core, "initialize3", []);
51+
await upgrade(policyRegistry, "initialize2", []);
52+
await upgrade(sortition, "initialize3", []);
53+
};
54+
55+
deployUpgradeAll.tags = ["UpgradeAll"];
56+
deployUpgradeAll.skip = async ({ network }) => {
57+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
58+
};
59+
60+
export default deployUpgradeAll;

contracts/deploy/upgrade-dispute-kit.ts renamed to contracts/deploy/upgrade-dispute-kit-v0.8.0.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { deployUpgradable } from "./utils/deployUpgradable";
44
import { HomeChains, isSkipped } from "./utils";
5+
import { getContractNamesFromNetwork } from "../scripts/utils/contracts";
56

67
const deployUpgradeDisputeKit: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
78
const { deployments, getNamedAccounts, getChainId } = hre;
@@ -12,10 +13,11 @@ const deployUpgradeDisputeKit: DeployFunction = async (hre: HardhatRuntimeEnviro
1213
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);
1314

1415
try {
15-
console.log("upgrading DisputeKitClassicNeo...");
16-
await deployUpgradable(deployments, "DisputeKitClassicNeo", {
17-
contract: "DisputeKitClassic",
18-
initializer: "initialize",
16+
const { disputeKitClassic: contractName } = await getContractNamesFromNetwork(hre);
17+
console.log(`upgrading ${contractName}...`);
18+
await deployUpgradable(deployments, contractName, {
19+
newImplementation: contractName,
20+
initializer: "initialize2",
1921
from: deployer,
2022
// Warning: do not reinitialize everything, only the new variables
2123
args: [],

contracts/deploy/upgrade-kleros-core.ts renamed to contracts/deploy/upgrade-kleros-core-v0.8.0.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { deployUpgradable } from "./utils/deployUpgradable";
44
import { HomeChains, isSkipped } from "./utils";
5+
import { getContractNamesFromNetwork } from "../scripts/utils/contracts";
56

67
const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
78
const { deployments, getNamedAccounts, getChainId } = hre;
@@ -12,10 +13,11 @@ const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnviro
1213
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);
1314

1415
try {
15-
console.log("upgrading KlerosCoreNeo...");
16-
await deployUpgradable(deployments, "KlerosCoreNeo", {
17-
newImplementation: "KlerosCoreNeo",
18-
initializer: "initialize",
16+
const { core: contractName } = await getContractNamesFromNetwork(hre);
17+
console.log(`upgrading ${contractName}...`);
18+
await deployUpgradable(deployments, contractName, {
19+
newImplementation: contractName,
20+
initializer: "initialize3",
1921
from: deployer,
2022
// Warning: do not reinitialize everything, only the new variables
2123
args: [],

contracts/deploy/upgrade-sortition-module-v0.9.0.ts renamed to contracts/deploy/upgrade-sortition-module-v0.8.0.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { deployUpgradable } from "./utils/deployUpgradable";
44
import { HomeChains, isSkipped } from "./utils";
5+
import { getContractNamesFromNetwork } from "../scripts/utils/contracts";
56

67
const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
78
const { deployments, getNamedAccounts, getChainId } = hre;
@@ -12,9 +13,10 @@ const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeE
1213
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);
1314

1415
try {
15-
console.log("upgrading SortitionModuleNeo...");
16-
await deployUpgradable(deployments, "SortitionModuleNeo", {
17-
newImplementation: "SortitionModuleNeo",
16+
const { sortition: contractName } = await getContractNamesFromNetwork(hre);
17+
console.log(`upgrading ${contractName}...`);
18+
await deployUpgradable(deployments, contractName, {
19+
newImplementation: contractName,
1820
initializer: "initialize3",
1921
from: deployer,
2022
// Warning: do not reinitialize everything, only the new variables

contracts/scripts/utils/contracts.ts

+87-20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
SortitionModuleUniversity,
1717
TransactionBatcher,
1818
KlerosCoreSnapshotProxy,
19+
EvidenceModule,
1920
} from "../../typechain-types";
2021

2122
export const Cores = {
@@ -26,6 +27,44 @@ export const Cores = {
2627

2728
export type Core = (typeof Cores)[keyof typeof Cores];
2829

30+
export const getContractNames = (coreType: Core) => {
31+
const coreSpecificNames = {
32+
[Cores.NEO]: {
33+
core: "KlerosCoreNeo",
34+
sortition: "SortitionModuleNeo",
35+
disputeKitClassic: "DisputeKitClassicNeo",
36+
disputeResolver: "DisputeResolverNeo",
37+
},
38+
[Cores.BASE]: {
39+
core: "KlerosCore",
40+
sortition: "SortitionModule",
41+
disputeKitClassic: "DisputeKitClassic",
42+
disputeResolver: "DisputeResolver",
43+
},
44+
[Cores.UNIVERSITY]: {
45+
core: "KlerosCoreUniversity",
46+
sortition: "SortitionModuleUniversity",
47+
disputeKitClassic: "DisputeKitClassicUniversity",
48+
disputeResolver: "DisputeResolverUniversity",
49+
},
50+
};
51+
52+
if (!(coreType in coreSpecificNames)) throw new Error("Invalid core type, must be one of BASE, NEO, or UNIVERSITY");
53+
54+
return {
55+
...coreSpecificNames[coreType],
56+
evidence: "EvidenceModule",
57+
disputeTemplateRegistry: "DisputeTemplateRegistry",
58+
policyRegistry: "PolicyRegistry",
59+
batcher: "TransactionBatcher",
60+
chainlinkRng: "ChainlinkRNG",
61+
randomizerRng: "RandomizerRNG",
62+
blockHashRNG: "BlockHashRNG",
63+
pnk: "PNK",
64+
snapshotProxy: "KlerosCoreSnapshotProxy",
65+
};
66+
};
67+
2968
export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Core) => {
3069
const { ethers } = hre;
3170
let core: KlerosCore | KlerosCoreNeo | KlerosCoreUniversity;
@@ -34,40 +73,46 @@ export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cor
3473
let disputeResolver: DisputeResolver;
3574
switch (coreType) {
3675
case Cores.NEO:
37-
core = await ethers.getContract<KlerosCoreNeo>("KlerosCoreNeo");
38-
sortition = await ethers.getContract<SortitionModuleNeo>("SortitionModuleNeo");
39-
disputeKitClassic = await ethers.getContract<DisputeKitClassic>("DisputeKitClassicNeo");
40-
disputeResolver = await ethers.getContract<DisputeResolver>("DisputeResolverNeo");
76+
core = await ethers.getContract<KlerosCoreNeo>(getContractNames(coreType).core);
77+
sortition = await ethers.getContract<SortitionModuleNeo>(getContractNames(coreType).sortition);
78+
disputeKitClassic = await ethers.getContract<DisputeKitClassic>(getContractNames(coreType).disputeKitClassic);
79+
disputeResolver = await ethers.getContract<DisputeResolver>(getContractNames(coreType).disputeResolver);
4180
break;
4281
case Cores.BASE:
43-
core = await ethers.getContract<KlerosCore>("KlerosCore");
44-
sortition = await ethers.getContract<SortitionModule>("SortitionModule");
45-
disputeKitClassic = await ethers.getContract<DisputeKitClassic>("DisputeKitClassic");
46-
disputeResolver = await ethers.getContract<DisputeResolver>("DisputeResolver");
82+
core = await ethers.getContract<KlerosCore>(getContractNames(coreType).core);
83+
sortition = await ethers.getContract<SortitionModule>(getContractNames(coreType).sortition);
84+
disputeKitClassic = await ethers.getContract<DisputeKitClassic>(getContractNames(coreType).disputeKitClassic);
85+
disputeResolver = await ethers.getContract<DisputeResolver>(getContractNames(coreType).disputeResolver);
4786
break;
4887
case Cores.UNIVERSITY:
49-
core = await ethers.getContract<KlerosCoreUniversity>("KlerosCoreUniversity");
50-
sortition = await ethers.getContract<SortitionModuleUniversity>("SortitionModuleUniversity");
51-
disputeKitClassic = await ethers.getContract<DisputeKitClassic>("DisputeKitClassicUniversity");
52-
disputeResolver = await ethers.getContract<DisputeResolver>("DisputeResolverUniversity");
88+
core = await ethers.getContract<KlerosCoreUniversity>(getContractNames(coreType).core);
89+
sortition = await ethers.getContract<SortitionModuleUniversity>(getContractNames(coreType).sortition);
90+
disputeKitClassic = await ethers.getContract<DisputeKitClassic>(getContractNames(coreType).disputeKitClassic);
91+
disputeResolver = await ethers.getContract<DisputeResolver>(getContractNames(coreType).disputeResolver);
5392
break;
5493
default:
5594
throw new Error("Invalid core type, must be one of BASE, NEO, or UNIVERSITY");
5695
}
57-
const disputeTemplateRegistry = await ethers.getContract<DisputeTemplateRegistry>("DisputeTemplateRegistry");
58-
const policyRegistry = await ethers.getContract<PolicyRegistry>("PolicyRegistry");
59-
const batcher = await ethers.getContract<TransactionBatcher>("TransactionBatcher");
60-
const chainlinkRng = await ethers.getContractOrNull<ChainlinkRNG>("ChainlinkRNG");
61-
const randomizerRng = await ethers.getContractOrNull<RandomizerRNG>("RandomizerRNG");
62-
const blockHashRNG = await ethers.getContractOrNull<BlockHashRNG>("BlockHashRNG");
63-
const pnk = await ethers.getContract<PNK>("PNK");
64-
const snapshotProxy = await ethers.getContractOrNull<KlerosCoreSnapshotProxy>("KlerosCoreSnapshotProxy");
96+
const disputeTemplateRegistry = await ethers.getContract<DisputeTemplateRegistry>(
97+
getContractNames(coreType).disputeTemplateRegistry
98+
);
99+
const evidence = await ethers.getContract<EvidenceModule>(getContractNames(coreType).evidence);
100+
const policyRegistry = await ethers.getContract<PolicyRegistry>(getContractNames(coreType).policyRegistry);
101+
const batcher = await ethers.getContract<TransactionBatcher>(getContractNames(coreType).batcher);
102+
const chainlinkRng = await ethers.getContractOrNull<ChainlinkRNG>(getContractNames(coreType).chainlinkRng);
103+
const randomizerRng = await ethers.getContractOrNull<RandomizerRNG>(getContractNames(coreType).randomizerRng);
104+
const blockHashRNG = await ethers.getContractOrNull<BlockHashRNG>(getContractNames(coreType).blockHashRNG);
105+
const pnk = await ethers.getContract<PNK>(getContractNames(coreType).pnk);
106+
const snapshotProxy = await ethers.getContractOrNull<KlerosCoreSnapshotProxy>(
107+
getContractNames(coreType).snapshotProxy
108+
);
65109
return {
66110
core,
67111
sortition,
68112
disputeKitClassic,
69113
disputeResolver,
70114
disputeTemplateRegistry,
115+
evidence,
71116
policyRegistry,
72117
chainlinkRng,
73118
randomizerRng,
@@ -77,3 +122,25 @@ export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cor
77122
snapshotProxy,
78123
};
79124
};
125+
126+
export const getContractsFromNetwork = async (hre: HardhatRuntimeEnvironment) => {
127+
const { network } = hre;
128+
if (network.name === "arbitrumSepoliaDevnet" || network.name === "arbitrumSepolia") {
129+
return getContracts(hre, Cores.BASE);
130+
} else if (network.name === "arbitrum") {
131+
return getContracts(hre, Cores.NEO);
132+
} else {
133+
throw new Error("Invalid network");
134+
}
135+
};
136+
137+
export const getContractNamesFromNetwork = async (hre: HardhatRuntimeEnvironment) => {
138+
const { network } = hre;
139+
if (network.name === "arbitrumSepoliaDevnet" || network.name === "arbitrumSepolia") {
140+
return getContractNames(Cores.BASE);
141+
} else if (network.name === "arbitrum") {
142+
return getContractNames(Cores.NEO);
143+
} else {
144+
throw new Error("Invalid network");
145+
}
146+
};

contracts/src/arbitration/DisputeTemplateRegistry.sol

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ contract DisputeTemplateRegistry is IDisputeTemplateRegistry, UUPSProxiable, Ini
4444
governor = _governor;
4545
}
4646

47+
function initialize2() external reinitializer(2) {
48+
// NOP
49+
}
50+
4751
// ************************ //
4852
// * Governance * //
4953
// ************************ //

contracts/src/arbitration/KlerosCore.sol

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ contract KlerosCore is KlerosCoreBase {
5656
);
5757
}
5858

59+
function initialize3() external reinitializer(3) {
60+
// NOP
61+
}
62+
5963
// ************************************* //
6064
// * Governance * //
6165
// ************************************* //

contracts/src/arbitration/KlerosCoreNeo.sol

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ contract KlerosCoreNeo is KlerosCoreBase {
6767
jurorNft = _jurorNft;
6868
}
6969

70+
function initialize3() external reinitializer(3) {
71+
// NOP
72+
}
73+
7074
// ************************************* //
7175
// * Governance * //
7276
// ************************************* //

contracts/src/arbitration/PolicyRegistry.sol

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ contract PolicyRegistry is UUPSProxiable, Initializable {
5151
governor = _governor;
5252
}
5353

54+
function initialize2() external reinitializer(2) {
55+
// NOP
56+
}
57+
5458
// ************************************* //
5559
// * Governance * //
5660
// ************************************* //

contracts/src/arbitration/devtools/KlerosCoreRuler.sol

+4
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable {
210210
);
211211
}
212212

213+
function initialize2() external reinitializer(2) {
214+
// NOP
215+
}
216+
213217
// ************************************* //
214218
// * Governance * //
215219
// ************************************* //

contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ contract DisputeKitClassic is DisputeKitClassicBase {
2929
__DisputeKitClassicBase_initialize(_governor, _core);
3030
}
3131

32+
function initialize2() external reinitializer(2) {
33+
// NOP
34+
}
35+
3236
// ************************ //
3337
// * Governance * //
3438
// ************************ //

contracts/src/arbitration/evidence/EvidenceModule.sol

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ contract EvidenceModule is IEvidence, Initializable, UUPSProxiable {
4141
governor = _governor;
4242
}
4343

44+
function initialize2() external reinitializer(2) {
45+
// NOP
46+
}
47+
4448
// ************************ //
4549
// * Governance * //
4650
// ************************ //

0 commit comments

Comments
 (0)