Smart Social Welfare Distribution

What it does:
Automates distribution of social welfare funds to eligible recipients based on verified criteria, ensuring transparency and fairness.

Why it matters:
Reduces fraud, ensures timely and accurate payments, increases trust in public welfare programs, and allows for auditable fund allocation.

How it works:

  • Citizens or beneficiaries are registered and verified on-chain

  • Eligibility criteria are defined (income level, employment status, age, etc.)

  • Smart contract automatically calculates and distributes welfare payments periodically

  • Payments can be conditional on milestones (e.g., school attendance, healthcare check-ins)

  • All transactions are recorded immutably for auditing

  • Dashboards provide transparency to authorities and the public

  • Integrates with Smart Tax Allocation and Community Budget Allocation

      // SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title SmartSocialWelfare
 * @author Nam
 * @notice Automates conditional social welfare distribution on-chain
 */
contract SmartSocialWelfare is Ownable {

    struct Beneficiary {
        bool registered;
        uint256 lastReceived;
        uint256 totalReceived;
        uint256 eligibilityScore; // Can represent income, age, etc.
    }

    mapping(address => Beneficiary) public beneficiaries;
    uint256 public paymentAmount;
    uint256 public paymentInterval; // seconds

    // -------------------- EVENTS --------------------

    event BeneficiaryRegistered(address indexed beneficiary, uint256 eligibilityScore);
    event WelfarePaid(address indexed beneficiary, uint256 amount);

    // -------------------- TREASURY --------------------

    receive() external payable {}

    // -------------------- BENEFICIARY MANAGEMENT --------------------

    function registerBeneficiary(address _beneficiary, uint256 _eligibilityScore) external onlyOwner {
        beneficiaries[_beneficiary] = Beneficiary({
            registered: true,
            lastReceived: 0,
            totalReceived: 0,
            eligibilityScore: _eligibilityScore
        });

        emit BeneficiaryRegistered(_beneficiary, _eligibilityScore);
    }

    function updateEligibility(address _beneficiary, uint256 _newScore) external onlyOwner {
        require(beneficiaries[_beneficiary].registered, "Not registered");
        beneficiaries[_beneficiary].eligibilityScore = _newScore;
    }

    // -------------------- PAYMENT MANAGEMENT --------------------

    function setPaymentAmount(uint256 _amount) external onlyOwner {
        paymentAmount = _amount;
    }

    function setPaymentInterval(uint256 _interval) external onlyOwner {
        paymentInterval = _interval;
    }

    function distributePayment(address _beneficiary) external {
        Beneficiary storage b = beneficiaries[_beneficiary];
        require(b.registered, "Not registered");
        require(block.timestamp >= b.lastReceived + paymentInterval, "Payment interval not reached");
        require(address(this).balance >= paymentAmount, "Insufficient funds");

        b.lastReceived = block.timestamp;
        b.totalReceived += paymentAmount;
        payable(_beneficiary).transfer(paymentAmount);

        emit WelfarePaid(_beneficiary, paymentAmount);
    }

    function batchDistribute(address[] calldata _beneficiaries) external {
        for (uint256 i = 0; i < _beneficiaries.length; i++) {
            distributePayment(_beneficiaries[i]);
        }
    }
}