// 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 }); } }