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 "./core/Forum.sol";
import "./Work.sol";
import "./interfaces/IOnValidate.sol";
contract Onboarding is Work, IOnValidate {
constructor(
DAO dao_,
Proposals proposals_,
uint price_
) Work(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
Author[] memory authors = new Author[](1);
authors[0] = Author(1000000, stake.worker);
dao.addPost(authors, request.evidencePostId, request.citations);
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
Citation[] memory emptyCitations;
Author[] memory authors = new Author[](1);
authors[0] = Author(1000000, request.customer);
dao.addPost(authors, request.requestPostId, emptyCitations);
dao.initiateValidationPool{value: request.fee / 10}(
request.requestPostId,
POOL_DURATION,
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
100,
true,
false,
""
);
}
}