// Contract: WebMasonCoin
// Target function: function _beforeTokenTransfer(
20/extensions/draft-IERC20Permit.sol";
// import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
// import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
// import "@openzeppelin/contracts/utils/Counters.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * _Available since v3.4._
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
    using Counters for Counters.Counter;

    mapping(address => Counters.Counter) private _nonces;

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private constant _PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    /**
     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
     * However, to ensure consistency with the upgradeable transpiler, we will continue
     * to reserve a slot.
     * @custom:oz-renamed-from _PERMIT_TYPEHASH
     */
    // solhint-disable-next-line var-name-mixedcase
    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {}

    /**
     * @dev See {IERC20Permit-permit}.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual override {
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _approve(owner, spender, value);
    }

    /**
     * @dev See {IERC20Permit-nonces}.
     */
    function nonces(address owner) public view virtual override returns (uint256) {
        return _nonces[owner].current();
    }

    /**
     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view override returns (bytes32) {
        return _domainSeparatorV4();
    }

    /**
     * @dev "Consume a nonce": return the current value and increment.
     *
     * _Available since v4.1._
     */
    function _useNonce(address owner) internal virtual returns (uint256 current) {
        Counters.Counter storage nonce = _nonces[owner];
        current = nonce.current();
        nonce.increment();
    }
}


// Dependency file: @openzeppelin/contracts/access/Ownable.sol

// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

// pragma solidity ^0.8.0;

// import "@openzeppelin/contracts/utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}


// Dependency file: contracts/interfaces/IVesting.sol

// pragma solidity ^0.8.0;

interface IVesting {
    struct VestingEntry {
        uint96 amount;
        uint64 start;
        uint32 lockup;
        uint32 cliff;
        uint32 vesting;
    }

    event AirdropperUpdated(address indexed account, bool status);
    event Airdrop(address indexed account, uint96 amount);
    event VestingEntryUpdated(
        address indexed account,
        uint96 amount,
        uint64 start,
        uint32 lockup,
        uint32 cliff,
        uint32 vesting
    );

    function vestingOf(address account)
        external
        view
        returns (
            uint64 start,
            uint32 lockup,
            uint32 cliff,
            uint32 vesting,
            uint96 balance,
            uint96 vested,
            uint96 locked,
            uint96 unlocked
        );

    function airdrop(
        uint32 lockup,
        uint32 cliff,
        uint32 vesting,
        address account,
        uint96 amount
    ) external returns (bool);

    function airdropBatch(
        uint32 lockup,
        uint32 cliff,
        uint32 vesting,
        address[] memory accounts,
        uint96[] memory amounts
    ) external returns (bool);
}


// Dependency file: contracts/utils/Vesting.sol

// pragma solidity ^0.8.0;

// import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// import "@openzeppelin/contracts/access/Ownable.sol";
// import "contracts/interfaces/IVesting.sol";

abstract contract Vesting is ERC20, Ownable, IVesting {
    mapping(address => VestingEntry) private _vestingOf;
    mapping(address => bool) private _isAirdropper;

    function vestingOf(address account)
        external
        view
        override
        returns (
            uint64 start,
            uint32 lockup,
            uint32 cliff,
            uint32 vesting,
            uint96 balance,
            uint96 vested,
            uint96 locked,
            uint96 unlocked
        )
    {
        if (_isVested(account)) {
            start = _vestingOf[account].start;
            lockup = _vestingOf[account].lockup;
            cliff = _vestingOf[account].cliff;
            vesting = _vestingOf[account].vesting;
            vested = _vestingOf[account].amount;
            locked = uint96(_lockedOf(account));
        }
        balance = uint96(balanceOf(account));
        unlocked = balance - locked;
    }

    function _isVested(address account) private view returns (bool) {
        return _vestingOf[account].amount != 0;
    }

    function _lockedOf(address account) private view returns (uint256) {
        return
            _pureLockedOf(
                _vestingOf[account].lockup,
                _vestingOf[account].cliff,
                _vestingOf[account].vesting,
                uint64(block.timestamp) - _vestingOf[account].start,
                uint256(_vestingOf[account].amount)
            );
    }

    function _pureLockedOf(
        uint32 lockupTime,
        uint32 cliffTime,
        uint32 vestingTime,
        uint64 passedTime,
        uint256 amount
    ) private pure returns (uint256) {
        if (passedTime >= (lockupTime + vestingTime)) return 0;
        if (passedTime <= (lockupTime + cliffTime)) return amount;
        return amount - (amount * (passedTime - lockupTime)) / vestingTime;
    }

    // Airdrop with vesting
    function setAirdropper(address account, bool status) external onlyOwner {
        _isAirdropper[account] = status;
        emit AirdropperUpdated(account, status);
    }

    modifier onlyAirdropper() {
        require(_isAirdropper[_msgSender()], "Caller is not allowed");
        _;
    }

    function airdrop(
        uint32 lockup,
        uint32 cliff,
        uint32 vesting,
        address account,
        uint96 amount
    ) external override onlyAirdropper returns (bool) {
        _airdrop(
            _msgSender(),
            uint64(block.timestamp),
            lockup,
            cliff,
            vesting,
            account,
            amount
        );
        return true;
    }

    function airdropBatch(
        uint32 lockup,
        uint32 cliff,
        uint32 vesting,
        address[] memory accounts,
        uint96[] memory amounts
    ) external override onlyAirdropper returns (bool) {
        require(accounts.length == amounts.length, "Mismatch");
        address from = _msgSender();
        uint64 start = uint64(block.timestamp);
        for (uint256 i = 0; i < accounts.length; i++) {
            _airdrop(
                from,
                start,
                lockup,
                cliff,
                vesting,
                accounts[i],
                amounts[i]
            );
        }
        return true;
    }

    function _airdrop(
        address from,
        uint64 start,
        uint32 lockup,
        uint32 cliff,
        uint32 vesting,
        address account,
        uint96 amount
    ) private {
        if (vesting != 0 || cliff != 0 || lockup != 0) {
            if (!_isVested(account)) {
                _vestingOf[account].start = start;
                _vestingOf[account].lockup = lockup;
                _vestingOf[account].cliff = cliff;
                _vestingOf[account].vesting = vesting;
            }
            _vestingOf[account].amount += amount;
            emit VestingEntryUpdated(
                account,
                _vestingOf[account].amount,
                _vestingOf[account].start,
                _vestingOf[account].lockup,
                _vestingOf[account].cliff,
                _vestingOf[account].vesting
            );
        }

        _transfer(from, account, amount);
        emit Airdrop(account, amount);
    }

    // The following functions are overrides required by Solidity.
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        if (_isVested(from)) {
            uint256 lockedAmount = _lockedOf(from);
            if (lockedAmount == 0) {
                delete _vestingOf[from];
            } else {
                require(
                    (balanceOf(from) - amount) >= lockedAmount,
                    "Transfer amount exceeds locked amount"
                );
            }
        }
        super._beforeTokenTransfer(from, to, amount);
    }
}


// Dependency file: contracts/interfaces/IRecoverable.sol

// pragma solidity ^0.8.0;

interface IRecoverable {
    event RecoveredFunds(
        address indexed token,
        uint256 amount,
        address indexed recipient
    );

    function recoverFunds(
        address token,
        uint256 amount,
        address recipient
    ) external returns (bool);
}


// Dependency file: contracts/utils/Recoverable.sol

// pragma solidity ^0.8.0;

// import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// import "@openzeppelin/contracts/access/Ownable.sol";
// import "contracts/interfaces/IRecoverable.sol";

/**
 @dev The contract is intendent to help recovering arbitrary ERC20 tokens and ETH accidentally transferred to the contract address
 */
abstract contract Recoverable is Ownable, IRecoverable {
    function _getRecoverableAmount(address token)
        internal
        view
        virtual
        returns (uint256)
    {
        if (token == address(0)) return address(this).balance;
        else return IERC20(token).balanceOf(address(this));
    }

    /**
     @param token ERC20 token's address to recover or address(0) to recover ETH
     @param amount to recover from contract's address
     @param recipient address to receive tokens from the contract
     */
    function recoverFunds(
        address token,
        uint256 amount,
        address recipient
    ) external override onlyOwner returns (bool) {
        uint256 recoverableAmount = _getRecoverableAmount(token);
        require(
            amount <= recoverableAmount,
            "Recoverable: RECOVERABLE_AMOUNT_NOT_ENOUGH"
        );
        if (token == address(0)) _transferEth(amount, recipient);
        else _transferErc20(token, amount, recipient);
        emit RecoveredFunds(token, amount, recipient);
        return true;
    }

    function _transferEth(uint256 amount, address recipient) private {
        address payable toPayable = payable(recipient);
        toPayable.transfer(amount);
    }

    function _transferErc20(
        address token,
        uint256 amount,
        address recipient
    ) private {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0xa9059cbb, recipient, amount)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "Recoverable: TRANSFER_FAILED"
        );
    }
}


// Dependency file: contracts/interfaces/ITransferBatch.sol

// pragma solidity ^0.8.0;

interface ITransferBatch {
    function transferBatch(address[] memory accounts, uint256[] memory amounts)
        external
        returns (bool);

    function transferBatchFrom(
        address from,
        address[] memory accounts,
        uint256[] memory amounts
    ) external returns (bool);
}


// Dependency file: contracts/utils/TransferBatch.sol

// pragma solidity ^0.8.0;

// import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// import "contracts/interfaces/ITransferBatch.sol";

abstract contract TransferBatch is ERC20, ITransferBatch {
    modifier checkMismatch(
        address[] memory accounts,
        uint256[] memory amounts
    ) {
        require(accounts.length == amounts.length, "Mismatch");
        _;
    }

    function transferBatch(address[] memory accounts, uint256[] memory amounts)
        external
        override
        checkMismatch(accounts, amounts)
        returns (bool)
    {
        address from = _msgSender();
        for (uint256 i = 0; i < accounts.length; i++) {
            _transfer(from, accounts[i], amounts[i]);
        }
        return true;
    }

    function transferBatchFrom(
        address from,
        address[] memory accounts,
        uint256[] memory amounts
    ) external override checkMismatch(accounts, amounts) returns (bool) {
        address spender = _msgSender();
        for (uint256 i = 0; i < accounts.length; i++) {
            _spendAllowance(from, spender, amounts[i]);
            _transfer(from, accounts[i], amounts[i]);
        }
        return true;
    }
}


// Root file: contracts/WebMasonCoin.sol

pragma solidity 0.8.14;

// import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
// import "@openzeppelin/contracts/access/Ownable.sol";
// import "contracts/utils/Vesting.sol";
// import "contracts/utils/Recoverable.sol";
// import "contracts/utils/TransferBatch.sol";

/// @custom:security-contact support@webmason.io
contract WebMasonCoin is
    ERC20,
    ERC20Permit,
    Ownable,
    Vesting,
    Recoverable,
    TransferBatch
{
    constructor() ERC20("WebMasonCoin", "WMC") ERC20Permit("WebMasonCoin") {
        _mint(_msgSender(), 10_000_000_000 * 10**decimals());
    }