Skip to content

Commit

Permalink
Check in diamond facet contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
10dimensions committed Nov 21, 2024
1 parent ef13887 commit 2b00ac3
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
50 changes: 50 additions & 0 deletions contracts/lib/worker/PropertyFacet.sol
Original file line number Diff line number Diff line change
@@ -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];
}
}
52 changes: 52 additions & 0 deletions contracts/lib/worker/WorkerFacet.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 2b00ac3

Please sign in to comment.