Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompile + refactor #103

Merged
merged 9 commits into from
Nov 10, 2023
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const config: HardhatUserConfig = {
accounts: [POLYGON_PRIVATE_KEY],
},
tevmos: {
url: "https://eth.bd.evmos.dev:8545",
url: "https://evmos-testnet.lava.build",
accounts: [TEVMOS_PRIVATE_KEY],
},
evmos: {
Expand Down
5 changes: 3 additions & 2 deletions tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import { question } from "../lib/utils";
const MULTISIG_MAINNET = "0xd232121c41EF9ad4e4d0251BdCbe60b9F3D20758";
const MULTISIG_TESTNET = "0x7549fe2ED3c16240f97FE736146347409C6dD81D";

task("deploy", "Deploy DAO")
task("deploy:dao", "Deploy DAO")
.addFlag("verify", "Verify contracts")
.addFlag("restart", "Start a new deployment from scratch")
.setAction(
async ({ verify, restart }: { verify: boolean; restart: boolean }, hre) => {
if (restart) await hre.run("compile", { force: true });
const neokingdom = await NeokingdomDAOHardhat.initialize(hre, {
verifyContracts: verify,
verbose: true,
Expand All @@ -28,7 +29,7 @@ task("deploy", "Deploy DAO")
}
);

task("setup", "Set up the DAO")
task("setup:dao", "Set up the DAO")
.addFlag("mainnet", "Go to Mainnet")
.setAction(async ({ mainnet }: { mainnet: boolean }, hre) => {
let sequence = SETUP_SEQUENCE_TESTNET;
Expand Down
136 changes: 50 additions & 86 deletions tasks/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,105 +1,69 @@
import { task } from "hardhat/config";

import {
GovernanceToken,
GovernanceToken__factory,
InternalMarket__factory,
ProxyAdmin,
ProxyAdmin__factory,
ResolutionManager__factory,
} from "../typechain";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { exit } from "process";

import { NeokingdomDAOHardhat } from "../lib";
import { NeokingdomContracts } from "../lib/internal/types";
import { question } from "../lib/utils";

task("upgrade:resolution", "Upgrade ResolutionManager", async (_, hre) => {
const resolutionFactory = (await hre.ethers.getContractFactory(
"ResolutionManager"
)) as ResolutionManager__factory;

function toPascalCase(str: string): string {
let words = str.split(/(?=[A-Z])/);

// Capitalize the first letter of each word, leave the rest as it is
let pascalCase = words
.map((word) => word[0].toUpperCase() + word.slice(1))
.join("");

return pascalCase;
}

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

async function upgrade(
hre: HardhatRuntimeEnvironment,
contractType: keyof NeokingdomContracts
) {
await hre.run("compile", { force: true });
const neokingdom = await NeokingdomDAOHardhat.initialize(hre);
const contracts = await neokingdom.loadContracts();
console.log("Upgrade ResolutionManager");
console.log(" Network:", hre.network.name);

const resolutionContract = await hre.upgrades.upgradeProxy(
contracts.resolutionManager.address,
resolutionFactory
);
await resolutionContract.deployed();

console.log(" Address:", resolutionContract.address);
console.log("Resolution upgraded");
});

task("upgrade:market", "Upgrade Internal Market", async (_, hre) => {
const internalMarketFactory = (await hre.ethers.getContractFactory(
"InternalMarket"
)) as InternalMarket__factory;

const neokingdom = await NeokingdomDAOHardhat.initialize(hre);
const contracts = await neokingdom.loadContracts();
console.log(`Upgrade InternalMarket ${contracts.internalMarket.address}`);
const contractTypeStr = toPascalCase(contractType);
const contractFactory = await hre.ethers.getContractFactory(contractTypeStr);
const proxyAddress = contracts[contractType].address;
console.log(`Upgrade ${contractTypeStr} ${proxyAddress}`);
console.log(" Network:", hre.network.name);

const answer = await question(
"This action is irreversible. Please type 'GO' to continue.\n"
);

if (answer == "GO") {
const internalMarketContract = await hre.upgrades.upgradeProxy(
contracts.internalMarket.address,
internalMarketFactory
const contractInstance = await hre.upgrades.upgradeProxy(
proxyAddress,
contractFactory
);
await internalMarketContract.deployed();
await contractInstance.deployed();

console.log(" Address:", internalMarketContract.address);
console.log("InternalMarket upgraded");
console.log(" Address:", contractInstance.address);
console.log(`${contractTypeStr} upgraded`);
}
});

task("upgrade:governance", "Upgrade Governance Token", async (_, hre) => {
const governanceTokenFactory = (await hre.ethers.getContractFactory(
"GovernanceToken"
)) as GovernanceToken__factory;

const neokingdom = await NeokingdomDAOHardhat.initialize(hre);
const contracts = await neokingdom.loadContracts();
console.log(`Upgrade GovernanceToken ${contracts.governanceToken.address}`);
console.log(" Network:", hre.network.name);

const answer = await question(
"This action is irreversible. Please type 'GO' to continue.\n"
);

if (answer == "GO") {
const governanceTokenContract = (await hre.upgrades.upgradeProxy(
contracts.governanceToken.address,
governanceTokenFactory
)) as GovernanceToken;
await governanceTokenContract.deployed();

console.log(" Address:", governanceTokenContract.address);
console.log("GovernanceToken upgraded");
}
});

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();
sirnicolaz marked this conversation as resolved.
Show resolved Hide resolved
}
);

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