Contract 0x49b5e7019564501747267350198C58AbB559A502

Contract Overview

Balance:
0 MATIC
Txn Hash
Method
Block
From
To
Value [Txn Fee]
0x75b120dd08562b398b4c789c6694c4e9a9b4d63c427afa7a1de6bd9e4071998cAdd Reward Rules336379582023-03-27 16:42:2773 days 8 hrs ago0x1416aaf1920e3f90cb88c61d5a21236bb1319ab3 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.0006161471483.104970034
0xe98a35f030a6fe675c1cc2433e0435bc377936dd8565cabdd4c44f923a13a54fAdd Lottery336379582023-03-27 16:42:2773 days 8 hrs ago0x1416aaf1920e3f90cb88c61d5a21236bb1319ab3 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.0014038780463.104970034
0x14c2afbef64b26c3d34294eec2b3a56b2648eb00509566b9867d823504058ec6Add Reward Rules336379572023-03-27 16:42:2573 days 8 hrs ago0x1416aaf1920e3f90cb88c61d5a21236bb1319ab3 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.000771845873.104970034
0x55140ed9b5022851a9d0cd76cabe435c487d666fefb45c4a4d26da3aca941897Add Lottery336379562023-03-27 16:42:2373 days 8 hrs ago0x1416aaf1920e3f90cb88c61d5a21236bb1319ab3 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.0011834282783.104970034
0x1eeef5519c19a898d1b1bb7a665063dd4313b46f8de0d8cc88fd8f6a60a99addAdd Reward Rules336379562023-03-27 16:42:2373 days 8 hrs ago0x1416aaf1920e3f90cb88c61d5a21236bb1319ab3 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.000771883133.104970034
0xbb438e32af7e413eba2cafc7db68825c3451e86076cb3664a50e6724dcde4c6fAdd Lottery336379552023-03-27 16:42:2173 days 8 hrs ago0x1416aaf1920e3f90cb88c61d5a21236bb1319ab3 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.0012365977853.104970034
0xed5d4e792a28055459eda7007362c407dc5888f7f0e42353cf3c475787c862a8Set Trigger Addr...336379552023-03-27 16:42:2173 days 8 hrs ago0x19c58f64fccf4b42556f77b818160a729e9d87c1 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.000143508613.104970034
0x83b99cebaffef114ef6c9fe96cf82132d1badd4b05d5eb6f9e39aa32585ed80eSet Random Gener...336379542023-03-27 16:42:1973 days 8 hrs ago0x19c58f64fccf4b42556f77b818160a729e9d87c1 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.0001464117563.104970034
0x95c3a63c9c397ed789859c4941380b3994e43e7a3be47c10a3211b9ca044da0fSet Treasury Add...336378762023-03-27 16:39:3373 days 8 hrs ago0x19c58f64fccf4b42556f77b818160a729e9d87c1 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.0000762993 1.650000017
0x95bd47365d4873f2e4b05c0374e1ad2dc81d9c91df8b42077508ffd855c55cf5Set Operator Add...336378742023-03-27 16:39:2973 days 8 hrs ago0x19c58f64fccf4b42556f77b818160a729e9d87c1 IN  0x49b5e7019564501747267350198c58abb559a5020 MATIC0.00277188 60
0x22540418088ae33e50180ae36469493418f53f58b72d97ab6a47c93fb5330bfd0x60a06040336378582023-03-27 16:38:5573 days 8 hrs ago0x19c58f64fccf4b42556f77b818160a729e9d87c1 IN  Create: QulotLottery0 MATIC0.00752845658 1.500000016
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
QulotLottery

Compiler Version
v0.8.6+commit.11564f7e

Optimization Enabled:
Yes with 2000 runs

Other Settings:
default evmVersion
File 1 of 15 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../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 Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        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);
    }
}

File 2 of 15 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 3 of 15 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface 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.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 4 of 15 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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);
}

File 5 of 15 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 15 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 7 of 15 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 8 of 15 : Counters.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 9 of 15 : 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 10 of 15 : IQulotLottery.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

import { RewardUnit } from "../lib/QulotLotteryEnums.sol";
import { Lottery, Round, Ticket } from "../lib/QulotLotteryStructs.sol";

interface IQulotLottery {
    /**
     * @notice Set the random generator
     * @dev The calls to functions are used to verify the new generator implements them properly.
     * Callable only by the contract owner
     * @param _randomGeneratorAddress: address of the random generator
     * @dev Callable by operator
     */
    function setRandomGenerator(address _randomGeneratorAddress) external;

    /**
     *
     * @notice Add new lottery. Only call when deploying smart contact for the first time
     * @param _lotteryId lottery id
     * @param _picture Lottery picture
     * @param _verboseName Verbose name of lottery
     * @param _numberOfItems Numbers on the ticket
     * @param _minValuePerItem Min value per number on the ticket
     * @param _maxValuePerItem Max value per number on the ticket
     * @param _periodDays Daily period of round
     * @param _periodHourOfDays Hourly period of round
     * @param _maxNumberTicketsPerBuy Maximum number of tickets that can be purchased
     * @param _pricePerTicket Price per ticket
     * @param _treasuryFeePercent Treasury fee
     * @param _amountInjectNextRoundPercent Amount inject for next round
     * @dev Callable by operator
     */
    function addLottery(
        string memory _lotteryId,
        string memory _picture,
        string memory _verboseName,
        uint32 _numberOfItems,
        uint32 _minValuePerItem,
        uint32 _maxValuePerItem,
        uint[] memory _periodDays,
        uint _periodHourOfDays,
        uint32 _maxNumberTicketsPerBuy,
        uint256 _pricePerTicket,
        uint32 _treasuryFeePercent,
        uint32 _amountInjectNextRoundPercent
    ) external;

    /**
     * @notice Add more rule reward for lottery payout. Only call when deploying smart contact for the first time
     * @param _lotteryId Lottery id
     * @param _matchNumbers Number match
     * @param _rewardUnits Reward unit
     * @param _rewardValues Reward value per unit
     * @dev Callable by operator
     */
    function addRewardRules(
        string calldata _lotteryId,
        uint32[] calldata _matchNumbers,
        RewardUnit[] calldata _rewardUnits,
        uint256[] calldata _rewardValues
    ) external;

    /**
     *
     * @notice Buy tickets for the current round
     * @param _roundId Rround id
     * @param _tickets array of ticket
     * @dev Callable by users
     */
    function buyTickets(uint256 _roundId, uint32[][] calldata _tickets) external;

    /**
     * @notice Claim a set of winning tickets for a lottery
     * @param _ticketIds: array of ticket ids
     * @dev Callable by users only, not contract!
     */
    function claimTickets(uint256[] calldata _ticketIds) external;

    /**
     *
     * @notice Open new round for lottery
     * @param _lotteryId lottery id
     * @param _drawDateTime New session draw datetime (UTC)
     */
    function open(string calldata _lotteryId, uint256 _drawDateTime) external;

    /**
     *
     * @notice Close current round for lottery
     * @param _lotteryId lottery id
     */
    function close(string calldata _lotteryId) external;

    /**
     *
     * @notice Draw round by id
     * @param _lotteryId lottery id
     * @dev Callable by operator
     */
    function draw(string calldata _lotteryId) external;

    /**
     *
     * @notice Reward round by id
     * @param _lotteryId round id
     * @dev Callable by operator
     */
    function reward(string calldata _lotteryId) external;

    /**
     * @notice Return a list of lottery ids
     */
    function getLotteryIds() external view returns (string[] memory lotteryIds);

    /**
     * @notice Return lottery by id
     * @param _lotteryId Id of lottery
     */
    function getLottery(string calldata _lotteryId) external view returns (Lottery memory lottery);

    /**
     * @notice Return a list of round ids
     */
    function getRoundIds() external view returns (uint256[] memory roundIds);

    /**
     * @notice Return round by id
     * @param _roundId Id of round
     */
    function getRound(uint256 _roundId) external view returns (Round memory round);

    /**
     * @notice Return a list of ticket ids
     */
    function getTicketIds() external view returns (uint256[] memory ticketIds);

    /**
     * @notice Return a list of ticket ids by user address
     * @param _user: user address
     * @param _cursor: cursor to start where to retrieve the tickets
     * @param _size: the number of tickets to retrieve
     */
    function getTicketIdsByUser(
        address _user,
        uint256 _cursor,
        uint256 _size
    ) external view returns (uint256[] memory ticketIds, uint256 cursor);

    /**
     * @notice Return ticket by id
     * @param _ticketId Id of round
     */
    function getTicket(uint256 _ticketId) external view returns (Ticket memory ticket);
}

File 11 of 15 : IRandomNumberGenerator.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

interface IRandomNumberGenerator {
    /**
     *
     * @param _roundId Request id combine lotteryProductId and lotteryroundId
     * @param _numbersOfItems Numbers of items
     * @param _minValuePerItems Min value per items
     * @param _maxValuePerItems Max value per items
     */
    function requestRandomNumbers(
        uint256 _roundId,
        uint32 _numbersOfItems,
        uint32 _minValuePerItems,
        uint32 _maxValuePerItems
    ) external;

    /**
     * @param _roundId Request id combine lotteryProductId and lotteryroundId
     */
    function getRandomResult(uint256 _roundId) external view returns (uint32[] memory);

    /**
     * @notice Set the address for the Qulot
     * @param _qulotLottery: address of the Qulot lottery
     */
    function setQulotLottery(address _qulotLottery) external;
}

File 12 of 15 : QulotLotteryEnums.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

enum RoundStatus {
    Open,
    Draw,
    Close,
    Reward
}

enum RewardUnit {
    Percent,
    Fixed
}

File 13 of 15 : QulotLotteryStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

import { RoundStatus, RewardUnit } from "./QulotLotteryEnums.sol";

struct Lottery {
    string verboseName;
    string picture;
    uint32 numberOfItems;
    uint32 minValuePerItem;
    uint32 maxValuePerItem;
    // day of the week (0 - 6) (Sunday-to-Saturday)
    uint[] periodDays;
    // hour (0 - 23)
    uint periodHourOfDays;
    uint32 maxNumberTicketsPerBuy;
    uint256 pricePerTicket;
    uint32 treasuryFeePercent;
    uint32 amountInjectNextRoundPercent;
}

struct Round {
    uint32[] winningNumbers;
    uint256 drawDateTime;
    uint256 openTime;
    uint256 totalAmount;
    uint256 totalTickets;
    uint256 firstRoundId;
    RoundStatus status;
}

struct Rule {
    uint32 matchNumber;
    RewardUnit rewardUnit;
    uint256 rewardValue;
}

struct Ticket {
    uint32[] numbers;
    address owner;
    uint256 roundId;
    bool winStatus;
    uint winRewardRule;
    uint256 winAmount;
    bool clamStatus;
}

File 14 of 15 : QulotLottery.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { Counters } from "@openzeppelin/contracts/utils/Counters.sol";
import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import { IQulotLottery } from "./interfaces/IQulotLottery.sol";
import { IRandomNumberGenerator } from "./interfaces/IRandomNumberGenerator.sol";
import { RoundStatus, RewardUnit } from "./lib/QulotLotteryEnums.sol";
import { String } from "./utils/StringUtils.sol";
import { Lottery, Round, Ticket, Rule } from "./lib/QulotLotteryStructs.sol";

contract QulotLottery is ReentrancyGuard, IQulotLottery, Ownable {
    using SafeERC20 for IERC20;
    using Counters for Counters.Counter;
    using SafeMath for uint256;

    /* #region Constants */
    string private constant ERROR_CONTRACT_NOT_ALLOWED = "ERROR_CONTRACT_NOT_ALLOWED";
    string private constant ERROR_PROXY_CONTRACT_NOT_ALLOWED = "ERROR_PROXY_CONTRACT_NOT_ALLOWED";
    string private constant ERROR_ONLY_OPERATOR = "ERROR_ONLY_OPERATOR";
    string private constant ERROR_ONLY_TRIGGER_OR_OPERATOR = "ERROR_ONLY_TRIGGER_OR_OPERATOR";
    string private constant ERROR_ROUND_IS_CLOSED = "ERROR_ROUND_IS_CLOSED";
    string private constant ERROR_ROUND_NOT_OPEN = "ERROR_ROUND_NOT_OPEN";
    string private constant ERROR_TICKETS_LIMIT = "ERROR_TICKETS_LIMIT";
    string private constant ERROR_TICKETS_EMPTY = "ERROR_TICKETS_EMPTY";
    string private constant ERROR_INVALID_TICKET = "ERROR_INVALID_TICKET";
    string private constant ERROR_INVALID_ZERO_ADDRESS = "ERROR_INVALID_ZERO_ADDRESS";
    string private constant ERROR_NOT_TIME_DRAW_LOTTERY = "ERROR_NOT_TIME_DRAW_LOTTERY";
    string private constant ERROR_NOT_TIME_OPEN_LOTTERY = "ERROR_NOT_TIME_OPEN_LOTTERY";
    string private constant ERROR_NOT_TIME_CLOSE_LOTTERY = "ERROR_NOT_TIME_CLOSE_LOTTERY";
    string private constant ERROR_NOT_TIME_REWARD_LOTTERY = "ERROR_NOT_TIME_REWARD_LOTTERY";
    string private constant ERROR_NOT_TIME_CLAIM_TICKET = "ERROR_NOT_TIME_CLAIM_TICKET";
    string private constant ERROR_INVALID_WINNING_NUMBERS = "ERROR_INVALID_WINNING_NUMBERS";
    string private constant ERROR_INVALID_LOTTERY_ID = "ERROR_INVALID_LOTTERY_ID";
    string private constant ERROR_INVALID_LOTTERY_VERBOSE_NAME = "ERROR_INVALID_LOTTERY_VERBOSE_NAME";
    string private constant ERROR_INVALID_LOTTERY_PICTURE = "ERROR_INVALID_LOTTERY_PICTURE";
    string private constant ERROR_INVALID_LOTTERY_NUMBER_OF_ITEMS = "ERROR_INVALID_LOTTERY_NUMBER_OF_ITEMS";
    string private constant ERROR_INVALID_LOTTERY_MIN_VALUE_PER_ITEMS = "ERROR_INVALID_LOTTERY_MIN_VALUE_PER_ITEMS";
    string private constant ERROR_INVALID_LOTTERY_MAX_VALUE_PER_ITEMS = "ERROR_INVALID_LOTTERY_MAX_VALUE_PER_ITEMS";
    string private constant ERROR_INVALID_LOTTERY_PERIOD_DAYS = "ERROR_INVALID_LOTTERY_PERIOD_DAYS";
    string private constant ERROR_INVALID_LOTTERY_PERIOD_HOUR_OF_DAYS = "ERROR_INVALID_LOTTERY_PERIOD_HOUR_OF_DAYS";
    string private constant ERROR_INVALID_LOTTERY_MAX_NUMBER_TICKETS_PER_BUY =
        "ERROR_INVALID_LOTTERY_MAX_NUMBER_TICKETS_PER_BUY";
    string private constant ERROR_INVALID_LOTTERY_PRICE_PER_TICKET = "ERROR_INVALID_LOTTERY_PRICE_PER_TICKET";
    string private constant ERROR_INVALID_LOTTERY_TREASURY_FEE_PERCENT = "ERROR_INVALID_LOTTERY_TREASURY_FEE_PERCENT";
    string private constant ERROR_LOTTERY_ALREADY_EXISTS = "ERROR_LOTTERY_ALREADY_EXISTS";
    string private constant ERROR_INVALID_RULE_REWARD_VALUE = "ERROR_INVALID_RULE_REWARD_VALUE";
    string private constant ERROR_INVALID_RULE_MATCH_NUMBER = "ERROR_INVALID_RULE_MATCH_NUMBER";
    string private constant ERROR_INVALID_RULES = "ERROR_INVALID_RULES";
    string private constant ERROR_INVALID_ROUND_DRAW_TIME = "ERROR_INVALID_ROUND_DRAW_TIME";
    string private constant ERROR_WRONG_TOKEN_ADDRESS = "ERROR_WRONG_TOKEN_ADDRESS";
    /* #endregion */

    /* #region Events */
    event TicketsPurchase(address indexed buyer, uint256 indexed roundId, uint256[] ticketIds, uint256 amount);
    event TicketsClaim(address indexed claimer, uint256 amount, uint256[] ticketIds);
    event NewLottery(
        string lotteryId,
        string verboseName,
        string picture,
        uint32 numberOfItems,
        uint32 minValuePerItem,
        uint32 maxValuePerItem,
        uint[] periodDays,
        uint periodHourOfDays,
        uint32 maxNumberTicketsPerBuy,
        uint256 pricePerTicket,
        uint32 treasuryFeePercent,
        uint32 amountInjectNextRoundPercent
    );
    event NewRewardRule(
        uint indexed ruleIndex,
        string lotteryId,
        uint32 matchNumber,
        RewardUnit rewardUnit,
        uint256 rewardValue
    );
    event RoundOpen(
        uint256 indexed roundId,
        string lotteryId,
        uint256 totalAmount,
        uint256 startTime,
        uint256 drawDateTime
    );
    event RoundClose(uint256 indexed roundId, uint256 totalAmount, uint256 totalTickets, uint256 endTime);
    event RoundDraw(uint256 indexed roundId, uint32[] numbers);
    event RoundReward(uint256 indexed roundId, uint256 amountTreasury, uint256 amountInjectNextRound);
    event RoundInjection(uint256 indexed roundId, uint256 injectedAmount);
    event NewRandomGenerator(address randomGeneratorAddress);
    event AdminTokenRecovery(address token, uint256 amount);
    /* #endregion */

    /* #region States */
    // Mapping lotteryId to lottery info
    string[] private lotteryIds;
    mapping(string => Lottery) private lotteries;

    // Mapping roundId to round info
    uint256[] private roundIds;
    mapping(uint256 => Round) private rounds;
    // Keep track of lottery id for a given lotteryId
    mapping(uint256 => string) private lotteriesPerRoundId;

    // Mapping ticketId to ticket info
    uint256[] private ticketIds;
    mapping(uint256 => Ticket) private tickets;
    // Keep track of user ticket ids for a given roundId
    mapping(address => uint256[]) private ticketsPerUserId;
    mapping(uint256 => uint256[]) private ticketsPerRoundId;

    mapping(string => uint256) public currentRoundIdPerLottery;
    mapping(string => uint256) public amountInjectNextRoundPerLottery;

    mapping(string => Rule[]) public rulesPerLotteryId;

    // The lottery scheduler account used to run regular operations.
    address public operatorAddress;
    address public treasuryAddress;
    address public triggerAddress;

    IERC20 public immutable token;
    IRandomNumberGenerator public randomGenerator;

    Counters.Counter private counterTicketId;
    Counters.Counter private counterRoundId;
    /* #endregion */

    /* #region Modifiers */
    /* solhint-disable avoid-tx-origin */
    modifier notContract() {
        require(!Address.isContract(msg.sender), ERROR_CONTRACT_NOT_ALLOWED);
        require(msg.sender == tx.origin, ERROR_PROXY_CONTRACT_NOT_ALLOWED);
        _;
    }
    /* solhint-enable */

    modifier onlyOperator() {
        require(msg.sender == operatorAddress, ERROR_ONLY_OPERATOR);
        _;
    }

    modifier onlyOperatorOrTrigger() {
        require(msg.sender == triggerAddress || msg.sender == operatorAddress, ERROR_ONLY_TRIGGER_OR_OPERATOR);
        _;
    }

    /* #endregion */

    /* #region Constructor */
    /**
     *
     * @notice Constructor
     * @param _tokenAddress Address of the ERC20 token
     */
    constructor(address _tokenAddress) {
        token = IERC20(_tokenAddress);
    }

    /* #endregion */

    /* #region Methods */

    /**
     *
     * @notice Add new lottery. Only call when deploying smart contact for the first time
     * @param _lotteryId lottery id
     * @param _picture Lottery picture
     * @param _verboseName Verbose name of lottery
     * @param _numberOfItems Numbers on the ticket
     * @param _minValuePerItem Min value per number on the ticket
     * @param _maxValuePerItem Max value per number on the ticket
     * @param _periodDays Daily period of round
     * @param _periodHourOfDays Hourly period of round
     * @param _maxNumberTicketsPerBuy Maximum number of tickets that can be purchased
     * @param _pricePerTicket Price per ticket
     * @param _treasuryFeePercent Treasury fee
     * @param _amountInjectNextRoundPercent Amount inject for next round
     * @dev Callable by operator
     */
    function addLottery(
        string memory _lotteryId,
        string memory _picture,
        string memory _verboseName,
        uint32 _numberOfItems,
        uint32 _minValuePerItem,
        uint32 _maxValuePerItem,
        uint[] memory _periodDays,
        uint _periodHourOfDays,
        uint32 _maxNumberTicketsPerBuy,
        uint256 _pricePerTicket,
        uint32 _treasuryFeePercent,
        uint32 _amountInjectNextRoundPercent
    ) external override onlyOperator {
        require(!String.isEmpty(_lotteryId), ERROR_INVALID_LOTTERY_ID);
        require(!String.isEmpty(_picture), ERROR_INVALID_LOTTERY_PICTURE);
        require(!String.isEmpty(_verboseName), ERROR_INVALID_LOTTERY_VERBOSE_NAME);
        require(_numberOfItems > 0, ERROR_INVALID_LOTTERY_NUMBER_OF_ITEMS);
        require(_minValuePerItem > 0, ERROR_INVALID_LOTTERY_MIN_VALUE_PER_ITEMS);
        require(_maxValuePerItem > 0 && _maxValuePerItem < type(uint32).max, ERROR_INVALID_LOTTERY_MAX_VALUE_PER_ITEMS);
        require(_periodDays.length > 0, ERROR_INVALID_LOTTERY_PERIOD_DAYS);
        require(_periodHourOfDays > 0 && _periodHourOfDays <= 24, ERROR_INVALID_LOTTERY_PERIOD_HOUR_OF_DAYS);
        require(
            _maxNumberTicketsPerBuy > 0 && _maxNumberTicketsPerBuy < type(uint32).max,
            ERROR_INVALID_LOTTERY_MAX_NUMBER_TICKETS_PER_BUY
        );
        require(_pricePerTicket > 0, ERROR_INVALID_LOTTERY_PRICE_PER_TICKET);
        require(_treasuryFeePercent >= 0, ERROR_INVALID_LOTTERY_TREASURY_FEE_PERCENT);

        require(
            !String.compareTwoStrings(lotteries[_lotteryId].verboseName, _verboseName),
            ERROR_LOTTERY_ALREADY_EXISTS
        );

        lotteries[_lotteryId] = Lottery({
            verboseName: _verboseName,
            picture: _picture,
            numberOfItems: _numberOfItems,
            minValuePerItem: _minValuePerItem,
            maxValuePerItem: _maxValuePerItem,
            periodDays: _periodDays,
            periodHourOfDays: _periodHourOfDays,
            maxNumberTicketsPerBuy: _maxNumberTicketsPerBuy,
            pricePerTicket: _pricePerTicket,
            treasuryFeePercent: _treasuryFeePercent,
            amountInjectNextRoundPercent: _amountInjectNextRoundPercent
        });
        lotteryIds.push(_lotteryId);

        emit NewLottery(
            _lotteryId,
            _verboseName,
            _picture,
            _numberOfItems,
            _minValuePerItem,
            _maxValuePerItem,
            _periodDays,
            _periodHourOfDays,
            _maxNumberTicketsPerBuy,
            _pricePerTicket,
            _treasuryFeePercent,
            _amountInjectNextRoundPercent
        );
    }

    /**
     * @notice Add many rules reward for lottery payout. Only call when deploying smart contact for the first time
     * @param _lotteryId Lottery id
     * @param _matchNumbers Number match
     * @param _rewardUnits Reward unit
     * @param _rewardValues Reward value per unit
     * @dev Callable by operator
     */
    function addRewardRules(
        string calldata _lotteryId,
        uint32[] calldata _matchNumbers,
        RewardUnit[] calldata _rewardUnits,
        uint256[] calldata _rewardValues
    ) external override onlyOperator {
        require(
            _matchNumbers.length == _rewardUnits.length && _rewardUnits.length == _rewardValues.length,
            ERROR_INVALID_RULES
        );

        for (uint i = 0; i < _matchNumbers.length; i++) {
            require(!String.isEmpty(_lotteryId), ERROR_INVALID_LOTTERY_ID);
            require(_matchNumbers[i] > 0, ERROR_INVALID_RULE_MATCH_NUMBER);
            require(_rewardValues[i] > 0, ERROR_INVALID_RULE_REWARD_VALUE);

            rulesPerLotteryId[_lotteryId].push(
                Rule({ matchNumber: _matchNumbers[i], rewardUnit: _rewardUnits[i], rewardValue: _rewardValues[i] })
            );
            emit NewRewardRule(i, _lotteryId, _matchNumbers[i], _rewardUnits[i], _rewardValues[i]);
        }
    }

    /**
     *
     * @param _roundId Request id combine lotterylotteryId and lotteryroundId
     * @param _tickets Array of ticket pick numbers
     * @dev Callable by users
     */
    function buyTickets(uint256 _roundId, uint32[][] calldata _tickets) external override notContract nonReentrant {
        // check list tickets is empty
        require(_tickets.length != 0, ERROR_TICKETS_EMPTY);
        // check round is open
        require(rounds[_roundId].status == RoundStatus.Open, ERROR_ROUND_IS_CLOSED);
        // check round too late
        require(block.timestamp < rounds[_roundId].drawDateTime, ERROR_ROUND_IS_CLOSED);
        // check limit ticket
        require(
            _tickets.length <= lotteries[lotteriesPerRoundId[_roundId]].maxNumberTicketsPerBuy,
            ERROR_TICKETS_LIMIT
        );

        // calculate total price to pay to this contract
        uint256 amountToTransfer = _caculateTotalPriceForBulkTickets(
            lotteries[lotteriesPerRoundId[_roundId]],
            _tickets.length
        );
        // transfer tokens to this contract
        token.safeTransferFrom(address(msg.sender), address(this), amountToTransfer);

        // increment the total amount collected for the round
        rounds[_roundId].totalAmount += amountToTransfer;
        rounds[_roundId].totalTickets += _tickets.length;
        uint256[] memory purchasedTicketIds = new uint256[](_tickets.length);
        for (uint i = 0; i < _tickets.length; i++) {
            uint32[] memory ticketNumbers = _tickets[i];

            // Check valid ticket numbers
            require(_isValidNumbers(ticketNumbers, lotteries[lotteriesPerRoundId[_roundId]]), ERROR_INVALID_TICKET);

            // Increment lottery ticket number
            counterTicketId.increment();
            tickets[counterTicketId.current()] = Ticket({
                owner: msg.sender,
                roundId: _roundId,
                numbers: ticketNumbers,
                winStatus: false,
                winRewardRule: 0,
                winAmount: 0,
                clamStatus: false
            });
            ticketIds.push(counterTicketId.current());
            ticketsPerUserId[msg.sender].push(counterTicketId.current());
            ticketsPerRoundId[_roundId].push(counterTicketId.current());
            purchasedTicketIds[i] = counterTicketId.current();
        }

        emit TicketsPurchase(msg.sender, _roundId, purchasedTicketIds, amountToTransfer);
    }

    /**
     * @notice Claim a set of winning tickets for a lottery
     * @param _ticketIds: array of ticket ids
     * @dev Callable by users only, not contract!
     */
    function claimTickets(uint256[] calldata _ticketIds) external override notContract nonReentrant {
        require(_ticketIds.length != 0, ERROR_TICKETS_EMPTY);

        // Initializes the rewardAmountToTransfer
        uint256 rewardAmountToTransfer;
        for (uint i = 0; i < _ticketIds.length; i++) {
            uint256 ticketId = _ticketIds[i];
            require(tickets[ticketId].owner == msg.sender, "ERROR_ONLY_OWNER");
            require(tickets[ticketId].winStatus, "ERROR_TICKET_NOT_WIN");
            require(!tickets[ticketId].clamStatus, "ERROR_ONLY_CLAIM_PRIZE_ONCE");
            tickets[ticketId].clamStatus = true;
            rewardAmountToTransfer += tickets[ticketId].winAmount;
        }

        // Transfer money to msg.sender
        token.safeTransfer(msg.sender, rewardAmountToTransfer);

        emit TicketsClaim(msg.sender, rewardAmountToTransfer, _ticketIds);
    }

    /**
     *
     * @param _lotteryId lottery id
     * @param _drawDateTime New round draw datetime (UTC)
     */
    function open(string calldata _lotteryId, uint256 _drawDateTime) external override onlyOperatorOrTrigger {
        require(!String.isEmpty(_lotteryId), ERROR_INVALID_LOTTERY_ID);
        require(_drawDateTime > 0, ERROR_INVALID_ROUND_DRAW_TIME);
        uint256 currentRoundId = currentRoundIdPerLottery[_lotteryId];
        require(
            (currentRoundId == 0) || (rounds[currentRoundId].status == RoundStatus.Reward),
            ERROR_NOT_TIME_OPEN_LOTTERY
        );

        uint256 firstRoundId = currentRoundIdPerLottery[_lotteryId];
        // Increment current round id of lottery to one
        counterRoundId.increment();
        uint256 nextRoundId = counterRoundId.current();

        // Keep track lottery id and round id
        currentRoundIdPerLottery[_lotteryId] = nextRoundId;
        lotteriesPerRoundId[nextRoundId] = _lotteryId;

        // Create new round
        uint256 totalAmount = amountInjectNextRoundPerLottery[_lotteryId];
        rounds[nextRoundId] = Round({
            firstRoundId: firstRoundId,
            winningNumbers: new uint32[](lotteries[_lotteryId].numberOfItems),
            drawDateTime: _drawDateTime,
            openTime: block.timestamp,
            totalAmount: totalAmount,
            totalTickets: 0,
            status: RoundStatus.Open
        });
        roundIds.push(nextRoundId);

        // Reset amount injection for next round
        amountInjectNextRoundPerLottery[_lotteryId] = 0;

        // Emit round open
        emit RoundOpen(nextRoundId, _lotteryId, totalAmount, block.timestamp, _drawDateTime);
    }

    /**
     *
     * @param _lotteryId lottery id
     */
    function close(string calldata _lotteryId) external override onlyOperatorOrTrigger {
        require(!String.isEmpty(_lotteryId), ERROR_INVALID_LOTTERY_ID);
        uint256 currentRoundId = currentRoundIdPerLottery[_lotteryId];
        require(
            (currentRoundId != 0) && rounds[currentRoundId].status == RoundStatus.Open,
            ERROR_NOT_TIME_CLOSE_LOTTERY
        );

        rounds[currentRoundId].status = RoundStatus.Close;

        // Request new random number
        randomGenerator.requestRandomNumbers(
            currentRoundId,
            lotteries[_lotteryId].numberOfItems,
            lotteries[_lotteryId].minValuePerItem,
            lotteries[_lotteryId].maxValuePerItem
        );

        // Emit round close
        emit RoundClose(
            currentRoundId,
            rounds[currentRoundId].totalAmount,
            rounds[currentRoundId].totalTickets,
            block.timestamp
        );
    }

    /**
     *
     * @notice Start round by id
     * @param _lotteryId round id
     * @dev Callable by operator
     */
    function draw(string calldata _lotteryId) external override onlyOperatorOrTrigger {
        require(!String.isEmpty(_lotteryId), ERROR_INVALID_LOTTERY_ID);
        uint256 currentRoundId = currentRoundIdPerLottery[_lotteryId];
        require(
            (currentRoundId != 0) && rounds[currentRoundId].status == RoundStatus.Close,
            ERROR_NOT_TIME_DRAW_LOTTERY
        );

        // get randomResult generated by ChainLink's fallback
        uint32[] memory winningNumbers = randomGenerator.getRandomResult(currentRoundId);

        // check winning numbers is valid or not
        require(_isValidNumbers(winningNumbers, lotteries[_lotteryId]), ERROR_INVALID_WINNING_NUMBERS);

        rounds[currentRoundId].status = RoundStatus.Draw;
        rounds[currentRoundId].winningNumbers = winningNumbers;

        // Emit round Draw
        emit RoundDraw(currentRoundIdPerLottery[_lotteryId], winningNumbers);
    }

    /**
     *
     * @notice Reward round by id
     * @param _lotteryId round id
     * @dev Callable by operator
     */
    function reward(string calldata _lotteryId) external override onlyOperatorOrTrigger {
        require(!String.isEmpty(_lotteryId), ERROR_INVALID_LOTTERY_ID);
        uint256 currentRoundId = currentRoundIdPerLottery[_lotteryId];
        require(
            (currentRoundId != 0) && rounds[currentRoundId].status == RoundStatus.Draw,
            ERROR_NOT_TIME_REWARD_LOTTERY
        );

        // Set round status to reward
        rounds[currentRoundId].status = RoundStatus.Reward;

        // Estimate
        (uint256 amountTreasury, uint256 amountInject, uint256 rewardAmount) = _estimateReward(
            _lotteryId,
            currentRoundId
        );

        uint256 outRewardValue = _findWinnersAndReward(_lotteryId, currentRoundId, rewardAmount);
        amountInject += outRewardValue;
        amountInjectNextRoundPerLottery[_lotteryId] = amountInject;
        // Transfer token to treasury address
        token.safeTransfer(treasuryAddress, amountTreasury);
        // Emit round Draw
        emit RoundReward(currentRoundId, amountTreasury, amountInject);
    }

    /**
     * @notice Inject funds
     * @param _roundId: round id
     * @param _amount: amount to inject in token
     * @dev Callable by owner or injector address
     */
    function injectFunds(uint256 _roundId, uint256 _amount) external onlyOwner {
        require(rounds[_roundId].status == RoundStatus.Open, ERROR_ROUND_NOT_OPEN);
        token.safeTransferFrom(address(msg.sender), address(this), _amount);
        rounds[_roundId].totalAmount += _amount;
        emit RoundInjection(_roundId, _amount);
    }

    /**
     * @notice It allows the admin to recover wrong tokens sent to the contract
     * @param _tokenAddress: the address of the token to withdraw
     * @param _tokenAmount: the number of token amount to withdraw
     * @dev Only callable by owner.
     */
    function recoverWrongTokens(address _tokenAddress, uint256 _tokenAmount) external onlyOwner {
        require(_tokenAddress != address(token), ERROR_WRONG_TOKEN_ADDRESS);
        IERC20(_tokenAddress).safeTransfer(address(msg.sender), _tokenAmount);
        emit AdminTokenRecovery(_tokenAddress, _tokenAmount);
    }

    /**
     * @notice Set the random generator
     * @dev The calls to functions are used to verify the new generator implements them properly.
     * Callable only by the contract owner
     * @param _randomGeneratorAddress: address of the random generator
     */
    function setRandomGenerator(address _randomGeneratorAddress) external override onlyOwner {
        randomGenerator = IRandomNumberGenerator(_randomGeneratorAddress);
        emit NewRandomGenerator(_randomGeneratorAddress);
    }

    /**
     *
     * @param _operatorAddress The lottery scheduler account used to run regular operations.
     * @dev Callable by owner
     */
    function setOperatorAddress(address _operatorAddress) external onlyOwner {
        require(_operatorAddress != address(0), ERROR_INVALID_ZERO_ADDRESS);
        operatorAddress = _operatorAddress;
    }

    /**
     *
     * @param _treasuryAddress The address in which the burn is sent
     * @dev Callable by owner
     */
    function setTreasuryAddress(address _treasuryAddress) external onlyOwner {
        require(_treasuryAddress != address(0), ERROR_INVALID_ZERO_ADDRESS);
        treasuryAddress = _treasuryAddress;
    }

    /**
     *
     * @param _triggerAddress The lottery scheduler account used to run regular operations.
     * @dev Callable by owner
     */
    function setTriggerAddress(address _triggerAddress) external onlyOwner {
        require(_triggerAddress != address(0), ERROR_INVALID_ZERO_ADDRESS);
        triggerAddress = _triggerAddress;
    }

    /**
     * @notice Return a list of lottery ids
     */
    function getLotteryIds() external view override returns (string[] memory) {
        return lotteryIds;
    }

    /**
     * @notice Return lottery by id
     * @param _lotteryId Id of lottery
     */
    function getLottery(string calldata _lotteryId) external view override returns (Lottery memory) {
        return lotteries[_lotteryId];
    }

    /**
     * @notice Return a list of round ids
     */
    function getRoundIds() external view override returns (uint256[] memory) {
        return roundIds;
    }

    /**
     * @notice Return round by id
     * @param _roundId Id of round
     */
    function getRound(uint256 _roundId) external view override returns (Round memory) {
        return rounds[_roundId];
    }

    /**
     * @notice Return a list of ticket ids
     */
    function getTicketIds() external view override returns (uint256[] memory) {
        return ticketIds;
    }

    /**
     * @notice Return a list of ticket ids by user address
     * @param _user: user address
     * @param _cursor: cursor to start where to retrieve the tickets
     * @param _size: the number of tickets to retrieve
     */
    function getTicketIdsByUser(
        address _user,
        uint256 _cursor,
        uint256 _size
    ) external view override returns (uint256[] memory ids, uint256 cursor) {
        uint256 numberTicketsBoughtAtLotteryId = ticketsPerUserId[_user].length;
        if (_size > (numberTicketsBoughtAtLotteryId - _cursor)) {
            _size = numberTicketsBoughtAtLotteryId - _cursor;
        }
        ids = new uint256[](_size);
        for (uint256 i = 0; i < _size; i++) {
            ids[i] = ticketsPerUserId[_user][i + _cursor];
        }
        cursor = _cursor + _size;
    }

    /**
     * @notice Return ticket by id
     * @param _ticketId Id of round
     */
    function getTicket(uint256 _ticketId) external view override returns (Ticket memory) {
        return tickets[_ticketId];
    }

    /**
     * @notice Find the winners and pay the prizes. the out reward will be added to inject
     * @param _lotteryId Id of lottery
     * @param _roundId Id of round
     * @param rewardAmount Reward amount share for winners
     * @dev Callable by internal
     */
    function _findWinnersAndReward(
        string calldata _lotteryId,
        uint256 _roundId,
        uint256 rewardAmount
    ) internal returns (uint256 outRewardValue) {
        outRewardValue = rewardAmount;
        uint[] memory winnersPerRule = new uint[](rulesPerLotteryId[_lotteryId].length);
        for (uint ticketIndex = 0; ticketIndex < ticketsPerRoundId[_roundId].length; ticketIndex++) {
            uint256 ticketId = ticketsPerRoundId[_roundId][ticketIndex];
            // Check if this ticket is eligible to win or not
            (bool isWin, uint matchRewardRule) = _checkIsWinTicket(ticketId, _lotteryId, _roundId);
            if (isWin) {
                tickets[ticketId].winStatus = isWin;
                tickets[ticketId].winRewardRule = matchRewardRule;
                winnersPerRule[matchRewardRule] += 1;
            }
        }

        uint256[] memory rewardsAmountPerRule = new uint256[](rulesPerLotteryId[_lotteryId].length);
        for (uint ruleIndex = 0; ruleIndex < winnersPerRule.length; ruleIndex++) {
            uint winnerPerRule = winnersPerRule[ruleIndex];
            if (winnerPerRule > 0) {
                uint256 rewardAmountPerRule = _calculateRewardAmountPerRule(_lotteryId, ruleIndex, rewardAmount);
                outRewardValue -= rewardAmountPerRule;
                uint256 rewardAmountPerTicket = rewardAmountPerRule.div(winnerPerRule);
                rewardsAmountPerRule[ruleIndex] = rewardAmountPerTicket;
            }
        }

        for (uint ticketIndex = 0; ticketIndex < ticketsPerRoundId[_roundId].length; ticketIndex++) {
            uint256 ticketId = ticketsPerRoundId[_roundId][ticketIndex];
            if (tickets[ticketId].winStatus) {
                uint256 rewardAmountPerRule = rewardsAmountPerRule[tickets[ticketId].winRewardRule];
                tickets[ticketId].winAmount = rewardAmountPerRule;
            }
        }
    }

    /**
     * @notice Return ticket by id
     * @param _lotteryId Id of lottery
     * @param _roundId Id of round
     * @return treasuryAmount Treasury fee on total prize
     * @return injectAmount Amount inject for the next round
     * @return rewardAmount Number of prizes to be divided among the winners
     */
    function _estimateReward(
        string memory _lotteryId,
        uint256 _roundId
    ) internal view returns (uint256 treasuryAmount, uint256 injectAmount, uint256 rewardAmount) {
        treasuryAmount = _percentageOf(rounds[_roundId].totalAmount, lotteries[_lotteryId].treasuryFeePercent);
        injectAmount = _percentageOf(rounds[_roundId].totalAmount, lotteries[_lotteryId].amountInjectNextRoundPercent);
        rewardAmount = rounds[_roundId].totalAmount.sub(treasuryAmount).sub(injectAmount);
    }

    /**
     *
     * @notice Check array of numbers is valid or not
     * @param _numbers Array of numbers need check in range LOTTERY require
     * @param _lottery LOTTERYs that users want to check
     */
    function _isValidNumbers(uint32[] memory _numbers, Lottery memory _lottery) internal pure returns (bool) {
        if (_numbers.length != _lottery.numberOfItems) {
            return false;
        }

        for (uint i = 0; i < _numbers.length; i++) {
            uint32 number = _numbers[i];
            if (number < _lottery.minValuePerItem || number > _lottery.maxValuePerItem) {
                return false;
            }
        }

        return true;
    }

    /**
     * @notice Calcuate final price for bulk of tickets
     * @param _lottery LOTTERYs that users want to buy tickets
     * @param _numberTickets Number of tickts want to by
     */
    function _caculateTotalPriceForBulkTickets(
        Lottery memory _lottery,
        uint256 _numberTickets
    ) internal pure returns (uint256) {
        return _lottery.pricePerTicket * _numberTickets;
    }

    /**
     * @notice Check if the ticket win or not. Returns the index of rule for ticket win
     * @param _ticketId Id of ticket
     * @param _lotteryId Id of lottery
     * @param _roundId Id of round
     * @return isWin Return true if ticket win
     * @return matchRewardRule Rule index rule match
     */
    function _checkIsWinTicket(
        uint256 _ticketId,
        string memory _lotteryId,
        uint256 _roundId
    ) internal view returns (bool isWin, uint matchRewardRule) {
        uint matchedNumbers = _matchNumbersCount(rounds[_roundId].winningNumbers, tickets[_ticketId].numbers);
        if (matchedNumbers != 0) {
            for (uint ruleIndex = 0; ruleIndex < rulesPerLotteryId[_lotteryId].length; ruleIndex++) {
                if (rulesPerLotteryId[_lotteryId][ruleIndex].matchNumber == matchedNumbers) {
                    isWin = true;
                    matchRewardRule = ruleIndex;
                    break;
                }
            }
        }
    }

    /**
     * @notice Calculate the amount to be paid for ticket win rule
     * @param _lotteryId Id of lottery
     * @param _ruleIndex Index of rule
     * @param _rewardAmount Total amount of reward
     */
    function _calculateRewardAmountPerRule(
        string memory _lotteryId,
        uint _ruleIndex,
        uint256 _rewardAmount
    ) internal view returns (uint256) {
        Rule memory rule = rulesPerLotteryId[_lotteryId][_ruleIndex];
        uint256 rewardAmountPerRule;
        if (rule.rewardUnit == RewardUnit.Percent) {
            rewardAmountPerRule = _percentageOf(_rewardAmount, rule.rewardValue);
        } else if (rule.rewardUnit == RewardUnit.Fixed) {
            rewardAmountPerRule = _rewardAmount - rule.rewardValue;
        }
        return rewardAmountPerRule;
    }

    /**
     * @notice Count the matching numbers between 2 arrays
     */
    function _matchNumbersCount(uint32[] memory _arr1, uint32[] memory _arr2) internal pure returns (uint) {
        uint count = 0;
        for (uint arr1Index = 0; arr1Index < _arr1.length; arr1Index++) {
            for (uint arr2Index = 0; arr2Index < _arr2.length; arr2Index++) {
                if (_arr1[arr1Index] == _arr2[arr2Index]) {
                    count++;
                }
            }
        }
        return count;
    }

    /**
     * @notice Calculate the treasury fee
     * @param _lotteryId Id of lottery
     * @param _roundId Id of round
     */
    function _calculateTreasuryFee(string memory _lotteryId, uint256 _roundId) internal view returns (uint256) {
        return _percentageOf(rounds[_roundId].totalAmount, lotteries[_lotteryId].treasuryFeePercent);
    }

    /**
     * @notice Calculate percentage value
     */
    function _percentageOf(uint256 amount, uint256 percent) internal pure returns (uint256) {
        require(percent >= 0 && percent <= 100, "INVALID_PERCENT_VALUE");
        return (amount.mul(percent)).div(100);
    }
    /* #endregion */
}

File 15 of 15 : StringUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

library String {
    /**
     * @notice Check string is empty or not
     * @param _str String
     */
    function isEmpty(string memory _str) internal pure returns (bool) {
        return bytes(_str).length == 0;
    }

    /**
     * @notice Compare two strings. Returns true if two strings are equal
     * @param _str1 String 1
     * @param _str2 String 2
     */
    function compareTwoStrings(string memory _str1, string memory _str2) internal pure returns (bool) {
        if (bytes(_str1).length != bytes(_str2).length) {
            return false;
        }
        return keccak256(abi.encodePacked(_str1)) == keccak256(abi.encodePacked(_str2));
    }
}

Settings
{
  "metadata": {
    "bytecodeHash": "none"
  },
  "optimizer": {
    "enabled": true,
    "runs": 2000
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AdminTokenRecovery","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"lotteryId","type":"string"},{"indexed":false,"internalType":"string","name":"verboseName","type":"string"},{"indexed":false,"internalType":"string","name":"picture","type":"string"},{"indexed":false,"internalType":"uint32","name":"numberOfItems","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"minValuePerItem","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"maxValuePerItem","type":"uint32"},{"indexed":false,"internalType":"uint256[]","name":"periodDays","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"periodHourOfDays","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"maxNumberTicketsPerBuy","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"pricePerTicket","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"treasuryFeePercent","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"amountInjectNextRoundPercent","type":"uint32"}],"name":"NewLottery","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"randomGeneratorAddress","type":"address"}],"name":"NewRandomGenerator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"ruleIndex","type":"uint256"},{"indexed":false,"internalType":"string","name":"lotteryId","type":"string"},{"indexed":false,"internalType":"uint32","name":"matchNumber","type":"uint32"},{"indexed":false,"internalType":"enum RewardUnit","name":"rewardUnit","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"rewardValue","type":"uint256"}],"name":"NewRewardRule","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalTickets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"RoundClose","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint32[]","name":"numbers","type":"uint32[]"}],"name":"RoundDraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"injectedAmount","type":"uint256"}],"name":"RoundInjection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"string","name":"lotteryId","type":"string"},{"indexed":false,"internalType":"uint256","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"drawDateTime","type":"uint256"}],"name":"RoundOpen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountTreasury","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountInjectNextRound","type":"uint256"}],"name":"RoundReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"claimer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"ticketIds","type":"uint256[]"}],"name":"TicketsClaim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"ticketIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TicketsPurchase","type":"event"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"},{"internalType":"string","name":"_picture","type":"string"},{"internalType":"string","name":"_verboseName","type":"string"},{"internalType":"uint32","name":"_numberOfItems","type":"uint32"},{"internalType":"uint32","name":"_minValuePerItem","type":"uint32"},{"internalType":"uint32","name":"_maxValuePerItem","type":"uint32"},{"internalType":"uint256[]","name":"_periodDays","type":"uint256[]"},{"internalType":"uint256","name":"_periodHourOfDays","type":"uint256"},{"internalType":"uint32","name":"_maxNumberTicketsPerBuy","type":"uint32"},{"internalType":"uint256","name":"_pricePerTicket","type":"uint256"},{"internalType":"uint32","name":"_treasuryFeePercent","type":"uint32"},{"internalType":"uint32","name":"_amountInjectNextRoundPercent","type":"uint32"}],"name":"addLottery","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"},{"internalType":"uint32[]","name":"_matchNumbers","type":"uint32[]"},{"internalType":"enum RewardUnit[]","name":"_rewardUnits","type":"uint8[]"},{"internalType":"uint256[]","name":"_rewardValues","type":"uint256[]"}],"name":"addRewardRules","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"amountInjectNextRoundPerLottery","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundId","type":"uint256"},{"internalType":"uint32[][]","name":"_tickets","type":"uint32[][]"}],"name":"buyTickets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_ticketIds","type":"uint256[]"}],"name":"claimTickets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"}],"name":"close","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"currentRoundIdPerLottery","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"}],"name":"draw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"}],"name":"getLottery","outputs":[{"components":[{"internalType":"string","name":"verboseName","type":"string"},{"internalType":"string","name":"picture","type":"string"},{"internalType":"uint32","name":"numberOfItems","type":"uint32"},{"internalType":"uint32","name":"minValuePerItem","type":"uint32"},{"internalType":"uint32","name":"maxValuePerItem","type":"uint32"},{"internalType":"uint256[]","name":"periodDays","type":"uint256[]"},{"internalType":"uint256","name":"periodHourOfDays","type":"uint256"},{"internalType":"uint32","name":"maxNumberTicketsPerBuy","type":"uint32"},{"internalType":"uint256","name":"pricePerTicket","type":"uint256"},{"internalType":"uint32","name":"treasuryFeePercent","type":"uint32"},{"internalType":"uint32","name":"amountInjectNextRoundPercent","type":"uint32"}],"internalType":"struct Lottery","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLotteryIds","outputs":[{"internalType":"string[]","name":"","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundId","type":"uint256"}],"name":"getRound","outputs":[{"components":[{"internalType":"uint32[]","name":"winningNumbers","type":"uint32[]"},{"internalType":"uint256","name":"drawDateTime","type":"uint256"},{"internalType":"uint256","name":"openTime","type":"uint256"},{"internalType":"uint256","name":"totalAmount","type":"uint256"},{"internalType":"uint256","name":"totalTickets","type":"uint256"},{"internalType":"uint256","name":"firstRoundId","type":"uint256"},{"internalType":"enum RoundStatus","name":"status","type":"uint8"}],"internalType":"struct Round","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRoundIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ticketId","type":"uint256"}],"name":"getTicket","outputs":[{"components":[{"internalType":"uint32[]","name":"numbers","type":"uint32[]"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"roundId","type":"uint256"},{"internalType":"bool","name":"winStatus","type":"bool"},{"internalType":"uint256","name":"winRewardRule","type":"uint256"},{"internalType":"uint256","name":"winAmount","type":"uint256"},{"internalType":"bool","name":"clamStatus","type":"bool"}],"internalType":"struct Ticket","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTicketIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_cursor","type":"uint256"},{"internalType":"uint256","name":"_size","type":"uint256"}],"name":"getTicketIdsByUser","outputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"injectFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"},{"internalType":"uint256","name":"_drawDateTime","type":"uint256"}],"name":"open","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"operatorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomGenerator","outputs":[{"internalType":"contract IRandomNumberGenerator","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"}],"name":"recoverWrongTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_lotteryId","type":"string"}],"name":"reward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"rulesPerLotteryId","outputs":[{"internalType":"uint32","name":"matchNumber","type":"uint32"},{"internalType":"enum RewardUnit","name":"rewardUnit","type":"uint8"},{"internalType":"uint256","name":"rewardValue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_operatorAddress","type":"address"}],"name":"setOperatorAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_randomGeneratorAddress","type":"address"}],"name":"setRandomGenerator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_treasuryAddress","type":"address"}],"name":"setTreasuryAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_triggerAddress","type":"address"}],"name":"setTriggerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasuryAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"triggerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a06040523480156200001157600080fd5b5060405162005a2e38038062005a2e8339810160408190526200003491620000ac565b600160005562000044336200005a565b60601b6001600160601b031916608052620000de565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600060208284031215620000bf57600080fd5b81516001600160a01b0381168114620000d757600080fd5b9392505050565b60805160601c61590e62000120600039600081816104d301528181610767015281816108d301528181610a470152818161142801526132e4015261590e6000f3fe608060405234801561001057600080fd5b50600436106101ef5760003560e01c80638f5b3d4b1161010f578063afbf442e116100a2578063dbdcb62711610071578063dbdcb62714610486578063dcbad90d146104a8578063f2fde38b146104bb578063fc0c546a146104ce57600080fd5b8063afbf442e14610437578063c42998e61461043f578063c5f956af14610452578063daaa7ccb1461046557600080fd5b80639f5b1bb3116100de5780639f5b1bb3146103de578063a348b2ea146103f1578063a8bd110014610404578063aebba34f1461042457600080fd5b80638f5b3d4b1461037857806399979ce4146103a35780639cf13f22146103b65780639d869eac146103cb57600080fd5b80634bc19fee116101875780637dc379fa116101565780637dc379fa1461031457806388c61855146103345780638da5cb5b146103475780638f1327c01461035857600080fd5b80634bc19fee146102d35780634e52aa91146102e65780636605bfda146102f9578063715018a61461030c57600080fd5b80632f1d5a60116101c35780632f1d5a6014610285578063352ea987146102985780633f138d4b146102ad578063471aeab4146102c057600080fd5b806291be55146101f4578063127effb214610224578063178bd8121461023757806327b0229e14610270575b600080fd5b601054610207906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b600e54610207906001600160a01b031681565b610262610245366004614d12565b8051602081830181018051600c8252928201919093012091525481565b60405190815260200161021b565b61028361027e366004614bcc565b6104f5565b005b610283610293366004614a2e565b6107de565b6102a0610871565b60405161021b9190615193565b6102836102bb366004614a49565b6108c9565b6102836102ce366004614f30565b6109b6565b6102836102e1366004614a2e565b610ace565b6102836102f4366004614c02565b610b37565b610283610307366004614a2e565b610f97565b61028361102a565b610327610322366004614ecb565b61103e565b60405161021b919061548f565b610283610342366004614aa6565b611179565b6001546001600160a01b0316610207565b61036b610366366004614ecb565b6114a3565b60405161021b9190615419565b610262610386366004614d12565b8051602081830181018051600b8252928201919093012091525481565b6102836103b1366004614cc6565b6115ab565b6103be611a2b565b60405161021b9190615113565b6102836103d9366004614bcc565b611b04565b6102836103ec366004614d47565b611e6f565b6102836103ff366004614a2e565b612546565b610417610412366004614bcc565b6125d9565b60405161021b919061531d565b610283610432366004614bcc565b612860565b6102a0612dca565b61028361044d366004614ee4565b612e20565b600f54610207906001600160a01b031681565b610478610473366004614a73565b61366c565b60405161021b9291906151a6565b610499610494366004614e86565b613779565b60405161021b9392919061555d565b601154610207906001600160a01b031681565b6102836104c9366004614a2e565b6137d6565b6102077f000000000000000000000000000000000000000000000000000000000000000081565b6010546001600160a01b03163314806105185750600e546001600160a01b031633145b6040518060400160405280601e81526020017f4552524f525f4f4e4c595f545249474745525f4f525f4f50455241544f520000815250906105755760405162461bcd60e51b815260040161056c919061524b565b60405180910390fd5b506105b582828080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061386692505050565b156040518060400160405280601881526020017f4552524f525f494e56414c49445f4c4f54544552595f494400000000000000008152509061060a5760405162461bcd60e51b815260040161056c919061524b565b506000600b838360405161061f929190615067565b9081526020016040518091039020549050806000141580156106665750600160008281526005602052604090206006015460ff1660038111156106645761066461574a565b145b6040518060400160405280601d81526020017f4552524f525f4e4f545f54494d455f5245574152445f4c4f5454455259000000815250906106ba5760405162461bcd60e51b815260040161056c919061524b565b506000818152600560209081526040808320600601805460ff191660031790558051601f86018390048302810183019091528481528291829161071991889088908190840183828082843760009201919091525088925061386b915050565b925092509250600061072d8787878561393f565b90506107398184615642565b925082600c888860405161074e929190615067565b90815260405190819003602001902055600f54610799907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03908116911686613ca4565b604080518581526020810185905286917f440302d3085437e8625e56b3455a9df10137442e3939d7f75d25cc3c62c81e3a91015b60405180910390a250505050505050565b6107e6613d4d565b60408051808201909152601a81527f4552524f525f494e56414c49445f5a45524f5f4144445245535300000000000060208201526001600160a01b0382166108415760405162461bcd60e51b815260040161056c919061524b565b50600e805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b606060078054806020026020016040519081016040528092919081815260200182805480156108bf57602002820191906000526020600020905b8154815260200190600101908083116108ab575b5050505050905090565b6108d1613d4d565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614156040518060400160405280601981526020017f4552524f525f57524f4e475f544f4b454e5f41444452455353000000000000008152509061095b5760405162461bcd60e51b815260040161056c919061524b565b506109706001600160a01b0383163383613ca4565b604080516001600160a01b0384168152602081018390527f74545154aac348a3eac92596bd1971957ca94795f4e954ec5f613b55fab78129910160405180910390a15050565b6109be613d4d565b60008281526005602052604081206006015460ff1660038111156109e4576109e461574a565b146040518060400160405280601481526020017f4552524f525f524f554e445f4e4f545f4f50454e00000000000000000000000081525090610a395760405162461bcd60e51b815260040161056c919061524b565b50610a6f6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084613da7565b60008281526005602052604081206003018054839290610a90908490615642565b909155505060405181815282907f3776e292653b1206ba03a9aec907ba31a558a5c4c8d60522fe5ee2da80aa190c9060200160405180910390a25050565b610ad6613d4d565b6011805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0383169081179091556040519081527f383f8cb39dfa7c3fb901a460dd449ea924868f0a92ff03da64740fffa5f1de629060200160405180910390a150565b600e5460408051808201909152601381527f4552524f525f4f4e4c595f4f50455241544f52000000000000000000000000006020820152906001600160a01b03163314610b975760405162461bcd60e51b815260040161056c919061524b565b508483148015610ba657508281145b6040518060400160405280601381526020017f4552524f525f494e56414c49445f52554c45530000000000000000000000000081525090610bfa5760405162461bcd60e51b815260040161056c919061524b565b5060005b85811015610f8c57610c4589898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061386692505050565b156040518060400160405280601881526020017f4552524f525f494e56414c49445f4c4f54544552595f4944000000000000000081525090610c9a5760405162461bcd60e51b815260040161056c919061524b565b506000878783818110610caf57610caf615760565b9050602002016020810190610cc49190614f52565b63ffffffff16116040518060400160405280601f81526020017f4552524f525f494e56414c49445f52554c455f4d415443485f4e554d4245520081525090610d1f5760405162461bcd60e51b815260040161056c919061524b565b506000838383818110610d3457610d34615760565b90506020020135116040518060400160405280601f81526020017f4552524f525f494e56414c49445f52554c455f5245574152445f56414c55450081525090610d905760405162461bcd60e51b815260040161056c919061524b565b50600d8989604051610da3929190615067565b90815260200160405180910390206040518060600160405280898985818110610dce57610dce615760565b9050602002016020810190610de39190614f52565b63ffffffff168152602001878785818110610e0057610e00615760565b9050602002016020810190610e159190614bab565b6001811115610e2657610e2661574a565b8152602001858585818110610e3d57610e3d615760565b602090810292909201359092528354600180820186556000958652948290208451600290920201805463ffffffff19811663ffffffff90931692831782559285015194959094935084927fffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000001690911790640100000000908490811115610ec557610ec561574a565b0217905550604082015181600101555050807f96e3df16072f17d05559700972c895ee63d8866e757f99e3132cbde933df64dd8a8a8a8a86818110610f0c57610f0c615760565b9050602002016020810190610f219190614f52565b898987818110610f3357610f33615760565b9050602002016020810190610f489190614bab565b888888818110610f5a57610f5a615760565b90506020020135604051610f7295949392919061520c565b60405180910390a280610f8481615719565b915050610bfe565b505050505050505050565b610f9f613d4d565b60408051808201909152601a81527f4552524f525f494e56414c49445f5a45524f5f4144445245535300000000000060208201526001600160a01b038216610ffa5760405162461bcd60e51b815260040161056c919061524b565b50600f805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b611032613d4d565b61103c6000613dfe565b565b61108b6040518060e001604052806060815260200160006001600160a01b031681526020016000815260200160001515815260200160008152602001600081526020016000151581525090565b600082815260086020908152604091829020825181546101009381028201840190945260e08101848152909391928492849184018282801561111857602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116110db5790505b505050918352505060018201546001600160a01b0316602082015260028201546040820152600382015460ff9081161515606083015260048301546080830152600583015460a0830152600690920154909116151560c09091015292915050565b60408051808201909152601a81527f4552524f525f434f4e54524143545f4e4f545f414c4c4f5745440000000000006020820152333b156111cd5760405162461bcd60e51b815260040161056c919061524b565b506040805180820190915260208082527f4552524f525f50524f58595f434f4e54524143545f4e4f545f414c4c4f574544908201523332146112225760405162461bcd60e51b815260040161056c919061524b565b5061122b613e5d565b60408051808201909152601381527f4552524f525f5449434b4554535f454d5054590000000000000000000000000060208201528161127d5760405162461bcd60e51b815260040161056c919061524b565b506000805b8281101561141a57600084848381811061129e5761129e615760565b6020908102929092013560008181526008909352604090922060010154919250506001600160a01b031633146113165760405162461bcd60e51b815260206004820152601060248201527f4552524f525f4f4e4c595f4f574e455200000000000000000000000000000000604482015260640161056c565b60008181526008602052604090206003015460ff166113775760405162461bcd60e51b815260206004820152601460248201527f4552524f525f5449434b45545f4e4f545f57494e000000000000000000000000604482015260640161056c565b60008181526008602052604090206006015460ff16156113d95760405162461bcd60e51b815260206004820152601b60248201527f4552524f525f4f4e4c595f434c41494d5f5052495a455f4f4e43450000000000604482015260640161056c565b600081815260086020526040902060068101805460ff19166001179055600501546114049084615642565b925050808061141290615719565b915050611282565b5061144f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163383613ca4565b336001600160a01b03167f8dcfd64ffe78197964feae30ea523daef02948dd2ab6e6f33fae297078878b4082858560405161148c93929190615501565b60405180910390a25061149f6001600055565b5050565b6114ab614659565b600082815260056020908152604091829020825181546101009381028201840190945260e08101848152909391928492849184018282801561153857602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116114fb5790505b50505091835250506001820154602082015260028201546040820152600380830154606083015260048301546080830152600583015460a0830152600683015460c09092019160ff16908111156115915761159161574a565b60038111156115a2576115a261574a565b90525092915050565b6010546001600160a01b03163314806115ce5750600e546001600160a01b031633145b6040518060400160405280601e81526020017f4552524f525f4f4e4c595f545249474745525f4f525f4f50455241544f520000815250906116225760405162461bcd60e51b815260040161056c919061524b565b5061166283838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061386692505050565b156040518060400160405280601881526020017f4552524f525f494e56414c49445f4c4f54544552595f49440000000000000000815250906116b75760405162461bcd60e51b815260040161056c919061524b565b5060408051808201909152601d81527f4552524f525f494e56414c49445f524f554e445f445241575f54494d4500000060208201528161170a5760405162461bcd60e51b815260040161056c919061524b565b506000600b848460405161171f929190615067565b908152602001604051809103902054905080600014806117645750600360008281526005602052604090206006015460ff1660038111156117625761176261574a565b145b6040518060400160405280601b81526020017f4552524f525f4e4f545f54494d455f4f50454e5f4c4f54544552590000000000815250906117b85760405162461bcd60e51b815260040161056c919061524b565b506000600b85856040516117cd929190615067565b90815260200160405180910390205490506117ec601380546001019055565b60006117f760135490565b905080600b878760405161180c929190615067565b90815260408051602092819003830190209290925560008381526006909152206118379087876146a6565b506000600c878760405161184c929190615067565b90815260200160405180910390205490506040518060e001604052806003898960405161187a929190615067565b9081526040519081900360200190206002015463ffffffff1667ffffffffffffffff8111156118ab576118ab615776565b6040519080825280602002602001820160405280156118d4578160200160208202803683370190505b508152602001868152602001428152602001828152602001600081526020018481526020016000600381111561190c5761190c61574a565b905260008381526005602090815260409091208251805191926119349284929091019061472a565b506020820151816001015560408201518160020155606082015181600301556080820151816004015560a0820151816005015560c08201518160060160006101000a81548160ff021916908360038111156119915761199161574a565b0217905550506004805460018101825560009182527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b01849055604051909150600c906119e1908a908a90615067565b908152602001604051809103902081905550817f9b8d9de88ab686509e9a71a83c4b6bb33a1ab0d14fc9812d35626d36f03cf550888884428a6040516107cd9594939291906151db565b60606002805480602002602001604051908101604052809291908181526020016000905b82821015611afb578382906000526020600020018054611a6e906156de565b80601f0160208091040260200160405190810160405280929190818152602001828054611a9a906156de565b8015611ae75780601f10611abc57610100808354040283529160200191611ae7565b820191906000526020600020905b815481529060010190602001808311611aca57829003601f168201915b505050505081526020019060010190611a4f565b50505050905090565b6010546001600160a01b0316331480611b275750600e546001600160a01b031633145b6040518060400160405280601e81526020017f4552524f525f4f4e4c595f545249474745525f4f525f4f50455241544f52000081525090611b7b5760405162461bcd60e51b815260040161056c919061524b565b50611bbb82828080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061386692505050565b156040518060400160405280601881526020017f4552524f525f494e56414c49445f4c4f54544552595f4944000000000000000081525090611c105760405162461bcd60e51b815260040161056c919061524b565b506000600b8383604051611c25929190615067565b908152602001604051809103902054905080600014158015611c6a575060008181526005602052604081206006015460ff166003811115611c6857611c6861574a565b145b6040518060400160405280601c81526020017f4552524f525f4e4f545f54494d455f434c4f53455f4c4f54544552590000000081525090611cbe5760405162461bcd60e51b815260040161056c919061524b565b5060008181526005602052604090819020600601805460ff1916600217905560115490516001600160a01b03909116906306385d9f908390600390611d069088908890615067565b9081526040519081900360200181206002015463ffffffff1690600390611d309089908990615067565b9081526040519081900360200181206002015463ffffffff6401000000009091041690600390611d63908a908a90615067565b908152604051908190036020018120600201547fffffffff0000000000000000000000000000000000000000000000000000000060e087901b168252600482019490945263ffffffff9283166024820152908216604482015268010000000000000000909204166064820152608401600060405180830381600087803b158015611dec57600080fd5b505af1158015611e00573d6000803e3d6000fd5b50505060008281526005602052604090819020600381015460049091015491518493507fd48295577edadfd05d0bc2792ea7fc9cf54a7c6305271b9e5fa310e30698701892611e62929142909283526020830191909152604082015260600190565b60405180910390a2505050565b600e5460408051808201909152601381527f4552524f525f4f4e4c595f4f50455241544f52000000000000000000000000006020820152906001600160a01b03163314611ecf5760405162461bcd60e51b815260040161056c919061524b565b508b5115156040518060400160405280601881526020017f4552524f525f494e56414c49445f4c4f54544552595f4944000000000000000081525090611f285760405162461bcd60e51b815260040161056c919061524b565b508a5115156040518060400160405280601d81526020017f4552524f525f494e56414c49445f4c4f54544552595f5049435455524500000081525090611f815760405162461bcd60e51b815260040161056c919061524b565b50895115156040518060600160405280602281526020016158166022913990611fbd5760405162461bcd60e51b815260040161056c919061524b565b5060008963ffffffff16116040518060600160405280602581526020016157c86025913990611fff5760405162461bcd60e51b815260040161056c919061524b565b5060008863ffffffff161160405180606001604052806029815260200161579f60299139906120415760405162461bcd60e51b815260040161056c919061524b565b5060008763ffffffff1611801561205d575063ffffffff878116105b60405180606001604052806029815260200161585960299139906120945760405162461bcd60e51b815260040161056c919061524b565b50600086511160405180606001604052806021815260200161583860219139906120d15760405162461bcd60e51b815260040161056c919061524b565b506000851180156120e3575060188511155b6040518060600160405280602981526020016157ed602991399061211a5760405162461bcd60e51b815260040161056c919061524b565b5060008463ffffffff16118015612136575063ffffffff848116105b6040518060600160405280603081526020016158d2603091399061216d5760405162461bcd60e51b815260040161056c919061524b565b50600083116040518060600160405280602681526020016158ac60269139906121a95760405162461bcd60e51b815260040161056c919061524b565b506040805160608101909152602a808252600191906158826020830139906121e45760405162461bcd60e51b815260040161056c919061524b565b5061229660038d6040516121f8919061504b565b9081526040519081900360200190208054612212906156de565b80601f016020809104026020016040519081016040528092919081815260200182805461223e906156de565b801561228b5780601f106122605761010080835404028352916020019161228b565b820191906000526020600020905b81548152906001019060200180831161226e57829003601f168201915b50505050508b613eb7565b156040518060400160405280601c81526020017f4552524f525f4c4f54544552595f414c52454144595f45584953545300000000815250906122eb5760405162461bcd60e51b815260040161056c919061524b565b506040518061016001604052808b81526020018c81526020018a63ffffffff1681526020018963ffffffff1681526020018863ffffffff1681526020018781526020018681526020018563ffffffff1681526020018481526020018363ffffffff1681526020018263ffffffff1681525060038d60405161236c919061504b565b908152602001604051809103902060008201518160000190805190602001906123969291906147d4565b5060208281015180516123af92600185019201906147d4565b5060408201516002820180546060850151608086015163ffffffff90811668010000000000000000027fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff9282166401000000000267ffffffffffffffff199094169190951617919091171691909117905560a0820151805161243b916003840191602090910190614848565b5060c0820151600482015560e082015160058201805463ffffffff191663ffffffff9283161790556101008301516006830155610120830151600790920180546101409094015192821667ffffffffffffffff19909416939093176401000000009290911691909102179055600280546001810182556000919091528c516124ea917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace019060208f01906147d4565b507ff57d5fca604889463d6bd5d985bc555c27e9ab3018e6f374a05ad34fcfb692e48c8b8d8c8c8c8c8c8c8c8c8c6040516125309c9b9a9998979695949392919061525e565b60405180910390a1505050505050505050505050565b61254e613d4d565b60408051808201909152601a81527f4552524f525f494e56414c49445f5a45524f5f4144445245535300000000000060208201526001600160a01b0382166125a95760405162461bcd60e51b815260040161056c919061524b565b506010805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b604080516101608101825260608082526020820181905260009282018390528082018390526080820183905260a082015260c0810182905260e081018290526101008101829052610120810182905261014081019190915260038383604051612643929190615067565b90815260200160405180910390206040518061016001604052908160008201805461266d906156de565b80601f0160208091040260200160405190810160405280929190818152602001828054612699906156de565b80156126e65780601f106126bb576101008083540402835291602001916126e6565b820191906000526020600020905b8154815290600101906020018083116126c957829003601f168201915b505050505081526020016001820180546126ff906156de565b80601f016020809104026020016040519081016040528092919081815260200182805461272b906156de565b80156127785780601f1061274d57610100808354040283529160200191612778565b820191906000526020600020905b81548152906001019060200180831161275b57829003601f168201915b5050509183525050600282015463ffffffff80821660208085019190915264010000000083048216604080860191909152680100000000000000009093049091166060840152600384018054835181840281018401909452808452608090940193909183018282801561280a57602002820191906000526020600020905b8154815260200190600101908083116127f6575b505050918352505060048201546020820152600582015463ffffffff9081166040830152600683015460608301526007909201548083166080830152640100000000900490911660a09091015290505b92915050565b6010546001600160a01b03163314806128835750600e546001600160a01b031633145b6040518060400160405280601e81526020017f4552524f525f4f4e4c595f545249474745525f4f525f4f50455241544f520000815250906128d75760405162461bcd60e51b815260040161056c919061524b565b5061291782828080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061386692505050565b156040518060400160405280601881526020017f4552524f525f494e56414c49445f4c4f54544552595f494400000000000000008152509061296c5760405162461bcd60e51b815260040161056c919061524b565b506000600b8383604051612981929190615067565b9081526020016040518091039020549050806000141580156129c85750600260008281526005602052604090206006015460ff1660038111156129c6576129c661574a565b145b6040518060400160405280601b81526020017f4552524f525f4e4f545f54494d455f445241575f4c4f5454455259000000000081525090612a1c5760405162461bcd60e51b815260040161056c919061524b565b506011546040517faea2035f000000000000000000000000000000000000000000000000000000008152600481018390526000916001600160a01b03169063aea2035f9060240160006040518083038186803b158015612a7b57600080fd5b505afa158015612a8f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ab79190810190614ae8565b9050612ce88160038686604051612acf929190615067565b908152602001604051809103902060405180610160016040529081600082018054612af9906156de565b80601f0160208091040260200160405190810160405280929190818152602001828054612b25906156de565b8015612b725780601f10612b4757610100808354040283529160200191612b72565b820191906000526020600020905b815481529060010190602001808311612b5557829003601f168201915b50505050508152602001600182018054612b8b906156de565b80601f0160208091040260200160405190810160405280929190818152602001828054612bb7906156de565b8015612c045780601f10612bd957610100808354040283529160200191612c04565b820191906000526020600020905b815481529060010190602001808311612be757829003601f168201915b5050509183525050600282015463ffffffff808216602080850191909152640100000000830482166040808601919091526801000000000000000090930490911660608401526003840180548351818402810184019094528084526080909401939091830182828015612c9657602002820191906000526020600020905b815481526020019060010190808311612c82575b505050918352505060048201546020820152600582015463ffffffff9081166040830152600683015460608301526007909201548083166080830152640100000000900490911660a090910152613f21565b6040518060400160405280601d81526020017f4552524f525f494e56414c49445f57494e4e494e475f4e554d4245525300000081525090612d3c5760405162461bcd60e51b815260040161056c919061524b565b50600082815260056020908152604090912060068101805460ff191660011790558251612d6b9284019061472a565b50600b8484604051612d7e929190615067565b9081526020016040518091039020547f7c3b778ef5eff450bcf7fabd2ad987446c7af9b392328161101b7183ba7a833482604051612dbc91906151c8565b60405180910390a250505050565b606060048054806020026020016040519081016040528092919081815260200182805480156108bf57602002820191906000526020600020908154815260200190600101908083116108ab575050505050905090565b60408051808201909152601a81527f4552524f525f434f4e54524143545f4e4f545f414c4c4f5745440000000000006020820152333b15612e745760405162461bcd60e51b815260040161056c919061524b565b506040805180820190915260208082527f4552524f525f50524f58595f434f4e54524143545f4e4f545f414c4c4f57454490820152333214612ec95760405162461bcd60e51b815260040161056c919061524b565b50612ed2613e5d565b60408051808201909152601381527f4552524f525f5449434b4554535f454d50545900000000000000000000000000602082015281612f245760405162461bcd60e51b815260040161056c919061524b565b5060008381526005602052604081206006015460ff166003811115612f4b57612f4b61574a565b146040518060400160405280601581526020017f4552524f525f524f554e445f49535f434c4f534544000000000000000000000081525090612fa05760405162461bcd60e51b815260040161056c919061524b565b50600560008481526020019081526020016000206001015442106040518060400160405280601581526020017f4552524f525f524f554e445f49535f434c4f53454400000000000000000000008152509061300e5760405162461bcd60e51b815260040161056c919061524b565b5060008381526006602052604090819020905160039161302d91615077565b90815260408051918290036020908101832060050154838301909252601383527f4552524f525f5449434b4554535f4c494d4954000000000000000000000000009083015263ffffffff168211156130985760405162461bcd60e51b815260040161056c919061524b565b5060008381526006602052604080822090516132d5916003916130bb9190615077565b9081526020016040518091039020604051806101600160405290816000820180546130e5906156de565b80601f0160208091040260200160405190810160405280929190818152602001828054613111906156de565b801561315e5780601f106131335761010080835404028352916020019161315e565b820191906000526020600020905b81548152906001019060200180831161314157829003601f168201915b50505050508152602001600182018054613177906156de565b80601f01602080910402602001604051908101604052809291908181526020018280546131a3906156de565b80156131f05780601f106131c5576101008083540402835291602001916131f0565b820191906000526020600020905b8154815290600101906020018083116131d357829003601f168201915b5050509183525050600282015463ffffffff80821660208085019190915264010000000083048216604080860191909152680100000000000000009093049091166060840152600384018054835181840281018401909452808452608090940193909183018282801561328257602002820191906000526020600020905b81548152602001906001019080831161326e575b505050918352505060048201546020820152600582015463ffffffff9081166040830152600683015460608301526007909201548083166080830152640100000000900490911660a09091015283613fc1565b905061330c6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084613da7565b6000848152600560205260408120600301805483929061332d908490615642565b909155505060008481526005602052604081206004018054849290613353908490615642565b90915550600090508267ffffffffffffffff81111561337457613374615776565b60405190808252806020026020018201604052801561339d578160200160208202803683370190505b50905060005b838110156136165760008585838181106133bf576133bf615760565b90506020028101906133d19190615585565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201829052508b8152600660205260409081902090519495506134269486945060039350612acf9250615077565b6040518060400160405280601481526020017f4552524f525f494e56414c49445f5449434b45540000000000000000000000008152509061347a5760405162461bcd60e51b815260040161056c919061524b565b50613489601280546001019055565b6040805160e0810182528281523360208201529081018890526000606082018190526080820181905260a0820181905260c082018190526008906134cc60125490565b81526020808201929092526040016000208251805191926134f29284929091019061472a565b5060208201516001820180546001600160a01b0390921673ffffffffffffffffffffffffffffffffffffffff1990921691909117905560408201516002820155606082015160038201805491151560ff199283161790556080830151600483015560a0830151600583015560c0909201516006909101805491151591909216179055600761357f60125490565b81546001810183556000928352602080842090910191909155338252600990526040902060125481546001810183556000928352602080842090910191909155888252600a905260409020601254815460018101835560009283526020909220909101556012548383815181106135f8576135f8615760565b6020908102919091010152508061360e81615719565b9150506133a3565b5084336001600160a01b03167ffa3c3e28ed4ef210c43bc42ec332fb9260d3b6d7b7ddd85eda76fb8d44438eb183856040516136539291906151a6565b60405180910390a350506136676001600055565b505050565b6001600160a01b03831660009081526009602052604081205460609190613693858261569b565b8411156136a7576136a4858261569b565b93505b8367ffffffffffffffff8111156136c0576136c0615776565b6040519080825280602002602001820160405280156136e9578160200160208202803683370190505b50925060005b84811015613763576001600160a01b03871660009081526009602052604090206137198783615642565b8154811061372957613729615760565b906000526020600020015484828151811061374657613746615760565b60209081029190910101528061375b81615719565b9150506136ef565b5061376e8486615642565b915050935093915050565b8151602081840181018051600d8252928201918501919091209190528054829081106137a457600080fd5b60009182526020909120600290910201805460019091015463ffffffff8216935064010000000090910460ff16915083565b6137de613d4d565b6001600160a01b03811661385a5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161056c565b61386381613dfe565b50565b511590565b60008060006138b8600560008681526020019081526020016000206003015460038760405161389a919061504b565b9081526040519081900360200190206007015463ffffffff16613fdb565b925061390b60056000868152602001908152602001600020600301546003876040516138e4919061504b565b9081526040519081900360200190206007015463ffffffff64010000000090910416613fdb565b6000858152600560205260409020600301549092506139369083906139309086614043565b90614043565b90509250925092565b60008190506000600d8686604051613958929190615067565b9081526040519081900360200190205467ffffffffffffffff81111561398057613980615776565b6040519080825280602002602001820160405280156139a9578160200160208202803683370190505b50905060005b6000858152600a6020526040902054811015613aaa576000858152600a602052604081208054839081106139e5576139e5615760565b90600052602060002001549050600080613a37838b8b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508d925061404f915050565b915091508115613a9457600083815260086020526040902060038101805460ff19168415151790556004018190558451600190869083908110613a7c57613a7c615760565b60200260200101818151613a909190615642565b9052505b5050508080613aa290615719565b9150506139af565b506000600d8787604051613abf929190615067565b9081526040519081900360200190205467ffffffffffffffff811115613ae757613ae7615776565b604051908082528060200260200182016040528015613b10578160200160208202803683370190505b50905060005b8251811015613bdc576000838281518110613b3357613b33615760565b602002602001015190506000811115613bc9576000613b8b8a8a8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508792508b91506142109050565b9050613b97818761569b565b95506000613ba5828461431d565b905080858581518110613bba57613bba615760565b60200260200101818152505050505b5080613bd481615719565b915050613b16565b5060005b6000868152600a6020526040902054811015613c99576000868152600a60205260408120805483908110613c1657613c16615760565b6000918252602080832090910154808352600890915260409091206003015490915060ff1615613c865760008181526008602052604081206004015484518591908110613c6557613c65615760565b60209081029190910181015160008481526008909252604090912060050155505b5080613c9181615719565b915050613be0565b505050949350505050565b6040516001600160a01b0383166024820152604481018290526136679084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152614329565b6001546001600160a01b0316331461103c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161056c565b6040516001600160a01b0380851660248301528316604482015260648101829052613df89085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401613ce9565b50505050565b600180546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60026000541415613eb05760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161056c565b6002600055565b60008151835114613eca5750600061285a565b81604051602001613edb919061504b565b6040516020818303038152906040528051906020012083604051602001613f02919061504b565b6040516020818303038152906040528051906020012014905092915050565b6000816040015163ffffffff16835114613f3d5750600061285a565b60005b8351811015613fb7576000848281518110613f5d57613f5d615760565b60200260200101519050836060015163ffffffff168163ffffffff161080613f945750836080015163ffffffff168163ffffffff16115b15613fa45760009250505061285a565b5080613faf81615719565b915050613f40565b5060019392505050565b600081836101000151613fd4919061567c565b9392505050565b6000606482111561402e5760405162461bcd60e51b815260206004820152601560248201527f494e56414c49445f50455243454e545f56414c55450000000000000000000000604482015260640161056c565b613fd4606461403d858561440e565b9061431d565b6000613fd4828461569b565b600081815260056020908152604080832080548251818502810185019093528083528493849361416893909290918301828280156140d857602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161409b5790505b50505060008a8152600860209081526040918290208054835181840281018401909452808452929450925083018282801561415e57602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116141215790505b505050505061441a565b905080156142075760005b600d86604051614183919061504b565b908152604051908190036020019020548110156142055781600d876040516141ab919061504b565b908152602001604051809103902082815481106141ca576141ca615760565b600091825260209091206002909102015463ffffffff1614156141f35760019350809250614205565b806141fd81615719565b915050614173565b505b50935093915050565b600080600d85604051614223919061504b565b9081526020016040518091039020848154811061424257614242615760565b60009182526020918290206040805160608101909152600290920201805463ffffffff81168352919290919083019060ff64010000000090910416600181111561428e5761428e61574a565b600181111561429f5761429f61574a565b8152600191909101546020909101529050600080826020015160018111156142c9576142c961574a565b14156142e4576142dd848360400151613fdb565b9050614314565b6001826020015160018111156142fc576142fc61574a565b1415614314576040820151614311908561569b565b90505b95945050505050565b6000613fd4828461565a565b600061437e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166144b59092919063ffffffff16565b805190915015613667578080602001905181019061439c9190614b89565b6136675760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161056c565b6000613fd4828461567c565b600080805b84518110156144ad5760005b845181101561449a5784818151811061444657614446615760565b602002602001015163ffffffff1686838151811061446657614466615760565b602002602001015163ffffffff161415614488578261448481615719565b9350505b8061449281615719565b91505061442b565b50806144a581615719565b91505061441f565b509392505050565b60606144c484846000856144cc565b949350505050565b6060824710156145445760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161056c565b600080866001600160a01b03168587604051614560919061504b565b60006040518083038185875af1925050503d806000811461459d576040519150601f19603f3d011682016040523d82523d6000602084013e6145a2565b606091505b50915091506145b3878383876145be565b979650505050505050565b6060831561462a578251614623576001600160a01b0385163b6146235760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161056c565b50816144c4565b6144c4838381511561463f5781518083602001fd5b8060405162461bcd60e51b815260040161056c919061524b565b6040518060e00160405280606081526020016000815260200160008152602001600081526020016000815260200160008152602001600060038111156146a1576146a161574a565b905290565b8280546146b2906156de565b90600052602060002090601f0160209004810192826146d4576000855561471a565b82601f106146ed5782800160ff1982351617855561471a565b8280016001018555821561471a579182015b8281111561471a5782358255916020019190600101906146ff565b50614726929150614882565b5090565b8280548282559060005260206000209060070160089004810192821561471a5791602002820160005b8382111561479757835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302614753565b80156147c75782816101000a81549063ffffffff0219169055600401602081600301049283019260010302614797565b5050614726929150614882565b8280546147e0906156de565b90600052602060002090601f016020900481019282614802576000855561471a565b82601f1061481b57805160ff191683800117855561471a565b8280016001018555821561471a579182015b8281111561471a57825182559160200191906001019061482d565b82805482825590600052602060002090810192821561471a579160200282018281111561471a57825182559160200191906001019061482d565b5b808211156147265760008155600101614883565b80356001600160a01b03811681146148ae57600080fd5b919050565b60008083601f8401126148c557600080fd5b50813567ffffffffffffffff8111156148dd57600080fd5b6020830191508360208260051b85010111156148f857600080fd5b9250929050565b600082601f83011261491057600080fd5b813560206149256149208361561e565b6155ed565b80838252828201915082860187848660051b890101111561494557600080fd5b60005b8581101561496457813584529284019290840190600101614948565b5090979650505050505050565b60008083601f84011261498357600080fd5b50813567ffffffffffffffff81111561499b57600080fd5b6020830191508360208285010111156148f857600080fd5b600082601f8301126149c457600080fd5b813567ffffffffffffffff8111156149de576149de615776565b6149f16020601f19601f840116016155ed565b818152846020838601011115614a0657600080fd5b816020850160208301376000918101602001919091529392505050565b80356148ae8161578c565b600060208284031215614a4057600080fd5b613fd482614897565b60008060408385031215614a5c57600080fd5b614a6583614897565b946020939093013593505050565b600080600060608486031215614a8857600080fd5b614a9184614897565b95602085013595506040909401359392505050565b60008060208385031215614ab957600080fd5b823567ffffffffffffffff811115614ad057600080fd5b614adc858286016148b3565b90969095509350505050565b60006020808385031215614afb57600080fd5b825167ffffffffffffffff811115614b1257600080fd5b8301601f81018513614b2357600080fd5b8051614b316149208261561e565b80828252848201915084840188868560051b8701011115614b5157600080fd5b600094505b83851015614b7d578051614b698161578c565b835260019490940193918501918501614b56565b50979650505050505050565b600060208284031215614b9b57600080fd5b81518015158114613fd457600080fd5b600060208284031215614bbd57600080fd5b813560028110613fd457600080fd5b60008060208385031215614bdf57600080fd5b823567ffffffffffffffff811115614bf657600080fd5b614adc85828601614971565b6000806000806000806000806080898b031215614c1e57600080fd5b883567ffffffffffffffff80821115614c3657600080fd5b614c428c838d01614971565b909a50985060208b0135915080821115614c5b57600080fd5b614c678c838d016148b3565b909850965060408b0135915080821115614c8057600080fd5b614c8c8c838d016148b3565b909650945060608b0135915080821115614ca557600080fd5b50614cb28b828c016148b3565b999c989b5096995094979396929594505050565b600080600060408486031215614cdb57600080fd5b833567ffffffffffffffff811115614cf257600080fd5b614cfe86828701614971565b909790965060209590950135949350505050565b600060208284031215614d2457600080fd5b813567ffffffffffffffff811115614d3b57600080fd5b6144c4848285016149b3565b6000806000806000806000806000806000806101808d8f031215614d6a57600080fd5b67ffffffffffffffff8d351115614d8057600080fd5b614d8d8e8e358f016149b3565b9b5067ffffffffffffffff60208e01351115614da857600080fd5b614db88e60208f01358f016149b3565b9a5067ffffffffffffffff60408e01351115614dd357600080fd5b614de38e60408f01358f016149b3565b9950614df160608e01614a23565b9850614dff60808e01614a23565b9750614e0d60a08e01614a23565b965067ffffffffffffffff60c08e01351115614e2857600080fd5b614e388e60c08f01358f016148ff565b955060e08d01359450614e4e6101008e01614a23565b93506101208d01359250614e656101408e01614a23565b9150614e746101608e01614a23565b90509295989b509295989b509295989b565b60008060408385031215614e9957600080fd5b823567ffffffffffffffff811115614eb057600080fd5b614ebc858286016149b3565b95602094909401359450505050565b600060208284031215614edd57600080fd5b5035919050565b600080600060408486031215614ef957600080fd5b83359250602084013567ffffffffffffffff811115614f1757600080fd5b614f23868287016148b3565b9497909650939450505050565b60008060408385031215614f4357600080fd5b50508035926020909101359150565b600060208284031215614f6457600080fd5b8135613fd48161578c565b600081518084526020808501945080840160005b83811015614f9f57815187529582019590820190600101614f83565b509495945050505050565b600081518084526020808501945080840160005b83811015614f9f57815163ffffffff1687529582019590820190600101614fbe565b60028110614ff057614ff061574a565b9052565b818352818160208501375060006020828401015260006020601f19601f840116840101905092915050565b600081518084526150378160208601602086016156b2565b601f01601f19169290920160200192915050565b6000825161505d8184602087016156b2565b9190910192915050565b8183823760009101908152919050565b600080835481600182811c91508083168061509357607f831692505b60208084108214156150b357634e487b7160e01b86526022600452602486fd5b8180156150c757600181146150d857615105565b60ff19861689528489019650615105565b60008a81526020902060005b868110156150fd5781548b8201529085019083016150e4565b505084890196505b509498975050505050505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015615186577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc088860301845261517485835161501f565b9450928501929085019060010161513a565b5092979650505050505050565b602081526000613fd46020830184614f6f565b6040815260006151b96040830185614f6f565b90508260208301529392505050565b602081526000613fd46020830184614faa565b6080815260006151ef608083018789614ff4565b602083019590955250604081019290925260609091015292915050565b608081526000615220608083018789614ff4565b905063ffffffff8516602083015261523b6040830185614fe0565b8260608301529695505050505050565b602081526000613fd4602083018461501f565b6101808152600061527361018083018f61501f565b8281036020840152615285818f61501f565b90508281036040840152615299818e61501f565b63ffffffff8d811660608601528c811660808601528b1660a0850152905082810360c08401526152c9818a614f6f565b9150508660e08301526152e561010083018763ffffffff169052565b846101208301526152ff61014083018563ffffffff169052565b63ffffffff83166101608301529d9c50505050505050505050505050565b602081526000825161016080602085015261533c61018085018361501f565b91506020850151601f198086850301604087015261535a848361501f565b935060408701519150615375606087018363ffffffff169052565b606087015163ffffffff811660808801529150608087015163ffffffff811660a0880152915060a08701519150808685030160c0870152506153b78382614f6f565b92505060c085015160e085015260e08501516101006153dd8187018363ffffffff169052565b8601516101208681019190915286015190506101406154038187018363ffffffff169052565b9095015163ffffffff1693019290925250919050565b602081526000825160e06020840152615436610100840182614faa565b9050602084015160408401526040840151606084015260608401516080840152608084015160a084015260a084015160c084015260c08401516004811061547f5761547f61574a565b60e0939093019290925250919050565b602081526000825160e060208401526154ac610100840182614faa565b90506001600160a01b03602085015116604084015260408401516060840152606084015115156080840152608084015160a084015260a084015160c084015260c0840151151560e08401528091505092915050565b8381526040602082015281604082015260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561554057600080fd5b8260051b8085606085013760009201606001918252509392505050565b63ffffffff84168152606081016155776020830185614fe0565b826040830152949350505050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126155ba57600080fd5b83018035915067ffffffffffffffff8211156155d557600080fd5b6020019150600581901b36038213156148f857600080fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561561657615616615776565b604052919050565b600067ffffffffffffffff82111561563857615638615776565b5060051b60200190565b6000821982111561565557615655615734565b500190565b60008261567757634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561569657615696615734565b500290565b6000828210156156ad576156ad615734565b500390565b60005b838110156156cd5781810151838201526020016156b5565b83811115613df85750506000910152565b600181811c908216806156f257607f821691505b6020821081141561571357634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561572d5761572d615734565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b63ffffffff8116811461386357600080fdfe4552524f525f494e56414c49445f4c4f54544552595f4d494e5f56414c55455f5045525f4954454d534552524f525f494e56414c49445f4c4f54544552595f4e554d4245525f4f465f4954454d534552524f525f494e56414c49445f4c4f54544552595f504552494f445f484f55525f4f465f444159534552524f525f494e56414c49445f4c4f54544552595f564552424f53455f4e414d454552524f525f494e56414c49445f4c4f54544552595f504552494f445f444159534552524f525f494e56414c49445f4c4f54544552595f4d41585f56414c55455f5045525f4954454d534552524f525f494e56414c49445f4c4f54544552595f54524541535552595f4645455f50455243454e544552524f525f494e56414c49445f4c4f54544552595f50524943455f5045525f5449434b45544552524f525f494e56414c49445f4c4f54544552595f4d41585f4e554d4245525f5449434b4554535f5045525f425559a164736f6c6343000806000a000000000000000000000000e6b8a5cf854791412c1f6efc7caf629f5df1c747

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000e6b8a5cf854791412c1f6efc7caf629f5df1c747

-----Decoded View---------------
Arg [0] : _tokenAddress (address): 0xe6b8a5cf854791412c1f6efc7caf629f5df1c747

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000e6b8a5cf854791412c1f6efc7caf629f5df1c747


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading