diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 9b7edb1..fb99213 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -25,7 +25,7 @@ "author": "", "license": "LGPL-3.0+", "devDependencies": { - "@gnosis-guild/zodiac-core": "1.1.0", + "@gnosis-guild/zodiac-core": "file:../../../zodiac-core", "@nomicfoundation/hardhat-chai-matchers": "^2.0.7", "@nomicfoundation/hardhat-ethers": "^3.0.6", "@nomicfoundation/hardhat-ignition": "^0.15.5", @@ -53,7 +53,7 @@ "path": "^0.12.7", "prettier": "^3.3.3", "rimraf": "^6.0.0", - "solhint": "5.0.2", + "solhint": "5.0.3", "solhint-plugin-prettier": "0.1.0", "solidity-coverage": "^0.8.12", "ts-node": "^10.9.2", diff --git a/packages/contracts/tasks/deploy-mastercopies.ts b/packages/contracts/tasks/deploy-mastercopies.ts index 09af8e9..fc2fc57 100644 --- a/packages/contracts/tasks/deploy-mastercopies.ts +++ b/packages/contracts/tasks/deploy-mastercopies.ts @@ -1,9 +1,6 @@ - import { task } from "hardhat/config"; -import { - deployAllMastercopies, -} from "@gnosis-guild/zodiac-core"; +import { readMastercopies, deployMastercopy } from "@gnosis-guild/zodiac-core"; import { createEIP1193 } from "./create-EIP1193"; task( @@ -13,9 +10,36 @@ task( const [signer] = await hre.ethers.getSigners(); const provider = createEIP1193(hre.network.provider, signer); - await deployAllMastercopies({ - provider, - }); -}); - + for (const mastercopy of await 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}` + ); + } + } +}); diff --git a/packages/contracts/tasks/deploy-mastercopy.ts b/packages/contracts/tasks/deploy-mastercopy.ts index 119f38d..719f46b 100644 --- a/packages/contracts/tasks/deploy-mastercopy.ts +++ b/packages/contracts/tasks/deploy-mastercopy.ts @@ -1,15 +1,11 @@ import { task, types } from "hardhat/config"; -import { - EIP1193Provider, - deployMastercopy, - readMastercopy, -} from "@gnosis-guild/zodiac-core"; +import { deployMastercopy, readMastercopies } from "@gnosis-guild/zodiac-core"; import { createEIP1193 } from "./create-EIP1193"; task( "deploy:mastercopy", - "For every version entry on the artifacts file, deploys a mastercopy into the current network" + "For every entry on the artifacts file, that corresponds to the provided entry, deploy the mastercopy into the current network" ) .addOptionalParam( "contractVersion", @@ -21,51 +17,36 @@ task( const [signer] = await hre.ethers.getSigners(); const provider = createEIP1193(hre.network.provider, signer); - // Deploy the contracts based on the provided version - await deployLatestMastercopyFromDisk(provider, contractVersion); - }); - -async function deployLatestMastercopyFromDisk( - provider: EIP1193Provider, - version?: string -) { - const CONTRACTS = [ - "Exit", - "ExitERC20", - "ExitERC721", - "CirculatingSupply", - "CirculatingSupplyERC20", - "CirculatingSupplyERC721", - ]; - - for (const contract of CONTRACTS) { - try { - // Read the artifact for the specific contract and version - const artifact = readMastercopy({ - contractName: contract, - contractVersion: version === "latest" ? undefined : version, - }); + for (const mastercopy of await readMastercopies({ contractVersion })) { + const { + contractName, + contractVersion, + factory, + bytecode, + constructorArgs, + salt, + } = mastercopy; const { address, noop } = await deployMastercopy({ - ...artifact, + factory, + bytecode, + constructorArgs, + salt, provider, + onStart: () => { + console.log( + `⏳ ${contractName}@${contractVersion}: Deployment starting...` + ); + }, }); - if (noop) { console.log( - `🔄 ${artifact.contractName}@${artifact.contractVersion}: Already deployed at ${address}` + `🔄 ${contractName}@${contractVersion}: Already deployed at ${address}` ); } else { console.log( - `🚀 ${artifact.contractName}@${artifact.contractVersion}: Successfully deployed at ${address}` + `🚀 ${contractName}@${contractVersion}: Successfully deployed at ${address}` ); } - } catch (error) { - console.error( - `⏭️ Skipping deployment of ${contract}@${version}: Version not found.` - ); - // Skip the current contract if there's an error and continue with the next one - continue; } - } -} + }); diff --git a/packages/contracts/tasks/verify-mastercopies.ts b/packages/contracts/tasks/verify-mastercopies.ts index c9fceef..4abfb60 100644 --- a/packages/contracts/tasks/verify-mastercopies.ts +++ b/packages/contracts/tasks/verify-mastercopies.ts @@ -1,7 +1,5 @@ import { task } from "hardhat/config"; -import { - verifyAllMastercopies, -} from "@gnosis-guild/zodiac-core"; +import { readMastercopies, verifyMastercopy } from "@gnosis-guild/zodiac-core"; const { ETHERSCAN_API_KEY } = process.env; @@ -14,8 +12,24 @@ task( } const chainId = String((await hre.ethers.provider.getNetwork()).chainId); - await verifyAllMastercopies({ - apiUrlOrChainId: chainId, - apiKey: ETHERSCAN_API_KEY, - }); + + for (const artifact of readMastercopies()) { + const { noop } = await verifyMastercopy({ + artifact, + apiUrlOrChainId: chainId, + apiKey: ETHERSCAN_API_KEY, + }); + + const { contractName, contractVersion, address } = artifact; + + if (noop) { + console.log( + `🔄 ${contractName}@${contractVersion}: Already verified at ${address}` + ); + } else { + console.log( + `🚀 ${contractName}@${contractVersion}: Successfully verified at ${address}` + ); + } + } }); diff --git a/packages/contracts/tasks/verify-mastercopy.ts b/packages/contracts/tasks/verify-mastercopy.ts index bbbc39d..5967d0f 100644 --- a/packages/contracts/tasks/verify-mastercopy.ts +++ b/packages/contracts/tasks/verify-mastercopy.ts @@ -1,30 +1,15 @@ import { task, types } from "hardhat/config"; -import { - readMastercopy, - verifyAllMastercopies, -} from "@gnosis-guild/zodiac-core"; -import path from "path"; -import fs from "fs"; -import { cwd } from "process"; +import { readMastercopies, verifyMastercopy } from "@gnosis-guild/zodiac-core"; const { ETHERSCAN_API_KEY } = process.env; -/** - * Simulates the SDK's `defaultMastercopyArtifactsFile`, pointing to the mastercopies.json file. - * - * @returns {string} The absolute path to the mastercopy artifacts file. - */ -function getMastercopyArtifactsFile(): string { - return path.join(cwd(), "temp-mastercopies.json"); -} - task( "verify:mastercopy", "Verifies all mastercopies from the artifacts file in the block explorer corresponding to the current network" ) .addOptionalParam( "contractVersion", - "The specific version of the contract to deploy", + "Filters by a specific version or lateat", "latest", // Default value types.string ) @@ -34,73 +19,24 @@ task( } const chainId = String((await hre.ethers.provider.getNetwork()).chainId); - await verifyLatestMastercopyFromDisk(chainId, contractVersion); - }); - -/** - * Verifies the latest mastercopy from disk, handling multiple contracts and versions. - * - * @param {string} chainId - The chain ID of the network. - * @param {string} [version] - The specific version of the contract to verify. - */ -async function verifyLatestMastercopyFromDisk( - chainId: string, - version?: string -) { - const CONTRACTS = [ - "Exit", - "ExitERC20", - "ExitERC721", - "CirculatingSupply", - "CirculatingSupplyERC20", - "CirculatingSupplyERC721", - ]; - - const verifyDir = path.dirname(getMastercopyArtifactsFile()); - - // Ensure the directory exists - if (!fs.existsSync(verifyDir)) { - fs.mkdirSync(verifyDir, { recursive: true }); - } - - // Define the mastercopyObject with the appropriate type - const mastercopyObject: { [key: string]: { [version: string]: any } } = {}; - for (const contract of CONTRACTS) { - try { - // Read the artifact for the specific contract and version - const latestArtifact = readMastercopy({ - contractName: contract, - contractVersion: version === "latest" ? undefined : version, + for (const artifact of readMastercopies({ contractVersion })) { + const { noop } = await verifyMastercopy({ + artifact, + apiUrlOrChainId: chainId, + apiKey: ETHERSCAN_API_KEY, }); - if (!latestArtifact) { - console.error( - `⏭️ Skipping verify of ${contract}@${version}: Artifact not found.` + const { contractName, contractVersion, address } = artifact; + + if (noop) { + console.log( + `🔄 ${contractName}@${contractVersion}: Already verified at ${address}` + ); + } else { + console.log( + `🚀 ${contractName}@${contractVersion}: Successfully verified at ${address}` ); - continue; } - - // Add the contract to the expected structure - mastercopyObject[contract] = { - [latestArtifact.contractVersion]: latestArtifact, - }; - } catch (error) { - console.error( - `⏭️ Skipping deployment of ${contract}@${version}: Version not found.` - ); - continue; } - } - - const tempFilePath = getMastercopyArtifactsFile(); - fs.writeFileSync(tempFilePath, JSON.stringify(mastercopyObject, null, 2)); - - await verifyAllMastercopies({ - apiUrlOrChainId: chainId, - apiKey: ETHERSCAN_API_KEY as string, - mastercopyArtifactsFile: tempFilePath, }); - - fs.unlinkSync(tempFilePath); -} diff --git a/packages/contracts/yarn.lock b/packages/contracts/yarn.lock index a7968c4..73ebae1 100644 --- a/packages/contracts/yarn.lock +++ b/packages/contracts/yarn.lock @@ -309,10 +309,8 @@ resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== -"@gnosis-guild/zodiac-core@1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@gnosis-guild/zodiac-core/-/zodiac-core-1.1.0.tgz#a15c4ec9bd6a860f732383cc3b65b7e3cac5deab" - integrity sha512-KrNYNEqFv18SU6OSDPOYS5ckzx7U472wiY9S1U6mBYnkvAj2rLODhOT/NlPMdWDlSfix1PT4UWL9GDChaOe4YQ== +"@gnosis-guild/zodiac-core@file:../../../zodiac-core": + version "1.1.1" dependencies: "@gnosis.pm/safe-contracts" "1.3.0" "@openzeppelin/contracts" "5.0.2" @@ -4473,10 +4471,10 @@ solhint-plugin-prettier@0.1.0: "@prettier/sync" "^0.3.0" prettier-linter-helpers "^1.0.0" -solhint@5.0.2: - version "5.0.2" - resolved "https://registry.yarnpkg.com/solhint/-/solhint-5.0.2.tgz#720f7a879d7d137ffa1498575462cac8e131ba2a" - integrity sha512-fDoflGz1jztGRqEDiLI25wSvpjGu0fIqeRXXYKYt4qBOA0EJi8RZwlM11+K2ZAcGFW2K8bevJ2A/wtZ0lDi/bw== +solhint@5.0.3: + version "5.0.3" + resolved "https://registry.yarnpkg.com/solhint/-/solhint-5.0.3.tgz#b57f6d2534fe09a60f9db1b92e834363edd1cbde" + integrity sha512-OLCH6qm/mZTCpplTXzXTJGId1zrtNuDYP5c2e6snIv/hdRVxPfBBz/bAlL91bY/Accavkayp2Zp2BaDSrLVXTQ== dependencies: "@solidity-parser/parser" "^0.18.0" ajv "^6.12.6" @@ -4573,7 +4571,16 @@ string-format@^2.0.0: resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" integrity sha512-bbEs3scLeYNXLecRRuk6uJxdXUSj6le/8rNPHChIJTn2V79aXVTR1EH2OH5zLKKoz0V02fOUKZZcw01pLUShZA== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -4626,7 +4633,14 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -5118,7 +5132,16 @@ workerpool@^6.5.1: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==