Skip to content

Commit 9377b31

Browse files
committed
fix: feedback from coderabbit
1 parent 5b5ea11 commit 9377b31

File tree

5 files changed

+49
-32
lines changed

5 files changed

+49
-32
lines changed

contracts/scripts/changeGovernor.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { task } from "hardhat/config";
22
import { prompt, print } from "gluegun";
33
import { Cores, getContracts } from "./utils/contracts";
4+
import { isAddress } from "viem";
45

56
const { bold } = print.colors;
67

@@ -9,6 +10,9 @@ task("change-governor", "Changes the governor for all the contracts")
910
.addOptionalParam("coreType", "The type of core to use between base, neo, university (default: base)", Cores.BASE)
1011
.setAction(async (taskArgs, hre) => {
1112
const newGovernor = taskArgs.newGovernor;
13+
if (!isAddress(newGovernor)) {
14+
throw new Error("Invalid governor address provided");
15+
}
1216
print.highlight(`💣 Changing governor to ${bold(newGovernor)}`);
1317

1418
const { confirm } = await prompt.ask({

contracts/scripts/getDisputeTemplate.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ import { IDisputeTemplateRegistry } from "../typechain-types";
44

55
task("get-dispute-template", "Gets a dispute template by ID")
66
.addPositionalParam("templateId", "The ID of the template to query")
7-
.setAction(async function ({ templateId }: { templateId: string }, hre: HardhatRuntimeEnvironment) {
7+
.setAction(async ({ templateId }: { templateId: string }, hre: HardhatRuntimeEnvironment) => {
88
const { ethers } = hre;
99

1010
// Get the contract instance
1111
const disputeTemplateRegistry = await ethers.getContract<IDisputeTemplateRegistry>("DisputeTemplateRegistry");
1212

1313
// Query the events
14-
const filter = disputeTemplateRegistry.filters.DisputeTemplate(BigInt(templateId));
15-
const events = await disputeTemplateRegistry.queryFilter(filter);
14+
let events;
15+
try {
16+
const filter = disputeTemplateRegistry.filters.DisputeTemplate(BigInt(templateId));
17+
events = await disputeTemplateRegistry.queryFilter(filter);
18+
} catch (error) {
19+
const errorMessage = error instanceof Error ? error.message : String(error);
20+
console.error(`Failed to query events for template ID ${templateId}:`, errorMessage);
21+
return;
22+
}
1623

1724
if (events.length === 0) {
1825
console.log(`No template found with ID ${templateId}`);

contracts/scripts/populateCourts.ts

+31-27
Original file line numberDiff line numberDiff line change
@@ -237,33 +237,37 @@ task("populate:courts", "Populates the courts and their parameters")
237237
}
238238
} else {
239239
console.log("Court %d not found, creating it with", court.id, court);
240-
if (coreType === Cores.UNIVERSITY) {
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);
253-
} else {
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);
240+
try {
241+
if (coreType === Cores.UNIVERSITY) {
242+
await (core as KlerosCoreUniversity).createCourt
243+
.populateTransaction(
244+
court.parent,
245+
court.hiddenVotes,
246+
court.minStake,
247+
court.alpha,
248+
court.feeForJuror,
249+
court.jurorsForCourtJump,
250+
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]],
251+
[DISPUTE_KIT_CLASSIC]
252+
)
253+
.then(execute);
254+
} else {
255+
await (core as KlerosCore).createCourt
256+
.populateTransaction(
257+
court.parent,
258+
court.hiddenVotes,
259+
court.minStake,
260+
court.alpha,
261+
court.feeForJuror,
262+
court.jurorsForCourtJump,
263+
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]],
264+
ethers.toBeHex(5), // Not accessible on-chain, but has always been set to the same value so far.
265+
[DISPUTE_KIT_CLASSIC]
266+
)
267+
.then(execute);
268+
}
269+
} catch (error) {
270+
console.error(`Failed to create court ${court.id}: ${error}`);
267271
}
268272
}
269273

contracts/scripts/utils/execution.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function writeTransactionBatch({ name, outputPath = "tx-batch.json" }: {
5050
try {
5151
const templateObject = template({ name, transactions });
5252
fs.writeFileSync(outputPath, JSON.stringify(templateObject, null, 2));
53+
transactions.length = 0;
5354
console.log(`Transaction batch written to ${outputPath}`);
5455
console.log(`The batch can be submitted to the Safe app at: ${transactionBuilderUrl}`);
5556
} catch (error) {

contracts/scripts/utils/tx-builder.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Transaction batch example: https://github.com/safe-global/safe-wallet-monorepo/blob/8bbf3b82edc347b70a038629cd9afd45eb1ed38a/apps/web/cypress/fixtures/test-working-batch.json
1+
import { arbitrum } from "viem/chains";
22

33
const governor = "0x66e8DE9B42308c6Ca913D1EE041d6F6fD037A57e";
44
const deployer = "0xf1C7c037891525E360C59f708739Ac09A7670c59";
55

6+
// Transaction batch example: https://github.com/safe-global/safe-wallet-monorepo/blob/8bbf3b82edc347b70a038629cd9afd45eb1ed38a/apps/web/cypress/fixtures/test-working-batch.json
67
export const template = ({ name, transactions }: { name: string; transactions: BuilderTransaction[] }) => ({
78
version: "1.0",
8-
chainId: "42161", // Arbitrum One
9+
chainId: arbitrum.id.toString(),
910
createdAt: Date.now(),
1011
meta: {
1112
name,

0 commit comments

Comments
 (0)