From d9c4d398d20d390c53f402eb87c32f15b2606f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3v=C3=A3o=20Honorato?= Date: Wed, 31 Jul 2024 19:14:48 +0200 Subject: [PATCH] Include tasks for store, deploy and verify mastercopies --- packages/contracts/hardhat.config.ts | 11 +++++- packages/contracts/package.json | 4 +- packages/contracts/tasks/mastercopy-deploy.ts | 31 +++++++++++++++ packages/contracts/tasks/mastercopy-store.ts | 38 +++++++++++++++++++ packages/contracts/tasks/mastercopy-verify.ts | 18 +++++++++ 5 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 packages/contracts/tasks/mastercopy-deploy.ts create mode 100644 packages/contracts/tasks/mastercopy-store.ts create mode 100644 packages/contracts/tasks/mastercopy-verify.ts diff --git a/packages/contracts/hardhat.config.ts b/packages/contracts/hardhat.config.ts index 15b2383..59881e0 100644 --- a/packages/contracts/hardhat.config.ts +++ b/packages/contracts/hardhat.config.ts @@ -11,6 +11,9 @@ dotenv.config(); const { INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY, PK } = process.env; import "./src/tasks/setup"; +import "./tasks/mastercopy-deploy"; +import "./tasks/mastercopy-store"; +import "./tasks/mastercopy-verify"; const DEFAULT_MNEMONIC = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"; @@ -43,14 +46,18 @@ export default { ...sharedNetworkConfig, url: `https://goerli.infura.io/v3/${INFURA_KEY}`, }, - xdai: { + gnosis: { ...sharedNetworkConfig, - url: "https://xdai.poanetwork.dev", + url: "https://rpc.gnosischain.com", }, matic: { ...sharedNetworkConfig, url: "https://rpc-mainnet.maticvigil.com", }, + sepolia: { + ...sharedNetworkConfig, + url: `https://sepolia.infura.io/v3/${INFURA_KEY}`, + }, }, namedAccounts: { deployer: 0, diff --git a/packages/contracts/package.json b/packages/contracts/package.json index a4eece6..bbb96a2 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -5,7 +5,9 @@ "scripts": { "build": "hardhat compile", "test": "hardhat test", - "deploy": "hardhat deploy --network", + "store-mastercopy": "yarn run build && yarn hardhat mastercopy:store", + "deploy-mastercopies": "yarn hardhat mastercopies:deploy --network", + "verify-mastercopies": "yarn hardhat mastercopies:verify --network", "coverage": "hardhat coverage", "lint": "yarn lint:sol && yarn lint:ts", "lint:sol": "solhint 'contracts/**/*.sol'", diff --git a/packages/contracts/tasks/mastercopy-deploy.ts b/packages/contracts/tasks/mastercopy-deploy.ts new file mode 100644 index 0000000..88ffc6e --- /dev/null +++ b/packages/contracts/tasks/mastercopy-deploy.ts @@ -0,0 +1,31 @@ +import { Signer } from "ethers"; +import { task } from "hardhat/config"; +import { EthereumProvider } from "hardhat/types"; + +import { EIP1193Provider, deployMastercopiesFromArtifact } from "zodiac-core"; + +task( + "mastercopies:deploy", + "For every version entry on the artifacts file, deploys a mastercopy into the current network" +).setAction(async (_, hre) => { + const [signer] = await hre.ethers.getSigners(); + await deployMastercopiesFromArtifact({ + provider: createEIP1193(hre.network.provider, signer), + }); +}); + +function createEIP1193( + provider: EthereumProvider, + 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 }); + }, + }; +} diff --git a/packages/contracts/tasks/mastercopy-store.ts b/packages/contracts/tasks/mastercopy-store.ts new file mode 100644 index 0000000..0f0182f --- /dev/null +++ b/packages/contracts/tasks/mastercopy-store.ts @@ -0,0 +1,38 @@ +import { task } from "hardhat/config"; + +import { storeMastercopyArtifact } from "zodiac-core"; + +import packageJson from "../package.json"; + +const AddressOne = "0x0000000000000000000000000000000000000001"; + +task( + "extract-current", + "Extracts and persists current mastercopy build artifacts" +).setAction(async (_, hre) => { + storeMastercopyArtifact({ + contractVersion: packageJson.version, + contractName: "ExitERC20", + compilerInput: await hre.run("verify:etherscan-get-minimal-input", { + sourceName: "contracts/ExitModule/ExitERC20Module.sol", + }), + constructorArgs: { + types: ["address", "address", "address", "address", "address"], + values: [AddressOne, AddressOne, AddressOne, AddressOne, AddressOne], + }, + salt: "0x0000000000000000000000000000000000000000000000000000000000000000", + }); + + storeMastercopyArtifact({ + contractVersion: packageJson.version, + contractName: "ExitERC721", + compilerInput: await hre.run("verify:etherscan-get-minimal-input", { + sourceName: "contracts/ExitModule/ExitERC721Module.sol", + }), + constructorArgs: { + types: ["address", "address", "address", "address", "address"], + values: [AddressOne, AddressOne, AddressOne, AddressOne, AddressOne], + }, + salt: "0x0000000000000000000000000000000000000000000000000000000000000000", + }); +}); diff --git a/packages/contracts/tasks/mastercopy-verify.ts b/packages/contracts/tasks/mastercopy-verify.ts new file mode 100644 index 0000000..68fc8a3 --- /dev/null +++ b/packages/contracts/tasks/mastercopy-verify.ts @@ -0,0 +1,18 @@ +import { task } from "hardhat/config"; +import { verifyMastercopiesFromArtifact } from "zodiac-core"; + +const { ETHERSCAN_API_KEY } = process.env; + +task( + "mastercopies:verify", + "Verifies all mastercopies from the artifacts file, in the block explorer corresponding to the current network" +).setAction(async (_, hre) => { + if (!ETHERSCAN_API_KEY) { + throw new Error("Missing ENV ETHERSCAN_API_KEY"); + } + + await verifyMastercopiesFromArtifact({ + apiUrl: String((await hre.ethers.provider.getNetwork()).chainId), + apiKey: ETHERSCAN_API_KEY, + }); +});