Skip to content

Commit

Permalink
Merge pull request #12 from ctrlc03/feat/contract-addresses-new-format
Browse files Browse the repository at this point in the history
feat: store contract addresses in new format
  • Loading branch information
yashgo0018 authored Sep 21, 2024
2 parents ee2c7f6 + 107b267 commit fa5437a
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ yarn start
- In a fourth terminal, clone the maci repo - `git clone [email protected]:privacy-scaling-explorations/maci.git`
- Copy the zkeys generated from the maci wrapper repo to the cli directory of the maci repo using `cp -r maci-wrapper/packages/hardhat/zkeys maci/packages/cli`.
- Install the dependencies using `pnpm i` and build the maci project using `pnpm run build`
- Copy the new contract addresses from the maci wrapper repo to the maci repo using `cp -r maci-wrapper/packages/hardhat/contractAddresses.json maci/packages/cli/build/contractAddresses.json`.
- Copy the new contract addresses from the maci wrapper repo to the maci repo using `cp -r maci-wrapper/packages/hardhat/contractAddresses.json maci/packages/cli/build/contractAddresses.json`. You can also copy the `deployed-contracts.json`file from the maci wrapper repo to the maci repo `cp maci-wrapper/packages/hardhat/deployed-contracts.json maci/packages/contracts/deployed-contracts.json`.
- Inside the MACI repo folder, run `cp packages/contracts/deploy-config-example.json packages/contracts/deploy-config.json`
- After this you should be able to run the commands written in the [maci documentation](https://maci.pse.dev/docs/quick-start/poll-finalization).
- First merge signups, then merge messages, and then generate proof, and upload the tally.json file which is generated in the process to the admin panel after the poll is over.

Expand Down
17 changes: 16 additions & 1 deletion packages/hardhat/deploy/00_initial_voice_credit_proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ContractStorage, EContracts } from "maci-contracts";
import { InitialVoiceCreditProxyContractName } from "../constants";

import type { ConstantInitialVoiceCreditProxy } from "../typechain-types";

const storage = ContractStorage.getInstance();

const DEFAULT_INITIAL_VOICE_CREDITS = 99;

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand All @@ -14,8 +19,18 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
autoMine: true,
});

const initialVoiceCreditProxy = await hre.ethers.getContract(InitialVoiceCreditProxyContractName, deployer);
const initialVoiceCreditProxy = await hre.ethers.getContract<ConstantInitialVoiceCreditProxy>(
InitialVoiceCreditProxyContractName,
deployer,
);
console.log(`The initial voice credit proxy is deployed at ${await initialVoiceCreditProxy.getAddress()}`);

await storage.register({
id: EContracts.ConstantInitialVoiceCreditProxy,
contract: initialVoiceCreditProxy,
args: [DEFAULT_INITIAL_VOICE_CREDITS.toString()],
network: hre.network.name,
});
};

export default deployContracts;
Expand Down
13 changes: 12 additions & 1 deletion packages/hardhat/deploy/01_gatekeepers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ContractStorage, EContracts } from "maci-contracts";
import { GatekeeperContractName } from "../constants";
import { FreeForAllGatekeeper } from "../typechain-types/";

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
Expand All @@ -12,8 +16,15 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
autoMine: true,
});

const gatekeeper = await hre.ethers.getContract(GatekeeperContractName, deployer);
const gatekeeper = await hre.ethers.getContract<FreeForAllGatekeeper>(GatekeeperContractName, deployer);
console.log(`The gatekeeper is deployed at ${await gatekeeper.getAddress()}`);

await storage.register({
id: EContracts.FreeForAllGatekeeper,
contract: gatekeeper,
network: hre.network.name,
args: [],
});
};

export default deployContracts;
Expand Down
14 changes: 13 additions & 1 deletion packages/hardhat/deploy/02_verifier.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { VerifierContractName } from "../constants";
import { ContractStorage, EContracts } from "maci-contracts";

import type { Verifier } from "../typechain-types";

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
Expand All @@ -12,8 +17,15 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
autoMine: true,
});

const verifier = await hre.ethers.getContract(VerifierContractName, deployer);
const verifier = await hre.ethers.getContract<Verifier>(VerifierContractName, deployer);
console.log(`The verifier is deployed at ${await verifier.getAddress()}`);

await storage.register({
id: EContracts.Verifier,
contract: verifier,
args: [],
network: hre.network.name,
});
};

export default deployContracts;
Expand Down
35 changes: 35 additions & 0 deletions packages/hardhat/deploy/03_poseidon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ContractStorage, EContracts } from "maci-contracts";

const storage = ContractStorage.getInstance();

async function deployPoseidenContract(
name: "PoseidonT3" | "PoseidonT4" | "PoseidonT5" | "PoseidonT6",
Expand Down Expand Up @@ -30,6 +33,38 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir

const poseidonT6 = await deployPoseidenContract("PoseidonT6", hre);
console.log(`The poseidonT6 is deployed at ${await poseidonT6.getAddress()}`);

await storage.register({
id: EContracts.PoseidonT3,
// @ts-expect-error mismatch
contract: poseidonT3,
args: [],
network: hre.network.name,
});

await storage.register({
id: EContracts.PoseidonT4,
// @ts-expect-error mismatch
contract: poseidonT4,
args: [],
network: hre.network.name,
});

await storage.register({
id: EContracts.PoseidonT5,
// @ts-expect-error mismatch
contract: poseidonT5,
args: [],
network: hre.network.name,
});

await storage.register({
id: EContracts.PoseidonT6,
// @ts-expect-error mismatch
contract: poseidonT6,
args: [],
network: hre.network.name,
});
};

export default deployContracts;
Expand Down
14 changes: 13 additions & 1 deletion packages/hardhat/deploy/04_poll_factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

import { ContractStorage, EContracts } from "maci-contracts";
import type { PollFactory } from "../typechain-types";

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();

Expand All @@ -22,9 +27,16 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
autoMine: true,
});

const pollFactory = await hre.ethers.getContract("PollFactory", deployer);
const pollFactory = await hre.ethers.getContract<PollFactory>("PollFactory", deployer);

console.log(`The poll factory is deployed at ${await pollFactory.getAddress()}`);

await storage.register({
id: EContracts.PollFactory,
contract: pollFactory,
args: [],
network: hre.network.name,
});
};

export default deployContracts;
Expand Down
17 changes: 16 additions & 1 deletion packages/hardhat/deploy/05_message_processor_factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ContractStorage, EContracts } from "maci-contracts";

import type { MessageProcessorFactory } from "../typechain-types";

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
Expand All @@ -22,7 +27,17 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
autoMine: true,
});

const messageProcessorFactory = await hre.ethers.getContract("MessageProcessorFactory", deployer);
const messageProcessorFactory = await hre.ethers.getContract<MessageProcessorFactory>(
"MessageProcessorFactory",
deployer,
);

await storage.register({
id: EContracts.MessageProcessorFactory,
contract: messageProcessorFactory,
args: [],
network: hre.network.name,
});

console.log(`The message processor factory is deployed at ${await messageProcessorFactory.getAddress()}`);
};
Expand Down
15 changes: 14 additions & 1 deletion packages/hardhat/deploy/06_tally_factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

import { ContractStorage, EContracts } from "maci-contracts";

import type { TallyFactory } from "../typechain-types";

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();

Expand All @@ -22,7 +28,14 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
autoMine: true,
});

const tallyFactory = await hre.ethers.getContract("TallyFactory", deployer);
const tallyFactory = await hre.ethers.getContract<TallyFactory>("TallyFactory", deployer);

await storage.register({
id: EContracts.TallyFactory,
contract: tallyFactory,
args: [],
network: hre.network.name,
});

console.log(`The tally factory is deployed at ${await tallyFactory.getAddress()}`);
};
Expand Down
20 changes: 19 additions & 1 deletion packages/hardhat/deploy/07_maci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { GatekeeperContractName, InitialVoiceCreditProxyContractName, stateTreeDepth } from "../constants";
import { MACIWrapper, SignUpGatekeeper } from "../typechain-types";
import { genEmptyBallotRoots } from "maci-contracts";
import { genEmptyBallotRoots, ContractStorage, EContracts } from "maci-contracts";

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
Expand Down Expand Up @@ -45,6 +47,22 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir

const tx = await gatekeeper.setMaciInstance(await maci.getAddress());
await tx.wait(1);

await storage.register({
id: EContracts.MACI,
// @ts-expect-error expected maci
contract: maci,
args: [
await pollFactory.getAddress(),
await messageProcessorFactory.getAddress(),
await tallyFactory.getAddress(),
await gatekeeper.getAddress(),
await initialVoiceCreditProxy.getAddress(),
stateTreeDepth,
emptyBallotRoots.map((root: bigint) => root.toString()),
],
network: hre.network.name,
});
};

export default deployContracts;
Expand Down
10 changes: 10 additions & 0 deletions packages/hardhat/deploy/08_vk_registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extractVk } from "maci-circuits";
import { VerifyingKey } from "maci-domainobjs";
import { ContractStorage, EContracts } from "maci-contracts";

import type { IVerifyingKeyStruct } from "maci-contracts";
import type { VkRegistry } from "../typechain-types";
Expand All @@ -23,6 +24,8 @@ export enum EMode {
NON_QV,
}

const storage = ContractStorage.getInstance();

const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();

Expand Down Expand Up @@ -60,6 +63,13 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
[tallyVkParam, tallyVkNonQvParam],
);
await tx.wait();

await storage.register({
id: EContracts.VkRegistry,
contract: vkRegistry,
args: [],
network: hre.network.name,
});
};

export default deployContracts;
Expand Down
Loading

0 comments on commit fa5437a

Please sign in to comment.