dgf-prototype/ethereum/contracts/Onboarding.sol

83 lines
2.5 KiB
Solidity
Raw Normal View History

2024-03-17 21:00:31 -05:00
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
import "./DAO.sol";
import "./WorkContract.sol";
2024-04-09 05:33:04 -05:00
import "./interfaces/IOnValidate.sol";
2024-03-17 21:00:31 -05:00
contract Onboarding is WorkContract, IOnValidate {
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
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
}(
postIndex,
POOL_DURATION,
2024-03-28 15:06:14 -05:00
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
100,
true,
true,
abi.encode(requestIndex)
);
2024-03-18 14:03:53 -05:00
dao.stake(poolIndex, 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
) 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);
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
);
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)],
100,
true,
false,
""
);
return 0;
2024-03-17 21:00:31 -05:00
}
}