dgf-prototype/ethereum/contracts/Onboarding.sol

92 lines
2.9 KiB
Solidity
Raw Normal View History

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-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 {
constructor(
2024-06-28 13:44:18 -05:00
DAO dao,
GlobalForum forum,
Proposals proposals,
uint price
) Work(dao, forum, 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
Author[] memory authors = new Author[](1);
authors[0] = Author(1000000, stake.worker);
2024-06-28 13:44:18 -05:00
forum.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-04-28 18:05:45 -05:00
request.evidencePostId,
POOL_DURATION,
2024-03-28 15:06:14 -05:00
[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
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
) 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);
return;
2024-03-18 14:03:53 -05:00
}
// Make onboarding post
2024-05-20 15:06:24 -05:00
Reference[] memory emptyReferences;
Author[] memory authors = new Author[](1);
authors[0] = Author(1000000, request.customer);
2024-06-28 13:44:18 -05:00
forum.addPost(authors, request.requestPostId, emptyReferences);
dao.initiateValidationPool{value: request.fee / 10}(
2024-04-28 18:05:45 -05:00
request.requestPostId,
POOL_DURATION,
2024-03-28 15:06:14 -05:00
[uint256(1), uint256(3)],
[uint256(1), uint256(2)],
100,
true,
false,
""
);
2024-03-17 21:00:31 -05:00
}
}