Contract 0x233C3cF579695B8FA804906d8A4b4eA747fb34f9

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xe157f57b49440a3ef4deb79ed30d59bb1a679b218893281b152f58c0d6d9b82d0x60806040172515282022-07-08 12:34:5784 days 3 hrs ago0x44cbfc3ce762fc0fee9ddd6372804b7b660176bc IN  Create: Rebalancer0 ETH0.008463644084 ETH
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x17bfb6302f3f1ea61134439247e6a0a949ac38af9a5bd1dc97b41a00d74a41d0262481222022-09-23 18:42:546 days 21 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x9dedcb5e22c1ec7af4e0dd5aebbe0bb21e29981ffe44781d8ede1dee2851c99a262481202022-09-23 18:42:536 days 21 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x1c435d9f5f64c1c7966fe4941d622a041c3fe83d7b45d04990515bb1b273de6e262421052022-09-23 18:02:426 days 22 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x8224e3bcb6352a4c9fc9c87ac9f42ee5ead4c34c238b211f54d16d877f8bd20f262408702022-09-23 17:52:336 days 22 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x4f15d1581fd6dde34566ef1ac586073c4697b4a82c32de5a8878a9175467b9eb262022952022-09-23 14:17:117 days 1 hr ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xf29460f09a1f13a9a32e1fc7267a5852f0860dbab6e5753285e3adadd7fc64a6261996092022-09-23 14:06:397 days 2 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x69b1d3190f8941ea31aa884d48fef02cdc4e66cf62900536c84882eb3bf81dbb252073272022-09-19 2:52:4311 days 13 hrs ago 0x3770bb20164c19d1e2a56c24938b228a4ed092c2 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xd8feb056753239dd3ef62d492752ffa109b0fe2d1afadcde40c0a1c702fbb53c252072032022-09-19 2:51:4811 days 13 hrs ago 0x3770bb20164c19d1e2a56c24938b228a4ed092c2 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xdd2e9dfdb570f585b9441dd3fdd0cd944151b864db5b72f52cf2994516a53da8248988102022-09-16 14:45:3314 days 1 hr ago 0x3770bb20164c19d1e2a56c24938b228a4ed092c2 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xfcdf523ede57a51bae8e6fe735427a238804a7b4ef8d8f8da23d71ff293e8ef4248988022022-09-16 14:45:3214 days 1 hr ago 0x3770bb20164c19d1e2a56c24938b228a4ed092c2 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x8c107839509141029bdc8664084a3ad8c11b705591310e17ca05494784dd945a226995282022-09-03 20:41:2626 days 19 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xda51d464e92f86832e4fd963090f37cd8f0446ceb8f355f5aab80efbe6678db4226995262022-09-03 20:41:2526 days 19 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x7bcb058b7e1488b4507ff3968ffa0f22e961a4890751cfdae5b133419ce02c86220430872022-08-30 20:45:3030 days 19 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xe9c34bfe7631a4b83ad1c4e03c97e65228fc6af34a08b625d3ef5e04a96157c1220430672022-08-30 20:45:3030 days 19 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x04c6099f3d11d77d2e9eb5c9e9d260b0306d3d36ebe2e06b306dad2fa9af2934220333042022-08-30 19:30:4530 days 20 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x4a4e956adcda50f133e32f4ffa1c2341edc02b7b75a62ec4e1e3da6a9243ddde220319262022-08-30 19:19:5630 days 20 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x4846f460f49f72321a463d08c1a308df9ff2c98b4f796481542449e78e297bd4220312642022-08-30 19:14:5530 days 20 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xbbb97d5e2bd55c6b1cc52ca4fd60c21cf74ed8824a8188fc46334d5c8deacbb1220312512022-08-30 19:14:5530 days 20 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x2bbabcca4d15c6833b990c08e18aecd0bff1d67872d9419fc558fafde1b54400220310712022-08-30 19:13:0330 days 20 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xf26d0fbf541384dfb0c461a0471a62ca495a6708ac7cbec485208768e0f3cdb0220301492022-08-30 19:03:3230 days 21 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x48372e88ffc650813ac14a9c0a25218511672e1b758fbaa5b8c1609c7bd4223c220062242022-08-30 15:26:3031 days 43 mins ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0xc4f85102fc7670369e63125fa9798a648c661e374dd3b0984b28f26762f01b92220050512022-08-30 15:17:0731 days 53 mins ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x6717299568b4e95a9f67c670949eeb81877fd1225dcd130b66e8cba6d336e622219833152022-08-30 12:45:5431 days 3 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x08ea946d653d77c2b92623290f0ae020718e592d64a35b25daf053692216935e219820342022-08-30 12:35:4731 days 3 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
0x916493424738626061b3931e1061da2e3aa1791576839012b9df66e01377782b219664862022-08-30 10:24:2531 days 5 hrs ago 0x3efe4639eb082e22209fee29aabaf14ade5bf82b 0x233c3cf579695b8fa804906d8a4b4ea747fb34f90 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Rebalancer

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 11 : Rebalancer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "./interfaces/IMuxRebalancerCallback.sol";
import "./interfaces/IOrderBook.sol";
import "./SafeOwnableUpgradeable.sol";

contract Rebalancer is Initializable, SafeOwnableUpgradeable, IMuxRebalancerCallback {
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;

    event AddOperator(address indexed newBroker);
    event RemoveOperator(address indexed broker);

    address public liquidityPool; // only LiquidityPool can call the callBack
    address public orderBook; // place order, cancel order
    mapping(address => bool) public operators; // only operators can place order
    mapping(uint64 => bytes) public orderContext; // orderId => parameters that can not fit into bytes32
    EnumerableSetUpgradeable.UintSet internal _orderIds; // keep track of my orderIds

    function initialize(address liquidityPool_, address orderBook_) external virtual initializer {
        __SafeOwnable_init();
        liquidityPool = liquidityPool_;
        orderBook = orderBook_;
    }

    modifier onlyLiquidityPool() {
        require(msg.sender == address(liquidityPool), "not pool");
        _;
    }

    modifier onlyOperator() {
        require(operators[msg.sender], "not operator");
        _;
    }

    modifier onlyOperatorOrOwner() {
        require(operators[msg.sender] || msg.sender == owner(), "not operator");
        _;
    }

    function listOrders()
        external
        view
        returns (
            uint64[] memory orderIds,
            bytes32[3][] memory orders,
            bytes[] memory contexts
        )
    {
        uint256 length = _orderIds.length();
        orderIds = new uint64[](length);
        orders = new bytes32[3][](length);
        contexts = new bytes[](length);
        for (uint256 i = 0; i < length; i++) {
            uint64 orderId = uint64(_orderIds.at(i));
            orderIds[i] = orderId;
            bool exists;
            (orders[i], exists) = IOrderBook(orderBook).getOrder(orderId);
            require(exists, "order not found");
            contexts[i] = orderContext[orderId];
        }
    }

    /**
     * @notice Rebalancer.muxRebalanceCallback is called when Brokers calls IOrderBook#fillRebalanceOrder, where
     *         Rebalancer is `msg.sender` of IOrderBook#placeRebalanceOrder.
     *
     *         Rebalancer will get token0 and send token1 back to `msg.sender`.
     */
    function muxRebalanceCallback(
        address token0,
        address token1,
        uint256 rawAmount0,
        uint256 minRawAmount1,
        bytes32 data
    ) external override onlyLiquidityPool {
        (Method method, uint64 orderId, ) = _parseUserData(data);
        bytes storage context = orderContext[orderId];
        if (method == Method.Simple) {
            // just send back token 1
        } else if (method == Method.OneInch) {
            // call 1inch
            address oneInch = _getOneInchContract();
            IERC20Upgradeable(token0).approve(oneInch, rawAmount0);
            uint256 rawAmount1Old = IERC20Upgradeable(token1).balanceOf(address(this));
            AddressUpgradeable.functionCall(oneInch, context, "1inch failed");
            uint256 rawAmount1New = IERC20Upgradeable(token1).balanceOf(address(this));
            require(rawAmount1New >= rawAmount1Old && rawAmount1New - rawAmount1Old >= minRawAmount1, "1inch slippage");
        }
        // send back token 1
        IERC20Upgradeable(token1).safeTransfer(liquidityPool, minRawAmount1);
        _orderIds.remove(orderId);
        delete (orderContext[orderId]);
    }

    function cancelOrder(uint64 orderId) external onlyOperator {
        IOrderBook(orderBook).cancelOrder(orderId);
        _orderIds.remove(orderId);
        delete (orderContext[orderId]);
    }

    function placeSimpleOrder(
        uint8 tokenId0,
        uint8 tokenId1,
        uint96 rawAmount0,
        uint96 maxRawAmount1
    ) external onlyOperator {
        uint64 orderId = IOrderBook(orderBook).nextOrderId();
        bytes32 userData = _buildUserData(Method.Simple, orderId, uint32(block.timestamp));
        _orderIds.add(orderId);
        IOrderBook(orderBook).placeRebalanceOrder(tokenId0, tokenId1, rawAmount0, maxRawAmount1, userData);
    }

    function placeOneInchOrder(
        uint8 tokenId0,
        uint8 tokenId1,
        uint96 rawAmount0,
        uint96 maxRawAmount1,
        bytes calldata oneInchCallData
    ) external onlyOperator {
        uint64 orderId = IOrderBook(orderBook).nextOrderId();
        bytes32 userData = _buildUserData(Method.OneInch, orderId, uint32(block.timestamp));
        orderContext[orderId] = oneInchCallData;
        _orderIds.add(orderId);
        IOrderBook(orderBook).placeRebalanceOrder(tokenId0, tokenId1, rawAmount0, maxRawAmount1, userData);
    }

    function withdrawERC20(address token, uint256 amount) external onlyOperatorOrOwner {
        IERC20Upgradeable(token).safeTransfer(msg.sender, amount);
    }

    function addOperator(address operator_) external onlyOwner {
        require(!operators[operator_], "unchanged");
        operators[operator_] = true;
        emit AddOperator(operator_);
    }

    function removeOperator(address operator_) external onlyOwner {
        require(operators[operator_], "unchanged");
        operators[operator_] = false;
        emit RemoveOperator(operator_);
    }

    /**
     *          248         184        152             0
     * +----------+------------+---------+-------------+
     * | method 8 | orderId 64 | time 32 |  unused 152 |
     * +----------+------------+---------+-------------+
     */
    enum Method {
        Simple,
        OneInch
    }

    function _buildUserData(
        Method method,
        uint64 orderId,
        uint32 time
    ) private pure returns (bytes32) {
        return bytes32((uint256(method) << 248) | (uint256(orderId) << 184) | (uint256(time) << 152));
    }

    function _parseUserData(bytes32 data)
        private
        pure
        returns (
            Method method,
            uint64 orderId,
            uint32 time
        )
    {
        method = Method(uint256(data) >> 248);
        orderId = uint64(uint256(data) >> 184);
        time = uint32(uint256(data) >> 152);
    }

    function _getOneInchContract() internal pure returns (address) {
        return 0x1111111254fb6c44bAC0beD2854e76F90643097d;
    }
}

File 2 of 11 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @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 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 3 of 11 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 4 of 11 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

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

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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));
        }
    }

    /**
     * @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(IERC20Upgradeable 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 5 of 11 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSetUpgradeable {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

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

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

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

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

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

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

        assembly {
            result := store
        }

        return result;
    }
}

File 6 of 11 : IMuxRebalancerCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

/**
 * @notice Any contract that calls IOrderBook#placeRebalanceOrder must implement this interface
 */
interface IMuxRebalancerCallback {
    /**
     * @notice Rebalancer.muxRebalanceCallback is called when Brokers calls IOrderBook#fillRebalanceOrder, where
     *         Rebalancer is `msg.sender` of IOrderBook#placeRebalanceOrder.
     *
     *         Rebalancer will get token0 and send token1 back to `msg.sender`.
     */
    function muxRebalanceCallback(
        address token0,
        address token1,
        uint256 rawAmount0,
        uint256 minRawAmount1,
        bytes32 data
    ) external;
}

File 7 of 11 : IOrderBook.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

interface IOrderBook {
    function nextOrderId() external view returns (uint64);

    function getOrder(uint64 orderId) external view returns (bytes32[3] memory, bool);

    /**
     * @dev   Rebalance pool liquidity. Swap token 0 for token 1.
     *
     *        msg.sender must implement IMuxRebalancerCallback.
     * @param tokenId0      asset.id to be swapped out of the pool
     * @param tokenId1      asset.id to be swapped into the pool
     * @param rawAmount0    token 0 amount. decimals = erc20.decimals
     * @param maxRawAmount1 max token 1 that rebalancer is willing to pay. decimals = erc20.decimals
     * @param userData       max token 1 that rebalancer is willing to pay. decimals = erc20.decimals
     */
    function placeRebalanceOrder(
        uint8 tokenId0,
        uint8 tokenId1,
        uint96 rawAmount0, // erc20.decimals
        uint96 maxRawAmount1, // erc20.decimals
        bytes32 userData
    ) external;

    function cancelOrder(uint64 orderId) external;
}

File 8 of 11 : SafeOwnableUpgradeable.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract SafeOwnableUpgradeable is OwnableUpgradeable {
    address internal _pendingOwner;

    event PrepareToTransferOwnership(address indexed pendingOwner);

    function __SafeOwnable_init() internal onlyInitializing {
        __Ownable_init();
    }

    function transferOwnership(address newOwner) public virtual override onlyOwner {
        require(newOwner != address(0), "O=0"); // Owner Is Zero
        require(newOwner != owner(), "O=O"); // Owner is the same as the old Owner
        _pendingOwner = newOwner;
        emit PrepareToTransferOwnership(_pendingOwner);
    }

    function takeOwnership() public virtual {
        require(_msgSender() == _pendingOwner, "SND"); // SeNDer is not authorized
        _transferOwnership(_pendingOwner);
        _pendingOwner = address(0);
    }

    function renounceOwnership() public virtual override onlyOwner {
        _pendingOwner = address(0);
        _transferOwnership(address(0));
    }
}

File 9 of 11 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

File 10 of 11 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

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

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

    /**
     * This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

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

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    /**
     * This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newBroker","type":"address"}],"name":"AddOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"PrepareToTransferOwnership","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"broker","type":"address"}],"name":"RemoveOperator","type":"event"},{"inputs":[{"internalType":"address","name":"operator_","type":"address"}],"name":"addOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"liquidityPool_","type":"address"},{"internalType":"address","name":"orderBook_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidityPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"listOrders","outputs":[{"internalType":"uint64[]","name":"orderIds","type":"uint64[]"},{"internalType":"bytes32[3][]","name":"orders","type":"bytes32[3][]"},{"internalType":"bytes[]","name":"contexts","type":"bytes[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"rawAmount0","type":"uint256"},{"internalType":"uint256","name":"minRawAmount1","type":"uint256"},{"internalType":"bytes32","name":"data","type":"bytes32"}],"name":"muxRebalanceCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"operators","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"orderBook","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"","type":"uint64"}],"name":"orderContext","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"tokenId0","type":"uint8"},{"internalType":"uint8","name":"tokenId1","type":"uint8"},{"internalType":"uint96","name":"rawAmount0","type":"uint96"},{"internalType":"uint96","name":"maxRawAmount1","type":"uint96"},{"internalType":"bytes","name":"oneInchCallData","type":"bytes"}],"name":"placeOneInchOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"tokenId0","type":"uint8"},{"internalType":"uint8","name":"tokenId1","type":"uint8"},{"internalType":"uint96","name":"rawAmount0","type":"uint96"},{"internalType":"uint96","name":"maxRawAmount1","type":"uint96"}],"name":"placeSimpleOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator_","type":"address"}],"name":"removeOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"takeOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50611eb8806100206000396000f3fe608060405234801561001057600080fd5b506004361061010b5760003560e01c8063715018a6116100a25780639870d7fe116100715780639870d7fe1461022c578063a1db97821461023f578063abb263a414610252578063ac8a584a14610265578063f2fde38b1461027857600080fd5b8063715018a6146101ed578063776af5ba146101f557806386f7f959146102085780638da5cb5b1461021b57600080fd5b8063523eb537116100de578063523eb53714610187578063605361721461019a578063665a11ca146101a257806367324fea146101cd57600080fd5b806313e7c9d814610110578063176091f4146101485780631da93cee1461015f578063485cc95514610174575b600080fd5b61013361011e366004611853565b60686020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b61015061028b565b60405161013f9392919061191f565b61017261016d3660046119da565b610577565b005b610172610182366004611a27565b6108f4565b610172610195366004611a6f565b6109e7565b610172610ab7565b6066546101b5906001600160a01b031681565b6040516001600160a01b03909116815260200161013f565b6101e06101db366004611a6f565b610b27565b60405161013f9190611a8c565b610172610bc1565b6067546101b5906001600160a01b031681565b610172610216366004611ac7565b610c07565b6033546001600160a01b03166101b5565b61017261023a366004611853565b610d59565b61017261024d366004611b1b565b610e24565b610172610260366004611b45565b610e80565b610172610273366004611853565b610ff9565b610172610286366004611853565b6110c0565b6060806060600061029c606a6111b4565b9050806001600160401b038111156102b6576102b6611bf8565b6040519080825280602002602001820160405280156102df578160200160208202803683370190505b509350806001600160401b038111156102fa576102fa611bf8565b60405190808252806020026020018201604052801561033357816020015b610320611746565b8152602001906001900390816103185790505b509250806001600160401b0381111561034e5761034e611bf8565b60405190808252806020026020018201604052801561038157816020015b606081526020019060019003908161036c5790505b50915060005b8181101561057057600061039c606a836111c4565b9050808683815181106103b1576103b1611c0e565b6001600160401b03928316602091820292909201015260675460405163337e741f60e21b815291831660048301526000916001600160a01b039091169063cdf9d07c90602401608060405180830381865afa158015610414573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104389190611c34565b87858151811061044a5761044a611c0e565b6020026020010181935082905250508061049d5760405162461bcd60e51b815260206004820152600f60248201526e1bdc99195c881b9bdd08199bdd5b99608a1b60448201526064015b60405180910390fd5b6001600160401b038216600090815260696020526040902080546104c090611cc0565b80601f01602080910402602001604051908101604052809291908181526020018280546104ec90611cc0565b80156105395780601f1061050e57610100808354040283529160200191610539565b820191906000526020600020905b81548152906001019060200180831161051c57829003601f168201915b505050505085848151811061055057610550611c0e565b60200260200101819052505050808061056890611d11565b915050610387565b5050909192565b6066546001600160a01b031633146105bc5760405162461bcd60e51b81526020600482015260086024820152671b9bdd081c1bdbdb60c21b6044820152606401610494565b6000806105c8836111d7565b506001600160401b03811660009081526069602052604081209294509092508360018111156105f9576105f9611d2c565b14156106045761089a565b600183600181111561061857610618611d2c565b141561089a576000731111111254fb6c44bac0bed2854e76f90643097d60405163095ea7b360e01b81526001600160a01b038083166004830152602482018a9052919250908a169063095ea7b3906044016020604051808303816000875af1158015610688573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ac9190611d42565b506040516370a0823160e01b81523060048201526000906001600160a01b038a16906370a0823190602401602060405180830381865afa1580156106f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107189190611d5d565b90506107d28284805461072a90611cc0565b80601f016020809104026020016040519081016040528092919081815260200182805461075690611cc0565b80156107a35780601f10610778576101008083540402835291602001916107a3565b820191906000526020600020905b81548152906001019060200180831161078657829003601f168201915b50505050506040518060400160405280600c81526020016b0c5a5b98da0819985a5b195960a21b815250611202565b506040516370a0823160e01b81523060048201526000906001600160a01b038b16906370a0823190602401602060405180830381865afa15801561081a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061083e9190611d5d565b90508181101580156108595750876108568383611d76565b10155b6108965760405162461bcd60e51b815260206004820152600e60248201526d31696e636820736c69707061676560901b6044820152606401610494565b5050505b6066546108b4906001600160a01b03898116911687611219565b6108c8606a6001600160401b03841661126b565b506001600160401b03821660009081526069602052604081206108ea91611764565b5050505050505050565b600054610100900460ff1661090f5760005460ff1615610913565b303b155b6109765760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610494565b600054610100900460ff16158015610998576000805461ffff19166101011790555b6109a0611277565b606680546001600160a01b038086166001600160a01b031992831617909255606780549285169290911691909117905580156109e2576000805461ff00191690555b505050565b3360009081526068602052604090205460ff16610a165760405162461bcd60e51b815260040161049490611d8d565b60675460405163523eb53760e01b81526001600160401b03831660048201526001600160a01b039091169063523eb53790602401600060405180830381600087803b158015610a6457600080fd5b505af1158015610a78573d6000803e3d6000fd5b50610a929250606a9150506001600160401b03831661126b565b506001600160401b0381166000908152606960205260408120610ab491611764565b50565b6065546001600160a01b0316336001600160a01b031614610b005760405162461bcd60e51b815260206004820152600360248201526214d39160ea1b6044820152606401610494565b606554610b15906001600160a01b03166112a6565b606580546001600160a01b0319169055565b60696020526000908152604090208054610b4090611cc0565b80601f0160208091040260200160405190810160405280929190818152602001828054610b6c90611cc0565b8015610bb95780601f10610b8e57610100808354040283529160200191610bb9565b820191906000526020600020905b815481529060010190602001808311610b9c57829003601f168201915b505050505081565b6033546001600160a01b03163314610beb5760405162461bcd60e51b815260040161049490611db3565b606580546001600160a01b0319169055610c0560006112a6565b565b3360009081526068602052604090205460ff16610c365760405162461bcd60e51b815260040161049490611d8d565b606754604080516302a58b3360e41b815290516000926001600160a01b031691632a58b3309160048083019260209291908290030181865afa158015610c80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca49190611de8565b90506000610cb4600083426112f8565b9050610cca606a6001600160401b038416611333565b506067546040516305ac05a560e41b815260ff8089166004830152871660248201526001600160601b03808716604483015285166064820152608481018390526001600160a01b0390911690635ac05a509060a401600060405180830381600087803b158015610d3957600080fd5b505af1158015610d4d573d6000803e3d6000fd5b50505050505050505050565b6033546001600160a01b03163314610d835760405162461bcd60e51b815260040161049490611db3565b6001600160a01b03811660009081526068602052604090205460ff1615610dd85760405162461bcd60e51b81526020600482015260096024820152681d5b98da185b99d95960ba1b6044820152606401610494565b6001600160a01b038116600081815260686020526040808220805460ff19166001179055517f4c141abccf173677929dea054f218ed87362117834a8869ec9f68d8bdaaea1dc9190a250565b3360009081526068602052604090205460ff1680610e4c57506033546001600160a01b031633145b610e685760405162461bcd60e51b815260040161049490611d8d565b610e7c6001600160a01b0383163383611219565b5050565b3360009081526068602052604090205460ff16610eaf5760405162461bcd60e51b815260040161049490611d8d565b606754604080516302a58b3360e41b815290516000926001600160a01b031691632a58b3309160048083019260209291908290030181865afa158015610ef9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1d9190611de8565b90506000610f2d600183426112f8565b6001600160401b0383166000908152606960205260409020909150610f5390858561179e565b50610f68606a6001600160401b038416611333565b506067546040516305ac05a560e41b815260ff808b166004830152891660248201526001600160601b03808916604483015287166064820152608481018390526001600160a01b0390911690635ac05a509060a401600060405180830381600087803b158015610fd757600080fd5b505af1158015610feb573d6000803e3d6000fd5b505050505050505050505050565b6033546001600160a01b031633146110235760405162461bcd60e51b815260040161049490611db3565b6001600160a01b03811660009081526068602052604090205460ff166110775760405162461bcd60e51b81526020600482015260096024820152681d5b98da185b99d95960ba1b6044820152606401610494565b6001600160a01b038116600081815260686020526040808220805460ff19169055517f6b4be2dd49eba45ba43390fbe7da13e2b965d255db41d6a0fcf6d2e15ac1fccb9190a250565b6033546001600160a01b031633146110ea5760405162461bcd60e51b815260040161049490611db3565b6001600160a01b0381166111265760405162461bcd60e51b815260206004820152600360248201526204f3d360ec1b6044820152606401610494565b6033546001600160a01b038281169116141561116a5760405162461bcd60e51b81526020600482015260036024820152624f3d4f60e81b6044820152606401610494565b606580546001600160a01b0319166001600160a01b0383169081179091556040517fb501f5dc3610d10a179d924f686fc89ddcdd3abb05afd7a1baeead166b2f122c90600090a250565b60006111be825490565b92915050565b60006111d0838361133f565b9392505050565b6000808060f884901c60018111156111f1576111f1611d2c565b9460b885901c9460981c9350915050565b60606112118484600085611369565b949350505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526109e290849061149a565b60006111d0838361156c565b600054610100900460ff1661129e5760405162461bcd60e51b815260040161049490611e05565b610c0561165f565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600060988263ffffffff16901b60b8846001600160401b0316901b60f886600181111561132757611327611d2c565b901b1717949350505050565b60006111d0838361168e565b600082600001828154811061135657611356611c0e565b9060005260206000200154905092915050565b6060824710156113ca5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610494565b6001600160a01b0385163b6114215760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610494565b600080866001600160a01b0316858760405161143d9190611e50565b60006040518083038185875af1925050503d806000811461147a576040519150601f19603f3d011682016040523d82523d6000602084013e61147f565b606091505b509150915061148f8282866116dd565b979650505050505050565b60006114ef826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166112029092919063ffffffff16565b8051909150156109e2578080602001905181019061150d9190611d42565b6109e25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610494565b60008181526001830160205260408120548015611655576000611590600183611d76565b85549091506000906115a490600190611d76565b90508181146116095760008660000182815481106115c4576115c4611c0e565b90600052602060002001549050808760000184815481106115e7576115e7611c0e565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061161a5761161a611e6c565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506111be565b60009150506111be565b600054610100900460ff166116865760405162461bcd60e51b815260040161049490611e05565b610c05611716565b60008181526001830160205260408120546116d5575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556111be565b5060006111be565b606083156116ec5750816111d0565b8251156116fc5782518084602001fd5b8160405162461bcd60e51b81526004016104949190611a8c565b600054610100900460ff1661173d5760405162461bcd60e51b815260040161049490611e05565b610c05336112a6565b60405180606001604052806003906020820280368337509192915050565b50805461177090611cc0565b6000825580601f10611780575050565b601f016020900490600052602060002090810190610ab49190611822565b8280546117aa90611cc0565b90600052602060002090601f0160209004810192826117cc5760008555611812565b82601f106117e55782800160ff19823516178555611812565b82800160010185558215611812579182015b828111156118125782358255916020019190600101906117f7565b5061181e929150611822565b5090565b5b8082111561181e5760008155600101611823565b80356001600160a01b038116811461184e57600080fd5b919050565b60006020828403121561186557600080fd5b6111d082611837565b60005b83811015611889578181015183820152602001611871565b83811115611898576000848401525b50505050565b600081518084526118b681602086016020860161186e565b601f01601f19169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b8581101561191257828403895261190084835161189e565b988501989350908401906001016118e8565b5091979650505050505050565b60608082528451828201819052600091906020906080850190828901855b828110156119625781516001600160401b03168452928401929084019060010161193d565b5050508481038286015286518082528783019183019060005b818110156119b95783518360005b60038110156119a657825182529187019190870190600101611989565b505050928401929185019160010161197b565b505085810360408701526119cd81886118ca565b9998505050505050505050565b600080600080600060a086880312156119f257600080fd5b6119fb86611837565b9450611a0960208701611837565b94979496505050506040830135926060810135926080909101359150565b60008060408385031215611a3a57600080fd5b611a4383611837565b9150611a5160208401611837565b90509250929050565b6001600160401b0381168114610ab457600080fd5b600060208284031215611a8157600080fd5b81356111d081611a5a565b6020815260006111d0602083018461189e565b803560ff8116811461184e57600080fd5b80356001600160601b038116811461184e57600080fd5b60008060008060808587031215611add57600080fd5b611ae685611a9f565b9350611af460208601611a9f565b9250611b0260408601611ab0565b9150611b1060608601611ab0565b905092959194509250565b60008060408385031215611b2e57600080fd5b611b3783611837565b946020939093013593505050565b60008060008060008060a08789031215611b5e57600080fd5b611b6787611a9f565b9550611b7560208801611a9f565b9450611b8360408801611ab0565b9350611b9160608801611ab0565b925060808701356001600160401b0380821115611bad57600080fd5b818901915089601f830112611bc157600080fd5b813581811115611bd057600080fd5b8a6020828501011115611be257600080fd5b6020830194508093505050509295509295509295565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b8051801515811461184e57600080fd5b60008060808385031215611c4757600080fd5b83601f840112611c5657600080fd5b604051606081018181106001600160401b0382111715611c7857611c78611bf8565b604052806060850186811115611c8d57600080fd5b855b81811015611ca7578051835260209283019201611c8f565b50829450611cb481611c24565b93505050509250929050565b600181811c90821680611cd457607f821691505b60208210811415611cf557634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6000600019821415611d2557611d25611cfb565b5060010190565b634e487b7160e01b600052602160045260246000fd5b600060208284031215611d5457600080fd5b6111d082611c24565b600060208284031215611d6f57600080fd5b5051919050565b600082821015611d8857611d88611cfb565b500390565b6020808252600c908201526b3737ba1037b832b930ba37b960a11b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060208284031215611dfa57600080fd5b81516111d081611a5a565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60008251611e6281846020870161186e565b9190910192915050565b634e487b7160e01b600052603160045260246000fdfea26469706673582212206f003a33836d823735883689bfa27227d5f7c8a19ddc959327f7ea2419eb6e3e64736f6c634300080a0033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.