diff --git a/helpers/DeployHelper.ts b/helpers/DeployHelper.ts index 4e62b52a..f0b8463e 100644 --- a/helpers/DeployHelper.ts +++ b/helpers/DeployHelper.ts @@ -6,16 +6,16 @@ import { GenesisUtilsWrapper, PrimitiveTypeUtilsWrapper } from "../typechain-typ import { SmtLibModule, UniversalVerifierModule, - IdentityTreeStoreModule, Groth16VerifierMTPWrapperModule, Groth16VerifierSigWrapperModule, Groth16VerifierV3WrapperModule, - CredentialAtomicQueryMTPV2ValidatorModule, - CredentialAtomicQuerySigV2ValidatorModule, - CredentialAtomicQueryV3ValidatorModule, VerifierLibModule, VCPaymentModule, StateProxyModule, + IdentityTreeStoreProxyModule, + CredentialAtomicQueryMTPV2ValidatorProxyModule, + CredentialAtomicQuerySigV2ValidatorProxyModule, + CredentialAtomicQueryV3ValidatorProxyModule, } from "../ignition"; import { chainIdInfoMap } from "./constants"; import { waitNotToInterfereWithHardhatIgnition } from "./helperUtils"; @@ -504,18 +504,20 @@ export class DeployHelper { switch (validatorType) { case "mtpV2": g16VerifierWrapperModule = Groth16VerifierMTPWrapperModule; - validatorModule = CredentialAtomicQueryMTPV2ValidatorModule; + validatorModule = CredentialAtomicQueryMTPV2ValidatorProxyModule; break; case "sigV2": g16VerifierWrapperModule = Groth16VerifierSigWrapperModule; - validatorModule = CredentialAtomicQuerySigV2ValidatorModule; + validatorModule = CredentialAtomicQuerySigV2ValidatorProxyModule; break; case "v3": g16VerifierWrapperModule = Groth16VerifierV3WrapperModule; - validatorModule = CredentialAtomicQueryV3ValidatorModule; + validatorModule = CredentialAtomicQueryV3ValidatorProxyModule; break; } + await waitNotToInterfereWithHardhatIgnition(undefined); + groth16VerifierWrapper = ( await ignition.deploy(g16VerifierWrapperModule, { strategy: deployStrategy, @@ -527,15 +529,14 @@ export class DeployHelper { `${g16VerifierContractWrapperName} Wrapper deployed to: ${await groth16VerifierWrapper.getAddress()}`, ); - // Deploying Validator contract to predictable address but with dummy implementation - const tx = await groth16VerifierWrapper.deploymentTransaction(); - await waitNotToInterfereWithHardhatIgnition(tx); + await waitNotToInterfereWithHardhatIgnition(await groth16VerifierWrapper.deploymentTransaction()); + // Deploying Validator contract to predictable address but with dummy implementation validator = ( await ignition.deploy(validatorModule, { strategy: deployStrategy, }) - ).validator; + ).proxy; await validator.waitForDeployment(); // Upgrading Validator contract to the first real implementation @@ -809,10 +810,10 @@ export class DeployHelper { // Deploying IdentityTreeStore contract to predictable address but with dummy implementation identityTreeStore = ( - await ignition.deploy(IdentityTreeStoreModule, { + await ignition.deploy(IdentityTreeStoreProxyModule, { strategy: deployStrategy, }) - ).identityTreeStore; + ).proxy; await identityTreeStore.waitForDeployment(); // Upgrading IdentityTreeStore contract to the first real implementation diff --git a/helpers/helperUtils.ts b/helpers/helperUtils.ts index 0acc4d89..61e13201 100644 --- a/helpers/helperUtils.ts +++ b/helpers/helperUtils.ts @@ -1,5 +1,6 @@ import { ContractTransactionResponse } from "ethers"; import hre, { network } from "hardhat"; +import { boolean } from "hardhat/internal/core/params/argumentTypes"; export function getConfig() { return { @@ -16,14 +17,32 @@ export function getConfig() { } export async function waitNotToInterfereWithHardhatIgnition( - tx: ContractTransactionResponse, + tx: ContractTransactionResponse | undefined, ): Promise { - const confirmationsNeeded = hre.config.ignition?.requiredConfirmations ?? 1; - const waitConfirmations = ["localhost", "hardhat"].includes(network.name) + const isLocalNetwork = ["localhost", "hardhat"].includes(network.name); + const confirmationsNeeded = isLocalNetwork ? 1 - : confirmationsNeeded; - console.log( - `Waiting for ${waitConfirmations} confirmations to not interfere with Hardhat Ignition`, - ); - await tx.wait(waitConfirmations); + : hre.config.ignition?.requiredConfirmations ?? 1; + + if (tx) { + console.log( + `Waiting for ${confirmationsNeeded} confirmations to not interfere with Hardhat Ignition`, + ); + await tx.wait(confirmationsNeeded); + } else if (isLocalNetwork) { + console.log( + `Mining ${confirmationsNeeded} blocks not to interfere with Hardhat Ignition`, + ); + for (const _ of Array.from({ length: confirmationsNeeded })) { + await hre.ethers.provider.send("evm_mine"); + } + } else { + const blockNumberDeployed = await hre.ethers.provider.getBlockNumber(); + let blockNumber = blockNumberDeployed; + console.log("Waiting some blocks to expect at least 5 confirmations for Hardhat Ignition..."); + while (blockNumber < blockNumberDeployed + 10) { + await new Promise((resolve) => setTimeout(resolve, 5000)); + blockNumber = await hre.ethers.provider.getBlockNumber(); + } + } } diff --git a/ignition/modules/credentialAtomicQueryMTPV2Validator.ts b/ignition/modules/credentialAtomicQueryMTPV2Validator.ts index 050050c7..b570d5a7 100644 --- a/ignition/modules/credentialAtomicQueryMTPV2Validator.ts +++ b/ignition/modules/credentialAtomicQueryMTPV2Validator.ts @@ -1,7 +1,7 @@ import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; import { create2AddressesInfo } from "../../helpers/constants"; -const CredentialAtomicQueryMTPV2ValidatorProxyModule = buildModule( +export const CredentialAtomicQueryMTPV2ValidatorProxyModule = buildModule( "CredentialAtomicQueryMTPV2ValidatorProxyModule", (m) => { const proxyAdminOwner = m.getAccount(0); @@ -25,20 +25,3 @@ const CredentialAtomicQueryMTPV2ValidatorProxyModule = buildModule( return { proxyAdmin, proxy }; }, ); - -export const CredentialAtomicQueryMTPV2ValidatorModule = buildModule( - "CredentialAtomicQueryMTPV2ValidatorModule", - (m) => { - const { proxy, proxyAdmin } = m.useModule(CredentialAtomicQueryMTPV2ValidatorProxyModule); - - // Here we're using m.contractAt(...) a bit differently than we did above. - // While we're still using it to create a contract instance, we're now telling Hardhat Ignition - // to treat the contract at the proxy address as an instance of the Demo contract. - // This allows us to interact with the underlying Demo contract via the proxy from within tests and scripts. - const CredentialAtomicQueryMTPV2Validator = m.contractAt( - "CredentialAtomicQueryMTPV2Validator", - proxy, - ); - return { validator: CredentialAtomicQueryMTPV2Validator, proxy, proxyAdmin }; - }, -); diff --git a/ignition/modules/credentialAtomicQuerySigV2Validator.ts b/ignition/modules/credentialAtomicQuerySigV2Validator.ts index b94d4744..55dec9f2 100644 --- a/ignition/modules/credentialAtomicQuerySigV2Validator.ts +++ b/ignition/modules/credentialAtomicQuerySigV2Validator.ts @@ -1,7 +1,7 @@ import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; import { create2AddressesInfo } from "../../helpers/constants"; -const CredentialAtomicQuerySigV2ValidatorProxyModule = buildModule( +export const CredentialAtomicQuerySigV2ValidatorProxyModule = buildModule( "CredentialAtomicQuerySigV2ValidatorProxyModule", (m) => { const proxyAdminOwner = m.getAccount(0); @@ -25,21 +25,3 @@ const CredentialAtomicQuerySigV2ValidatorProxyModule = buildModule( return { proxyAdmin, proxy }; }, ); - -export const CredentialAtomicQuerySigV2ValidatorModule = buildModule( - "CredentialAtomicQuerySigV2ValidatorModule", - (m) => { - const { proxy, proxyAdmin } = m.useModule(CredentialAtomicQuerySigV2ValidatorProxyModule); - - // Here we're using m.contractAt(...) a bit differently than we did above. - // While we're still using it to create a contract instance, we're now telling Hardhat Ignition - // to treat the contract at the proxy address as an instance of the Demo contract. - // This allows us to interact with the underlying Demo contract via the proxy from within tests and scripts. - const CredentialAtomicQuerySigV2Validator = m.contractAt( - "CredentialAtomicQuerySigV2Validator", - proxy, - ); - - return { validator: CredentialAtomicQuerySigV2Validator, proxy, proxyAdmin }; - }, -); diff --git a/ignition/modules/credentialAtomicQueryV3Validator.ts b/ignition/modules/credentialAtomicQueryV3Validator.ts index 72dc6f3e..b2dcf13c 100644 --- a/ignition/modules/credentialAtomicQueryV3Validator.ts +++ b/ignition/modules/credentialAtomicQueryV3Validator.ts @@ -1,7 +1,7 @@ import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; import { create2AddressesInfo } from "../../helpers/constants"; -const CredentialAtomicQueryV3ValidatorProxyModule = buildModule( +export const CredentialAtomicQueryV3ValidatorProxyModule = buildModule( "CredentialAtomicQueryV3ValidatorProxyModule", (m) => { const proxyAdminOwner = m.getAccount(0); @@ -23,21 +23,3 @@ const CredentialAtomicQueryV3ValidatorProxyModule = buildModule( return { proxyAdmin, proxy }; }, ); - -export const CredentialAtomicQueryV3ValidatorModule = buildModule( - "CredentialAtomicQueryV3ValidatorModule", - (m) => { - const { proxy, proxyAdmin } = m.useModule(CredentialAtomicQueryV3ValidatorProxyModule); - - // Here we're using m.contractAt(...) a bit differently than we did above. - // While we're still using it to create a contract instance, we're now telling Hardhat Ignition - // to treat the contract at the proxy address as an instance of the Demo contract. - // This allows us to interact with the underlying Demo contract via the proxy from within tests and scripts. - const CredentialAtomicQueryV3Validator = m.contractAt( - "CredentialAtomicQueryV3Validator", - proxy, - ); - - return { validator: CredentialAtomicQueryV3Validator, proxy, proxyAdmin }; - }, -); diff --git a/ignition/modules/identityTreeStore.ts b/ignition/modules/identityTreeStore.ts index 2b3c6aa3..c5bf4795 100644 --- a/ignition/modules/identityTreeStore.ts +++ b/ignition/modules/identityTreeStore.ts @@ -1,7 +1,7 @@ import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; import { create2AddressesInfo } from "../../helpers/constants"; -const IdentityTreeStoreProxyModule = buildModule("IdentityTreeStoreProxyModule", (m) => { +export const IdentityTreeStoreProxyModule = buildModule("IdentityTreeStoreProxyModule", (m) => { const proxyAdminOwner = m.getAccount(0); // This contract is supposed to be deployed to the same address across many networks, @@ -20,14 +20,3 @@ const IdentityTreeStoreProxyModule = buildModule("IdentityTreeStoreProxyModule", return { proxyAdmin, proxy }; }); - -export const IdentityTreeStoreModule = buildModule("IdentityTreeStoreModule", (m) => { - const { proxy, proxyAdmin } = m.useModule(IdentityTreeStoreProxyModule); - - // Here we're using m.contractAt(...) a bit differently than we did above. - // While we're still using it to create a contract instance, we're now telling Hardhat Ignition - // to treat the contract at the proxy address as an instance of the Demo contract. - // This allows us to interact with the underlying Demo contract via the proxy from within tests and scripts. - const identityTreeStore = m.contractAt("IdentityTreeStore", proxy); - return { identityTreeStore, proxy, proxyAdmin }; -}); diff --git a/scripts/deployValidators.ts b/scripts/deployValidators.ts index 90c5a466..dbae1b18 100644 --- a/scripts/deployValidators.ts +++ b/scripts/deployValidators.ts @@ -2,7 +2,7 @@ import fs from "fs"; import path from "path"; import { DeployHelper } from "../helpers/DeployHelper"; import hre, { ethers, network } from "hardhat"; -import { getConfig } from "../helpers/helperUtils"; +import { getConfig, waitNotToInterfereWithHardhatIgnition } from "../helpers/helperUtils"; async function main() { const config = getConfig(); @@ -30,13 +30,6 @@ async function main() { validator: await validator.getAddress(), groth16verifier: await groth16VerifierWrapper.getAddress(), }); - const blockNumberDeployed = await hre.ethers.provider.getBlockNumber(); - let blockNumber = blockNumberDeployed; - console.log("Waiting some blocks to expect at least 5 confirmations for ignition..."); - while (blockNumber < blockNumberDeployed + 10) { - await new Promise((resolve) => setTimeout(resolve, 5000)); - blockNumber = await hre.ethers.provider.getBlockNumber(); - } } const chainId = parseInt(await network.provider.send("eth_chainId"), 16);