dgf-prototype/ethereum/contracts/Onboarding.sol

82 lines
2.5 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_,
Proposals proposals_,
uint price_
) WorkContract(dao_, proposals_, 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,
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
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,
uint,
uint,
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,
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
100,
true,
false,
""
);
}
}