Skip to content

Commit

Permalink
feat(merkleroot-gatekeeper): merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Crisgarner committed Sep 30, 2024
2 parents af86164 + 8c04308 commit 704dc44
Show file tree
Hide file tree
Showing 23 changed files with 882 additions and 100 deletions.
3 changes: 3 additions & 0 deletions packages/contracts/contracts/maci/Poll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract Poll is Ownable, BasePoll, ICommon {

/// @notice events
event SetRegistry(address indexed registry);
event PollInit();

/// @notice custom errors
error RegistryAlreadyInitialized();
Expand Down Expand Up @@ -113,6 +114,8 @@ contract Poll is Ownable, BasePoll, ICommon {
function init() public override onlyOwner isRegistryInitialized {
initTime = block.timestamp;
super.init();

emit PollInit();
}

/// @inheritdoc BasePoll
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/contracts/registry/SimpleRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import { BaseRegistry } from "./BaseRegistry.sol";

contract SimpleRegistry is BaseRegistry {
/// @notice Create a new instance of the registry contract
/// @param max The maximum number of projects that can be registered
/// @param url The metadata url
/// @param ownerAddress The owner address
constructor(
uint256 max,
string memory url,
address ownerAddress
) payable BaseRegistry(max, url, ownerAddress) {}
}
103 changes: 83 additions & 20 deletions packages/contracts/deploy-config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,23 @@
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "EASGatekeeper",
"registryManager": "EASRegistryManager"
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0xC2679fBD37d54388Ce493F1DB75320D236e1815e"
"easAddress": "0x4200000000000000000000000000000000000021"
},
"VkRegistry": {
"stateTreeDepth": 10,
Expand Down Expand Up @@ -98,14 +107,23 @@
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "ZupassGatekeeper",
"registryManager": "EASRegistryManager"
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0xaEF4103A04090071165F78D45D83A0C0782c2B2a"
"easAddress": "0x4200000000000000000000000000000000000021"
},
"VkRegistry": {
"stateTreeDepth": 10,
Expand Down Expand Up @@ -166,11 +184,20 @@
"groupId": 0
},
"MACI": {
"stateTreeDepth": 6,
"gatekeeper": "EASGatekeeper",
"registryManager": "EASRegistryManager"
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0x4200000000000000000000000000000000000021"
Expand Down Expand Up @@ -234,14 +261,23 @@
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "EASRegistryManager"
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0xC2679fBD37d54388Ce493F1DB75320D236e1815e"
"easAddress": "0x4200000000000000000000000000000000000021"
},
"VkRegistry": {
"stateTreeDepth": 10,
Expand Down Expand Up @@ -302,14 +338,23 @@
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "EASRegistryManager"
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0xC2679fBD37d54388Ce493F1DB75320D236e1815e"
"easAddress": "0x4200000000000000000000000000000000000021"
},
"VkRegistry": {
"stateTreeDepth": 10,
Expand Down Expand Up @@ -370,11 +415,20 @@
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "EASRegistryManager"
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0x4200000000000000000000000000000000000021"
Expand Down Expand Up @@ -445,9 +499,18 @@
"MACI": {
"stateTreeDepth": 14,
"gatekeeper": "FreeForAllGatekeeper",
"registryManager": "EASRegistryManager"
"registryManager": "RegistryManager",
"registry": "SimpleRegistry"
},
"RegistryManager": {},
"EASRegistryManager": {
"easAddress": "0x4200000000000000000000000000000000000021"
},
"SimpleRegistry": {
"maxRecipients": 25,
"metadataUrl": "url"
},
"EASRegistry": {
"maxRecipients": 25,
"metadataUrl": "url",
"easAddress": "0x4200000000000000000000000000000000000021"
Expand Down
23 changes: 12 additions & 11 deletions packages/contracts/tasks/deploy/poll/01-poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContractStorage, Deployment, EMode } from "maci-contracts";
import { PubKey } from "maci-domainobjs";

import { type Poll, type MACI } from "../../../typechain-types";
import { EContracts, EDeploySteps, REGISTRY_TYPES, TRegistryManager } from "../../helpers/constants";
import { EContracts, EDeploySteps, REGISTRY_TYPES, TRegistryManager, TRegistry } from "../../helpers/constants";

const deployment = Deployment.getInstance();
const storage = ContractStorage.getInstance();
Expand Down Expand Up @@ -52,20 +52,21 @@ deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) =>
deployment.getDeployConfigField<TRegistryManager | null>(EContracts.MACI, "registryManager") ||
EContracts.EASRegistryManager;
const registryManagerAddress = storage.getAddress(registryManagerType, hre.network.name);

const registryType =
deployment.getDeployConfigField<TRegistry | null>(EContracts.MACI, "registry") || EContracts.EASRegistry;

const maxRecipients = deployment.getDeployConfigField<number, keyof typeof EContracts>(
EContracts.EASRegistryManager,
registryType,
"maxRecipients",
);
const metadataUrl = deployment.getDeployConfigField<string, keyof typeof EContracts>(
EContracts.EASRegistryManager,
"metadataUrl",
);
const easAddress = deployment.getDeployConfigField<string, keyof typeof EContracts>(
EContracts.EASRegistryManager,
"easAddress",
);
const metadataUrl = deployment.getDeployConfigField<string, keyof typeof EContracts>(registryType, "metadataUrl");
const easAddress = deployment.getDeployConfigField<string, keyof typeof EContracts>(registryType, "easAddress");

const registryArgs = [maxRecipients, metadataUrl, easAddress, registryManagerAddress];
const registryArgs =
registryType === EContracts.EASRegistry
? [maxRecipients, metadataUrl, easAddress, registryManagerAddress]
: [maxRecipients, metadataUrl, registryManagerAddress];
const pollRegistry = await deployment.deployContract(
{ name: REGISTRY_TYPES[registryManagerType] },
...registryArgs,
Expand Down
7 changes: 5 additions & 2 deletions packages/contracts/tasks/helpers/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const EDeploySteps = {
*/
export enum EPlatformContracts {
EASRegistryManager = "EASRegistryManager",
RegistryManager = "RegistryManager",
EASRegistry = "EASRegistry",
SimpleRegistry = "SimpleRegistry",
}

/**
Expand All @@ -34,18 +36,19 @@ export const EContracts = {
/**
* Supported registry manager types
*/
export type TRegistryManager = EPlatformContracts.EASRegistryManager;
export type TRegistryManager = EPlatformContracts.EASRegistryManager | EPlatformContracts.RegistryManager;

/**
* Supported registry types
*/
export type TRegistry = EPlatformContracts.EASRegistry;
export type TRegistry = EPlatformContracts.EASRegistry | EPlatformContracts.SimpleRegistry;

/**
* Registry types by registry manager
*/
export const REGISTRY_TYPES: Record<TRegistryManager, TRegistry> = {
[EPlatformContracts.EASRegistryManager]: EPlatformContracts.EASRegistry,
[EPlatformContracts.RegistryManager]: EPlatformContracts.SimpleRegistry,
};

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"@hookform/resolvers": "^3.3.4",
"@nivo/line": "^0.84.0",
"@openzeppelin/merkle-tree": "^1.0.7",
"@pcd/eddsa-pcd": "^0.6.5",
"@pcd/pcd-types": "^0.11.4",
"@pcd/util": "^0.5.4",
"@pcd/zk-eddsa-event-ticket-pcd": "^0.6.6",
"@pcd/zuauth": "^1.4.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@rainbow-me/rainbowkit": "^2.0.1",
Expand All @@ -38,6 +43,7 @@
"dotenv": "^16.4.1",
"ethers": "^6.13.1",
"graphql-request": "^6.1.0",
"js-sha256": "^0.11.0",
"lowdb": "^1.0.0",
"lucide-react": "^0.316.0",
"maci-cli": "^2.4.0",
Expand Down
36 changes: 20 additions & 16 deletions packages/interface/src/components/BallotOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Link from "next/link";
import { useRouter } from "next/router";

import { Heading } from "~/components/ui/Heading";
import { useBallot } from "~/contexts/Ballot";
Expand All @@ -9,29 +8,34 @@ import { EAppState } from "~/utils/types";
import { AddedProjects } from "./AddedProjects";
import { VotingUsage } from "./VotingUsage";

export const BallotOverview = (): JSX.Element => {
interface IBallotOverviewProps {
title?: string;
}

export const BallotOverview = ({ title = undefined }: IBallotOverviewProps): JSX.Element => {
const { ballot } = useBallot();
const { asPath } = useRouter();

const appState = useAppState();

return (
<Link
href={
ballot.published && (appState === EAppState.TALLYING || appState === EAppState.RESULTS)
? "/ballot/confirmation"
: "/ballot"
}
>
<div className="dark:bg-lightBlack my-8 flex-col items-center gap-2 rounded-lg bg-white p-5 uppercase shadow-lg dark:text-white">
<Heading as="h3" size="3xl">
{asPath.includes("ballot") ? "Summary" : "My Ballot"}
</Heading>
<div className="w-full">
<Link
href={
ballot.published && (appState === EAppState.TALLYING || appState === EAppState.RESULTS)
? "/ballot/confirmation"
: "/ballot"
}
>
{title && (
<Heading as="h3" size="3xl">
{title}
</Heading>
)}

<AddedProjects />

<VotingUsage />
</div>
</Link>
</Link>
</div>
);
};
Loading

0 comments on commit 704dc44

Please sign in to comment.