From bf56d3b55c88804b9d9daa5b10177407cdc67d39 Mon Sep 17 00:00:00 2001 From: Asgeir Date: Mon, 2 Jan 2023 15:49:59 +0100 Subject: [PATCH] Improve deployment scripts --- deploy/01_mastercopy_module.ts | 20 ++++++++++++++------ deploy/03_proxy_module.ts | 12 ++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/deploy/01_mastercopy_module.ts b/deploy/01_mastercopy_module.ts index 8596331..c54dc84 100644 --- a/deploy/01_mastercopy_module.ts +++ b/deploy/01_mastercopy_module.ts @@ -2,7 +2,7 @@ import { ethers } from "hardhat" import "hardhat-deploy" import { DeployFunction } from "hardhat-deploy/types" import { HardhatRuntimeEnvironment } from "hardhat/types" -import { deployMastercopy } from "@gnosis.pm/zodiac" +import { computeTargetAddress, deployMastercopy } from "@gnosis.pm/zodiac" import MODULE_CONTRACT_ARTIFACT from "../artifacts/contracts/MyModule.sol/MyModule.json" const FirstAddress = "0x0000000000000000000000000000000000000001" @@ -11,7 +11,7 @@ const Salt = "0x0000000000000000000000000000000000000000000000000000000000000000 const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const contract = await ethers.getContractFactory("MyModule") - const address = await deployMastercopy( + let address = await deployMastercopy( hre, contract, [ @@ -22,12 +22,20 @@ const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { ) if (address === ethers.constants.AddressZero) { - console.log("Mastercopy already deployed") - } else { - console.log("Mastercopy deployed to:", address) + // the mastercopy was already deployed + const target = await computeTargetAddress( + hre, + contract, + [ + FirstAddress, // owner + FirstAddress, // button + ], + Salt, + ) + address = target.address } - hre.deployments.save("MyModule", { + hre.deployments.save("MyModuleMastercopy", { abi: MODULE_CONTRACT_ARTIFACT.abi, address, }) diff --git a/deploy/03_proxy_module.ts b/deploy/03_proxy_module.ts index 41e1c24..3872e22 100644 --- a/deploy/03_proxy_module.ts +++ b/deploy/03_proxy_module.ts @@ -2,6 +2,7 @@ import "hardhat-deploy" import { DeployFunction } from "hardhat-deploy/types" import { HardhatRuntimeEnvironment } from "hardhat/types" import { deployAndSetUpCustomModule, ContractAddresses, KnownContracts, SupportedNetworks } from "@gnosis.pm/zodiac" +import MODULE_CONTRACT_ARTIFACT from "../artifacts/contracts/MyModule.sol/MyModule.json" const deploy: DeployFunction = async function ({ deployments, @@ -16,17 +17,19 @@ const deploy: DeployFunction = async function ({ const buttonDeployment = await deployments.get("Button") const testAvatarDeployment = await deployments.get("TestAvatar") - const myModuleMastercopyDeployment = await deployments.get("MyModule") + const myModuleMastercopyDeployment = await deployments.get("MyModuleMastercopy") const chainId = await getChainId() const network: SupportedNetworks = Number(chainId) if ((await ethers.provider.getCode(ContractAddresses[network][KnownContracts.FACTORY])) === "0x") { - // it is the Module Factory should already be deployed to all supported chains + // the Module Factory should already be deployed to all supported chains // if you are deploying to a chain where its not deployed yet (most likely locale test chains), run deployModuleFactory from the zodiac package throw Error("The Module Factory is not deployed on this network. Please deploy it first.") } + console.log("buttonDeployment.address:", buttonDeployment.address) + const { transaction } = deployAndSetUpCustomModule( myModuleMastercopyDeployment.address, myModuleMastercopyDeployment.abi, @@ -43,6 +46,11 @@ const deploy: DeployFunction = async function ({ const myModuleProxyAddress = receipt.logs[1].address console.log("MyModule minimal proxy deployed to:", myModuleProxyAddress) + deployments.save("MyModuleProxy", { + abi: MODULE_CONTRACT_ARTIFACT.abi, + address: myModuleProxyAddress, + }) + // Enable MyModule as a module on the safe to give it access to the safe's execTransactionFromModule() function const testAvatarContract = await ethers.getContractAt("TestAvatar", testAvatarDeployment.address, deployerSigner) const currentActiveModule = await testAvatarContract.module()