2024-03-17 21:00:31 -05:00
|
|
|
// SPDX-License-Identifier: Unlicense
|
|
|
|
pragma solidity ^0.8.24;
|
|
|
|
|
|
|
|
import "./DAO.sol";
|
2024-03-18 10:53:39 -05:00
|
|
|
import "./WorkContract.sol";
|
2024-04-09 05:33:04 -05:00
|
|
|
import "./interfaces/IOnValidate.sol";
|
2024-03-17 21:00:31 -05:00
|
|
|
|
2024-03-18 10:53:39 -05:00
|
|
|
contract Onboarding is WorkContract, IOnValidate {
|
2024-03-31 12:59:57 -05:00
|
|
|
constructor(
|
|
|
|
DAO dao_,
|
|
|
|
Proposals proposals_,
|
|
|
|
uint price_
|
|
|
|
) WorkContract(dao_, proposals_, price_) {}
|
2024-03-17 21:00:31 -05:00
|
|
|
|
|
|
|
/// Accept work approval/disapproval from customer
|
2024-03-18 10:53:39 -05:00
|
|
|
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 18:28:38 -05:00
|
|
|
}(
|
|
|
|
postIndex,
|
|
|
|
POOL_DURATION,
|
2024-03-28 15:06:14 -05:00
|
|
|
[uint256(1), uint256(3)],
|
|
|
|
[uint256(1), uint256(2)],
|
2024-03-26 18:28:38 -05:00
|
|
|
100,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
abi.encode(requestIndex)
|
|
|
|
);
|
2024-04-09 20:50:04 -05:00
|
|
|
// We have an approval from stake.worker to transfer up to stake.amount
|
2024-04-10 13:43:58 -05:00
|
|
|
dao.delegatedStakeOnValidationPool(
|
|
|
|
poolIndex,
|
|
|
|
stake.worker,
|
|
|
|
stake.amount,
|
|
|
|
true
|
|
|
|
);
|
2024-03-17 21:00:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Callback to be executed when review pool completes
|
2024-03-27 14:03:57 -05:00
|
|
|
function onValidate(
|
|
|
|
bool votePasses,
|
|
|
|
bool quorumMet,
|
2024-03-28 15:06:14 -05:00
|
|
|
uint,
|
|
|
|
uint,
|
2024-03-27 14:03:57 -05:00
|
|
|
bytes calldata callbackData
|
2024-04-02 13:36:40 -05:00
|
|
|
) external returns (uint) {
|
2024-03-17 21:00:31 -05:00
|
|
|
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-27 14:03:57 -05:00
|
|
|
if (!votePasses || !quorumMet) {
|
2024-03-18 14:03:53 -05:00
|
|
|
// refund the customer the remaining amount
|
|
|
|
payable(request.customer).transfer(request.fee / 10);
|
2024-04-02 13:36:40 -05:00
|
|
|
return 1;
|
2024-03-18 14:03:53 -05:00
|
|
|
}
|
2024-03-19 22:22:36 -05:00
|
|
|
uint postIndex = dao.addPost(
|
|
|
|
request.customer,
|
|
|
|
request.requestContentId
|
|
|
|
);
|
2024-03-18 10:53:39 -05:00
|
|
|
dao.initiateValidationPool{value: request.fee / 10}(
|
|
|
|
postIndex,
|
|
|
|
POOL_DURATION,
|
2024-03-28 15:06:14 -05:00
|
|
|
[uint256(1), uint256(3)],
|
|
|
|
[uint256(1), uint256(2)],
|
2024-03-26 18:28:38 -05:00
|
|
|
100,
|
|
|
|
true,
|
2024-03-18 10:53:39 -05:00
|
|
|
false,
|
|
|
|
""
|
|
|
|
);
|
2024-04-02 13:36:40 -05:00
|
|
|
return 0;
|
2024-03-17 21:00:31 -05:00
|
|
|
}
|
|
|
|
}
|