// Contract: DreamBeatzGenesis_Staking
// Target function: function stake(uint256 id, uint level, bytes32[] calldata merkleproof) public
░░░▒▓▒░▓▒▓████░░░▒▓███▓▒▒▒▒▒▒░░
// ░░░░░██░░░███████▒░░░░░░███████▒░░▓███████████████▓▓▓▓▓██████████████████████████████░░░▓▓▓▓▓▒▓░░░████████████▓░░░▓░░▓▓▒░░░▒░░█▓████▒░▒░░░░▓█▓▒▒░░░░░░
// ░░░░▒█▓░░▒██████▓░░░░░░▒███████░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▓▓▓▓░▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒░░░▓█▒░░░░░▒▒░░▓█████▒▓▒███▒░░▓██░░░░░░░
// ░░░░██░░░███████▓▒▒▒▒▒▒███████▓▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░▓▓▓▓▓▓▒░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░███▓▓▓▒█▓▒██▓░░▓███░░░░░░
// ░░░▒█▓░░▓███████▓▓▓▓▓▓▓▓▓███████░░███████▓▓▓▓▓▓▓▓▓███████▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▒▓█░▓▓▓▓▓▓▓▓▒▓▓▓▓░░▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▒░░░░▓▓▓█▓▓▒▒▓▓░▒░░▒████▓░░░░░
// ░░░██░░░███████░░░░░░░░░▓██████▓░▓███████░░░░░░░░░███▒░▒█░░░░░░░░░░░░░░░░░░█████▓█▒░▓▓▓▓▓▓▓▒▓▓▓▓░░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▒░░░░░░▓██▓▒▓░░░░░░░▒▓█████▒░░░░░
// ░░▓█▓░░▓██████▓░░░░░░░░▒███████░░████████████████████▓██▓░▓███████████████████████░░░░▓▓▓▓▓▓░░░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▒░░░░░░▒▒▒▓▓▓▓▓▒░░░░░░░▓██████░░░░░░
// ░░██░░░▓░▒▓███░░░░░░░░░▓██████▓░▓███████░░░░░░░░░░░░░░░░░▒███████░░░░░░░░░███████▒░░░░█████▓░░░░░░░░░░▒▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▒▒▒▒▒▒▒░░░░░▒▒░░████▓▒░░░░░░
// ░▓█▒░░▓█▒█████▒▒▒▒▒▒▒▒▓███████░░███████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░███████▓▒▒▒▒▒▒▒▒▓███████░░░████████▓▓▓░░░░▒▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒░░▓█████▓░░░▒▒▒░░▒████▒██▓░░░░
// ░██░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░▓▓▓▓▓▓▓▓▓▓▓░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▓▓▓▓▓▓░░░░░░░▒▓█████▓█▓▓░░░░
// ░▒█▓▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▓▓█████████░░░░░░░░
// ░░▒█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▓░░░░░░░░░
// ░░░▒█████████████████████████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓█████████████████████████████████████████████████▓▒░░░░░░░░░░░
// ░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;  
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
 
    constructor() {
        _transferOwnership(_msgSender());
    }
 
    function owner() public view virtual returns (address) {
        return _owner;
    } 
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }
 
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }
 
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }
 
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
interface IERC165 { 
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
interface IERC721 is IERC165 { 
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 
    function balanceOf(address owner) external view returns (uint256 balance); 
    function ownerOf(uint256 tokenId) external view returns (address owner); 
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external; 
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external; 
    function approve(address to, uint256 tokenId) external;
 
    function getApproved(uint256 tokenId) external view returns (address operator); 
    function setApprovalForAll(address operator, bool _approved) external; 
    function isApprovedForAll(address owner, address operator) external view returns (bool); 
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;
}
library MerkleProof {
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }
   function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            bytes32 proofElement = proof[i];
            if (computedHash <= proofElement) {
                computedHash = _efficientHash(computedHash, proofElement);
            } else {
                computedHash = _efficientHash(proofElement, computedHash);
            }
        }
        return computedHash;
    }

    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    function stakeReward(address to, uint256 amount) external;
}

contract DreamBeatzGenesis_Staking is Ownable{
    
    mapping(uint => uint) public rewardMultiplier; //24hours
    function setRewardMultiplier(uint level, uint reward_in_wei) public onlyOwner{
        rewardMultiplier[level] = reward_in_wei;
    }
    
    mapping(uint => bytes32) public merkleRoot;
    function setMerkleRoot(uint level, bytes32 m) public onlyOwner{
        merkleRoot[level] = m;
    }
    
    address public beatzAddress = 0xa5f365d79273BbAdC67F362ca359faD70d3D7391;
    function setBeatzAddress(address a) public onlyOwner{
        beatzAddress = a;
    }
    
    address public beatz_vault = 0x410DA9946c248Bd34A339d8CfB29e5cBDaE27dF0;
    function setBeatzVault(address a) public onlyOwner{
        beatz_vault = a;
    }
    
    address public beatzNFT = 0xBB15002647DE0E6a86779F2C9919c51fDb603083;
    function setBeatzNFT(address a) public onlyOwner{
        beatzNFT = a;
    }

    uint public period = 75600;
    function setPeriod(uint p) public onlyOwner{
        period = p;
    }

    struct Stake {
        uint id;
        address address_;
        uint time;
        uint level;
        bool staked;
    }
    
    mapping(uint => Stake) public STAKES;
    mapping(address => uint[]) public stakeIds;