dgf-prototype/ethereum/contracts/Onboarding.sol

76 lines
2.3 KiB
Solidity

// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
import "./DAO.sol";
import "./WorkContract.sol";
import "./IOnValidate.sol";
contract Onboarding is WorkContract, IOnValidate {
constructor(DAO dao_, uint price_) WorkContract(dao_, price_) {}
/// Accept work approval/disapproval from customer
function submitWorkApproval(
uint requestIndex,
bool approval
) external override {
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
uint postIndex = dao.addPost(stake.worker, request.evidenceContentId);
emit WorkApprovalSubmitted(requestIndex, approval);
// Initiate validation pool
uint poolIndex = dao.initiateValidationPool{
value: request.fee - request.fee / 10
}(
postIndex,
POOL_DURATION,
1,
3,
100,
true,
true,
abi.encode(requestIndex)
);
dao.stake(poolIndex, stake.amount, true);
}
/// Callback to be executed when review pool completes
function onValidate(
bool votePasses,
bool quorumMet,
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];
if (!votePasses || !quorumMet) {
// refund the customer the remaining amount
payable(request.customer).transfer(request.fee / 10);
return;
}
uint postIndex = dao.addPost(
request.customer,
request.requestContentId
);
dao.initiateValidationPool{value: request.fee / 10}(
postIndex,
POOL_DURATION,
1,
3,
100,
true,
false,
""
);
}
}