-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
54 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(1); | ||
} | ||
); | ||
|
||
await upgrade(hre, contract as keyof NeokingdomContracts); | ||
}); |