Skip to content

Commit

Permalink
Merge pull request #76 from gnosisguild/use-zodiac-core-v2
Browse files Browse the repository at this point in the history
feat: improve hardhat task
  • Loading branch information
juliopavila authored Aug 26, 2024
2 parents 90fb019 + 6454406 commit b98bc9f
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 405 deletions.
9 changes: 5 additions & 4 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import type { HttpNetworkUserConfig } from "hardhat/types";
dotenv.config();
const { INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY, PK } = process.env;

import "./tasks/setup";
import "./tasks/mastercopy-deploy";
import "./tasks/mastercopy-extract";
import "./tasks/mastercopy-verify";
import "./tasks/deploy-mastercopies";
import "./tasks/deploy-mastercopy";
import "./tasks/extract-mastercopy";
import "./tasks/verify-mastercopies";
import "./tasks/verify-mastercopy";

const DEFAULT_MNEMONIC =
"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
Expand Down
22 changes: 14 additions & 8 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
"scripts": {
"build": "hardhat compile",
"test": "hardhat test",
"extract-mastercopy": "yarn run build && yarn hardhat mastercopy:extract",
"deploy-mastercopy": "yarn hardhat mastercopy:deploy --network",
"verify-mastercopy": "yarn hardhat mastercopy:verify --network",
"extract:mastercopy": "yarn run build && yarn hardhat extract:mastercopy",
"deploy:mastercopies": "yarn hardhat deploy:mastercopies --network",
"deploy:mastercopy": "yarn hardhat deploy:mastercopy --network",
"verify:mastercopies": "yarn hardhat verify:mastercopies --network",
"verify:mastercopy": "yarn hardhat verify:mastercopy --network",
"coverage": "hardhat coverage",
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:ts": "eslint --max-warnings 0 .",
"fmt": "yarn fmt:sol && yarn fmt:ts",
"fmt:sol": "prettier 'contracts/**/*.sol' -w",
"fmt:ts": "prettier 'tasks/**/*.ts' 'test/**/*.ts' -w",
"prepack": "yarn build"
},
"repository": {
Expand All @@ -21,11 +25,11 @@
"author": "",
"license": "LGPL-3.0+",
"devDependencies": {
"@gnosis-guild/zodiac-core": "1.1.0",
"@gnosis-guild/zodiac-core": "^2.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.5",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.9",
Expand All @@ -38,17 +42,19 @@
"chai": "4.3.4",
"debug": "4.3.2",
"dotenv": "10.0.0",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint": "^9.8.0",
"hardhat-gas-reporter": "^2.2.0",
"fs": "^0.0.1-security",
"hardhat": "^2.22.7",
"hardhat-gas-reporter": "^2.2.0",
"path": "^0.12.7",
"prettier": "^3.3.3",
"rimraf": "^6.0.0",
"solhint": "5.0.3",
"solhint-plugin-prettier": "0.1.0",
"solhint": "5.0.2",
"solidity-coverage": "^0.8.12",
"ts-node": "^10.9.2",
"typechain": "^8.1.1",
Expand Down
19 changes: 19 additions & 0 deletions packages/contracts/tasks/create-EIP1193.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EIP1193Provider } from "@gnosis-guild/zodiac-core";
import { Signer } from "ethers";
import { EthereumProvider } from "hardhat/types";

export 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 });
},
};
}
44 changes: 44 additions & 0 deletions packages/contracts/tasks/deploy-mastercopies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { task } from "hardhat/config";

import { readMastercopies, deployMastercopy } from "@gnosis-guild/zodiac-core";
import { createEIP1193 } from "./create-EIP1193";

task(
"deploy:mastercopies",
"For every version entry on the artifacts file, deploys a mastercopy into the current network"
).setAction(async (_, hre) => {
const [signer] = await hre.ethers.getSigners();
const provider = createEIP1193(hre.network.provider, signer);
for (const mastercopy of readMastercopies()) {
const {
contractName,
contractVersion,
factory,
bytecode,
constructorArgs,
salt,
} = mastercopy;

const { address, noop } = await deployMastercopy({
factory,
bytecode,
constructorArgs,
salt,
provider,
onStart: () => {
console.log(
`⏳ ${contractName}@${contractVersion}: Deployment starting...`
);
},
});
if (noop) {
console.log(
`🔄 ${contractName}@${contractVersion}: Already deployed at ${address}`
);
} else {
console.log(
`🚀 ${contractName}@${contractVersion}: Successfully deployed at ${address}`
);
}
}
});
48 changes: 48 additions & 0 deletions packages/contracts/tasks/deploy-mastercopy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { task, types } from "hardhat/config";

import { deployMastercopy, readMastercopies } from "@gnosis-guild/zodiac-core";
import { createEIP1193 } from "./create-EIP1193";

task(
"deploy:mastercopy",
"For every entry on the artifacts file, that corresponds to the provided entry, deploy the mastercopy into the current network"
)
.addOptionalParam(
"contractVersion",
"The specific version of the contract to deploy",
"latest", // Default value
types.string
)
.setAction(async ({ contractVersion }, hre) => {
const [signer] = await hre.ethers.getSigners();
const provider = createEIP1193(hre.network.provider, signer);

for (const mastercopy of readMastercopies({ contractVersion })) {
const {
contractName,
contractVersion,
factory,
bytecode,
constructorArgs,
salt,
} = mastercopy;
const { address, noop } = await deployMastercopy({
factory,
bytecode,
constructorArgs,
salt,
provider,
onStart: () => {
console.log(
`⏳ ${contractName}@${contractVersion}: Deployment starting...`
);
},
});
if (noop) {
console.log(
`🔄 ${contractName}@${contractVersion}: Already deployed at ${address}`
);
} else {
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import packageJson from "../package.json";
const AddressOne = "0x0000000000000000000000000000000000000001";

task(
"mastercopy:extract",
"extract:mastercopy",
"Extracts and persists current mastercopy build artifacts"
).setAction(async (_, hre) => {
writeMastercopyFromBuild({
Expand Down
34 changes: 0 additions & 34 deletions packages/contracts/tasks/mastercopy-deploy.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/contracts/tasks/mastercopy-verify.ts

This file was deleted.

Loading

0 comments on commit b98bc9f

Please sign in to comment.