Skip to content

Commit

Permalink
Use zodiac-core
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jul 30, 2024
1 parent a68ca70 commit 00d1335
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 155 deletions.
2 changes: 1 addition & 1 deletion contracts/MyModule.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "@gnosis.pm/zodiac/contracts/core/Module.sol";
import "zodiac-core/contracts/core/Module.sol";

contract MyModule is Module {
address public button;
Expand Down
19 changes: 14 additions & 5 deletions deploy/01_mastercopy_module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { ZeroHash } from "ethers"
import { DeployFunction } from "hardhat-deploy/types"
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { createFactory, deployViaFactory } from "../factories/eip2470"
import { deployFactories, deploySingleton } from "zodiac-core"

import createAdapter from "./eip1193"
import MODULE_CONTRACT_ARTIFACT from "../artifacts/contracts/MyModule.sol/MyModule.json"

const FirstAddress = "0x0000000000000000000000000000000000000001"

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, ethers } = hre
const { deployer: deployerAddress } = await getNamedAccounts()
const deployer = await ethers.getSigner(deployerAddress)

await createFactory(deployer)
const provider = createAdapter({
provider: hre.network.provider,
signer: await ethers.getSigner(deployerAddress),
})

await deployFactories({ provider })

const MyModule = await ethers.getContractFactory("MyModule")
const tx = await MyModule.getDeployTransaction(FirstAddress, FirstAddress)

const mastercopy = await deployViaFactory({ bytecode: tx.data, salt: ZeroHash }, deployer)
const { address: mastercopy } = await deploySingleton({
bytecode: MyModule.bytecode,
constructorArgs: { types: ["address", "address"], values: [FirstAddress, FirstAddress] },
salt: ZeroHash,
provider,
})

hre.deployments.save("MyModuleMastercopy", {
abi: MODULE_CONTRACT_ARTIFACT.abi,
Expand Down
31 changes: 16 additions & 15 deletions deploy/03_proxy_module.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { ZeroHash } from "ethers"
import { DeployFunction } from "hardhat-deploy/types"
import { HardhatRuntimeEnvironment } from "hardhat/types"

import { createFactory, deployModAsProxy } from "../factories/moduleProxyFactory"

import MODULE_CONTRACT_ARTIFACT from "../artifacts/contracts/MyModule.sol/MyModule.json"
import createAdapter from "./eip1193"
import { deployFactories, deployProxy } from "zodiac-core"

const deploy: DeployFunction = async function ({
deployments,
getNamedAccounts,
ethers,
getChainId,
network,
}: HardhatRuntimeEnvironment) {
console.log("Deploying MyModule Proxy")
const { deployer: deployerAddress } = await getNamedAccounts()
const deployer = await ethers.getSigner(deployerAddress)

const buttonDeployment = await deployments.get("Button")
const testAvatarDeployment = await deployments.get("TestAvatar")

const myModuleMastercopyDeployment = await deployments.get("MyModuleMastercopy")

const provider = createAdapter({
provider: network.provider,
signer: await ethers.getSigner(deployerAddress),
})

/// const chainId = await getChainId()
// const network: SupportedNetworks = Number(chainId)
// if ((await ethers.provider.getCode(ContractAddresses[network][KnownContracts.FACTORY])) === "0x") {
Expand All @@ -32,19 +35,17 @@ const deploy: DeployFunction = async function ({
console.log("buttonDeployment.address:", buttonDeployment.address)

// Deploys the ModuleFactory (and the Singleton factory) if it is not already deployed
const factory = await createFactory(deployer)
const { transaction } = await deployModAsProxy(
factory,
myModuleMastercopyDeployment.address,
{
await deployFactories({ provider })
const { address: myModuleProxyAddress } = await deployProxy({
mastercopy: myModuleMastercopyDeployment.address,
setupArgs: {
values: [testAvatarDeployment.address, buttonDeployment.address],
types: ["address", "address"],
},
ZeroHash,
)
const deploymentTransaction = await deployer.sendTransaction(transaction)
const receipt = (await deploymentTransaction.wait())!
const myModuleProxyAddress = receipt.logs[1].address
saltNonce: 0,
provider,
})

console.log("MyModule minimal proxy deployed to:", myModuleProxyAddress)

deployments.save("MyModuleProxy", {
Expand Down
21 changes: 21 additions & 0 deletions deploy/eip1193.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Signer } from "ethers"
import { EIP1193Provider } from "zodiac-core"

export default function createAdapter({
provider,
signer,
}: {
provider: EIP1193Provider
signer: Signer
}): EIP1193Provider {
return {
request: async ({ method, params }) => {
if (method == "eth_sendTransaction") {
const { hash } = await signer.sendTransaction((params as any[])[0])
return hash
}

return provider.request({ method, params })
},
}
}
56 changes: 0 additions & 56 deletions factories/eip2470.ts

This file was deleted.

58 changes: 0 additions & 58 deletions factories/moduleProxyFactory.ts

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"homepage": "https://github.com/gnosis/zodiac-mod-starter-kit",
"devDependencies": {
"@gnosis.pm/safe-contracts": "^1.3.0",
"@gnosis.pm/zodiac": "4.0.3",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ethers": "3.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.7",
Expand Down Expand Up @@ -59,6 +58,7 @@
"solidity-coverage": "^0.8.4",
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"zodiac-core": "file:../zodiac-core"
}
}
41 changes: 23 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -590,27 +590,11 @@
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"
integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==

"@gnosis.pm/mock-contract@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@gnosis.pm/mock-contract/-/mock-contract-4.0.0.tgz#eaf500fddcab81b5f6c22280a7b22ff891dd6f87"
integrity sha512-SkRq2KwPx6vo0LAjSc8JhgQstrQFXRyn2yqquIfub7r2WHi5nUbF8beeSSXsd36hvBcQxQfmOIYNYRpj9JOhrQ==

"@gnosis.pm/[email protected]", "@gnosis.pm/safe-contracts@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-contracts/-/safe-contracts-1.3.0.tgz#316741a7690d8751a1f701538cfc9ec80866eedc"
integrity sha512-1p+1HwGvxGUVzVkFjNzglwHrLNA67U/axP0Ct85FzzH8yhGJb4t9jDjPYocVMzLorDoWAfKicGy1akPY9jXRVw==

"@gnosis.pm/[email protected]":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@gnosis.pm/zodiac/-/zodiac-4.0.3.tgz#3323f496cda279e2a68ca2bf726ad840388e8229"
integrity sha512-yliHytBRlb4wNkeiYsaaAvYZC5VwiUBVfJ+HLEmjnWPG2EHB5tvAOUboDU7XvSQ4GUJAz8h2YUrph0XkH+/xfA==
dependencies:
"@gnosis.pm/mock-contract" "^4.0.0"
"@gnosis.pm/safe-contracts" "1.3.0"
"@openzeppelin/contracts" "^5.0.0"
"@openzeppelin/contracts-upgradeable" "^5.0.0"
ethers "^6.9.2"

"@humanwhocodes/config-array@^0.11.14":
version "0.11.14"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b"
Expand Down Expand Up @@ -896,12 +880,12 @@
"@nomicfoundation/solidity-analyzer-win32-ia32-msvc" "0.1.0"
"@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.1.0"

"@openzeppelin/contracts-upgradeable@^5.0.0":
"@openzeppelin/contracts-upgradeable@5.0.2", "@openzeppelin/contracts-upgradeable@^5.0.0":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.0.2.tgz#3e5321a2ecdd0b206064356798c21225b6ec7105"
integrity sha512-0MmkHSHiW2NRFiT9/r5Lu4eJq5UJ4/tzlOgYXNAIj/ONkQTVnz22pLxDvp4C4uZ9he7ZFvGn3Driptn1/iU7tQ==

"@openzeppelin/contracts@^5.0.0":
"@openzeppelin/contracts@5.0.2", "@openzeppelin/contracts@^5.0.0":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.2.tgz#b1d03075e49290d06570b2fd42154d76c2a5d210"
integrity sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==
Expand Down Expand Up @@ -2927,6 +2911,19 @@ ethers@^5.7.0:
"@ethersproject/web" "5.7.1"
"@ethersproject/wordlists" "5.7.0"

ethers@^6.13.2:
version "6.13.2"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.13.2.tgz#4b67d4b49e69b59893931a032560999e5e4419fe"
integrity sha512-9VkriTTed+/27BGuY1s0hf441kqwHJ1wtN2edksEtiRvXx+soxRX3iSXTfFqq2+YwrOqbDoTHjIhQnjJRlzKmg==
dependencies:
"@adraffy/ens-normalize" "1.10.1"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@types/node" "18.15.13"
aes-js "4.0.0-beta.5"
tslib "2.4.0"
ws "8.17.1"

ethers@^6.9.2:
version "6.13.1"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.13.1.tgz#2b9f9c7455cde9d38b30fe6589972eb083652961"
Expand Down Expand Up @@ -6496,3 +6493,11 @@ zksync-web3@^0.14.3:
version "0.14.4"
resolved "https://registry.yarnpkg.com/zksync-web3/-/zksync-web3-0.14.4.tgz#0b70a7e1a9d45cc57c0971736079185746d46b1f"
integrity sha512-kYehMD/S6Uhe1g434UnaMN+sBr9nQm23Ywn0EUP5BfQCsbjcr3ORuS68PosZw8xUTu3pac7G6YMSnNHk+fwzvg==

"zodiac-core@file:../zodiac-core":
version "4.0.3"
dependencies:
"@gnosis.pm/safe-contracts" "1.3.0"
"@openzeppelin/contracts" "5.0.2"
"@openzeppelin/contracts-upgradeable" "5.0.2"
ethers "^6.13.2"

0 comments on commit 00d1335

Please sign in to comment.