Skip to content

Commit

Permalink
Merge pull request #1784 from privacy-scaling-explorations/chore/depl…
Browse files Browse the repository at this point in the history
…oyment-keys

chore(contracts): use cwd path for contract storage and config
  • Loading branch information
0xmad authored Aug 19, 2024
2 parents 94cd505 + a78408d commit a08d49d
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/website/versioned_docs/version-v1.2/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
9 changes: 8 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion packages/contracts/tasks/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/tasks/deploy/maci/02-gatekeepers.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/maci/03-verifier.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/maci/04-poseidon.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/maci/05-pollFactory.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/maci/07-tallyFactory.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/maci/08-maci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/maci/09-vkRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/tasks/deploy/poll/01-poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tasks/helpers/ContractStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ContractStorage {
this.db = low(
typeof window !== "undefined"
? new LocalStorageSync<TStorage>("deployed-contracts")
: new FileSync<TStorage>(storagePath ?? path.resolve(__dirname, "..", "..", "./deployed-contracts.json")),
: new FileSync<TStorage>(storagePath ?? path.resolve(process.cwd(), "./deployed-contracts.json")),
);
}

Expand Down
18 changes: 10 additions & 8 deletions packages/contracts/tasks/helpers/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Deployment {
/**
* Step catalog to create sequential tasks
*/
private stepCatalog: Map<string, IDeployStepCatalog[]>;
private stepCatalog: Map<string, Record<string, IDeployStepCatalog>>;

/**
* Json file database instance
Expand All @@ -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<TConfig>("deploy-config")
: new FileSync<TConfig>(path.resolve(__dirname, "..", "..", "./deploy-config.json")),
: new FileSync<TConfig>(path.resolve(process.cwd(), "./deploy-config.json")),
);
this.storage = ContractStorage.getInstance();
}
Expand Down Expand Up @@ -270,7 +270,7 @@ export class Deployment {
throw new Error(`Unknown deploy type: ${deployType}`);
}

steps.push({ name, taskName, paramsFn });
steps[taskName] = { name, taskName, paramsFn };
}

/**
Expand All @@ -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,
})),
);
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/tasks/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tests/SignUpGatekeeper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit a08d49d

Please sign in to comment.