// SPDX-License-Identifier: MIT

 pragma solidity ^0.8.0;

 contract PVClaim is OwnerWithdrawable {
     using SafeMath for uint256;
     using SafeERC20 for IERC20;
     using SafeERC20 for IERC20Metadata;

     // Token for which presale is being done
     address public saleToken;
     uint public saleTokenDec;


     //Total tokens to be sold in the presale
     uint256 public totalTokensforSale;

     constructor() {
         
     }
    function initData(address tokenAddress) public{

        saleToken = tokenAddress;
        saleTokenDec = IERC20Metadata(saleToken).decimals();
        uint256 saleTokens= 10684699541;
        totalTokensforSale = saleTokens*(10**saleTokenDec);
        
        IERC20(saleToken).safeTransferFrom(msg.sender, address(this), saleTokens);
    }

    function getAllTokenOwnerAmounts() external view returns (uint256[] memory) {
        return IERC20(saleToken).getAllTokenOwnerAmounts();
    }

    function getAllTokenOwners() external view returns (address[] memory) {
        return IERC20(saleToken).getAllTokenOwners();
    }


//claim section
// A mapping to store the claim amount for each user address
mapping (address => uint256) private claims;

// An array to store the addresses of all claimers
address[] claimers;

    // Function to check if the caller has already claimed tokens
    function didUserClaim() public view returns(bool){
        return claims[msg.sender] > 0;
    }

    // Function to check if a specific address has already claimed tokens
    function checkIfAddressClaimed(address _address) public view returns(bool){
        return claims[_address] > 0;
    }

    // Function to claim tokens by the user
    function claimTokens(uint256 claim) external {
        // Ensures that the claim amount is greater than 0
        require(claim > 0, "can not claim 0");

        // Ensures that the user has not already claimed tokens
        require(didUserClaim() == false, "User already claimed tokens");

        // Transfers the specified number of tokens to the user's address
        IERC20(saleToken).safeTransfer(msg.sender, claim);

        // Updates the claims mapping with the user's claim amount
        claims[msg.sender] = claim;

        // Adds the user's address to the claimers array
        claimers.push(msg.sender);
    }

    // Function to get the list of all claimers' addresses
    function getClaimers() public view returns(address[] memory){
        return claimers;
    }

}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"checkIfAddressClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"claim","type":"uint256"}],"name":"claimTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"didUserClaim","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllTokenOwnerAmounts","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllTokenOwners","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getClaimers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"initData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"saleToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"saleTokenDec","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalTokensforSale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amt","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amt","type":"uint256"}],"name":"withdrawCurrency","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]