diff --git a/apps/website/versioned_docs/version-v1.2/contracts.md b/apps/website/versioned_docs/version-v1.2/contracts.md index d3c45bc653..3d34449e22 100644 --- a/apps/website/versioned_docs/version-v1.2/contracts.md +++ b/apps/website/versioned_docs/version-v1.2/contracts.md @@ -349,7 +349,7 @@ This contract can be used by the `SignUpGateKeeper` to determine whether a user MACI requires a signup gatekeeper to ensure that only designed users register. It is up to MACI's deployer how they wish to allow sign-ups, therefore they can implement their own GateKeeper. The repository comes with different options: -- `FreeForAllSignUpGatekeeper` - This allows anyone to signup on MACI. +- `FreeForAllGatekeeper` - This allows anyone to signup on MACI. - `SignUpTokenGatekeeper` - This makes use of a ERC721 token to gatekeep the signup function. - `EASGatekeeper` - This allows gatekeeping signups to only users who have a specific EAS attestation. diff --git a/apps/website/versioned_docs/version-v2.x/developers-references/smart-contracts/Gatekeepers.md b/apps/website/versioned_docs/version-v2.x/developers-references/smart-contracts/Gatekeepers.md index e097b2c1a9..8d54f6b267 100644 --- a/apps/website/versioned_docs/version-v2.x/developers-references/smart-contracts/Gatekeepers.md +++ b/apps/website/versioned_docs/version-v2.x/developers-references/smart-contracts/Gatekeepers.md @@ -15,7 +15,7 @@ MACI uses a "gatekeeper" contract, which is used to configure and enforce the el The MACI repository comes with several out-of-the-box options: -- `FreeForAllSignUpGatekeeper` - This allows anyone to signup on MACI. +- `FreeForAllGatekeeper` - This allows anyone to signup on MACI. - `SignUpTokenGatekeeper` - This restricts signups only to holders of a specific ERC721 token. - `EASGatekeeper` - This restricts signups only to users who have received an attestation of a specific schema from a trusted attester. - `HatsGatekeeper` - This allows gatekeeping signups to only users who have a specific [Hat](https://www.hatsprotocol.xyz/). diff --git a/packages/contracts/contracts/gatekeepers/FreeForAllSignUpGatekeeper.sol b/packages/contracts/contracts/gatekeepers/FreeForAllGatekeeper.sol similarity index 100% rename from packages/contracts/contracts/gatekeepers/FreeForAllSignUpGatekeeper.sol rename to packages/contracts/contracts/gatekeepers/FreeForAllGatekeeper.sol diff --git a/packages/contracts/package.json b/packages/contracts/package.json index f6978c8333..d55a88a9b7 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -11,7 +11,14 @@ "./typechain-types": { "types": "./build/typechain-types/index.d.ts", "default": "./build/typechain-types/index.js" - } + }, + "./tasks/deploy": { + "types": "./build/tasks/deploy/index.d.ts", + "default": "./build/tasks/deploy/index.js" + }, + "./tasks/deploy/maci/*": "./build/tasks/deploy/maci/*.js", + "./tasks/deploy/poll/*": "./build/tasks/deploy/poll/*.js", + "./tasks/runner/*": "./build/tasks/runner/*.js" }, "bin": { "maci-contracts": "./build/ts/index.js" diff --git a/packages/contracts/tasks/deploy/index.ts b/packages/contracts/tasks/deploy/index.ts index 63d76bd6d8..b35df05a92 100644 --- a/packages/contracts/tasks/deploy/index.ts +++ b/packages/contracts/tasks/deploy/index.ts @@ -9,7 +9,11 @@ import path from "path"; if (fs.existsSync(tasksPath)) { fs.readdirSync(tasksPath) - .filter((p) => p.includes(".ts") && !p.includes("index.ts")) + .filter( + (p) => + (p.endsWith(".ts") && !p.endsWith("index.ts") && !p.endsWith("d.ts")) || + (p.endsWith(".js") && !p.endsWith("index.js")), + ) .forEach((task) => { import(`${tasksPath}/${task}`); }); diff --git a/packages/contracts/tasks/deploy/maci/01-constantInitialVoiceCreditProxy.ts b/packages/contracts/tasks/deploy/maci/01-constantInitialVoiceCreditProxy.ts index d6c778b8a3..ddab04cd73 100644 --- a/packages/contracts/tasks/deploy/maci/01-constantInitialVoiceCreditProxy.ts +++ b/packages/contracts/tasks/deploy/maci/01-constantInitialVoiceCreditProxy.ts @@ -1,3 +1,4 @@ +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -11,7 +12,7 @@ const storage = ContractStorage.getInstance(); * Deploy step registration and task itself */ deployment - .deployTask("full:deploy-constant-initial-voice-credit-proxy", "Deploy constant initial voice credit proxy") + .deployTask(EDeploySteps.ConstantInitialVoiceCreditProxy, "Deploy constant initial voice credit proxy") .then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); diff --git a/packages/contracts/tasks/deploy/maci/02-gatekeepers.ts b/packages/contracts/tasks/deploy/maci/02-gatekeepers.ts index e48789c7ee..f3020fcf21 100644 --- a/packages/contracts/tasks/deploy/maci/02-gatekeepers.ts +++ b/packages/contracts/tasks/deploy/maci/02-gatekeepers.ts @@ -1,5 +1,5 @@ import { HatsGatekeeperBase } from "../../../typechain-types"; -import { ESupportedChains } from "../../helpers/constants"; +import { EDeploySteps, ESupportedChains } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { uuidToBigInt } from "../../helpers/numericParser"; @@ -11,7 +11,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers").then((task) => +deployment.deployTask(EDeploySteps.Gatekeepers, "Deploy gatekeepers").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/03-verifier.ts b/packages/contracts/tasks/deploy/maci/03-verifier.ts index 139e2c1659..adb04cd78c 100644 --- a/packages/contracts/tasks/deploy/maci/03-verifier.ts +++ b/packages/contracts/tasks/deploy/maci/03-verifier.ts @@ -1,3 +1,4 @@ +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -8,7 +9,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-verifier", "Deploy verifier").then((task) => +deployment.deployTask(EDeploySteps.Verifier, "Deploy verifier").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/04-poseidon.ts b/packages/contracts/tasks/deploy/maci/04-poseidon.ts index 7b3871d384..29c5a83205 100644 --- a/packages/contracts/tasks/deploy/maci/04-poseidon.ts +++ b/packages/contracts/tasks/deploy/maci/04-poseidon.ts @@ -1,3 +1,4 @@ +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -8,7 +9,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-poseidon", "Deploy poseidon contracts").then((task) => +deployment.deployTask(EDeploySteps.Poseidon, "Deploy poseidon contracts").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/05-pollFactory.ts b/packages/contracts/tasks/deploy/maci/05-pollFactory.ts index 4839b1413c..5a306b72ac 100644 --- a/packages/contracts/tasks/deploy/maci/05-pollFactory.ts +++ b/packages/contracts/tasks/deploy/maci/05-pollFactory.ts @@ -1,3 +1,4 @@ +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -8,7 +9,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-poll-factory", "Deploy poll factory").then((task) => +deployment.deployTask(EDeploySteps.PollFactory, "Deploy poll factory").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/06-messageProcessorFactory.ts b/packages/contracts/tasks/deploy/maci/06-messageProcessorFactory.ts index 0b9c9d1b66..9c1027d536 100644 --- a/packages/contracts/tasks/deploy/maci/06-messageProcessorFactory.ts +++ b/packages/contracts/tasks/deploy/maci/06-messageProcessorFactory.ts @@ -1,3 +1,4 @@ +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -8,7 +9,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-message-processor-factory", "Deploy message processor factory").then((task) => +deployment.deployTask(EDeploySteps.MessageProcessorFactory, "Deploy message processor factory").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/07-tallyFactory.ts b/packages/contracts/tasks/deploy/maci/07-tallyFactory.ts index 5092b3544e..477bcada33 100644 --- a/packages/contracts/tasks/deploy/maci/07-tallyFactory.ts +++ b/packages/contracts/tasks/deploy/maci/07-tallyFactory.ts @@ -1,3 +1,4 @@ +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -8,7 +9,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-tally-factory", "Deploy tally factory").then((task) => +deployment.deployTask(EDeploySteps.TallyFactory, "Deploy tally factory").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/08-maci.ts b/packages/contracts/tasks/deploy/maci/08-maci.ts index 47bb56725d..09bd49dab2 100644 --- a/packages/contracts/tasks/deploy/maci/08-maci.ts +++ b/packages/contracts/tasks/deploy/maci/08-maci.ts @@ -8,6 +8,7 @@ import type { } from "../../../typechain-types"; import { genEmptyBallotRoots } from "../../../ts/genEmptyBallotRoots"; +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, IDeployParams } from "../../helpers/types"; @@ -20,7 +21,7 @@ const DEFAULT_STATE_TREE_DEPTH = 10; /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-maci", "Deploy MACI contract").then((task) => +deployment.deployTask(EDeploySteps.Maci, "Deploy MACI contract").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/maci/09-vkRegistry.ts b/packages/contracts/tasks/deploy/maci/09-vkRegistry.ts index 4a04ddbab6..da7b7f734a 100644 --- a/packages/contracts/tasks/deploy/maci/09-vkRegistry.ts +++ b/packages/contracts/tasks/deploy/maci/09-vkRegistry.ts @@ -5,6 +5,7 @@ import type { IVerifyingKeyStruct } from "../../../ts/types"; import type { VkRegistry } from "../../../typechain-types"; import { EMode } from "../../../ts/constants"; +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts, type IDeployParams } from "../../helpers/types"; @@ -15,7 +16,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("full:deploy-vk-registry", "Deploy Vk Registry and set keys").then((task) => +deployment.deployTask(EDeploySteps.VkRegistry, "Deploy Vk Registry and set keys").then((task) => task.setAction(async ({ incremental }: IDeployParams, hre) => { deployment.setHre(hre); const deployer = await deployment.getDeployer(); diff --git a/packages/contracts/tasks/deploy/poll/01-poll.ts b/packages/contracts/tasks/deploy/poll/01-poll.ts index bbe34866b1..38c5719133 100644 --- a/packages/contracts/tasks/deploy/poll/01-poll.ts +++ b/packages/contracts/tasks/deploy/poll/01-poll.ts @@ -4,6 +4,7 @@ import { PubKey } from "maci-domainobjs"; import type { MACI, Poll } from "../../../typechain-types"; import { EMode } from "../../../ts/constants"; +import { EDeploySteps } from "../../helpers/constants"; import { ContractStorage } from "../../helpers/ContractStorage"; import { Deployment } from "../../helpers/Deployment"; import { EContracts } from "../../helpers/types"; @@ -14,7 +15,7 @@ const storage = ContractStorage.getInstance(); /** * Deploy step registration and task itself */ -deployment.deployTask("poll:deploy-poll", "Deploy poll").then((task) => +deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) => task.setAction(async (_, hre) => { deployment.setHre(hre); diff --git a/packages/contracts/tasks/helpers/ContractStorage.ts b/packages/contracts/tasks/helpers/ContractStorage.ts index 7724d0c46c..1ee9d9f733 100644 --- a/packages/contracts/tasks/helpers/ContractStorage.ts +++ b/packages/contracts/tasks/helpers/ContractStorage.ts @@ -44,7 +44,7 @@ export class ContractStorage { this.db = low( typeof window !== "undefined" ? new LocalStorageSync("deployed-contracts") - : new FileSync(storagePath ?? path.resolve(__dirname, "..", "..", "./deployed-contracts.json")), + : new FileSync(storagePath ?? path.resolve(process.cwd(), "./deployed-contracts.json")), ); } diff --git a/packages/contracts/tasks/helpers/Deployment.ts b/packages/contracts/tasks/helpers/Deployment.ts index b53e44ec9d..e161a04c3b 100644 --- a/packages/contracts/tasks/helpers/Deployment.ts +++ b/packages/contracts/tasks/helpers/Deployment.ts @@ -44,7 +44,7 @@ export class Deployment { /** * Step catalog to create sequential tasks */ - private stepCatalog: Map; + private stepCatalog: Map>; /** * Json file database instance @@ -61,14 +61,14 @@ export class Deployment { */ private constructor(hre?: HardhatRuntimeEnvironment) { this.stepCatalog = new Map([ - ["full", []], - ["poll", []], + ["full", {}], + ["poll", {}], ]); this.hre = hre; this.config = low( typeof window !== "undefined" ? new LocalStorageSync("deploy-config") - : new FileSync(path.resolve(__dirname, "..", "..", "./deploy-config.json")), + : new FileSync(path.resolve(process.cwd(), "./deploy-config.json")), ); this.storage = ContractStorage.getInstance(); } @@ -270,7 +270,7 @@ export class Deployment { throw new Error(`Unknown deploy type: ${deployType}`); } - steps.push({ name, taskName, paramsFn }); + steps[taskName] = { name, taskName, paramsFn }; } /** @@ -296,11 +296,13 @@ export class Deployment { throw new Error(`Unknown deploy type: ${deployType}`); } - return Promise.all(stepList.map(({ paramsFn }) => paramsFn(params))).then((stepArgs) => + const steps = Object.values(stepList); + + return Promise.all(steps.map(({ paramsFn }) => paramsFn(params))).then((stepArgs) => stepArgs.map((args, index) => ({ id: index + 1, - name: stepList[index].name, - taskName: stepList[index].taskName, + name: steps[index].name, + taskName: steps[index].taskName, args: args as unknown, })), ); diff --git a/packages/contracts/tasks/helpers/constants.ts b/packages/contracts/tasks/helpers/constants.ts index 38ed0b0bf1..5788f8fc9a 100644 --- a/packages/contracts/tasks/helpers/constants.ts +++ b/packages/contracts/tasks/helpers/constants.ts @@ -1,3 +1,19 @@ +/** + * Deploy steps + */ +export enum EDeploySteps { + ConstantInitialVoiceCreditProxy = "full:deploy-constant-initial-voice-credit-proxy", + Gatekeepers = "full:deploy-gatekeepers", + Verifier = "full:deploy-verifier", + Poseidon = "full:deploy-poseidon", + PollFactory = "full:deploy-poll-factory", + MessageProcessorFactory = "full:deploy-message-processor-factory", + TallyFactory = "full:deploy-tally-factory", + Maci = "full:deploy-maci", + VkRegistry = "full:deploy-vk-registry", + Poll = "poll:deploy-poll", +} + /** * Supported networks for deployment and task running */ diff --git a/packages/contracts/tests/SignUpGatekeeper.test.ts b/packages/contracts/tests/SignUpGatekeeper.test.ts index 92851d2ef7..cdf4937025 100644 --- a/packages/contracts/tests/SignUpGatekeeper.test.ts +++ b/packages/contracts/tests/SignUpGatekeeper.test.ts @@ -91,7 +91,7 @@ describe("SignUpGatekeeper", () => { }); }); - describe("FreeForAllSignUpGatekeeper", () => { + describe("FreeForAllGatekeeper", () => { it("should always complete successfully", async () => { const tx = await freeForAllContract.register(ZeroAddress, AbiCoder.defaultAbiCoder().encode(["uint256"], [1])); const receipt = await tx.wait(); diff --git a/packages/contracts/ts/index.ts b/packages/contracts/ts/index.ts index 221993aba7..0161021f39 100644 --- a/packages/contracts/ts/index.ts +++ b/packages/contracts/ts/index.ts @@ -19,6 +19,7 @@ export { genMaciStateFromContract } from "./genMaciState"; export { genEmptyBallotRoots } from "./genEmptyBallotRoots"; export { formatProofForVerifierContract, getDefaultSigner, getDefaultNetwork, getSigners } from "./utils"; export { EMode } from "./constants"; +export { EDeploySteps } from "../tasks/helpers/constants"; export { Deployment } from "../tasks/helpers/Deployment"; export { ContractStorage } from "../tasks/helpers/ContractStorage"; export { ProofGenerator } from "../tasks/helpers/ProofGenerator";