Skip to content

Commit

Permalink
simplify upgrade scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sirnicolaz committed Nov 10, 2023
1 parent f152de8 commit cbc9e0d
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions tasks/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Contract, ContractFactory } from "ethers";
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ProxyAdmin } from "../typechain";
import { exit } from "process";

import { NeokingdomDAOHardhat } from "../lib";
import { NeokingdomContracts } from "../lib/internal/types";
Expand All @@ -19,6 +17,15 @@ function toPascalCase(str: string): string {
return pascalCase;
}

const validContracts = [
"governanceToken",
"internalMarket",
"redemptionController",
"resolutionManager",
"shareholderRegistry",
"voting",
];

async function upgrade(
hre: HardhatRuntimeEnvironment,
contractType: keyof NeokingdomContracts
Expand Down Expand Up @@ -49,34 +56,14 @@ async function upgrade(
}
}

task("upgrade:resolution", "Upgrade ResolutionManager", async (_, hre) => {
await upgrade(hre, "resolutionManager");
});

task("upgrade:market", "Upgrade Internal Market", async (_, hre) => {
await upgrade(hre, "internalMarket");
});

task("upgrade:governance", "Upgrade Governance Token", async (_, hre) => {
await upgrade(hre, "governanceToken");
});

task("impl", "Get Proxy Impl")
.addParam("admin", "Proxy Admin")
.addParam("address", "Proxy address")
.setAction(
async ({ admin, address }: { admin: string; address: string }, hre) => {
const [deployer] = await hre.ethers.getSigners();
const ProxyAdmin = await hre.ethers.getContractFactory("ProxyAdmin");
const proxyAdmin = ProxyAdmin.attach(admin).connect(
deployer
) as ProxyAdmin;

console.log(" Proxy Owner:", await proxyAdmin.owner());

console.log(
" Address:",
await proxyAdmin.getProxyImplementation(address)
);
task("upgrade")
.addPositionalParam("contract", "The smart contract to upgrade")
.setAction(async ({ contract }: { contract: string }, hre) => {
console.log(contract);
if (!validContracts.includes(contract)) {
console.error(`Invalid contract. Valid options are: ${validContracts}`);
exit();
}
);

await upgrade(hre, contract as keyof NeokingdomContracts);
});

0 comments on commit cbc9e0d

Please sign in to comment.