From 86c6a7990fbdea6e84e274022ff446693701fa47 Mon Sep 17 00:00:00 2001 From: Carter Carlson Date: Mon, 9 Sep 2024 11:45:32 -0700 Subject: [PATCH] chore: build (#111) --- contracts/hub/Hub.sol | 15 ++-- contracts/hub/HubDomainsRegistry.sol | 24 +++--- contracts/hub/HubRegistry.sol | 42 +---------- contracts/hub/interfaces/IHubRegistry.sol | 3 - .../old/modules/registry/ModuleRegistry.sol | 2 +- script/DeployAll.s.sol | 75 ++++--------------- script/deploy/DeployAllowlist.s.sol | 33 -------- .../DeploySimpleOnboardingAllowlist.sol | 40 ---------- test/BaseTest.sol | 5 -- 9 files changed, 39 insertions(+), 200 deletions(-) delete mode 100644 script/deploy/DeployAllowlist.s.sol delete mode 100644 script/deploy/DeploySimpleOnboardingAllowlist.sol diff --git a/contracts/hub/Hub.sol b/contracts/hub/Hub.sol index f6d878c2..92cc1d60 100644 --- a/contracts/hub/Hub.sol +++ b/contracts/hub/Hub.sol @@ -7,7 +7,7 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet import {TimeLibrary} from "../libraries/TimeLibrary.sol"; import {IGlobalParameters} from "../globalParameters/IGlobalParameters.sol"; import {IMembership} from "../membership/IMembership.sol"; -import {OnboardingModule} from "../modules/onboarding/OnboardingModule.sol"; +// import {OnboardingModule} from "../modules/onboarding/OnboardingModule.sol"; import {HubUtils} from "./HubUtils.sol"; import {IHub} from "./interfaces/IHub.sol"; import {ITaskManager} from "../tasks/interfaces/ITaskManager.sol"; @@ -196,12 +196,13 @@ contract Hub is IHub, HubUtils, OwnableUpgradeable, HubUpgradeable { return false; } - if (onboarding != address(0)) { - if (OnboardingModule(onboarding).isActive()) { - return OnboardingModule(onboarding).isOnboarded(who, role); - } - return false; - } + // TODO: onboarding module + // if (onboarding != address(0)) { + // if (OnboardingModule(onboarding).isActive()) { + // return OnboardingModule(onboarding).isOnboarded(who, role); + // } + // return false; + // } return true; } diff --git a/contracts/hub/HubDomainsRegistry.sol b/contracts/hub/HubDomainsRegistry.sol index 2bae6c79..8e3c34e9 100644 --- a/contracts/hub/HubDomainsRegistry.sol +++ b/contracts/hub/HubDomainsRegistry.sol @@ -2,10 +2,11 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; +import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "./interfaces/IHubDomainsRegistry.sol"; +import "./interfaces/IHubRegistry.sol"; -contract HubDomainsRegistry is IHubDomainsRegistry, Ownable { +contract HubDomainsRegistry is IHubDomainsRegistry, OwnableUpgradeable { struct Domain { string name; address hubAddress; @@ -17,7 +18,7 @@ contract HubDomainsRegistry is IHubDomainsRegistry, Ownable { mapping(address => string[]) private hubAddressToDomains; mapping(uint256 => string) private tokenIdToDomain; uint256 private tokenIdCounter; - address private permittedContract; + address private hubRegistry; event DomainRegistered( address indexed hubAddress, @@ -27,14 +28,17 @@ contract HubDomainsRegistry is IHubDomainsRegistry, Ownable { string metadataUri ); - constructor(address _permittedContract) Ownable(msg.sender) { - require(_permittedContract != address(0), "Permitted contract address cannot be zero"); - tokenIdCounter = 0; - permittedContract = _permittedContract; + constructor() { + _disableInitializers(); } - modifier onlyPermittedContract() { - require(msg.sender == permittedContract, "Caller is not the permitted contract"); + function initialize(address _hubRegistry) external initializer { + __Ownable_init(msg.sender); + hubRegistry = _hubRegistry; + } + + modifier onlyFromHub() { + require(IHubRegistry(hubRegistry).checkHub(msg.sender)); _; } @@ -42,7 +46,7 @@ contract HubDomainsRegistry is IHubDomainsRegistry, Ownable { string calldata domain, address hubAddress, string calldata metadataUri - ) external override(IHubDomainsRegistry) onlyPermittedContract { + ) external override(IHubDomainsRegistry) onlyFromHub { require(domains[domain].hubAddress == address(0), "Domain already registered"); require(hubAddressToDomains[hubAddress].length == 0, "Domain already registered"); require(_isValidDomain(domain), "Invalid domain format"); diff --git a/contracts/hub/HubRegistry.sol b/contracts/hub/HubRegistry.sol index b1eb0d40..73675c4d 100644 --- a/contracts/hub/HubRegistry.sol +++ b/contracts/hub/HubRegistry.sol @@ -10,11 +10,8 @@ import { ContextUpgradeable } from "@openzeppelin/contracts-upgradeable/metatx/ERC2771ContextUpgradeable.sol"; -import {IModuleRegistry} from "../modules/registry/IModuleRegistry.sol"; import {IHubRegistry} from "./interfaces/IHubRegistry.sol"; -import {IInteractionRegistry} from "../interactions/InteractionRegistry.sol"; import {IGlobalParameters} from "../globalParameters/IGlobalParameters.sol"; -import {IAllowlist} from "../utils/IAllowlist.sol"; import {IHub} from "./interfaces/IHub.sol"; import {IHubModule} from "./interfaces/IHubModule.sol"; @@ -22,10 +19,7 @@ import {IHubModule} from "./interfaces/IHubModule.sol"; /// @title HubRegistry contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradeable { event HubCreated(address deployer, address hubAddress, uint256 market, uint256 commitment, string metadata); - event AllowlistSet(address allowlist); - // just for interface compatibility - // actually there is no need to store it in the contract mapping(address => address[]) public hubDeployers; mapping(address => address[]) internal _userHubList; mapping(address => mapping(address => uint256)) internal _userHubListIds; @@ -44,14 +38,12 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea address public autId; address public hubDomainsRegistry; address public taskRegistry; - address public interactionRegistry; address public globalParameters; address public membershipImplementation; address public participationImplementation; address public taskFactoryImplementation; address public taskManagerImplementation; UpgradeableBeacon public upgradeableBeacon; - IAllowlist public allowlist; constructor(address trustedForwarder_) ERC2771ContextUpgradeable(trustedForwarder_) {} @@ -60,7 +52,6 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea address hubLogic, address hubDomainsRegistry_, address taskRegistry_, - address interactionRegistry_, address globalParameters_, address _membershipImplementation, address _participationImplementation, @@ -75,7 +66,6 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea autId = autId_; hubDomainsRegistry = hubDomainsRegistry_; taskRegistry = taskRegistry_; - interactionRegistry = interactionRegistry_; globalParameters = globalParameters_; upgradeableBeacon = new UpgradeableBeacon(hubLogic, address(this)); @@ -83,8 +73,6 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea participationImplementation = _participationImplementation; taskFactoryImplementation = _taskFactoryImplementation; taskManagerImplementation = _taskManagerImplementation; - // allowlist = - // IAllowlist(IModuleRegistry(IPluginRegistry(pluginRegistry_).modulesRegistry()).getAllowListAddress()); } function currentPeriodId() public view returns (uint32) { @@ -95,10 +83,6 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea return IGlobalParameters(globalParameters).period0Start(); } - function isInteractionId(bytes32 interactionId) external view returns (bool) { - return IInteractionRegistry(interactionRegistry).isInteractionId(interactionId); - } - // the only reason for this function is to keep interface compatible with sdk // `hubs` variable is public anyway // the only reason for `hubs` variable is that TheGraph is not connected @@ -185,34 +169,12 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea upgradeableBeacon.upgradeTo(newLogic); } - /// @dev sets a new allowlist - function setAllowlistAddress(address newAllowlist) external onlyOwner { - // inactive, if set to `address(0)` - allowlist = IAllowlist(newAllowlist); - - emit AllowlistSet(newAllowlist); - } - - /// @dev transfer beacon ownership (hopefuly to a new and better-implemented registry) - function tranferBeaconOwnership(address newOwner) external onlyOwner { + /// @dev transfer beacon ownership + function transferBeaconOwnership(address newOwner) external onlyOwner { require(newOwner != address(0), "HubRegistry: address zero"); upgradeableBeacon.transferOwnership(newOwner); } - function _checkAllowlist() internal view { - if (_msgSender() == deployerAddress || _msgSender() == upgradeableBeacon.owner()) return; - if (address(allowlist) != address(0)) { - // if (!allowlist.isAllowed(_msgSender())) { - // revert IAllowlist.Unallowed(); - // } - if ((hubDeployers[_msgSender()].length != 0)) { - revert IAllowlist.AlreadyDeployedAHub(); - // `hubDeployers` state is not stored within allowlist, - // although the error belongs to allowlist - } - } - } - function _validateHubDeploymentParams(uint256 market, string memory metadata, uint256 commitment) internal pure { require(market > 0 && market < 6, "HubRegistry: invalid market value"); require(bytes(metadata).length != 0, "HubRegistry: metadata empty"); diff --git a/contracts/hub/interfaces/IHubRegistry.sol b/contracts/hub/interfaces/IHubRegistry.sol index 9fde0493..df643550 100644 --- a/contracts/hub/interfaces/IHubRegistry.sol +++ b/contracts/hub/interfaces/IHubRegistry.sol @@ -7,7 +7,6 @@ interface IHubRegistry { address hubLogic, address hubDomainsRegistry_, address taskRegistry_, - address interactionRegistry_, address globalParameters_, address _membershipImplementation, address _participationImplementation, @@ -22,6 +21,4 @@ interface IHubRegistry { function join(address hub, address member, uint256 role, uint8 commitment) external; function listUserHubs(address user) external view returns (address[] memory); - - function setAllowlistAddress(address) external; } diff --git a/contracts/old/modules/registry/ModuleRegistry.sol b/contracts/old/modules/registry/ModuleRegistry.sol index 6983ae41..36914f08 100644 --- a/contracts/old/modules/registry/ModuleRegistry.sol +++ b/contracts/old/modules/registry/ModuleRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.20; import "./IModuleRegistry.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; -import {IAllowlist} from "../../utils/IAllowlist.sol"; +import {IAllowlist} from "../../IAllowlist.sol"; contract ModuleRegistry is IModuleRegistry, Ownable { ModuleDefinition[] public modules; diff --git a/script/DeployAll.s.sol b/script/DeployAll.s.sol index 0301a4ef..5ed857fc 100644 --- a/script/DeployAll.s.sol +++ b/script/DeployAll.s.sol @@ -4,17 +4,11 @@ pragma solidity ^0.8.20; import {IHub} from "../contracts/hub/interfaces/IHub.sol"; import {IAutID} from "../contracts/autid/IAutID.sol"; import {IHubRegistry} from "../contracts/hub/interfaces/IHubRegistry.sol"; -import {IAllowlist} from "../contracts/utils/IAllowlist.sol"; import {IGlobalParameters} from "../contracts/globalParameters/IGlobalParameters.sol"; -import {SimpleAllowlistOnboarding} from "../contracts/onboarding/SimpleAllowlistOnboarding.sol"; -import {BasicOnboarding} from "../contracts/onboarding/BasicOnboarding.sol"; import {Hub} from "../contracts/hub/Hub.sol"; import {AutID} from "../contracts/autid/AutID.sol"; import {HubRegistry} from "../contracts/hub/HubRegistry.sol"; -import {InteractionRegistry} from "../contracts/interactions/InteractionRegistry.sol"; -import {Allowlist} from "../contracts/utils/Allowlist.sol"; import {GlobalParameters} from "../contracts/globalParameters/GlobalParameters.sol"; -import {PluginRegistry} from "../contracts/pluginRegistry/PluginRegistry.sol"; import {HubDomainsRegistry} from "../contracts/hub/HubDomainsRegistry.sol"; import {AutProxy} from "../contracts/proxy/AutProxy.sol"; import {TrustedForwarder} from "../contracts/mocks/TrustedForwarder.sol"; @@ -39,13 +33,10 @@ contract DeployAll is Script { address taskManagerImplementation; AutID public autId; - PluginRegistry pluginRegistry; HubRegistry public hubRegistry; HubDomainsRegistry public hubDomainsRegistry; TaskRegistry public taskRegistry; - InteractionRegistry public interactionRegistry; GlobalParameters public globalParameters; - BasicOnboarding public basicOnboarding; struct TNamedAddress { address target; @@ -79,10 +70,8 @@ contract DeployAll is Script { // Deploy AutID autId = deployAutId(trustedForwarder, vm.addr(privateKey)); - pluginRegistry = deployPluginRegistry(owner); hubDomainsRegistry = deployHubDomainsRegistry(owner); taskRegistry = deployTaskRegistry(owner); - interactionRegistry = deployInteractionRegistry(owner); globalParameters = deployGlobalParameters(owner); ( membershipImplementation, @@ -96,22 +85,19 @@ contract DeployAll is Script { _autIdAddress: address(autId), _hubDomainsRegistryAddress: address(hubDomainsRegistry), _taskRegistryAddress: address(taskRegistry), - _interactionRegistryAddress: address(interactionRegistry), _globalParametersAddress: address(globalParameters), _membershipImplementation: membershipImplementation, _participationImplementation: participationImplementation, _taskFactoryImplementation: taskFactoryImplementation, _taskManagerImplementation: taskManagerImplementation }); - basicOnboarding = deployBasicOnboarding(owner); // set hubRegistry to autId and transfer ownership autId.setHubRegistry(address(hubRegistry)); autId.transferOwnership(owner); - // Create and set the allowlist - Allowlist allowlist = new Allowlist(); - hubRegistry.setAllowlistAddress(address(allowlist)); + // init hubDomainsRegistry now that hubRegistry is deployed + hubDomainsRegistry.initialize(address(hubRegistry)); // Setup initial tasks Task[] memory tasks = new Task[](3); @@ -129,15 +115,12 @@ contract DeployAll is Script { // todo: convert to helper function if (deploying) { string memory filename = "deployments.txt"; - TNamedAddress[8] memory na; + TNamedAddress[5] memory na; na[0] = TNamedAddress({name: "globalParametersProxy", target: address(globalParameters)}); na[1] = TNamedAddress({name: "autIDProxy", target: address(autId)}); na[2] = TNamedAddress({name: "hubRegistryProxy", target: address(hubRegistry)}); - na[3] = TNamedAddress({name: "pluginRegistryProxy", target: address(pluginRegistry)}); - na[4] = TNamedAddress({name: "allowlist", target: address(allowlist)}); - na[5] = TNamedAddress({name: "basicOnboarding", target: address(basicOnboarding)}); - na[6] = TNamedAddress({name: "hubDomainsRegistry", target: address(hubDomainsRegistry)}); - na[7] = TNamedAddress({name: "taskRegistry", target: address(taskRegistry)}); + na[3] = TNamedAddress({name: "hubDomainsRegistry", target: address(hubDomainsRegistry)}); + na[4] = TNamedAddress({name: "taskRegistry", target: address(taskRegistry)}); vm.writeLine(filename, string.concat(vm.toString(block.chainid), " ", vm.toString(block.timestamp))); for (uint256 i = 0; i != na.length; ++i) { vm.writeLine(filename, string.concat(vm.toString(i), ". ", na[i].name, ": ", vm.toString(na[i].target))); @@ -148,9 +131,9 @@ contract DeployAll is Script { } function deployAutId(address _trustedForwarder, address _owner) returns (AutID) { - AutID autIdImplementation = new AutID(_trustedForwarder); + address autIdImplementation = address(new AutID(_trustedForwarder)); AutProxy autIdProxy = new AutProxy( - address(autIdImplementation), + autIdImplementation, _owner, abi.encodeWithSelector( AutID.initialize.selector, @@ -160,25 +143,16 @@ function deployAutId(address _trustedForwarder, address _owner) returns (AutID) return AutID(address(autIdProxy)); } -function deployPluginRegistry(address _owner) returns (PluginRegistry) { - PluginRegistry pluginRegistryImplementation = new PluginRegistry(); - AutProxy pluginRegistryProxy = new AutProxy( - address(pluginRegistryImplementation), - _owner, - abi.encodeWithSelector( - PluginRegistry.initialize.selector, - _owner - ) - ); - return PluginRegistry(address(pluginRegistryProxy)); -} - function deployHubDomainsRegistry( address _owner ) returns (HubDomainsRegistry) { - // address hubDomainsRegistry = address(new HubDomainsRegistry(hubImpl)); - HubDomainsRegistry hubDomainsRegistry = new HubDomainsRegistry(_owner); - return hubDomainsRegistry; + address hubDomainsRegistryImplementation = address(new HubDomainsRegistry()); + AutProxy hubDomainsRegistryProxy = new AutProxy( + hubDomainsRegistryImplementation, + _owner, + "" + ); + return HubDomainsRegistry(address(hubDomainsRegistryProxy)); } function deployTaskRegistry(address _owner) returns (TaskRegistry) { @@ -191,11 +165,6 @@ function deployTaskRegistry(address _owner) returns (TaskRegistry) { return TaskRegistry(address(taskRegistryProxy)); } -function deployInteractionRegistry(address _owner) returns (InteractionRegistry) { - InteractionRegistry interactionRegistry = new InteractionRegistry(_owner); - return interactionRegistry; -} - function deployGlobalParameters(address _owner) returns (GlobalParameters) { address globalParametersImplementation = address(new GlobalParameters()); AutProxy globalParametersProxy = new AutProxy( @@ -224,7 +193,6 @@ function deployHubRegistry( address _autIdAddress, address _hubDomainsRegistryAddress, address _taskRegistryAddress, - address _interactionRegistryAddress, address _globalParametersAddress, address _membershipImplementation, address _participationImplementation, @@ -243,7 +211,6 @@ function deployHubRegistry( hubImplementation, _hubDomainsRegistryAddress, _taskRegistryAddress, - _interactionRegistryAddress, _globalParametersAddress, _membershipImplementation, _participationImplementation, @@ -253,18 +220,4 @@ function deployHubRegistry( ) ); return HubRegistry(address(hubRegistryProxy)); -} - -function deployBasicOnboarding(address _owner) returns (BasicOnboarding) { - address onboardingRole1 = address(new SimpleAllowlistOnboarding(_owner)); - address onboardingRole2 = address(new SimpleAllowlistOnboarding(_owner)); - address onboardingRole3 = address(new SimpleAllowlistOnboarding(_owner)); - - address[] memory addresses = new address[](3); - addresses[0] = onboardingRole1; - addresses[1] = onboardingRole2; - addresses[2] = onboardingRole3; - BasicOnboarding basicOnboarding = new BasicOnboarding(addresses); - - return basicOnboarding; } \ No newline at end of file diff --git a/script/deploy/DeployAllowlist.s.sol b/script/deploy/DeployAllowlist.s.sol deleted file mode 100644 index d12a8517..00000000 --- a/script/deploy/DeployAllowlist.s.sol +++ /dev/null @@ -1,33 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import {IAllowlist} from "../../contracts/utils/IAllowlist.sol"; -import {IHubRegistry} from "../../contracts/hub/interfaces/IHubRegistry.sol"; - -import {Allowlist} from "../../contracts/utils/Allowlist.sol"; - -import "forge-std/Script.sol"; - -contract DeployAllowlist is Script { - address public owner; - - function setUp() public { - if (block.chainid == 31337) { - // todo: replace 31337 by forge constant - owner = vm.envAddress("A1"); - } else if (block.chainid == 80001) { - owner = 0x5D45D9C907B26EdE7848Bb9BdD4D08308983d613; - } else { - revert("invalid chainid"); - } - console.log("setUp -- done"); - } - - function run() public { - vm.startBroadcast(vm.envUint("PVK_A1")); - - address allowlistImpl = address(new Allowlist()); - IHubRegistry hubRegistry = IHubRegistry(0x3d299cA87A62bd0fB005e6e7b081e794c15456DA); - hubRegistry.setAllowlistAddress(allowlistImpl); - } -} diff --git a/script/deploy/DeploySimpleOnboardingAllowlist.sol b/script/deploy/DeploySimpleOnboardingAllowlist.sol deleted file mode 100644 index 8a7465e5..00000000 --- a/script/deploy/DeploySimpleOnboardingAllowlist.sol +++ /dev/null @@ -1,40 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import {IAllowlist} from "../../contracts/utils/IAllowlist.sol"; -import {IHubRegistry} from "../../contracts/hub/interfaces/IHubRegistry.sol"; - -import {SimpleAllowlistOnboarding} from "../../contracts/onboarding/SimpleAllowlistOnboarding.sol"; -import {BasicOnboarding} from "../../contracts/onboarding/BasicOnboarding.sol"; - -import "forge-std/Script.sol"; - -contract DeploySimpleAllowlistOnboarding is Script { - address public owner; - - function setUp() public { - if (block.chainid == 31337) { - // todo: replace 31337 by forge constant - owner = vm.envAddress("A1"); - } else if (block.chainid == 80001) { - owner = 0x5D45D9C907B26EdE7848Bb9BdD4D08308983d613; - } else { - revert("invalid chainid"); - } - console.log("setUp -- done"); - } - - function run() public { - vm.startBroadcast(vm.envUint("PVK_A1")); - - address onboardingRole1 = address(new SimpleAllowlistOnboarding(owner)); - address onboardingRole2 = address(new SimpleAllowlistOnboarding(owner)); - address onboardingRole3 = address(new SimpleAllowlistOnboarding(owner)); - - address[] memory addresses = new address[](3); - addresses[0] = onboardingRole1; - addresses[1] = onboardingRole2; - addresses[2] = onboardingRole3; - address basicOnboarding = address(new BasicOnboarding(addresses)); - } -} diff --git a/test/BaseTest.sol b/test/BaseTest.sol index cf5f3cbb..1de64f18 100644 --- a/test/BaseTest.sol +++ b/test/BaseTest.sol @@ -9,8 +9,6 @@ abstract contract BaseTest is Test { HubRegistry public hubRegistry; GlobalParameters public globalParameters; HubDomainsRegistry public hubDomainsRegistry; - InteractionRegistry public interactionRegistry; - BasicOnboarding public basicOnboarding; address public owner = address(this); address public alice = address(0x411Ce); @@ -27,8 +25,6 @@ abstract contract BaseTest is Test { hubRegistry = deploy.hubRegistry(); globalParameters = deploy.globalParameters(); hubDomainsRegistry = deploy.hubDomainsRegistry(); - interactionRegistry = deploy.interactionRegistry(); - basicOnboarding = deploy.basicOnboarding(); // labeling vm.label(owner, "Owner"); @@ -38,6 +34,5 @@ abstract contract BaseTest is Test { vm.label(address(hubRegistry), "hubRegistry"); vm.label(address(globalParameters), "globalParameters"); vm.label(address(hubDomainsRegistry), "hubDomainsRegistry"); - vm.label(address(basicOnboarding), "basicOnboarding"); } } \ No newline at end of file