Skip to content

Commit

Permalink
Include tasks for store, deploy and verify mastercopies
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jul 31, 2024
1 parent 24d9413 commit d9c4d39
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
31 changes: 31 additions & 0 deletions packages/contracts/tasks/mastercopy-deploy.ts
Original file line number Diff line number Diff line change
@@ -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 });
},
};
}
38 changes: 38 additions & 0 deletions packages/contracts/tasks/mastercopy-store.ts
Original file line number Diff line number Diff line change
@@ -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",
});
});
18 changes: 18 additions & 0 deletions packages/contracts/tasks/mastercopy-verify.ts
Original file line number Diff line number Diff line change
@@ -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,
});
});

0 comments on commit d9c4d39

Please sign in to comment.