From 107b26703d99d53c6f597f819b1c6d684d3a1ae1 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:52:37 +0800 Subject: [PATCH] feat: store contract addresses in new format --- README.md | 3 +- .../deploy/00_initial_voice_credit_proxy.ts | 17 ++- packages/hardhat/deploy/01_gatekeepers.ts | 13 +- packages/hardhat/deploy/02_verifier.ts | 14 ++- packages/hardhat/deploy/03_poseidon.ts | 35 ++++++ packages/hardhat/deploy/04_poll_factory.ts | 14 ++- .../deploy/05_message_processor_factory.ts | 17 ++- packages/hardhat/deploy/06_tally_factory.ts | 15 ++- packages/hardhat/deploy/07_maci.ts | 20 ++- packages/hardhat/deploy/08_vk_registry.ts | 10 ++ packages/hardhat/deployed-contracts.json | 118 ++++++++++++++++++ 11 files changed, 268 insertions(+), 8 deletions(-) create mode 100644 packages/hardhat/deployed-contracts.json diff --git a/README.md b/README.md index 35f9299..7942625 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,8 @@ yarn start - In a fourth terminal, clone the maci repo - `git clone git@github.com: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. diff --git a/packages/hardhat/deploy/00_initial_voice_credit_proxy.ts b/packages/hardhat/deploy/00_initial_voice_credit_proxy.ts index a2ad0d8..3296d15 100644 --- a/packages/hardhat/deploy/00_initial_voice_credit_proxy.ts +++ b/packages/hardhat/deploy/00_initial_voice_credit_proxy.ts @@ -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) { @@ -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( + 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; diff --git a/packages/hardhat/deploy/01_gatekeepers.ts b/packages/hardhat/deploy/01_gatekeepers.ts index 9f65d43..a56e3e5 100644 --- a/packages/hardhat/deploy/01_gatekeepers.ts +++ b/packages/hardhat/deploy/01_gatekeepers.ts @@ -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(); @@ -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(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; diff --git a/packages/hardhat/deploy/02_verifier.ts b/packages/hardhat/deploy/02_verifier.ts index 9ebb4b2..514134b 100644 --- a/packages/hardhat/deploy/02_verifier.ts +++ b/packages/hardhat/deploy/02_verifier.ts @@ -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(); @@ -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(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; diff --git a/packages/hardhat/deploy/03_poseidon.ts b/packages/hardhat/deploy/03_poseidon.ts index 58528ac..19d6fd8 100644 --- a/packages/hardhat/deploy/03_poseidon.ts +++ b/packages/hardhat/deploy/03_poseidon.ts @@ -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", @@ -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; diff --git a/packages/hardhat/deploy/04_poll_factory.ts b/packages/hardhat/deploy/04_poll_factory.ts index 28b9e2c..f5f1775 100644 --- a/packages/hardhat/deploy/04_poll_factory.ts +++ b/packages/hardhat/deploy/04_poll_factory.ts @@ -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(); @@ -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", 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; diff --git a/packages/hardhat/deploy/05_message_processor_factory.ts b/packages/hardhat/deploy/05_message_processor_factory.ts index d3ceffb..7cd8a50 100644 --- a/packages/hardhat/deploy/05_message_processor_factory.ts +++ b/packages/hardhat/deploy/05_message_processor_factory.ts @@ -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(); @@ -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", + 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()}`); }; diff --git a/packages/hardhat/deploy/06_tally_factory.ts b/packages/hardhat/deploy/06_tally_factory.ts index 77c334f..fda19e7 100644 --- a/packages/hardhat/deploy/06_tally_factory.ts +++ b/packages/hardhat/deploy/06_tally_factory.ts @@ -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(); @@ -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", 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()}`); }; diff --git a/packages/hardhat/deploy/07_maci.ts b/packages/hardhat/deploy/07_maci.ts index d964e90..cd9bc73 100644 --- a/packages/hardhat/deploy/07_maci.ts +++ b/packages/hardhat/deploy/07_maci.ts @@ -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(); @@ -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; diff --git a/packages/hardhat/deploy/08_vk_registry.ts b/packages/hardhat/deploy/08_vk_registry.ts index 4b0ce00..a35cd67 100644 --- a/packages/hardhat/deploy/08_vk_registry.ts +++ b/packages/hardhat/deploy/08_vk_registry.ts @@ -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"; @@ -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(); @@ -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; diff --git a/packages/hardhat/deployed-contracts.json b/packages/hardhat/deployed-contracts.json new file mode 100644 index 0000000..0e54c51 --- /dev/null +++ b/packages/hardhat/deployed-contracts.json @@ -0,0 +1,118 @@ +{ + "localhost": { + "instance": { + "0x5FbDB2315678afecb367f032d93F642f64180aa3": { + "id": "ConstantInitialVoiceCreditProxy", + "verify": { + "args": "[\"99\"]" + } + }, + "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512": { + "id": "FreeForAllGatekeeper", + "verify": { + "args": "[]" + } + }, + "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0": { + "id": "Verifier", + "verify": { + "args": "[]" + } + }, + "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9": { + "id": "PoseidonT3", + "verify": { + "args": "[]" + } + }, + "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9": { + "id": "PoseidonT4", + "verify": { + "args": "[]" + } + }, + "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707": { + "id": "PoseidonT5", + "verify": { + "args": "[]" + } + }, + "0x0165878A594ca255338adfa4d48449f69242Eb8F": { + "id": "PoseidonT6", + "verify": { + "args": "[]" + } + }, + "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853": { + "id": "PollFactory", + "verify": { + "args": "[]" + } + }, + "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6": { + "id": "MessageProcessorFactory", + "verify": { + "args": "[]" + } + }, + "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318": { + "id": "TallyFactory", + "verify": { + "args": "[]" + } + }, + "0x610178dA211FEF7D417bC0e6FeD39F05609AD788": { + "id": "MACI", + "verify": { + "args": "[\"0xa513E6E4b8f2a923D98304ec87F64353C4D5C853\",\"0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6\",\"0x8A791620dd6260079BF849Dc5567aDC3F2FdC318\",\"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512\",\"0x5FbDB2315678afecb367f032d93F642f64180aa3\",10,[\"16015576667038038422103932363190100635991292382181099511410843174865570503661\",\"166510078825589460025300915201657086611944528317298994959376081297530246971\",\"10057734083972610459557695472359628128485394923403014377687504571662791937025\",\"4904828619307091008204672239231377290495002626534171783829482835985709082773\",\"18694062287284245784028624966421731916526814537891066525886866373016385890569\"]]" + } + } + }, + "named": { + "ConstantInitialVoiceCreditProxy": { + "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3", + "count": 1 + }, + "FreeForAllGatekeeper": { + "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + "count": 1 + }, + "Verifier": { + "address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + "count": 1 + }, + "PoseidonT3": { + "address": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", + "count": 1 + }, + "PoseidonT4": { + "address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", + "count": 1 + }, + "PoseidonT5": { + "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", + "count": 1 + }, + "PoseidonT6": { + "address": "0x0165878A594ca255338adfa4d48449f69242Eb8F", + "count": 1 + }, + "PollFactory": { + "address": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", + "count": 1 + }, + "MessageProcessorFactory": { + "address": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6", + "count": 1 + }, + "TallyFactory": { + "address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318", + "count": 1 + }, + "MACI": { + "address": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788", + "count": 1 + } + } + } +} \ No newline at end of file