Skip to content

Commit

Permalink
Improve deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
asgeir-s committed Jan 2, 2023
1 parent 1f3a59e commit bf56d3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 14 additions & 6 deletions deploy/01_mastercopy_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
[
Expand All @@ -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,
})
Expand Down
12 changes: 10 additions & 2 deletions deploy/03_proxy_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit bf56d3b

Please sign in to comment.