-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'repovation' into feat/test
- Loading branch information
Showing
10 changed files
with
151 additions
and
89 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
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
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
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,44 @@ | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
|
||
import { TASK_CLEAN, TASK_COMPILE } from "hardhat/builtin-tasks/task-names"; | ||
import { task } from "hardhat/config"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
||
import { log, yl } from "lib/log"; | ||
|
||
const ABI_OUTPUT_PATH = path.resolve(process.cwd(), "lib", "abi"); | ||
const LIDO_ARTIFACT_PREFIX = "contracts/"; | ||
const ARAGON_ARTIFACT_PATHS = [ | ||
"@aragon/apps-finance/contracts/Finance.sol:Finance", | ||
"@aragon/apps-vault/contracts/Vault.sol:Vault", | ||
"@aragon/apps-lido/apps/voting/contracts/Voting.sol:Voting", | ||
"@aragon/apps-lido/apps/token-manager/contracts/TokenManager.sol:TokenManager", | ||
]; | ||
|
||
const SKIP_NAMES_REGEX = /(Mock|Harness|test_helpers|Imports|deposit_contract|Pausable|.dbg.json|build-info)/; | ||
|
||
task("abis:extract", "Extract ABIs from artifacts").setAction(async (_: unknown, hre: HardhatRuntimeEnvironment) => { | ||
await hre.run(TASK_CLEAN); | ||
await hre.run(TASK_COMPILE); | ||
|
||
const artifactNames = await hre.artifacts.getAllFullyQualifiedNames(); | ||
|
||
const artifactNamesToPublish = artifactNames | ||
.filter((name) => !SKIP_NAMES_REGEX.test(name) && name.startsWith(LIDO_ARTIFACT_PREFIX)) | ||
.concat(ARAGON_ARTIFACT_PATHS); | ||
|
||
await fs.rm(ABI_OUTPUT_PATH, { recursive: true, force: true }); | ||
await fs.mkdir(ABI_OUTPUT_PATH, { recursive: true }); | ||
|
||
for (const name of artifactNamesToPublish) { | ||
const artifact = await hre.artifacts.readArtifact(name); | ||
if (artifact.abi && artifact.abi.length > 0) { | ||
const abiData = JSON.stringify(artifact.abi, null, 2); | ||
await fs.writeFile(path.join(ABI_OUTPUT_PATH, `${artifact.contractName}.json`), abiData); | ||
log.success(`ABI for ${yl(artifact.contractName)} has been saved!`); | ||
} | ||
} | ||
|
||
log.success("All ABIs have been extracted and saved!"); | ||
}); |
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,2 @@ | ||
export * from "./verify-contracts"; | ||
export * from "./extract-abis"; |
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,90 @@ | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
|
||
import { task } from "hardhat/config"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
||
import { cy, log, yl } from "lib/log"; | ||
|
||
type DeployedContract = { | ||
contract: string; | ||
address: string; | ||
constructorArgs: unknown[]; | ||
}; | ||
|
||
type ProxyContract = { | ||
proxy: DeployedContract; | ||
implementation: DeployedContract; | ||
}; | ||
|
||
type Contract = DeployedContract | ProxyContract; | ||
|
||
type NetworkState = { | ||
deployer: string; | ||
[key: string]: Contract | string | number; | ||
}; | ||
|
||
const errors = [] as string[]; | ||
|
||
task("verify:deployed", "Verifies deployed contracts based on state file").setAction( | ||
async (_: unknown, hre: HardhatRuntimeEnvironment) => { | ||
try { | ||
const network = hre.network.name; | ||
log("Verifying contracts for network:", network); | ||
|
||
const networkStateFile = `deployed-${network}.json`; | ||
const networkStateFilePath = path.resolve("./", networkStateFile); | ||
const data = await fs.readFile(networkStateFilePath, "utf8"); | ||
const networkState = JSON.parse(data) as NetworkState; | ||
|
||
const deployedContracts = Object.values(networkState) | ||
.filter((contract): contract is Contract => typeof contract === "object") | ||
.flatMap(getDeployedContract); | ||
|
||
// Not using Promise.all to avoid logging messages out of order | ||
for (const contract of deployedContracts) { | ||
await verifyContract(contract, hre); | ||
} | ||
} catch (error) { | ||
log.error("Error verifying deployed contracts:", error as Error); | ||
throw error; | ||
} | ||
|
||
if (errors.length > 0) { | ||
log.error(`Failed to verify ${errors.length} contract(s):`, errors as string[]); | ||
process.exitCode = errors.length; | ||
} | ||
}, | ||
); | ||
|
||
async function verifyContract(contract: DeployedContract, hre: HardhatRuntimeEnvironment) { | ||
const contractName = contract.contract.split("/").pop()?.split(".")[0]; | ||
const verificationParams = { | ||
address: contract.address, | ||
constructorArguments: contract.constructorArgs, | ||
contract: `${contract.contract}:${contractName}`, | ||
}; | ||
|
||
log.withArguments( | ||
`Verifying contract: ${yl(contract.contract)} at ${cy(contract.address)} with constructor args `, | ||
verificationParams.constructorArguments as string[], | ||
); | ||
|
||
try { | ||
await hre.run("verify:verify", verificationParams); | ||
log.success(`Successfully verified ${yl(contract.contract)}!`); | ||
} catch (error) { | ||
log.error(`Failed to verify ${yl(contract.contract)}:`, error as Error); | ||
errors.push(verificationParams.address); | ||
} | ||
log.emptyLine(); | ||
} | ||
|
||
function getDeployedContract(contract: Contract): DeployedContract[] { | ||
if ("proxy" in contract && "implementation" in contract) { | ||
return [contract.proxy, contract.implementation]; | ||
} else if ("contract" in contract && "address" in contract && "constructorArgs" in contract) { | ||
return [contract]; | ||
} | ||
return []; | ||
} |
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