false
true
0

Contract Address Details

0x2d01b3C1Cd94e0b8C835312aEE3ECfBb87CEF300

Contract Name
NineInchDCAPLS
Creator
0x20f72d–806f10 at 0xe258cf–d03795
Balance
1 tPLS
Tokens
Fetching tokens...
Transactions
Fetching transactions...
Transfers
Fetching transfers...
Gas Used
Fetching gas used...
Last Balance Update
25349050
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
NineInchDCAPLS




Optimization enabled
true
Compiler version
v0.8.19+commit.7dd6d404




Optimization runs
200
EVM Version
default




Verified at
2024-03-22T19:17:56.341424Z

Constructor Arguments

0x00000000000000000000000099c2d4937756cf66d04f7db362b87604f43039690000000000000000000000000cd7ceaf7169c38554263d54ddda53ab2a21bd2f0000000000000000000000000cd7ceaf7169c38554263d54ddda53ab2a21bd2f

Arg [0] (address) : 0x99c2d4937756cf66d04f7db362b87604f4303969
Arg [1] (address) : 0x0cd7ceaf7169c38554263d54ddda53ab2a21bd2f
Arg [2] (address) : 0x0cd7ceaf7169c38554263d54ddda53ab2a21bd2f

              

contracts/swap/DCA.sol

// Sources flattened with hardhat v2.19.1 https://hardhat.org

// SPDX-License-Identifier: GPLv3 AND MIT

// File @openzeppelin/contracts/utils/Context.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

/**
 * @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 @openzeppelin/contracts/access/Ownable.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.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. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling 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 @openzeppelin/contracts/security/Pausable.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

// File @openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

/**
 * @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 @openzeppelin/contracts/token/ERC20/IERC20.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

/**
 * @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 @openzeppelin/contracts/utils/Address.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

/**
 * @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
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [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://consensys.net/diligence/blog/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.8.0/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 @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.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;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(token.transfer.selector, to, value)
        );
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    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)
        );
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(
                token.approve.selector,
                spender,
                oldAllowance + value
            )
        );
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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"
            );
            _callOptionalReturn(
                token,
                abi.encodeWithSelector(
                    token.approve.selector,
                    spender,
                    oldAllowance - value
                )
            );
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        bytes memory approvalCall = abi.encodeWithSelector(
            token.approve.selector,
            spender,
            value
        );

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(
                token,
                abi.encodeWithSelector(token.approve.selector, spender, 0)
            );
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    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"
        );
        require(
            returndata.length == 0 || abi.decode(returndata, (bool)),
            "SafeERC20: ERC20 operation 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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(
        IERC20 token,
        bytes memory data
    ) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success &&
            (returndata.length == 0 || abi.decode(returndata, (bool))) &&
            Address.isContract(address(token));
    }
}

// File contracts/swap/interfaces/INineInchRouter01.sol

// Original license: SPDX_License_Identifier: GPLv3

interface INineInchRouter01 {
    function factory() external view returns (address);

    function WETH() external view returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);

    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    )
        external
        payable
        returns (uint amountToken, uint amountETH, uint liquidity);

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);

    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);

    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint amountA, uint amountB);

    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint amountToken, uint amountETH);

    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapExactETHForTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable returns (uint[] memory amounts);

    function swapTokensForExactETH(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapExactTokensForETH(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapETHForExactTokens(
        uint amountOut,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable returns (uint[] memory amounts);

    function quote(
        uint amountA,
        uint reserveA,
        uint reserveB
    ) external pure returns (uint amountB);

    function getAmountOut(
        uint amountIn,
        uint reserveIn,
        uint reserveOut
    ) external pure returns (uint amountOut);

    function getAmountIn(
        uint amountOut,
        uint reserveIn,
        uint reserveOut
    ) external pure returns (uint amountIn);

    function getAmountsOut(
        uint amountIn,
        address[] calldata path
    ) external view returns (uint[] memory amounts);

    function getAmountsIn(
        uint amountOut,
        address[] calldata path
    ) external view returns (uint[] memory amounts);
}

// File contracts/swap/interfaces/INineInchRouter02.sol

// Original license: SPDX_License_Identifier: GPLv3

interface INineInchRouter02 is INineInchRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);

    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

// File @openzeppelin/contracts/security/ReentrancyGuard.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

// File @openzeppelin/contracts/utils/math/SafeCast.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(
            value <= type(uint248).max,
            "SafeCast: value doesn't fit in 248 bits"
        );
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(
            value <= type(uint240).max,
            "SafeCast: value doesn't fit in 240 bits"
        );
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(
            value <= type(uint232).max,
            "SafeCast: value doesn't fit in 232 bits"
        );
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(
            value <= type(uint224).max,
            "SafeCast: value doesn't fit in 224 bits"
        );
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(
            value <= type(uint216).max,
            "SafeCast: value doesn't fit in 216 bits"
        );
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(
            value <= type(uint208).max,
            "SafeCast: value doesn't fit in 208 bits"
        );
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(
            value <= type(uint200).max,
            "SafeCast: value doesn't fit in 200 bits"
        );
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(
            value <= type(uint192).max,
            "SafeCast: value doesn't fit in 192 bits"
        );
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(
            value <= type(uint184).max,
            "SafeCast: value doesn't fit in 184 bits"
        );
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(
            value <= type(uint176).max,
            "SafeCast: value doesn't fit in 176 bits"
        );
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(
            value <= type(uint168).max,
            "SafeCast: value doesn't fit in 168 bits"
        );
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(
            value <= type(uint160).max,
            "SafeCast: value doesn't fit in 160 bits"
        );
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(
            value <= type(uint152).max,
            "SafeCast: value doesn't fit in 152 bits"
        );
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(
            value <= type(uint144).max,
            "SafeCast: value doesn't fit in 144 bits"
        );
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(
            value <= type(uint136).max,
            "SafeCast: value doesn't fit in 136 bits"
        );
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(
            value <= type(uint128).max,
            "SafeCast: value doesn't fit in 128 bits"
        );
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(
            value <= type(uint120).max,
            "SafeCast: value doesn't fit in 120 bits"
        );
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(
            value <= type(uint112).max,
            "SafeCast: value doesn't fit in 112 bits"
        );
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(
            value <= type(uint104).max,
            "SafeCast: value doesn't fit in 104 bits"
        );
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(
            value <= type(uint96).max,
            "SafeCast: value doesn't fit in 96 bits"
        );
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(
            value <= type(uint88).max,
            "SafeCast: value doesn't fit in 88 bits"
        );
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(
            value <= type(uint80).max,
            "SafeCast: value doesn't fit in 80 bits"
        );
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(
            value <= type(uint72).max,
            "SafeCast: value doesn't fit in 72 bits"
        );
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(
            value <= type(uint64).max,
            "SafeCast: value doesn't fit in 64 bits"
        );
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(
            value <= type(uint56).max,
            "SafeCast: value doesn't fit in 56 bits"
        );
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(
            value <= type(uint48).max,
            "SafeCast: value doesn't fit in 48 bits"
        );
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(
            value <= type(uint40).max,
            "SafeCast: value doesn't fit in 40 bits"
        );
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(
            value <= type(uint32).max,
            "SafeCast: value doesn't fit in 32 bits"
        );
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(
            value <= type(uint24).max,
            "SafeCast: value doesn't fit in 24 bits"
        );
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(
            value <= type(uint16).max,
            "SafeCast: value doesn't fit in 16 bits"
        );
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(
            value <= type(uint8).max,
            "SafeCast: value doesn't fit in 8 bits"
        );
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(
            value <= uint256(type(int256).max),
            "SafeCast: value doesn't fit in an int256"
        );
        return int256(value);
    }
}

// File @openzeppelin/contracts/utils/math/SafeMath.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

// 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 @openzeppelin/contracts/utils/structs/EnumerableSet.sol@v4.9.3

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(
        Set storage set,
        bytes32 value
    ) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(
        Set storage set,
        uint256 index
    ) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(
        Bytes32Set storage set,
        bytes32 value
    ) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(
        Bytes32Set storage set,
        bytes32 value
    ) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(
        Bytes32Set storage set,
        bytes32 value
    ) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(
        Bytes32Set storage set,
        uint256 index
    ) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(
        Bytes32Set storage set
    ) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(
        AddressSet storage set,
        address value
    ) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(
        AddressSet storage set,
        address value
    ) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(
        AddressSet storage set,
        address value
    ) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(
        AddressSet storage set,
        uint256 index
    ) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(
        AddressSet storage set
    ) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(
        UintSet storage set,
        uint256 value
    ) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(
        UintSet storage set,
        uint256 value
    ) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(
        UintSet storage set,
        uint256 index
    ) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(
        UintSet storage set
    ) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

abstract contract IERC20Extented is IERC20 {
    function decimals() public view virtual returns (uint8);
}

// File contracts/swap/NineInchDCAPLS.sol

// Original license: SPDX_License_Identifier: GPLv3
pragma solidity 0.8.19;

/**
 * @title NineInchDCAPLS
 * @notice It allows
 */
contract NineInchDCAPLS is ReentrancyGuard, Pausable, Ownable {
    //---------- Libraries ----------//
    using SafeMath for uint256;
    using SafeCast for uint256;
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // ---------- ERRORS ----------//
    error SendEthFailed();
    error SenderIsNotAdmin();

    //---------- Contracts ----------//
    INineInchRouter02 private nineInchRouter; // 9inchRouter Router contract.
    address public keeper; // Address of the admin who can performKeep.

    //---------- Storage -----------//
    address feeWallet; // Address of the wallet that will receive the fee.
    uint256 fee = 10; // 0.1% Fee to be charged for each swap.
    uint randNo = 0;

    struct Order {
        // Order Identity.
        bytes32 orderId;
        // Amount of tokens to swap.
        uint256 amountIn;
        // Path to be performed by the swap.
        address[] path;
        // Address of the order maker.
        address user;
        // Swap interval.
        uint256 interval;
        // Date of the last swap.
        uint256 lastSwapDate;
        // How many "from" tokens there are left to swap
        uint256 remaining;
        // How many swaps left the position has to execute
        uint8 swapsLeft;
        // Number of orders to execute.
        uint8 numOfOrders;
        // Minimum price to execute the order.
        uint256 minPrice;
        // Maximum price to execute the order.
        uint256 maxPrice;
    }

    mapping(bytes32 => Order) private orderBook; // Mapping from orderId to order.
    EnumerableSet.Bytes32Set private orderIndex; // Mapping of ids of orders.

    //---------- Events -----------//
    event OrderCreated(
        bytes32 indexed orderId,
        uint256 amountIn,
        address tokenIn,
        address tokenOut,
        uint8 numOfOrders,
        uint256 interval,
        address indexed user
    );
    event OrderPushed(Order order);
    event OrderCancelled(bytes32 indexed orderId);
    event OrderFilled(
        bytes32 indexed orderId,
        uint256 amountIn,
        uint256 timestamp
    );
    event OrderExecuted(
        bytes32 indexed orderId,
        bytes32 indexed subOrderId,
        uint256 amountIn,
        uint256 amountOut,
        uint256 rate,
        uint256 timestamp
    );
    event OrderFailed(bytes32 indexed orderId);

    //---------- Constructor ----------//
    constructor(address routerAddress, address _keeper, address _feeWallet) {
        nineInchRouter = INineInchRouter02(routerAddress);
        keeper = _keeper;
        feeWallet = _feeWallet;
    }

    //---------- Modifiers ----------//
    /**
     * @dev Reverts if keeper is not admin.
     */
    modifier onlyKeeper() {
        if (_msgSender() != keeper) revert SenderIsNotAdmin();
        _;
    }

    /**
     * @dev Cancel a existent order.
     * @param orderId Order Identity.
     */
    function _deleteOrder(bytes32 orderId) private {
        orderIndex.remove(orderId);
        delete orderBook[orderId];
    }

    /**
     * @dev Return true if token is native
     * @param token Address of the asset.
     */
    function _isNative(address token) private view returns (bool) {
        return token == address(nineInchRouter.WETH());
    }

    /**
     * @dev Return funds to user
     * @param amount Amount to return.
     * @param token Address of the asset.
     * @param user Address of the order maker.
     */
    function _returnFunds(uint256 amount, address token, address user) private {
        if (_isNative(token)) {
            (bool success, ) = payable(user).call{value: amount}("");
            if (!success) revert SendEthFailed();
        } else {
            IERC20 _token = IERC20(token);
            _token.safeTransfer(user, amount);
        }
    }

    /**
     * @dev Perform a swap once the target price is reached.
     * @param orderId Order Identity
     */
    function _performSwap(bytes32 orderId) private {
        require(orderIndex.contains(orderId), "Order does not exist");
        Order storage order = orderBook[orderId];
        uint256 amountIn = order.amountIn / order.numOfOrders;
        if (order.remaining < amountIn) amountIn = order.remaining;

        uint256 oneToken = 10 **
            uint256(IERC20Extented(order.path[0]).decimals());

        (bool success, uint256 price) = getPrice(amountIn, order.path);
        (bool success2, uint256 oneTokenPrice) = getPrice(oneToken, order.path);
        uint256 amountOutMin = price.mul(10000 - 450).div(10000);

        string memory methodName;
        bytes memory selector;
        uint256 ethValue = 0;

        // is tokenIn native
        if (_isNative(order.path[0])) {
            methodName = "swapExactETHForTokens(uint256,address[],address,uint256)";
            selector = abi.encodeWithSelector(
                bytes4(keccak256(bytes(methodName))),
                amountOutMin,
                order.path,
                order.user,
                block.timestamp.add(300)
            );
            ethValue = amountIn;
        }
        // is tokenOut native
        else if (_isNative(order.path[order.path.length - 1])) {
            methodName = "swapExactTokensForETH(uint256,uint256,address[],address,uint256)";
            selector = abi.encodeWithSelector(
                bytes4(keccak256(bytes(methodName))),
                amountIn,
                amountOutMin,
                order.path,
                order.user,
                block.timestamp.add(300)
            );
        }
        // is tokenIn and tokenOut not native
        else {
            methodName = "swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256,uint256,address[],address,uint256)";
            selector = abi.encodeWithSelector(
                bytes4(keccak256(bytes(methodName))),
                amountIn,
                amountOutMin,
                order.path,
                order.user,
                block.timestamp.add(300)
            );
        }

        IERC20(order.path[0]).approve(address(nineInchRouter), amountIn);
        (bool successSwap, ) = address(nineInchRouter).call{value: ethValue}(
            selector
        );

        if (successSwap) {
            order.swapsLeft -= 1;
            order.lastSwapDate = block.timestamp;
            order.remaining -= amountIn;

            bytes32 subOrderId = keccak256(
                abi.encodePacked(
                    orderId,
                    amountIn,
                    oneTokenPrice,
                    block.timestamp,
                    block.number
                )
            );

            emit OrderExecuted(
                orderId,
                subOrderId,
                amountIn,
                price,
                oneTokenPrice,
                block.timestamp
            );

            if (order.swapsLeft == 0) {
                _deleteOrder(orderId);
                emit OrderFilled(orderId, order.amountIn, block.timestamp);
            }
        } else {
            _returnFunds(amountIn, order.path[0], order.user);
            emit OrderFailed(orderId);
        }
    }

    /**
     * @notice Show the amounts out of path.
     * @param amountIn Amount to query.
     * @param path Path to query.
     * @return If exist and the amount out.
     */
    function getPrice(
        uint256 amountIn,
        address[] memory path
    ) public view returns (bool, uint256) {
        try nineInchRouter.getAmountsOut(amountIn, path) returns (
            uint256[] memory result
        ) {
            return (true, result[path.length - 1]);
        } catch {
            return (false, 0);
        }
    }

    /**
     * @dev Calculate the amount of digits in a number.
     * @param number Number to check.
     * @return uint256 amount of difits.
     */
    function _numDigits(uint256 number) private pure returns (uint256) {
        uint256 digits = 0;
        while (number != 0) {
            number /= 10;
            digits++;
        }
        return digits;
    }

    /**
     * @dev Calculate the number of pages in proportion to 100 orders per page.
     * @return book_ amount of pages.
     * @return digitpage_ difits of pages.
     */
    function _getPagination()
        private
        view
        returns (uint256 book_, uint256 digitpage_)
    {
        uint256 _book = orderIndex.length().div(100);
        uint256 remainder = _book.mul(100);
        _book = remainder < orderIndex.length() ? _book.add(1) : _book;
        return (_book, _numDigits(_book));
    }

    //----------- External Functions -----------//
    /**
     * @notice Show the number of total open orders.
     * @return The number of orders.
     */
    function totalOrders() external view returns (uint256) {
        return orderIndex.length();
    }

    /**
     * @notice Show the order in the searched index.
     * @param index Index number for query.
     * @return The id of the order.
     */
    function getOrderAt(uint256 index) external view returns (bytes32) {
        return orderIndex.at(index);
    }

    /**
     * @notice Show data of the order.
     * @param orderId ID for query.
     * @return The data of the order.
     */
    function getOrder(bytes32 orderId) external view returns (Order memory) {
        require(orderIndex.contains(orderId), "Query for nonexistent order");
        return orderBook[orderId];
    }

    /**
     * @notice Show the start and end index for the keeper query, these indexes change according to the block number.
     * This function is implemented so that keepers can read all open orders and not have a reduced limit.
     * @return start index to check.
     * @return end index to check.
     */
    function getBatch() public view returns (uint256 start, uint256 end) {
        if (orderIndex.length() != 0) {
            (uint256 pages, uint256 batchDigits) = _getPagination();
            uint256 blockTens = block.number.div(10);
            uint256 underBlock = blockTens.div(10 ** batchDigits);
            uint256 overBlock = underBlock.mul(10 ** batchDigits);
            uint256 result = blockTens.sub(overBlock);
            result = result == 0 ? 1 : result;
            while (result > pages) {
                result -= pages;
            }
            uint256 start_ = result.sub(1).mul(100);
            uint256 end_ = result.mul(100) > orderIndex.length()
                ? orderIndex.length()
                : result.mul(100);
            return (start_, end_);
        }
        return (0, 0);
    }

    /**
     * @notice Create new order.
     * @param amountIn_ Amount to swap.
     * @param path_ Path to be performed by the swap.
     */
    function createOrder(
        uint256 amountIn_,
        address[] calldata path_,
        uint256 interval_,
        uint8 numOfOrders_,
        uint256[] memory priceRange_ // [minPrice, maxPrice]
    ) external payable whenNotPaused nonReentrant {
        //Checks
        require(amountIn_ != 0, "Zero amount in");
        require(path_.length >= 2, "Invalid path");
        require(interval_ >= 1 && interval_ <= 31556952, "Invalid interval");
        require(numOfOrders_ <= 255, "Invalid num of orders");

        if (priceRange_[0] != 0 && priceRange_[1] != 0) {
            require(priceRange_[0] < priceRange_[1], "Invalid price range");
        }

        uint256 amountIn = amountIn_;
        address[] calldata path = path_;
        uint256 _interval = interval_;
        address tokenIn = path[0];
        address tokenOut = path[path_.length - 1];
        address user = _msgSender();
        require(
            tokenIn != address(0x0) &&
                tokenOut != address(0x0) &&
                tokenIn != tokenOut,
            "Invalid tokens"
        );

        uint256 feeAmount = amountIn.mul(fee).div(10000);
        if (tokenIn == address(nineInchRouter.WETH())) {
            require(
                msg.value >= amountIn + feeAmount,
                "Insufficient eth value for swap"
            );
            // transfer fee to feeWallet
            (bool successFee, ) = payable(feeWallet).call{value: feeAmount}("");
            require(successFee, "Transfer failed");
            if (msg.value > amountIn - feeAmount) {
                (bool successOver, ) = payable(msg.sender).call{
                    value: msg.value - amountIn - feeAmount
                }("");
                require(successOver, "Transfer failed");
            }
        } else {
            IERC20 _token = IERC20(tokenIn);
            require(
                _token.allowance(user, address(this)) >= amountIn + feeAmount,
                "Insufficient token allowance for swap"
            );
            _token.transferFrom(user, address(this), amountIn);
            // transfer fee to feeWallet
            _token.transferFrom(user, feeWallet, feeAmount);
        }

        randNo = uint(
            keccak256(abi.encodePacked(msg.sender, block.timestamp, randNo))
        );
        bytes32 orderId = keccak256(
            abi.encodePacked(
                amountIn,
                tokenIn,
                tokenOut,
                user,
                _interval,
                numOfOrders_,
                randNo,
                block.number
            )
        );

        require(!orderIndex.contains(orderId), "Order id mistake");

        //Create order
        Order memory newOrder = Order(
            orderId,
            amountIn,
            path,
            user,
            _interval,
            block.timestamp,
            amountIn,
            numOfOrders_,
            numOfOrders_,
            priceRange_[0],
            priceRange_[1]
        );
        orderIndex.add(orderId);
        orderBook[orderId] = newOrder;

        //Interactions
        uint8 numOfOrders = numOfOrders_;
        emit OrderCreated(
            orderId,
            amountIn,
            tokenIn,
            tokenOut,
            numOfOrders,
            _interval,
            user
        );
        emit OrderPushed(newOrder);
    }

    /**
     * @notice Cancel a existent order.
     * @param orderId Order identity.
     */
    function cancelOrder(bytes32 orderId) external nonReentrant {
        //Checks
        require(orderIndex.contains(orderId), "Order does not exist");
        Order memory order = orderBook[orderId];
        require(order.user == _msgSender(), "Invalid access");
        address tokenIn = order.path[0];

        //Effects
        _deleteOrder(orderId);

        //Interactions
        _returnFunds(order.remaining, tokenIn, order.user);
        emit OrderCancelled(orderId);
    }

    /**
     * @notice Check if any order need to be execute.
     * @param checkData default data of keeper.
     * @return If need to be execute and the order id.
     */
    function checkUpkeep(
        bytes calldata checkData
    ) external view returns (bytes32[] memory) {
        (uint256 start, uint256 end) = getBatch();
        bytes32[] memory executableOrders = new bytes32[](end - start);
        for (uint256 i = start; i < end; i++) {
            bytes32 orderId = orderIndex.at(i);
            Order memory order = orderBook[orderId];
            uint256 amount = order.amountIn / order.numOfOrders;

            // check if order is within the price range
            // check if the minimum price is greater or equal than current price
            if (order.minPrice != 0) {
                (bool success, uint256 price) = getPrice(amount, order.path);
                uint256 minPrice = order.minPrice / order.numOfOrders;
                /*
                require(
                    success && price >= minPrice,
                    "Order price is below the minimum"
                );
                */
                // check if price is lower than the minimum price, continue to the next order
                if (!success || price < minPrice) {
                    continue;
                }
            }

            // check if the maximum price is lower or equal than current price
            if (order.maxPrice != 0) {
                (bool success, uint256 price) = getPrice(amount, order.path);
                uint256 maxPrice = order.maxPrice / order.numOfOrders;

                /*
                require(
                    success && price < maxPrice,
                    "Order price is above the maximum"
                );
                */

                // check if price is greater than the maximum price, continue to the next order
                if (!success || price > maxPrice) {
                    continue;
                }
            }

            // check if the order is ready to be executed, will be executed if the interval has passed,
            // and if the remaining amount is greater than 0 and the number of swaps left is greater than 0
            if (order.swapsLeft == order.numOfOrders) {
                // return (true, abi.encodePacked(orderId));
                executableOrders[i - start] = orderId;
            } else {
                if (
                    order.remaining > 0 &&
                    order.swapsLeft > 0 &&
                    block.timestamp >= order.lastSwapDate + order.interval
                ) {
                   executableOrders[i - start] = orderId;
                    // return (true, abi.encodePacked(orderId));
                }
            }
        }
        return executableOrders;
    }

    /**
     * @notice Execute an order, only keepers can do this execution.
     * @param performData order id to execute.
     */
    function performUpkeep(
        bytes32[] memory performData
    ) external nonReentrant onlyKeeper {
        bytes32[] memory orders = performData;
        // bytes32 orderId = abi.decode(performData, (bytes32));

        for (uint i = 0; i < orders.length; i++) {
            bytes32 orderId = orders[i];
            require(orderIndex.contains(orderId), "Order does not exist");
            Order memory order = orderBook[orderId];
            uint32 swapsLeft = order.swapsLeft;
            uint256 remaining = order.remaining;
            uint256 lastSwapDate = order.lastSwapDate;
            uint256 amountIn = order.amountIn / order.numOfOrders;
            if (order.remaining < amountIn) amountIn = order.remaining;

            // check if order is within the price range
            // check if the minimum price is greater or equal than current price
            if (order.minPrice != 0) {
                (bool success, uint256 price) = getPrice(amountIn, order.path);
                uint256 minPrice = order.minPrice / order.numOfOrders;
                /*
                require(
                    success && price >= minPrice,
                    "Order price is below the minimum"
                );
                */
                // check if price is lower than the minimum price, continue to the next order
                if (!success || price < minPrice) {
                    return;
                }
            }

            // check if the maximum price is lower or equal than current price
            if (order.maxPrice != 0) {
                (bool success, uint256 price) = getPrice(amountIn, order.path);
                uint256 maxPrice = order.maxPrice / order.numOfOrders;

                /*
                require(
                    success && price < maxPrice,
                    "Order price is above the maximum"
                );
                */

                // check if price is greater than the maximum price, continue to the next order
                if (!success || price > maxPrice) {
                    return;
                }
            }

            // check if the order is ready to be executed, will be executed if the interval has passed,
            // and if the remaining amount is greater than 0 and the number of swaps left is greater than 0
            if (swapsLeft != order.numOfOrders) {
                require(swapsLeft > 0, "No swaps left");
                require(remaining > 0, "No remaining amount");
                require(
                   block.timestamp >= lastSwapDate + order.interval,
                    "Interval not reached"
                );
            }

            //Interactions
            _performSwap(orderId);
        }
    }

    /**
     * @notice Cancel a existent order by the contract owner.
     * @param orderId_ Order identity.
     */
    function forceCancelOrder(bytes32 orderId_) external onlyOwner {
        //Checks
        require(orderIndex.contains(orderId_), "Order does not exist");
        Order memory order = orderBook[orderId_];
        address tokenIn = order.path[0];

        //Effects
        _deleteOrder(orderId_);

        //Interactions
        _returnFunds(order.remaining, tokenIn, order.user);
        emit OrderCancelled(orderId_);
    }

    function updateKeeper(address _keeper) external onlyOwner {
        keeper = _keeper;
    }

    function updateRouter(address _router) external onlyOwner {
        nineInchRouter = INineInchRouter02(_router);
    }

    function updateFeeWallet(address _feeWallet) external onlyOwner {
        feeWallet = _feeWallet;
    }

    function updateFee(uint256 _fee) external onlyOwner {
        fee = _fee;
    }

    /**
     * @notice Functions for pause and unpause the contract.
     */
    function pause() external onlyOwner {
        _pause();
    }

    function unpause() external onlyOwner {
        _unpause();
    }
}
        

Compiler Settings

{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"routerAddress","internalType":"address"},{"type":"address","name":"_keeper","internalType":"address"},{"type":"address","name":"_feeWallet","internalType":"address"}]},{"type":"error","name":"SendEthFailed","inputs":[]},{"type":"error","name":"SenderIsNotAdmin","inputs":[]},{"type":"event","name":"OrderCancelled","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"OrderCreated","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true},{"type":"uint256","name":"amountIn","internalType":"uint256","indexed":false},{"type":"address","name":"tokenIn","internalType":"address","indexed":false},{"type":"address","name":"tokenOut","internalType":"address","indexed":false},{"type":"uint8","name":"numOfOrders","internalType":"uint8","indexed":false},{"type":"uint256","name":"interval","internalType":"uint256","indexed":false},{"type":"address","name":"user","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OrderExecuted","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"subOrderId","internalType":"bytes32","indexed":true},{"type":"uint256","name":"amountIn","internalType":"uint256","indexed":false},{"type":"uint256","name":"amountOut","internalType":"uint256","indexed":false},{"type":"uint256","name":"rate","internalType":"uint256","indexed":false},{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OrderFailed","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"OrderFilled","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true},{"type":"uint256","name":"amountIn","internalType":"uint256","indexed":false},{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OrderPushed","inputs":[{"type":"tuple","name":"order","internalType":"struct NineInchDCAPLS.Order","indexed":false,"components":[{"type":"bytes32","name":"orderId","internalType":"bytes32"},{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"interval","internalType":"uint256"},{"type":"uint256","name":"lastSwapDate","internalType":"uint256"},{"type":"uint256","name":"remaining","internalType":"uint256"},{"type":"uint8","name":"swapsLeft","internalType":"uint8"},{"type":"uint8","name":"numOfOrders","internalType":"uint8"},{"type":"uint256","name":"minPrice","internalType":"uint256"},{"type":"uint256","name":"maxPrice","internalType":"uint256"}]}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelOrder","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"","internalType":"bytes32[]"}],"name":"checkUpkeep","inputs":[{"type":"bytes","name":"checkData","internalType":"bytes"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"createOrder","inputs":[{"type":"uint256","name":"amountIn_","internalType":"uint256"},{"type":"address[]","name":"path_","internalType":"address[]"},{"type":"uint256","name":"interval_","internalType":"uint256"},{"type":"uint8","name":"numOfOrders_","internalType":"uint8"},{"type":"uint256[]","name":"priceRange_","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"forceCancelOrder","inputs":[{"type":"bytes32","name":"orderId_","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"start","internalType":"uint256"},{"type":"uint256","name":"end","internalType":"uint256"}],"name":"getBatch","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct NineInchDCAPLS.Order","components":[{"type":"bytes32","name":"orderId","internalType":"bytes32"},{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"interval","internalType":"uint256"},{"type":"uint256","name":"lastSwapDate","internalType":"uint256"},{"type":"uint256","name":"remaining","internalType":"uint256"},{"type":"uint8","name":"swapsLeft","internalType":"uint8"},{"type":"uint8","name":"numOfOrders","internalType":"uint8"},{"type":"uint256","name":"minPrice","internalType":"uint256"},{"type":"uint256","name":"maxPrice","internalType":"uint256"}]}],"name":"getOrder","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getOrderAt","inputs":[{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPrice","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"keeper","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"performUpkeep","inputs":[{"type":"bytes32[]","name":"performData","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalOrders","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFee","inputs":[{"type":"uint256","name":"_fee","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFeeWallet","inputs":[{"type":"address","name":"_feeWallet","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateKeeper","inputs":[{"type":"address","name":"_keeper","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRouter","inputs":[{"type":"address","name":"_router","internalType":"address"}]}]
              

Contract Creation Code

0x6080604052600a60055560006006553480156200001b57600080fd5b50604051620039c2380380620039c28339810160408190526200003e9162000112565b60016000819055805460ff1916905562000058336200009b565b600280546001600160a01b039485166001600160a01b0319918216179091556003805493851693821693909317909255600480549190931691161790556200015c565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b80516001600160a01b03811681146200010d57600080fd5b919050565b6000806000606084860312156200012857600080fd5b6200013384620000f5565b92506200014360208501620000f5565b91506200015360408501620000f5565b90509250925092565b613856806200016c6000396000f3fe60806040526004361061012a5760003560e01c806373a423d0116100ab57806395048d461161006f57806395048d46146103405780639779021714610360578063aced166114610380578063b462ae62146103a0578063c851cc32146103c0578063f2fde38b146103e057600080fd5b806373a423d0146102945780637489ec23146102b45780638456cb59146102d45780638da5cb5b146102e95780639012c4a81461032057600080fd5b80635778472a116100f25780635778472a146101e25780635c975abb1461020f57806366718524146102325780636e04ff0d14610252578063715018a61461027f57600080fd5b80630c0fa81a1461012f5780631d8344091461016b5780633b1fee6c1461018e5780633f4ba83a146101b85780634a6354ff146101cf575b600080fd5b34801561013b57600080fd5b5061014f61014a366004612e8b565b610400565b6040805192151583526020830191909152015b60405180910390f35b34801561017757600080fd5b506101806104ba565b604051908152602001610162565b34801561019a57600080fd5b506101a36104cb565b60408051928352602083019190915201610162565b3480156101c457600080fd5b506101cd6105d1565b005b6101cd6101dd366004612fbb565b6105e3565b3480156101ee57600080fd5b506102026101fd366004613076565b611089565b60405161016291906130d3565b34801561021b57600080fd5b5060015460ff166040519015158152602001610162565b34801561023e57600080fd5b506101cd61024d36600461318a565b61123a565b34801561025e57600080fd5b5061027261026d3660046131a7565b611264565b6040516101629190613219565b34801561028b57600080fd5b506101cd611585565b3480156102a057600080fd5b506101806102af366004613076565b611597565b3480156102c057600080fd5b506101cd6102cf366004613076565b6115a4565b3480156102e057600080fd5b506101cd611787565b3480156102f557600080fd5b5060015461010090046001600160a01b03165b6040516001600160a01b039091168152602001610162565b34801561032c57600080fd5b506101cd61033b366004613076565b611797565b34801561034c57600080fd5b506101cd61035b366004613076565b6117a4565b34801561036c57600080fd5b506101cd61037b36600461318a565b61192e565b34801561038c57600080fd5b50600354610308906001600160a01b031681565b3480156103ac57600080fd5b506101cd6103bb36600461325d565b611958565b3480156103cc57600080fd5b506101cd6103db36600461318a565b611d11565b3480156103ec57600080fd5b506101cd6103fb36600461318a565b611d3b565b60025460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f9061043790879087906004016132e3565b600060405180830381865afa92505050801561047557506040513d6000823e601f3d908101601f19168201604052610472919081019061333a565b60015b610484575060009050806104b3565b6001816001865161049591906133d6565b815181106104a5576104a56133e9565b602002602001015192509250505b9250929050565b60006104c66008611db1565b905090565b6000806104d86008611db1565b156105c8576000806104e8611dbb565b909250905060006104fa43600a611e17565b9050600061051361050c84600a6134e3565b8390611e17565b9050600061052c61052585600a6134e3565b8390611e2a565b9050600061053a8483611e36565b90508015610548578061054b565b60015b90505b858111156105675761056086826133d6565b905061054e565b600061057f6064610579846001611e36565b90611e2a565b9050600061058d6008611db1565b610598846064611e2a565b116105ad576105a8836064611e2a565b6105b7565b6105b76008611db1565b919a91995090975050505050505050565b50600091829150565b6105d9611e42565b6105e1611ea2565b565b6105eb611ef4565b6105f3611f3a565b856000036106395760405162461bcd60e51b815260206004820152600e60248201526d2d32b9379030b6b7bab73a1034b760911b60448201526064015b60405180910390fd5b60028410156106795760405162461bcd60e51b815260206004820152600c60248201526b092dcecc2d8d2c840e0c2e8d60a31b6044820152606401610630565b6001831015801561068e57506301e185588311155b6106cd5760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081a5b9d195c9d985b60821b6044820152606401610630565b60ff8260ff1611156107195760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206e756d206f66206f726465727360581b6044820152606401610630565b8060008151811061072c5761072c6133e9565b602002602001015160001415801561075f575080600181518110610752576107526133e9565b6020026020010151600014155b156107dd5780600181518110610777576107776133e9565b602002602001015181600081518110610792576107926133e9565b6020026020010151106107dd5760405162461bcd60e51b8152602060048201526013602482015272496e76616c69642070726963652072616e676560681b6044820152606401610630565b858585856000838382816107f3576107f36133e9565b9050602002016020810190610808919061318a565b90506000848461081960018d6133d6565b818110610828576108286133e9565b905060200201602081019061083d919061318a565b9050336001600160a01b0383161580159061086057506001600160a01b03821615155b801561087e5750816001600160a01b0316836001600160a01b031614155b6108bb5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420746f6b656e7360901b6044820152606401610630565b60006108de6127106108d86005548b611e2a90919063ffffffff16565b90611e17565b9050600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610933573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095791906134ef565b6001600160a01b0316846001600160a01b031603610b1257610979818961350c565b3410156109c85760405162461bcd60e51b815260206004820152601f60248201527f496e73756666696369656e74206574682076616c756520666f722073776170006044820152606401610630565b6004546040516000916001600160a01b03169083908381818185875af1925050503d8060008114610a15576040519150601f19603f3d011682016040523d82523d6000602084013e610a1a565b606091505b5050905080610a5d5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610630565b610a67828a6133d6565b341115610b0c5760003383610a7c8c346133d6565b610a8691906133d6565b604051600081818185875af1925050503d8060008114610ac2576040519150601f19603f3d011682016040523d82523d6000602084013e610ac7565b606091505b5050905080610b0a5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610630565b505b50610ce8565b83610b1d828a61350c565b604051636eb1769f60e11b81526001600160a01b03858116600483015230602483015283169063dd62ed3e90604401602060405180830381865afa158015610b69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8d919061351f565b1015610be95760405162461bcd60e51b815260206004820152602560248201527f496e73756666696369656e7420746f6b656e20616c6c6f77616e636520666f72604482015264020737761760dc1b6064820152608401610630565b6040516323b872dd60e01b81526001600160a01b038481166004830152306024830152604482018b90528216906323b872dd906064016020604051808303816000875af1158015610c3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c629190613538565b50600480546040516323b872dd60e01b81526001600160a01b0386811693820193909352908216602482015260448101849052908216906323b872dd906064016020604051808303816000875af1158015610cc1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce59190613538565b50505b6006546040516bffffffffffffffffffffffff193360601b166020820152426034820152605481019190915260740160408051601f19818403018152828252805160209182012060068190559083018b90526bffffffffffffffffffffffff19606088811b82169385019390935286831b811660548501529185901b9091166068830152607c82018790526001600160f81b031960f88d901b16609c830152609d8201524360bd82015260009060dd0160408051601f1981840301815291905280516020909101209050610dbd600882611f93565b15610dfd5760405162461bcd60e51b815260206004820152601060248201526f4f72646572206964206d697374616b6560801b6044820152606401610630565b60006040518061016001604052808381526020018b81526020018a8a8080602002602001604051908101604052809392919081815260200183836020028082843760009201829052509385525050506001600160a01b0387166020830152604082018a9052426060830152608082018d905260ff8f1660a0830181905260c08301528d5160e0909201918e9190610e9657610e966133e9565b602002602001015181526020018c600181518110610eb657610eb66133e9565b60200260200101518152509050610ed7826008611fab90919063ffffffff16565b5060008281526007602090815260409182902083518155818401516001820155918301518051849392610f11926002850192910190612d77565b5060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015560a0820151816005015560c0820151816006015560e08201518160070160006101000a81548160ff021916908360ff1602179055506101008201518160070160016101000a81548160ff021916908360ff1602179055506101208201518160080155610140820151816009015590505060008c9050846001600160a01b0316837f329ea8877957d9a6bc95ae3900bd5494970aa1252e257c6d72a1ce23e1b584bb8d8a8a868e60405161102d9594939291909485526001600160a01b03938416602086015291909216604084015260ff919091166060830152608082015260a00190565b60405180910390a37f16d133c9eece7c94928db36c8942774e6874c5f13907ecb20f458b3348e296488260405161106491906130d3565b60405180910390a150505050505050505050506110816001600055565b505050505050565b6110f860405180610160016040528060008019168152602001600081526020016060815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600060ff168152602001600060ff16815260200160008152602001600081525090565b611103600883611f93565b61114f5760405162461bcd60e51b815260206004820152601b60248201527f517565727920666f72206e6f6e6578697374656e74206f7264657200000000006044820152606401610630565b60008281526007602090815260409182902082516101608101845281548152600182015481840152600282018054855181860281018601875281815292959394938601938301828280156111cc57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116111ae575b505050918352505060038201546001600160a01b03166020820152600482015460408201526005820154606082015260068201546080820152600782015460ff80821660a0840152610100918290041660c0830152600883015460e083015260099092015491015292915050565b611242611e42565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b60606000806112716104cb565b9092509050600061128283836133d6565b67ffffffffffffffff81111561129a5761129a612e0b565b6040519080825280602002602001820160405280156112c3578160200160208202803683370190505b509050825b828110156115795760006112dd600883611fb7565b90506000600760008381526020019081526020016000206040518061016001604052908160008201548152602001600182015481526020016002820180548060200260200160405190810160405280929190818152602001828054801561136d57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161134f575b505050918352505060038201546001600160a01b0316602080830191909152600483015460408301526005830154606083015260068301546080830152600783015460ff80821660a085015261010091829004811660c0850152600885015460e08501526009909401549281019290925290830151908301519293506000926113fa92919091169061355a565b905081610120015160001461145b5760008061141a838560400151610400565b91509150600084610100015160ff16856101200151611439919061355a565b905082158061144757508082105b1561145757505050505050611567565b5050505b610140820151156114b857600080611477838560400151610400565b91509150600084610100015160ff16856101400151611496919061355a565b90508215806114a457508082115b156114b457505050505050611567565b5050505b81610100015160ff168260e0015160ff16036114fb5782856114da89876133d6565b815181106114ea576114ea6133e9565b602002602001018181525050611563565b60008260c00151118015611516575060008260e0015160ff16115b8015611535575081608001518260a00151611531919061350c565b4210155b1561156357828561154689876133d6565b81518110611556576115566133e9565b6020026020010181815250505b5050505b806115718161357c565b9150506112c8565b50925050505b92915050565b61158d611e42565b6105e16000611fc3565b600061157f600883611fb7565b6115ac611f3a565b6115b7600882611f93565b6115d35760405162461bcd60e51b815260040161063090613595565b60008181526007602090815260408083208151610160810183528154815260018201548185015260028201805484518187028101870186528181529295939486019383018282801561164e57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611630575b505050918352505060038201546001600160a01b03166020820152600482015460408201526005820154606082015260068201546080820152600782015460ff80821660a0840152610100918290041660c0830152600883015460e08301526009909201549101529050336001600160a01b031681606001516001600160a01b03161461170e5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642061636365737360901b6044820152606401610630565b60008160400151600081518110611727576117276133e9565b6020026020010151905061173a8361201d565b61174d8260c00151828460600151612096565b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a250506117846001600055565b50565b61178f611e42565b6105e1612138565b61179f611e42565b600555565b6117ac611e42565b6117b7600882611f93565b6117d35760405162461bcd60e51b815260040161063090613595565b60008181526007602090815260408083208151610160810183528154815260018201548185015260028201805484518187028101870186528181529295939486019383018282801561184e57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611830575b505050918352505060038201546001600160a01b0316602082015260048201546040808301919091526005830154606083015260068301546080830152600783015460ff80821660a0850152610100918290041660c0840152600884015460e08401526009909301549290910191909152810151805191925060009182906118d8576118d86133e9565b602002602001015190506118eb8361201d565b6118fe8260c00151828460600151612096565b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a2505050565b611936611e42565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b611960611f3a565b6003546001600160a01b0316336001600160a01b03161461199457604051636587b01b60e11b815260040160405180910390fd5b8060005b8151811015611d045760008282815181106119b5576119b56133e9565b602002602001015190506119d3816008611f9390919063ffffffff16565b6119ef5760405162461bcd60e51b815260040161063090613595565b600081815260076020908152604080832081516101608101835281548152600182015481850152600282018054845181870281018701865281815292959394860193830182828015611a6a57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611a4c575b505050918352505060038201546001600160a01b0316602080830191909152600483015460408301526005830154606083015260068301546080830152600783015460ff80821660a08086019190915261010092839004821660c080870191909152600887015460e080880191909152600990970154958401959095529486015193860151948601519186015192860151959650928316949092600092611b139291169061355a565b9050808560c001511015611b28575060c08401515b61012085015115611b8a57600080611b44838860400151610400565b91509150600087610100015160ff16886101200151611b63919061355a565b9050821580611b7157508082105b15611b86575050505050505050505050611d07565b5050505b61014085015115611bec57600080611ba6838860400151610400565b91509150600087610100015160ff16886101400151611bc5919061355a565b9050821580611bd357508082115b15611be8575050505050505050505050611d07565b5050505b84610100015160ff168463ffffffff1614611ce25760008463ffffffff1611611c475760405162461bcd60e51b815260206004820152600d60248201526c139bc81cddd85c1cc81b19599d609a1b6044820152606401610630565b60008311611c8d5760405162461bcd60e51b8152602060048201526013602482015272139bc81c995b585a5b9a5b99c8185b5bdd5b9d606a1b6044820152606401610630565b6080850151611c9c908361350c565b421015611ce25760405162461bcd60e51b8152602060048201526014602482015273125b9d195c9d985b081b9bdd081c995858da195960621b6044820152606401610630565b611ceb86612173565b5050505050508080611cfc9061357c565b915050611998565b50505b6117846001600055565b611d19611e42565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b611d43611e42565b6001600160a01b038116611da85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610630565b61178481611fc3565b600061157f825490565b6000806000611dcf60646108d86008611db1565b90506000611dde826064611e2a565b9050611dea6008611db1565b8110611df65781611e01565b611e01826001612841565b915081611e0d8361284d565b9350935050509091565b6000611e23828461355a565b9392505050565b6000611e2382846135c3565b6000611e2382846133d6565b6001546001600160a01b036101009091041633146105e15760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610630565b611eaa612876565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60015460ff16156105e15760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610630565b600260005403611f8c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610630565b6002600055565b60008181526001830160205260408120541515611e23565b6000611e2383836128bf565b6000611e23838361290e565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b612028600882612938565b506000818152600760205260408120818155600181018290559061204f6002830182612ddc565b506003810180546001600160a01b0319169055600060048201819055600582018190556006820181905560078201805461ffff191690556008820181905560099091015550565b61209f82612944565b1561211e576000816001600160a01b03168460405160006040518083038185875af1925050503d80600081146120f1576040519150601f19603f3d011682016040523d82523d6000602084013e6120f6565b606091505b505090508061211857604051630cefd29f60e41b815260040160405180910390fd5b50505050565b816121186001600160a01b03821683866129cd565b505050565b612140611ef4565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611ed7565b61217e600882611f93565b61219a5760405162461bcd60e51b815260040161063090613595565b600081815260076020819052604082209081015460018201549192916121c891610100900460ff169061355a565b905080826006015410156121dd575060068101545b6000826002016000815481106121f5576121f56133e9565b600091825260209182902001546040805163313ce56760e01b815290516001600160a01b039092169263313ce567926004808401938290030181865afa158015612243573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226791906135da565b6122759060ff16600a6134e3565b90506000806122e084866002018054806020026020016040519081016040528092919081815260200182805480156122d657602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116122b8575b5050505050610400565b9150915060008061234b85886002018054806020026020016040519081016040528092919081815260200182805480156122d6576020028201919060005260206000209081546001600160a01b031681526001909101906020018083116122b8575050505050610400565b909250905060006123646127106108d88661254e611e2a565b9050606080600061239e8b600201600081548110612384576123846133e9565b6000918252602090912001546001600160a01b0316612944565b15612437576040518060600160405280603881526020016137e9603891398051602082012060038d015491945090859060028e01906001600160a01b03166123e84261012c612841565b6040516024016123fb9493929190613635565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091529150899050612587565b60028b01805461245e919061244e906001906133d6565b81548110612384576123846133e9565b156124f757604051806060016040528060408152602001613749604091398051602082012060038d0154919450908b90869060028f01906001600160a01b03166124aa4261012c612841565b6040516024016124be95949392919061366a565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091529150612587565b604051806080016040528060608152602001613789606091398051602082012060038d0154919450908b90869060028f01906001600160a01b031661253e4261012c612841565b60405160240161255295949392919061366a565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915291505b8a60020160008154811061259d5761259d6133e9565b60009182526020909120015460025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018d905291169063095ea7b3906044016020604051808303816000875af11580156125fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061261f9190613538565b506002546040516000916001600160a01b03169083906126409086906136ca565b60006040518083038185875af1925050503d806000811461267d576040519150601f19603f3d011682016040523d82523d6000602084013e612682565b606091505b5050905080156127c95760078c018054600191906000906126a790849060ff166136e6565b92506101000a81548160ff021916908360ff160217905550428c600501819055508a8c60060160008282546126dc91906133d6565b909155505060408051602081018f90529081018c9052606081018790524260808201524360a082015260009060c00160408051601f1981840301815282825280516020918201208f84529083018c9052908201899052426060830152915081908f907fad2e99392dc283414380c576281b0a970817175893f602f4615c16f9111d78a39060800160405180910390a360078d015460ff166000036127c3576127838e61201d565b60018d0154604080519182524260208301528f917fb38583f2adb435cac858db9d3e8d3ca952ccb32307e2f3d0053b415d2d293481910160405180910390a25b50612832565b6128068b8d6002016000815481106127e3576127e36133e9565b60009182526020909120015460038f01546001600160a01b039182169116612096565b6040518d907fe1bf2a28c083b93b502e4140fe14e357c3d973a7ec3d8517b6022a70bfd3562690600090a25b50505050505050505050505050565b6000611e23828461350c565b6000805b821561157f57612862600a8461355a565b92508061286e8161357c565b915050612851565b60015460ff166105e15760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610630565b60008181526001830160205260408120546129065750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561157f565b50600061157f565b6000826000018281548110612925576129256133e9565b9060005260206000200154905092915050565b6000611e238383612a1f565b600254604080516315ab88c960e31b815290516000926001600160a01b03169163ad5c46489160048083019260209291908290030181865afa15801561298e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129b291906134ef565b6001600160a01b0316826001600160a01b0316149050919050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052612133908490612b12565b60008181526001830160205260408120548015612b08576000612a436001836133d6565b8554909150600090612a57906001906133d6565b9050818114612abc576000866000018281548110612a7757612a776133e9565b9060005260206000200154905080876000018481548110612a9a57612a9a6133e9565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612acd57612acd6136ff565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061157f565b600091505061157f565b6000612b67826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612be79092919063ffffffff16565b9050805160001480612b88575080806020019051810190612b889190613538565b6121335760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610630565b6060612bf68484600085612bfe565b949350505050565b606082471015612c5f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610630565b600080866001600160a01b03168587604051612c7b91906136ca565b60006040518083038185875af1925050503d8060008114612cb8576040519150601f19603f3d011682016040523d82523d6000602084013e612cbd565b606091505b5091509150612cce87838387612cd9565b979650505050505050565b60608315612d48578251600003612d41576001600160a01b0385163b612d415760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610630565b5081612bf6565b612bf68383815115612d5d5781518083602001fd5b8060405162461bcd60e51b81526004016106309190613715565b828054828255906000526020600020908101928215612dcc579160200282015b82811115612dcc57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190612d97565b50612dd8929150612df6565b5090565b508054600082559060005260206000209081019061178491905b5b80821115612dd85760008155600101612df7565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612e4a57612e4a612e0b565b604052919050565b600067ffffffffffffffff821115612e6c57612e6c612e0b565b5060051b60200190565b6001600160a01b038116811461178457600080fd5b60008060408385031215612e9e57600080fd5b8235915060208084013567ffffffffffffffff811115612ebd57600080fd5b8401601f81018613612ece57600080fd5b8035612ee1612edc82612e52565b612e21565b81815260059190911b82018301908381019088831115612f0057600080fd5b928401925b82841015612f27578335612f1881612e76565b82529284019290840190612f05565b80955050505050509250929050565b60ff8116811461178457600080fd5b8035612f5081612f36565b919050565b600082601f830112612f6657600080fd5b81356020612f76612edc83612e52565b82815260059290921b84018101918181019086841115612f9557600080fd5b8286015b84811015612fb05780358352918301918301612f99565b509695505050505050565b60008060008060008060a08789031215612fd457600080fd5b86359550602087013567ffffffffffffffff80821115612ff357600080fd5b818901915089601f83011261300757600080fd5b81358181111561301657600080fd5b8a60208260051b850101111561302b57600080fd5b60208301975095506040890135945061304660608a01612f45565b9350608089013591508082111561305c57600080fd5b5061306989828a01612f55565b9150509295509295509295565b60006020828403121561308857600080fd5b5035919050565b600081518084526020808501945080840160005b838110156130c85781516001600160a01b0316875295820195908201906001016130a3565b509495945050505050565b6020815281516020820152602082015160408201526000604083015161016080606085015261310661018085018361308f565b9150606085015161312260808601826001600160a01b03169052565b50608085015160a085015260a085015160c085015260c085015160e085015260e08501516101006131578187018360ff169052565b860151905061012061316d8682018360ff169052565b860151610140868101919091529095015193019290925250919050565b60006020828403121561319c57600080fd5b8135611e2381612e76565b600080602083850312156131ba57600080fd5b823567ffffffffffffffff808211156131d257600080fd5b818501915085601f8301126131e657600080fd5b8135818111156131f557600080fd5b86602082850101111561320757600080fd5b60209290920196919550909350505050565b6020808252825182820181905260009190848201906040850190845b8181101561325157835183529284019291840191600101613235565b50909695505050505050565b6000602080838503121561327057600080fd5b823567ffffffffffffffff81111561328757600080fd5b8301601f8101851361329857600080fd5b80356132a6612edc82612e52565b81815260059190911b820183019083810190878311156132c557600080fd5b928401925b82841015612cce578335825292840192908401906132ca565b6000604082018483526020604081850152818551808452606086019150828701935060005b8181101561332d5784516001600160a01b031683529383019391830191600101613308565b5090979650505050505050565b6000602080838503121561334d57600080fd5b825167ffffffffffffffff81111561336457600080fd5b8301601f8101851361337557600080fd5b8051613383612edc82612e52565b81815260059190911b820183019083810190878311156133a257600080fd5b928401925b82841015612cce578351825292840192908401906133a7565b634e487b7160e01b600052601160045260246000fd5b8181038181111561157f5761157f6133c0565b634e487b7160e01b600052603260045260246000fd5b600181815b8085111561343a578160001904821115613420576134206133c0565b8085161561342d57918102915b93841c9390800290613404565b509250929050565b6000826134515750600161157f565b8161345e5750600061157f565b8160018114613474576002811461347e5761349a565b600191505061157f565b60ff84111561348f5761348f6133c0565b50506001821b61157f565b5060208310610133831016604e8410600b84101617156134bd575081810a61157f565b6134c783836133ff565b80600019048211156134db576134db6133c0565b029392505050565b6000611e238383613442565b60006020828403121561350157600080fd5b8151611e2381612e76565b8082018082111561157f5761157f6133c0565b60006020828403121561353157600080fd5b5051919050565b60006020828403121561354a57600080fd5b81518015158114611e2357600080fd5b60008261357757634e487b7160e01b600052601260045260246000fd5b500490565b60006001820161358e5761358e6133c0565b5060010190565b60208082526014908201527313dc99195c88191bd95cc81b9bdd08195e1a5cdd60621b604082015260600190565b808202811582820484141761157f5761157f6133c0565b6000602082840312156135ec57600080fd5b8151611e2381612f36565b6000815480845260208085019450836000528060002060005b838110156130c85781546001600160a01b031687529582019560019182019101613610565b84815260806020820152600061364e60808301866135f7565b6001600160a01b03949094166040830152506060015292915050565b85815284602082015260a06040820152600061368960a08301866135f7565b6001600160a01b0394909416606083015250608001529392505050565b60005b838110156136c15781810151838201526020016136a9565b50506000910152565b600082516136dc8184602087016136a6565b9190910192915050565b60ff828116828216039081111561157f5761157f6133c0565b634e487b7160e01b600052603160045260246000fd5b60208152600082518060208401526137348160408501602087016136a6565b601f01601f1916919091016040019291505056fe737761704578616374546f6b656e73466f724554482875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e7432353629737761704578616374546f6b656e73466f72546f6b656e73537570706f7274696e674665654f6e5472616e73666572546f6b656e732875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e7432353629737761704578616374455448466f72546f6b656e732875696e743235362c616464726573735b5d2c616464726573732c75696e7432353629a26469706673582212205ac413addb6046ba2d06f183078dd7f5d95da1e3bfd87fe2f11b519f628303d264736f6c6343000813003300000000000000000000000099c2d4937756cf66d04f7db362b87604f43039690000000000000000000000000cd7ceaf7169c38554263d54ddda53ab2a21bd2f0000000000000000000000000cd7ceaf7169c38554263d54ddda53ab2a21bd2f

Deployed ByteCode

0x60806040526004361061012a5760003560e01c806373a423d0116100ab57806395048d461161006f57806395048d46146103405780639779021714610360578063aced166114610380578063b462ae62146103a0578063c851cc32146103c0578063f2fde38b146103e057600080fd5b806373a423d0146102945780637489ec23146102b45780638456cb59146102d45780638da5cb5b146102e95780639012c4a81461032057600080fd5b80635778472a116100f25780635778472a146101e25780635c975abb1461020f57806366718524146102325780636e04ff0d14610252578063715018a61461027f57600080fd5b80630c0fa81a1461012f5780631d8344091461016b5780633b1fee6c1461018e5780633f4ba83a146101b85780634a6354ff146101cf575b600080fd5b34801561013b57600080fd5b5061014f61014a366004612e8b565b610400565b6040805192151583526020830191909152015b60405180910390f35b34801561017757600080fd5b506101806104ba565b604051908152602001610162565b34801561019a57600080fd5b506101a36104cb565b60408051928352602083019190915201610162565b3480156101c457600080fd5b506101cd6105d1565b005b6101cd6101dd366004612fbb565b6105e3565b3480156101ee57600080fd5b506102026101fd366004613076565b611089565b60405161016291906130d3565b34801561021b57600080fd5b5060015460ff166040519015158152602001610162565b34801561023e57600080fd5b506101cd61024d36600461318a565b61123a565b34801561025e57600080fd5b5061027261026d3660046131a7565b611264565b6040516101629190613219565b34801561028b57600080fd5b506101cd611585565b3480156102a057600080fd5b506101806102af366004613076565b611597565b3480156102c057600080fd5b506101cd6102cf366004613076565b6115a4565b3480156102e057600080fd5b506101cd611787565b3480156102f557600080fd5b5060015461010090046001600160a01b03165b6040516001600160a01b039091168152602001610162565b34801561032c57600080fd5b506101cd61033b366004613076565b611797565b34801561034c57600080fd5b506101cd61035b366004613076565b6117a4565b34801561036c57600080fd5b506101cd61037b36600461318a565b61192e565b34801561038c57600080fd5b50600354610308906001600160a01b031681565b3480156103ac57600080fd5b506101cd6103bb36600461325d565b611958565b3480156103cc57600080fd5b506101cd6103db36600461318a565b611d11565b3480156103ec57600080fd5b506101cd6103fb36600461318a565b611d3b565b60025460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f9061043790879087906004016132e3565b600060405180830381865afa92505050801561047557506040513d6000823e601f3d908101601f19168201604052610472919081019061333a565b60015b610484575060009050806104b3565b6001816001865161049591906133d6565b815181106104a5576104a56133e9565b602002602001015192509250505b9250929050565b60006104c66008611db1565b905090565b6000806104d86008611db1565b156105c8576000806104e8611dbb565b909250905060006104fa43600a611e17565b9050600061051361050c84600a6134e3565b8390611e17565b9050600061052c61052585600a6134e3565b8390611e2a565b9050600061053a8483611e36565b90508015610548578061054b565b60015b90505b858111156105675761056086826133d6565b905061054e565b600061057f6064610579846001611e36565b90611e2a565b9050600061058d6008611db1565b610598846064611e2a565b116105ad576105a8836064611e2a565b6105b7565b6105b76008611db1565b919a91995090975050505050505050565b50600091829150565b6105d9611e42565b6105e1611ea2565b565b6105eb611ef4565b6105f3611f3a565b856000036106395760405162461bcd60e51b815260206004820152600e60248201526d2d32b9379030b6b7bab73a1034b760911b60448201526064015b60405180910390fd5b60028410156106795760405162461bcd60e51b815260206004820152600c60248201526b092dcecc2d8d2c840e0c2e8d60a31b6044820152606401610630565b6001831015801561068e57506301e185588311155b6106cd5760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081a5b9d195c9d985b60821b6044820152606401610630565b60ff8260ff1611156107195760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206e756d206f66206f726465727360581b6044820152606401610630565b8060008151811061072c5761072c6133e9565b602002602001015160001415801561075f575080600181518110610752576107526133e9565b6020026020010151600014155b156107dd5780600181518110610777576107776133e9565b602002602001015181600081518110610792576107926133e9565b6020026020010151106107dd5760405162461bcd60e51b8152602060048201526013602482015272496e76616c69642070726963652072616e676560681b6044820152606401610630565b858585856000838382816107f3576107f36133e9565b9050602002016020810190610808919061318a565b90506000848461081960018d6133d6565b818110610828576108286133e9565b905060200201602081019061083d919061318a565b9050336001600160a01b0383161580159061086057506001600160a01b03821615155b801561087e5750816001600160a01b0316836001600160a01b031614155b6108bb5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420746f6b656e7360901b6044820152606401610630565b60006108de6127106108d86005548b611e2a90919063ffffffff16565b90611e17565b9050600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610933573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095791906134ef565b6001600160a01b0316846001600160a01b031603610b1257610979818961350c565b3410156109c85760405162461bcd60e51b815260206004820152601f60248201527f496e73756666696369656e74206574682076616c756520666f722073776170006044820152606401610630565b6004546040516000916001600160a01b03169083908381818185875af1925050503d8060008114610a15576040519150601f19603f3d011682016040523d82523d6000602084013e610a1a565b606091505b5050905080610a5d5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610630565b610a67828a6133d6565b341115610b0c5760003383610a7c8c346133d6565b610a8691906133d6565b604051600081818185875af1925050503d8060008114610ac2576040519150601f19603f3d011682016040523d82523d6000602084013e610ac7565b606091505b5050905080610b0a5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610630565b505b50610ce8565b83610b1d828a61350c565b604051636eb1769f60e11b81526001600160a01b03858116600483015230602483015283169063dd62ed3e90604401602060405180830381865afa158015610b69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8d919061351f565b1015610be95760405162461bcd60e51b815260206004820152602560248201527f496e73756666696369656e7420746f6b656e20616c6c6f77616e636520666f72604482015264020737761760dc1b6064820152608401610630565b6040516323b872dd60e01b81526001600160a01b038481166004830152306024830152604482018b90528216906323b872dd906064016020604051808303816000875af1158015610c3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c629190613538565b50600480546040516323b872dd60e01b81526001600160a01b0386811693820193909352908216602482015260448101849052908216906323b872dd906064016020604051808303816000875af1158015610cc1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce59190613538565b50505b6006546040516bffffffffffffffffffffffff193360601b166020820152426034820152605481019190915260740160408051601f19818403018152828252805160209182012060068190559083018b90526bffffffffffffffffffffffff19606088811b82169385019390935286831b811660548501529185901b9091166068830152607c82018790526001600160f81b031960f88d901b16609c830152609d8201524360bd82015260009060dd0160408051601f1981840301815291905280516020909101209050610dbd600882611f93565b15610dfd5760405162461bcd60e51b815260206004820152601060248201526f4f72646572206964206d697374616b6560801b6044820152606401610630565b60006040518061016001604052808381526020018b81526020018a8a8080602002602001604051908101604052809392919081815260200183836020028082843760009201829052509385525050506001600160a01b0387166020830152604082018a9052426060830152608082018d905260ff8f1660a0830181905260c08301528d5160e0909201918e9190610e9657610e966133e9565b602002602001015181526020018c600181518110610eb657610eb66133e9565b60200260200101518152509050610ed7826008611fab90919063ffffffff16565b5060008281526007602090815260409182902083518155818401516001820155918301518051849392610f11926002850192910190612d77565b5060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015560a0820151816005015560c0820151816006015560e08201518160070160006101000a81548160ff021916908360ff1602179055506101008201518160070160016101000a81548160ff021916908360ff1602179055506101208201518160080155610140820151816009015590505060008c9050846001600160a01b0316837f329ea8877957d9a6bc95ae3900bd5494970aa1252e257c6d72a1ce23e1b584bb8d8a8a868e60405161102d9594939291909485526001600160a01b03938416602086015291909216604084015260ff919091166060830152608082015260a00190565b60405180910390a37f16d133c9eece7c94928db36c8942774e6874c5f13907ecb20f458b3348e296488260405161106491906130d3565b60405180910390a150505050505050505050506110816001600055565b505050505050565b6110f860405180610160016040528060008019168152602001600081526020016060815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600060ff168152602001600060ff16815260200160008152602001600081525090565b611103600883611f93565b61114f5760405162461bcd60e51b815260206004820152601b60248201527f517565727920666f72206e6f6e6578697374656e74206f7264657200000000006044820152606401610630565b60008281526007602090815260409182902082516101608101845281548152600182015481840152600282018054855181860281018601875281815292959394938601938301828280156111cc57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116111ae575b505050918352505060038201546001600160a01b03166020820152600482015460408201526005820154606082015260068201546080820152600782015460ff80821660a0840152610100918290041660c0830152600883015460e083015260099092015491015292915050565b611242611e42565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b60606000806112716104cb565b9092509050600061128283836133d6565b67ffffffffffffffff81111561129a5761129a612e0b565b6040519080825280602002602001820160405280156112c3578160200160208202803683370190505b509050825b828110156115795760006112dd600883611fb7565b90506000600760008381526020019081526020016000206040518061016001604052908160008201548152602001600182015481526020016002820180548060200260200160405190810160405280929190818152602001828054801561136d57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161134f575b505050918352505060038201546001600160a01b0316602080830191909152600483015460408301526005830154606083015260068301546080830152600783015460ff80821660a085015261010091829004811660c0850152600885015460e08501526009909401549281019290925290830151908301519293506000926113fa92919091169061355a565b905081610120015160001461145b5760008061141a838560400151610400565b91509150600084610100015160ff16856101200151611439919061355a565b905082158061144757508082105b1561145757505050505050611567565b5050505b610140820151156114b857600080611477838560400151610400565b91509150600084610100015160ff16856101400151611496919061355a565b90508215806114a457508082115b156114b457505050505050611567565b5050505b81610100015160ff168260e0015160ff16036114fb5782856114da89876133d6565b815181106114ea576114ea6133e9565b602002602001018181525050611563565b60008260c00151118015611516575060008260e0015160ff16115b8015611535575081608001518260a00151611531919061350c565b4210155b1561156357828561154689876133d6565b81518110611556576115566133e9565b6020026020010181815250505b5050505b806115718161357c565b9150506112c8565b50925050505b92915050565b61158d611e42565b6105e16000611fc3565b600061157f600883611fb7565b6115ac611f3a565b6115b7600882611f93565b6115d35760405162461bcd60e51b815260040161063090613595565b60008181526007602090815260408083208151610160810183528154815260018201548185015260028201805484518187028101870186528181529295939486019383018282801561164e57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611630575b505050918352505060038201546001600160a01b03166020820152600482015460408201526005820154606082015260068201546080820152600782015460ff80821660a0840152610100918290041660c0830152600883015460e08301526009909201549101529050336001600160a01b031681606001516001600160a01b03161461170e5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642061636365737360901b6044820152606401610630565b60008160400151600081518110611727576117276133e9565b6020026020010151905061173a8361201d565b61174d8260c00151828460600151612096565b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a250506117846001600055565b50565b61178f611e42565b6105e1612138565b61179f611e42565b600555565b6117ac611e42565b6117b7600882611f93565b6117d35760405162461bcd60e51b815260040161063090613595565b60008181526007602090815260408083208151610160810183528154815260018201548185015260028201805484518187028101870186528181529295939486019383018282801561184e57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611830575b505050918352505060038201546001600160a01b0316602082015260048201546040808301919091526005830154606083015260068301546080830152600783015460ff80821660a0850152610100918290041660c0840152600884015460e08401526009909301549290910191909152810151805191925060009182906118d8576118d86133e9565b602002602001015190506118eb8361201d565b6118fe8260c00151828460600151612096565b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a2505050565b611936611e42565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b611960611f3a565b6003546001600160a01b0316336001600160a01b03161461199457604051636587b01b60e11b815260040160405180910390fd5b8060005b8151811015611d045760008282815181106119b5576119b56133e9565b602002602001015190506119d3816008611f9390919063ffffffff16565b6119ef5760405162461bcd60e51b815260040161063090613595565b600081815260076020908152604080832081516101608101835281548152600182015481850152600282018054845181870281018701865281815292959394860193830182828015611a6a57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611a4c575b505050918352505060038201546001600160a01b0316602080830191909152600483015460408301526005830154606083015260068301546080830152600783015460ff80821660a08086019190915261010092839004821660c080870191909152600887015460e080880191909152600990970154958401959095529486015193860151948601519186015192860151959650928316949092600092611b139291169061355a565b9050808560c001511015611b28575060c08401515b61012085015115611b8a57600080611b44838860400151610400565b91509150600087610100015160ff16886101200151611b63919061355a565b9050821580611b7157508082105b15611b86575050505050505050505050611d07565b5050505b61014085015115611bec57600080611ba6838860400151610400565b91509150600087610100015160ff16886101400151611bc5919061355a565b9050821580611bd357508082115b15611be8575050505050505050505050611d07565b5050505b84610100015160ff168463ffffffff1614611ce25760008463ffffffff1611611c475760405162461bcd60e51b815260206004820152600d60248201526c139bc81cddd85c1cc81b19599d609a1b6044820152606401610630565b60008311611c8d5760405162461bcd60e51b8152602060048201526013602482015272139bc81c995b585a5b9a5b99c8185b5bdd5b9d606a1b6044820152606401610630565b6080850151611c9c908361350c565b421015611ce25760405162461bcd60e51b8152602060048201526014602482015273125b9d195c9d985b081b9bdd081c995858da195960621b6044820152606401610630565b611ceb86612173565b5050505050508080611cfc9061357c565b915050611998565b50505b6117846001600055565b611d19611e42565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b611d43611e42565b6001600160a01b038116611da85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610630565b61178481611fc3565b600061157f825490565b6000806000611dcf60646108d86008611db1565b90506000611dde826064611e2a565b9050611dea6008611db1565b8110611df65781611e01565b611e01826001612841565b915081611e0d8361284d565b9350935050509091565b6000611e23828461355a565b9392505050565b6000611e2382846135c3565b6000611e2382846133d6565b6001546001600160a01b036101009091041633146105e15760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610630565b611eaa612876565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60015460ff16156105e15760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610630565b600260005403611f8c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610630565b6002600055565b60008181526001830160205260408120541515611e23565b6000611e2383836128bf565b6000611e23838361290e565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b612028600882612938565b506000818152600760205260408120818155600181018290559061204f6002830182612ddc565b506003810180546001600160a01b0319169055600060048201819055600582018190556006820181905560078201805461ffff191690556008820181905560099091015550565b61209f82612944565b1561211e576000816001600160a01b03168460405160006040518083038185875af1925050503d80600081146120f1576040519150601f19603f3d011682016040523d82523d6000602084013e6120f6565b606091505b505090508061211857604051630cefd29f60e41b815260040160405180910390fd5b50505050565b816121186001600160a01b03821683866129cd565b505050565b612140611ef4565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611ed7565b61217e600882611f93565b61219a5760405162461bcd60e51b815260040161063090613595565b600081815260076020819052604082209081015460018201549192916121c891610100900460ff169061355a565b905080826006015410156121dd575060068101545b6000826002016000815481106121f5576121f56133e9565b600091825260209182902001546040805163313ce56760e01b815290516001600160a01b039092169263313ce567926004808401938290030181865afa158015612243573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226791906135da565b6122759060ff16600a6134e3565b90506000806122e084866002018054806020026020016040519081016040528092919081815260200182805480156122d657602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116122b8575b5050505050610400565b9150915060008061234b85886002018054806020026020016040519081016040528092919081815260200182805480156122d6576020028201919060005260206000209081546001600160a01b031681526001909101906020018083116122b8575050505050610400565b909250905060006123646127106108d88661254e611e2a565b9050606080600061239e8b600201600081548110612384576123846133e9565b6000918252602090912001546001600160a01b0316612944565b15612437576040518060600160405280603881526020016137e9603891398051602082012060038d015491945090859060028e01906001600160a01b03166123e84261012c612841565b6040516024016123fb9493929190613635565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091529150899050612587565b60028b01805461245e919061244e906001906133d6565b81548110612384576123846133e9565b156124f757604051806060016040528060408152602001613749604091398051602082012060038d0154919450908b90869060028f01906001600160a01b03166124aa4261012c612841565b6040516024016124be95949392919061366a565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091529150612587565b604051806080016040528060608152602001613789606091398051602082012060038d0154919450908b90869060028f01906001600160a01b031661253e4261012c612841565b60405160240161255295949392919061366a565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915291505b8a60020160008154811061259d5761259d6133e9565b60009182526020909120015460025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018d905291169063095ea7b3906044016020604051808303816000875af11580156125fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061261f9190613538565b506002546040516000916001600160a01b03169083906126409086906136ca565b60006040518083038185875af1925050503d806000811461267d576040519150601f19603f3d011682016040523d82523d6000602084013e612682565b606091505b5050905080156127c95760078c018054600191906000906126a790849060ff166136e6565b92506101000a81548160ff021916908360ff160217905550428c600501819055508a8c60060160008282546126dc91906133d6565b909155505060408051602081018f90529081018c9052606081018790524260808201524360a082015260009060c00160408051601f1981840301815282825280516020918201208f84529083018c9052908201899052426060830152915081908f907fad2e99392dc283414380c576281b0a970817175893f602f4615c16f9111d78a39060800160405180910390a360078d015460ff166000036127c3576127838e61201d565b60018d0154604080519182524260208301528f917fb38583f2adb435cac858db9d3e8d3ca952ccb32307e2f3d0053b415d2d293481910160405180910390a25b50612832565b6128068b8d6002016000815481106127e3576127e36133e9565b60009182526020909120015460038f01546001600160a01b039182169116612096565b6040518d907fe1bf2a28c083b93b502e4140fe14e357c3d973a7ec3d8517b6022a70bfd3562690600090a25b50505050505050505050505050565b6000611e23828461350c565b6000805b821561157f57612862600a8461355a565b92508061286e8161357c565b915050612851565b60015460ff166105e15760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610630565b60008181526001830160205260408120546129065750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561157f565b50600061157f565b6000826000018281548110612925576129256133e9565b9060005260206000200154905092915050565b6000611e238383612a1f565b600254604080516315ab88c960e31b815290516000926001600160a01b03169163ad5c46489160048083019260209291908290030181865afa15801561298e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129b291906134ef565b6001600160a01b0316826001600160a01b0316149050919050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052612133908490612b12565b60008181526001830160205260408120548015612b08576000612a436001836133d6565b8554909150600090612a57906001906133d6565b9050818114612abc576000866000018281548110612a7757612a776133e9565b9060005260206000200154905080876000018481548110612a9a57612a9a6133e9565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612acd57612acd6136ff565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061157f565b600091505061157f565b6000612b67826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612be79092919063ffffffff16565b9050805160001480612b88575080806020019051810190612b889190613538565b6121335760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610630565b6060612bf68484600085612bfe565b949350505050565b606082471015612c5f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610630565b600080866001600160a01b03168587604051612c7b91906136ca565b60006040518083038185875af1925050503d8060008114612cb8576040519150601f19603f3d011682016040523d82523d6000602084013e612cbd565b606091505b5091509150612cce87838387612cd9565b979650505050505050565b60608315612d48578251600003612d41576001600160a01b0385163b612d415760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610630565b5081612bf6565b612bf68383815115612d5d5781518083602001fd5b8060405162461bcd60e51b81526004016106309190613715565b828054828255906000526020600020908101928215612dcc579160200282015b82811115612dcc57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190612d97565b50612dd8929150612df6565b5090565b508054600082559060005260206000209081019061178491905b5b80821115612dd85760008155600101612df7565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612e4a57612e4a612e0b565b604052919050565b600067ffffffffffffffff821115612e6c57612e6c612e0b565b5060051b60200190565b6001600160a01b038116811461178457600080fd5b60008060408385031215612e9e57600080fd5b8235915060208084013567ffffffffffffffff811115612ebd57600080fd5b8401601f81018613612ece57600080fd5b8035612ee1612edc82612e52565b612e21565b81815260059190911b82018301908381019088831115612f0057600080fd5b928401925b82841015612f27578335612f1881612e76565b82529284019290840190612f05565b80955050505050509250929050565b60ff8116811461178457600080fd5b8035612f5081612f36565b919050565b600082601f830112612f6657600080fd5b81356020612f76612edc83612e52565b82815260059290921b84018101918181019086841115612f9557600080fd5b8286015b84811015612fb05780358352918301918301612f99565b509695505050505050565b60008060008060008060a08789031215612fd457600080fd5b86359550602087013567ffffffffffffffff80821115612ff357600080fd5b818901915089601f83011261300757600080fd5b81358181111561301657600080fd5b8a60208260051b850101111561302b57600080fd5b60208301975095506040890135945061304660608a01612f45565b9350608089013591508082111561305c57600080fd5b5061306989828a01612f55565b9150509295509295509295565b60006020828403121561308857600080fd5b5035919050565b600081518084526020808501945080840160005b838110156130c85781516001600160a01b0316875295820195908201906001016130a3565b509495945050505050565b6020815281516020820152602082015160408201526000604083015161016080606085015261310661018085018361308f565b9150606085015161312260808601826001600160a01b03169052565b50608085015160a085015260a085015160c085015260c085015160e085015260e08501516101006131578187018360ff169052565b860151905061012061316d8682018360ff169052565b860151610140868101919091529095015193019290925250919050565b60006020828403121561319c57600080fd5b8135611e2381612e76565b600080602083850312156131ba57600080fd5b823567ffffffffffffffff808211156131d257600080fd5b818501915085601f8301126131e657600080fd5b8135818111156131f557600080fd5b86602082850101111561320757600080fd5b60209290920196919550909350505050565b6020808252825182820181905260009190848201906040850190845b8181101561325157835183529284019291840191600101613235565b50909695505050505050565b6000602080838503121561327057600080fd5b823567ffffffffffffffff81111561328757600080fd5b8301601f8101851361329857600080fd5b80356132a6612edc82612e52565b81815260059190911b820183019083810190878311156132c557600080fd5b928401925b82841015612cce578335825292840192908401906132ca565b6000604082018483526020604081850152818551808452606086019150828701935060005b8181101561332d5784516001600160a01b031683529383019391830191600101613308565b5090979650505050505050565b6000602080838503121561334d57600080fd5b825167ffffffffffffffff81111561336457600080fd5b8301601f8101851361337557600080fd5b8051613383612edc82612e52565b81815260059190911b820183019083810190878311156133a257600080fd5b928401925b82841015612cce578351825292840192908401906133a7565b634e487b7160e01b600052601160045260246000fd5b8181038181111561157f5761157f6133c0565b634e487b7160e01b600052603260045260246000fd5b600181815b8085111561343a578160001904821115613420576134206133c0565b8085161561342d57918102915b93841c9390800290613404565b509250929050565b6000826134515750600161157f565b8161345e5750600061157f565b8160018114613474576002811461347e5761349a565b600191505061157f565b60ff84111561348f5761348f6133c0565b50506001821b61157f565b5060208310610133831016604e8410600b84101617156134bd575081810a61157f565b6134c783836133ff565b80600019048211156134db576134db6133c0565b029392505050565b6000611e238383613442565b60006020828403121561350157600080fd5b8151611e2381612e76565b8082018082111561157f5761157f6133c0565b60006020828403121561353157600080fd5b5051919050565b60006020828403121561354a57600080fd5b81518015158114611e2357600080fd5b60008261357757634e487b7160e01b600052601260045260246000fd5b500490565b60006001820161358e5761358e6133c0565b5060010190565b60208082526014908201527313dc99195c88191bd95cc81b9bdd08195e1a5cdd60621b604082015260600190565b808202811582820484141761157f5761157f6133c0565b6000602082840312156135ec57600080fd5b8151611e2381612f36565b6000815480845260208085019450836000528060002060005b838110156130c85781546001600160a01b031687529582019560019182019101613610565b84815260806020820152600061364e60808301866135f7565b6001600160a01b03949094166040830152506060015292915050565b85815284602082015260a06040820152600061368960a08301866135f7565b6001600160a01b0394909416606083015250608001529392505050565b60005b838110156136c15781810151838201526020016136a9565b50506000910152565b600082516136dc8184602087016136a6565b9190910192915050565b60ff828116828216039081111561157f5761157f6133c0565b634e487b7160e01b600052603160045260246000fd5b60208152600082518060208401526137348160408501602087016136a6565b601f01601f1916919091016040019291505056fe737761704578616374546f6b656e73466f724554482875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e7432353629737761704578616374546f6b656e73466f72546f6b656e73537570706f7274696e674665654f6e5472616e73666572546f6b656e732875696e743235362c75696e743235362c616464726573735b5d2c616464726573732c75696e7432353629737761704578616374455448466f72546f6b656e732875696e743235362c616464726573735b5d2c616464726573732c75696e7432353629a26469706673582212205ac413addb6046ba2d06f183078dd7f5d95da1e3bfd87fe2f11b519f628303d264736f6c63430008130033