// SPDX-License-Identifier: MIT pragma solidity 0.8.30; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; /// @notice HVT discussion draft v0.2. Compile with OpenZeppelin Contracts 5.4.0. contract HumanValueToken is ERC20 { uint256 private constant INITIAL_SUPPLY = 1_000 ether; // ERC-20 uses 18 decimals. uint256 public constant AWARD_UNIT = 0.01 ether; // Each recipient earns whole hundredths of HVT. uint256 public constant ALLOWANCE_PER_PARTICIPANT = INITIAL_SUPPLY / 100_000; enum ParticipantKind { Person, AI } address[3] public reviewers; uint256 public immutable startedAt; uint256 public yearOfLastAward; uint256 public yearOpeningSupply = INITIAL_SUPPLY; uint256 public mintedThisYear; bool public awardsPaused; uint256 public approvalEpoch; mapping(bytes16 caseId => bool) public awarded; mapping(bytes16 participantId => bool) public qualified; mapping(uint256 year => uint256) public qualificationsByYear; mapping(bytes32 decision => address) public firstApproval; event Approved(bytes32 indexed decision, address indexed reviewer); event ApprovalWithdrawn(bytes32 indexed decision); event AwardPaid(bytes16 indexed caseId, bytes32 indexed evidenceHash, uint256 total, uint256 minted); event ParticipantQualified(bytes16 indexed participantId, bytes16 indexed caseId, uint256 indexed year, ParticipantKind kind, bytes32 evidenceHash); event AwardsPauseChanged(bool paused); error InvalidAward(); error InvalidQualification(); error InvalidAddress(); error ReviewerRequired(); error BeneficiaryCannotApprove(); error ApprovalExpiredOrTooLong(); error DifferentReviewerRequired(); error AnnualLimitExceeded(); error AwardsPaused(); error AlreadyInThatState(); constructor(address founder, address[3] memory initialReviewers) ERC20("Human Value Token", "HVT") { if (founder == address(0) || founder == address(this)) revert InvalidAddress(); for (uint256 i = 0; i < initialReviewers.length; ++i) { address reviewer = initialReviewers[i]; if (reviewer == address(0) || reviewer == address(this) || isReviewer(reviewer)) revert InvalidAddress(); reviewers[i] = reviewer; } startedAt = block.timestamp; _mint(founder, 100 ether); _mint(address(this), INITIAL_SUPPLY - 100 ether); } function isReviewer(address account) public view returns (bool) { return account != address(0) && (account == reviewers[0] || account == reviewers[1] || account == reviewers[2]); } function projectYear() public view returns (uint256) { return (block.timestamp - startedAt) / 365 days; // Zero-based. } function remainingMintAllowance() public view returns (uint256) { uint256 year = projectYear(); uint256 participationAllowance = qualificationsByYear[year] * ALLOWANCE_PER_PARTICIPANT; if (year != yearOfLastAward) return totalSupply() / 20 + participationAllowance; return yearOpeningSupply / 20 + participationAllowance - mintedThisYear; } /// @notice Confirm a distinct participant's first verified contribution independently of payment. /// @param participantId Stable public participant UUID, reused across wallets, cases and years. /// @param evidenceHash Keccak-256 of the public qualification decision's exact bytes. function approveQualification( bytes16 participantId, ParticipantKind kind, bytes16 caseId, bytes32 evidenceHash, uint256 deadline ) external { if (awardsPaused) revert AwardsPaused(); if (participantId == 0 || qualified[participantId] || caseId == 0 || evidenceHash == 0) { revert InvalidQualification(); } if (!_approve(deadline)) return; uint256 year = projectYear(); qualified[participantId] = true; ++qualificationsByYear[year]; emit ParticipantQualified(participantId, caseId, year, kind, evidenceHash); } /// @param caseId UUID of the public case. One payment can credit several contributors. /// @param evidenceHash Keccak-256 of the published decision document's exact bytes. /// @param amounts Each share must be a positive multiple of AWARD_UNIT (0.01 HVT). function approveAward( bytes16 caseId, bytes32 evidenceHash, address[] calldata recipients, uint256[] calldata amounts, uint256 deadline ) external { if (awardsPaused) revert AwardsPaused(); if (caseId == 0 || awarded[caseId] || evidenceHash == 0 || recipients.length == 0 || recipients.length != amounts.length) revert InvalidAward(); uint256 total; for (uint256 i = 0; i < recipients.length; ++i) { if (recipients[i] == address(0) || recipients[i] == address(this)) revert InvalidAward(); if (amounts[i] == 0 || amounts[i] % AWARD_UNIT != 0) revert InvalidAward(); if (recipients[i] == msg.sender) revert BeneficiaryCannotApprove(); total += amounts[i]; } if (!_approve(deadline)) return; uint256 year = projectYear(); if (year != yearOfLastAward) { yearOfLastAward = year; yearOpeningSupply = totalSupply(); mintedThisYear = 0; } uint256 reserve = balanceOf(address(this)); uint256 shortfall = total > reserve ? total - reserve : 0; if (shortfall > remainingMintAllowance()) revert AnnualLimitExceeded(); awarded[caseId] = true; if (shortfall > 0) { mintedThisYear += shortfall; _mint(address(this), shortfall); } for (uint256 i = 0; i < recipients.length; ++i) { _transfer(address(this), recipients[i], amounts[i]); } emit AwardPaid(caseId, evidenceHash, total, shortfall); } function setAwardsPaused(bool paused, uint256 deadline) external { if (awardsPaused == paused) revert AlreadyInThatState(); if (!_approve(deadline)) return; awardsPaused = paused; ++approvalEpoch; // Pending decisions need fresh approvals after a pause or restart. emit AwardsPauseChanged(paused); } function withdrawApproval(bytes32 decision) external { if (firstApproval[decision] != msg.sender) revert ReviewerRequired(); delete firstApproval[decision]; emit ApprovalWithdrawn(decision); } // Both reviewers submit identical calldata, including the decision type and deadline. function _approve(uint256 deadline) private returns (bool) { if (!isReviewer(msg.sender)) revert ReviewerRequired(); if (deadline < block.timestamp || deadline > block.timestamp + 30 days) revert ApprovalExpiredOrTooLong(); bytes32 decision = keccak256(abi.encode(approvalEpoch, msg.data)); address first = firstApproval[decision]; if (first == msg.sender) revert DifferentReviewerRequired(); emit Approved(decision, msg.sender); if (first == address(0)) { firstApproval[decision] = msg.sender; return false; } delete firstApproval[decision]; return true; } }