MATIC Price: $0.739995 (+2.64%)
Gas: 60 GWei
 

Overview

MATIC Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 MATIC

MATIC Value

$0.00

Token Holdings

Sponsored

Transaction Hash
Method
Block
From
To
Value
Increase Nonce550281602024-03-24 13:46:3560 days ago1711287995IN
KyberSwap: Limit Order
0 MATIC0.0013964649.21801188
Increase Nonce550281212024-03-24 13:45:1160 days ago1711287911IN
KyberSwap: Limit Order
0 MATIC0.001540854.30533032
Increase Nonce549278182024-03-21 21:10:3563 days ago1711055435IN
KyberSwap: Limit Order
0 MATIC0.0011660141.09577118
Increase Nonce549227432024-03-21 17:50:1663 days ago1711043416IN
KyberSwap: Limit Order
0 MATIC0.00513603112.94688892
Increase Nonce501465412023-11-19 21:02:06186 days ago1700427726IN
KyberSwap: Limit Order
0 MATIC0.0013641930.00000618
Increase Nonce480300522023-09-27 3:33:05239 days ago1695785585IN
KyberSwap: Limit Order
0 MATIC0.0018945241.66263397
Cancel Batch Ord...477295372023-09-19 12:06:49247 days ago1695125209IN
KyberSwap: Limit Order
0 MATIC0.00676679109.36594867
Cancel Batch Ord...477295322023-09-19 12:06:37247 days ago1695125197IN
KyberSwap: Limit Order
0 MATIC0.00696569112.77744199
Cancel Batch Ord...477295252023-09-19 12:06:23247 days ago1695125183IN
KyberSwap: Limit Order
0 MATIC0.00654923105.97288292
Cancel Batch Ord...477295192023-09-19 12:06:09247 days ago1695125169IN
KyberSwap: Limit Order
0 MATIC0.0060566897.77516218
Cancel Batch Ord...477295112023-09-19 12:05:53247 days ago1695125153IN
KyberSwap: Limit Order
0 MATIC0.0061921100.01944441
Increase Nonce477294932023-09-19 12:05:15247 days ago1695125115IN
KyberSwap: Limit Order
0 MATIC0.002775597.82197012
Increase Nonce477294852023-09-19 12:04:57247 days ago1695125097IN
KyberSwap: Limit Order
0 MATIC0.00284428100.24634345
Increase Nonce477294792023-09-19 12:04:45247 days ago1695125085IN
KyberSwap: Limit Order
0 MATIC0.0028317299.80358645
Increase Nonce475990412023-09-16 5:00:24250 days ago1694840424IN
KyberSwap: Limit Order
0 MATIC0.0033126116.75217081
Cancel Batch Ord...475963572023-09-16 3:24:38250 days ago1694834678IN
KyberSwap: Limit Order
0 MATIC0.0057850493.40810736
Cancel Batch Ord...475917442023-09-16 0:36:18250 days ago1694824578IN
KyberSwap: Limit Order
0 MATIC0.00694522111.92412378
Increase Nonce475491922023-09-14 23:01:28251 days ago1694732488IN
KyberSwap: Limit Order
0 MATIC0.00428993151.1976517
Cancel Batch Ord...475480152023-09-14 22:19:46252 days ago1694729986IN
KyberSwap: Limit Order
0 MATIC0.01075755174
Cancel Batch Ord...475409352023-09-14 18:04:43252 days ago1694714683IN
KyberSwap: Limit Order
0 MATIC0.00848475189.40462966
Cancel Batch Ord...475360782023-09-14 15:08:01252 days ago1694704081IN
KyberSwap: Limit Order
0 MATIC0.01212168195.72262193
Cancel Batch Ord...475309292023-09-14 12:01:26252 days ago1694692886IN
KyberSwap: Limit Order
0 MATIC0.00795004128.29060807
Cancel Batch Ord...475196412023-09-14 5:02:30252 days ago1694667750IN
KyberSwap: Limit Order
0 MATIC0.00862567139.35528438
Cancel Batch Ord...474938422023-09-13 13:36:14253 days ago1694612174IN
KyberSwap: Limit Order
0 MATIC0.00501486111.94641968
Increase Nonce474874072023-09-13 9:38:40253 days ago1694597920IN
KyberSwap: Limit Order
0 MATIC0.004208192.54070915
View all transactions

Parent Transaction Hash Block From To Value
View All Internal Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x3C2E9227...7b40Ff124
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
LimitOrderProtocol

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 9999 runs

Other Settings:
default evmVersion
File 1 of 26 : LimitOrderProtocol.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol';
import './OrderMixin.sol';
import './OrderRFQMixin.sol';

/// @title Kyber Limit Order Protocol
contract LimitOrderProtocol is
  EIP712('Kyber Limit Order Protocol', '2'),
  OrderMixin,
  OrderRFQMixin
{
  // solhint-disable-next-line func-name-mixedcase
  function DOMAIN_SEPARATOR() external view returns (bytes32) {
    return _domainSeparatorV4();
  }
}

File 1 of 26 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

File 1 of 26 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 1 of 26 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 *
 * _Available since v4.1._
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

File 1 of 26 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

File 1 of 26 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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 1 of 26 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

File 1 of 26 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 1 of 26 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 1 of 26 : SignatureChecker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.1) (utils/cryptography/SignatureChecker.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";
import "../Address.sol";
import "../../interfaces/IERC1271.sol";

/**
 * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
 * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
 * Argent and Gnosis Safe.
 *
 * _Available since v4.1._
 */
library SignatureChecker {
    /**
     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
     * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidSignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
        if (error == ECDSA.RecoverError.NoError && recovered == signer) {
            return true;
        }

        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
        );
        return (success &&
            result.length == 32 &&
            abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
    }
}

File 1 of 26 : draft-EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }
}

File 1 of 26 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/SafeCast.sol)

pragma solidity ^0.8.0;

/**
 * @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) {
        require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits");
        return int248(value);
    }

    /**
     * @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) {
        require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits");
        return int240(value);
    }

    /**
     * @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) {
        require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits");
        return int232(value);
    }

    /**
     * @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) {
        require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits");
        return int224(value);
    }

    /**
     * @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) {
        require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits");
        return int216(value);
    }

    /**
     * @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) {
        require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits");
        return int208(value);
    }

    /**
     * @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) {
        require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits");
        return int200(value);
    }

    /**
     * @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) {
        require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits");
        return int192(value);
    }

    /**
     * @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) {
        require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits");
        return int184(value);
    }

    /**
     * @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) {
        require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits");
        return int176(value);
    }

    /**
     * @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) {
        require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits");
        return int168(value);
    }

    /**
     * @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) {
        require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits");
        return int160(value);
    }

    /**
     * @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) {
        require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits");
        return int152(value);
    }

    /**
     * @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) {
        require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits");
        return int144(value);
    }

    /**
     * @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) {
        require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits");
        return int136(value);
    }

    /**
     * @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) {
        require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
        return int128(value);
    }

    /**
     * @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) {
        require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits");
        return int120(value);
    }

    /**
     * @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) {
        require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits");
        return int112(value);
    }

    /**
     * @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) {
        require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits");
        return int104(value);
    }

    /**
     * @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) {
        require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits");
        return int96(value);
    }

    /**
     * @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) {
        require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits");
        return int88(value);
    }

    /**
     * @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) {
        require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits");
        return int80(value);
    }

    /**
     * @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) {
        require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits");
        return int72(value);
    }

    /**
     * @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) {
        require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
        return int64(value);
    }

    /**
     * @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) {
        require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits");
        return int56(value);
    }

    /**
     * @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) {
        require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits");
        return int48(value);
    }

    /**
     * @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) {
        require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits");
        return int40(value);
    }

    /**
     * @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) {
        require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
        return int32(value);
    }

    /**
     * @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) {
        require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits");
        return int24(value);
    }

    /**
     * @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) {
        require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
        return int16(value);
    }

    /**
     * @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) {
        require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
        return int8(value);
    }

    /**
     * @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 2 of 26 : OrderMixin.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@openzeppelin/contracts/utils/Address.sol';
import '@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol';
import '@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/access/Ownable.sol';

import './helpers/AmountCalculator.sol';
import './helpers/ChainlinkCalculator.sol';
import './helpers/NonceManager.sol';
import './helpers/PredicateHelper.sol';
import './interfaces/InteractiveNotificationReceiver.sol';
import './interfaces/ILimitOrderCallee.sol';
import './libraries/ArgumentsDecoder.sol';
import './libraries/Permitable.sol';

/// @title Regular Limit Order mixin
abstract contract OrderMixin is
  EIP712,
  AmountCalculator,
  ChainlinkCalculator,
  NonceManager,
  PredicateHelper,
  Permitable,
  Ownable
{
  using Address for address;
  using ArgumentsDecoder for bytes;

  /// @notice Emitted every time order gets filled, including partial fills
  event OrderFilled(
    address indexed taker,
    bytes32 orderHash,
    uint256 remaining,
    uint256 makingAmount,
    uint256 takingAmount
  );

  /// @notice Emitted when order gets cancelled
  event OrderCanceled(address indexed maker, bytes32 orderHash, uint256 remainingRaw);

  /// @notice Emitted when update interaction target whitelist
  event UpdatedInteractionWhitelist(address _address, bool isWhitelist);

  // Fixed-size order part with core information
  struct StaticOrder {
    uint256 salt;
    address makerAsset;
    address takerAsset;
    address maker;
    address receiver;
    address allowedSender; // equals to Zero address on public orders
    uint256 makingAmount;
    uint256 takingAmount;
    address feeRecipient;
    uint32 makerTokenFeePercent;
  }

  // `StaticOrder` extension including variable-sized additional order meta information
  struct Order {
    uint256 salt;
    address makerAsset;
    address takerAsset;
    address maker;
    address receiver;
    address allowedSender; // equals to Zero address on public orders
    uint256 makingAmount;
    uint256 takingAmount;
    address feeRecipient;
    uint32 makerTokenFeePercent;
    bytes makerAssetData;
    bytes takerAssetData;
    bytes getMakerAmount; // this.staticcall(abi.encodePacked(bytes, swapTakerAmount)) => (swapMakerAmount)
    bytes getTakerAmount; // this.staticcall(abi.encodePacked(bytes, swapMakerAmount)) => (swapTakerAmount)
    bytes predicate; // this.staticcall(bytes) => (bool)
    bytes permit; // On first fill: permit.1.call(abi.encodePacked(permit.selector, permit.2))
    bytes interaction;
  }

  struct FillOrderParams {
    Order order;
    bytes signature;
    uint256 makingAmount;
    uint256 takingAmount;
    uint256 thresholdAmount;
    address target;
    bytes callbackData;
  }

  struct FillBatchOrdersParams {
    Order[] orders;
    bytes[] signatures;
    uint256 takingAmount;
    uint256 thresholdAmount;
    address target;
  }

  bytes32 public constant LIMIT_ORDER_TYPEHASH =
    keccak256(
      'Order(uint256 salt,address makerAsset,address takerAsset,address maker,address receiver,address allowedSender,uint256 makingAmount,uint256 takingAmount,address feeRecipient,uint32 makerTokenFeePercent,bytes makerAssetData,bytes takerAssetData,bytes getMakerAmount,bytes getTakerAmount,bytes predicate,bytes permit,bytes interaction)'
    );
  uint256 private constant _ORDER_DOES_NOT_EXIST = 0;
  uint256 private constant _ORDER_FILLED = 1;
  uint16 internal constant BPS = 10000;

  /// @notice Stores unfilled amounts for each order plus one
  /// Therefore 0 means order doesn't exist and 1 means order was filled
  mapping(bytes32 => uint256) private _remaining;
  mapping(address => bool) interactionWhitelist;

  /// @notice Update interaction target whitelist
  function updateInteractionWhitelist(address _address, bool isWhitelist) external onlyOwner {
    interactionWhitelist[_address] = isWhitelist;
    emit UpdatedInteractionWhitelist(_address, isWhitelist);
  }

  /// @notice Returns unfilled amount for order. Throws if order does not exist
  function remaining(bytes32 orderHash) external view returns (uint256) {
    uint256 amount = _remaining[orderHash];
    require(amount != _ORDER_DOES_NOT_EXIST, 'LOP: Unknown order');
    unchecked {
      amount -= 1;
    }
    return amount;
  }

  /// @notice Returns unfilled amount for order
  /// @return Result Unfilled amount of order plus one if order exists. Otherwise 0
  function remainingRaw(bytes32 orderHash) external view returns (uint256) {
    return _remaining[orderHash];
  }

  /// @notice Same as `remainingRaw` but for multiple orders
  function remainingsRaw(bytes32[] memory orderHashes) external view returns (uint256[] memory) {
    uint256[] memory results = new uint256[](orderHashes.length);
    for (uint256 i = 0; i < orderHashes.length; i++) {
      results[i] = _remaining[orderHashes[i]];
    }
    return results;
  }

  /**
   * @notice Calls every target with corresponding data. Then reverts with CALL_RESULTS_0101011 where zeroes and ones
   * denote failure or success of the corresponding call
   * @param targets Array of addresses that will be called
   * @param data Array of data that will be passed to each call
   */
  function simulateCalls(address[] calldata targets, bytes[] calldata data) external {
    require(targets.length == data.length, 'LOP: array size mismatch');
    bytes memory reason = new bytes(targets.length);
    for (uint256 i = 0; i < targets.length; i++) {
      // solhint-disable-next-line avoid-low-level-calls
      (bool success, bytes memory result) = targets[i].call(data[i]);
      if (success && result.length > 0) {
        success = result.length == 32 && result.decodeBool();
      }
      reason[i] = success ? bytes1('1') : bytes1('0');
    }

    // Always revert and provide per call results
    revert(string(abi.encodePacked('CALL_RESULTS_', reason)));
  }

  /// @notice Cancels order by setting remaining amount to zero
  function cancelOrder(Order memory order) public {
    require(order.maker == msg.sender, 'LOP: Access denied');

    bytes32 orderHash = hashOrder(order);
    uint256 orderRemaining = _remaining[orderHash];
    require(orderRemaining != _ORDER_FILLED, 'LOP: already filled');
    emit OrderCanceled(msg.sender, orderHash, orderRemaining);
    _remaining[orderHash] = _ORDER_FILLED;
  }

  /// @notice Cancels multiple orders by setting remaining amount to zero
  function cancelBatchOrders(Order[] memory orders) external {
    for (uint256 i = 0; i < orders.length; ++i) {
      cancelOrder(orders[i]);
    }
  }

  /// @notice Fills an order. If one doesn't exist (first fill) it will be created using order.makerAssetData
  /// @param order Order quote to fill
  /// @param signature Signature to confirm quote ownership
  /// @param makingAmount Making amount
  /// @param takingAmount Taking amount
  /// @param thresholdAmount Specifies maximum allowed takingAmount when takingAmount is zero, otherwise specifies minimum allowed makingAmount
  /// @param callbackData CallbackData to callback to the msg.sender after receiving the makingAmount, the msg.sender transfer takingAmount to the maker after this call
  /// @return actualMakingAmount
  /// @return actualTakingAmount
  function fillOrder(
    Order memory order,
    bytes calldata signature,
    uint256 makingAmount,
    uint256 takingAmount,
    uint256 thresholdAmount,
    bytes calldata callbackData
  )
    external
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    return
      fillOrderTo(
        FillOrderParams(
          order,
          signature,
          makingAmount,
          takingAmount,
          thresholdAmount,
          msg.sender,
          callbackData
        ),
        false
      );
  }

  /// @notice Same as `fillOrder` but calls permit first,
  /// allowing to approve token spending and make a swap in one transaction.
  /// Also allows to specify funds destination instead of `msg.sender`
  /// @param order Order quote to fill
  /// @param signature Signature to confirm quote ownership
  /// @param makingAmount Making amount
  /// @param takingAmount Taking amount
  /// @param thresholdAmount Specifies maximum allowed takingAmount when takingAmount is zero, otherwise specifies minimum allowed makingAmount
  /// @param target Address that will receive swap funds
  /// @param permit Should consist of abiencoded token address and encoded `IERC20Permit.permit` call.
  /// @dev See tests for examples
  function fillOrderToWithPermit(
    Order memory order,
    bytes calldata signature,
    uint256 makingAmount,
    uint256 takingAmount,
    uint256 thresholdAmount,
    address target,
    bytes calldata permit,
    bytes calldata callbackData
  )
    external
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    /* permit */
    {
      require(permit.length >= 20, 'LOP: permit length too low');
      (address token, bytes calldata permitData) = permit.decodeTargetAndData();
      _permit(token, permitData);
    }
    return
      fillOrderTo(
        FillOrderParams(
          order,
          signature,
          makingAmount,
          takingAmount,
          thresholdAmount,
          target,
          callbackData
        ),
        false
      );
  }

  /// @notice Same as `fillOrder`
  /// @param params FillOrderParams:
  ///   - Order order: quote to fill
  ///   - bytes signature: Signature to confirm quote ownership
  ///   - uint256 makingAmount: Making amount
  ///   - uint256 takingAmount: Taking amount
  ///   - uint256 thresholdAmount : Specifies maximum allowed takingAmount when takingAmount is zero, otherwise specifies minimum allowed makingAmount
  ///   - address target: Maker asset recipient
  ///   - bytes callbackData: CallbackData to callback to the msg.sender after receiving the makingAmount, the msg.sender transfer takingAmount to the maker after this call
  /// @param isForcedFill if isForcedFill is true, no matter the maker's balance or allowance is not enough, still try to fill with a new makingAmount = min(makerBalance, makerAllowance)
  /// @return actualMakingAmount
  /// @return actualTakingAmount
  function fillOrderTo(FillOrderParams memory params, bool isForcedFill)
    public
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    require(params.target != address(0), 'LOP: zero target is forbidden');
    bytes32 orderHash = hashOrder(params.order);

    {
      // Stack too deep
      uint256 remainingMakerAmount = _remaining[orderHash];
      if (remainingMakerAmount == _ORDER_FILLED) return (0, 0);
      require(
        params.order.allowedSender == address(0) || params.order.allowedSender == msg.sender,
        'LOP: private order'
      );
      if (remainingMakerAmount == _ORDER_DOES_NOT_EXIST) {
        // First fill: validate order and permit maker asset
        require(
          SignatureChecker.isValidSignatureNow(params.order.maker, orderHash, params.signature),
          'LOP: bad signature'
        );
        remainingMakerAmount = params.order.makingAmount;
        if (params.order.permit.length >= 20) {
          // proceed only if permit length is enough to store address
          (address token, bytes memory permit) = params.order.permit.decodeTargetAndCalldata();
          _permitMemory(token, permit);
          require(_remaining[orderHash] == _ORDER_DOES_NOT_EXIST, 'LOP: reentrancy detected');
        }
      } else {
        unchecked {
          remainingMakerAmount -= 1;
        }
      }

      // Check if order is valid
      if (params.order.predicate.length > 0) {
        bool isValidPredicate = checkPredicate(params.order);
        if (isForcedFill) {
          if (!isValidPredicate) return (0, 0);
        } else {
          require(isValidPredicate, 'LOP: predicate returned false');
        }
      }

      // Compute maker and taker assets amount
      if ((params.takingAmount == 0) == (params.makingAmount == 0)) {
        revert('LOP: only one amount should be 0');
      } else if (params.takingAmount == 0) {
        uint256 requestedMakingAmount = params.makingAmount;
        if (params.makingAmount > remainingMakerAmount) {
          params.makingAmount = remainingMakerAmount;
        }
        /// If isForcedFill is true, set params.makingAmount = min(params.makingAmount, makerBalance, makerAllowance)
        if (isForcedFill) {
          (, params.makingAmount) = _modifyMakingAmount(
            params.order.makerAsset,
            params.order.maker,
            params.makingAmount
          );
        }

        params.takingAmount = _callGetter(
          params.order.getTakerAmount,
          params.order.makingAmount,
          params.makingAmount,
          params.order.takingAmount
        );
        // check that actual rate is not worse than what was expected
        // takingAmount / makingAmount <= thresholdAmount / requestedMakingAmount
        require(
          params.takingAmount * requestedMakingAmount <=
            params.thresholdAmount * params.makingAmount,
          'LOP: taking amount too high'
        );
      } else {
        uint256 requestedTakingAmount = params.takingAmount;
        params.makingAmount = _callGetter(
          params.order.getMakerAmount,
          params.order.takingAmount,
          params.takingAmount,
          params.order.makingAmount
        );
        /// If isForcedFill is true, set params.makingAmount = min(params.makingAmount, remainingMakerAmount, makerBalance, makerAllowance)
        bool isModified = false;
        if (isForcedFill) {
          (isModified, params.makingAmount) = _modifyMakingAmount(
            params.order.makerAsset,
            params.order.maker,
            params.makingAmount
          );
        }
        if (isModified || params.makingAmount > remainingMakerAmount) {
          params.makingAmount = params.makingAmount > remainingMakerAmount
            ? remainingMakerAmount
            : params.makingAmount;
          params.takingAmount = _callGetter(
            params.order.getTakerAmount,
            params.order.makingAmount,
            params.makingAmount,
            params.order.takingAmount
          );
        }
        // check that actual rate is not worse than what was expected
        // makingAmount / takingAmount >= thresholdAmount / requestedTakingAmount
        require(
          params.makingAmount * requestedTakingAmount >=
            params.thresholdAmount * params.takingAmount,
          'LOP: making amount too low'
        );
      }

      require(params.makingAmount > 0 && params.takingAmount > 0, "LOP: can't swap 0 amount");

      // Update remaining amount in storage
      unchecked {
        remainingMakerAmount = remainingMakerAmount - params.makingAmount;
        _remaining[orderHash] = remainingMakerAmount + 1;
      }
      emit OrderFilled(
        msg.sender,
        orderHash,
        remainingMakerAmount,
        params.makingAmount,
        params.takingAmount
      );
    }

    // Maker => FeeRecipient
    uint256 feeAmount = 0;
    if (params.order.feeRecipient != address(0) && params.order.makerTokenFeePercent > 0) {
      feeAmount = (params.makingAmount * params.order.makerTokenFeePercent + BPS - 1) / BPS;
      _makeCall(
        params.order.makerAsset,
        abi.encodePacked(
          IERC20.transferFrom.selector,
          uint256(uint160(params.order.maker)),
          uint256(uint160(params.order.feeRecipient)),
          feeAmount,
          params.order.makerAssetData
        )
      );
    }

    // Maker => Taker
    _makeCall(
      params.order.makerAsset,
      abi.encodePacked(
        IERC20.transferFrom.selector,
        uint256(uint160(params.order.maker)),
        uint256(uint160(params.target)),
        params.makingAmount - feeAmount,
        params.order.makerAssetData
      )
    );

    // Callback to msg.sender
    if (params.callbackData.length > 0) {
      ILimitOrderCallee(msg.sender).limitOrderCall(
        params.makingAmount,
        params.takingAmount,
        params.callbackData
      );
    }

    // Taker => Maker
    _makeCall(
      params.order.takerAsset,
      abi.encodePacked(
        IERC20.transferFrom.selector,
        uint256(uint160(msg.sender)),
        uint256(
          uint160(params.order.receiver == address(0) ? params.order.maker : params.order.receiver)
        ),
        params.takingAmount,
        params.order.takerAssetData
      )
    );

    // Maker can handle funds interactively
    if (params.order.interaction.length >= 20) {
      // proceed only if interaction length is enough to store address
      (address interactionTarget, bytes memory interactionData) = params
        .order
        .interaction
        .decodeTargetAndCalldata();
      require(
        interactionWhitelist[interactionTarget],
        'LOP: the interaction target is not whitelisted'
      );
      InteractiveNotificationReceiver(interactionTarget).notifyFillOrder(
        msg.sender,
        params.order.makerAsset,
        params.order.takerAsset,
        params.makingAmount,
        params.takingAmount,
        interactionData
      );
    }

    return (params.makingAmount, params.takingAmount);
  }

  /// @notice Try to fulfill the takingAmount across multiple orders that have the same makerAsset and takerAsset
  /// @param params FillBatchOrdersParams:
  ///   - Order[] orders: Order list to fill one by one until fulfill the takingAmount
  ///   - bytes[] signatures: Signatures of the orders to confirm quote ownership
  ///   - uint256 takingAmount: Taking amount
  ///   - uint256 thresholdAmount: Minimun makingAmount is acceptable
  ///   - address target: Recipient address for maker asset
  /// @return actualMakingAmount
  /// @return actualTakingAmount
  function fillBatchOrdersTo(FillBatchOrdersParams memory params)
    external
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    require(params.orders.length > 0, 'LOP: empty array');
    require(params.orders.length == params.signatures.length, 'LOP: array size mismatch');
    require(params.takingAmount != 0, 'LOP: zero takingAmount');

    address makerAsset = params.orders[0].makerAsset;
    address takerAsset = params.orders[0].takerAsset;
    uint256 actualMakingAmount = 0;
    uint256 remainingTakingAmount = params.takingAmount;
    for (uint256 i = 0; i < params.orders.length; i++) {
      require(
        makerAsset == params.orders[i].makerAsset && takerAsset == params.orders[i].takerAsset,
        'LOP: invalid pair'
      );
      (uint256 _makingAmount, uint256 _takingAmount) = fillOrderTo(
        FillOrderParams(
          params.orders[i],
          params.signatures[i],
          0,
          remainingTakingAmount,
          0,
          params.target,
          ''
        ),
        true
      );
      actualMakingAmount += _makingAmount;
      remainingTakingAmount -= _takingAmount;
      if (remainingTakingAmount == 0) break;
    }
    require(remainingTakingAmount == 0, 'LOP: cannot fulfill');
    require(actualMakingAmount >= params.thresholdAmount, 'LOP: making amount too low');
    return (actualMakingAmount, params.takingAmount);
  }

  /// @notice Checks order predicate
  function checkPredicate(Order memory order) public view returns (bool) {
    bytes memory result = address(this).functionStaticCall(
      order.predicate,
      'LOP: predicate call failed'
    );
    require(result.length == 32, 'LOP: invalid predicate return');
    return result.decodeBool();
  }

  function hashOrder(Order memory order) public view returns (bytes32) {
    StaticOrder memory staticOrder;
    assembly {
      // solhint-disable-line no-inline-assembly
      staticOrder := order
    }
    return
      _hashTypedDataV4(
        keccak256(
          abi.encode(
            LIMIT_ORDER_TYPEHASH,
            staticOrder,
            keccak256(order.makerAssetData),
            keccak256(order.takerAssetData),
            keccak256(order.getMakerAmount),
            keccak256(order.getTakerAmount),
            keccak256(order.predicate),
            keccak256(order.permit),
            keccak256(order.interaction)
          )
        )
      );
  }

  function _makeCall(address asset, bytes memory assetData) private {
    bytes memory result = asset.functionCall(assetData, 'LOP: asset.call failed');
    if (result.length > 0) {
      require(result.length == 32 && result.decodeBool(), 'LOP: asset.call bad result');
    }
  }

  function _callGetter(
    bytes memory getter,
    uint256 orderExpectedAmount,
    uint256 amount,
    uint256 orderResultAmount
  ) private view returns (uint256) {
    if (getter.length == 0) {
      // On empty getter calldata only exact amount is allowed
      require(amount == orderExpectedAmount, 'LOP: wrong amount');
      return orderResultAmount;
    } else {
      bytes memory result = address(this).functionStaticCall(
        abi.encodePacked(getter, amount),
        'LOP: getAmount call failed'
      );
      require(result.length == 32, 'LOP: invalid getAmount return');
      return result.decodeUint256();
    }
  }

  /// @notice Returns makingAmount = min(params.makingAmount, makerBalance, makerAllowance)
  /// @param makerAsset Maker asset address
  /// @param maker Maker address
  /// @param makingAmount Making amount
  /// @return isModified
  /// @return makingAmount
  function _modifyMakingAmount(
    address makerAsset,
    address maker,
    uint256 makingAmount
  ) private view returns (bool, uint256) {
    uint256 makerBalance = IERC20(makerAsset).balanceOf(maker);
    uint256 makerAllowance = IERC20(makerAsset).allowance(maker, address(this));

    if (makingAmount > makerBalance || makingAmount > makerAllowance) {
      makingAmount = makerBalance > makerAllowance ? makerAllowance : makerBalance;
      return (true, makingAmount);
    }

    return (false, makingAmount);
  }
}

File 2 of 26 : OrderRFQMixin.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol';
import '@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

import './helpers/AmountCalculator.sol';
import './libraries/Permitable.sol';

/// @title RFQ Limit Order mixin
abstract contract OrderRFQMixin is EIP712, AmountCalculator, Permitable {
  using SafeERC20 for IERC20;

  /// @notice Emitted when RFQ gets filled
  event OrderFilledRFQ(
    address indexed taker,
    bytes32 indexed orderHash,
    uint256 makingAmount,
    uint256 takingAmount
  );

  struct OrderRFQ {
    uint256 info; // lowest 64 bits is the order id, next 64 bits is the expiration timestamp
    IERC20 makerAsset;
    IERC20 takerAsset;
    address maker;
    address allowedSender; // equals to Zero address on public orders
    uint256 makingAmount;
    uint256 takingAmount;
    uint256 makingAmountThreshold;
  }

  bytes32 public constant LIMIT_ORDER_RFQ_TYPEHASH =
    keccak256(
      'OrderRFQ(uint256 info,address makerAsset,address takerAsset,address maker,address allowedSender,uint256 makingAmount,uint256 takingAmount)'
    );

  mapping(address => mapping(uint256 => uint256)) private _invalidator;

  /// @notice Returns bitmask for double-spend invalidators based on lowest byte of order.info and filled quotes
  /// @return Result Each bit represents whether corresponding was already invalidated
  function invalidatorForOrderRFQ(address maker, uint256 slot) external view returns (uint256) {
    return _invalidator[maker][slot];
  }

  /// @notice Cancels order's quote
  function cancelOrderRFQ(uint256 orderInfo) external {
    _invalidateOrder(msg.sender, orderInfo);
  }

  /// @notice Fills order's quote, fully or partially (whichever is possible)
  /// @param order Order quote to fill
  /// @param signature Signature to confirm quote ownership
  /// @param makingAmount Making amount
  /// @param takingAmount Taking amount
  function fillOrderRFQ(
    OrderRFQ memory order,
    bytes calldata signature,
    uint256 makingAmount,
    uint256 takingAmount
  )
    external
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    return fillOrderRFQTo(order, signature, makingAmount, takingAmount, msg.sender);
  }

  /// @notice Fills Same as `fillOrderRFQ` but calls permit first,
  /// allowing to approve token spending and make a swap in one transaction.
  /// Also allows to specify funds destination instead of `msg.sender`
  /// @param order Order quote to fill
  /// @param signature Signature to confirm quote ownership
  /// @param makingAmount Making amount
  /// @param takingAmount Taking amount
  /// @param target Address that will receive swap funds
  /// @param permit Should consist of abiencoded token address and encoded `IERC20Permit.permit` call.
  /// @dev See tests for examples
  function fillOrderRFQToWithPermit(
    OrderRFQ memory order,
    bytes calldata signature,
    uint256 makingAmount,
    uint256 takingAmount,
    address target,
    bytes calldata permit
  )
    external
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    _permit(address(order.takerAsset), permit);
    return fillOrderRFQTo(order, signature, makingAmount, takingAmount, target);
  }

  /// @notice Same as `fillOrderRFQ` but allows to specify funds destination instead of `msg.sender`
  /// @param order Order quote to fill
  /// @param signature Signature to confirm quote ownership
  /// @param makingAmount Making amount
  /// @param takingAmount Taking amount
  /// @param target Address that will receive swap funds
  function fillOrderRFQTo(
    OrderRFQ memory order,
    bytes calldata signature,
    uint256 makingAmount,
    uint256 takingAmount,
    address target
  )
    public
    returns (
      uint256, /* actualMakingAmount */
      uint256 /* actualTakingAmount */
    )
  {
    require(target != address(0), 'LOP: zero target is forbidden');

    address maker = order.maker;

    // Validate order
    require(
      order.allowedSender == address(0) || order.allowedSender == msg.sender,
      'LOP: private order'
    );
    bytes32 orderHash = _hashTypedDataV4(keccak256(abi.encode(LIMIT_ORDER_RFQ_TYPEHASH, order)));
    require(
      SignatureChecker.isValidSignatureNow(maker, orderHash, signature),
      'LOP: bad signature'
    );

    {
      // Stack too deep
      uint256 info = order.info;
      // Check time expiration
      uint256 expiration = uint128(info) >> 64;
      require(expiration == 0 || block.timestamp <= expiration, 'LOP: order expired'); // solhint-disable-line not-rely-on-time
      _invalidateOrder(maker, info);
    }

    {
      // stack too deep
      uint256 orderMakingAmount = order.makingAmount;
      uint256 orderTakingAmount = order.takingAmount;
      // Compute partial fill if needed
      if (takingAmount == 0 && makingAmount == 0) {
        // Two zeros means whole order
        makingAmount = orderMakingAmount;
        takingAmount = orderTakingAmount;
      } else if (takingAmount == 0) {
        require(makingAmount <= orderMakingAmount, 'LOP: making amount exceeded');
        takingAmount = getTakerAmount(orderMakingAmount, orderTakingAmount, makingAmount);
      } else if (makingAmount == 0) {
        require(takingAmount <= orderTakingAmount, 'LOP: taking amount exceeded');
        makingAmount = getMakerAmount(orderMakingAmount, orderTakingAmount, takingAmount);
      } else {
        revert('LOP: both amounts are non-zero');
      }
    }

    require(makingAmount > 0 && takingAmount > 0, "LOP: can't swap 0 amount");
    require(makingAmount >= order.makingAmountThreshold, 'LOP: not enough filled amount');
    // Maker => Taker, Taker => Maker
    order.makerAsset.safeTransferFrom(maker, target, makingAmount);
    order.takerAsset.safeTransferFrom(msg.sender, maker, takingAmount);

    emit OrderFilledRFQ(msg.sender, orderHash, makingAmount, takingAmount);
    return (makingAmount, takingAmount);
  }

  function _invalidateOrder(address maker, uint256 orderInfo) private {
    uint256 invalidatorSlot = uint64(orderInfo) >> 8;
    uint256 invalidatorBit = 1 << uint8(orderInfo);
    mapping(uint256 => uint256) storage invalidatorStorage = _invalidator[maker];
    uint256 invalidator = invalidatorStorage[invalidatorSlot];
    require(invalidator & invalidatorBit == 0, 'LOP: invalidated order');
    invalidatorStorage[invalidatorSlot] = invalidator | invalidatorBit;
  }

  function hashOrderRFQ(OrderRFQ memory order) public view returns (bytes32) {
    return _hashTypedDataV4(keccak256(abi.encode(LIMIT_ORDER_RFQ_TYPEHASH, order)));
  }
}

File 2 of 26 : AmountCalculator.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@openzeppelin/contracts/utils/Address.sol';

/// @title A helper contract for calculations related to order amounts
contract AmountCalculator {
  using Address for address;

  /// @notice Calculates maker amount
  /// @return Result Floored maker amount
  function getMakerAmount(
    uint256 orderMakerAmount,
    uint256 orderTakerAmount,
    uint256 swapTakerAmount
  ) public pure returns (uint256) {
    return (swapTakerAmount * orderMakerAmount) / orderTakerAmount;
  }

  /// @notice Calculates taker amount
  /// @return Result Ceiled taker amount
  function getTakerAmount(
    uint256 orderMakerAmount,
    uint256 orderTakerAmount,
    uint256 swapMakerAmount
  ) public pure returns (uint256) {
    return (swapMakerAmount * orderTakerAmount + orderMakerAmount - 1) / orderMakerAmount;
  }

  /// @notice Performs an arbitrary call to target with data
  /// @return Result Bytes transmuted to uint256
  function arbitraryStaticCall(address target, bytes memory data) external view returns (uint256) {
    bytes memory result = target.functionStaticCall(data, 'AC: arbitraryStaticCall');
    return abi.decode(result, (uint256));
  }
}

File 2 of 26 : ChainlinkCalculator.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol';
import '@openzeppelin/contracts/utils/math/SafeCast.sol';

/// @title A helper contract for interactions with https://docs.chain.link
contract ChainlinkCalculator {
  using SafeCast for int256;

  uint256 private constant _SPREAD_DENOMINATOR = 1e9;
  uint256 private constant _ORACLE_EXPIRATION_TIME = 30 minutes;
  uint256 private constant _INVERSE_MASK = 1 << 255;

  /// @notice Calculates price of token relative to oracle unit (ETH or USD)
  /// @param inverseAndSpread concatenated inverse flag and spread.
  /// Lowest 254 bits specify spread amount. Spread is scaled by 1e9, i.e. 101% = 1.01e9, 99% = 0.99e9.
  /// Highest bit is set when oracle price should be inverted,
  /// e.g. for DAI-ETH oracle, inverse=false means that we request DAI price in ETH
  /// and inverse=true means that we request ETH price in DAI
  /// @return Amount * spread * oracle price
  function singlePrice(
    AggregatorV3Interface oracle,
    uint256 inverseAndSpread,
    uint256 amount
  ) external view returns (uint256) {
    (, int256 latestAnswer, , uint256 latestTimestamp, ) = oracle.latestRoundData();
    // solhint-disable-next-line not-rely-on-time
    require(latestTimestamp + _ORACLE_EXPIRATION_TIME > block.timestamp, 'CC: stale data');
    bool inverse = inverseAndSpread & _INVERSE_MASK > 0;
    uint256 spread = inverseAndSpread & (~_INVERSE_MASK);
    if (inverse) {
      return
        (amount * spread * (10**oracle.decimals())) /
        latestAnswer.toUint256() /
        _SPREAD_DENOMINATOR;
    } else {
      return
        (amount * spread * latestAnswer.toUint256()) /
        (10**oracle.decimals()) /
        _SPREAD_DENOMINATOR;
    }
  }

  /// @notice Calculates price of token A relative to token B. Note that order is important
  /// @return Result Token A relative price times amount
  function doublePrice(
    AggregatorV3Interface oracle1,
    AggregatorV3Interface oracle2,
    uint256 spread,
    uint256 amount
  ) external view returns (uint256) {
    require(oracle1.decimals() == oracle2.decimals(), "CC: oracle decimals don't match");

    (, int256 latestAnswer1, , uint256 latestTimestamp1, ) = oracle1.latestRoundData();
    (, int256 latestAnswer2, , uint256 latestTimestamp2, ) = oracle2.latestRoundData();
    // solhint-disable-next-line not-rely-on-time
    require(latestTimestamp1 + _ORACLE_EXPIRATION_TIME > block.timestamp, 'CC: stale data O1');
    // solhint-disable-next-line not-rely-on-time
    require(latestTimestamp2 + _ORACLE_EXPIRATION_TIME > block.timestamp, 'CC: stale data O2');

    return
      (amount * spread * latestAnswer1.toUint256()) /
      latestAnswer2.toUint256() /
      _SPREAD_DENOMINATOR;
  }
}

File 2 of 26 : NonceManager.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

/// @title A helper contract for managing nonce of tx sender
contract NonceManager {
  event NonceIncreased(address indexed maker, uint256 oldNonce, uint256 newNonce);

  mapping(address => uint256) public nonce;

  /// @notice Advances nonce by one
  function increaseNonce() external {
    advanceNonce(1);
  }

  /// @notice Advances nonce by specified amount
  function advanceNonce(uint8 amount) public {
    uint256 newNonce = nonce[msg.sender] + amount;
    nonce[msg.sender] = newNonce;
    emit NonceIncreased(msg.sender, newNonce - amount, newNonce);
  }

  /// @notice Checks if `makerAddress` has specified `makerNonce`
  /// @return Result True if `makerAddress` has specified nonce. Otherwise, false
  function nonceEquals(address makerAddress, uint256 makerNonce) external view returns (bool) {
    return nonce[makerAddress] == makerNonce;
  }
}

File 2 of 26 : PredicateHelper.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@openzeppelin/contracts/utils/Address.sol';

/// @title A helper contract for executing boolean functions on arbitrary target call results
contract PredicateHelper {
  using Address for address;

  /// @notice Calls every target with corresponding data
  /// @return Result True if call to any target returned True. Otherwise, false
  function or(address[] calldata targets, bytes[] calldata data) external view returns (bool) {
    require(targets.length == data.length, 'PH: input array size mismatch');
    for (uint256 i = 0; i < targets.length; i++) {
      bytes memory result = targets[i].functionStaticCall(data[i], "PH: 'or' subcall failed");
      require(result.length == 32, 'PH: invalid call result');
      if (abi.decode(result, (bool))) {
        return true;
      }
    }
    return false;
  }

  /// @notice Calls every target with corresponding data
  /// @return Result True if calls to all targets returned True. Otherwise, false
  function and(address[] calldata targets, bytes[] calldata data) external view returns (bool) {
    require(targets.length == data.length, 'PH: input array size mismatch');
    for (uint256 i = 0; i < targets.length; i++) {
      bytes memory result = targets[i].functionStaticCall(data[i], "PH: 'and' subcall failed");
      require(result.length == 32, 'PH: invalid call result');
      if (!abi.decode(result, (bool))) {
        return false;
      }
    }
    return true;
  }

  /// @notice Calls target with specified data and tests if it's equal to the value
  /// @param value Value to test
  /// @return Result True if call to target returns the same value as `value`. Otherwise, false
  function eq(
    uint256 value,
    address target,
    bytes memory data
  ) external view returns (bool) {
    bytes memory result = target.functionStaticCall(data, 'PH: eq');
    require(result.length == 32, 'PH: invalid call result');
    return abi.decode(result, (uint256)) == value;
  }

  /// @notice Calls target with specified data and tests if it's lower than value
  /// @param value Value to test
  /// @return Result True if call to target returns value which is lower than `value`. Otherwise, false
  function lt(
    uint256 value,
    address target,
    bytes memory data
  ) external view returns (bool) {
    bytes memory result = target.functionStaticCall(data, 'PH: lt');
    require(result.length == 32, 'PH: invalid call result');
    return abi.decode(result, (uint256)) < value;
  }

  /// @notice Calls target with specified data and tests if it's bigger than value
  /// @param value Value to test
  /// @return Result True if call to target returns value which is bigger than `value`. Otherwise, false
  function gt(
    uint256 value,
    address target,
    bytes memory data
  ) external view returns (bool) {
    bytes memory result = target.functionStaticCall(data, 'PH: gt');
    require(result.length == 32, 'PH: invalid call result');
    return abi.decode(result, (uint256)) > value;
  }

  /// @notice Checks passed time against block timestamp
  /// @return Result True if current block timestamp is lower than `time`. Otherwise, false
  function timestampBelow(uint256 time) external view returns (bool) {
    return block.timestamp < time; // solhint-disable-line not-rely-on-time
  }
}

File 2 of 26 : IDaiLikePermit.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/// @title Interface for DAI-style permits
interface IDaiLikePermit {
  function permit(
    address holder,
    address spender,
    uint256 nonce,
    uint256 expiry,
    bool allowed,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external;
}

File 2 of 26 : ILimitOrderCallee.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

/// @title Interface for DAI-style permits
interface ILimitOrderCallee {
  function limitOrderCall(
    uint256 makingAmount,
    uint256 takingAmount,
    bytes memory callbackData
  ) external;
}

File 2 of 26 : InteractiveNotificationReceiver.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/// @title Interface for interactor which acts between `maker => taker` and `taker => maker` transfers.
interface InteractiveNotificationReceiver {
  /// @notice Callback method that gets called after taker transferred funds to maker but before
  /// the opposite transfer happened
  function notifyFillOrder(
    address taker,
    address makerAsset,
    address takerAsset,
    uint256 makingAmount,
    uint256 takingAmount,
    bytes memory interactiveData
  ) external;
}

File 2 of 26 : ArgumentsDecoder.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

/// @title Library with gas efficient alternatives to `abi.decode`
library ArgumentsDecoder {
  function decodeUint256(bytes memory data) internal pure returns (uint256) {
    uint256 value;
    assembly {
      // solhint-disable-line no-inline-assembly
      value := mload(add(data, 0x20))
    }
    return value;
  }

  function decodeBool(bytes memory data) internal pure returns (bool) {
    bool value;
    assembly {
      // solhint-disable-line no-inline-assembly
      value := eq(mload(add(data, 0x20)), 1)
    }
    return value;
  }

  function decodeTargetAndCalldata(bytes memory data)
    internal
    pure
    returns (address, bytes memory)
  {
    address target;
    bytes memory args;
    assembly {
      // solhint-disable-line no-inline-assembly
      target := mload(add(data, 0x14))
      args := add(data, 0x14)
      mstore(args, sub(mload(data), 0x14))
    }
    return (target, args);
  }

  function decodeTargetAndData(bytes calldata data)
    internal
    pure
    returns (address, bytes calldata)
  {
    address target;
    bytes calldata args;
    assembly {
      // solhint-disable-line no-inline-assembly
      target := shr(96, calldataload(data.offset))
    }
    args = data[20:];
    return (target, args);
  }
}

File 2 of 26 : Permitable.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

import '@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol';
import './RevertReasonParser.sol';
import '../interfaces/IDaiLikePermit.sol';

/// @title Base contract with common permit handling logics
abstract contract Permitable {
  function _permit(address token, bytes calldata permit) internal {
    if (permit.length > 0) {
      bool success;
      bytes memory result;
      if (permit.length == 32 * 7) {
        // solhint-disable-next-line avoid-low-level-calls
        (success, result) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
      } else if (permit.length == 32 * 8) {
        // solhint-disable-next-line avoid-low-level-calls
        (success, result) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
      } else {
        revert('Wrong permit length');
      }
      if (!success) {
        revert(RevertReasonParser.parse(result, 'Permit failed: '));
      }
    }
  }

  function _permitMemory(address token, bytes memory permit) internal {
    if (permit.length > 0) {
      bool success;
      bytes memory result;
      if (permit.length == 32 * 7) {
        // solhint-disable-next-line avoid-low-level-calls
        (success, result) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
      } else if (permit.length == 32 * 8) {
        // solhint-disable-next-line avoid-low-level-calls
        (success, result) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
      } else {
        revert('Wrong permit length');
      }
      if (!success) {
        revert(RevertReasonParser.parse(result, 'Permit failed: '));
      }
    }
  }
}

File 2 of 26 : RevertReasonParser.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;
pragma abicoder v1;

/*
“Copyright (c) 2019-2021 1inch 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”.
*/

/// @title Library that allows to parse unsuccessful arbitrary calls revert reasons.
/// See https://solidity.readthedocs.io/en/latest/control-structures.html#revert for details.
/// Note that we assume revert reason being abi-encoded as Error(string) so it may fail to parse reason
/// if structured reverts appear in the future.
///
/// All unsuccessful parsings get encoded as Unknown(data) string
library RevertReasonParser {
  bytes4 private constant _PANIC_SELECTOR = bytes4(keccak256('Panic(uint256)'));
  bytes4 private constant _ERROR_SELECTOR = bytes4(keccak256('Error(string)'));

  function parse(bytes memory data, string memory prefix) internal pure returns (string memory) {
    if (data.length >= 4) {
      bytes4 selector;

      assembly {
        // solhint-disable-line no-inline-assembly
        selector := mload(add(data, 0x20))
      }

      // 68 = 4-byte selector + 32 bytes offset + 32 bytes length
      if (selector == _ERROR_SELECTOR && data.length >= 68) {
        uint256 offset;
        bytes memory reason;
        assembly {
          // solhint-disable-line no-inline-assembly
          // 36 = 32 bytes data length + 4-byte selector
          offset := mload(add(data, 36))
          reason := add(data, add(36, offset))
        }
        /*
                    revert reason is padded up to 32 bytes with ABI encoder: Error(string)
                    also sometimes there is extra 32 bytes of zeros padded in the end:
                    https://github.com/ethereum/solidity/issues/10170
                    because of that we can't check for equality and instead check
                    that offset + string length + extra 36 bytes is less than overall data length
                */
        require(data.length >= 36 + offset + reason.length, 'Invalid revert reason');
        return string(abi.encodePacked(prefix, 'Error(', reason, ')'));
      }
      // 36 = 4-byte selector + 32 bytes integer
      else if (selector == _PANIC_SELECTOR && data.length == 36) {
        uint256 code;
        assembly {
          // solhint-disable-line no-inline-assembly
          // 36 = 32 bytes data length + 4-byte selector
          code := mload(add(data, 36))
        }
        return string(abi.encodePacked(prefix, 'Panic(', _toHex(code), ')'));
      }
    }

    return string(abi.encodePacked(prefix, 'Unknown(', _toHex(data), ')'));
  }

  function _toHex(uint256 value) private pure returns (string memory) {
    return _toHex(abi.encodePacked(value));
  }

  function _toHex(bytes memory data) private pure returns (string memory) {
    bytes16 alphabet = 0x30313233343536373839616263646566;
    bytes memory str = new bytes(2 + data.length * 2);
    str[0] = '0';
    str[1] = 'x';
    for (uint256 i = 0; i < data.length; i++) {
      str[2 * i + 2] = alphabet[uint8(data[i] >> 4)];
      str[2 * i + 3] = alphabet[uint8(data[i] & 0x0f)];
    }
    return string(str);
  }
}

Settings
{
  "remappings": [
    "@chainlink/=lib/chainlink/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "chainlink/=lib/chainlink/contracts/src/v0.8/dev/vendor/@arbitrum/nitro-contracts/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 9999
  },
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"maker","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldNonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newNonce","type":"uint256"}],"name":"NonceIncreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"maker","type":"address"},{"indexed":false,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"remainingRaw","type":"uint256"}],"name":"OrderCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"taker","type":"address"},{"indexed":false,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"remaining","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"makingAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"takingAmount","type":"uint256"}],"name":"OrderFilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"taker","type":"address"},{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"makingAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"takingAmount","type":"uint256"}],"name":"OrderFilledRFQ","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_address","type":"address"},{"indexed":false,"internalType":"bool","name":"isWhitelist","type":"bool"}],"name":"UpdatedInteractionWhitelist","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIMIT_ORDER_RFQ_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIMIT_ORDER_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"amount","type":"uint8"}],"name":"advanceNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"and","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"arbitraryStaticCall","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order[]","name":"orders","type":"tuple[]"}],"name":"cancelBatchOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order","name":"order","type":"tuple"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderInfo","type":"uint256"}],"name":"cancelOrderRFQ","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order","name":"order","type":"tuple"}],"name":"checkPredicate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract AggregatorV3Interface","name":"oracle1","type":"address"},{"internalType":"contract AggregatorV3Interface","name":"oracle2","type":"address"},{"internalType":"uint256","name":"spread","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"doublePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"eq","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order[]","name":"orders","type":"tuple[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"thresholdAmount","type":"uint256"},{"internalType":"address","name":"target","type":"address"}],"internalType":"struct OrderMixin.FillBatchOrdersParams","name":"params","type":"tuple"}],"name":"fillBatchOrdersTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"thresholdAmount","type":"uint256"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"name":"fillOrder","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"info","type":"uint256"},{"internalType":"contract IERC20","name":"makerAsset","type":"address"},{"internalType":"contract IERC20","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"makingAmountThreshold","type":"uint256"}],"internalType":"struct OrderRFQMixin.OrderRFQ","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"}],"name":"fillOrderRFQ","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"info","type":"uint256"},{"internalType":"contract IERC20","name":"makerAsset","type":"address"},{"internalType":"contract IERC20","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"makingAmountThreshold","type":"uint256"}],"internalType":"struct OrderRFQMixin.OrderRFQ","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"target","type":"address"}],"name":"fillOrderRFQTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"info","type":"uint256"},{"internalType":"contract IERC20","name":"makerAsset","type":"address"},{"internalType":"contract IERC20","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"makingAmountThreshold","type":"uint256"}],"internalType":"struct OrderRFQMixin.OrderRFQ","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"permit","type":"bytes"}],"name":"fillOrderRFQToWithPermit","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"thresholdAmount","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"internalType":"struct OrderMixin.FillOrderParams","name":"params","type":"tuple"},{"internalType":"bool","name":"isForcedFill","type":"bool"}],"name":"fillOrderTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"thresholdAmount","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"name":"fillOrderToWithPermit","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderMakerAmount","type":"uint256"},{"internalType":"uint256","name":"orderTakerAmount","type":"uint256"},{"internalType":"uint256","name":"swapTakerAmount","type":"uint256"}],"name":"getMakerAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderMakerAmount","type":"uint256"},{"internalType":"uint256","name":"orderTakerAmount","type":"uint256"},{"internalType":"uint256","name":"swapMakerAmount","type":"uint256"}],"name":"getTakerAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"gt","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"makerAsset","type":"address"},{"internalType":"address","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint32","name":"makerTokenFeePercent","type":"uint32"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"getMakerAmount","type":"bytes"},{"internalType":"bytes","name":"getTakerAmount","type":"bytes"},{"internalType":"bytes","name":"predicate","type":"bytes"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"interaction","type":"bytes"}],"internalType":"struct OrderMixin.Order","name":"order","type":"tuple"}],"name":"hashOrder","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"info","type":"uint256"},{"internalType":"contract IERC20","name":"makerAsset","type":"address"},{"internalType":"contract IERC20","name":"takerAsset","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"allowedSender","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"takingAmount","type":"uint256"},{"internalType":"uint256","name":"makingAmountThreshold","type":"uint256"}],"internalType":"struct OrderRFQMixin.OrderRFQ","name":"order","type":"tuple"}],"name":"hashOrderRFQ","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increaseNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"maker","type":"address"},{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"invalidatorForOrderRFQ","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"lt","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"makerAddress","type":"address"},{"internalType":"uint256","name":"makerNonce","type":"uint256"}],"name":"nonceEquals","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"or","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"remaining","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"remainingRaw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"orderHashes","type":"bytes32[]"}],"name":"remainingsRaw","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"simulateCalls","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract AggregatorV3Interface","name":"oracle","type":"address"},{"internalType":"uint256","name":"inverseAndSpread","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"singlePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"timestampBelow","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"bool","name":"isWhitelist","type":"bool"}],"name":"updateInteractionWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102c85760003560e01c80637e54f0921161017b578063bc1ed74c116100d8578063cf6fc6e31161008c578063e613330111610071578063e613330114610639578063f2fde38b1461064c578063f4a215c31461065f57600080fd5b8063cf6fc6e3146105f9578063da589f3d1461062657600080fd5b8063bf45f189116100bd578063bf45f189146105cb578063c05435f1146105de578063c53a0292146105f157600080fd5b8063bc1ed74c146105a5578063bf15fcd8146105b857600080fd5b8063942461bb1161012f578063a52a0b0e11610114578063a52a0b0e1461056c578063ad60d2a41461057f578063b6df4d471461059257600080fd5b8063942461bb14610539578063961d5b1e1461055957600080fd5b8063825caba111610160578063825caba1146104f8578063871919d51461050b5780638da5cb5b1461051e57600080fd5b80637e54f092146104c55780637f29a59d146104e557600080fd5b806342e7f66b116102295780636aa0caf8116101dd578063715018a6116101c2578063715018a61461049757806372c244a81461049f57806374e75938146104b257600080fd5b80636aa0caf81461046257806370ae92d21461047757600080fd5b806354dd5f741161020e57806354dd5f74146103f257806356f161241461041957806363592c2b1461044f57600080fd5b806342e7f66b146103cc578063452d8087146103df57600080fd5b8063296637bf1161028057806336006bf31161026557806336006bf31461039e5780633644e515146103b157806341c79a84146103b957600080fd5b8063296637bf1461037857806332565d611461038b57600080fd5b806312d12f98116102b157806312d12f981461032a578063150b195f146103525780632186f6921461036557600080fd5b8063057702e9146102cd57806306bf53d0146102f5575b600080fd5b6102e06102db3660046149af565b610672565b60405190151581526020015b60405180910390f35b61031c7f74ab4f0cde46aaf927859983f7d04002116dd057d4c4941f6dbfb775c3e31f4581565b6040519081526020016102ec565b61033d610338366004614c32565b610741565b604080519283526020830191909152016102ec565b61031c610360366004614d94565b610800565b61031c610373366004614db1565b610859565b61031c610386366004614de6565b610944565b6102e06103993660046149af565b61097a565b61031c6103ac366004614e12565b610a42565b61031c610d69565b61033d6103c7366004614e58565b610d78565b6102e06103da366004614db1565b610eb7565b61033d6103ed366004614f49565b610f61565b61031c7f1c78ba9cd318bd0d3a52be3de7029ea8b16cd87be2927d2e524d4f7607f363e481565b61031c610427366004614fb3565b6001600160a01b03919091166000908152600460209081526040808320938352929052205490565b6102e061045d366004614fdf565b421090565b610475610470366004615011565b610f80565b005b61031c61048536600461504a565b60006020819052908152604090205481565b610475611009565b6104756104ad366004615067565b61101d565b61033d6104c036600461508a565b611099565b61031c6104d3366004614fdf565b60009081526002602052604090205490565b6104756104f336600461514f565b611515565b610475610506366004614fdf565b611769565b6102e06105193660046149af565b611776565b6001546040516001600160a01b0390911681526020016102ec565b61054c6105473660046151df565b61183e565b6040516102ec919061526a565b6102e061056736600461514f565b6118f7565b61047561057a366004614db1565b611ab2565b61047561058d366004615339565b611bcd565b61033d6105a036600461536e565b611c0f565b61031c6105b3366004614fdf565b611fb8565b61031c6105c6366004615493565b61201e565b61033d6105d93660046154e3565b612095565b61031c6105ec3660046155d9565b612a6f565b610475612c98565b6102e0610607366004614fb3565b6001600160a01b03919091166000908152602081905260409020541490565b61033d61063436600461560e565b612ca2565b6102e061064736600461514f565b612cc2565b61047561065a36600461504a565b612e59565b61031c61066d366004614de6565b612ee6565b6000806106c8836040518060400160405280600681526020017f50483a2067740000000000000000000000000000000000000000000000000000815250866001600160a01b0316612ef39092919063ffffffff16565b905080516020146107205760405162461bcd60e51b815260206004820152601760248201527f50483a20696e76616c69642063616c6c20726573756c7400000000000000000060448201526064015b60405180910390fd5b8481806020019051810190610735919061569c565b119150505b9392505050565b6000806107ef6040518060e001604052808c81526020018b8b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525060208082018b905260408083018b9052606083018a90523360808401528051601f890183900483028101830190915287815260a090920191908890889081908401838280828437600092018290525093909452509091506120959050565b915091509850989650505050505050565b60006108537f74ab4f0cde46aaf927859983f7d04002116dd057d4c4941f6dbfb775c3e31f45836040516020016108389291906156b5565b60405160208183030381529060405280519060200120612fe6565b92915050565b6040805161014081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905282905061073a7f1c78ba9cd318bd0d3a52be3de7029ea8b16cd87be2927d2e524d4f7607f363e482856101400151805190602001208661016001518051906020012087610180015180519060200120886101a0015180519060200120896101c00151805190602001208a6101e00151805190602001208b61020001518051906020012060405160200161083899989796959493929190615738565b600083600181610954868661586b565b61095e919061588a565b61096891906158a2565b61097291906158b9565b949350505050565b6000806109d0836040518060400160405280600681526020017f50483a2065710000000000000000000000000000000000000000000000000000815250866001600160a01b0316612ef39092919063ffffffff16565b90508051602014610a235760405162461bcd60e51b815260206004820152601760248201527f50483a20696e76616c69642063616c6c20726573756c740000000000000000006044820152606401610717565b8481806020019051810190610a38919061569c565b1495945050505050565b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a82573d6000803e3d6000fd5b505050506040513d6020811015610a9857600080fd5b5051604080517f313ce567000000000000000000000000000000000000000000000000000000008152905160ff909216916001600160a01b0388169163313ce5679160048083019260209291908290030181865afa158015610afe573d6000803e3d6000fd5b505050506040513d6020811015610b1457600080fd5b505160ff1614610b6b576040805162461bcd60e51b815260206004820152601f60248201527f43433a206f7261636c6520646563696d616c7320646f6e2774206d6174636800604482015290519081900360640190fd5b600080866001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015610bac573d6000803e3d6000fd5b505050506040513d60a0811015610bc257600080fd5b506020810151606090910151604080517ffeaf968c000000000000000000000000000000000000000000000000000000008152905192945090925060009182916001600160a01b038a169163feaf968c9160048082019260a0929091908290030181865afa158015610c38573d6000803e3d6000fd5b505050506040513d60a0811015610c4e57600080fd5b506020810151606090910151909250905042610c6c6107088561588a565b11610cbe576040805162461bcd60e51b815260206004820152601160248201527f43433a207374616c652064617461204f31000000000000000000000000000000604482015290519081900360640190fd5b42610ccb6107088361588a565b11610d1d576040805162461bcd60e51b815260206004820152601160248201527f43433a207374616c652064617461204f32000000000000000000000000000000604482015290519081900360640190fd5b633b9aca00610d2b8361304f565b610d348661304f565b610d3e8a8a61586b565b610d48919061586b565b610d5291906158b9565b610d5c91906158b9565b9998505050505050505050565b6000610d736130a5565b905090565b6000806014851015610dcc5760405162461bcd60e51b815260206004820152601a60248201527f4c4f503a207065726d6974206c656e67746820746f6f206c6f770000000000006044820152606401610717565b6000366000610ddb89896131cc565b925092509250610dec8383836131f5565b505050610ea36040518060e001604052808f81526020018e8e8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525060208082018e905260408083018e9052606083018d90526001600160a01b038c1660808401528051601f890183900483028101830190915287815260a090920191908890889081908401838280828437600092018290525093909452509091506120959050565b915091509b509b9950505050505050505050565b6101c081015160408051808201909152601a81527f4c4f503a207072656469636174652063616c6c206661696c656400000000000060208201526000918291610f01913091612ef3565b90508051602014610f545760405162461bcd60e51b815260206004820152601d60248201527f4c4f503a20696e76616c6964207072656469636174652072657475726e0000006044820152606401610717565b602081015160011461073a565b600080610f72878787878733611099565b915091509550959350505050565b610f886134ba565b6001600160a01b03821660008181526003602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168515159081179091558251938452908301527f96b334259df143c9ad3afe9060498fd354c454701b379de2e6c83ec2336e60aa910160405180910390a15050565b6110116134ba565b61101b6000613514565b565b3360009081526020819052604081205461103b9060ff84169061588a565b3360008181526020819052604090208290559091507fdc0537f71d06d3708f52baf4ddf6918b25f1a145ba08873de27485682b35cac161107e60ff8516846158a2565b60408051918252602082018590528051918290030190a25050565b6000806001600160a01b0383166110f25760405162461bcd60e51b815260206004820152601d60248201527f4c4f503a207a65726f2074617267657420697320666f7262696464656e0000006044820152606401610717565b606088015160808901516001600160a01b0316158061111d575060808901516001600160a01b031633145b6111695760405162461bcd60e51b815260206004820152601260248201527f4c4f503a2070726976617465206f7264657200000000000000000000000000006044820152606401610717565b60006111a17f74ab4f0cde46aaf927859983f7d04002116dd057d4c4941f6dbfb775c3e31f458b6040516020016108389291906156b5565b90506111e482828b8b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061357e92505050565b6112305760405162461bcd60e51b815260206004820152601260248201527f4c4f503a20626164207369676e617475726500000000000000000000000000006044820152606401610717565b895167ffffffffffffffff604082901c1680158061124e5750804211155b61129a5760405162461bcd60e51b815260206004820152601260248201527f4c4f503a206f72646572206578706972656400000000000000000000000000006044820152606401610717565b6112a48483613706565b505060a08a015160c08b0151871580156112bc575088155b156112cc578198508097506113e2565b8761133357818911156113215760405162461bcd60e51b815260206004820152601b60248201527f4c4f503a206d616b696e6720616d6f756e7420657863656564656400000000006044820152606401610717565b61132c82828b610944565b97506113e2565b8861139a57808811156113885760405162461bcd60e51b815260206004820152601b60248201527f4c4f503a2074616b696e6720616d6f756e7420657863656564656400000000006044820152606401610717565b61139382828a612ee6565b98506113e2565b60405162461bcd60e51b815260206004820152601e60248201527f4c4f503a20626f746820616d6f756e747320617265206e6f6e2d7a65726f00006044820152606401610717565b50506000871180156113f45750600086115b6114405760405162461bcd60e51b815260206004820152601860248201527f4c4f503a2063616e27742073776170203020616d6f756e7400000000000000006044820152606401610717565b8960e001518710156114945760405162461bcd60e51b815260206004820152601d60248201527f4c4f503a206e6f7420656e6f7567682066696c6c656420616d6f756e740000006044820152606401610717565b60208a01516114ae906001600160a01b031683878a6137ab565b60408a01516114c8906001600160a01b03163384896137ab565b6040805188815260208101889052829133917feb6e58fbaca6cb4b6726ec4e1ac663797ae31405c07620f4d6babd436ee9f0f7910160405180910390a35094989397509295505050505050565b8281146115645760405162461bcd60e51b815260206004820152601860248201527f4c4f503a2061727261792073697a65206d69736d6174636800000000000000006044820152606401610717565b60008367ffffffffffffffff81111561157f5761157f61486f565b6040519080825280601f01601f1916602001820160405280156115a9576020820181803683370190505b50905060005b84811015611731576000808787848181106115cc576115cc6158f4565b90506020020160208101906115e1919061504a565b6001600160a01b03168686858181106115fc576115fc6158f4565b905060200281019061160e9190615923565b60405161161c929190615988565b6000604051808303816000865af19150503d8060008114611659576040519150601f19603f3d011682016040523d82523d6000602084013e61165e565b606091505b5091509150818015611671575060008151115b1561168e578051602014801561168b575060208101516001145b91505b816116b9577f30000000000000000000000000000000000000000000000000000000000000006116db565b7f31000000000000000000000000000000000000000000000000000000000000005b8484815181106116ed576116ed6158f4565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505050808061172990615998565b9150506115af565b508060405160200161174391906159df565b60408051601f198184030181529082905262461bcd60e51b825261071791600401615a50565b6117733382613706565b50565b6000806117cc836040518060400160405280600681526020017f50483a206c740000000000000000000000000000000000000000000000000000815250866001600160a01b0316612ef39092919063ffffffff16565b9050805160201461181f5760405162461bcd60e51b815260206004820152601760248201527f50483a20696e76616c69642063616c6c20726573756c740000000000000000006044820152606401610717565b8481806020019051810190611834919061569c565b1095945050505050565b60606000825167ffffffffffffffff81111561185c5761185c61486f565b604051908082528060200260200182016040528015611885578160200160208202803683370190505b50905060005b83518110156118f057600260008583815181106118aa576118aa6158f4565b60200260200101518152602001908152602001600020548282815181106118d3576118d36158f4565b6020908102919091010152806118e881615998565b91505061188b565b5092915050565b60008382146119485760405162461bcd60e51b815260206004820152601d60248201527f50483a20696e7075742061727261792073697a65206d69736d617463680000006044820152606401610717565b60005b84811015611aa6576000611a1d85858481811061196a5761196a6158f4565b905060200281019061197c9190615923565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051808201909152601881527f50483a2027616e64272073756263616c6c206661696c65640000000000000000602082015291508a905089868181106119f8576119f86158f4565b9050602002016020810190611a0d919061504a565b6001600160a01b03169190612ef3565b90508051602014611a705760405162461bcd60e51b815260206004820152601760248201527f50483a20696e76616c69642063616c6c20726573756c740000000000000000006044820152606401610717565b80806020019051810190611a849190615a63565b611a9357600092505050610972565b5080611a9e81615998565b91505061194b565b50600195945050505050565b60608101516001600160a01b03163314611b0e5760405162461bcd60e51b815260206004820152601260248201527f4c4f503a204163636573732064656e69656400000000000000000000000000006044820152606401610717565b6000611b1982610859565b6000818152600260205260409020549091506001811415611b7c5760405162461bcd60e51b815260206004820152601360248201527f4c4f503a20616c72656164792066696c6c6564000000000000000000000000006044820152606401610717565b604080518381526020810183905233917fcbfa7d191838ece7ba4783ca3a30afd316619b7f368094b57ee7ffde9a923db1910160405180910390a25060009081526002602052604090206001905550565b60005b8151811015611c0b57611bfb828281518110611bee57611bee6158f4565b6020026020010151611ab2565b611c0481615998565b9050611bd0565b5050565b600080600083600001515111611c675760405162461bcd60e51b815260206004820152601060248201527f4c4f503a20656d707479206172726179000000000000000000000000000000006044820152606401610717565b60208301515183515114611cbd5760405162461bcd60e51b815260206004820152601860248201527f4c4f503a2061727261792073697a65206d69736d6174636800000000000000006044820152606401610717565b6040830151611d0e5760405162461bcd60e51b815260206004820152601660248201527f4c4f503a207a65726f2074616b696e67416d6f756e74000000000000000000006044820152606401610717565b60008360000151600081518110611d2757611d276158f4565b602002602001015160200151905060008460000151600081518110611d4e57611d4e6158f4565b60200260200101516040015190506000808660400151905060005b875151811015611f05578751805182908110611d8757611d876158f4565b6020026020010151602001516001600160a01b0316856001600160a01b0316148015611de357508751805182908110611dc257611dc26158f4565b6020026020010151604001516001600160a01b0316846001600160a01b0316145b611e2f5760405162461bcd60e51b815260206004820152601160248201527f4c4f503a20696e76616c696420706169720000000000000000000000000000006044820152606401610717565b600080611ec76040518060e001604052808c600001518681518110611e5657611e566158f4565b602002602001015181526020018c602001518681518110611e7957611e796158f4565b6020026020010151815260200160008152602001868152602001600081526020018c608001516001600160a01b03168152602001604051806020016040528060008152508152506001612095565b9092509050611ed6828661588a565b9450611ee281856158a2565b935083611ef0575050611f05565b50508080611efd90615998565b915050611d69565b508015611f545760405162461bcd60e51b815260206004820152601360248201527f4c4f503a2063616e6e6f742066756c66696c6c000000000000000000000000006044820152606401610717565b8660600151821015611fa85760405162461bcd60e51b815260206004820152601a60248201527f4c4f503a206d616b696e6720616d6f756e7420746f6f206c6f770000000000006044820152606401610717565b5060409095015194959350505050565b600081815260026020526040812054806120145760405162461bcd60e51b815260206004820152601260248201527f4c4f503a20556e6b6e6f776e206f7264657200000000000000000000000000006044820152606401610717565b6000190192915050565b600080612074836040518060400160405280601781526020017f41433a2061726269747261727953746174696343616c6c000000000000000000815250866001600160a01b0316612ef39092919063ffffffff16565b905080806020019051602081101561208b57600080fd5b5051949350505050565b60a082015160009081906001600160a01b03166120f45760405162461bcd60e51b815260206004820152601d60248201527f4c4f503a207a65726f2074617267657420697320666f7262696464656e0000006044820152606401610717565b60006121038560000151610859565b600081815260026020526040902054909150600181141561212c57600080935093505050612a68565b855160a001516001600160a01b031615806121545750855160a001516001600160a01b031633145b6121a05760405162461bcd60e51b815260206004820152601260248201527f4c4f503a2070726976617465206f7264657200000000000000000000000000006044820152606401610717565b806122c0576121bc86600001516060015183886020015161357e565b6122085760405162461bcd60e51b815260206004820152601260248201527f4c4f503a20626164207369676e617475726500000000000000000000000000006044820152606401610717565b50845160c08101516101e090910151516014116122bb5785516101e0015160148101805191517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec01815261225c8282613839565b600084815260026020526040902054156122b85760405162461bcd60e51b815260206004820152601860248201527f4c4f503a207265656e7472616e637920646574656374656400000000000000006044820152606401610717565b50505b6122c5565b600019015b85516101c0015151156123515760006122e18760000151610eb7565b9050851561230257806122fd5760008094509450505050612a68565b61234f565b8061234f5760405162461bcd60e51b815260206004820152601d60248201527f4c4f503a207072656469636174652072657475726e65642066616c73650000006044820152606401610717565b505b6040860151606087015115901514156123ac5760405162461bcd60e51b815260206004820181905260248201527f4c4f503a206f6e6c79206f6e6520616d6f756e742073686f756c6420626520306044820152606401610717565b6060860151612495576040860151818111156123ca57604087018290525b85156123f6576123ef8760000151602001518860000151606001518960400151613a46565b6040890152505b86516101a081015160c082015160408a015160e0909301516124189390613ba5565b606088015260408701516080880151612431919061586b565b818860600151612441919061586b565b111561248f5760405162461bcd60e51b815260206004820152601b60248201527f4c4f503a2074616b696e6720616d6f756e7420746f6f206869676800000000006044820152606401610717565b506125ba565b6060860151865161018081015160e082015160c0909201516124b992908490613ba5565b6040880152600086156124ed576124e58860000151602001518960000151606001518a60400151613a46565b60408a015290505b80806124fc5750828860400151115b156125455782886040015111612516578760400151612518565b825b6040890181905288516101a081015160c082015160e09092015161253f9391929190613ba5565b60608901525b87606001518860800151612559919061586b565b828960400151612569919061586b565b10156125b75760405162461bcd60e51b815260206004820152601a60248201527f4c4f503a206d616b696e6720616d6f756e7420746f6f206c6f770000000000006044820152606401610717565b50505b600086604001511180156125d2575060008660600151115b61261e5760405162461bcd60e51b815260206004820152601860248201527f4c4f503a2063616e27742073776170203020616d6f756e7400000000000000006044820152606401610717565b6040808701805160008581526002602052839020600191909403908101909355516060880151915133927fda67fd5efd7c65cc617b4e30cdd2569c6c2b3d0034729f3c616c6a83b4520a8f9261268e92879287929193845260208401929092526040830152606082015260800190565b60405180910390a250845161010001516000906001600160a01b0316158015906126c357508551610120015163ffffffff1615155b15612787578551610120015160408701516127109160019183916126ef9163ffffffff9091169061586b565b6126f9919061588a565b61270391906158a2565b61270d91906158b9565b8651602080820151606083015161010084015161014090940151604051959650612787959294612773947f23b872dd00000000000000000000000000000000000000000000000000000000946001600160a01b0394851694909216928992909101615a80565b604051602081830303815290604052613cc1565b6127e68660000151602001516323b872dd60e01b8860000151606001516001600160a01b03168960a001516001600160a01b0316858b604001516127cb91906158a2565b8b516101400151604051612773959493929190602001615a80565b60c0860151511561287257604080870151606088015160c089015192517f143d601a000000000000000000000000000000000000000000000000000000008152339363143d601a9361283f939092909190600401615add565b600060405180830381600087803b15801561285957600080fd5b505af115801561286d573d6000803e3d6000fd5b505050505b855160408101516080909101516128f191907f23b872dd000000000000000000000000000000000000000000000000000000009033906001600160a01b0316156128c1578951608001516128c8565b8951606001515b60608b01518b5161016001516040516127739594936001600160a01b0316929190602001615a80565b8551610200015151601411612a57578551610200015160148101805191517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec0181526001600160a01b03821660009081526003602052604090205460ff166129c15760405162461bcd60e51b815260206004820152602e60248201527f4c4f503a2074686520696e746572616374696f6e20746172676574206973206e60448201527f6f742077686974656c69737465640000000000000000000000000000000000006064820152608401610717565b87516020810151604091820151828b015160608c015193517fcf21c7750000000000000000000000000000000000000000000000000000000081526001600160a01b0387169463cf21c77594612a2294339491939092908990600401615b05565b600060405180830381600087803b158015612a3c57600080fd5b505af1158015612a50573d6000803e3d6000fd5b5050505050505b856040015186606001519350935050505b9250929050565b6000806000856001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015612ab2573d6000803e3d6000fd5b505050506040513d60a0811015612ac857600080fd5b506020810151606090910151909250905042612ae66107088361588a565b11612b38576040805162461bcd60e51b815260206004820152600e60248201527f43433a207374616c652064617461000000000000000000000000000000000000604482015290519081900360640190fd5b7f80000000000000000000000000000000000000000000000000000000000000008516158015907f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff871690612c2957633b9aca00612b958561304f565b896001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612bd3573d6000803e3d6000fd5b505050506040513d6020811015612be957600080fd5b5051612bf690600a615c29565b612c00848a61586b565b612c0a919061586b565b612c1491906158b9565b612c1e91906158b9565b94505050505061073a565b633b9aca00886001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c6c573d6000803e3d6000fd5b505050506040513d6020811015612c8257600080fd5b5051612c8f90600a615c29565b612bf68661304f565b61101b600161101d565b600080612cb48a6040015185856131f5565b6107ef8a8a8a8a8a8a611099565b6000838214612d135760405162461bcd60e51b815260206004820152601d60248201527f50483a20696e7075742061727261792073697a65206d69736d617463680000006044820152606401610717565b60005b84811015612e4d576000612dc3858584818110612d3557612d356158f4565b9050602002810190612d479190615923565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051808201909152601781527f50483a20276f72272073756263616c6c206661696c6564000000000000000000602082015291508a905089868181106119f8576119f86158f4565b90508051602014612e165760405162461bcd60e51b815260206004820152601760248201527f50483a20696e76616c69642063616c6c20726573756c740000000000000000006044820152606401610717565b80806020019051810190612e2a9190615a63565b15612e3a57600192505050610972565b5080612e4581615998565b915050612d16565b50600095945050505050565b612e616134ba565b6001600160a01b038116612edd5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610717565b61177381613514565b600082610968858461586b565b60606001600160a01b0384163b612f715760405162461bcd60e51b8152602060048201526024808201527f416464726573733a207374617469632063616c6c20746f206e6f6e2d636f6e7460448201527f72616374000000000000000000000000000000000000000000000000000000006064820152608401610717565b600080856001600160a01b031685604051612f8c9190615c38565b600060405180830381855afa9150503d8060008114612fc7576040519150601f19603f3d011682016040523d82523d6000602084013e612fcc565b606091505b5091509150612fdc828286613d81565b9695505050505050565b6000610853612ff36130a5565b836040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6000808212156130a15760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610717565b5090565b6000306001600160a01b037f000000000000000000000000227b0c196ea8db17a665ea6824d972a64202e936161480156130fe57507f000000000000000000000000000000000000000000000000000000000000008946145b1561312857507f34e723ed4d7ad31880d1e36618f316d6c8a47db58d1763f3893491ae9755f1e490565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527fe7c60c44dcf09f57ecaec74141174774f3a95bfb11a27146a89bcba2aeef0e6c828401527fad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a560608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b60003681843560601c82826131e4876014818b615c54565b939650945091925050509250925092565b80156134b5576000606060e0831415613307576040517fd505accf00000000000000000000000000000000000000000000000000000000602082018181526001600160a01b03881692879187916024018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b602083106132955780518252601f199092019160209182019101613276565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146132f7576040519150601f19603f3d011682016040523d82523d6000602084013e6132fc565b606091505b5090925090506133ea565b61010083141561339d576040517f8fcbaf0c00000000000000000000000000000000000000000000000000000000602082018181526001600160a01b0388169287918791602401838380828437808301925050509350505050604051602081830303815290604052604051808280519060200190808383602083106132955780518252601f199092019160209182019101613276565b6040805162461bcd60e51b815260206004820152601360248201527f57726f6e67207065726d6974206c656e67746800000000000000000000000000604482015290519081900360640190fd5b816134b25761342e816040518060400160405280600f81526020017f5065726d6974206661696c65643a200000000000000000000000000000000000815250613dba565b60405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561347757818101518382015260200161345f565b50505050905090810190601f1680156134a45780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50505b505050565b6001546001600160a01b0316331461101b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610717565b600180546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600080600061358d8585614213565b909250905060008160048111156135a6576135a6615c7e565b1480156135c45750856001600160a01b0316826001600160a01b0316145b156135d45760019250505061073a565b600080876001600160a01b0316631626ba7e60e01b88886040516024016135fc929190615cad565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009094169390931790925290516136679190615c38565b600060405180830381855afa9150503d80600081146136a2576040519150601f19603f3d011682016040523d82523d6000602084013e6136a7565b606091505b50915091508180156136ba575080516020145b80156136fa575080517f1626ba7e00000000000000000000000000000000000000000000000000000000906136f8908301602090810190840161569c565b145b98975050505050505050565b6001600160a01b038216600090815260046020908152604080832066ffffffffffffff600886901c16808552928190529220549091600160ff85161b91808316156137935760405162461bcd60e51b815260206004820152601660248201527f4c4f503a20696e76616c696461746564206f72646572000000000000000000006044820152606401610717565b60009384526020919091526040909220911790555050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd00000000000000000000000000000000000000000000000000000000179052613833908590614256565b50505050565b805115611c0b5760006060825160e0141561398e57836001600160a01b031663d505accf60e01b8460405160200180837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260040182805190602001908083835b602083106138b85780518252601f199092019160209182019101613899565b6001836020036101000a038019825116818451168082178552505050505050905001925050506040516020818303038152906040526040518082805190602001908083835b6020831061391c5780518252601f1990920191602091820191016138fd565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461397e576040519150601f19603f3d011682016040523d82523d6000602084013e613983565b606091505b509092509050613a02565b8251610100141561339d57836001600160a01b0316638fcbaf0c60e01b8460405160200180837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191681526004018280519060200190808383602083106138b85780518252601f199092019160209182019101613899565b816138335761342e816040518060400160405280600f81526020017f5065726d6974206661696c65643a200000000000000000000000000000000000815250613dba565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03838116600483015260009182918291908716906370a0823190602401602060405180830381865afa158015613aad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad1919061569c565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081526001600160a01b03878116600483015230602483015291925060009188169063dd62ed3e90604401602060405180830381865afa158015613b3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b60919061569c565b905081851180613b6f57508085115b15613b9357808211613b815781613b83565b805b9450600185935093505050613b9d565b6000859350935050505b935093915050565b6000845160001415613c0757838314613c005760405162461bcd60e51b815260206004820152601160248201527f4c4f503a2077726f6e6720616d6f756e740000000000000000000000000000006044820152606401610717565b5080610972565b6000613c638685604051602001613c1f929190615cc6565b60408051601f19818403018152828201909152601a82527f4c4f503a20676574416d6f756e742063616c6c206661696c656400000000000060208301523091612ef3565b90508051602014613cb65760405162461bcd60e51b815260206004820152601d60248201527f4c4f503a20696e76616c696420676574416d6f756e742072657475726e0000006044820152606401610717565b602001519050610972565b6000613d16826040518060400160405280601681526020017f4c4f503a2061737365742e63616c6c206661696c656400000000000000000000815250856001600160a01b031661433b9092919063ffffffff16565b8051909150156134b55780516020148015613d35575060208101516001145b6134b55760405162461bcd60e51b815260206004820152601a60248201527f4c4f503a2061737365742e63616c6c2062616420726573756c740000000000006044820152606401610717565b60608315613d9057508161073a565b825115613da05782518084602001fd5b8160405162461bcd60e51b81526004016107179190615a50565b606060048351106141015760208301517fffffffff00000000000000000000000000000000000000000000000000000000811662461bcd60e51b148015613e0357506044845110155b15613f9057602484810151808601820180519192909190613e2590849061588a565b613e2f919061588a565b86511015613e84576040805162461bcd60e51b815260206004820152601560248201527f496e76616c69642072657665727420726561736f6e0000000000000000000000604482015290519081900360640190fd5b84816040516020018083805190602001908083835b60208310613eb85780518252601f199092019160209182019101613e99565b51815160209384036101000a60001901801990921691161790527f4572726f72280000000000000000000000000000000000000000000000000000919093019081528451600690910192850191508083835b60208310613f295780518252601f199092019160209182019101613f0a565b6001836020036101000a038019825116818451168082178552505050505050905001807f2900000000000000000000000000000000000000000000000000000000000000815250600101925050506040516020818303038152906040529350505050610853565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f4e487b7100000000000000000000000000000000000000000000000000000000148015613fe2575083516024145b156140ff57602484015183613ff68261434a565b6040516020018083805190602001908083835b602083106140285780518252601f199092019160209182019101614009565b51815160209384036101000a60001901801990921691161790527f50616e6963280000000000000000000000000000000000000000000000000000919093019081528451600690910192850191508083835b602083106140995780518252601f19909201916020918201910161407a565b6001836020036101000a038019825116818451168082178552505050505050905001807f29000000000000000000000000000000000000000000000000000000000000008152506001019250505060405160208183030381529060405292505050610853565b505b8161410b84614370565b6040516020018083805190602001908083835b6020831061413d5780518252601f19909201916020918201910161411e565b51815160209384036101000a60001901801990921691161790527f556e6b6e6f776e28000000000000000000000000000000000000000000000000919093019081528451600890910192850191508083835b602083106141ae5780518252601f19909201916020918201910161418f565b6001836020036101000a038019825116818451168082178552505050505050905001807f290000000000000000000000000000000000000000000000000000000000000081525060010192505050604051602081830303815290604052905092915050565b60008082516041141561424a5760208301516040840151606085015160001a61423e87828585614615565b94509450505050612a68565b50600090506002612a68565b60006142ab826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661433b9092919063ffffffff16565b8051909150156134b557808060200190518101906142c99190615a63565b6134b55760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610717565b60606109728484600085614702565b606061085382604051602001808281526020019150506040516020818303038152906040525b80516060907f3031323334353637383961626364656600000000000000000000000000000000906000906143a590600261586b565b6143b090600261588a565b67ffffffffffffffff8111156143c8576143c861486f565b6040519080825280601f01601f1916602001820160405280156143f2576020820181803683370190505b5090507f300000000000000000000000000000000000000000000000000000000000000081600081518110614429576144296158f4565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061448c5761448c6158f4565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060005b845181101561460d578260048683815181106144dc576144dc6158f4565b01602001517fff0000000000000000000000000000000000000000000000000000000000000016901c60f81c60108110614518576145186158f4565b1a60f81b8261452883600261586b565b61453390600261588a565b81518110614543576145436158f4565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535082858281518110614585576145856158f4565b60209101015160f81c600f16601081106145a1576145a16158f4565b1a60f81b826145b183600261586b565b6145bc90600361588a565b815181106145cc576145cc6158f4565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508061460581615998565b9150506144be565b509392505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561464c57506000905060036146f9565b8460ff16601b1415801561466457508460ff16601c14155b1561467557506000905060046146f9565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156146c9573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166146f2576000600192509250506146f9565b9150600090505b94509492505050565b60608247101561477a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610717565b6001600160a01b0385163b6147d15760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610717565b600080866001600160a01b031685876040516147ed9190615c38565b60006040518083038185875af1925050503d806000811461482a576040519150601f19603f3d011682016040523d82523d6000602084013e61482f565b606091505b509150915061483f828286613d81565b979650505050505050565b6001600160a01b038116811461177357600080fd5b803561486a8161484a565b919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610220810167ffffffffffffffff811182821017156148c2576148c261486f565b60405290565b60405160a0810167ffffffffffffffff811182821017156148c2576148c261486f565b60405160e0810167ffffffffffffffff811182821017156148c2576148c261486f565b604051601f8201601f1916810167ffffffffffffffff811182821017156149375761493761486f565b604052919050565b600082601f83011261495057600080fd5b813567ffffffffffffffff81111561496a5761496a61486f565b61497d6020601f19601f8401160161490e565b81815284602083860101111561499257600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000606084860312156149c457600080fd5b8335925060208401356149d68161484a565b9150604084013567ffffffffffffffff8111156149f257600080fd5b6149fe8682870161493f565b9150509250925092565b803563ffffffff8116811461486a57600080fd5b60006102208284031215614a2f57600080fd5b614a3761489e565b905081358152614a496020830161485f565b6020820152614a5a6040830161485f565b6040820152614a6b6060830161485f565b6060820152614a7c6080830161485f565b6080820152614a8d60a0830161485f565b60a082015260c082013560c082015260e082013560e0820152610100614ab481840161485f565b90820152610120614ac6838201614a08565b908201526101408281013567ffffffffffffffff80821115614ae757600080fd5b614af38683870161493f565b83850152610160925082850135915080821115614b0f57600080fd5b614b1b8683870161493f565b83850152610180925082850135915080821115614b3757600080fd5b614b438683870161493f565b838501526101a0925082850135915080821115614b5f57600080fd5b614b6b8683870161493f565b838501526101c0925082850135915080821115614b8757600080fd5b614b938683870161493f565b838501526101e0925082850135915080821115614baf57600080fd5b614bbb8683870161493f565b83850152610200925082850135915080821115614bd757600080fd5b50614be48582860161493f565b82840152505092915050565b60008083601f840112614c0257600080fd5b50813567ffffffffffffffff811115614c1a57600080fd5b602083019150836020828501011115612a6857600080fd5b60008060008060008060008060c0898b031215614c4e57600080fd5b883567ffffffffffffffff80821115614c6657600080fd5b614c728c838d01614a1c565b995060208b0135915080821115614c8857600080fd5b614c948c838d01614bf0565b909950975060408b0135965060608b0135955060808b0135945060a08b0135915080821115614cc257600080fd5b50614ccf8b828c01614bf0565b999c989b5096995094979396929594505050565b6000610100808385031215614cf757600080fd5b6040519081019067ffffffffffffffff82118183101715614d1a57614d1a61486f565b816040528092508335815260208401359150614d358261484a565b816020820152614d476040850161485f565b6040820152614d586060850161485f565b6060820152614d696080850161485f565b608082015260a084013560a082015260c084013560c082015260e084013560e0820152505092915050565b60006101008284031215614da757600080fd5b61073a8383614ce3565b600060208284031215614dc357600080fd5b813567ffffffffffffffff811115614dda57600080fd5b61097284828501614a1c565b600080600060608486031215614dfb57600080fd5b505081359360208301359350604090920135919050565b60008060008060808587031215614e2857600080fd5b8435614e338161484a565b93506020850135614e438161484a565b93969395505050506040820135916060013590565b60008060008060008060008060008060006101008c8e031215614e7a57600080fd5b67ffffffffffffffff808d351115614e9157600080fd5b614e9e8e8e358f01614a1c565b9b508060208e01351115614eb157600080fd5b614ec18e60208f01358f01614bf0565b909b50995060408d0135985060608d0135975060808d01359650614ee760a08e0161485f565b95508060c08e01351115614efa57600080fd5b614f0a8e60c08f01358f01614bf0565b909550935060e08d0135811015614f2057600080fd5b50614f318d60e08e01358e01614bf0565b81935080925050509295989b509295989b9093969950565b60008060008060006101608688031215614f6257600080fd5b614f6c8787614ce3565b945061010086013567ffffffffffffffff811115614f8957600080fd5b614f9588828901614bf0565b96999098509596610120810135966101409091013595509350505050565b60008060408385031215614fc657600080fd5b8235614fd18161484a565b946020939093013593505050565b600060208284031215614ff157600080fd5b5035919050565b801515811461177357600080fd5b803561486a81614ff8565b6000806040838503121561502457600080fd5b823561502f8161484a565b9150602083013561503f81614ff8565b809150509250929050565b60006020828403121561505c57600080fd5b813561073a8161484a565b60006020828403121561507957600080fd5b813560ff8116811461073a57600080fd5b60008060008060008061018087890312156150a457600080fd5b6150ae8888614ce3565b955061010087013567ffffffffffffffff8111156150cb57600080fd5b6150d789828a01614bf0565b909650945050610120870135925061014087013591506101608701356150fc8161484a565b809150509295509295509295565b60008083601f84011261511c57600080fd5b50813567ffffffffffffffff81111561513457600080fd5b6020830191508360208260051b8501011115612a6857600080fd5b6000806000806040858703121561516557600080fd5b843567ffffffffffffffff8082111561517d57600080fd5b6151898883890161510a565b909650945060208701359150808211156151a257600080fd5b506151af8782880161510a565b95989497509550505050565b600067ffffffffffffffff8211156151d5576151d561486f565b5060051b60200190565b600060208083850312156151f257600080fd5b823567ffffffffffffffff81111561520957600080fd5b8301601f8101851361521a57600080fd5b803561522d615228826151bb565b61490e565b81815260059190911b8201830190838101908783111561524c57600080fd5b928401925b8284101561483f57833582529284019290840190615251565b6020808252825182820181905260009190848201906040850190845b818110156152a257835183529284019291840191600101615286565b50909695505050505050565b600082601f8301126152bf57600080fd5b813560206152cf615228836151bb565b82815260059290921b840181019181810190868411156152ee57600080fd5b8286015b8481101561532e57803567ffffffffffffffff8111156153125760008081fd5b6153208986838b0101614a1c565b8452509183019183016152f2565b509695505050505050565b60006020828403121561534b57600080fd5b813567ffffffffffffffff81111561536257600080fd5b610972848285016152ae565b6000602080838503121561538157600080fd5b823567ffffffffffffffff8082111561539957600080fd5b9084019060a082870312156153ad57600080fd5b6153b56148c8565b8235828111156153c457600080fd5b6153d0888286016152ae565b82525083830135828111156153e457600080fd5b8301601f810188136153f557600080fd5b8035615403615228826151bb565b81815260059190911b8201860190868101908a83111561542257600080fd5b8784015b8381101561545a5780358781111561543e5760008081fd5b61544c8d8b8389010161493f565b845250918801918801615426565b5080888601525050505060408301356040820152606083013560608201526154846080840161485f565b60808201529695505050505050565b600080604083850312156154a657600080fd5b82356154b18161484a565b9150602083013567ffffffffffffffff8111156154cd57600080fd5b6154d98582860161493f565b9150509250929050565b600080604083850312156154f657600080fd5b823567ffffffffffffffff8082111561550e57600080fd5b9084019060e0828703121561552257600080fd5b61552a6148eb565b82358281111561553957600080fd5b61554588828601614a1c565b82525060208301358281111561555a57600080fd5b6155668882860161493f565b60208301525060408301356040820152606083013560608201526080830135608082015261559660a0840161485f565b60a082015260c0830135828111156155ad57600080fd5b6155b98882860161493f565b60c08301525093506155d091505060208401615006565b90509250929050565b6000806000606084860312156155ee57600080fd5b83356155f98161484a565b95602085013595506040909401359392505050565b6000806000806000806000806101a0898b03121561562b57600080fd5b6156358a8a614ce3565b975061010089013567ffffffffffffffff8082111561565357600080fd5b61565f8c838d01614bf0565b90995097506101208b013596506101408b013595506101608b013591506156858261484a565b9093506101808a01359080821115614cc257600080fd5b6000602082840312156156ae57600080fd5b5051919050565b6000610120820190508382528251602083015260208301516001600160a01b0380821660408501528060408601511660608501528060608601511660808501525050608083015161571160a08401826001600160a01b03169052565b5060a083015160c083015260c083015160e083015260e08301516101008301529392505050565b6000610240820190508a82528951602083015260208a015161576560408401826001600160a01b03169052565b5060408a01516001600160a01b03811660608401525060608a01516001600160a01b03811660808401525060808a01516001600160a01b03811660a08401525060a08a01516001600160a01b03811660c08401525060c08a015160e083015260e08a01516101008181850152808c01519150506101206157ef818501836001600160a01b03169052565b909a015163ffffffff166101408301526101608201989098526101808101969096526101a08601949094526101c08501929092526101e08401526102008301526102209091015292915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160001904831182151516156158855761588561583c565b500290565b6000821982111561589d5761589d61583c565b500190565b6000828210156158b4576158b461583c565b500390565b6000826158ef577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261595857600080fd5b83018035915067ffffffffffffffff82111561597357600080fd5b602001915036819003821315612a6857600080fd5b8183823760009101908152919050565b60006000198214156159ac576159ac61583c565b5060010190565b60005b838110156159ce5781810151838201526020016159b6565b838111156138335750506000910152565b7f43414c4c5f524553554c54535f00000000000000000000000000000000000000815260008251615a1781600d8501602087016159b3565b91909101600d0192915050565b60008151808452615a3c8160208601602086016159b3565b601f01601f19169290920160200192915050565b60208152600061073a6020830184615a24565b600060208284031215615a7557600080fd5b815161073a81614ff8565b7fffffffff000000000000000000000000000000000000000000000000000000008616815284600482015283602482015282604482015260008251615acc8160648501602087016159b3565b919091016064019695505050505050565b838152826020820152606060408201526000615afc6060830184615a24565b95945050505050565b60006001600160a01b038089168352808816602084015280871660408401525084606083015283608083015260c060a08301526136fa60c0830184615a24565b600181815b80851115615b80578160001904821115615b6657615b6661583c565b80851615615b7357918102915b93841c9390800290615b4a565b509250929050565b600082615b9757506001610853565b81615ba457506000610853565b8160018114615bba5760028114615bc457615be0565b6001915050610853565b60ff841115615bd557615bd561583c565b50506001821b610853565b5060208310610133831016604e8410600b8410161715615c03575081810a610853565b615c0d8383615b45565b8060001904821115615c2157615c2161583c565b029392505050565b600061073a60ff841683615b88565b60008251615c4a8184602087016159b3565b9190910192915050565b60008085851115615c6457600080fd5b83861115615c7157600080fd5b5050820193919092039150565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8281526040602082015260006109726040830184615a24565b60008351615cd88184602088016159b3565b919091019182525060200191905056fea26469706673582212201ef49fd39b1865254c961137909b5687a9e3b3c57f335071cb93e50a734da78d64736f6c634300080a0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.