Skip to content

Commit

Permalink
feat: initialContributionManager (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter authored Oct 11, 2024
1 parent 0aecd13 commit d57abda
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions contracts/hub/HubRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {

import {IHubRegistry} from "./interfaces/IHubRegistry.sol";
import {IGlobalParameters} from "../globalParameters/IGlobalParameters.sol";
import {ITaskManager} from "../tasks/interfaces/ITaskManager.sol";

import {IHub} from "./interfaces/IHub.sol";
import {IHubModule} from "./interfaces/IHubModule.sol";
Expand Down Expand Up @@ -39,6 +40,7 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea
address public hubDomainsRegistry;
address public taskRegistry;
address public globalParameters;
address public initialContributionManager;
address public membershipImplementation;
address public participationImplementation;
address public taskFactoryImplementation;
Expand All @@ -53,6 +55,7 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea
address hubDomainsRegistry_,
address taskRegistry_,
address globalParameters_,
address _initialContributionManager,
address _membershipImplementation,
address _participationImplementation,
address _taskFactoryImplementation,
Expand All @@ -69,12 +72,18 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea
globalParameters = globalParameters_;
upgradeableBeacon = new UpgradeableBeacon(hubLogic, address(this));

setInitialContributionManager(_initialContributionManager);

membershipImplementation = _membershipImplementation;
participationImplementation = _participationImplementation;
taskFactoryImplementation = _taskFactoryImplementation;
taskManagerImplementation = _taskManagerImplementation;
}

function setInitialContributionManager(address _initialContributionManager) public onlyOwner {
initialContributionManager = _initialContributionManager;
}

function currentPeriodId() public view returns (uint32) {
return IGlobalParameters(globalParameters).currentPeriodId();
}
Expand Down Expand Up @@ -135,6 +144,9 @@ contract HubRegistry is IHubRegistry, ERC2771ContextUpgradeable, OwnableUpgradea
_membership: membership
});

// Set the initial contribution manager as stored in this contract
ITaskManager(taskManager).initialize2(initialContributionManager);

hubDeployers[_msgSender()].push(hub);
hubs.push(hub);
checkHub[hub] = true;
Expand Down
1 change: 1 addition & 0 deletions contracts/hub/interfaces/IHubRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IHubRegistry {
address hubDomainsRegistry_,
address taskRegistry_,
address globalParameters_,
address _initialContributionManager,
address _membershipImplementation,
address _participationImplementation,
address _taskFactoryImplementation,
Expand Down
2 changes: 1 addition & 1 deletion contracts/tasks/TaskFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract TaskFactory is ITaskFactory, Initializable, PeriodUtils, AccessUtils {
function registerDescriptions(Description[] calldata descriptions) external returns (bytes32[] memory) {
uint256 length = descriptions.length;
bytes32[] memory newDescriptionIds = new bytes32[](length);
for (uint256 i=0; i < length; i++) {
for (uint256 i = 0; i < length; i++) {
newDescriptionIds[i] = _registerDescription(descriptions[i]);
}

Expand Down
10 changes: 9 additions & 1 deletion contracts/tasks/TaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,20 @@ contract TaskManager is ITaskManager, Initializable, PeriodUtils, AccessUtils {
_init_PeriodUtils({_period0Start: _period0Start, _initPeriodId: _initPeriodId});
}

/// @dev set the initial contribution manager from the hub registry
function initialize2(address initialContributionManager) external reinitializer(2) {
_addContributionManager(initialContributionManager);
}

// ContributionManager-management

function addContributionManager(address who) external {
_revertIfNotAdmin();
if (!_contributionManagers.add(who)) revert AlreadyContributionManager();
_addContributionManager(who);
}

function _addContributionManager(address who) internal {
if (!_contributionManagers.add(who)) revert AlreadyContributionManager();
emit AddContributionManager(who);
}

Expand Down
3 changes: 3 additions & 0 deletions contracts/tasks/interfaces/ITaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ interface ITaskManager {
bytes encodedContributionStatus
);

/// @notice Set the initial contribution manager from the hub registry
function initialize2(address _initialContributionManager) external;

/// @notice Get the amount of outstanding contribution points for the current period
function pointsActive() external view returns (uint128);

Expand Down
7 changes: 7 additions & 0 deletions script/DeployAll.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import "forge-std/Script.sol";

contract DeployAll is Script {
address public owner;
address public initialContributionManager;
uint256 public privateKey;
bool public deploying;

Expand Down Expand Up @@ -50,13 +51,16 @@ contract DeployAll is Script {
function setUp() public {
if (block.chainid == 137) {
owner = vm.envAddress("MAINNET_OWNER_ADDRESS");
initialContributionManager = vm.envAddress("MAINNET_INITIAL_CONTRIBUTION_MANAGER");
privateKey = vm.envUint("MAINNET_PRIVATE_KEY");
} else if (block.chainid == 80002) {
owner = vm.envAddress("TESTNET_OWNER_ADDRESS");
initialContributionManager = vm.envAddress("TESTNET_INITIAL_CONTRIBUTION_MANAGER");
privateKey = vm.envUint("TESTNET_PRIVATE_KEY");
} else {
// testing
owner = address(123456);
initialContributionManager = address(11111111);
privateKey = 567890;
}
console.log("setUp -- done");
Expand Down Expand Up @@ -86,6 +90,7 @@ contract DeployAll is Script {
_hubDomainsRegistryAddress: address(hubDomainsRegistry),
_taskRegistryAddress: address(taskRegistry),
_globalParametersAddress: address(globalParameters),
_initialContributionManager: initialContributionManager,
_membershipImplementation: membershipImplementation,
_participationImplementation: participationImplementation,
_taskFactoryImplementation: taskFactoryImplementation,
Expand Down Expand Up @@ -205,6 +210,7 @@ function deployHubRegistry(
address _hubDomainsRegistryAddress,
address _taskRegistryAddress,
address _globalParametersAddress,
address _initialContributionManager,
address _membershipImplementation,
address _participationImplementation,
address _taskFactoryImplementation,
Expand All @@ -223,6 +229,7 @@ function deployHubRegistry(
_hubDomainsRegistryAddress,
_taskRegistryAddress,
_globalParametersAddress,
_initialContributionManager,
_membershipImplementation,
_participationImplementation,
_taskFactoryImplementation,
Expand Down

0 comments on commit d57abda

Please sign in to comment.