Skip to content

Commit

Permalink
chore: build (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter authored Sep 9, 2024
1 parent 0cef59c commit 86c6a79
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 200 deletions.
15 changes: 8 additions & 7 deletions contracts/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 14 additions & 10 deletions contracts/hub/HubDomainsRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -27,22 +28,25 @@ 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));
_;
}

function registerDomain(
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");
Expand Down
42 changes: 2 additions & 40 deletions contracts/hub/HubRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@ 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";

/// @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;
Expand All @@ -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_) {}

Expand All @@ -60,7 +52,6 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea
address hubLogic,
address hubDomainsRegistry_,
address taskRegistry_,
address interactionRegistry_,
address globalParameters_,
address _membershipImplementation,
address _participationImplementation,
Expand All @@ -75,16 +66,13 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea
autId = autId_;
hubDomainsRegistry = hubDomainsRegistry_;
taskRegistry = taskRegistry_;
interactionRegistry = interactionRegistry_;
globalParameters = globalParameters_;
upgradeableBeacon = new UpgradeableBeacon(hubLogic, address(this));

membershipImplementation = _membershipImplementation;
participationImplementation = _participationImplementation;
taskFactoryImplementation = _taskFactoryImplementation;
taskManagerImplementation = _taskManagerImplementation;
// allowlist =
// IAllowlist(IModuleRegistry(IPluginRegistry(pluginRegistry_).modulesRegistry()).getAllowListAddress());
}

function currentPeriodId() public view returns (uint32) {
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 0 additions & 3 deletions contracts/hub/interfaces/IHubRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface IHubRegistry {
address hubLogic,
address hubDomainsRegistry_,
address taskRegistry_,
address interactionRegistry_,
address globalParameters_,
address _membershipImplementation,
address _participationImplementation,
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion contracts/old/modules/registry/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
75 changes: 14 additions & 61 deletions script/DeployAll.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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)));
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -224,7 +193,6 @@ function deployHubRegistry(
address _autIdAddress,
address _hubDomainsRegistryAddress,
address _taskRegistryAddress,
address _interactionRegistryAddress,
address _globalParametersAddress,
address _membershipImplementation,
address _participationImplementation,
Expand All @@ -243,7 +211,6 @@ function deployHubRegistry(
hubImplementation,
_hubDomainsRegistryAddress,
_taskRegistryAddress,
_interactionRegistryAddress,
_globalParametersAddress,
_membershipImplementation,
_participationImplementation,
Expand All @@ -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;
}
Loading

0 comments on commit 86c6a79

Please sign in to comment.