Skip to content

Commit

Permalink
feat(tasks): add task to transfer contract ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Feb 28, 2024
1 parent b24c10c commit 4ba2ac1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
1 change: 1 addition & 0 deletions tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ require('./get-roles')
require('./set_permissions')
require('./upgrade')
require('./upgrade-safe')
require('./transfer-ownership')
27 changes: 27 additions & 0 deletions tasks/transfer-ownership.js
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4ba2ac1

Please sign in to comment.