|
| 1 | +import { task } from "hardhat/config"; |
| 2 | +import { prompt, print } from "gluegun"; |
| 3 | +import { Cores, getContracts } from "./utils/contracts"; |
| 4 | +import { isAddress } from "viem"; |
| 5 | + |
| 6 | +const { bold } = print.colors; |
| 7 | + |
| 8 | +task("change-owner", "Changes the owner for all the contracts") |
| 9 | + .addPositionalParam("newOwner", "The address of the new owner") |
| 10 | + .addOptionalParam("coreType", "The type of core to use between base, neo, university (default: base)", Cores.BASE) |
| 11 | + .setAction(async (taskArgs, hre) => { |
| 12 | + const newOwner = taskArgs.newOwner; |
| 13 | + if (!isAddress(newOwner)) { |
| 14 | + throw new Error("Invalid owner address provided"); |
| 15 | + } |
| 16 | + print.highlight(`💣 Changing owner to ${bold(newOwner)}`); |
| 17 | + |
| 18 | + const { confirm } = await prompt.ask({ |
| 19 | + type: "confirm", |
| 20 | + name: "confirm", |
| 21 | + message: "Are you sure you want to proceed?", |
| 22 | + }); |
| 23 | + if (!confirm) { |
| 24 | + console.log("Operation cancelled by user."); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + const coreType = Cores[taskArgs.coreType.toUpperCase() as keyof typeof Cores]; |
| 29 | + if (coreType === undefined) { |
| 30 | + console.error("Invalid core type, must be one of base, neo, university"); |
| 31 | + return; |
| 32 | + } |
| 33 | + console.log("Using core type %s", coreType); |
| 34 | + |
| 35 | + const { |
| 36 | + core, |
| 37 | + disputeKitClassic, |
| 38 | + disputeResolver, |
| 39 | + disputeTemplateRegistry, |
| 40 | + policyRegistry, |
| 41 | + chainlinkRng, |
| 42 | + randomizerRng, |
| 43 | + snapshotProxy, |
| 44 | + sortition, |
| 45 | + evidence, |
| 46 | + } = await getContracts(hre, coreType); |
| 47 | + |
| 48 | + const updateOwner = async (contractName: string, contractInstance: any) => { |
| 49 | + print.info(`Changing owner for ${contractName}`); |
| 50 | + |
| 51 | + const spinner = print.spin(`Executing transaction for ${contractName}...`); |
| 52 | + try { |
| 53 | + const tx = await contractInstance.changeOwner(newOwner); |
| 54 | + await tx.wait(); |
| 55 | + spinner.succeed(`Owner changed for ${contractName}, tx hash: ${tx.hash}`); |
| 56 | + } catch (error) { |
| 57 | + if (error instanceof Error) { |
| 58 | + spinner.fail(`Failed to change owner for ${contractName}: ${error.message}`); |
| 59 | + } else { |
| 60 | + spinner.fail(`Failed to change owner for ${contractName}: ${String(error)}`); |
| 61 | + } |
| 62 | + } |
| 63 | + }; |
| 64 | + |
| 65 | + await updateOwner("KlerosCore", core); |
| 66 | + await updateOwner("DisputeKitClassic", disputeKitClassic); |
| 67 | + await updateOwner("DisputeResolver", disputeResolver); |
| 68 | + await updateOwner("DisputeTemplateRegistry", disputeTemplateRegistry); |
| 69 | + await updateOwner("PolicyRegistry", policyRegistry); |
| 70 | + await updateOwner("KlerosCoreSnapshotProxy", snapshotProxy); |
| 71 | + await updateOwner("SortitionModule", sortition); |
| 72 | + await updateOwner("EvidenceModule", evidence); |
| 73 | + if (chainlinkRng) await updateOwner("ChainlinkRNG", chainlinkRng); |
| 74 | + if (randomizerRng) await updateOwner("RandomizerRNG", randomizerRng); |
| 75 | + |
| 76 | + print.success("Owner changed successfully"); |
| 77 | + }); |
0 commit comments