Skip to content

Commit

Permalink
Merge pull request #204 from OriginTrail/fix/revert-initialize-contra…
Browse files Browse the repository at this point in the history
…cts-script

Fix/revert initialize contracts script
  • Loading branch information
u-hubar authored Dec 11, 2023
2 parents 46f5605 + 86eb3ce commit c5685c6
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 39 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
33 changes: 6 additions & 27 deletions deploy/998_initialize_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,29 @@ 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;
const multiSigWalletAddress = process.env['MULTISIG_' + hre.network.name.toUpperCase()];

if (multiSigWalletAddress === undefined) {
throw new Error(`MULTISIG_ADDRESS should be defined in the environment for the ${hre.network.name} blockchain!`);
}

console.log(`HubController: ${hubControllerAddress}`);
console.log(`MultiSigWallet: ${multiSigWalletAddress}`);

const HubController = await hre.ethers.getContractAt('HubController', hubControllerAddress, deployer);
const MultiSigWallet = await hre.ethers.getContractAt('MultiSigWallet', multiSigWalletAddress, deployer);

console.log(`New or redeployed contracts: ${JSON.stringify(newContracts)}`);
console.log(`New or redeployed Asset Storage contracts: ${JSON.stringify(newAssetStorageContracts)}`);
console.log(`Initialized contracts: ${JSON.stringify(contractsForReinitialization)}`);
console.log(`Encoded data for parameters settings: ${JSON.stringify(setParametersEncodedData)}`);
console.log(`New or redeployed hash functions set in the proxy: ${JSON.stringify(newHashFunctions)}`);
console.log(`New or redeployed score functions set in the proxy: ${JSON.stringify(newScoreFunctions)}`);
console.log(`Initialized contracts: ${JSON.stringify(contractsForReinitialization)}`);
console.log(`Encoded data for parameters settings: ${JSON.stringify(setParametersEncodedData)}`);

// Prepare the data for the setAndReinitializeContracts function call
const encodedData = HubController.interface.encodeFunctionData('setAndReinitializeContracts', [
const setAndReinitializeContractsTx = await HubController.setAndReinitializeContracts(
newContracts,
newAssetStorageContracts,
newHashFunctions,
newScoreFunctions,
contractsForReinitialization,
setParametersEncodedData,
]);

MultiSigWallet.on('Submission', (transactionId) => {
console.log(`[Multisig] HubController.setAndReinitializeContracts Transaction ID: ${transactionId}`);
});

// Submit the transaction to the multisig wallet
const submitTx = await MultiSigWallet.submitTransaction(hubControllerAddress, 0, encodedData);
await submitTx.wait();

// After that, other owners of the multisig wallet should use 'confirmTransaction' function.
// When needed confirmations amount is reached, 'executeTransaction' should be executed.
);
await setAndReinitializeContractsTx.wait();
}
};

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 c5685c6

Please sign in to comment.