// File: @openzeppelin/contracts/utils/math/SafeMath.sol
// SPDX-License-Identifier: MIT

// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// File: airdrop.sol


pragma solidity ^0.8.0;


interface IERC20 {
    function transfer(address recipient, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

interface mineIF  {       
    function mineInfo(address user, uint256 number) external view  returns (uint256); 
}

contract AirdropContract {
    using SafeMath for uint;

    IERC20 token;
    mineIF minerpunk;
    
    address private owner;

    mapping(address => bool) private whitelist;   
    mapping(address => bool) private Claimed; 
    mapping (address => uint256)private Amount;
    
    uint256 private _totalWhitelist;
    uint256 private _totalClaimed;
    uint256 private _amountperpower;
    uint256 private _baseamount;
  
    

    constructor(address _ERC20,address _ERC721,uint256 Amountperpower, uint256 Baseamount ) {
        owner = msg.sender;
        token = IERC20(_ERC20);  
        minerpunk =   mineIF(_ERC721);
        _amountperpower = Amountperpower;
        _baseamount = Baseamount;
    }

    function addWhitelist(address[] memory addressesToAdd) external onlyOwner {
        for (uint256 i = 0; i < addressesToAdd.length; i++) {
            if (!whitelist[addressesToAdd[i]]) {
                whitelist[addressesToAdd[i]] = true;  
                uint Quota = countQuota(addressesToAdd[i]);                 
                Amount[addressesToAdd[i]] = Quota.add(_baseamount);                        
                _totalWhitelist = _totalWhitelist.add(1);

            }
        }
    }

    function countQuota(address addr)private view returns (uint256){
       uint256 power = minerpunk.mineInfo(addr, 2);       
       uint256 quota = power.mul(_amountperpower);
       return  quota;
    }

    function removeWhitelist(address[] memory addressesToRemove) external onlyOwner {
        for (uint256 i = 0; i < addressesToRemove.length; i++) {
            if (whitelist[addressesToRemove[i]]) {
                whitelist[addressesToRemove[i]] = false;
                Amount[addressesToRemove[i]] = 0;
                _totalWhitelist = _totalWhitelist.sub(1);
            }
        }
    }

    function claim ()external {
        require(whitelist[msg.sender] == true);
        require(Claimed[msg.sender] == false);
        require(token.balanceOf(address(this)) > 0);
        require(minerpunk.mineInfo(msg.sender, 2) > 0);
        

        token.transfer(msg.sender,tokenAmount(msg.sender));

        _totalClaimed = _totalClaimed.add(1);
        Claimed[msg.sender] = true;
        Amount[msg.sender] = 0;
    }



    function isWhitelisted(address addr) public view returns (bool) {
        return whitelist[addr];
    }

    function isClaimed(address addr) public view returns (bool) {
        return Claimed[addr];
    }


    function totalWhitelist() public view returns (uint256) {
        return _totalWhitelist;
    }

    function totalClaimed() public view returns (uint256) {
        return _totalClaimed;
    }



    function tokenAmount(address addr) public view returns (uint256) {
        return Amount[addr];
    }


    function amountperpower() public view returns (uint256) {
        return _amountperpower;
    }


  

    modifier onlyOwner() {
        require(msg.sender == owner, "Only owner can call this function");
        _;
    }
}