Skip to content

Commit

Permalink
Using 'development' environment from the network config instead of ju…
Browse files Browse the repository at this point in the history
…st hardhat in deployment scripts
  • Loading branch information
0xbraindevd committed Dec 11, 2023
1 parent 8145a38 commit 86eb3ce
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deploy/001_deploy_hub_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
(hre.helpers.contractDeployments.contracts['Hub'].version !== undefined &&
!hre.helpers.contractDeployments.contracts['Hub'].version.startsWith('1.'))
) {
if (hre.network.name === 'hardhat') {
if (hre.network.config.environment === 'development') {
hre.helpers.resetDeploymentsJson();
console.log('Hardhat deployments config reset.');
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/002_deploy_hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
(hre.helpers.contractDeployments.contracts['Hub'].version !== undefined &&
!hre.helpers.contractDeployments.contracts['Hub'].version.startsWith('2.'))
) {
if (hre.network.name === 'hardhat') {
if (hre.network.config.environment === 'development') {
hre.helpers.resetDeploymentsJson();
console.log('Hardhat deployments config reset.');
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/003_deploy_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const setTokenTx = await HubController.setContractAddress('Token', tokenAddress);
await setTokenTx.wait();
}
} else if (!isDeployed && hre.network.name === 'hardhat') {
} else if (!isDeployed && hre.network.config.environment === 'development') {
const Token = await hre.helpers.deploy({
newContractName: 'Token',
passHubInConstructor: false,
Expand Down
2 changes: 1 addition & 1 deletion deploy/007_deploy_sha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
});

if (!isDeployed) {
if (hre.network.name === 'hardhat') {
if (hre.network.config.environment === 'development') {
const { deployer } = await hre.getNamedAccounts();

const hubControllerAddress = hre.helpers.contractDeployments.contracts['HubController'].evmAddress;
Expand Down
2 changes: 1 addition & 1 deletion deploy/009_deploy_log2pldsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
});

if (!isDeployed) {
if (hre.network.name === 'hardhat') {
if (hre.network.config.environment === 'development') {
const { deployer } = await hre.getNamedAccounts();

const hubControllerAddress = hre.helpers.contractDeployments.contracts['HubController'].evmAddress;
Expand Down
5 changes: 1 addition & 4 deletions deploy/998_initialize_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
newScoreFunctions,
].every((arr) => arr.length === 0);

if (
!noChangesWereMade &&
(hre.network.config.environment === 'testnet' || hre.network.config.environment == 'mainnet')
) {
if (!noChangesWereMade && hre.network.config.environment !== 'development') {
const hubControllerAddress = hre.helpers.contractDeployments.contracts['HubController'].evmAddress;

console.log(`HubController: ${hubControllerAddress}`);
Expand Down
4 changes: 1 addition & 3 deletions deploy/999_save_deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const networkPrefixes = ['otp', 'gnosis'];

if (networkPrefixes.some((networkPrefix) => hre.network.name.startsWith(networkPrefix))) {
if (hre.network.config.environment !== 'development') {
hre.helpers.saveDeploymentsJson('deployments');
}
};
Expand Down
8 changes: 4 additions & 4 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Helpers {
log: true,
});
} catch (error) {
if (this.hre.network.name !== 'hardhat') {
if (this.hre.network.config.environment !== 'development') {
this.saveDeploymentsJson('deployments');
}
let message;
Expand All @@ -184,14 +184,14 @@ export class Helpers {

let tx;
if (setContractInHub) {
if (this.hre.network.name === 'hardhat') {
if (this.hre.network.config.environment === 'development') {
tx = await HubController.setContractAddress(nameInHub, newContract.address);
await tx.wait();
} else {
this.newContracts.push([nameInHub, newContract.address]);
}
} else if (setAssetStorageInHub) {
if (this.hre.network.name === 'hardhat') {
if (this.hre.network.config.environment === 'development') {
tx = await HubController.setAssetStorageAddress(nameInHub, newContract.address);
await tx.wait();
} else {
Expand All @@ -200,7 +200,7 @@ export class Helpers {
}

if (this.hasFunction(nameInHub, 'initialize')) {
if ((setContractInHub || setAssetStorageInHub) && this.hre.network.name === 'hardhat') {
if ((setContractInHub || setAssetStorageInHub) && this.hre.network.config.environment === 'development') {
const newContractInterface = new this.hre.ethers.utils.Interface(this.getAbi(nameInHub));
const initializeTx = await HubController.forwardCall(
newContract.address,
Expand Down

0 comments on commit 86eb3ce

Please sign in to comment.