Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/lite state improve deploy scripts #271

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions helpers/DeployHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 27 additions & 8 deletions helpers/helperUtils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,14 +17,32 @@ export function getConfig() {
}

export async function waitNotToInterfereWithHardhatIgnition(
tx: ContractTransactionResponse,
tx: ContractTransactionResponse | undefined,
): Promise<void> {
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();
}
}
}
19 changes: 1 addition & 18 deletions ignition/modules/credentialAtomicQueryMTPV2Validator.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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 };
},
);
20 changes: 1 addition & 19 deletions ignition/modules/credentialAtomicQuerySigV2Validator.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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 };
},
);
20 changes: 1 addition & 19 deletions ignition/modules/credentialAtomicQueryV3Validator.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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 };
},
);
13 changes: 1 addition & 12 deletions ignition/modules/identityTreeStore.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 };
});
9 changes: 1 addition & 8 deletions scripts/deployValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Loading