2024-03-17 21:00:31 -05:00
|
|
|
// SPDX-License-Identifier: Unlicense
|
|
|
|
pragma solidity ^0.8.24;
|
|
|
|
|
2024-04-15 13:34:46 -05:00
|
|
|
import "./core/DAO.sol";
|
2024-04-10 15:47:25 -05:00
|
|
|
import "./core/Forum.sol";
|
2024-04-28 18:11:20 -05:00
|
|
|
import "./Work.sol";
|
2024-04-09 05:33:04 -05:00
|
|
|
import "./interfaces/IOnValidate.sol";
|
2024-03-17 21:00:31 -05:00
|
|
|
|
2024-04-28 18:11:20 -05:00
|
|
|
contract Onboarding is Work, IOnValidate {
|
2024-03-31 12:59:57 -05:00
|
|
|
constructor(
|
|
|
|
DAO dao_,
|
|
|
|
Proposals proposals_,
|
|
|
|
uint price_
|
2024-04-28 18:11:20 -05:00
|
|
|
) Work(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-04-19 14:28:26 -05:00
|
|
|
Author[] memory authors = new Author[](1);
|
2024-04-21 10:28:44 -05:00
|
|
|
authors[0] = Author(1000000, stake.worker);
|
2024-05-20 15:06:24 -05:00
|
|
|
dao.addPost(authors, request.evidencePostId, request.references);
|
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
|
|
|
}(
|
2024-04-28 18:05:45 -05:00
|
|
|
request.evidencePostId,
|
2024-03-26 18:28:38 -05:00
|
|
|
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-30 15:56:43 -05:00
|
|
|
) external {
|
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-30 15:56:43 -05:00
|
|
|
return;
|
2024-03-18 14:03:53 -05:00
|
|
|
}
|
2024-04-19 14:28:26 -05:00
|
|
|
// Make onboarding post
|
2024-05-20 15:06:24 -05:00
|
|
|
Reference[] memory emptyReferences;
|
2024-04-19 14:28:26 -05:00
|
|
|
Author[] memory authors = new Author[](1);
|
2024-04-21 10:28:44 -05:00
|
|
|
authors[0] = Author(1000000, request.customer);
|
2024-05-20 15:06:24 -05:00
|
|
|
dao.addPost(authors, request.requestPostId, emptyReferences);
|
2024-03-18 10:53:39 -05:00
|
|
|
dao.initiateValidationPool{value: request.fee / 10}(
|
2024-04-28 18:05:45 -05:00
|
|
|
request.requestPostId,
|
2024-03-18 10:53:39 -05:00
|
|
|
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-03-17 21:00:31 -05:00
|
|
|
}
|
|
|
|
}
|