dgf-prototype/ethereum/contracts/Onboarding.sol

92 lines
2.9 KiB
Solidity

// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
import "./core/DAO.sol";
import "./Work.sol";
import "./interfaces/IOnValidate.sol";
contract Onboarding is Work, IOnValidate {
constructor(
DAO dao,
GlobalForum forum,
Proposals proposals,
uint price
) Work(dao, forum, 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
Author[] memory authors = new Author[](1);
authors[0] = Author(1000000, stake.worker);
forum.addPost(authors, request.evidencePostId, request.references);
emit WorkApprovalSubmitted(requestIndex, approval);
// Initiate validation pool
uint poolIndex = dao.initiateValidationPool{
value: request.fee - request.fee / 10
}(
request.evidencePostId,
POOL_DURATION,
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
100,
true,
true,
abi.encode(requestIndex)
);
// We have an approval from stake.worker to transfer up to stake.amount
dao.delegatedStakeOnValidationPool(
poolIndex,
stake.worker,
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;
}
// Make onboarding post
Reference[] memory emptyReferences;
Author[] memory authors = new Author[](1);
authors[0] = Author(1000000, request.customer);
forum.addPost(authors, request.requestPostId, emptyReferences);
dao.initiateValidationPool{value: request.fee / 10}(
request.requestPostId,
POOL_DURATION,
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
100,
true,
false,
""
);
}
}