From 2aafd84fc2ede29402605c236082e71fee645995 Mon Sep 17 00:00:00 2001 From: yu-zhen Date: Thu, 19 Sep 2024 22:21:43 +0900 Subject: [PATCH] chore: add simple registry and move some arguments to registry config --- .../contracts/registry/SimpleRegistry.sol | 16 +++++++++++++ packages/contracts/deploy-config-example.json | 11 ++++++++- .../contracts/tasks/deploy/poll/01-poll.ts | 23 ++++++++++--------- .../tasks/helpers/constants/index.ts | 7 ++++-- 4 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 packages/contracts/contracts/registry/SimpleRegistry.sol diff --git a/packages/contracts/contracts/registry/SimpleRegistry.sol b/packages/contracts/contracts/registry/SimpleRegistry.sol new file mode 100644 index 00000000..11c443cb --- /dev/null +++ b/packages/contracts/contracts/registry/SimpleRegistry.sol @@ -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) {} +} diff --git a/packages/contracts/deploy-config-example.json b/packages/contracts/deploy-config-example.json index da4e8725..619e3772 100644 --- a/packages/contracts/deploy-config-example.json +++ b/packages/contracts/deploy-config-example.json @@ -445,9 +445,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" diff --git a/packages/contracts/tasks/deploy/poll/01-poll.ts b/packages/contracts/tasks/deploy/poll/01-poll.ts index 770d597f..8677b5a1 100644 --- a/packages/contracts/tasks/deploy/poll/01-poll.ts +++ b/packages/contracts/tasks/deploy/poll/01-poll.ts @@ -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(); @@ -52,20 +52,21 @@ deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) => deployment.getDeployConfigField(EContracts.MACI, "registryManager") || EContracts.EASRegistryManager; const registryManagerAddress = storage.getAddress(registryManagerType, hre.network.name); + + const registryType = + deployment.getDeployConfigField(EContracts.MACI, "registry") || EContracts.EASRegistry; + const maxRecipients = deployment.getDeployConfigField( - EContracts.EASRegistryManager, + registryType, "maxRecipients", ); - const metadataUrl = deployment.getDeployConfigField( - EContracts.EASRegistryManager, - "metadataUrl", - ); - const easAddress = deployment.getDeployConfigField( - EContracts.EASRegistryManager, - "easAddress", - ); + const metadataUrl = deployment.getDeployConfigField(registryType, "metadataUrl"); + const easAddress = deployment.getDeployConfigField(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, diff --git a/packages/contracts/tasks/helpers/constants/index.ts b/packages/contracts/tasks/helpers/constants/index.ts index ad14b968..11fe988b 100644 --- a/packages/contracts/tasks/helpers/constants/index.ts +++ b/packages/contracts/tasks/helpers/constants/index.ts @@ -20,7 +20,9 @@ export const EDeploySteps = { */ export enum EPlatformContracts { EASRegistryManager = "EASRegistryManager", + RegistryManager = "RegistryManager", EASRegistry = "EASRegistry", + SimpleRegistry = "SimpleRegistry", } /** @@ -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 = { [EPlatformContracts.EASRegistryManager]: EPlatformContracts.EASRegistry, + [EPlatformContracts.RegistryManager]: EPlatformContracts.SimpleRegistry, }; /**