UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

109 lines (108 loc) 6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.upgradeGovernanceToV2 = void 0; const hardhat_1 = require("hardhat"); const deploy_1 = require("./deploy"); const common_1 = require("./common"); const upgradeGovernanceToV2 = async () => { const { governor, xAllocationVoting, otherAccount, owner } = await (0, deploy_1.getOrDeployContractInstances)({}); //////////////////////////// // ---------------------- Deploy Libraries V2 ---------------------- // Deploy Governor Clock Logic const GovernorClockLogic = await hardhat_1.ethers.getContractFactory("GovernorClockLogic"); const GovernorClockLogicLib = await GovernorClockLogic.deploy(); await GovernorClockLogicLib.waitForDeployment(); // Deploy Governor Configurator const GovernorConfigurator = await hardhat_1.ethers.getContractFactory("GovernorConfigurator"); const GovernorConfiguratorLib = await GovernorConfigurator.deploy(); await GovernorConfiguratorLib.waitForDeployment(); // Deploy Governor Function Restrictions Logic const GovernorFunctionRestrictionsLogic = await hardhat_1.ethers.getContractFactory("GovernorFunctionRestrictionsLogic"); const GovernorFunctionRestrictionsLogicLib = await GovernorFunctionRestrictionsLogic.deploy(); await GovernorFunctionRestrictionsLogicLib.waitForDeployment(); // Deploy Governor Governance Logic const GovernorGovernanceLogic = await hardhat_1.ethers.getContractFactory("GovernorGovernanceLogic"); const GovernorGovernanceLogicLib = await GovernorGovernanceLogic.deploy(); await GovernorGovernanceLogicLib.waitForDeployment(); // Deploy Governor Quorum Logic const GovernorQuorumLogic = await hardhat_1.ethers.getContractFactory("GovernorQuorumLogic", { libraries: { GovernorClockLogic: await GovernorClockLogicLib.getAddress(), }, }); const GovernorQuorumLogicLib = await GovernorQuorumLogic.deploy(); await GovernorQuorumLogicLib.waitForDeployment(); // Deploy Governor Proposal Logic const GovernorProposalLogic = await hardhat_1.ethers.getContractFactory("GovernorProposalLogic", { libraries: { GovernorClockLogic: await GovernorClockLogicLib.getAddress(), }, }); const GovernorProposalLogicLib = await GovernorProposalLogic.deploy(); await GovernorProposalLogicLib.waitForDeployment(); // Deploy Governor Votes Logic const GovernorVotesLogic = await hardhat_1.ethers.getContractFactory("GovernorVotesLogic", { libraries: { GovernorClockLogic: await GovernorClockLogicLib.getAddress(), }, }); const GovernorVotesLogicLib = await GovernorVotesLogic.deploy(); await GovernorVotesLogicLib.waitForDeployment(); // Deploy Governor Deposit Logic const GovernorDepositLogic = await hardhat_1.ethers.getContractFactory("GovernorDepositLogic", { libraries: { GovernorClockLogic: await GovernorClockLogicLib.getAddress(), }, }); const GovernorDepositLogicLib = await GovernorDepositLogic.deploy(); await GovernorDepositLogicLib.waitForDeployment(); // Deploy Governor State Logic const GovernorStateLogic = await hardhat_1.ethers.getContractFactory("GovernorStateLogic", { libraries: { GovernorClockLogic: await GovernorClockLogicLib.getAddress(), }, }); const GovernorStateLogicLib = await GovernorStateLogic.deploy(); await GovernorStateLogicLib.waitForDeployment(); // Start emissions await (0, common_1.bootstrapAndStartEmissions)(); const B3TRGovernorV2 = await hardhat_1.ethers.getContractFactory("B3TRGovernor", { libraries: { GovernorClockLogic: await GovernorClockLogicLib.getAddress(), GovernorConfigurator: await GovernorConfiguratorLib.getAddress(), GovernorDepositLogic: await GovernorDepositLogicLib.getAddress(), GovernorFunctionRestrictionsLogic: await GovernorFunctionRestrictionsLogicLib.getAddress(), GovernorProposalLogic: await GovernorProposalLogicLib.getAddress(), GovernorQuorumLogic: await GovernorQuorumLogicLib.getAddress(), GovernorStateLogic: await GovernorStateLogicLib.getAddress(), GovernorVotesLogic: await GovernorVotesLogicLib.getAddress(), }, }); const newGovernor = await B3TRGovernorV2.deploy(); await newGovernor.waitForDeployment(); const V1Contract = await hardhat_1.ethers.getContractAt("B3TRGovernor", await governor.getAddress()); // Now we can create a proposal const encodedFunctionCall = V1Contract.interface.encodeFunctionData("upgradeToAndCall", [ await newGovernor.getAddress(), "0x", ]); const descriptionUpgrade = "Upgrading Governance contracts"; const descriptionHash = hardhat_1.ethers.keccak256(hardhat_1.ethers.toUtf8Bytes(descriptionUpgrade)); const currentRoundId = await xAllocationVoting.currentRoundId(); const txGovernorUpgrade = await governor .connect(owner) .propose([await governor.getAddress()], [0], [encodedFunctionCall], descriptionUpgrade, currentRoundId + 1n, 0, { gasLimit: 10000000, }); const proposalIdGovernor = await (0, common_1.getProposalIdFromTx)(txGovernorUpgrade); await (0, common_1.getVot3Tokens)(otherAccount, "10000"); await (0, common_1.waitForProposalToBeActive)(proposalIdGovernor); await governor.connect(otherAccount).castVote(proposalIdGovernor, 1); await (0, common_1.waitForVotingPeriodToEnd)(proposalIdGovernor); await governor.queue([await governor.getAddress()], [0], [encodedFunctionCall], descriptionHash); await governor.execute([await governor.getAddress()], [0], [encodedFunctionCall], descriptionHash); // Check that the new implementation works const governorV2 = B3TRGovernorV2.attach(await governor.getAddress()); return governorV2; }; exports.upgradeGovernanceToV2 = upgradeGovernanceToV2;