From 870e7905145001de50926610946915a00ddddc11 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Wed, 20 Dec 2023 10:51:55 +0100 Subject: [PATCH] Small fixes in deployment scripts --- deploy/001_deploy_hub_v2.ts | 22 ++++++++++++++++------ deploy/002_deploy_hub.ts | 22 +++++++++++++++------- utils/helpers.ts | 2 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/deploy/001_deploy_hub_v2.ts b/deploy/001_deploy_hub_v2.ts index 0bfe78d7..0da15b52 100644 --- a/deploy/001_deploy_hub_v2.ts +++ b/deploy/001_deploy_hub_v2.ts @@ -46,8 +46,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const hubAddress = hre.helpers.contractDeployments.contracts['Hub'].evmAddress; const Hub = await hre.ethers.getContractAt('Hub', hubAddress, deployer); - const transferHubOwneshipTx = await Hub.transferOwnership(HubController.address); - await transferHubOwneshipTx.wait(); + const hubOwner = await Hub.owner(); + + if (deployer.toLowerCase() === hubOwner.toLowerCase()) { + const transferHubOwneshipTx = await Hub.transferOwnership(HubController.address); + await transferHubOwneshipTx.wait(); + + console.log(`Hub ownership transferred to HubController (${HubController.address})`); + } } else { const previousHubController = await hre.ethers.getContractAt( 'HubController', @@ -55,11 +61,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { deployer, ); - const transferHubOwneshipTx = await previousHubController.transferHubOwnership(HubController.address); - await transferHubOwneshipTx.wait(); - } + const previousHubControllerOwner = await previousHubController.owner(); - console.log(`Hub ownership transferred to HubController (${HubController.address})`); + if (deployer.toLowerCase() === previousHubControllerOwner.toLowerCase()) { + const transferHubOwneshipTx = await previousHubController.transferHubOwnership(HubController.address); + await transferHubOwneshipTx.wait(); + + console.log(`Hub ownership transferred to HubController (${HubController.address})`); + } + } } }; diff --git a/deploy/002_deploy_hub.ts b/deploy/002_deploy_hub.ts index 8be8f900..fb372910 100644 --- a/deploy/002_deploy_hub.ts +++ b/deploy/002_deploy_hub.ts @@ -46,21 +46,29 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const hubAddress = hre.helpers.contractDeployments.contracts['Hub'].evmAddress; const Hub = await hre.ethers.getContractAt('Hub', hubAddress, deployer); - const transferHubOwneshipTx = await Hub.transferOwnership(HubController.address); - await transferHubOwneshipTx.wait(); + const hubOwner = await Hub.owner(); - console.log(`Hub ownership transferred to HubController (${HubController.address})`); - } else if (hre.network.config.environment !== 'testnet' && hre.network.config.environment !== 'mainnet') { + if (deployer.toLowerCase() === hubOwner.toLowerCase()) { + const transferHubOwneshipTx = await Hub.transferOwnership(HubController.address); + await transferHubOwneshipTx.wait(); + + console.log(`Hub ownership transferred to HubController (${HubController.address})`); + } + } else { const previousHubController = await hre.ethers.getContractAt( 'HubController', previousHubControllerAddress, deployer, ); - const transferHubOwneshipTx = await previousHubController.transferHubOwnership(HubController.address); - await transferHubOwneshipTx.wait(); + const previousHubControllerOwner = await previousHubController.owner(); + + if (deployer.toLowerCase() === previousHubControllerOwner.toLowerCase()) { + const transferHubOwneshipTx = await previousHubController.transferHubOwnership(HubController.address); + await transferHubOwneshipTx.wait(); - console.log(`Hub ownership transferred to HubController (${HubController.address})`); + console.log(`Hub ownership transferred to HubController (${HubController.address})`); + } } } }; diff --git a/utils/helpers.ts b/utils/helpers.ts index 16eba1bc..a786ddc7 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -213,7 +213,7 @@ export class Helpers { await this.updateDeploymentsJson(nameInHub, newContract.address); - return await this.hre.ethers.getContractAt(newContractName, newContract.address, deployer); + return await this.hre.ethers.getContractAt(this.getAbi(newContractName), newContract.address, deployer); } public async updateContractParameters(contractName: string, contract: Contract) {