diff --git a/contracts/lib/worker/PropertyFacet.sol b/contracts/lib/worker/PropertyFacet.sol new file mode 100644 index 0000000..f4a11ff --- /dev/null +++ b/contracts/lib/worker/PropertyFacet.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +library LibProperty { + struct Property { + string name; + uint256 propertyType; // 0 = Residential, 1 = Commercial + uint256 workerPoolBalance; // Funds allocated to workers + address owner; + } + + struct PropertyStorage { + mapping(uint256 => Property) properties; + uint256 propertyCounter; + } + + bytes32 constant STORAGE_POSITION = keccak256("gizaprotocol.property.storage"); + + function propertyStorage() internal pure returns (PropertyStorage storage ps) { + bytes32 position = STORAGE_POSITION; + assembly { + ps.slot := position + } + } +} + +contract PropertyFacet { + event PropertyAdded(uint256 indexed propertyId, string name, uint256 propertyType, address owner); + + function addProperty( + string memory _name, + uint256 _propertyType, + address _owner + ) external { + LibProperty.PropertyStorage storage ps = LibProperty.propertyStorage(); + ps.properties[ps.propertyCounter] = LibProperty.Property({ + name: _name, + propertyType: _propertyType, + workerPoolBalance: 0, + owner: _owner + }); + emit PropertyAdded(ps.propertyCounter, _name, _propertyType, _owner); + ps.propertyCounter++; + } + + function getProperty(uint256 propertyId) external view returns (LibProperty.Property memory) { + LibProperty.PropertyStorage storage ps = LibProperty.propertyStorage(); + return ps.properties[propertyId]; + } +} diff --git a/contracts/lib/worker/WorkerFacet.sol b/contracts/lib/worker/WorkerFacet.sol new file mode 100644 index 0000000..3215aa9 --- /dev/null +++ b/contracts/lib/worker/WorkerFacet.sol @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +library LibWorker { + struct Worker { + address wallet; + uint256 contributionShare; // Share of the total contribution + bool isRegistered; + } + + struct WorkerStorage { + mapping(address => Worker) workers; + address[] workerAddresses; + } + + bytes32 constant STORAGE_POSITION = keccak256("gizaprotocol.worker.storage"); + + function workerStorage() internal pure returns (WorkerStorage storage ws) { + bytes32 position = STORAGE_POSITION; + assembly { + ws.slot := position + } + } +} + +contract WorkerFacet { + event WorkerRegistered(address indexed worker, uint256 contributionShare); + + function registerWorker(address _worker, uint256 _contributionShare) external { + LibWorker.WorkerStorage storage ws = LibWorker.workerStorage(); + require(!ws.workers[_worker].isRegistered, "Worker already registered"); + + ws.workers[_worker] = LibWorker.Worker({ + wallet: _worker, + contributionShare: _contributionShare, + isRegistered: true + }); + ws.workerAddresses.push(_worker); + + emit WorkerRegistered(_worker, _contributionShare); + } + + function getWorker(address _worker) external view returns (LibWorker.Worker memory) { + LibWorker.WorkerStorage storage ws = LibWorker.workerStorage(); + return ws.workers[_worker]; + } + + function getAllWorkers() external view returns (address[] memory) { + LibWorker.WorkerStorage storage ws = LibWorker.workerStorage(); + return ws.workerAddresses; + } +}