diff --git a/deploy/004_deploy_parameters_storage.ts b/deploy/004_deploy_parameters_storage.ts index 38016a8a..e1582a67 100644 --- a/deploy/004_deploy_parameters_storage.ts +++ b/deploy/004_deploy_parameters_storage.ts @@ -2,29 +2,11 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const isDeployed = hre.helpers.isDeployed('ParametersStorage'); - - await hre.helpers.deploy({ + const ParametersStorage = await hre.helpers.deploy({ newContractName: 'ParametersStorage', }); - if (!isDeployed && ['otp_alphanet', 'otp_devnet', 'otp_testnet'].includes(hre.network.name)) { - const variables = hre.helpers.contractDeployments.contracts['ParametersStorage'].variables ?? {}; - - const ParametersStorageAbi = hre.helpers.getAbi('ParametersStorage'); - const ParametersStorageInterface = new hre.ethers.utils.Interface(ParametersStorageAbi); - - hre.helpers.setParametersEncodedData = [['ParametersStorage', []]]; - - for (const variableName in variables) { - hre.helpers.setParametersEncodedData[0][1].push( - ParametersStorageInterface.encodeFunctionData( - `set${variableName.charAt(0).toUpperCase() + variableName.slice(1)}`, - [variables[variableName]], - ), - ); - } - } + await hre.helpers.updateContractParameters('ParametersStorage', ParametersStorage); }; export default func; diff --git a/deploy/005_deploy_whitelist_storage.ts b/deploy/005_deploy_whitelist_storage.ts index 847cb92e..30131179 100644 --- a/deploy/005_deploy_whitelist_storage.ts +++ b/deploy/005_deploy_whitelist_storage.ts @@ -2,9 +2,11 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - await hre.helpers.deploy({ + const WhitelistStorage = await hre.helpers.deploy({ newContractName: 'WhitelistStorage', }); + + await hre.helpers.updateContractParameters('WhitelistStorage', WhitelistStorage); }; export default func; diff --git a/deploy/009_deploy_log2pldsf.ts b/deploy/009_deploy_log2pldsf.ts index 558aaff8..122e4ac8 100644 --- a/deploy/009_deploy_log2pldsf.ts +++ b/deploy/009_deploy_log2pldsf.ts @@ -28,6 +28,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { hre.helpers.newScoreFunctions.push(Log2PLDSF.address); } } + + await hre.helpers.updateContractParameters('Log2PLDSF', Log2PLDSF); }; export default func; diff --git a/deploy/027_deploy_commit_manager_v1.ts b/deploy/027_deploy_commit_manager_v1.ts index 1c78ba69..e9d34d46 100644 --- a/deploy/027_deploy_commit_manager_v1.ts +++ b/deploy/027_deploy_commit_manager_v1.ts @@ -2,9 +2,11 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - await hre.helpers.deploy({ + const CommitManagerV1 = await hre.helpers.deploy({ newContractName: 'CommitManagerV1', }); + + await hre.helpers.updateContractParameters('CommitManagerV1', CommitManagerV1); }; export default func; diff --git a/deploy/028_deploy_proof_manager_v1.ts b/deploy/028_deploy_proof_manager_v1.ts index 3c2707af..bbf51669 100644 --- a/deploy/028_deploy_proof_manager_v1.ts +++ b/deploy/028_deploy_proof_manager_v1.ts @@ -2,9 +2,11 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - await hre.helpers.deploy({ + const ProofManagerV1 = await hre.helpers.deploy({ newContractName: 'ProofManagerV1', }); + + await hre.helpers.updateContractParameters('ProofManagerV1', ProofManagerV1); }; export default func; diff --git a/deploy/029_deploy_commit_manager_v1_u1.ts b/deploy/029_deploy_commit_manager_v1_u1.ts index ad0a0106..a99b3a8c 100644 --- a/deploy/029_deploy_commit_manager_v1_u1.ts +++ b/deploy/029_deploy_commit_manager_v1_u1.ts @@ -2,9 +2,11 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - await hre.helpers.deploy({ + const CommitManagerV1U1 = await hre.helpers.deploy({ newContractName: 'CommitManagerV1U1', }); + + await hre.helpers.updateContractParameters('CommitManagerV1U1', CommitManagerV1U1); }; export default func; diff --git a/deploy/030_deploy_proof_manager_v1_u1.ts b/deploy/030_deploy_proof_manager_v1_u1.ts index d12c8eb3..7f787631 100644 --- a/deploy/030_deploy_proof_manager_v1_u1.ts +++ b/deploy/030_deploy_proof_manager_v1_u1.ts @@ -2,9 +2,11 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - await hre.helpers.deploy({ + const ProofManagerV1U1 = await hre.helpers.deploy({ newContractName: 'ProofManagerV1U1', }); + + await hre.helpers.updateContractParameters('ProofManagerV1U1', ProofManagerV1U1); }; export default func; diff --git a/deploy/998_initialize_contracts.ts b/deploy/998_initialize_contracts.ts index 543bdb57..fff28e18 100644 --- a/deploy/998_initialize_contracts.ts +++ b/deploy/998_initialize_contracts.ts @@ -13,12 +13,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { newScoreFunctions, } = hre.helpers; - if (hre.network.name !== 'hardhat') { + if (hre.network.config.environment === 'testnet' || hre.network.config.environment == 'mainnet') { const hubControllerAddress = hre.helpers.contractDeployments.contracts['HubController'].evmAddress; + const multiSigWalletAddress = hre.helpers.contractDeployments.contracts['Multisig'].evmAddress; 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)}`); @@ -27,15 +30,26 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { 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)}`); - const setAndReinitializeContractsTx = await HubController.setAndReinitializeContracts( + // Prepare the data for the setAndReinitializeContracts function call + const encodedData = HubController.interface.encodeFunctionData('setAndReinitializeContracts', [ newContracts, newAssetStorageContracts, newHashFunctions, newScoreFunctions, contractsForReinitialization, setParametersEncodedData, - ); - await setAndReinitializeContractsTx.wait(); + ]); + + 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. } }; diff --git a/deployments/parameters.json b/deployments/parameters.json new file mode 100644 index 00000000..bd9bf9f3 --- /dev/null +++ b/deployments/parameters.json @@ -0,0 +1,626 @@ +{ + "development": { + "CommitManagerV1": { + "reqs": [ + { + "desiredValue": false, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, false] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + } + ] + }, + "CommitManagerV1U1": { + "reqs": [ + { + "desiredValue": false, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, false] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + }, + { + "desiredValue": false, + "getterArgs": [4], + "setter": "setReq", + "setterArgs": [4, false] + }, + { + "desiredValue": false, + "getterArgs": [5], + "setter": "setReq", + "setterArgs": [5, false] + } + ] + }, + "Log2PLDSF": { + "a": "1", + "b": "0", + "c": "1", + "d": "1", + "distanceExponent": "2", + "distanceMappingCoefficient": "115792089237316195423570985008687907853269984665640564039457584007913129639", + "logArgumentConstant": "1", + "multiplier": "10000", + "stakeExponent": "1", + "stakeRangeMax": "200000" + }, + "ParametersStorage": { + "commitWindowDurationPerc": "25", + "epochLength": "7776000", + "finalizationCommitsNumber": "3", + "maxProofWindowOffsetPerc": "75", + "maximumStake": "5000000000000000000000000", + "minProofWindowOffsetPerc": "50", + "minimumStake": "50000000000000000000000", + "proofWindowDurationPerc": "25", + "r0": "3", + "r1": "8", + "r2": "20", + "replacementWindowDurationPerc": "0", + "rewardWithdrawalDelay": "300", + "slashingFreezeDuration": "63072000", + "stakeWithdrawalDelay": "300", + "updateCommitWindowDuration": "1800" + }, + "ProofManagerV1": { + "reqs": [ + { + "desiredValue": false, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, false] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + } + ] + }, + "ProofManagerV1U1": { + "reqs": [ + { + "desiredValue": false, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, false] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + } + ] + } + }, + "devnet": { + "CommitManagerV1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + } + ] + }, + "CommitManagerV1U1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": true, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, true] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + }, + { + "desiredValue": false, + "getterArgs": [4], + "setter": "setReq", + "setterArgs": [4, false] + }, + { + "desiredValue": false, + "getterArgs": [5], + "setter": "setReq", + "setterArgs": [5, false] + } + ] + }, + "Log2PLDSF": { + "a": "1", + "b": "0", + "c": "1", + "d": "1", + "distanceExponent": "2", + "distanceMappingCoefficient": "115792089237316195423570985008687907853269984665640564039457584007913129639", + "logArgumentConstant": "1", + "multiplier": "10000", + "stakeExponent": "1", + "stakeRangeMax": "200000" + }, + "ParametersStorage": { + "commitWindowDurationPerc": "25", + "epochLength": "3600", + "finalizationCommitsNumber": "3", + "maxProofWindowOffsetPerc": "75", + "maximumStake": "5000000000000000000000000", + "minProofWindowOffsetPerc": "50", + "minimumStake": "50000000000000000000000", + "proofWindowDurationPerc": "25", + "r0": "3", + "r1": "8", + "r2": "20", + "replacementWindowDurationPerc": "0", + "rewardWithdrawalDelay": "300", + "slashingFreezeDuration": "63072000", + "stakeWithdrawalDelay": "300", + "updateCommitWindowDuration": "600" + }, + "ProofManagerV1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": true, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, true] + } + ] + }, + "ProofManagerV1U1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": true, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, true] + } + ] + } + }, + "testnet": { + "CommitManagerV1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + } + ] + }, + "CommitManagerV1U1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + }, + { + "desiredValue": false, + "getterArgs": [4], + "setter": "setReq", + "setterArgs": [4, false] + }, + { + "desiredValue": false, + "getterArgs": [5], + "setter": "setReq", + "setterArgs": [5, false] + } + ] + }, + "Log2PLDSF": { + "a": "1", + "b": "0", + "c": "1", + "d": "1", + "distanceExponent": "2", + "distanceMappingCoefficient": "115792089237316195423570985008687907853269984665640564039457584007913129639", + "logArgumentConstant": "1", + "multiplier": "10000", + "stakeExponent": "1", + "stakeRangeMax": "200000" + }, + "ParametersStorage": { + "commitWindowDurationPerc": "25", + "epochLength": "7776000", + "finalizationCommitsNumber": "3", + "maxProofWindowOffsetPerc": "75", + "maximumStake": "5000000000000000000000000", + "minProofWindowOffsetPerc": "50", + "minimumStake": "50000000000000000000000", + "proofWindowDurationPerc": "25", + "r0": "3", + "r1": "8", + "r2": "20", + "replacementWindowDurationPerc": "0", + "rewardWithdrawalDelay": "300", + "slashingFreezeDuration": "63072000", + "stakeWithdrawalDelay": "3600", + "updateCommitWindowDuration": "1800" + }, + "ProofManagerV1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": true, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, true] + } + ] + }, + "ProofManagerV1U1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": true, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, true] + } + ] + } + }, + "mainnet": { + "CommitManagerV1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + } + ] + }, + "CommitManagerV1U1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": false, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, false] + }, + { + "desiredValue": false, + "getterArgs": [4], + "setter": "setReq", + "setterArgs": [4, false] + }, + { + "desiredValue": false, + "getterArgs": [5], + "setter": "setReq", + "setterArgs": [5, false] + } + ] + }, + "Log2PLDSF": { + "a": "1", + "b": "0", + "c": "1", + "d": "1", + "distanceExponent": "2", + "distanceMappingCoefficient": "115792089237316195423570985008687907853269984665640564039457584007913129639", + "logArgumentConstant": "1", + "multiplier": "10000", + "stakeExponent": "1", + "stakeRangeMax": "200000" + }, + "ParametersStorage": { + "commitWindowDurationPerc": "25", + "epochLength": "7776000", + "finalizationCommitsNumber": "3", + "maxProofWindowOffsetPerc": "75", + "maximumStake": "5000000000000000000000000", + "minProofWindowOffsetPerc": "50", + "minimumStake": "50000000000000000000000", + "proofWindowDurationPerc": "25", + "r0": "3", + "r1": "8", + "r2": "20", + "replacementWindowDurationPerc": "0", + "rewardWithdrawalDelay": "300", + "slashingFreezeDuration": "63072000", + "stakeWithdrawalDelay": "3600", + "updateCommitWindowDuration": "1800" + }, + "ProofManagerV1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": true, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, true] + } + ] + }, + "ProofManagerV1U1": { + "reqs": [ + { + "desiredValue": true, + "getterArgs": [0], + "setter": "setReq", + "setterArgs": [0, true] + }, + { + "desiredValue": false, + "getterArgs": [1], + "setter": "setReq", + "setterArgs": [1, false] + }, + { + "desiredValue": false, + "getterArgs": [2], + "setter": "setReq", + "setterArgs": [2, false] + }, + { + "desiredValue": true, + "getterArgs": [3], + "setter": "setReq", + "setterArgs": [3, true] + } + ] + } + } +} diff --git a/hardhat.config.ts b/hardhat.config.ts index 2ba99599..826fe7c2 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -31,6 +31,7 @@ extendEnvironment((hre: HardhatRuntimeEnvironment) => { config.networks = { ...config.networks, otp_alphanet: { + environment: 'devnet', chainId: 2043, url: rpc('otp_alphanet'), gas: 10_000_000, // Gas limit used for deployments @@ -39,6 +40,7 @@ config.networks = { saveDeployments: false, }, otp_devnet: { + environment: 'devnet', chainId: 2160, url: rpc('otp_devnet'), gas: 10_000_000, // Gas limit used for deployments @@ -47,6 +49,7 @@ config.networks = { saveDeployments: false, }, otp_testnet: { + environment: 'testnet', chainId: 20430, url: rpc('otp_testnet'), gas: 10_000_000, // Gas limit used for deploys @@ -55,6 +58,7 @@ config.networks = { saveDeployments: false, }, otp_mainnet: { + environment: 'mainnet', chainId: 2043, url: rpc('otp_mainnet'), gas: 10_000_000, // Gas limit used for deploys @@ -63,6 +67,7 @@ config.networks = { saveDeployments: false, }, gnosis_chiado_dev: { + environment: 'devnet', chainId: 10200, url: rpc('gnosis_chiado_dev'), gasPrice: 1_000_000_000, @@ -70,6 +75,7 @@ config.networks = { saveDeployments: false, }, gnosis_chiado_test: { + environment: 'testnet', chainId: 10200, url: rpc('gnosis_chiado_test'), gasPrice: 1_000_000_000, @@ -77,6 +83,7 @@ config.networks = { saveDeployments: false, }, gnosis_mainnet: { + environment: 'mainnet', chainId: 100, url: rpc('gnosis_mainnet'), accounts: accounts('gnosis_mainnet'), diff --git a/hardhat.node.config.ts b/hardhat.node.config.ts index 02f8daf0..d9b15ccd 100644 --- a/hardhat.node.config.ts +++ b/hardhat.node.config.ts @@ -1,8 +1,8 @@ import 'hardhat-deploy'; import 'hardhat-deploy-ethers'; -import { HardhatUserConfig, extendEnvironment } from 'hardhat/config'; +import { extendEnvironment } from 'hardhat/config'; import { lazyObject } from 'hardhat/plugins'; -import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { HardhatRuntimeEnvironment, HardhatUserConfig } from 'hardhat/types'; import { Helpers } from './utils/helpers'; import { accounts, rpc } from './utils/network'; @@ -19,11 +19,13 @@ const config: HardhatUserConfig = { }, networks: { localhost: { + environment: 'development', url: rpc('localhost'), accounts: accounts('localhost'), saveDeployments: false, }, hardhat: { + environment: 'development', chainId: 31337, gas: 15_000_000, gasMultiplier: 1, diff --git a/utils/helpers.ts b/utils/helpers.ts index b26f876c..5c5f5e02 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import 'dotenv/config'; import { execSync } from 'child_process'; import * as fs from 'fs'; @@ -28,9 +29,6 @@ type ContractDeployments = { gitCommitHash: string; deploymentTimestamp: number; deployed: boolean; - variables?: { - [variableName: string]: unknown; - }; }; }; }; @@ -45,6 +43,25 @@ type DeploymentParameters = { deterministicDeployment?: boolean; }; +type ContractParameter = { + getterArgs?: any[]; + desiredValue?: any[]; + setter?: string; + setterArgs: any[]; +}; + +type ContractParametersConfig = { + [parameter: string]: ContractParameter | string | ContractParameter[]; +}; + +type EnvironmentParametersConfig = { + [contractName: string]: ContractParametersConfig; +}; + +type ParametersConfig = { + [environment: string]: EnvironmentParametersConfig; +}; + type EvmWallet = { address: string; mnemonic: string; @@ -62,6 +79,7 @@ export class Helpers { provider: HttpProvider; repositoryPath: string; contractDeployments: ContractDeployments; + parametersConfig: ParametersConfig; newContracts: Array>; newAssetStorageContracts: Array>; contractsForReinitialization: Array; @@ -84,6 +102,19 @@ export class Helpers { this.contractDeployments = { contracts: {} }; } + const parametersConfig = './deployments/parameters.json'; + + if (fs.existsSync(parametersConfig)) { + this.parametersConfig = JSON.parse(fs.readFileSync(parametersConfig).toString()); + } else { + this.parametersConfig = { + development: {}, + devnet: {}, + testnet: {}, + mainnet: {}, + }; + } + this.newContracts = []; this.newAssetStorageContracts = []; this.contractsForReinitialization = []; @@ -185,6 +216,81 @@ export class Helpers { return await this.hre.ethers.getContractAt(nameInHub, newContract.address, deployer); } + public async updateContractParameters(contractName: string, contract: Contract) { + const parameters = + this.parametersConfig[this.hre.network.config.environment as keyof ParametersConfig]?.[contractName]; + if (!parameters) { + return; + } + + const encodedData: [string, string[]] = [contractName, []]; + for (const [getterName, paramValue] of Object.entries(parameters)) { + const values = Array.isArray(paramValue) ? paramValue : [paramValue]; + + for (const value of values) { + let getterArgs = []; + let desiredValue; + let setterName; + let setterArgs; + + if (value instanceof Object) { + getterArgs = value.getterArgs ? value.getterArgs : []; + desiredValue = value.setterArgs.length === 1 ? value.setterArgs[0] : value.desiredValue; + setterName = value.setter ? value.setter : `set${getterName.charAt(0).toUpperCase() + getterName.slice(1)}`; + setterArgs = value.setterArgs; + } else { + desiredValue = value; + setterName = `set${getterName.charAt(0).toUpperCase() + getterName.slice(1)}`; + setterArgs = [value]; + } + + if (getterName in contract.functions) { + const currentValue = await contract[getterName](...getterArgs); + + if (currentValue.toString() !== desiredValue.toString()) { + console.log( + `Parameter '${getterName}' for ${contractName} in the contract isn't the same as define in config. Blockchain: ${currentValue}. Config: ${desiredValue}.`, + ); + if (setterName in contract.functions) { + const encodedFunctionData = contract.interface.encodeFunctionData(setterName, setterArgs); + + if (this.hre.network.config.environment === 'development') { + console.log(`[${contractName}] Setting parameter '${getterName}' value to be ${desiredValue}.`); + + const { deployer } = await this.hre.getNamedAccounts(); + + const targetContractAddress = this.contractDeployments.contracts[contractName].evmAddress; + const hubControllerAddress = this.contractDeployments.contracts['HubController'].evmAddress; + const HubController = await this.hre.ethers.getContractAt( + 'HubController', + hubControllerAddress, + deployer, + ); + + const tx = await HubController.forwardCall(targetContractAddress, encodedFunctionData); + await tx.wait(); + } else { + console.log( + `[${contractName}] Adding parameter '${getterName}' value to be set to ${desiredValue} using HubController.`, + ); + + encodedData[1].push(encodedFunctionData); + } + } else { + throw Error(`Setter '${setterName}' doesn't exist in the contract '${contractName}'.`); + } + } + } else { + throw Error(`Parameter '${getterName}' doesn't exist in the contract '${contractName}'.`); + } + + if (encodedData[1].length !== 0) { + this.setParametersEncodedData.push(encodedData); + } + } + } + } + public inConfig(contractName: string): boolean { return contractName in this.contractDeployments.contracts; } @@ -211,8 +317,6 @@ export class Helpers { } public async updateDeploymentsJson(newContractName: string, newContractAddress: string) { - const variables = this.contractDeployments.contracts[newContractName]?.variables ?? undefined; - const contractABI = this.getAbi(newContractName); const isVersionedContract = contractABI.some( (abiEntry) => abiEntry.type === 'function' && abiEntry.name === 'version', @@ -235,7 +339,6 @@ export class Helpers { gitCommitHash: this.getCurrentGitCommitHash(), deploymentTimestamp: Date.now(), deployed: true, - variables, }; } diff --git a/utils/type-extensions.ts b/utils/type-extensions.ts index 88e65f66..4cc62328 100644 --- a/utils/type-extensions.ts +++ b/utils/type-extensions.ts @@ -1,7 +1,27 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions */ +import 'hardhat/types/config'; import 'hardhat/types/runtime'; + import { Helpers } from './helpers'; +declare module 'hardhat/types/config' { + export interface HardhatNetworkConfig { + environment: string; + } + + export interface HardhatNetworkUserConfig { + environment: string; + } + + export interface HttpNetworkConfig { + environment: string; + } + + export interface HttpNetworkUserConfig { + environment: string; + } +} + declare module 'hardhat/types/runtime' { export interface HardhatRuntimeEnvironment { helpers: Helpers;