diff --git a/lib/constants.js b/lib/constants.js index 89f73eb..b61470e 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -96,6 +96,8 @@ module.exports = { PARAM_METADATA: 'metadata', PARAM_DESC_METADATA: 'pNetwork metadata', PARAM_CONTRACT_FACTORY: 'factory', - PARAM_DESC_CONTRACT_FACTORY: "Contract factory name (e.g. 'EpochsManager')" + PARAM_DESC_CONTRACT_FACTORY: "Contract factory name (e.g. 'EpochsManager')", + PARAM_NEW_OWNER: 'newOwner', + PARAM_DESC_NEW_OWNER: 'New contract owner' } } diff --git a/tasks/index.js b/tasks/index.js index 4f48a60..79a591f 100644 --- a/tasks/index.js +++ b/tasks/index.js @@ -12,3 +12,4 @@ require('./get-roles') require('./set_permissions') require('./upgrade') require('./upgrade-safe') +require('./transfer-ownership') diff --git a/tasks/transfer-ownership.js b/tasks/transfer-ownership.js new file mode 100644 index 0000000..775ad14 --- /dev/null +++ b/tasks/transfer-ownership.js @@ -0,0 +1,27 @@ +const { Confirm } = require('enquirer') +const { task } = require('hardhat/config') + +const { + TASKS: { PARAM_ADDRESS, PARAM_DESC_ADDRESS, PARAM_NEW_OWNER, PARAM_DESC_NEW_OWNER } +} = require('../lib/constants') + +const main = async (_args, _hre) => { + const c = await _hre.ethers.getContractAt('Ownable', _args[PARAM_ADDRESS]) + + const upgradeConfirm = new Confirm({ + message: `Transfer ownership of ${_args[PARAM_ADDRESS]} to ${_args[PARAM_NEW_OWNER]}?` + }) + + if (!(await upgradeConfirm.run())) { + console.info('Quitting') + return + } + + await c.transferOwnership(_args[PARAM_NEW_OWNER]) + console.info(`✔ Ownership transferred to ${_args[PARAM_NEW_OWNER]}...`) +} + +task('permissions:transfer-ownership', ' Transfer contract ownership to a new owner') + .addPositionalParam(PARAM_ADDRESS, PARAM_DESC_ADDRESS) + .addPositionalParam(PARAM_NEW_OWNER, PARAM_DESC_NEW_OWNER) + .setAction(main)