Contract 0x917863ced89fcf12a2aa590f692ff48983103a50

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xf6b3b3decfeba1682dbb2b12a9aa2a92403837ebd9ab4481d438538826c064820x60806040182754542022-07-22 7:49:15136 days 14 hrs ago0x44cbfc3ce762fc0fee9ddd6372804b7b660176bc IN  Create: OrderBook0 ETH0.011958718519 ETH
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0xe24298a7a8a17e49d09050382c0a14c4555f6f2d327f14c66d14d1c5bbb49f26223277872022-09-01 11:31:0095 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x97a2f2dc93cd6f257e2a4f5203472f903cb7638753e114e396e926de3b547cfe223277802022-09-01 11:30:5995 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xa35fa9e3545a19718591fe4db79e78c6d4349176d0e1f612d002c2ee3062ddfc223262682022-09-01 11:18:2895 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xcbd1caff234fa14575aebd54a08434706605c94a4caad66cb52d05569b5f200a223262642022-09-01 11:18:2695 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xd746bec4586e3dba663e72223eb473d4fb1fbad78c0944d05de1824b81a27c88223257142022-09-01 11:13:4395 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x6d4795500b7a730a162b7ed91fae13252ce38aaf23efb1834e6580b1bef7d7c7223257112022-09-01 11:13:4195 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x73cb65c16f2892a1de9af6342ea7d4415c748a218b49b105a7efb0b605457d6c223256852022-09-01 11:13:2695 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xd432f250acb45062dead09d9b7392b0df2b2f31fdb6fa7242aa008a7c83015f5223256822022-09-01 11:13:2495 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x2eafbc8b611f85706558c3dd22ee489c3641d9308a076ac97d67980a53b3df2b223247952022-09-01 11:05:5995 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x95423b1737d8f9e12cfe673f894100b5bec8c74e47b914d963796c1666aace02223247932022-09-01 11:05:5895 days 10 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xee9c312f4127cb9048c1dc77aa9ae0d27a938b1a58fa7f1d62dabcb0c215dfa9223245222022-09-01 11:03:4695 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x789253b562d5aab6dea5a7664ad1d03ccb3b4f067af9570f2a5b5125048e9919223245202022-09-01 11:03:4495 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x4f4cfa2f1a394faf8ed124b91799603ac51e6cd419ac1d62147e2aca8c373364223236722022-09-01 10:56:0395 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x2d29fab45608085dac56d0688db400fb9fab6181e1c01c306a3b4636418db051223225682022-09-01 10:45:3795 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x35a88dea0a33d3c29f13b99d0983616be98594930f06e04a5d17dd8de2e16791223225622022-09-01 10:45:3695 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x1999b66a4430be0265d08c4da1054941e29e535907921bf4a5b24d9d60707291223224512022-09-01 10:44:3995 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xcd48f7af987a7e597a4be37bda6ce9252c242fbf6f964b6a6c849e57480b86fa223224502022-09-01 10:44:3795 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x72da441e8a0e22e5cea273049c7ec75c99b3fbd1f7118d3456d075029babb4d5223219682022-09-01 10:40:3795 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x390c018076ad240278fbe8fa4e32844b9a1740c32e3d56d5aac023709b579fc6223219632022-09-01 10:40:3595 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x46a16e76e89a1247fbfb987f4573d9af6d96bbdd77487588907e121de1ee51f7223210792022-09-01 10:32:4495 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x943f33b31b89861259636e5045b1bc63a60621a741d83490620d02369073d916223210782022-09-01 10:32:4395 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x2ccc837c2187bb36989198d2a9f45650b64378b99a0375c6ecd1ed41ca1690b6223210112022-09-01 10:32:0495 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xb4c8013ee1f1e72c6332b69f538173274586d9d1766d0f89a2f859a21ec17144223210082022-09-01 10:32:0295 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0xeece2c18aa318cc90f777fc5b02d163ae7d5c37e3df3fdb780fc6623aa6ca696223209532022-09-01 10:31:3395 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
0x1f479f667b01298582982e3c0d7cf823bf943bb58990ee9c54cf3d6af962720a223209512022-09-01 10:31:3195 days 11 hrs ago 0xa19fd5ab6c8dcffa2a295f78a5bb4ac543aaf5e30x917863ced89fcf12a2aa590f692ff48983103a500 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OrderBook

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 18 : OrderBook.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "./Types.sol";
import "./Admin.sol";
import "../libraries/LibSubAccount.sol";
import "../libraries/LibMath.sol";

contract OrderBook is Storage, Admin {
    using LibSubAccount for bytes32;
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using LibOrder for LibOrder.OrderList;
    using LibOrder for bytes32[3];
    using LibOrder for PositionOrder;
    using LibOrder for LiquidityOrder;
    using LibOrder for WithdrawalOrder;

    event NewPositionOrder(
        bytes32 indexed subAccountId,
        uint64 indexed orderId,
        uint96 collateral, // erc20.decimals
        uint96 size, // 1e18
        uint96 price, // 1e18
        uint8 profitTokenId,
        uint8 flags,
        uint32 deadline // 1e0. 0 if market order. > 0 if limit order
    );
    event NewLiquidityOrder(
        address indexed account,
        uint64 indexed orderId,
        uint8 assetId,
        uint96 rawAmount, // erc20.decimals
        bool isAdding
    );
    event NewWithdrawalOrder(
        bytes32 indexed subAccountId,
        uint64 indexed orderId,
        uint96 rawAmount, // erc20.decimals
        uint8 profitTokenId,
        bool isProfit
    );
    event NewRebalanceOrder(
        address indexed rebalancer,
        uint64 indexed orderId,
        uint8 tokenId0,
        uint8 tokenId1,
        uint96 rawAmount0,
        uint96 maxRawAmount1,
        bytes32 userData
    );
    event FillOrder(uint64 orderId, OrderType orderType, bytes32[3] orderData);
    event CancelOrder(uint64 orderId, OrderType orderType, bytes32[3] orderData);

    function initialize(
        address pool,
        address mlp,
        address weth,
        address nativeUnwrapper
    ) external initializer {
        __SafeOwnable_init();

        _pool = ILiquidityPool(pool);
        _mlp = IERC20Upgradeable(mlp);
        _weth = IWETH(weth);
        _nativeUnwrapper = INativeUnwrapper(nativeUnwrapper);
        maintainer = owner();
    }

    function getOrderCount() external view returns (uint256) {
        return _orders.length();
    }

    function getOrder(uint64 orderId) external view returns (bytes32[3] memory, bool) {
        return (_orders.get(orderId), _orders.contains(orderId));
    }

    function getOrders(uint256 begin, uint256 end)
        external
        view
        returns (bytes32[3][] memory orderArray, uint256 totalCount)
    {
        totalCount = _orders.length();
        if (begin >= end || begin >= totalCount) {
            return (orderArray, totalCount);
        }
        end = end <= totalCount ? end : totalCount;
        uint256 size = end - begin;
        orderArray = new bytes32[3][](size);
        for (uint256 i = 0; i < size; i++) {
            orderArray[i] = _orders.at(i + begin);
        }
    }

    /**
     * @dev   Open/close position. called by Trader
     *
     *        Market order will expire after marketOrderTimeout seconds.
     *        Limit/Trigger order will expire after deadline.
     * @param subAccountId       sub account id. see LibSubAccount.decodeSubAccountId
     * @param collateralAmount   deposit collateral before open; or withdraw collateral after close. decimals = erc20.decimals
     * @param size               position size. decimals = 18
     * @param price              limit price. decimals = 18
     * @param profitTokenId      specify the profitable asset.id when closing a position and making a profit.
     *                           take no effect when opening a position or loss.
     * @param flags              a bitset of LibOrder.POSITION_*
     *                           POSITION_INCREASING               0x80 means openPosition; otherwise closePosition
     *                           POSITION_MARKET_ORDER             0x40 means ignore limitPrice
     *                           POSITION_WITHDRAW_ALL_IF_EMPTY    0x20 means auto withdraw all collateral if position.size == 0
     *                           POSITION_TRIGGER_ORDER            0x10 means this is a trigger order (ex: stop-loss order). 0 means this is a limit order (ex: take-profit order)
     * @param deadline           a unix timestamp after which the limit/trigger order MUST NOT be filled. fill 0 for market order.
     */
    function placePositionOrder(
        bytes32 subAccountId,
        uint96 collateralAmount, // erc20.decimals
        uint96 size, // 1e18
        uint96 price, // 1e18
        uint8 profitTokenId,
        uint8 flags,
        uint32 deadline // 1e0
    ) external payable {
        LibSubAccount.DecodedSubAccountId memory account = subAccountId.decodeSubAccountId();
        require(account.account == _msgSender(), "SND"); // SeNDer is not authorized
        require(size != 0, "S=0"); // order Size Is Zero
        uint32 expire10s;
        if ((flags & LibOrder.POSITION_MARKET_ORDER) != 0) {
            require(price == 0, "P!0"); // market order does not need a limit Price
            require(deadline == 0, "D!0"); // market order does not need a deadline
        } else {
            require(deadline > _blockTimestamp(), "D<0"); // Deadline is earlier than now
            expire10s = (deadline - _blockTimestamp()) / 10;
        }
        if (profitTokenId > 0) {
            // note: profitTokenId == 0 is also valid, this only partially protects the function from misuse
            require((flags & LibOrder.POSITION_OPEN) == 0, "T!0"); // opening position does not need a Token id
        }
        // add order
        uint64 orderId = nextOrderId++;
        require(expire10s <= type(uint24).max, "DTL"); // Deadline is Too Large
        bytes32[3] memory data = LibOrder.encodePositionOrder(
            orderId,
            subAccountId,
            collateralAmount,
            size,
            price,
            profitTokenId,
            flags,
            _blockTimestamp(),
            uint24(expire10s)
        );
        _orders.add(orderId, data);
        // fetch collateral
        if (collateralAmount > 0 && ((flags & LibOrder.POSITION_OPEN) != 0)) {
            address collateralAddress = _pool.getAssetAddress(account.collateralId);
            _transferIn(collateralAddress, address(this), collateralAmount);
        }
        emit NewPositionOrder(subAccountId, orderId, collateralAmount, size, price, profitTokenId, flags, deadline);
    }

    /**
     * @dev   Add/remove liquidity. called by Liquidity Provider
     *
     *        Can be filled after liquidityLockPeriod seconds.
     * @param assetId   asset.id that added/removed to
     * @param rawAmount asset token amount. decimals = erc20.decimals
     * @param isAdding  true for add liquidity, false for remove liquidity
     */
    function placeLiquidityOrder(
        uint8 assetId,
        uint96 rawAmount, // erc20.decimals
        bool isAdding
    ) external payable {
        require(rawAmount != 0, "A=0"); // Amount Is Zero
        address account = _msgSender();
        if (isAdding) {
            address collateralAddress = _pool.getAssetAddress(assetId);
            _transferIn(collateralAddress, address(this), rawAmount);
        } else {
            _mlp.safeTransferFrom(_msgSender(), address(this), rawAmount);
        }
        uint64 orderId = nextOrderId++;
        bytes32[3] memory data = LibOrder.encodeLiquidityOrder(
            orderId,
            account,
            assetId,
            rawAmount,
            isAdding,
            _blockTimestamp()
        );
        _orders.add(orderId, data);

        emit NewLiquidityOrder(account, orderId, assetId, rawAmount, isAdding);
    }

    /**
     * @dev   Withdraw collateral/profit. called by Trader
     *
     *        This order will expire after marketOrderTimeout seconds.
     * @param subAccountId       sub account id. see LibSubAccount.decodeSubAccountId
     * @param rawAmount          collateral or profit asset amount. decimals = erc20.decimals
     * @param profitTokenId      specify the profitable asset.id
     * @param isProfit           true for withdraw profit. false for withdraw collateral
     */
    function placeWithdrawalOrder(
        bytes32 subAccountId,
        uint96 rawAmount, // erc20.decimals
        uint8 profitTokenId,
        bool isProfit
    ) external {
        address trader = subAccountId.getSubAccountOwner();
        require(trader == _msgSender(), "SND"); // SeNDer is not authorized
        require(rawAmount != 0, "A=0"); // Amount Is Zero

        uint64 orderId = nextOrderId++;
        bytes32[3] memory data = LibOrder.encodeWithdrawalOrder(
            orderId,
            subAccountId,
            rawAmount,
            profitTokenId,
            isProfit,
            _blockTimestamp()
        );
        _orders.add(orderId, data);

        emit NewWithdrawalOrder(subAccountId, orderId, rawAmount, profitTokenId, isProfit);
    }

    /**
     * @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 onlyRebalancer {
        require(rawAmount0 != 0, "A=0"); // Amount Is Zero
        address rebalancer = _msgSender();
        uint64 orderId = nextOrderId++;
        bytes32[3] memory data = LibOrder.encodeRebalanceOrder(
            orderId,
            rebalancer,
            tokenId0,
            tokenId1,
            rawAmount0,
            maxRawAmount1,
            userData
        );
        _orders.add(orderId, data);
        emit NewRebalanceOrder(rebalancer, orderId, tokenId0, tokenId1, rawAmount0, maxRawAmount1, userData);
    }

    /**
     * @dev   Open/close a position. called by Broker
     *
     * @param orderId           order id
     * @param collateralPrice   collateral price. decimals = 18
     * @param assetPrice        asset price. decimals = 18
     * @param profitAssetPrice  profit asset price. decimals = 18
     */
    function fillPositionOrder(
        uint64 orderId,
        uint96 collateralPrice,
        uint96 assetPrice,
        uint96 profitAssetPrice // only used when !isLong
    ) external onlyBroker whenPositionOrderEnabled {
        require(_orders.contains(orderId), "OID"); // can not find this OrderID
        bytes32[3] memory orderData = _orders.get(orderId);
        _orders.remove(orderId);
        OrderType orderType = LibOrder.getOrderType(orderData);
        require(orderType == OrderType.PositionOrder, "TYP"); // order TYPe mismatch

        PositionOrder memory order = orderData.decodePositionOrder();
        require(_blockTimestamp() <= _positionOrderDeadline(order), "EXP"); // EXPired
        uint96 tradingPrice;
        if (order.isOpenPosition()) {
            // auto deposit
            uint96 collateralAmount = order.collateral;
            if (collateralAmount > 0) {
                IERC20Upgradeable collateral = IERC20Upgradeable(
                    _pool.getAssetAddress(order.subAccountId.getSubAccountCollateralId())
                );
                collateral.safeTransfer(address(_pool), collateralAmount);
                _pool.depositCollateral(order.subAccountId, collateralAmount);
            }
            tradingPrice = _pool.openPosition(order.subAccountId, order.size, collateralPrice, assetPrice);
        } else {
            tradingPrice = _pool.closePosition(
                order.subAccountId,
                order.size,
                order.profitTokenId,
                collateralPrice,
                assetPrice,
                profitAssetPrice
            );

            // auto withdraw
            uint96 collateralAmount = order.collateral;
            if (collateralAmount > 0) {
                _pool.withdrawCollateral(order.subAccountId, collateralAmount, collateralPrice, assetPrice);
            }
            if (order.isWithdrawIfEmpty()) {
                (uint96 collateral, uint96 size, , , ) = _pool.getSubAccount(order.subAccountId);
                if (size == 0 && collateral > 0) {
                    _pool.withdrawAllCollateral(order.subAccountId);
                }
            }
        }
        if (!order.isMarketOrder()) {
            // open,long      0,0   0,1   1,1   1,0
            // limitOrder     <=    >=    <=    >=
            // triggerOrder   >=    <=    >=    <=
            bool isLess = (order.subAccountId.isLong() == order.isOpenPosition());
            if (order.isTriggerOrder()) {
                isLess = !isLess;
            }
            if (isLess) {
                require(tradingPrice <= order.price, "LMT"); // LiMiTed by limitPrice
            } else {
                require(tradingPrice >= order.price, "LMT"); // LiMiTed by limitPrice
            }
        }

        emit FillOrder(orderId, orderType, orderData);
    }

    /**
     * @dev   Add/remove liquidity. called by Broker
     *
     *        Check _getLiquidityFeeRate in Liquidity.sol on how to calculate liquidity fee.
     * @param orderId           order id
     * @param assetPrice        token price that added/removed to
     * @param mlpPrice          mlp price
     * @param currentAssetValue liquidity USD value of a single asset in all chains (even if tokenId is a stable asset)
     * @param targetAssetValue  weight / Σ weight * total liquidity USD value in all chains
     */
    function fillLiquidityOrder(
        uint64 orderId,
        uint96 assetPrice,
        uint96 mlpPrice,
        uint96 currentAssetValue,
        uint96 targetAssetValue
    ) external onlyBroker whenLiquidityOrderEnabled {
        require(_orders.contains(orderId), "OID"); // can not find this OrderID
        bytes32[3] memory orderData = _orders.get(orderId);
        _orders.remove(orderId);
        OrderType orderType = LibOrder.getOrderType(orderData);
        require(orderType == OrderType.LiquidityOrder, "TYP"); // order TYPe mismatch

        LiquidityOrder memory order = orderData.decodeLiquidityOrder();
        require(_blockTimestamp() >= order.placeOrderTime + liquidityLockPeriod, "LCK"); // mlp token is LoCKed
        uint96 rawAmount = order.rawAmount;
        if (order.isAdding) {
            IERC20Upgradeable collateral = IERC20Upgradeable(_pool.getAssetAddress(order.assetId));
            collateral.safeTransfer(address(_pool), rawAmount);
            _pool.addLiquidity(
                order.account,
                order.assetId,
                rawAmount,
                assetPrice,
                mlpPrice,
                currentAssetValue,
                targetAssetValue
            );
        } else {
            _mlp.safeTransfer(address(_pool), rawAmount);
            _pool.removeLiquidity(
                order.account,
                rawAmount,
                order.assetId,
                assetPrice,
                mlpPrice,
                currentAssetValue,
                targetAssetValue
            );
        }

        emit FillOrder(orderId, orderType, orderData);
    }

    /**
     * @dev   Withdraw collateral/profit. called by Broker
     *
     * @param orderId           order id
     * @param collateralPrice   collateral price. decimals = 18
     * @param assetPrice        asset price. decimals = 18
     * @param profitAssetPrice  profit asset price. decimals = 18
     */
    function fillWithdrawalOrder(
        uint64 orderId,
        uint96 collateralPrice,
        uint96 assetPrice,
        uint96 profitAssetPrice // only used when !isLong
    ) external onlyBroker {
        require(_orders.contains(orderId), "OID"); // can not find this OrderID
        bytes32[3] memory orderData = _orders.get(orderId);
        _orders.remove(orderId);
        OrderType orderType = LibOrder.getOrderType(orderData);
        require(orderType == OrderType.WithdrawalOrder, "TYP"); // order TYPe mismatch

        WithdrawalOrder memory order = orderData.decodeWithdrawalOrder();
        require(_blockTimestamp() <= order.placeOrderTime + marketOrderTimeout, "EXP"); // EXPired
        if (order.isProfit) {
            _pool.withdrawProfit(
                order.subAccountId,
                order.rawAmount,
                order.profitTokenId,
                collateralPrice,
                assetPrice,
                profitAssetPrice
            );
        } else {
            _pool.withdrawCollateral(order.subAccountId, order.rawAmount, collateralPrice, assetPrice);
        }

        emit FillOrder(orderId, orderType, orderData);
    }

    /**
     * @dev   Rebalance. called by Broker
     *
     * @param orderId  order id
     * @param price0   price of token 0
     * @param price1   price of token 1
     */
    function fillRebalanceOrder(
        uint64 orderId,
        uint96 price0,
        uint96 price1
    ) external onlyBroker whenLiquidityOrderEnabled {
        require(_orders.contains(orderId), "OID"); // can not find this OrderID
        bytes32[3] memory orderData = _orders.get(orderId);
        _orders.remove(orderId);
        OrderType orderType = LibOrder.getOrderType(orderData);
        require(orderType == OrderType.RebalanceOrder, "TYP"); // order TYPe mismatch

        RebalanceOrder memory order = orderData.decodeRebalanceOrder();
        _pool.rebalance(
            order.rebalancer,
            order.tokenId0,
            order.tokenId1,
            order.rawAmount0,
            order.maxRawAmount1,
            order.userData,
            price0,
            price1
        );

        emit FillOrder(orderId, orderType, orderData);
    }

    /**
     * @notice Cancel an order
     */
    function cancelOrder(uint64 orderId) external {
        require(_orders.contains(orderId), "OID"); // can not find this OrderID
        bytes32[3] memory orderData = _orders.get(orderId);
        _orders.remove(orderId);
        address account = orderData.getOrderOwner();
        OrderType orderType = LibOrder.getOrderType(orderData);
        if (orderType == OrderType.PositionOrder) {
            PositionOrder memory order = orderData.decodePositionOrder();
            if (brokers[_msgSender()]) {
                require(_blockTimestamp() > _positionOrderDeadline(order), "EXP"); // not EXPired yet
            } else {
                require(_msgSender() == account, "SND"); // SeNDer is not authorized
            }
            if (order.isOpenPosition() && order.collateral > 0) {
                address collateralAddress = _pool.getAssetAddress(order.subAccountId.getSubAccountCollateralId());
                _transferOut(collateralAddress, account, order.collateral);
            }
        } else if (orderType == OrderType.LiquidityOrder) {
            require(_msgSender() == account, "SND"); // SeNDer is not authorized
            LiquidityOrder memory order = orderData.decodeLiquidityOrder();
            if (order.isAdding) {
                address collateralAddress = _pool.getAssetAddress(order.assetId);
                _transferOut(collateralAddress, account, order.rawAmount);
            } else {
                _mlp.safeTransfer(account, order.rawAmount);
            }
        } else if (orderType == OrderType.WithdrawalOrder) {
            if (brokers[_msgSender()]) {
                WithdrawalOrder memory order = orderData.decodeWithdrawalOrder();
                uint256 deadline = order.placeOrderTime + marketOrderTimeout;
                require(_blockTimestamp() > deadline, "EXP"); // not EXPired yet
            } else {
                require(_msgSender() == account, "SND"); // SeNDer is not authorized
            }
        } else if (orderType == OrderType.RebalanceOrder) {
            require(_msgSender() == account, "SND"); // SeNDer is not authorized
        } else {
            revert();
        }
        emit CancelOrder(orderId, LibOrder.getOrderType(orderData), orderData);
    }

    /**
     * @notice Trader can withdraw all collateral only when position = 0
     */
    function withdrawAllCollateral(bytes32 subAccountId) external {
        LibSubAccount.DecodedSubAccountId memory account = subAccountId.decodeSubAccountId();
        require(account.account == _msgSender(), "SND"); // SeNDer is not authorized
        _pool.withdrawAllCollateral(subAccountId);
    }

    /**
     * @notice Broker can update funding each [fundingInterval] seconds by specifying utilizations.
     *
     *         Check _getFundingRate in Liquidity.sol on how to calculate funding rate.
     * @param  stableUtilization    Stable coin utilization in all chains
     * @param  unstableTokenIds     All unstable Asset id(s) MUST be passed in order. ex: 1, 2, 5, 6, ...
     * @param  unstableUtilizations Unstable Asset utilizations in all chains
     * @param  unstablePrices       Unstable Asset prices
     */
    function updateFundingState(
        uint32 stableUtilization, // 1e5
        uint8[] calldata unstableTokenIds,
        uint32[] calldata unstableUtilizations, // 1e5
        uint96[] calldata unstablePrices
    ) external onlyBroker {
        _pool.updateFundingState(stableUtilization, unstableTokenIds, unstableUtilizations, unstablePrices);
    }

    /**
     * @notice Deposit collateral into a subAccount
     *
     * @param  subAccountId       sub account id. see LibSubAccount.decodeSubAccountId
     * @param  collateralAmount   collateral amount. decimals = erc20.decimals
     */
    function depositCollateral(bytes32 subAccountId, uint256 collateralAmount) external payable {
        LibSubAccount.DecodedSubAccountId memory account = subAccountId.decodeSubAccountId();
        require(account.account == _msgSender(), "SND"); // SeNDer is not authorized
        require(collateralAmount != 0, "C=0"); // Collateral Is Zero
        address collateralAddress = _pool.getAssetAddress(account.collateralId);
        _transferIn(collateralAddress, address(_pool), collateralAmount);
        _pool.depositCollateral(subAccountId, collateralAmount);
    }

    function liquidate(
        bytes32 subAccountId,
        uint8 profitAssetId, // only used when !isLong
        uint96 collateralPrice,
        uint96 assetPrice,
        uint96 profitAssetPrice // only used when !isLong
    ) external onlyBroker {
        _pool.liquidate(subAccountId, profitAssetId, collateralPrice, assetPrice, profitAssetPrice);
        // auto withdraw
        (uint96 collateral, , , , ) = _pool.getSubAccount(subAccountId);
        if (collateral > 0) {
            _pool.withdrawAllCollateral(subAccountId);
        }
    }

    function redeemMuxToken(uint8 tokenId, uint96 muxTokenAmount) external {
        Asset memory asset = _pool.getAssetInfo(tokenId);
        _transferIn(asset.muxTokenAddress, address(_pool), muxTokenAmount);
        _pool.redeemMuxToken(_msgSender(), tokenId, muxTokenAmount);
    }

    /**
     * @dev Broker can withdraw brokerGasRebate
     */
    function claimBrokerGasRebate() external onlyBroker returns (uint256 rawAmount) {
        return _pool.claimBrokerGasRebate(msg.sender);
    }

    function _transferIn(
        address tokenAddress,
        address recipient,
        uint256 rawAmount
    ) private {
        if (tokenAddress == address(_weth)) {
            require(msg.value > 0 && msg.value == rawAmount, "VAL"); // transaction VALue SHOULD equal to rawAmount
            _weth.deposit{ value: rawAmount }();
            if (recipient != address(this)) {
                _weth.transfer(recipient, rawAmount);
            }
        } else {
            require(msg.value == 0, "VAL"); // transaction VALue SHOULD be 0
            IERC20Upgradeable(tokenAddress).safeTransferFrom(_msgSender(), recipient, rawAmount);
        }
    }

    function _transferOut(
        address tokenAddress,
        address recipient,
        uint256 rawAmount
    ) internal {
        if (tokenAddress == address(_weth)) {
            _weth.transfer(address(_nativeUnwrapper), rawAmount);
            INativeUnwrapper(_nativeUnwrapper).unwrap(payable(recipient), rawAmount);
        } else {
            IERC20Upgradeable(tokenAddress).safeTransfer(recipient, rawAmount);
        }
    }

    function _blockTimestamp() internal view virtual returns (uint32) {
        return uint32(block.timestamp);
    }

    function _positionOrderDeadline(PositionOrder memory order) internal view returns (uint32) {
        if (order.isMarketOrder()) {
            return order.placeOrderTime + marketOrderTimeout;
        } else {
            return order.placeOrderTime + LibMath.min32(uint32(order.expire10s) * 10, maxLimitOrderTimeout);
        }
    }
}

File 2 of 18 : 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 3 of 18 : Types.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

enum OrderType {
    None, // 0
    PositionOrder, // 1
    LiquidityOrder, // 2
    WithdrawalOrder, // 3
    RebalanceOrder // 4
}

//                                  160        152       144         120        96   72   64               8        0
// +----------------------------------------------------------------------------------+--------------------+--------+
// |              subAccountId 184 (already shifted by 72bits)                        |     orderId 64     | type 8 |
// +----------------------------------+----------+---------+-----------+---------+---------+---------------+--------+
// |              size 96             | profit 8 | flags 8 | unused 24 | exp 24  | time 32 |      enumIndex 64      |
// +----------------------------------+----------+---------+-----------+---------+---------+---------------+--------+
// |             price 96             |                    collateral 96                   |        unused 64       |
// +----------------------------------+----------------------------------------------------+------------------------+
struct PositionOrder {
    uint64 id;
    bytes32 subAccountId; // 160 + 8 + 8 + 8 = 184
    uint96 collateral; // erc20.decimals
    uint96 size; // 1e18
    uint96 price; // 1e18
    uint8 profitTokenId;
    uint8 flags;
    uint32 placeOrderTime; // 1e0
    uint24 expire10s; // 10 seconds. deadline = placeOrderTime + expire * 10
}

//                                  160       152       144          96          72    64              8        0
// +------------------------------------------------------------------+-----------+--------------------+--------+
// |                        account 160                               | unused 24 |     orderId 64     | type 8 |
// +----------------------------------+---------+---------+-----------+-----------+-----+--------------+--------+
// |             amount 96            | asset 8 | flags 8 | unused 48 |     time 32     |      enumIndex 64     |
// +----------------------------------+---------+---------+-----------+-----------------+-----------------------+
// |                                                 unused 256                                                 |
// +------------------------------------------------------------------------------------------------------------+
struct LiquidityOrder {
    uint64 id;
    address account;
    uint96 rawAmount; // erc20.decimals
    uint8 assetId;
    bool isAdding;
    uint32 placeOrderTime; // 1e0
}

//                                  160        152       144          96   72       64               8        0
// +------------------------------------------------------------------------+------------------------+--------+
// |              subAccountId 184 (already shifted by 72bits)              |       orderId 64       | type 8 |
// +----------------------------------+----------+---------+-----------+----+--------+---------------+--------+
// |             amount 96            | profit 8 | flags 8 | unused 48 |   time 32   |      enumIndex 64      |
// +----------------------------------+----------+---------+-----------+-------------+------------------------+
// |                                                unused 256                                                |
// +----------------------------------------------------------------------------------------------------------+
struct WithdrawalOrder {
    uint64 id;
    bytes32 subAccountId; // 160 + 8 + 8 + 8 = 184
    uint96 rawAmount; // erc20.decimals
    uint8 profitTokenId;
    bool isProfit;
    uint32 placeOrderTime; // 1e0
}

//                                          160       96      88      80        72    64                 8        0
// +---------------------------------------------------+-------+-------+----------+----------------------+--------+
// |                  rebalancer 160                   | id0 8 | id1 8 | unused 8 |      orderId 64      | type 8 |
// +------------------------------------------+--------+-------+-------+----------+----+-----------------+--------+
// |                amount0 96                |                amount1 96              |       enumIndex 64       |
// +------------------------------------------+----------------------------------------+--------------------------+
// |                                                 userData 256                                                 |
// +--------------------------------------------------------------------------------------------------------------+
struct RebalanceOrder {
    uint64 id;
    address rebalancer;
    uint8 tokenId0;
    uint8 tokenId1;
    uint96 rawAmount0; // erc20.decimals
    uint96 maxRawAmount1; // erc20.decimals
    bytes32 userData;
}

File 4 of 18 : Admin.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "./Storage.sol";

contract Admin is Storage {
    event AddBroker(address indexed newBroker);
    event RemoveBroker(address indexed broker);
    event AddRebalancer(address indexed newRebalancer);
    event RemoveRebalancer(address indexed rebalancer);
    event SetLiquidityLockPeriod(uint32 oldLockPeriod, uint32 newLockPeriod);
    event SetOrderTimeout(uint32 marketOrderTimeout, uint32 maxLimitOrderTimeout);
    event PausePositionOrder(bool isPaused);
    event PauseLiquidityOrder(bool isPaused);
    event SetMaintainer(address indexed newMaintainer);

    modifier onlyBroker() {
        require(brokers[_msgSender()], "BKR"); // only BroKeR
        _;
    }

    modifier onlyRebalancer() {
        require(rebalancers[_msgSender()], "BAL"); // only reBALancer
        _;
    }

    modifier onlyMaintainer() {
        require(_msgSender() == maintainer || _msgSender() == owner(), "S!M"); // Sender is Not MaiNTainer
        _;
    }

    function addBroker(address newBroker) external onlyOwner {
        require(!brokers[newBroker], "CHG"); // not CHanGed
        brokers[newBroker] = true;
        emit AddBroker(newBroker);
    }

    function removeBroker(address broker) external onlyOwner {
        _removeBroker(broker);
    }

    function renounceBroker() external {
        _removeBroker(msg.sender);
    }

    function addRebalancer(address newRebalancer) external onlyOwner {
        require(!rebalancers[newRebalancer], "CHG"); // not CHanGed
        rebalancers[newRebalancer] = true;
        emit AddRebalancer(newRebalancer);
    }

    function removeRebalancer(address rebalancer) external onlyOwner {
        _removeRebalancer(rebalancer);
    }

    function renounceRebalancer() external {
        _removeRebalancer(msg.sender);
    }

    function setLiquidityLockPeriod(uint32 newLiquidityLockPeriod) external onlyOwner {
        require(newLiquidityLockPeriod <= 86400 * 30, "LCK"); // LoCK time is too large
        require(liquidityLockPeriod != newLiquidityLockPeriod, "CHG"); // setting is not CHanGed
        emit SetLiquidityLockPeriod(liquidityLockPeriod, newLiquidityLockPeriod);
        liquidityLockPeriod = newLiquidityLockPeriod;
    }

    function setOrderTimeout(uint32 marketOrderTimeout_, uint32 maxLimitOrderTimeout_) external onlyOwner {
        require(marketOrderTimeout_ != 0, "T=0"); // Timeout Is Zero
        require(marketOrderTimeout_ / 10 <= type(uint24).max, "T>M"); // Timeout is Larger than Max
        require(maxLimitOrderTimeout_ != 0, "T=0"); // Timeout Is Zero
        require(maxLimitOrderTimeout_ / 10 <= type(uint24).max, "T>M"); // Timeout is Larger than Max
        require(marketOrderTimeout != marketOrderTimeout_ || maxLimitOrderTimeout != maxLimitOrderTimeout_, "CHG"); // setting is not CHanGed
        marketOrderTimeout = marketOrderTimeout_;
        maxLimitOrderTimeout = maxLimitOrderTimeout_;
        emit SetOrderTimeout(marketOrderTimeout_, maxLimitOrderTimeout_);
    }

    function pause(bool isPositionOrderPaused_, bool isLiquidityOrderPaused_) external onlyMaintainer {
        if (isPositionOrderPaused != isPositionOrderPaused_) {
            isPositionOrderPaused = isPositionOrderPaused_;
            emit PausePositionOrder(isPositionOrderPaused_);
        }
        if (isLiquidityOrderPaused != isLiquidityOrderPaused_) {
            isLiquidityOrderPaused = isLiquidityOrderPaused_;
            emit PauseLiquidityOrder(isLiquidityOrderPaused_);
        }
    }

    function setMaintainer(address newMaintainer) external onlyOwner {
        require(maintainer != newMaintainer, "CHG"); // not CHanGed
        maintainer = newMaintainer;
        emit SetMaintainer(newMaintainer);
    }

    function _removeBroker(address broker) internal {
        require(brokers[broker], "CHG"); // not CHanGed
        brokers[broker] = false;
        emit RemoveBroker(broker);
    }

    function _removeRebalancer(address rebalancer) internal {
        require(rebalancers[rebalancer], "CHG"); // not CHanGed
        rebalancers[rebalancer] = false;
        emit RemoveRebalancer(rebalancer);
    }
}

File 5 of 18 : LibSubAccount.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "../core/Types.sol";

/**
 * SubAccountId
 *         96             88        80       72        0
 * +---------+--------------+---------+--------+--------+
 * | Account | collateralId | assetId | isLong | unused |
 * +---------+--------------+---------+--------+--------+
 */
library LibSubAccount {
    bytes32 constant SUB_ACCOUNT_ID_FORBIDDEN_BITS = bytes32(uint256(0xffffffffffffffffff));

    function getSubAccountOwner(bytes32 subAccountId) internal pure returns (address account) {
        account = address(uint160(uint256(subAccountId) >> 96));
    }

    function getSubAccountCollateralId(bytes32 subAccountId) internal pure returns (uint8) {
        return uint8(uint256(subAccountId) >> 88);
    }

    function isLong(bytes32 subAccountId) internal pure returns (bool) {
        return uint8((uint256(subAccountId) >> 72)) > 0;
    }

    struct DecodedSubAccountId {
        address account;
        uint8 collateralId;
        uint8 assetId;
        bool isLong;
    }

    function decodeSubAccountId(bytes32 subAccountId) internal pure returns (DecodedSubAccountId memory decoded) {
        require((subAccountId & SUB_ACCOUNT_ID_FORBIDDEN_BITS) == 0, "AID"); // bad subAccount ID
        decoded.account = address(uint160(uint256(subAccountId) >> 96));
        decoded.collateralId = uint8(uint256(subAccountId) >> 88);
        decoded.assetId = uint8(uint256(subAccountId) >> 80);
        decoded.isLong = uint8((uint256(subAccountId) >> 72)) > 0;
    }
}

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

library LibMath {
    function min(uint96 a, uint96 b) internal pure returns (uint96) {
        return a <= b ? a : b;
    }

    function min32(uint32 a, uint32 b) internal pure returns (uint32) {
        return a <= b ? a : b;
    }

    function max32(uint32 a, uint32 b) internal pure returns (uint32) {
        return a >= b ? a : b;
    }

    function wmul(uint256 a, uint256 b) internal pure returns (uint256) {
        return (a * b) / 1e18;
    }

    function rmul(uint256 a, uint256 b) internal pure returns (uint256) {
        return (a * b) / 1e5;
    }

    function wdiv(uint256 a, uint256 b) internal pure returns (uint256) {
        return (a * 1e18) / b;
    }

    function safeUint32(uint256 n) internal pure returns (uint32) {
        require(n <= type(uint32).max, "O32"); // uint32 Overflow
        return uint32(n);
    }

    function safeUint96(uint256 n) internal pure returns (uint96) {
        require(n <= type(uint96).max, "O96"); // uint96 Overflow
        return uint96(n);
    }

    function safeUint128(uint256 n) internal pure returns (uint128) {
        require(n <= type(uint128).max, "O12"); // uint128 Overflow
        return uint128(n);
    }
}

File 7 of 18 : 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 8 of 18 : 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 9 of 18 : Storage.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../components/SafeOwnableUpgradeable.sol";
import "../interfaces/ILiquidityPool.sol";
import "../interfaces/IWETH9.sol";
import "../interfaces/INativeUnwrapper.sol";
import "../libraries/LibOrder.sol";

contract Storage is Initializable, SafeOwnableUpgradeable {
    bool private _reserved1;
    mapping(address => bool) public brokers;
    ILiquidityPool internal _pool;
    uint64 public nextOrderId;
    LibOrder.OrderList internal _orders;
    IERC20Upgradeable internal _mlp;
    IWETH internal _weth;
    uint32 public liquidityLockPeriod; // 1e0
    INativeUnwrapper public _nativeUnwrapper;
    mapping(address => bool) public rebalancers;
    bool public isPositionOrderPaused;
    bool public isLiquidityOrderPaused;
    uint32 public marketOrderTimeout;
    uint32 public maxLimitOrderTimeout;
    address public maintainer;
    bytes32[44] _gap;

    modifier whenPositionOrderEnabled() {
        require(!isPositionOrderPaused, "POP"); // Position Order Paused
        _;
    }

    modifier whenLiquidityOrderEnabled() {
        require(!isLiquidityOrderPaused, "LOP"); // Liquidity Order Paused
        _;
    }
}

File 10 of 18 : 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 11 of 18 : 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 12 of 18 : ILiquidityPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "../core/Types.sol";

interface ILiquidityPool {
    /////////////////////////////////////////////////////////////////////////////////
    //                                 getters

    function getAssetInfo(uint8 assetId) external view returns (Asset memory);

    function getAllAssetInfo() external view returns (Asset[] memory);

    function getAssetAddress(uint8 assetId) external view returns (address);

    function getLiquidityPoolStorage()
        external
        view
        returns (
            // [0] shortFundingBaseRate8H
            // [1] shortFundingLimitRate8H
            // [2] lastFundingTime
            // [3] fundingInterval
            // [4] liquidityBaseFeeRate
            // [5] liquidityDynamicFeeRate
            // [6] sequence. note: will be 0 after 0xffffffff
            // [7] strictStableDeviation
            uint32[8] memory u32s,
            // [0] mlpPriceLowerBound
            // [1] mlpPriceUpperBound
            uint96[2] memory u96s
        );

    function getSubAccount(bytes32 subAccountId)
        external
        view
        returns (
            uint96 collateral,
            uint96 size,
            uint32 lastIncreasedTime,
            uint96 entryPrice,
            uint128 entryFunding
        );

    /////////////////////////////////////////////////////////////////////////////////
    //                             for Trader / Broker

    function withdrawAllCollateral(bytes32 subAccountId) external;

    /////////////////////////////////////////////////////////////////////////////////
    //                                 only Broker

    function depositCollateral(
        bytes32 subAccountId,
        uint256 rawAmount // NOTE: OrderBook SHOULD transfer rawAmount collateral to LiquidityPool
    ) external;

    function withdrawCollateral(
        bytes32 subAccountId,
        uint256 rawAmount,
        uint96 collateralPrice,
        uint96 assetPrice
    ) external;

    function withdrawProfit(
        bytes32 subAccountId,
        uint256 rawAmount,
        uint8 profitAssetId, // only used when !isLong
        uint96 collateralPrice,
        uint96 assetPrice,
        uint96 profitAssetPrice // only used when !isLong
    ) external;

    /**
     * @dev   Add liquidity
     *
     * @param trader            liquidity provider address
     * @param tokenId           asset.id that added
     * @param rawAmount         asset token amount. decimals = erc20.decimals
     * @param tokenPrice        token price
     * @param mlpPrice          mlp price
     * @param currentAssetValue liquidity USD value of a single asset in all chains (even if tokenId is a stable asset)
     * @param targetAssetValue  weight / Σ weight * total liquidity USD value in all chains
     */
    function addLiquidity(
        address trader,
        uint8 tokenId,
        uint256 rawAmount, // NOTE: OrderBook SHOULD transfer rawAmount collateral to LiquidityPool
        uint96 tokenPrice,
        uint96 mlpPrice,
        uint96 currentAssetValue,
        uint96 targetAssetValue
    ) external;

    /**
     * @dev   Remove liquidity
     *
     * @param trader            liquidity provider address
     * @param mlpAmount         mlp amount
     * @param tokenId           asset.id that removed to
     * @param tokenPrice        token price
     * @param mlpPrice          mlp price
     * @param currentAssetValue liquidity USD value of a single asset in all chains (even if tokenId is a stable asset)
     * @param targetAssetValue  weight / Σ weight * total liquidity USD value in all chains
     */
    function removeLiquidity(
        address trader,
        uint96 mlpAmount, // NOTE: OrderBook SHOULD transfer mlpAmount mlp to LiquidityPool
        uint8 tokenId,
        uint96 tokenPrice,
        uint96 mlpPrice,
        uint96 currentAssetValue,
        uint96 targetAssetValue
    ) external;

    function openPosition(
        bytes32 subAccountId,
        uint96 amount,
        uint96 collateralPrice,
        uint96 assetPrice
    ) external returns (uint96);

    /**
     * @notice Close a position
     *
     * @param  subAccountId     check LibSubAccount.decodeSubAccountId for detail.
     * @param  amount           position size.
     * @param  profitAssetId    for long position (unless asset.useStable is true), ignore this argument;
     *                          for short position, the profit asset should be one of the stable coin.
     * @param  collateralPrice  price of subAccount.collateral.
     * @param  assetPrice       price of subAccount.asset.
     * @param  profitAssetPrice price of profitAssetId. ignore this argument if profitAssetId is ignored.
     */
    function closePosition(
        bytes32 subAccountId,
        uint96 amount,
        uint8 profitAssetId, // only used when !isLong
        uint96 collateralPrice,
        uint96 assetPrice,
        uint96 profitAssetPrice // only used when !isLong
    ) external returns (uint96);

    /**
     * @notice Broker can update funding each [fundingInterval] seconds by specifying utilizations.
     *
     * @param  stableUtilization    Stable coin utilization in all chains
     * @param  unstableTokenIds     All unstable Asset id(s) MUST be passed in order. ex: 1, 2, 5, 6, ...
     * @param  unstableUtilizations Unstable Asset utilizations in all chains
     * @param  unstablePrices       Unstable Asset prices
     */
    function updateFundingState(
        uint32 stableUtilization, // 1e5
        uint8[] calldata unstableTokenIds,
        uint32[] calldata unstableUtilizations, // 1e5
        uint96[] calldata unstablePrices
    ) external;

    function liquidate(
        bytes32 subAccountId,
        uint8 profitAssetId, // only used when !isLong
        uint96 collateralPrice,
        uint96 assetPrice,
        uint96 profitAssetPrice // only used when !isLong
    ) external returns (uint96);

    function redeemMuxToken(
        address trader,
        uint8 tokenId,
        uint96 muxTokenAmount // NOTE: OrderBook SHOULD transfer muxTokenAmount to LiquidityPool
    ) external;

    function rebalance(
        address rebalancer,
        uint8 tokenId0,
        uint8 tokenId1,
        uint96 rawAmount0,
        uint96 maxRawAmount1,
        bytes32 userData,
        uint96 price0,
        uint96 price1
    ) external;

    /**
     * @dev Broker can withdraw brokerGasRebate
     */
    function claimBrokerGasRebate(address receiver) external returns (uint256 rawAmount);

    /////////////////////////////////////////////////////////////////////////////////
    //                            only LiquidityManager

    function transferLiquidityOut(uint8[] memory assetIds, uint256[] memory amounts) external;

    function transferLiquidityIn(uint8[] memory assetIds, uint256[] memory amounts) external;
}

File 13 of 18 : IWETH9.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

interface IWETH {
    function deposit() external payable;

    function transfer(address to, uint256 value) external returns (bool);

    function withdraw(uint256) external;
}

File 14 of 18 : INativeUnwrapper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

interface INativeUnwrapper {
    function unwrap(address payable to, uint256 rawAmount) external;
}

File 15 of 18 : LibOrder.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

import "../orderbook/Types.sol";
import "./LibSubAccount.sol";

library LibOrder {
    // position order flags
    uint8 constant POSITION_OPEN = 0x80; // 0x80 means openPosition; otherwise closePosition
    uint8 constant POSITION_MARKET_ORDER = 0x40; // 0x40 means ignore limitPrice
    uint8 constant POSITION_WITHDRAW_ALL_IF_EMPTY = 0x20; // 0x20 means auto withdraw all collateral if position.size == 0
    uint8 constant POSITION_TRIGGER_ORDER = 0x10; // 0x10 means this is a trigger order (ex: stop-loss order). 0 means this is a limit order (ex: take-profit order)

    // order data[1] SHOULD reserve lower 64bits for enumIndex
    bytes32 constant ENUM_INDEX_BITS = bytes32(uint256(0xffffffffffffffff));

    struct OrderList {
        uint64[] _orderIds;
        mapping(uint64 => bytes32[3]) _orders;
    }

    function add(
        OrderList storage list,
        uint64 orderId,
        bytes32[3] memory order
    ) internal {
        require(!contains(list, orderId), "DUP"); // already seen this orderId
        list._orderIds.push(orderId);
        // The value is stored at length-1, but we add 1 to all indexes
        // and use 0 as a sentinel value
        uint256 enumIndex = list._orderIds.length;
        require(enumIndex <= type(uint64).max, "O64"); // Overflow uint64
        // order data[1] SHOULD reserve lower 64bits for enumIndex
        require((order[1] & ENUM_INDEX_BITS) == 0, "O1F"); // bad Order[1] Field
        order[1] = bytes32(uint256(order[1]) | uint256(enumIndex));
        list._orders[orderId] = order;
    }

    function remove(OrderList storage list, uint64 orderId) internal {
        bytes32[3] storage orderToRemove = list._orders[orderId];
        uint64 enumIndexToRemove = uint64(uint256(orderToRemove[1]));
        require(enumIndexToRemove != 0, "OID"); // orderId is not found
        // swap and pop
        uint256 indexToRemove = enumIndexToRemove - 1;
        uint256 lastIndex = list._orderIds.length - 1;
        if (lastIndex != indexToRemove) {
            uint64 lastOrderId = list._orderIds[lastIndex];
            // move the last orderId
            list._orderIds[indexToRemove] = lastOrderId;
            // replace enumIndex
            bytes32[3] storage lastOrder = list._orders[lastOrderId];
            lastOrder[1] = (lastOrder[1] & (~ENUM_INDEX_BITS)) | bytes32(uint256(enumIndexToRemove));
        }
        list._orderIds.pop();
        delete list._orders[orderId];
    }

    function contains(OrderList storage list, uint64 orderId) internal view returns (bool) {
        bytes32[3] storage order = list._orders[orderId];
        // order data[1] always contains enumIndex
        return order[1] != bytes32(0);
    }

    function length(OrderList storage list) internal view returns (uint256) {
        return list._orderIds.length;
    }

    function at(OrderList storage list, uint256 index) internal view returns (bytes32[3] memory order) {
        require(index < list._orderIds.length, "IDX"); // InDex overflow
        uint64 orderId = list._orderIds[index];
        order = list._orders[orderId];
    }

    function get(OrderList storage list, uint64 orderId) internal view returns (bytes32[3] memory) {
        return list._orders[orderId];
    }

    function getOrderType(bytes32[3] memory orderData) internal pure returns (OrderType) {
        return OrderType(uint8(uint256(orderData[0])));
    }

    function getOrderOwner(bytes32[3] memory orderData) internal pure returns (address) {
        return address(bytes20(orderData[0]));
    }

    // check Types.PositionOrder for schema
    function encodePositionOrder(
        uint64 orderId,
        bytes32 subAccountId,
        uint96 collateral, // erc20.decimals
        uint96 size, // 1e18
        uint96 price, // 1e18
        uint8 profitTokenId,
        uint8 flags,
        uint32 placeOrderTime,
        uint24 expire10s
    ) internal pure returns (bytes32[3] memory data) {
        require((subAccountId & LibSubAccount.SUB_ACCOUNT_ID_FORBIDDEN_BITS) == 0, "AID"); // bad subAccount ID
        data[0] = subAccountId | bytes32(uint256(orderId) << 8) | bytes32(uint256(OrderType.PositionOrder));
        data[1] = bytes32(
            (uint256(size) << 160) |
                (uint256(profitTokenId) << 152) |
                (uint256(flags) << 144) |
                (uint256(expire10s) << 96) |
                (uint256(placeOrderTime) << 64)
        );
        data[2] = bytes32((uint256(price) << 160) | (uint256(collateral) << 64));
    }

    // check Types.PositionOrder for schema
    function decodePositionOrder(bytes32[3] memory data) internal pure returns (PositionOrder memory order) {
        order.subAccountId = bytes32(bytes23(data[0]));
        order.collateral = uint96(bytes12(data[2] << 96));
        order.size = uint96(bytes12(data[1]));
        order.flags = uint8(bytes1(data[1] << 104));
        order.price = uint96(bytes12(data[2]));
        order.profitTokenId = uint8(bytes1(data[1] << 96));
        order.expire10s = uint24(bytes3(data[1] << 136));
        order.placeOrderTime = uint32(bytes4(data[1] << 160));
    }

    // check Types.LiquidityOrder for schema
    function encodeLiquidityOrder(
        uint64 orderId,
        address account,
        uint8 assetId,
        uint96 rawAmount, // erc20.decimals
        bool isAdding,
        uint32 placeOrderTime
    ) internal pure returns (bytes32[3] memory data) {
        uint8 flags = isAdding ? 1 : 0;
        data[0] = bytes32(
            (uint256(uint160(account)) << 96) | (uint256(orderId) << 8) | uint256(OrderType.LiquidityOrder)
        );
        data[1] = bytes32(
            (uint256(rawAmount) << 160) |
                (uint256(assetId) << 152) |
                (uint256(flags) << 144) |
                (uint256(placeOrderTime) << 64)
        );
    }

    // check Types.LiquidityOrder for schema
    function decodeLiquidityOrder(bytes32[3] memory data) internal pure returns (LiquidityOrder memory order) {
        order.account = address(bytes20(data[0]));
        order.rawAmount = uint96(bytes12(data[1]));
        order.assetId = uint8(bytes1(data[1] << 96));
        uint8 flags = uint8(bytes1(data[1] << 104));
        order.isAdding = flags > 0;
        order.placeOrderTime = uint32(bytes4(data[1] << 160));
    }

    // check Types.WithdrawalOrder for schema
    function encodeWithdrawalOrder(
        uint64 orderId,
        bytes32 subAccountId,
        uint96 rawAmount, // erc20.decimals
        uint8 profitTokenId,
        bool isProfit,
        uint32 placeOrderTime
    ) internal pure returns (bytes32[3] memory data) {
        require((subAccountId & LibSubAccount.SUB_ACCOUNT_ID_FORBIDDEN_BITS) == 0, "AID"); // bad subAccount ID
        uint8 flags = isProfit ? 1 : 0;
        data[0] = subAccountId | bytes32(uint256(orderId) << 8) | bytes32(uint256(OrderType.WithdrawalOrder));
        data[1] = bytes32(
            (uint256(rawAmount) << 160) |
                (uint256(profitTokenId) << 152) |
                (uint256(flags) << 144) |
                (uint256(placeOrderTime) << 64)
        );
    }

    // check Types.WithdrawalOrder for schema
    function decodeWithdrawalOrder(bytes32[3] memory data) internal pure returns (WithdrawalOrder memory order) {
        order.subAccountId = bytes32(bytes23(data[0]));
        order.rawAmount = uint96(bytes12(data[1]));
        order.profitTokenId = uint8(bytes1(data[1] << 96));
        uint8 flags = uint8(bytes1(data[1] << 104));
        order.isProfit = flags > 0;
        order.placeOrderTime = uint32(bytes4(data[1] << 160));
    }

    // check Types.RebalanceOrder for schema
    function encodeRebalanceOrder(
        uint64 orderId,
        address rebalancer,
        uint8 tokenId0,
        uint8 tokenId1,
        uint96 rawAmount0, // erc20.decimals
        uint96 maxRawAmount1, // erc20.decimals
        bytes32 userData
    ) internal pure returns (bytes32[3] memory data) {
        data[0] = bytes32(
            (uint256(uint160(rebalancer)) << 96) |
                (uint256(tokenId0) << 88) |
                (uint256(tokenId1) << 80) |
                (uint256(orderId) << 8) |
                uint256(OrderType.RebalanceOrder)
        );
        data[1] = bytes32((uint256(rawAmount0) << 160) | (uint256(maxRawAmount1) << 64));
        data[2] = userData;
    }

    // check Types.RebalanceOrder for schema
    function decodeRebalanceOrder(bytes32[3] memory data) internal pure returns (RebalanceOrder memory order) {
        order.rebalancer = address(bytes20(data[0]));
        order.tokenId0 = uint8(bytes1(data[0] << 160));
        order.tokenId1 = uint8(bytes1(data[0] << 168));
        order.rawAmount0 = uint96(bytes12(data[1]));
        order.maxRawAmount1 = uint96(bytes12(data[1] << 96));
        order.userData = data[2];
    }

    function isOpenPosition(PositionOrder memory order) internal pure returns (bool) {
        return (order.flags & POSITION_OPEN) != 0;
    }

    function isMarketOrder(PositionOrder memory order) internal pure returns (bool) {
        return (order.flags & POSITION_MARKET_ORDER) != 0;
    }

    function isWithdrawIfEmpty(PositionOrder memory order) internal pure returns (bool) {
        return (order.flags & POSITION_WITHDRAW_ALL_IF_EMPTY) != 0;
    }

    function isTriggerOrder(PositionOrder memory order) internal pure returns (bool) {
        return (order.flags & POSITION_TRIGGER_ORDER) != 0;
    }
}

File 16 of 18 : 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 17 of 18 : 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;
}

File 18 of 18 : Types.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.10;

struct LiquidityPoolStorage {
    // slot
    address orderBook;
    // slot
    address mlp;
    // slot
    address liquidityManager;
    // slot
    address weth;
    // slot
    uint128 _reserved1;
    uint32 shortFundingBaseRate8H; // 1e5
    uint32 shortFundingLimitRate8H; // 1e5
    uint32 fundingInterval; // 1e0
    uint32 lastFundingTime; // 1e0
    // slot
    uint32 _reserved2;
    // slot
    Asset[] assets;
    // slot
    mapping(bytes32 => SubAccount) accounts;
    // slot
    mapping(address => bytes32) _reserved3;
    // slot
    address _reserved4;
    uint96 _reserved5;
    // slot
    uint96 mlpPriceLowerBound; // safeguard against mlp price attacks
    uint96 mlpPriceUpperBound; // safeguard against mlp price attacks
    uint32 liquidityBaseFeeRate; // 1e5
    uint32 liquidityDynamicFeeRate; // 1e5
    // slot
    address nativeUnwrapper;
    // a sequence number that changes when LiquidityPoolStorage updated. this helps to keep track the state of LiquidityPool.
    uint32 sequence; // 1e0. note: will be 0 after 0xffffffff
    uint32 strictStableDeviation; // 1e5. strictStable price is 1.0 if in this damping range
    uint32 brokerTransactions; // transaction count for broker gas rebates
    // slot
    address vault;
    uint96 brokerGasRebate; // the number of native tokens for broker gas rebates per transaction
    // slot
    address maintainer;
    bytes32[50] _gap;
}

struct Asset {
    // slot
    // assets with the same symbol in different chains are the same asset. they shares the same muxToken. so debts of the same symbol
    // can be accumulated across chains (see Reader.AssetState.deduct). ex: ERC20(fBNB).symbol should be "BNB", so that BNBs of
    // different chains are the same.
    // since muxToken of all stable coins is the same and is calculated separately (see Reader.ChainState.stableDeduct), stable coin
    // symbol can be different (ex: "USDT", "USDT.e" and "fUSDT").
    bytes32 symbol;
    // slot
    address tokenAddress; // erc20.address
    uint8 id;
    uint8 decimals; // erc20.decimals
    uint56 flags; // a bitset of ASSET_*
    uint24 _flagsPadding;
    // slot
    uint32 initialMarginRate; // 1e5
    uint32 maintenanceMarginRate; // 1e5
    uint32 minProfitRate; // 1e5
    uint32 minProfitTime; // 1e0
    uint32 positionFeeRate; // 1e5
    // note: 96 bits remaining
    // slot
    address referenceOracle;
    uint32 referenceDeviation; // 1e5
    uint8 referenceOracleType;
    uint32 halfSpread; // 1e5
    // note: 24 bits remaining
    // slot
    uint128 _reserved1;
    uint128 _reserved2;
    // slot
    uint96 collectedFee;
    uint32 _reserved3;
    uint96 spotLiquidity;
    // note: 32 bits remaining
    // slot
    uint96 maxLongPositionSize;
    uint96 totalLongPosition;
    // note: 64 bits remaining
    // slot
    uint96 averageLongPrice;
    uint96 maxShortPositionSize;
    // note: 64 bits remaining
    // slot
    uint96 totalShortPosition;
    uint96 averageShortPrice;
    // note: 64 bits remaining
    // slot, less used
    address muxTokenAddress; // muxToken.address. all stable coins share the same muxTokenAddress
    uint32 spotWeight; // 1e0
    uint32 longFundingBaseRate8H; // 1e5
    uint32 longFundingLimitRate8H; // 1e5
    // slot
    uint128 longCumulativeFundingRate; // Σ_t fundingRate_t
    uint128 shortCumulativeFunding; // Σ_t fundingRate_t * indexPrice_t
}

uint32 constant FUNDING_PERIOD = 3600 * 8;

uint56 constant ASSET_IS_STABLE = 0x00000000000001; // is a usdt, usdc, ...
uint56 constant ASSET_CAN_ADD_REMOVE_LIQUIDITY = 0x00000000000002; // can call addLiquidity and removeLiquidity with this token
uint56 constant ASSET_IS_TRADABLE = 0x00000000000100; // allowed to be assetId
uint56 constant ASSET_IS_OPENABLE = 0x00000000010000; // can open position
uint56 constant ASSET_IS_SHORTABLE = 0x00000001000000; // allow shorting this asset
uint56 constant ASSET_USE_STABLE_TOKEN_FOR_PROFIT = 0x00000100000000; // take profit will get stable coin
uint56 constant ASSET_IS_ENABLED = 0x00010000000000; // allowed to be assetId and collateralId
uint56 constant ASSET_IS_STRICT_STABLE = 0x01000000000000; // assetPrice is always 1 unless volatility exceeds strictStableDeviation

struct SubAccount {
    // slot
    uint96 collateral;
    uint96 size;
    uint32 lastIncreasedTime;
    // slot
    uint96 entryPrice;
    uint128 entryFunding; // entry longCumulativeFundingRate for long position. entry shortCumulativeFunding for short position
}

enum ReferenceOracleType {
    None,
    Chainlink
}

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":"AddBroker","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newRebalancer","type":"address"}],"name":"AddRebalancer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"orderId","type":"uint64"},{"indexed":false,"internalType":"enum OrderType","name":"orderType","type":"uint8"},{"indexed":false,"internalType":"bytes32[3]","name":"orderData","type":"bytes32[3]"}],"name":"CancelOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"orderId","type":"uint64"},{"indexed":false,"internalType":"enum OrderType","name":"orderType","type":"uint8"},{"indexed":false,"internalType":"bytes32[3]","name":"orderData","type":"bytes32[3]"}],"name":"FillOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"uint64","name":"orderId","type":"uint64"},{"indexed":false,"internalType":"uint8","name":"assetId","type":"uint8"},{"indexed":false,"internalType":"uint96","name":"rawAmount","type":"uint96"},{"indexed":false,"internalType":"bool","name":"isAdding","type":"bool"}],"name":"NewLiquidityOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"subAccountId","type":"bytes32"},{"indexed":true,"internalType":"uint64","name":"orderId","type":"uint64"},{"indexed":false,"internalType":"uint96","name":"collateral","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"size","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"price","type":"uint96"},{"indexed":false,"internalType":"uint8","name":"profitTokenId","type":"uint8"},{"indexed":false,"internalType":"uint8","name":"flags","type":"uint8"},{"indexed":false,"internalType":"uint32","name":"deadline","type":"uint32"}],"name":"NewPositionOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rebalancer","type":"address"},{"indexed":true,"internalType":"uint64","name":"orderId","type":"uint64"},{"indexed":false,"internalType":"uint8","name":"tokenId0","type":"uint8"},{"indexed":false,"internalType":"uint8","name":"tokenId1","type":"uint8"},{"indexed":false,"internalType":"uint96","name":"rawAmount0","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"maxRawAmount1","type":"uint96"},{"indexed":false,"internalType":"bytes32","name":"userData","type":"bytes32"}],"name":"NewRebalanceOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"subAccountId","type":"bytes32"},{"indexed":true,"internalType":"uint64","name":"orderId","type":"uint64"},{"indexed":false,"internalType":"uint96","name":"rawAmount","type":"uint96"},{"indexed":false,"internalType":"uint8","name":"profitTokenId","type":"uint8"},{"indexed":false,"internalType":"bool","name":"isProfit","type":"bool"}],"name":"NewWithdrawalOrder","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":"bool","name":"isPaused","type":"bool"}],"name":"PauseLiquidityOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PausePositionOrder","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":"RemoveBroker","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rebalancer","type":"address"}],"name":"RemoveRebalancer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"oldLockPeriod","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newLockPeriod","type":"uint32"}],"name":"SetLiquidityLockPeriod","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newMaintainer","type":"address"}],"name":"SetMaintainer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"marketOrderTimeout","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"maxLimitOrderTimeout","type":"uint32"}],"name":"SetOrderTimeout","type":"event"},{"inputs":[],"name":"_nativeUnwrapper","outputs":[{"internalType":"contract INativeUnwrapper","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newBroker","type":"address"}],"name":"addBroker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newRebalancer","type":"address"}],"name":"addRebalancer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"brokers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimBrokerGasRebate","outputs":[{"internalType":"uint256","name":"rawAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"subAccountId","type":"bytes32"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"}],"name":"depositCollateral","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"},{"internalType":"uint96","name":"assetPrice","type":"uint96"},{"internalType":"uint96","name":"mlpPrice","type":"uint96"},{"internalType":"uint96","name":"currentAssetValue","type":"uint96"},{"internalType":"uint96","name":"targetAssetValue","type":"uint96"}],"name":"fillLiquidityOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"},{"internalType":"uint96","name":"collateralPrice","type":"uint96"},{"internalType":"uint96","name":"assetPrice","type":"uint96"},{"internalType":"uint96","name":"profitAssetPrice","type":"uint96"}],"name":"fillPositionOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"},{"internalType":"uint96","name":"price0","type":"uint96"},{"internalType":"uint96","name":"price1","type":"uint96"}],"name":"fillRebalanceOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"},{"internalType":"uint96","name":"collateralPrice","type":"uint96"},{"internalType":"uint96","name":"assetPrice","type":"uint96"},{"internalType":"uint96","name":"profitAssetPrice","type":"uint96"}],"name":"fillWithdrawalOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"orderId","type":"uint64"}],"name":"getOrder","outputs":[{"internalType":"bytes32[3]","name":"","type":"bytes32[3]"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOrderCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"begin","type":"uint256"},{"internalType":"uint256","name":"end","type":"uint256"}],"name":"getOrders","outputs":[{"internalType":"bytes32[3][]","name":"orderArray","type":"bytes32[3][]"},{"internalType":"uint256","name":"totalCount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"mlp","type":"address"},{"internalType":"address","name":"weth","type":"address"},{"internalType":"address","name":"nativeUnwrapper","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isLiquidityOrderPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPositionOrderPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"subAccountId","type":"bytes32"},{"internalType":"uint8","name":"profitAssetId","type":"uint8"},{"internalType":"uint96","name":"collateralPrice","type":"uint96"},{"internalType":"uint96","name":"assetPrice","type":"uint96"},{"internalType":"uint96","name":"profitAssetPrice","type":"uint96"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidityLockPeriod","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maintainer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketOrderTimeout","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLimitOrderTimeout","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextOrderId","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"isPositionOrderPaused_","type":"bool"},{"internalType":"bool","name":"isLiquidityOrderPaused_","type":"bool"}],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"assetId","type":"uint8"},{"internalType":"uint96","name":"rawAmount","type":"uint96"},{"internalType":"bool","name":"isAdding","type":"bool"}],"name":"placeLiquidityOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"subAccountId","type":"bytes32"},{"internalType":"uint96","name":"collateralAmount","type":"uint96"},{"internalType":"uint96","name":"size","type":"uint96"},{"internalType":"uint96","name":"price","type":"uint96"},{"internalType":"uint8","name":"profitTokenId","type":"uint8"},{"internalType":"uint8","name":"flags","type":"uint8"},{"internalType":"uint32","name":"deadline","type":"uint32"}],"name":"placePositionOrder","outputs":[],"stateMutability":"payable","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":"bytes32","name":"userData","type":"bytes32"}],"name":"placeRebalanceOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"subAccountId","type":"bytes32"},{"internalType":"uint96","name":"rawAmount","type":"uint96"},{"internalType":"uint8","name":"profitTokenId","type":"uint8"},{"internalType":"bool","name":"isProfit","type":"bool"}],"name":"placeWithdrawalOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rebalancers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"tokenId","type":"uint8"},{"internalType":"uint96","name":"muxTokenAmount","type":"uint96"}],"name":"redeemMuxToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"broker","type":"address"}],"name":"removeBroker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rebalancer","type":"address"}],"name":"removeRebalancer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceBroker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceRebalancer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newLiquidityLockPeriod","type":"uint32"}],"name":"setLiquidityLockPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newMaintainer","type":"address"}],"name":"setMaintainer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"marketOrderTimeout_","type":"uint32"},{"internalType":"uint32","name":"maxLimitOrderTimeout_","type":"uint32"}],"name":"setOrderTimeout","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":"uint32","name":"stableUtilization","type":"uint32"},{"internalType":"uint8[]","name":"unstableTokenIds","type":"uint8[]"},{"internalType":"uint32[]","name":"unstableUtilizations","type":"uint32[]"},{"internalType":"uint96[]","name":"unstablePrices","type":"uint96[]"}],"name":"updateFundingState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"subAccountId","type":"bytes32"}],"name":"withdrawAllCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50615440806100206000396000f3fe60806040526004361061025c5760003560e01c80636e2027dd11610144578063cdf9d07c116100b6578063ee8f99dc1161007a578063ee8f99dc14610756578063f065ae4914610775578063f2fde38b14610795578063f8c8765e146107b5578063fbb8d4ce146107d5578063fe6facc4146107ea57600080fd5b8063cdf9d07c146106b5578063d0ee758c146106e3578063d99d6f9a14610703578063ddeb509414610723578063dea9b4641461074357600080fd5b80638f72fc77116101085780638f72fc77146105db5780639850d32b1461060957806399a349521461063057806399e4ef5914610650578063a44d57a014610665578063b4b9ef731461069557600080fd5b80636e2027dd1461053e578063715018a614610551578063836cae65146105665780638d0a5fbb146105865780638da5cb5b146105a957600080fd5b80633d491e6f116101dd57806358b09b89116101a157806358b09b89146104755780635ac05a501461049557806360536172146104b557806366874cc5146104ca57806366e10ec6146104fa5780636b811a3c1461051e57600080fd5b80633d491e6f146103ed578063431e5c9d1461040d57806343bc4b9a146104225780634af3e01714610442578063523eb5371461045557600080fd5b8063315dca6e11610224578063315dca6e14610331578063330a4f9d14610351578063337c96b414610389578063340e2d19146103a95780633d0ebb89146103cd57600080fd5b80630c9799191461026157806313ea5d29146102835780631666bcde146102a35780631ad6a870146102d25780632a58b330146102f2575b600080fd5b34801561026d57600080fd5b5061028161027c366004614527565b61080a565b005b34801561028f57600080fd5b5061028161029e366004614527565b6108c2565b3480156102af57600080fd5b50606e546102bd9060ff1681565b60405190151581526020015b60405180910390f35b3480156102de57600080fd5b506102816102ed366004614556565b61098c565b3480156102fe57600080fd5b5060675461031990600160a01b90046001600160401b031681565b6040516001600160401b0390911681526020016102c9565b34801561033d57600080fd5b5061028161034c3660046145bb565b610b87565b34801561035d57600080fd5b50606e546103749062010000900463ffffffff1681565b60405163ffffffff90911681526020016102c9565b34801561039557600080fd5b506102816103a4366004614604565b610dcd565b3480156103b557600080fd5b50606b5461037490600160a01b900463ffffffff1681565b3480156103d957600080fd5b506102816103e8366004614665565b610ed9565b3480156103f957600080fd5b50610281610408366004614720565b610f7f565b34801561041957600080fd5b506102816110a0565b34801561042e57600080fd5b5061028161043d366004614527565b6110ab565b61028161045036600461475c565b6110e1565b34801561046157600080fd5b5061028161047036600461479c565b611293565b34801561048157600080fd5b506102816104903660046147b7565b6116ba565b3480156104a157600080fd5b506102816104b0366004614811565b611d6d565b3480156104c157600080fd5b50610281611ebd565b3480156104d657600080fd5b506102bd6104e5366004614527565b60666020526000908152604090205460ff1681565b34801561050657600080fd5b50606e5461037490600160301b900463ffffffff1681565b34801561052a57600080fd5b50610281610539366004614875565b611f17565b61028161054c36600461488e565b611fb0565b34801561055d57600080fd5b5061028161231f565b34801561057257600080fd5b50610281610581366004614527565b612363565b34801561059257600080fd5b5061059b612412565b6040519081526020016102c9565b3480156105b557600080fd5b506033546001600160a01b03165b6040516001600160a01b0390911681526020016102c9565b3480156105e757600080fd5b506105fb6105f636600461491b565b612422565b6040516102c992919061493d565b34801561061557600080fd5b50606e546105c390600160501b90046001600160a01b031681565b34801561063c57600080fd5b5061028161064b3660046147b7565b612518565b34801561065c57600080fd5b5061059b61279a565b34801561067157600080fd5b506102bd610680366004614527565b606d6020526000908152604090205460ff1681565b3480156106a157600080fd5b506102816106b03660046149ad565b612837565b3480156106c157600080fd5b506106d56106d036600461479c565b612963565b6040516102c9929190614a18565b3480156106ef57600080fd5b506102816106fe366004614a35565b61299f565b34801561070f57600080fd5b5061028161071e366004614527565b612d5b565b34801561072f57600080fd5b5061028161073e366004614aa4565b612d8e565b61028161075136600461491b565b612eab565b34801561076257600080fd5b50606e546102bd90610100900460ff1681565b34801561078157600080fd5b50606c546105c3906001600160a01b031681565b3480156107a157600080fd5b506102816107b0366004614527565b613011565b3480156107c157600080fd5b506102816107d0366004614ad2565b613105565b3480156107e157600080fd5b5061028161323b565b3480156107f657600080fd5b50610281610805366004614b23565b613244565b6033546001600160a01b0316331461083d5760405162461bcd60e51b815260040161083490614b4d565b60405180910390fd5b6001600160a01b0381166000908152606d602052604090205460ff16156108765760405162461bcd60e51b815260040161083490614b82565b6001600160a01b0381166000818152606d6020526040808220805460ff19166001179055517fc5115f53265d15ca7930718dd520cd314285a7f2f0027e59b441f1f33b87b6919190a250565b6033546001600160a01b031633146108ec5760405162461bcd60e51b815260040161083490614b4d565b606e546001600160a01b03828116600160501b9092041614156109215760405162461bcd60e51b815260040161083490614b82565b606e80547fffff0000000000000000000000000000000000000000ffffffffffffffffffff16600160501b6001600160a01b038416908102919091179091556040517f20495ad1c3942659031bc9602fe224bb567644c05306fe5656f04f0c5cd09ef590600090a250565b6033546001600160a01b031633146109b65760405162461bcd60e51b815260040161083490614b4d565b63ffffffff82166109ef5760405162461bcd60e51b81526020600482015260036024820152620543d360ec1b6044820152606401610834565b62ffffff6109fe600a84614bb5565b63ffffffff161115610a385760405162461bcd60e51b8152602060048201526003602482015262543e4d60e81b6044820152606401610834565b63ffffffff8116610a715760405162461bcd60e51b81526020600482015260036024820152620543d360ec1b6044820152606401610834565b62ffffff610a80600a83614bb5565b63ffffffff161115610aba5760405162461bcd60e51b8152602060048201526003602482015262543e4d60e81b6044820152606401610834565b606e5463ffffffff8381166201000090920416141580610aec5750606e5463ffffffff828116600160301b9092041614155b610b085760405162461bcd60e51b815260040161083490614b82565b606e805469ffffffffffffffff000019166201000063ffffffff85811691820269ffffffff000000000000191692909217600160301b928516928302179092556040805192835260208301919091527f0ac6ed41369d4003621c3216eaf4456c865743f8c396285512c18ac78150aaad91015b60405180910390a15050565b3360009081526066602052604090205460ff16610bb65760405162461bcd60e51b815260040161083490614be6565b606e54610100900460ff1615610bf45760405162461bcd60e51b815260206004820152600360248201526204c4f560ec1b6044820152606401610834565b6001600160401b038316600090815260696020526040902060010154610c2c5760405162461bcd60e51b815260040161083490614c03565b6000610c396068856133f7565b9050610c4660688561344c565b6000610c51826135f5565b90506004816004811115610c6757610c67614c20565b14610c845760405162461bcd60e51b815260040161083490614c36565b6040805160e0810182526000808252602080830182815283850183815260608086018581526080870186815260a080890188815260c08a018981528d5190951c968790528c5160581c60ff908116968790528d5160501c1693849052968c01805190911c9182905251891c6001600160601b03908116968790528b8a0151938490526067548a51639eee96df60e01b81526004810197909752602487019590955260448601929092526064850152608484019490945260a483015289831660c483015291881660e4820152935192936001600160a01b0390911692639eee96df926101048084019391929182900301818387803b158015610d8457600080fd5b505af1158015610d98573d6000803e3d6000fd5b505050506000805160206153eb833981519152868385604051610dbd93929190614c53565b60405180910390a1505050505050565b6033546001600160a01b03163314610df75760405162461bcd60e51b815260040161083490614b4d565b62278d008163ffffffff161115610e365760405162461bcd60e51b81526020600482015260036024820152624c434b60e81b6044820152606401610834565b606b5463ffffffff828116600160a01b909204161415610e685760405162461bcd60e51b815260040161083490614b82565b606b546040805163ffffffff600160a01b9093048316815291831660208301527f0c0b8e3bb5e77c750110c5892a4426f766651572fc356dcff0300a53a79771e8910160405180910390a1606b805463ffffffff909216600160a01b0263ffffffff60a01b19909216919091179055565b3360009081526066602052604090205460ff16610f085760405162461bcd60e51b815260040161083490614be6565b606754604051633d0ebb8960e01b81526001600160a01b0390911690633d0ebb8990610f44908a908a908a908a908a908a908a90600401614cdd565b600060405180830381600087803b158015610f5e57600080fd5b505af1158015610f72573d6000803e3d6000fd5b5050505050505050505050565b60675460405163c8c7fe6b60e01b815260ff841660048201526000916001600160a01b03169063c8c7fe6b9060240161040060405180830381865afa158015610fcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff09190614e4d565b610340810151606754919250611018916001600160a01b03166001600160601b038516613614565b6067546001600160a01b03166375eace64336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260ff861660248201526001600160601b0385166044820152606401600060405180830381600087803b15801561108357600080fd5b505af1158015611097573d6000803e3d6000fd5b50505050505050565b6110a9336137ac565b565b6033546001600160a01b031633146110d55760405162461bcd60e51b815260040161083490614b4d565b6110de8161382d565b50565b6001600160601b0382166111075760405162461bcd60e51b81526004016108349061509a565b33811561119a576067546040516316a3636160e11b815260ff861660048201526000916001600160a01b031690632d46c6c290602401602060405180830381865afa15801561115a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061117e91906150b7565b90506111948130866001600160601b0316613614565b506111bb565b6111bb33606a546001600160a01b031690306001600160601b0387166138ae565b60678054600091600160a01b9091046001600160401b03169060146111df836150d4565b91906101000a8154816001600160401b0302191690836001600160401b031602179055509050600061121b82848888886112164290565b613919565b9050611229606883836139a8565b6040805160ff881681526001600160601b03871660208201528515158183015290516001600160401b038416916001600160a01b038616917f66340b656a5a83a68f9bf9206f8b20299c11d9c3c7c5ae3bc6ab4ba12f82927e9181900360600190a3505050505050565b6001600160401b0381166000908152606960205260409020600101546112cb5760405162461bcd60e51b815260040161083490614c03565b60006112d86068836133f7565b90506112e560688361344c565b60006112f2825160601c90565b905060006112ff836135f5565b9050600181600481111561131557611315614c20565b141561146b57600061132684613ae0565b3360009081526066602052604090205490915060ff16156113795761134a81613b97565b63ffffffff164263ffffffff16116113745760405162461bcd60e51b8152600401610834906150fb565b6113a1565b336001600160a01b038416146113a15760405162461bcd60e51b815260040161083490615118565b60c0810151608016151580156113c45750600081604001516001600160601b0316115b156114655760675460208201516000916001600160a01b031690632d46c6c29060581c6040516001600160e01b031960e084901b16815260ff9091166004820152602401602060405180830381865afa158015611425573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144991906150b7565b9050611463818584604001516001600160601b0316613c0f565b505b50611671565b600281600481111561147f5761147f614c20565b141561158257336001600160a01b038316146114ad5760405162461bcd60e51b815260040161083490615118565b60006114b884613d01565b905080608001511561155a5760675460608201516040516316a3636160e11b815260ff90911660048201526000916001600160a01b031690632d46c6c290602401602060405180830381865afa158015611516573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061153a91906150b7565b9050611554818584604001516001600160601b0316613c0f565b50611465565b6040810151606a54611465916001600160a01b039091169085906001600160601b0316613d95565b600381600481111561159657611596614c20565b1415611647573360009081526066602052604090205460ff16156116105760006115bf84613dc5565b606e5460a08201519192506000916115e39162010000900463ffffffff1690615135565b63ffffffff169050804263ffffffff16116114635760405162461bcd60e51b8152600401610834906150fb565b6001600160a01b038216335b6001600160a01b0316146116425760405162461bcd60e51b815260040161083490615118565b611671565b600481600481111561165b5761165b614c20565b141561025c576001600160a01b0382163361161c565b7fe5033f0fc6c1035c36f3d7c2b4278c1d0fc20d165ba0873a0ce56a661e8cf8668461169c856135f5565b856040516116ac93929190614c53565b60405180910390a150505050565b3360009081526066602052604090205460ff166116e95760405162461bcd60e51b815260040161083490614be6565b606e5460ff16156117225760405162461bcd60e51b81526020600482015260036024820152620504f560ec1b6044820152606401610834565b6001600160401b03841660009081526069602052604090206001015461175a5760405162461bcd60e51b815260040161083490614c03565b60006117676068866133f7565b905061177460688661344c565b600061177f826135f5565b9050600181600481111561179557611795614c20565b146117b25760405162461bcd60e51b815260040161083490614c36565b60006117bd83613ae0565b90506117c881613b97565b63ffffffff164263ffffffff1611156117f35760405162461bcd60e51b8152600401610834906150fb565b60006118058260c00151608016151590565b156119da5760408201516001600160601b038116156119395760675460208401516000916001600160a01b031690632d46c6c29060581c6040516001600160e01b031960e084901b16815260ff9091166004820152602401602060405180830381865afa15801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e91906150b7565b6067549091506118c4906001600160a01b0380841691166001600160601b038516613d95565b60675460208501516040516337aa6d1960e21b815260048101919091526001600160601b03841660248201526001600160a01b039091169063dea9b46490604401600060405180830381600087803b15801561191f57600080fd5b505af1158015611933573d6000803e3d6000fd5b50505050505b606754602084015160608501516040516369912dc760e11b815260048101929092526001600160601b039081166024830152808b166044830152891660648201526001600160a01b039091169063d3225b8e906084016020604051808303816000875af11580156119ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119d2919061515d565b915050611c4a565b6067546020830151606084015160a0850151604051639a69721f60e01b815260048101939093526001600160601b03918216602484015260ff166044830152808a1660648301528089166084830152871660a48201526001600160a01b0390911690639a69721f9060c4016020604051808303816000875af1158015611a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a88919061515d565b60408301519091506001600160601b03811615611b23576067546020840151604051634700832960e11b815260048101919091526001600160601b038084166024830152808b166044830152891660648201526001600160a01b0390911690638e01065290608401600060405180830381600087803b158015611b0a57600080fd5b505af1158015611b1e573d6000803e3d6000fd5b505050505b60c083015160201615611c485760675460208401516040516303e9375760e01b815260009283926001600160a01b03909116916303e9375791611b6c9160040190815260200190565b60a060405180830381865afa158015611b89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bad919061517a565b50505091509150806001600160601b03166000148015611bd657506000826001600160601b0316115b15611c45576067546020860151604051631ae0468f60e21b81526001600160a01b0390921691636b811a3c91611c129160040190815260200190565b600060405180830381600087803b158015611c2c57600080fd5b505af1158015611c40573d6000803e3d6000fd5b505050505b50505b505b60c0820151604016611d3a576000611c688360c00151608016151590565b60208401519015159060481c60ff1615151515149050611c8e8360c00151601016151590565b15611c9557155b8015611cec5782608001516001600160601b0316826001600160601b03161115611ce75760405162461bcd60e51b815260206004820152600360248201526213135560ea1b6044820152606401610834565b611d38565b82608001516001600160601b0316826001600160601b03161015611d385760405162461bcd60e51b815260206004820152600360248201526213135560ea1b6044820152606401610834565b505b6000805160206153eb833981519152888486604051611d5b93929190614c53565b60405180910390a15050505050505050565b336000908152606d602052604090205460ff16611db25760405162461bcd60e51b815260206004820152600360248201526210905360ea1b6044820152606401610834565b6001600160601b038316611dd85760405162461bcd60e51b81526004016108349061509a565b606780543391600091600160a01b90046001600160401b0316906014611dfd836150d4565b91906101000a8154816001600160401b0302191690836001600160401b0316021790555090506000611e3482848a8a8a8a8a613e0d565b9050611e42606883836139a8565b6040805160ff8a81168252891660208201526001600160601b0388811682840152871660608201526080810186905290516001600160401b038416916001600160a01b038616917f5c1a7ceefa482bcc616dec79c7a8bb748520ec46eb6d550f10ecf97e70f1c96a9181900360a00190a35050505050505050565b6065546001600160a01b0316336001600160a01b031614611ef05760405162461bcd60e51b815260040161083490615118565b606554611f05906001600160a01b0316613e96565b606580546001600160a01b0319169055565b6000611f2282613ee8565b80519091506001600160a01b03163314611f4e5760405162461bcd60e51b815260040161083490615118565b606754604051631ae0468f60e21b8152600481018490526001600160a01b0390911690636b811a3c90602401600060405180830381600087803b158015611f9457600080fd5b505af1158015611fa8573d6000803e3d6000fd5b505050505050565b6000611fbb88613ee8565b80519091506001600160a01b03163314611fe75760405162461bcd60e51b815260040161083490615118565b6001600160601b0386166120235760405162461bcd60e51b81526020600482015260036024820152620533d360ec1b6044820152606401610834565b600060408416156120aa576001600160601b0386161561206b5760405162461bcd60e51b815260206004820152600360248201526205021360ec1b6044820152606401610834565b63ffffffff8316156120a55760405162461bcd60e51b815260206004820152600360248201526204421360ec1b6044820152606401610834565b612104565b4263ffffffff168363ffffffff16116120eb5760405162461bcd60e51b81526020600482015260036024820152620443c360ec1b6044820152606401610834565b600a6120f742856151ea565b6121019190614bb5565b90505b60ff8516156121445760808416156121445760405162461bcd60e51b815260206004820152600360248201526205421360ec1b6044820152606401610834565b60678054600091600160a01b9091046001600160401b0316906014612168836150d4565b91906101000a8154816001600160401b0302191690836001600160401b03160217905550905062ffffff80168263ffffffff1611156121cf5760405162461bcd60e51b815260206004820152600360248201526211151360ea1b6044820152606401610834565b60006121e2828c8c8c8c8c8c428b613f6b565b90506121f0606883836139a8565b60008a6001600160601b031611801561220b57506080861615155b1561229e5760675460208501516040516316a3636160e11b815260ff90911660048201526000916001600160a01b031690632d46c6c290602401602060405180830381865afa158015612262573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061228691906150b7565b905061229c81308d6001600160601b0316613614565b505b604080516001600160601b038c811682528b811660208301528a168183015260ff89811660608301528816608082015263ffffffff871660a082015290516001600160401b038416918d917eda46badc3d23e4ffbd09bb00128a2274573502fdbb15d233ec3441c01b6af39181900360c00190a35050505050505050505050565b6033546001600160a01b031633146123495760405162461bcd60e51b815260040161083490614b4d565b606580546001600160a01b03191690556110a96000613e96565b6033546001600160a01b0316331461238d5760405162461bcd60e51b815260040161083490614b4d565b6001600160a01b03811660009081526066602052604090205460ff16156123c65760405162461bcd60e51b815260040161083490614b82565b6001600160a01b038116600081815260666020526040808220805460ff19166001179055517f2fcbb5eda85b2352f87cce68063c290996e8cbc17c8f7c25a8b9ba1e59de256c9190a250565b600061241d60685490565b905090565b6060600061242f60685490565b905082841015806124405750808410155b1561244a57612511565b80831115612458578061245a565b825b92506000612468858561520f565b9050806001600160401b0381111561248257612482614d8a565b6040519080825280602002602001820160405280156124bb57816020015b6124a86144a1565b8152602001906001900390816124a05790505b50925060005b8181101561250e576124de6124d68783615226565b606890614040565b8482815181106124f0576124f061523e565b6020026020010181905250808061250690615254565b9150506124c1565b50505b9250929050565b3360009081526066602052604090205460ff166125475760405162461bcd60e51b815260040161083490614be6565b6001600160401b03841660009081526069602052604090206001015461257f5760405162461bcd60e51b815260040161083490614c03565b600061258c6068866133f7565b905061259960688661344c565b60006125a4826135f5565b905060038160048111156125ba576125ba614c20565b146125d75760405162461bcd60e51b815260040161083490614c36565b60006125e283613dc5565b9050606e60029054906101000a900463ffffffff168160a001516126069190615135565b63ffffffff164263ffffffff1611156126315760405162461bcd60e51b8152600401610834906150fb565b8060800151156126df5760675460208201516040808401516060850151915163484289c760e01b815260048101939093526001600160601b03908116602484015260ff909116604483015280891660648301528088166084830152861660a48201526001600160a01b039091169063484289c79060c401600060405180830381600087803b1580156126c257600080fd5b505af11580156126d6573d6000803e3d6000fd5b50505050612768565b60675460208201516040808401519051634700832960e11b815260048101929092526001600160601b0390811660248301528089166044830152871660648201526001600160a01b0390911690638e01065290608401600060405180830381600087803b15801561274f57600080fd5b505af1158015612763573d6000803e3d6000fd5b505050505b6000805160206153eb83398151915287838560405161278993929190614c53565b60405180910390a150505050505050565b3360009081526066602052604081205460ff166127c95760405162461bcd60e51b815260040161083490614be6565b606754604051636bc72faf60e11b81523360048201526001600160a01b039091169063d78e5f5e906024016020604051808303816000875af1158015612813573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061241d919061526f565b60006128438560601c90565b90506001600160a01b038116331461286d5760405162461bcd60e51b815260040161083490615118565b6001600160601b0384166128935760405162461bcd60e51b81526004016108349061509a565b60678054600091600160a01b9091046001600160401b03169060146128b7836150d4565b91906101000a8154816001600160401b0302191690836001600160401b03160217905550905060006128f382888888886128ee4290565b614102565b9050612901606883836139a8565b604080516001600160601b038816815260ff871660208201528515158183015290516001600160401b0384169189917f201d03547a8fd1f2eaa0fda90af89681a6c4dc6a8e495565e5ca6a62b3579cf09181900360600190a350505050505050565b61296b6144a1565b60006129786068846133f7565b6001600160401b038416600090815260696020526040902060010154151591509150915091565b3360009081526066602052604090205460ff166129ce5760405162461bcd60e51b815260040161083490614be6565b606e54610100900460ff1615612a0c5760405162461bcd60e51b815260206004820152600360248201526204c4f560ec1b6044820152606401610834565b6001600160401b038516600090815260696020526040902060010154612a445760405162461bcd60e51b815260040161083490614c03565b6000612a516068876133f7565b9050612a5e60688761344c565b6000612a69826135f5565b90506002816004811115612a7f57612a7f614c20565b14612a9c5760405162461bcd60e51b815260040161083490614c36565b6000612aa783613d01565b9050606b60149054906101000a900463ffffffff168160a00151612acb9190615135565b63ffffffff164263ffffffff161015612b0c5760405162461bcd60e51b81526020600482015260036024820152624c434b60e81b6044820152606401610834565b6040810151608082015115612c5e5760675460608301516040516316a3636160e11b815260ff90911660048201526000916001600160a01b031690632d46c6c290602401602060405180830381865afa158015612b6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b9191906150b7565b606754909150612bb7906001600160a01b0380841691166001600160601b038516613d95565b60675460208401516060850151604051630248b34d60e01b81526001600160a01b03928316600482015260ff90911660248201526001600160601b038086166044830152808d166064830152808c166084830152808b1660a4830152891660c4820152911690630248b34d9060e401600060405180830381600087803b158015612c4057600080fd5b505af1158015612c54573d6000803e3d6000fd5b5050505050612d27565b606754606a54612c84916001600160a01b0391821691166001600160601b038416613d95565b60675460208301516060840151604051637ee92e6d60e11b81526001600160a01b0392831660048201526001600160601b03808616602483015260ff9092166044820152818c166064820152818b166084820152818a1660a482015290881660c482015291169063fdd25cda9060e401600060405180830381600087803b158015612d0e57600080fd5b505af1158015612d22573d6000803e3d6000fd5b505050505b6000805160206153eb833981519152898486604051612d4893929190614c53565b60405180910390a1505050505050505050565b6033546001600160a01b03163314612d855760405162461bcd60e51b815260040161083490614b4d565b6110de816137ac565b606e54600160501b90046001600160a01b0316336001600160a01b03161480612dc157506033546001600160a01b031633145b612df35760405162461bcd60e51b815260206004820152600360248201526253214d60e81b6044820152606401610834565b606e5460ff16151582151514612e4857606e805460ff19168315159081179091556040519081527ff08d1ca9cf739c5ed2fcedf748abbfa8f14006e47f4a0a3805e6ce8ace2411229060200160405180910390a15b606e5460ff61010090910416151581151514612ea757606e80548215156101000261ff00199091161790556040517f1dd885054d26280b4f25ebb658ef23327620ee20f5ad56b33902e87f8ad65bba90610b7b90831515815260200190565b5050565b6000612eb683613ee8565b80519091506001600160a01b03163314612ee25760405162461bcd60e51b815260040161083490615118565b81612f155760405162461bcd60e51b81526020600482015260036024820152620433d360ec1b6044820152606401610834565b60675460208201516040516316a3636160e11b815260ff90911660048201526000916001600160a01b031690632d46c6c290602401602060405180830381865afa158015612f67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f8b91906150b7565b606754909150612fa69082906001600160a01b031685613614565b6067546040516337aa6d1960e21b815260048101869052602481018590526001600160a01b039091169063dea9b46490604401600060405180830381600087803b158015612ff357600080fd5b505af1158015613007573d6000803e3d6000fd5b5050505050505050565b6033546001600160a01b0316331461303b5760405162461bcd60e51b815260040161083490614b4d565b6001600160a01b0381166130775760405162461bcd60e51b815260206004820152600360248201526204f3d360ec1b6044820152606401610834565b6033546001600160a01b03828116911614156130bb5760405162461bcd60e51b81526020600482015260036024820152624f3d4f60e81b6044820152606401610834565b606580546001600160a01b0319166001600160a01b0383169081179091556040517fb501f5dc3610d10a179d924f686fc89ddcdd3abb05afd7a1baeead166b2f122c90600090a250565b600054610100900460ff166131205760005460ff1615613124565b303b155b6131875760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610834565b600054610100900460ff161580156131a9576000805461ffff19166101011790555b6131b161419b565b606780546001600160a01b03199081166001600160a01b0388811691909117909255606a80548216878416179055606b80548216868416179055606c805490911684831617905560335416606e600a6101000a8154816001600160a01b0302191690836001600160a01b031602179055508015613234576000805461ff00191690555b5050505050565b6110a93361382d565b3360009081526066602052604090205460ff166132735760405162461bcd60e51b815260040161083490614be6565b606754604051633f9beb3160e21b81526004810187905260ff861660248201526001600160601b0380861660448301528085166064830152831660848201526001600160a01b039091169063fe6facc49060a4016020604051808303816000875af11580156132e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061330a919061515d565b506067546040516303e9375760e01b8152600481018790526000916001600160a01b0316906303e937579060240160a060405180830381865afa158015613355573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613379919061517a565b5050505090506000816001600160601b03161115611fa857606754604051631ae0468f60e21b8152600481018890526001600160a01b0390911690636b811a3c90602401600060405180830381600087803b1580156133d757600080fd5b505af11580156133eb573d6000803e3d6000fd5b50505050505050505050565b6133ff6144a1565b6001600160401b038216600090815260018401602052604090819020815160608101928390529160039082845b81548152602001906001019080831161342c575050505050905092915050565b6001600160401b0381166000908152600180840160205260408220919082015490506001600160401b0381166134945760405162461bcd60e51b815260040161083490614c03565b60006134a1600183615288565b85546001600160401b039190911691506000906134c09060019061520f565b90508181146135875760008660000182815481106134e0576134e061523e565b90600052602060002090600491828204019190066008029054906101000a90046001600160401b03169050808760000184815481106135215761352161523e565b600091825260208083206004830401805460039093166008026101000a6001600160401b03818102199094169584160294909417909355838116825260018a81019093526040909120919086169067ffffffffffffffff19908301541617816001015550505b8554869080613598576135986152a8565b6000828152602080822060046000199094019384040180546001600160401b03600860038716026101000a810219909116909155929093559087168152600188810190925260408120818155918201819055600290910155611fa8565b805160009060ff16600481111561360e5761360e614c20565b92915050565b606b546001600160a01b03848116911614156137635760003411801561363957508034145b61366b5760405162461bcd60e51b815260206004820152600360248201526215905360ea1b6044820152606401610834565b606b60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156136bb57600080fd5b505af11580156136cf573d6000803e3d6000fd5b505050506001600160a01b0383163014905061375e57606b5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af1158015613738573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061375c91906152be565b505b505050565b34156137975760405162461bcd60e51b815260206004820152600360248201526215905360ea1b6044820152606401610834565b61375e6001600160a01b0384163384846138ae565b6001600160a01b03811660009081526066602052604090205460ff166137e45760405162461bcd60e51b815260040161083490614b82565b6001600160a01b038116600081815260666020526040808220805460ff19169055517fcdf53ae488d66a98f509e3342bdc0a13dee821f05bfb372351346a7a991df7a29190a250565b6001600160a01b0381166000908152606d602052604090205460ff166138655760405162461bcd60e51b815260040161083490614b82565b6001600160a01b0381166000818152606d6020526040808220805460ff19169055517f963257db523ad7beed5ed8d412d9efcfa2ec8b73e3c20c3aaf5b6161f9ec48119190a250565b6040516001600160a01b038085166024830152831660448201526064810182905261375c9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526141ca565b6139216144a1565b60008361392f576000613932565b60015b600889901b68ffffffffffffffff0016606089901b6bffffffffffffffffffffffff19161760021783529050604083901b63ffffffff60401b16609082901b60ff60901b16609888901b60ff60981b1660a088901b6001600160a01b0319161717178260015b6020020152509695505050505050565b6001600160401b0382166000908152600180850160205260409091200154156139f95760405162461bcd60e51b815260206004820152600360248201526204455560ec1b6044820152606401610834565b82546001810184556000848152602090206004820401805460039092166008026101000a6001600160401b038181021990931685841691909102179055835490811115613a6e5760405162461bcd60e51b815260206004820152600360248201526213cd8d60ea1b6044820152606401610834565b60208201516001600160401b031615613aaf5760405162461bcd60e51b81526020600482015260036024820152622798a360e91b6044820152606401610834565b60208083018051831790526001600160401b03841660009081526001860190915260409020613234908360036144bf565b60408051610120810182526000808252602080830182815283850183815260608086018581526080870186815260a080890188815260c08a0189815260e08b018a81526101008c019a8b528d5168ffffffffffffffffff19169098528c8c0180518d1c6001600160601b03169097529b9097018051821c909352825160901c60ff908116909b52935190931c909252815160981c909716909252815190951c62ffffff169091525190911c63ffffffff1690915290565b6000613ba98260c00151604016151590565b15613bcc57606e5460e083015161360e9162010000900463ffffffff1690615135565b613bfb82610100015162ffffff16600a613be691906152db565b606e54600160301b900463ffffffff1661429c565b8260e0015161360e9190615135565b919050565b606b546001600160a01b0384811691161415613ced57606b54606c5460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810184905291169063a9059cbb906044016020604051808303816000875af1158015613c7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9e91906152be565b50606c546040516339f4769360e01b81526001600160a01b03848116600483015260248201849052909116906339f4769390604401600060405180830381600087803b15801561108357600080fd5b61375e6001600160a01b0384168383613d95565b6040805160c08101825260008082526020820181815292820181905260608083018290526080830182905260a08301919091528351901c9091528160015b602002015160a01c604082015260608260016020020151901b60f81c6060820152600060688360016020020151901b60f81c8015156080840152905060a08360016020020151901b60e01c60a083015250919050565b6040516001600160a01b03831660248201526044810182905261375e90849063a9059cbb60e01b906064016138e2565b6040805160c081018252600080825260208201818152928201819052606082018190526080820181905260a0820152825168ffffffffffffffffff1916909152816001613d3f565b613e156144a1565b60089790971b68ffffffffffffffff001660509490941b60ff60501b1660589590951b60ff60581b1660609690961b6bffffffffffffffffffffffff19169590951793909317919091176004178452604091821b6bffffffffffffffffffffffff60401b1660a09190911b6001600160a01b03191617602084015282015290565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60408051608081018252600080825260208201819052918101829052606081019190915268ffffffffffffffffff821615613f355760405162461bcd60e51b815260040161083490615307565b606082811c825260ff605884901c81166020840152605084901c8116604084015260489390931c90921615159181019190915290565b613f736144a1565b68ffffffffffffffffff891615613f9c5760405162461bcd60e51b815260040161083490615307565b600168ffffffffffffffff0060088c901b168a171781600060200201526001600160a01b031960a088901b1660ff60981b609887901b161760ff60901b609086901b161762ffffff60601b606084901b161763ffffffff60401b604085901b161781600160200201526001600160a01b031960a087901b166bffffffffffffffffffffffff60401b60408a901b161781600260200201529998505050505050505050565b6140486144a1565b8254821061407e5760405162461bcd60e51b815260206004820152600360248201526209288b60eb1b6044820152606401610834565b60008360000183815481106140955761409561523e565b6000918252602080832060048304015460039283166008026101000a90046001600160401b03168084526001880190915260409283902083516060810194859052919450909290919082845b8154815260200190600101908083116140e157505050505091505092915050565b61410a6144a1565b68ffffffffffffffffff8616156141335760405162461bcd60e51b815260040161083490615307565b600083614141576000614144565b60015b600889901b68ffffffffffffffff0016881760031783529050604083901b63ffffffff60401b16609082901b60ff60901b16609887901b60ff60981b1660a089901b6001600160a01b031916171717826001613998565b600054610100900460ff166141c25760405162461bcd60e51b815260040161083490615324565b6110a96142c1565b600061421f826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166142f09092919063ffffffff16565b80519091501561375e578080602001905181019061423d91906152be565b61375e5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610834565b60008163ffffffff168363ffffffff1611156142b857816142ba565b825b9392505050565b600054610100900460ff166142e85760405162461bcd60e51b815260040161083490615324565b6110a9614307565b60606142ff8484600085614337565b949350505050565b600054610100900460ff1661432e5760405162461bcd60e51b815260040161083490615324565b6110a933613e96565b6060824710156143985760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610834565b6001600160a01b0385163b6143ef5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610834565b600080866001600160a01b0316858760405161440b919061539b565b60006040518083038185875af1925050503d8060008114614448576040519150601f19603f3d011682016040523d82523d6000602084013e61444d565b606091505b509150915061445d828286614468565b979650505050505050565b606083156144775750816142ba565b8251156144875782518084602001fd5b8160405162461bcd60e51b815260040161083491906153b7565b60405180606001604052806003906020820280368337509192915050565b82600381019282156144ed579160200282015b828111156144ed5782518255916020019190600101906144d2565b506144f99291506144fd565b5090565b5b808211156144f957600081556001016144fe565b6001600160a01b03811681146110de57600080fd5b60006020828403121561453957600080fd5b81356142ba81614512565b63ffffffff811681146110de57600080fd5b6000806040838503121561456957600080fd5b823561457481614544565b9150602083013561458481614544565b809150509250929050565b80356001600160401b0381168114613c0a57600080fd5b6001600160601b03811681146110de57600080fd5b6000806000606084860312156145d057600080fd5b6145d98461458f565b925060208401356145e9816145a6565b915060408401356145f9816145a6565b809150509250925092565b60006020828403121561461657600080fd5b81356142ba81614544565b60008083601f84011261463357600080fd5b5081356001600160401b0381111561464a57600080fd5b6020830191508360208260051b850101111561251157600080fd5b60008060008060008060006080888a03121561468057600080fd5b873561468b81614544565b965060208801356001600160401b03808211156146a757600080fd5b6146b38b838c01614621565b909850965060408a01359150808211156146cc57600080fd5b6146d88b838c01614621565b909650945060608a01359150808211156146f157600080fd5b506146fe8a828b01614621565b989b979a50959850939692959293505050565b60ff811681146110de57600080fd5b6000806040838503121561473357600080fd5b823561473e81614711565b91506020830135614584816145a6565b80151581146110de57600080fd5b60008060006060848603121561477157600080fd5b833561477c81614711565b9250602084013561478c816145a6565b915060408401356145f98161474e565b6000602082840312156147ae57600080fd5b6142ba8261458f565b600080600080608085870312156147cd57600080fd5b6147d68561458f565b935060208501356147e6816145a6565b925060408501356147f6816145a6565b91506060850135614806816145a6565b939692955090935050565b600080600080600060a0868803121561482957600080fd5b853561483481614711565b9450602086013561484481614711565b93506040860135614854816145a6565b92506060860135614864816145a6565b949793965091946080013592915050565b60006020828403121561488757600080fd5b5035919050565b600080600080600080600060e0888a0312156148a957600080fd5b8735965060208801356148bb816145a6565b955060408801356148cb816145a6565b945060608801356148db816145a6565b935060808801356148eb81614711565b925060a08801356148fb81614711565b915060c088013561490b81614544565b8091505092959891949750929550565b6000806040838503121561492e57600080fd5b50508035926020909101359150565b6040808252835190820181905260009060609081840190602080880185805b8481101561499957825186835b600381101561498657825182529186019190860190600101614969565b505050948601949183019160010161495c565b505050949094019490945250919392505050565b600080600080608085870312156149c357600080fd5b8435935060208501356149d5816145a6565b925060408501356149e581614711565b915060608501356148068161474e565b8060005b600381101561375c5781518452602093840193909101906001016149f9565b60808101614a2682856149f5565b82151560608301529392505050565b600080600080600060a08688031215614a4d57600080fd5b614a568661458f565b94506020860135614a66816145a6565b93506040860135614a76816145a6565b92506060860135614a86816145a6565b91506080860135614a96816145a6565b809150509295509295909350565b60008060408385031215614ab757600080fd5b8235614ac28161474e565b915060208301356145848161474e565b60008060008060808587031215614ae857600080fd5b8435614af381614512565b93506020850135614b0381614512565b92506040850135614b1381614512565b9150606085013561480681614512565b600080600080600060a08688031215614b3b57600080fd5b853594506020860135614a6681614711565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526003908201526243484760e81b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600063ffffffff80841680614bda57634e487b7160e01b600052601260045260246000fd5b92169190910492915050565b6020808252600390820152622125a960e91b604082015260600190565b60208082526003908201526213d25160ea1b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b60208082526003908201526205459560ec1b604082015260600190565b6001600160401b038416815260a0810160058410614c8157634e487b7160e01b600052602160045260246000fd5b8360208301526142ff60408301846149f5565b8183526000602080850194508260005b85811015614cd2578135614cb7816145a6565b6001600160601b031687529582019590820190600101614ca4565b509495945050505050565b63ffffffff888116825260806020808401829052908301889052600091899160a08501845b8b811015614d2a578435614d1581614711565b60ff1682529382019390820190600101614d02565b508581036040870152888152810192508860005b89811015614d65578135614d5181614544565b841685529382019390820190600101614d3e565b505050508281036060840152614d7c818587614c94565b9a9950505050505050505050565b634e487b7160e01b600052604160045260246000fd5b60405161040081016001600160401b0381118282101715614dd157634e487b7160e01b600052604160045260246000fd5b60405290565b8051613c0a81614512565b8051613c0a81614711565b805166ffffffffffffff81168114613c0a57600080fd5b805162ffffff81168114613c0a57600080fd5b8051613c0a81614544565b80516fffffffffffffffffffffffffffffffff81168114613c0a57600080fd5b8051613c0a816145a6565b60006104008284031215614e6057600080fd5b614e68614da0565b82518152614e7860208401614dd7565b6020820152614e8960408401614de2565b6040820152614e9a60608401614de2565b6060820152614eab60808401614ded565b6080820152614ebc60a08401614e04565b60a0820152614ecd60c08401614e17565b60c0820152614ede60e08401614e17565b60e0820152610100614ef1818501614e17565b90820152610120614f03848201614e17565b90820152610140614f15848201614e17565b90820152610160614f27848201614dd7565b90820152610180614f39848201614e17565b908201526101a0614f4b848201614de2565b908201526101c0614f5d848201614e17565b908201526101e0614f6f848201614e22565b90820152610200614f81848201614e22565b90820152610220614f93848201614e42565b90820152610240614fa5848201614e17565b90820152610260614fb7848201614e42565b90820152610280614fc9848201614e42565b908201526102a0614fdb848201614e42565b908201526102c0614fed848201614e42565b908201526102e0614fff848201614e42565b90820152610300615011848201614e42565b90820152610320615023848201614e42565b90820152610340615035848201614dd7565b90820152610360615047848201614e17565b90820152610380615059848201614e17565b908201526103a061506b848201614e17565b908201526103c061507d848201614e22565b908201526103e061508f848201614e22565b908201529392505050565b6020808252600390820152620413d360ec1b604082015260600190565b6000602082840312156150c957600080fd5b81516142ba81614512565b60006001600160401b03808316818114156150f1576150f1614b9f565b6001019392505050565b60208082526003908201526204558560ec1b604082015260600190565b60208082526003908201526214d39160ea1b604082015260600190565b600063ffffffff80831681851680830382111561515457615154614b9f565b01949350505050565b60006020828403121561516f57600080fd5b81516142ba816145a6565b600080600080600060a0868803121561519257600080fd5b855161519d816145a6565b60208701519095506151ae816145a6565b60408701519094506151bf81614544565b60608701519093506151d0816145a6565b91506151de60808701614e22565b90509295509295909350565b600063ffffffff8381169083168181101561520757615207614b9f565b039392505050565b60008282101561522157615221614b9f565b500390565b6000821982111561523957615239614b9f565b500190565b634e487b7160e01b600052603260045260246000fd5b600060001982141561526857615268614b9f565b5060010190565b60006020828403121561528157600080fd5b5051919050565b60006001600160401b038381169083168181101561520757615207614b9f565b634e487b7160e01b600052603160045260246000fd5b6000602082840312156152d057600080fd5b81516142ba8161474e565b600063ffffffff808316818516818304811182151516156152fe576152fe614b9f565b02949350505050565b60208082526003908201526210525160ea1b604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b8381101561538a578181015183820152602001615372565b8381111561375c5750506000910152565b600082516153ad81846020870161536f565b9190910192915050565b60208152600082518060208401526153d681604085016020870161536f565b601f01601f1916919091016040019291505056fe6204728db10730656ada9f8ce5b258b0d97dc6ac8e8a101ff4b905c3c9cc7dc5a2646970667358221220b73d56d3e4d17ba5dbaa2ae4cd838de5395c525de1c78a4d508aa87fca00de7f64736f6c634300080a0033

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.