From 403e2292e53d642277892e8824b1b6dfba44e835 Mon Sep 17 00:00:00 2001 From: sourcekeeper_42 Date: Sun, 19 Apr 2026 09:08:02 +0000 Subject: [PATCH] Initial community governance contract implementation --- contracts/LabHelper.sol | 95 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 contracts/LabHelper.sol diff --git a/contracts/LabHelper.sol b/contracts/LabHelper.sol new file mode 100644 index 000000000..cc73d419a --- /dev/null +++ b/contracts/LabHelper.sol @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import "./interfaces/ILabRegistry.sol"; + +library LabHelper { + struct LabMetadata { + address owner; + uint256 createdAt; + uint256 lastUpdated; + uint256 totalContributions; + bool isActive; + } + + struct ContributionRecord { + address contributor; + uint256 amount; + uint256 timestamp; + string contributionType; + } + + error InsufficientContribution(uint256 minimum, uint256 provided); + error InvalidLabConfiguration(string reason); + error UnauthorizedAccess(address caller); + + uint256 private constant MINIMUM_CONTRIBUTION = 0.01 ether; + uint256 private constant MAX_CONTRIBUTION_RECORDS = 10; + + function validateLabCreation( + address _owner, + uint256 _initialFunds + ) internal pure returns (bool) { + if (_owner == address(0)) { + revert InvalidLabConfiguration("Invalid owner address"); + } + + if (_initialFunds < MINIMUM_CONTRIBUTION) { + revert InsufficientContribution(MINIMUM_CONTRIBUTION, _initialFunds); + } + + return true; + } + + function calculateContributionScore( + ContributionRecord[] memory _records + ) internal pure returns (uint256 totalScore) { + for (uint256 i = 0; i < _records.length; i++) { + uint256 scoreMultiplier = _getContributionTypeMultiplier( + _records[i].contributionType + ); + + totalScore += _records[i].amount * scoreMultiplier; + } + } + + function _getContributionTypeMultiplier( + string memory _type + ) private pure returns (uint256) { + bytes32 typeHash = keccak256(abi.encodePacked(_type)); + + if (typeHash == keccak256("code")) return 3; + if (typeHash == keccak256("research")) return 2; + if (typeHash == keccak256("documentation")) return 1; + + return 0; + } + + function validateContributor( + address _contributor, + ILabRegistry _registry + ) internal view returns (bool) { + if (_contributor == address(0)) { + return false; + } + + // Check against external registry + try _registry.isValidContributor(_contributor) returns (bool result) { + return result; + } catch { + return false; + } + } + + function generateLabMetadata( + address _owner + ) internal view returns (LabMetadata memory) { + return LabMetadata({ + owner: _owner, + createdAt: block.timestamp, + lastUpdated: block.timestamp, + totalContributions: 0, + isActive: true + }); + } +} \ No newline at end of file