Skip to content

Commit 598ce94

Browse files
committed
chore: scripts handling of the governor being a contract
1 parent 06da46c commit 598ce94

File tree

5 files changed

+113
-81
lines changed

5 files changed

+113
-81
lines changed

contracts/scripts/changeGovernor.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ const { bold } = print.colors;
66

77
task("change-governor", "Changes the governor for all the contracts")
88
.addPositionalParam("newGovernor", "The address of the new governor")
9-
.addOptionalParam(
10-
"coreType",
11-
"The type of core to use between base, neo, university (default: base)",
12-
Cores.BASE.toString()
13-
)
9+
.addOptionalParam("coreType", "The type of core to use between base, neo, university (default: base)", Cores.BASE)
1410
.setAction(async (taskArgs, hre) => {
1511
const newGovernor = taskArgs.newGovernor;
1612
print.highlight(`💣 Changing governor to ${bold(newGovernor)}`);
@@ -25,16 +21,22 @@ task("change-governor", "Changes the governor for all the contracts")
2521
return;
2622
}
2723

28-
let coreType = Cores.BASE;
29-
coreType = Cores[taskArgs.coreType.toUpperCase() as keyof typeof Cores];
24+
const coreType = Cores[taskArgs.coreType.toUpperCase() as keyof typeof Cores];
3025
if (coreType === undefined) {
3126
console.error("Invalid core type, must be one of base, neo, university");
3227
return;
3328
}
34-
console.log("Using core type %s", Cores[coreType]);
29+
console.log("Using core type %s", coreType);
3530

36-
const { core, disputeKitClassic, disputeResolver, disputeTemplateRegistry, chainlinkRng, randomizerRng } =
37-
await getContracts(hre, coreType);
31+
const {
32+
core,
33+
disputeKitClassic,
34+
disputeResolver,
35+
disputeTemplateRegistry,
36+
policyRegistry,
37+
chainlinkRng,
38+
randomizerRng,
39+
} = await getContracts(hre, coreType);
3840

3941
const updateGovernor = async (contractName: string, contractInstance: any) => {
4042
print.info(`Changing governor for ${contractName}`);
@@ -54,12 +56,13 @@ task("change-governor", "Changes the governor for all the contracts")
5456
};
5557

5658
// TODO: upgrade and add changeGovernor!
57-
// await updateGovernor("Sortition", sortition)
59+
// await updateGovernor("SortitionModule", sortition)
5860

5961
await updateGovernor("KlerosCore", core);
6062
await updateGovernor("DisputeKitClassic", disputeKitClassic);
6163
await updateGovernor("DisputeResolver", disputeResolver);
6264
await updateGovernor("DisputeTemplateRegistry", disputeTemplateRegistry);
65+
await updateGovernor("PolicyRegistry", policyRegistry);
6366
if (chainlinkRng) await updateGovernor("ChainlinkRNG", chainlinkRng);
6467
if (randomizerRng) await updateGovernor("RandomizerRNG", randomizerRng);
6568

contracts/scripts/populateCourts.ts

+42-59
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import courtsV2ArbitrumTestnet from "../config/courts.v2.testnet.json";
77
import courtsV2ArbitrumDevnet from "../config/courts.v2.devnet.json";
88
import courtsV2MainnetNeo from "../config/courts.v2.mainnet-neo.json";
99
import { isDevnet } from "../deploy/utils";
10+
import { execute } from "./utils/execution";
11+
import { getContracts, Cores } from "./utils/contracts";
1012

1113
enum HomeChains {
1214
ARBITRUM_ONE = 42161,
@@ -22,12 +24,6 @@ enum Sources {
2224
V2_MAINNET_NEO,
2325
}
2426

25-
enum Cores {
26-
BASE,
27-
NEO,
28-
UNIVERSITY,
29-
}
30-
3127
type Court = {
3228
id: number;
3329
parent: number;
@@ -57,11 +53,7 @@ task("populate:courts", "Populates the courts and their parameters")
5753
undefined,
5854
types.int
5955
)
60-
.addOptionalParam(
61-
"coreType",
62-
"The type of core to use between base, neo, university (default: base)",
63-
Cores.BASE.toString()
64-
)
56+
.addOptionalParam("coreType", "The type of core to use between base, neo, university (default: base)", Cores.BASE)
6557
.addFlag("reverse", "Iterates the courts in reverse order, useful to increase minStake in the child courts first")
6658
.addFlag("forceV1ParametersToDev", "Use development values for the v1 courts parameters")
6759
.setAction(async (taskArgs, hre) => {
@@ -90,13 +82,12 @@ task("populate:courts", "Populates the courts and their parameters")
9082
}
9183
console.log("Populating from source %s", Sources[from]);
9284

93-
let coreType = Cores.BASE;
94-
coreType = Cores[taskArgs.coreType.toUpperCase() as keyof typeof Cores];
85+
const coreType = Cores[taskArgs.coreType.toUpperCase() as keyof typeof Cores];
9586
if (coreType === undefined) {
9687
console.error("Invalid core type, must be one of base, neo, university");
9788
return;
9889
}
99-
console.log("Using core type %s", Cores[coreType]);
90+
console.log("Using core type %s", coreType);
10091

10192
const truncateWei = (x: bigint) => (x / TEN_THOUSAND_GWEI) * TEN_THOUSAND_GWEI;
10293

@@ -163,21 +154,7 @@ task("populate:courts", "Populates the courts and their parameters")
163154

164155
console.log("courtsV2 = %O", courtsV2);
165156

166-
let core: KlerosCore | KlerosCoreNeo | KlerosCoreUniversity;
167-
switch (coreType) {
168-
case Cores.UNIVERSITY:
169-
console.log("Using KlerosCoreUniversity");
170-
core = (await ethers.getContract("KlerosCoreUniversity")) as KlerosCoreUniversity;
171-
break;
172-
case Cores.NEO:
173-
console.log("Using KlerosCoreNeo");
174-
core = (await ethers.getContract("KlerosCoreNeo")) as KlerosCoreNeo;
175-
break;
176-
default:
177-
console.log("Using KlerosCore");
178-
core = (await ethers.getContract("KlerosCore")) as KlerosCore;
179-
break;
180-
}
157+
const { core } = await getContracts(hre, coreType);
181158

182159
for (const court of courtsV2) {
183160
const courtPresent = await core.courts(court.id).catch(() => {});
@@ -244,43 +221,49 @@ task("populate:courts", "Populates the courts and their parameters")
244221
continue;
245222
}
246223
try {
247-
await core.changeCourtParameters(
248-
court.id,
249-
court.hiddenVotes,
250-
court.minStake,
251-
court.alpha,
252-
court.feeForJuror,
253-
court.jurorsForCourtJump,
254-
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]]
255-
);
224+
await core.changeCourtParameters
225+
.populateTransaction(
226+
court.id,
227+
court.hiddenVotes,
228+
court.minStake,
229+
court.alpha,
230+
court.feeForJuror,
231+
court.jurorsForCourtJump,
232+
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]]
233+
)
234+
.then(execute);
256235
} catch (error) {
257236
console.error("Error changing court parameters: %s", error);
258237
}
259238
} else {
260239
console.log("Court %d not found, creating it with", court.id, court);
261240
if (coreType === Cores.UNIVERSITY) {
262-
await (core as KlerosCoreUniversity).createCourt(
263-
court.parent,
264-
court.hiddenVotes,
265-
court.minStake,
266-
court.alpha,
267-
court.feeForJuror,
268-
court.jurorsForCourtJump,
269-
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]],
270-
[DISPUTE_KIT_CLASSIC]
271-
);
241+
await (core as KlerosCoreUniversity).createCourt
242+
.populateTransaction(
243+
court.parent,
244+
court.hiddenVotes,
245+
court.minStake,
246+
court.alpha,
247+
court.feeForJuror,
248+
court.jurorsForCourtJump,
249+
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]],
250+
[DISPUTE_KIT_CLASSIC]
251+
)
252+
.then(execute);
272253
} else {
273-
await (core as KlerosCore).createCourt(
274-
court.parent,
275-
court.hiddenVotes,
276-
court.minStake,
277-
court.alpha,
278-
court.feeForJuror,
279-
court.jurorsForCourtJump,
280-
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]],
281-
ethers.toBeHex(5), // Not accessible on-chain, but has always been set to the same value so far.
282-
[DISPUTE_KIT_CLASSIC]
283-
);
254+
await (core as KlerosCore).createCourt
255+
.populateTransaction(
256+
court.parent,
257+
court.hiddenVotes,
258+
court.minStake,
259+
court.alpha,
260+
court.feeForJuror,
261+
court.jurorsForCourtJump,
262+
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]],
263+
ethers.toBeHex(5), // Not accessible on-chain, but has always been set to the same value so far.
264+
[DISPUTE_KIT_CLASSIC]
265+
)
266+
.then(execute);
284267
}
285268
}
286269

contracts/scripts/populatePolicyRegistry.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import policiesV2ArbitrumTestnet from "../config/policies.v2.testnet.json";
66
import policiesV2ArbitrumDevnet from "../config/policies.v2.devnet.json";
77
import policiesV2MainnetNeo from "../config/policies.v2.mainnet-neo.json";
88
import { isDevnet } from "../deploy/utils";
9+
import { execute } from "./utils/execution";
910

1011
enum HomeChains {
1112
ARBITRUM_ONE = 42161,
@@ -109,6 +110,6 @@ task("populate:policy-registry", "Populates the policy registry for each court")
109110

110111
for await (const policy of policiesV2) {
111112
console.log("Populating policy for %s Court (%d): %s", policy.name, policy.court, policy.uri);
112-
await policyRegistry.setPolicy(policy.court, policy.name, policy.uri);
113+
await policyRegistry.setPolicy.populateTransaction(policy.court, policy.name, policy.uri).then(execute);
113114
}
114115
});

contracts/scripts/utils/contracts.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@ import {
77
DisputeTemplateRegistry,
88
KlerosCore,
99
KlerosCoreNeo,
10+
KlerosCoreUniversity,
1011
PNK,
12+
PolicyRegistry,
1113
RandomizerRNG,
1214
SortitionModule,
1315
SortitionModuleNeo,
16+
SortitionModuleUniversity,
1417
TransactionBatcher,
1518
} from "../../typechain-types";
1619

17-
export enum Cores {
18-
BASE,
19-
NEO,
20-
UNIVERSITY,
21-
}
20+
export const Cores = {
21+
BASE: "BASE",
22+
NEO: "NEO",
23+
UNIVERSITY: "UNIVERSITY",
24+
} as const;
2225

23-
export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cores) => {
26+
export type Core = (typeof Cores)[keyof typeof Cores];
27+
28+
export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Core) => {
2429
const { ethers } = hre;
25-
let core: KlerosCore | KlerosCoreNeo;
26-
let sortition: SortitionModule | SortitionModuleNeo;
30+
let core: KlerosCore | KlerosCoreNeo | KlerosCoreUniversity;
31+
let sortition: SortitionModule | SortitionModuleNeo | SortitionModuleUniversity;
2732
let disputeKitClassic: DisputeKitClassic;
2833
let disputeResolver: DisputeResolver;
2934
switch (coreType) {
@@ -40,11 +45,16 @@ export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cor
4045
disputeResolver = (await ethers.getContract("DisputeResolver")) as DisputeResolver;
4146
break;
4247
case Cores.UNIVERSITY:
43-
throw new Error("University core is not supported");
48+
core = (await ethers.getContract("KlerosCoreUniversity")) as KlerosCoreUniversity;
49+
sortition = (await ethers.getContract("SortitionModuleUniversity")) as SortitionModuleUniversity;
50+
disputeKitClassic = (await ethers.getContract("DisputeKitClassicUniversity")) as DisputeKitClassic;
51+
disputeResolver = (await ethers.getContract("DisputeResolverUniversity")) as DisputeResolver;
52+
break;
4453
default:
45-
throw new Error("Invalid core type, must be one of base, neo");
54+
throw new Error("Invalid core type, must be one of BASE, NEO, or UNIVERSITY");
4655
}
4756
const disputeTemplateRegistry = (await ethers.getContract("DisputeTemplateRegistry")) as DisputeTemplateRegistry;
57+
const policyRegistry = (await ethers.getContract("PolicyRegistry")) as PolicyRegistry;
4858
const batcher = (await ethers.getContract("TransactionBatcher")) as TransactionBatcher;
4959
const chainlinkRng = await ethers.getContractOrNull<ChainlinkRNG>("ChainlinkRNG");
5060
const randomizerRng = await ethers.getContractOrNull<RandomizerRNG>("RandomizerRNG");
@@ -56,6 +66,7 @@ export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cor
5666
disputeKitClassic,
5767
disputeResolver,
5868
disputeTemplateRegistry,
69+
policyRegistry,
5970
chainlinkRng,
6071
randomizerRng,
6172
blockHashRNG,

contracts/scripts/utils/execution.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { type ContractTransaction } from "ethers";
2+
3+
const governableAbi = [
4+
{
5+
inputs: [],
6+
name: "governor",
7+
outputs: [
8+
{
9+
internalType: "address",
10+
name: "",
11+
type: "address",
12+
},
13+
],
14+
stateMutability: "view",
15+
type: "function",
16+
},
17+
];
18+
19+
export const execute = async (tx: ContractTransaction) => {
20+
const hre = require("hardhat");
21+
const { ethers } = hre;
22+
23+
const contract = await ethers.getContractAt(governableAbi, tx.to);
24+
const governor = await contract.governor();
25+
const isContract = (await ethers.provider.getCode(governor)).length > 2;
26+
if (isContract) {
27+
// Don't execute, just log the tx. It must be submitted for execution separately.
28+
console.log("tx = %O", tx);
29+
} else {
30+
// Execute the tx
31+
const signer = (await ethers.getSigners())[0];
32+
await signer.sendTransaction(tx);
33+
}
34+
};

0 commit comments

Comments
 (0)