dgf-prototype/ethereum/contracts/Onboarding.sol

61 lines
2.1 KiB
Solidity
Raw Normal View History

2024-03-17 21:00:31 -05:00
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
import "./DAO.sol";
import "./WorkContract.sol";
2024-03-17 21:00:31 -05:00
import "./IOnValidate.sol";
contract Onboarding is WorkContract, IOnValidate {
constructor(DAO dao_, uint price_) WorkContract(dao_, price_) {}
2024-03-17 21:00:31 -05:00
/// Accept work approval/disapproval from customer
function submitWorkApproval(
uint requestIndex,
bool approval
) external override {
2024-03-17 21:00:31 -05:00
WorkRequest storage request = requests[requestIndex];
require(
request.status == WorkStatus.EvidenceSubmitted,
"Status must be EvidenceSubmitted"
);
AvailabilityStake storage stake = stakes[request.stakeIndex];
request.status = WorkStatus.ApprovalSubmitted;
request.approval = approval;
// Make work evidence post
2024-03-19 22:22:36 -05:00
uint postIndex = dao.addPost(stake.worker, request.evidenceContentId);
2024-03-17 21:00:31 -05:00
emit WorkApprovalSubmitted(requestIndex, approval);
// Initiate validation pool
2024-03-18 14:03:53 -05:00
uint poolIndex = dao.initiateValidationPool{
value: request.fee - request.fee / 10
2024-03-26 15:20:54 -05:00
}(postIndex, POOL_DURATION, 1, 3, true, abi.encode(requestIndex));
2024-03-18 14:03:53 -05:00
dao.stake(poolIndex, stake.amount, true);
2024-03-17 21:00:31 -05:00
}
/// Callback to be executed when review pool completes
function onValidate(bool votePasses, bytes calldata callbackData) external {
require(
msg.sender == address(dao),
"onValidate may only be called by the DAO contract"
);
uint requestIndex = abi.decode(callbackData, (uint));
WorkRequest storage request = requests[requestIndex];
2024-03-18 14:03:53 -05:00
if (!votePasses) {
// refund the customer the remaining amount
payable(request.customer).transfer(request.fee / 10);
return;
}
2024-03-19 22:22:36 -05:00
uint postIndex = dao.addPost(
request.customer,
request.requestContentId
);
dao.initiateValidationPool{value: request.fee / 10}(
postIndex,
POOL_DURATION,
2024-03-26 15:20:54 -05:00
1,
3,
false,
""
);
2024-03-17 21:00:31 -05:00
}
}