// File: contracts/HorsesGame.sol



// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address recipient, uint256 amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
}
contract Ownable {
    address private _owner;
    address private _previousOwner;
    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    constructor() {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function owner() public view returns (address) {
        return _owner;
    }

    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }

}

library SafeMath {
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;
        return c;
    }

    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        return c;
    }
}


contract HorsesGame is Ownable  {
    using SafeMath for uint256;

    IERC20 private tokenAddress = IERC20(0x420A210dA79512D38A00796d35beA4bFFc0F7dB9);
     address payable private _devWallet;
    //=================GAME==================

    event Deposit(address indexed from, uint256 amount);
    event Withdraw(address indexed from, uint256 amount);

    constructor(){
        _devWallet = payable(_msgSender());
    }

    // config onlyOwner
    function depositPoolGame(uint256 _amount) external onlyOwner{
        tokenAddress.transferFrom(_msgSender(), address(this), _amount);
    }

    function deposit(uint256 _amount) external {
        tokenAddress.transferFrom(_msgSender(), address(this), _amount);
        emit Deposit(_msgSender(), _amount);
    }
    
    function withdraw(address _address, uint256 _amount) external onlyOwner {
        tokenAddress.transfer(_address, _amount);
        emit Withdraw(_address, _amount);
    }

    function changeTokenAdress(address _address) external onlyOwner {
        tokenAddress=IERC20(_address);
    }

    function clearStuckBalance() external onlyOwner {
         tokenAddress.transfer(owner(), tokenAddress.balanceOf(address(this)));
    }

    receive() external payable {}

    function clearStuckETH() external onlyOwner {
        uint256 ethBalance=address(this).balance;
        require(ethBalance > 0);
        _devWallet.transfer(ethBalance);
    }

}