Skip to content

Commit

Permalink
feat: add the new version of zodiac core and refactor hardhat tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
juliopavila committed Aug 26, 2024
1 parent 6e20851 commit 684a009
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 190 deletions.
122 changes: 65 additions & 57 deletions mastercopies.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"author": "[email protected]",
"license": "MIT",
"devDependencies": {
"@gnosis-guild/zodiac-core": "^1.1.0",
"@gnosis-guild/zodiac-core": "2.0.0",
"@gnosis.pm/safe-contracts": "1.3.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
Expand Down
16 changes: 8 additions & 8 deletions tasks/create-EIP1193.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { EIP1193Provider } from "@gnosis-guild/zodiac-core";
import { Signer } from "ethers";
import { EthereumProvider } from "hardhat/types";
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;
if (method == 'eth_sendTransaction') {
const { hash } = await signer.sendTransaction((params as any[])[0])
return hash
}

return provider.request({ method, params });
return provider.request({ method, params })
},
};
}
}
36 changes: 32 additions & 4 deletions tasks/deploy-mastercopies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +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 @@ -9,8 +9,36 @@ task(
).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

await deployAllMastercopies({
provider,
})
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}`
)
}
}
})
68 changes: 28 additions & 40 deletions tasks/deploy-mastercopy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
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(
Expand All @@ -21,39 +17,31 @@ 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 contract = 'Delay'
try {
// Read the artifact for the specific contract and version
const artifact = readMastercopy({
contractName: contract,
contractVersion: version === 'latest' ? undefined : version,
})

const { address, noop } = await deployMastercopy({
...artifact,
provider,
})

if (noop) {
console.log(
`🔄 ${artifact.contractName}@${version}: Already deployed at ${address}`
)
} else {
console.log(
`🚀 ${artifact.contractName}@${version}: Successfully deployed at ${address}`
)
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}`
)
}
}
} catch (error) {
console.error(
`⏭️ Skipping deployment of ${contract}@${version}: Version not found.`
)
}
}
})
26 changes: 21 additions & 5 deletions tasks/verify-mastercopies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +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 @@ -12,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}`
)
}
}
})
91 changes: 20 additions & 71 deletions 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,60 +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 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 } } = {}
const contract = 'Delay'
try {
// Read the artifact for the specific contract and version
const latestArtifact = readMastercopy({
contractName: contract,
contractVersion: version === 'latest' ? undefined : version,
})

if (!latestArtifact) {
console.error(
`⏭️ Skipping verify of ${contract}@${version}: Artifact not found.`
)
for (const artifact of readMastercopies({ contractVersion })) {
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}`
)
}
}

// Add the contract to the expected structure
mastercopyObject[contract] = {
[latestArtifact.contractVersion]: latestArtifact,
}
} catch (error) {
console.error(
`⏭️ Skipping deployment of ${contract}@${version}: Version not found.`
)
}

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)
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@
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@2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@gnosis-guild/zodiac-core/-/zodiac-core-2.0.0.tgz#eed83229414b47a1656c1deebfe635beda24786c"
integrity sha512-R3ggh7fv+kS5meN89k/PTCOrTgw73LP3yOykbyBNVzgivXkX8uoaUwJ4anzj5Z18E+Ufbw99fLBvxn9jPTSpqg==
dependencies:
"@gnosis.pm/safe-contracts" "1.3.0"
"@openzeppelin/contracts" "5.0.2"
Expand Down

0 comments on commit 684a009

Please sign in to comment.