UNPKG

@vechain/vebetterdao-contracts

Version:

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

183 lines (182 loc) 9.27 kB
export const transferAdminRole = async (contract, oldAdmin, newAdminAddress) => { if (oldAdmin.address === newAdminAddress) return; const adminRole = await contract.DEFAULT_ADMIN_ROLE(); await contract .connect(oldAdmin) .grantRole(adminRole, newAdminAddress) .then(async (tx) => await tx.wait()); await contract .connect(oldAdmin) .renounceRole(adminRole, oldAdmin.address) .then(async (tx) => await tx.wait()); const newAdminSet = await contract.hasRole(adminRole, newAdminAddress); const oldAdminRemoved = !(await contract.hasRole(adminRole, oldAdmin.address)); if (!newAdminSet || !oldAdminRemoved) throw new Error("Admin role not set correctly on " + (await contract.getAddress())); console.log("Admin role transferred successfully on " + (await contract.getAddress())); }; export const transferMinterRole = async (contract, admin, oldMinterAddress, newMinterAddress) => { if (oldMinterAddress === newMinterAddress) return; const minterRole = await contract.MINTER_ROLE(); // If newMinterAddress is provided, set a new minter before revoking the old one // otherwise just revoke the old one if (newMinterAddress) { await contract .connect(admin) .grantRole(minterRole, newMinterAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .revokeRole(minterRole, oldMinterAddress) .then(async (tx) => await tx.wait()); const newMinterSet = await contract.hasRole(minterRole, newMinterAddress); const oldMinterRemoved = !(await contract.hasRole(minterRole, oldMinterAddress)); if (!newMinterSet || !oldMinterRemoved) throw new Error("Minter role not set correctly on " + (await contract.getAddress())); console.log("Minter role transferred successfully on " + (await contract.getAddress())); } else { await contract .connect(admin) .revokeRole(minterRole, oldMinterAddress) .then(async (tx) => await tx.wait()); const oldMinterRemoved = !(await contract.hasRole(minterRole, oldMinterAddress)); if (!oldMinterRemoved) throw new Error("Minter role not removed correctly on " + (await contract.getAddress())); console.log("Minter role revoked (without granting new) successfully on " + (await contract.getAddress())); } }; // Transfer governance role to treasury contract admin for intial phases of project export const transferGovernanceRole = async (contract, admin, oldAddress, newAddress) => { if (oldAddress === newAddress) return; const governanceRole = await contract.GOVERNANCE_ROLE(); // If newAddress is provided, set a new admin before revoking the old one // otherwise just revoke the old one if (newAddress) { await contract .connect(admin) .grantRole(governanceRole, newAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .revokeRole(governanceRole, oldAddress) .then(async (tx) => await tx.wait()); const newGovernanceSet = await contract.hasRole(governanceRole, newAddress); const oldGovernanceRemoved = !(await contract.hasRole(governanceRole, oldAddress)); if (!newGovernanceSet || !oldGovernanceRemoved) throw new Error("Minter role not set correctly on " + (await contract.getAddress())); console.log("Governance role transferred successfully on " + (await contract.getAddress())); } else { await contract .connect(admin) .revokeRole(governanceRole, oldAddress) .then(async (tx) => await tx.wait()); const oldGovernanceRemoved = !(await contract.hasRole(governanceRole, oldAddress)); if (!oldGovernanceRemoved) throw new Error("Governance role not removed correctly on " + (await contract.getAddress())); console.log("Governance role revoked (without granting new) successfully on " + (await contract.getAddress())); } }; export const transferContractsAddressManagerRole = async (contract, admin, newAddress) => { if (admin.address === newAddress) return; const contractsAddressManagerRole = await contract.CONTRACTS_ADDRESS_MANAGER_ROLE(); await contract .connect(admin) .grantRole(contractsAddressManagerRole, newAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .renounceRole(contractsAddressManagerRole, admin.address) .then(async (tx) => await tx.wait()); const newRoleSet = await contract.hasRole(contractsAddressManagerRole, newAddress); const oldRoleRemoved = !(await contract.hasRole(contractsAddressManagerRole, admin.address)); if (!newRoleSet || !oldRoleRemoved) throw new Error("Role not set correctly on " + (await contract.getAddress())); console.log("Contract Address Manager Role transferred successfully on " + (await contract.getAddress())); }; export const transferDecaySettingsManagerRole = async (contract, admin, newAddress) => { if (admin.address === newAddress) return; const decaySettingsManagerRole = await contract.DECAY_SETTINGS_MANAGER_ROLE(); await contract .connect(admin) .grantRole(decaySettingsManagerRole, newAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .renounceRole(decaySettingsManagerRole, admin.address) .then(async (tx) => await tx.wait()); const newRoleSet = await contract.hasRole(decaySettingsManagerRole, newAddress); const oldRoleRemoved = !(await contract.hasRole(decaySettingsManagerRole, admin.address)); if (!newRoleSet || !oldRoleRemoved) throw new Error("Role not set correctly on " + (await contract.getAddress())); console.log("Decay Settings Manager Role transferred successfully on " + (await contract.getAddress())); }; export const transferGovernorFunctionSettingsRole = async (contract, admin, newAddress) => { if (admin.address === newAddress) return; const governorFunctionSettingsRole = await contract.GOVERNOR_FUNCTIONS_SETTINGS_ROLE(); await contract .connect(admin) .grantRole(governorFunctionSettingsRole, newAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .renounceRole(governorFunctionSettingsRole, admin.address) .then(async (tx) => await tx.wait()); const newRoleSet = await contract.hasRole(governorFunctionSettingsRole, newAddress); const oldRoleRemoved = !(await contract.hasRole(governorFunctionSettingsRole, admin.address)); if (!newRoleSet || !oldRoleRemoved) throw new Error("Role not set correctly on " + (await contract.getAddress())); console.log("Governor Function Settings Role transferred successfully on " + (await contract.getAddress())); }; // Function that checks that roles are set correctly on the contracts export const validateContractRole = async (contract, expectedAddress, tempAdmin, role) => { if (expectedAddress === tempAdmin) return; const roleSet = await contract.hasRole(role, expectedAddress); // Check that the temporary admin does not have the role const roleRemoved = !(await contract.hasRole(role, tempAdmin)); if (!roleSet || !roleRemoved) throw new Error("Role " + role + " not set correctly on " + (await contract.getAddress())); }; export const transferSettingsManagerRole = async (contract, admin, newAddress) => { if (admin.address === newAddress) return; const settingsManagerRole = await contract.SETTINGS_MANAGER_ROLE(); await contract .connect(admin) .grantRole(settingsManagerRole, newAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .renounceRole(settingsManagerRole, admin.address) .then(async (tx) => await tx.wait()); const newRoleSet = await contract.hasRole(settingsManagerRole, newAddress); const oldRoleRemoved = !(await contract.hasRole(settingsManagerRole, admin.address)); if (!newRoleSet || !oldRoleRemoved) throw new Error("Role not set correctly on " + (await contract.getAddress())); console.log("Settings Manager Role transferred successfully on " + (await contract.getAddress())); }; export const transferUpgraderRole = async (contract, admin, newAddress) => { if (admin.address === newAddress) return; const upgraderRole = await contract.UPGRADER_ROLE(); await contract .connect(admin) .grantRole(upgraderRole, newAddress) .then(async (tx) => await tx.wait()); await contract .connect(admin) .renounceRole(upgraderRole, admin.address) .then(async (tx) => await tx.wait()); const newRoleSet = await contract.hasRole(upgraderRole, newAddress); const oldRoleRemoved = !(await contract.hasRole(upgraderRole, admin.address)); if (!newRoleSet || !oldRoleRemoved) throw new Error("Role not set correctly on " + (await contract.getAddress())); };