-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reafactor: hardhat scripts, task and config
- Loading branch information
1 parent
2662df1
commit 3c53365
Showing
12 changed files
with
275 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { task } from 'hardhat/config' | ||
|
||
import { deployAllMastercopies } 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) | ||
|
||
await deployAllMastercopies({ | ||
provider, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { task, types } from 'hardhat/config' | ||
|
||
import { | ||
EIP1193Provider, | ||
deployMastercopy, | ||
readMastercopy, | ||
} 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' | ||
) | ||
.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) | ||
|
||
// 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}` | ||
) | ||
} | ||
} catch (error) { | ||
console.error( | ||
`⏭️ Skipping deployment of ${contract}@${version}: Version not found.` | ||
) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { task } from 'hardhat/config' | ||
import { verifyAllMastercopies } from '@gnosis-guild/zodiac-core' | ||
|
||
const { ETHERSCAN_API_KEY } = process.env | ||
|
||
task( | ||
'verify:mastercopies', | ||
'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') | ||
} | ||
|
||
const chainId = String((await hre.ethers.provider.getNetwork()).chainId) | ||
await verifyAllMastercopies({ | ||
apiUrlOrChainId: chainId, | ||
apiKey: ETHERSCAN_API_KEY, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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' | ||
|
||
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', | ||
'latest', // Default value | ||
types.string | ||
) | ||
.setAction(async ({ contractVersion }, hre) => { | ||
if (!ETHERSCAN_API_KEY) { | ||
throw new Error('Missing ENV ETHERSCAN_API_KEY') | ||
} | ||
|
||
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.` | ||
) | ||
} | ||
|
||
// 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) | ||
} |