Skip to content

Commit

Permalink
refact: preparing the package for zodiac-core v2
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Aug 26, 2024
1 parent c0c9619 commit fcfe728
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 151 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
42 changes: 33 additions & 9 deletions packages/contracts/tasks/deploy-mastercopies.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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}`
);
}
}
});
65 changes: 23 additions & 42 deletions packages/contracts/tasks/deploy-mastercopy.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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;
}
}
}
});
28 changes: 21 additions & 7 deletions packages/contracts/tasks/verify-mastercopies.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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}`
);
}
}
});
96 changes: 16 additions & 80 deletions packages/contracts/tasks/verify-mastercopy.ts
Original file line number Diff line number Diff line change
@@ -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
)
Expand All @@ -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);
}
Loading

0 comments on commit fcfe728

Please sign in to comment.