Contract 0x34bc1b87f60e0a30c0e24FD7Abada70436c71406 3

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x12f4b0917a9e118db9c6a3e726e9eab76016ce88b29d61b9bf96f061f2de9c110x60e0604047653632022-09-23 11:02:2968 days 19 hrs ago0xc802a5a140224ed72e7c821f637c1e5759744045 IN  Create: LimitOrderManager0 CRO19.7557753314970
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
LimitOrderManager

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 100 runs

Other Settings:
default evmVersion
File 1 of 11 : LimitOrderManager.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./core/interfaces/IiZiSwapCallback.sol";
import "./core/interfaces/IiZiSwapFactory.sol";
import "./core/interfaces/IiZiSwapPool.sol";

import "./libraries/MulDivMath.sol";
import "./libraries/TwoPower.sol";
import "./libraries/LogPowMath.sol";
import "./libraries/LimOrder.sol";
import "./libraries/LimOrderCircularQueue.sol";

import "./base/base.sol";

contract LimitOrderManager is Base, IiZiSwapAddLimOrderCallback {

    using LimOrderCircularQueue for LimOrderCircularQueue.Queue;

    /// @notice Emitted when user successfully create an limit order
    /// @param pool address of swap pool
    /// @param point point (price) of this limit order
    /// @param user address of user
    /// @param amount amount of token ready to sell
    /// @param sellingRemain amount of selling token remained after successfully create this limit order
    /// @param earn amount of acquired token after successfully create this limit order
    /// @param sellXEaryY true if this order sell tokenX, false if sell tokenY
    event NewLimitOrder(
        address pool,
        int24 point,
        address user,
        uint128 amount,
        uint128 sellingRemain,
        uint128 earn,
        bool sellXEaryY
    );
    /// @notice Emitted when user dec or update his limit order
    /// @param pool address of swap pool
    /// @param point point (price) of this limit order
    /// @param user address of user
    /// @param sold amount of token sold from last claim to now
    /// @param earn amount of token earned from last claim to now
    /// @param sellXEaryY true if sell tokenX, false if sell tokenY
    event Claim(
        address pool,
        int24 point,
        address user,
        uint128 sold,
        uint128 earn,
        bool sellXEaryY
    );
    // max-poolId in poolIds, poolId starts from 1
    uint128 private maxPoolId = 1;

    // owners of limit order
    mapping(uint256 =>address) public sellers;
    
    struct PoolMeta {
        address tokenX;
        address tokenY;
        uint24 fee;
    }

    // mapping from pool id to pool's meta info
    mapping(uint128 =>PoolMeta) public poolMetas;

    // mapping from pool id to pool address
    mapping(uint128 =>address) public poolAddrs;

    // mapping from pool address to poolid
    mapping(address =>uint128) public poolIds;

    // seller's active order id
    mapping(address => LimOrder[]) private addr2ActiveOrder;
    // seller's canceled or finished order id
    mapping(address => LimOrderCircularQueue.Queue) private addr2DeactiveOrder;

    // maximum number of active order per user
    // TODO: 
    //   currently we used a fixed number of storage space. A better way is to allow user to expand it.
    //   Otherwise, the first 300 orders need more gas for storage.
    uint256 public immutable DEACTIVE_ORDER_LIM = 300;

    // callback data passed through iZiSwapPool#addLimOrderWithX(Y) to the callback
    struct LimCallbackData {
        // tokenX of swap pool
        address tokenX;
        // tokenY of swap pool
        address tokenY;
        // fee amount of swap pool
        uint24 fee;
        // the address who provides token to sell
        address payer;
    }

    modifier checkActive(uint256 lIdx) {
        require(addr2ActiveOrder[msg.sender].length > lIdx, 'Out Of Length!');
        require(addr2ActiveOrder[msg.sender][lIdx].active, 'Not Active!');
        _;
    }

    /// @notice Constructor to create this contract.
    /// @param factory address of iZiSwapFactory
    /// @param weth address of WETH token
    constructor( address factory, address weth ) Base(factory, weth) {}

    /// @notice Callback for add limit order, in order to deposit corresponding tokens
    /// @param x amount of tokenX need to pay from miner
    /// @param y amount of tokenY need to pay from miner
    /// @param data encoded LimCallbackData
    function payCallback(
        uint256 x,
        uint256 y,
        bytes calldata data
    ) external override {
        LimCallbackData memory dt = abi.decode(data, (LimCallbackData));
        verify(dt.tokenX, dt.tokenY, dt.fee);
        if (x > 0) {
            pay(dt.tokenX, dt.payer, msg.sender, x);
        }
        if (y > 0) {
            pay(dt.tokenY, dt.payer, msg.sender, y);
        }
    }

    function limOrderKey(address miner, int24 pt) internal pure returns(bytes32) {
        return keccak256(abi.encodePacked(miner, pt));
    }

    function cachePoolKey(address pool, PoolMeta memory meta) private returns (uint128 poolId) {
        poolId = poolIds[pool];
        if (poolId == 0) {
            poolIds[pool] = (poolId = maxPoolId++);
            poolMetas[poolId] = meta;
            poolAddrs[poolId] = pool;
        }
    }

    function getEarnX(address pool, bytes32 key) private view returns(uint256, uint128, uint128) {
        (uint256 lastAccEarn, , , uint128 earn, uint128 legacyEarn, ) = IiZiSwapPool(pool).userEarnX(key);
        return (lastAccEarn, earn, legacyEarn);
    }

    function getEarnX(address pool, address miner, int24 pt) private view returns(uint256 accEarn, uint128 earn, uint128 legacyEarn) {
        (accEarn, earn, legacyEarn) = getEarnX(pool, limOrderKey(miner, pt));
    }

    function getEarnY(address pool, bytes32 key) private view returns(uint256, uint128, uint128) {
        (uint256 lastAccEarn, , , uint128 earn, uint128 legacyEarn, ) = IiZiSwapPool(pool).userEarnY(key);
        return (lastAccEarn, earn, legacyEarn);
    }

    function getEarnY(address pool, address miner, int24 pt) private view returns(uint256 accEarn, uint128 earn, uint128 legacyEarn) {
        (accEarn, earn, legacyEarn) = getEarnY(pool, limOrderKey(miner, pt));
    }

    function getEarn(address pool, address miner, int24 pt, bool sellXEarnY) private view returns(uint256 accEarn, uint128 earn, uint128 legacyEarn) {
        if (sellXEarnY) {
            (accEarn, earn, legacyEarn) = getEarnY(pool, limOrderKey(miner, pt));
        } else {
            (accEarn, earn, legacyEarn) = getEarnX(pool, limOrderKey(miner, pt));
        }
    }

    /// parameters when calling newLimOrder, grouped together to avoid stake too deep
    struct AddLimOrderParam {
        // tokenX of swap pool
        address tokenX;
        // tokenY of swap pool
        address tokenY;
        // fee amount of swap pool
        uint24 fee;
        // on which point to add limit order
        int24 pt;
        // amount of token to sell
        uint128 amount;
        // sell tokenX or sell tokenY
        bool sellXEarnY;

        uint256 deadline;
    }

    function _addLimOrder(
        address pool, AddLimOrderParam memory addLimitOrderParam
    ) private returns (uint128 order, uint128 acquire) {
        if (addLimitOrderParam.sellXEarnY) {
            (order, acquire) = IiZiSwapPool(pool).addLimOrderWithX(
                address(this), addLimitOrderParam.pt, addLimitOrderParam.amount,
                abi.encode(LimCallbackData({tokenX: addLimitOrderParam.tokenX, tokenY: addLimitOrderParam.tokenY, fee: addLimitOrderParam.fee, payer: msg.sender}))
            );
        } else {
            (order, acquire) = IiZiSwapPool(pool).addLimOrderWithY(
                address(this), addLimitOrderParam.pt, addLimitOrderParam.amount,
                abi.encode(LimCallbackData({tokenX: addLimitOrderParam.tokenX, tokenY: addLimitOrderParam.tokenY, fee: addLimitOrderParam.fee, payer: msg.sender}))
            );
        }
    }

    /// @notice Create a limit order for recipient.
    /// @param idx slot in the addr2ActiveOrder[msg.sender]
    /// @param addLimitOrderParam describe params of added limit order, see AddLimOrderParam for more
    /// @return orderAmount actual amount of token added in limit order
    /// @return acquire amount of tokenY acquired if there is a limit order to sell the other token before adding
    function newLimOrder(
        uint256 idx,
        AddLimOrderParam calldata addLimitOrderParam
    ) external payable checkDeadline(addLimitOrderParam.deadline) returns (uint128 orderAmount, uint128 acquire) {
        require(addLimitOrderParam.tokenX < addLimitOrderParam.tokenY, 'x<y');

        address pool = IiZiSwapFactory(factory).pool(addLimitOrderParam.tokenX, addLimitOrderParam.tokenY, addLimitOrderParam.fee);
        (orderAmount, acquire) = _addLimOrder(pool, addLimitOrderParam);
        (uint256 accEarn, , ) = getEarn(pool, address(this), addLimitOrderParam.pt, addLimitOrderParam.sellXEarnY);
        uint128 poolId = cachePoolKey(pool, PoolMeta({tokenX: addLimitOrderParam.tokenX, tokenY: addLimitOrderParam.tokenY, fee: addLimitOrderParam.fee}));
        LimOrder[] storage limOrders = addr2ActiveOrder[msg.sender];
        if (idx < limOrders.length) {
            // replace
            require(limOrders[idx].active == false, 'active conflict!');
            limOrders[idx] = LimOrder({
                pt: addLimitOrderParam.pt,
                amount: addLimitOrderParam.amount,
                sellingRemain: orderAmount,
                accSellingDec: 0,
                sellingDec: 0,
                earn: acquire,
                lastAccEarn: accEarn,
                poolId: poolId,
                sellXEarnY: addLimitOrderParam.sellXEarnY,
                timestamp: uint128(block.timestamp),
                active: true
            });
        } else {
            limOrders.push(LimOrder({
                pt: addLimitOrderParam.pt,
                amount: addLimitOrderParam.amount,
                sellingRemain: orderAmount,
                accSellingDec: 0,
                sellingDec: 0,
                earn: acquire,
                lastAccEarn: accEarn,
                poolId: poolId,
                sellXEarnY: addLimitOrderParam.sellXEarnY,
                timestamp: uint128(block.timestamp),
                active: true
            }));
        }
        emit NewLimitOrder(pool, addLimitOrderParam.pt, msg.sender, addLimitOrderParam.amount, orderAmount, acquire, addLimitOrderParam.sellXEarnY);
    }

    /// @notice Compute max amount of earned token the seller can claim.
    /// @param lastAccEarn total amount of earned token of all users on this point before last update of this limit order
    /// @param accEarn total amount of earned token of all users on this point now
    /// @param earnRemain total amount of unclaimed earned token of all users on this point
    /// @return earnLim max amount of earned token the seller can claim
    function getEarnLim(uint256 lastAccEarn, uint256 accEarn, uint128 earnRemain) private pure returns(uint128 earnLim) {
        require(accEarn >= lastAccEarn, "AEO");
        uint256 earnLim256 = accEarn - lastAccEarn;
        if (earnLim256 > earnRemain) {
            earnLim256 = earnRemain;
        }
        earnLim = uint128(earnLim256);
    }

    /// @notice Compute amount of earned token and amount of sold token for a limit order as much as possible.
    /// @param sqrtPrice_96 a 96 bit fixpoint number to describe sqrt(price) of pool
    /// @param earnLim max amount of earned token computed by getEarnLim(...)
    /// @param sellingRemain amount of token before exchange in the limit order
    /// @param isEarnY direction of the limit order (sell Y or sell tokenY)
    /// @return earn amount of earned token this limit order can claim
    /// @return sold amount of sold token which will be minused from sellingRemain
    function getEarnSold(
        uint160 sqrtPrice_96,
        uint128 earnLim,
        uint128 sellingRemain,
        bool isEarnY
    ) private pure returns (uint128 earn, uint128 sold) {
        earn = earnLim;
        uint256 sold256;
        if (isEarnY) {
            uint256 l = MulDivMath.mulDivCeil(earn, TwoPower.pow96, sqrtPrice_96);
            sold256 = MulDivMath.mulDivCeil(l, TwoPower.pow96, sqrtPrice_96);
        } else {
            uint256 l = MulDivMath.mulDivCeil(earn, sqrtPrice_96, TwoPower.pow96);
            sold256 = MulDivMath.mulDivCeil(l, sqrtPrice_96, TwoPower.pow96);
        }
        if (sold256 > sellingRemain) {
            sold256 = sellingRemain;
            if (isEarnY) {
                uint256 l = MulDivMath.mulDivFloor(sold256, sqrtPrice_96, TwoPower.pow96);
                earn = uint128(MulDivMath.mulDivFloor(l, sqrtPrice_96, TwoPower.pow96));
            } else {
                uint256 l = MulDivMath.mulDivFloor(sold256, TwoPower.pow96, sqrtPrice_96);
                earn = uint128(MulDivMath.mulDivFloor(l, TwoPower.pow96, sqrtPrice_96));
            }
        }
        sold = uint128(sold256);
    }

    /// @notice Compute amount of earned token for a legacy order
    ///    an limit order we call it 'legacy' if it together with other limit order of same
    ///    direction and same point on the pool is cleared during one time of exchanging.
    ///    if an limit order is convinced to be 'legacy', we should mark it as 'sold out',
    ///    etc, transform all its remained selling token to earned token.
    /// @param sqrtPrice_96 a 96 bit fixpoint number to describe sqrt(price) of pool
    /// @param earnLim remained amount of legacy part of earnings from corresponding limit order in core contract
    ///    corresponding limit order is an aggregated limit order owned by this contract at same point
    /// @param sellingRemain amount of token before exchange in the limit order
    /// @param isEarnY direction of the limit order (sell Y or sell tokenY)
    /// @return earn amount of earned token this limit order can claim
    function getLegacyEarn(
        uint160 sqrtPrice_96,
        uint128 earnLim,
        uint128 sellingRemain,
        bool isEarnY
    ) private pure returns (uint128 earn) {
        uint256 sold256 = sellingRemain;
        if (isEarnY) {
            uint256 l = MulDivMath.mulDivFloor(sold256, sqrtPrice_96, TwoPower.pow96);
            earn = uint128(MulDivMath.mulDivFloor(l, sqrtPrice_96, TwoPower.pow96));
        } else {
            uint256 l = MulDivMath.mulDivFloor(sold256, TwoPower.pow96, sqrtPrice_96);
            earn = uint128(MulDivMath.mulDivFloor(l, TwoPower.pow96, sqrtPrice_96));
        }
        if (earn > earnLim) {
            earn = earnLim;
        }
    }

    /// @notice assign some amount of earned token from earnings of corresponding limit order in core contract
    ///    to current user (msg.sender)
    ///    corresponding limit order is an aggregated limit order owned by this contract at same point
    /// @param pool swap pool address
    /// @param pt point (price) of limit order
    /// @param amount amount of legacy or unlegacy earned token to assgin from core's aggregated limit order
    /// @param isEarnY direction of the limit order (sell Y or sell tokenY)
    /// @param fromLegacy true for legacy order false for unlegacy
    /// @return actualAssign actual earned token assgiend from core
    function assignLimOrderEarn(
        address pool, int24 pt, uint128 amount, bool isEarnY, bool fromLegacy
    ) private returns(uint128 actualAssign) {
        if (isEarnY) {
            actualAssign = IiZiSwapPool(pool).assignLimOrderEarnY(pt, amount, fromLegacy);
        } else {
            actualAssign = IiZiSwapPool(pool).assignLimOrderEarnX(pt, amount, fromLegacy);
        }
    }

    /// @notice Update a limit order to claim earned tokens as much as possible.
    /// @param order the order to update, see LimOrder for more
    /// @param pool address of swap pool
    /// @return earn amount of earned token this limit order can claim
    function _updateOrder(
        LimOrder storage order,
        address pool
    ) private returns (uint128 earn) {
        uint256 legacyAccEarn;
        if (order.sellXEarnY) {
            (, legacyAccEarn) = IiZiSwapPool(pool).decLimOrderWithX(order.pt, 0);
        } else {
            (, legacyAccEarn) = IiZiSwapPool(pool).decLimOrderWithY(order.pt, 0);
        }
        uint128 sold;
        uint160 sqrtPrice_96 = LogPowMath.getSqrtPrice(order.pt);
        (uint256 accEarn, uint128 earnLim, uint128 legacyEarnLim) = getEarn(pool, address(this), order.pt, order.sellXEarnY);
        if (order.lastAccEarn < legacyAccEarn) {
            earn = getLegacyEarn(sqrtPrice_96, legacyEarnLim, order.sellingRemain, order.sellXEarnY);
            earn = assignLimOrderEarn(pool, order.pt, earn, order.sellXEarnY, true);
            sold = order.sellingRemain;
            order.earn = order.earn + earn;
            order.sellingRemain = 0;
        } else {
            earnLim = getEarnLim(order.lastAccEarn, accEarn, earnLim);
            (earn, sold) = getEarnSold(sqrtPrice_96, earnLim, order.sellingRemain, order.sellXEarnY);
            earn = assignLimOrderEarn(pool, order.pt, earn, order.sellXEarnY, false);
            order.earn = order.earn + earn;
            order.sellingRemain = order.sellingRemain - sold;
        }
        order.lastAccEarn = accEarn;
        emit Claim(pool, order.pt, msg.sender, sold, earn, order.sellXEarnY);
    }

    /// @notice Update a limit order to claim earned tokens as much as possible.
    /// @param orderIdx idx of order to update
    /// @return earn amount of earned token this limit order can claim
    function updateOrder(
        uint256 orderIdx
    ) external checkActive(orderIdx) returns (uint256 earn) {
        LimOrder storage order = addr2ActiveOrder[msg.sender][orderIdx];
        address pool = poolAddrs[order.poolId];
        earn = _updateOrder(order, pool);
    }

    /// @notice Decrease amount of selling-token of a limit order.
    /// @param orderIdx point of seller's limit order
    /// @param amount max amount of selling-token to decrease
    /// @param deadline deadline timestamp of transaction
    /// @return actualDelta actual amount of selling-token decreased
    function decLimOrder(
        uint256 orderIdx,
        uint128 amount,
        uint256 deadline
    ) external checkActive(orderIdx) checkDeadline(deadline) returns (uint128 actualDelta) {
        require(amount > 0, "A0");
        LimOrder storage order = addr2ActiveOrder[msg.sender][orderIdx];
        address pool = poolAddrs[order.poolId];
        // update order first
        _updateOrder(order, pool);
        // now dec
        actualDelta = amount;
        if (actualDelta > order.sellingRemain) {
            actualDelta = uint128(order.sellingRemain);
        }
        uint128 actualDeltaRefund;
        if (order.sellXEarnY) {
            (actualDeltaRefund, ) = IiZiSwapPool(pool).decLimOrderWithX(order.pt, actualDelta);
        } else {
            (actualDeltaRefund, ) = IiZiSwapPool(pool).decLimOrderWithY(order.pt, actualDelta);
        }
        // actualDeltaRefund may be less than actualDelta
        // but we still minus actualDelta in sellingRemain, and only add actualDeltaRefund to sellingDec
        // because if actualDeltaRefund < actualDelta
        // then other users cannot buy from this limit order any more
        // and also, the seller cannot fetch back more than actualDeltaRefund from swap pool >_<
        // but fortunately, actualDeltaRefund < actualDelta only happens after swap on this limit order
        // and also, actualDelta - actualDeltaRefund is a very small deviation
        order.sellingRemain -= actualDelta;
        order.sellingDec += actualDeltaRefund;
        order.accSellingDec += actualDeltaRefund;
    }

    /// @notice Collect earned or decreased token from a limit order.
    /// @param recipient address to benefit
    /// @param orderIdx idx of limit order
    /// @param collectDec max amount of decreased selling token to collect
    /// @param collectEarn max amount of earned token to collect
    /// @return actualCollectDec actual amount of decresed selling token collected
    /// @return actualCollectEarn actual amount of earned token collected
    function collectLimOrder(
        address recipient,
        uint256 orderIdx,
        uint128 collectDec,
        uint128 collectEarn
    ) external checkActive(orderIdx) returns (uint128 actualCollectDec, uint128 actualCollectEarn) {
        LimOrder storage order = addr2ActiveOrder[msg.sender][orderIdx];
        address pool = poolAddrs[order.poolId];
        // update order first
        _updateOrder(order, pool);
        // now collect
        actualCollectDec = collectDec;
        if (actualCollectDec > order.sellingDec) {
            actualCollectDec = order.sellingDec;
        }
        actualCollectEarn = collectEarn;
        if (actualCollectEarn > order.earn) {
            actualCollectEarn = order.earn;
        }
        if (recipient == address(0)) {
            recipient = address(this);
        }
        IiZiSwapPool(pool).collectLimOrder(recipient, order.pt, actualCollectDec, actualCollectEarn, order.sellXEarnY);
        // collect from core may be less, but we still do not modify actualCollectEarn(Dec)
        order.sellingDec -= actualCollectDec;
        order.earn -= actualCollectEarn;

        bool noRemain = (order.sellingRemain == 0);
        if (order.sellingRemain > 0) {
            noRemain = (order.amount / order.sellingRemain > 100000);
        }

        if (order.sellingDec == 0 && noRemain && order.earn == 0) {
            order.active = false;
            // addr2DeactiveOrderID[msg.sender].add(orderId);
            addr2DeactiveOrder[msg.sender].add(order, DEACTIVE_ORDER_LIM);
        }
    }

    /// @notice Returns active orders for the seller.
    /// @param user address of the seller
    /// @return activeIdx list of active order idx
    /// @return activeLimitOrder list of active order
    function getActiveOrders(address user)
        external
        view
        returns (uint256[] memory activeIdx, LimOrder[] memory activeLimitOrder)
    {
        uint256 activeNum = 0;
        uint256 length = addr2ActiveOrder[user].length;
        for (uint256 i = 0; i < length; i ++) {
            if (addr2ActiveOrder[user][i].active) {
                activeNum += 1;
            }
        }
        if (activeNum == 0) {
            return (activeIdx, activeLimitOrder);
        }
        activeIdx = new uint256[](activeNum);
        activeLimitOrder = new LimOrder[](activeNum);
        activeNum = 0;
        for (uint256 i = 0; i < length; i ++) {
            if (addr2ActiveOrder[user][i].active) {
                activeIdx[activeNum] = i;
                activeLimitOrder[activeNum] = addr2ActiveOrder[user][i];
                activeNum += 1;
            }
        }
        return (activeIdx, activeLimitOrder);
    }

    /// @notice Returns a single active order for the seller.
    /// @param user address of the seller
    /// @param idx index of the active order list
    /// @return limOrder the target active order
    function getActiveOrder(address user, uint256 idx) external view returns (LimOrder memory limOrder) {
        require(idx < addr2ActiveOrder[user].length, 'Out Of Length');
        return addr2ActiveOrder[user][idx];
    }

    /// @notice Returns a slot in the active order list, which can be replaced with a new order.
    /// @param user address of the seller
    /// @return slotIdx the first available slot index
    function getDeactiveSlot(address user) external view returns (uint256 slotIdx) {
        slotIdx = addr2ActiveOrder[user].length;
        for (uint256 i = 0; i < addr2ActiveOrder[user].length; i ++) {
            if (!addr2ActiveOrder[user][i].active) {
                return i;
            }
        }
        return slotIdx;
    }

    /// @notice Returns deactived orders for the seller.
    /// @param user address of the seller
    /// @return deactiveLimitOrder list of deactived orders
    function getDeactiveOrders(address user) external view returns (LimOrder[] memory deactiveLimitOrder) {
        LimOrderCircularQueue.Queue storage queue = addr2DeactiveOrder[user];
        if (queue.limOrders.length == 0) {
            return deactiveLimitOrder;
        }
        deactiveLimitOrder = new LimOrder[](queue.limOrders.length);
        uint256 start = queue.start;
        for (uint256 i = 0; i < queue.limOrders.length; i ++) {
            deactiveLimitOrder[i] = queue.limOrders[(start + i) % queue.limOrders.length];
        }
        return deactiveLimitOrder;
    }

    /// @notice Returns a single deactived order for the seller.
    /// @param user address of the seller
    /// @param idx index of the deactived order list
    /// @return limOrder the target deactived order
    function getDeactiveOrder(address user, uint256 idx) external view returns (LimOrder memory limOrder) {
        LimOrderCircularQueue.Queue storage queue = addr2DeactiveOrder[user];
        require(idx < queue.limOrders.length, 'Out Of Length');
        return queue.limOrders[(queue.start + idx) % queue.limOrders.length];
    }

}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 3 of 11 : IiZiSwapCallback.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.4;

interface IiZiSwapMintCallback {

    /// @notice Called to msg.sender in iZiSwapPool#mint call
    /// @param x Amount of tokenX need to pay from miner
    /// @param y Amount of tokenY need to pay from miner
    /// @param data Any data passed through by the msg.sender via the iZiSwapPool#mint call
    function mintDepositCallback(
        uint256 x,
        uint256 y,
        bytes calldata data
    ) external;

}

interface IiZiSwapCallback {

    /// @notice Called to msg.sender in iZiSwapPool#swapY2X(DesireX) call
    /// @param x Amount of tokenX trader will acquire
    /// @param y Amount of tokenY trader will pay
    /// @param data Any dadta passed though by the msg.sender via the iZiSwapPool#swapY2X(DesireX) call
    function swapY2XCallback(
        uint256 x,
        uint256 y,
        bytes calldata data
    ) external;

    /// @notice Called to msg.sender in iZiSwapPool#swapX2Y(DesireY) call
    /// @param x Amount of tokenX trader will pay
    /// @param y Amount of tokenY trader will require
    /// @param data Any dadta passed though by the msg.sender via the iZiSwapPool#swapX2Y(DesireY) call
    function swapX2YCallback(
        uint256 x,
        uint256 y,
        bytes calldata data
    ) external;

}

interface IiZiSwapAddLimOrderCallback {

    /// @notice Called to msg.sender in iZiSwapPool#addLimOrderWithX(Y) call
    /// @param x Amount of tokenX seller will pay
    /// @param y Amount of tokenY seller will pay
    /// @param data Any dadta passed though by the msg.sender via the iZiSwapPool#addLimOrderWithX(Y) call
    function payCallback(
        uint256 x,
        uint256 y,
        bytes calldata data
    ) external;

}

File 4 of 11 : IiZiSwapFactory.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.4;

interface IiZiSwapFactory {

    /// @notice emit when successfuly create a new pool (calling iZiSwapFactory#newPool)
    /// @param tokenX address of erc-20 tokenX
    /// @param tokenY address of erc-20 tokenY
    /// @param fee fee amount of swap (3000 means 0.3%)
    /// @param pointDelta minimum number of distance between initialized or limitorder points
    /// @param pool address of swap pool
    event NewPool(
        address indexed tokenX,
        address indexed tokenY,
        uint24 indexed fee,
        uint24 pointDelta,
        address pool
    );

    /// @notice module to support swap from tokenX to tokenY
    /// @return swapX2YModule address
    function swapX2YModule() external returns (address);

    /// @notice module to support swap from tokenY to tokenX
    /// @return swapY2XModule address
    function swapY2XModule() external returns (address);

    /// @notice module to support mint/burn/collect function of pool
    /// @return liquidityModule address
    function liquidityModule() external returns (address);

    /// @notice address of module for user to manage limit orders
    /// @return limitOrderModule address
    function limitOrderModule() external returns (address);

    /// @notice address of module for flash loan
    /// @return flashModule address
    function flashModule() external returns (address);

    /// @notice default fee rate from miner's fee gain
    /// @return defaultFeeChargePercent default fee rate * 100
    function defaultFeeChargePercent() external returns (uint24);

    /// @notice Enables a fee amount with the given pointDelta
    /// @dev Fee amounts may never be removed once enabled
    /// @param fee fee amount (3000 means 0.3%)
    /// @param pointDelta The spacing between points to be enforced for all pools created with the given fee amount
    function enableFeeAmount(uint24 fee, uint24 pointDelta) external;

    /// @notice Create a new pool which not exists.
    /// @param tokenX address of tokenX
    /// @param tokenY address of tokenY
    /// @param fee fee amount
    /// @param currentPoint initial point (log 1.0001 of price)
    /// @return address of newly created pool
    function newPool(
        address tokenX,
        address tokenY,
        uint24 fee,
        int24 currentPoint
    ) external returns (address);

    /// @notice Charge receiver of all pools.
    /// @return address of charge receiver
    function chargeReceiver() external view returns(address);

    /// @notice Get pool of (tokenX, tokenY, fee), address(0) for not exists.
    /// @param tokenX address of tokenX
    /// @param tokenY address of tokenY
    /// @param fee fee amount
    /// @return address of pool
    function pool(
        address tokenX,
        address tokenY,
        uint24 fee
    ) external view returns(address);

    /// @notice Get point delta of a given fee amount.
    /// @param fee fee amount
    /// @return pointDelta the point delta
    function fee2pointDelta(uint24 fee) external view returns (int24 pointDelta);

    /// @notice Change charge receiver, only owner of factory can call.
    /// @param _chargeReceiver address of new receiver
    function modifyChargeReceiver(address _chargeReceiver) external;

    /// @notice Change defaultFeeChargePercent
    /// @param _defaultFeeChargePercent new charge percent
    function modifyDefaultFeeChargePercent(uint24 _defaultFeeChargePercent) external;

    function deployPoolParams() external view returns(
        address tokenX,
        address tokenY,
        uint24 fee,
        int24 currentPoint,
        int24 pointDelta,
        uint24 feeChargePercent
    );
    
}

File 5 of 11 : IiZiSwapPool.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.4;

interface IiZiSwapPool {

    /// @notice Emitted when miner successfully add liquidity (mint).
    /// @param sender the address that minted the liquidity
    /// @param owner the owner who will benefit from this liquidity
    /// @param leftPoint left endpoint of the liquidity
    /// @param rightPoint right endpoint of the liquidity
    /// @param liquidity the amount of liquidity minted to the range [leftPoint, rightPoint)
    /// @param amountX amount of tokenX deposit
    /// @param amountY amount of tokenY deposit
    event Mint(
        address sender, 
        address indexed owner, 
        int24 indexed leftPoint, 
        int24 indexed rightPoint, 
        uint128 liquidity, 
        uint256 amountX, 
        uint256 amountY
    );

    /// @notice Emitted when miner successfully decrease liquidity (withdraw).
    /// @param owner owner address of liquidity
    /// @param leftPoint left endpoint of liquidity
    /// @param rightPoint right endpoint of liquidity
    /// @param liquidity amount of liquidity decreased
    /// @param amountX amount of tokenX withdrawed
    /// @param amountY amount of tokenY withdrawed
    event Burn(
        address indexed owner, 
        int24 indexed leftPoint,
        int24 indexed rightPoint,
        uint128 liquidity,
        uint256 amountX,
        uint256 amountY
    );

    /// @notice Emitted when fees and withdrawed liquidity are collected 
    /// @param owner The owner of the Liquidity
    /// @param recipient recipient of those token
    /// @param leftPoint The left point of the liquidity
    /// @param rightPoint The right point of the liquidity
    /// @param amountX The amount of tokenX (fees and withdrawed tokenX from liquidity)
    /// @param amountY The amount of tokenY (fees and withdrawed tokenY from liquidity)
    event CollectLiquidity(
        address indexed owner,
        address recipient,
        int24 indexed leftPoint,
        int24 indexed rightPoint,
        uint256 amountX,
        uint256 amountY
    );

    /// @notice Emitted when a trader successfully exchange.
    /// @param tokenX tokenX of pool
    /// @param tokenY tokenY of pool
    /// @param fee fee amount of pool
    /// @param sellXEarnY true for selling tokenX, false for buying tokenX
    /// @param amountX amount of tokenX in this exchange
    /// @param amountY amount of tokenY in this exchange
    event Swap(
        address indexed tokenX,
        address indexed tokenY,
        uint24 indexed fee,
        bool sellXEarnY,
        uint256 amountX,
        uint256 amountY
    );

    /// @notice Emitted by the pool for any flashes of tokenX/tokenY.
    /// @param sender the address that initiated the swap call, and that received the callback
    /// @param recipient the address that received the tokens from flash
    /// @param amountX the amount of tokenX that was flashed
    /// @param amountY the amount of tokenY that was flashed
    /// @param paidX the amount of tokenX paid for the flash, which can exceed the amountX plus the fee
    /// @param paidY the amount of tokenY paid for the flash, which can exceed the amountY plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amountX,
        uint256 amountY,
        uint256 paidX,
        uint256 paidY
    );

    /// @notice Emitted when a seller successfully add a limit order.
    /// @param owner owner of limit order
    /// @param addAmount amount of token to sell the seller added
    /// @param acquireAmount amount of earn-token acquired, if there exists some opposite order before 
    /// @param point point of limit order
    /// @param claimSold claimed sold sell-token, if this owner has order with same direction on this point before
    /// @param claimEarn claimed earned earn-token, if this owner has order with same direction on this point before
    /// @param sellXEarnY direction of limit order, etc. sell tokenX or sell tokenY
    event AddLimitOrder(
        address indexed owner,
        uint128 addAmount,
        uint128 acquireAmount,
        int24 indexed point,
        uint128 claimSold,
        uint128 claimEarn,
        bool sellXEarnY
    );

    /// @notice Emitted when a seller successfully decrease a limit order.
    /// @param owner owner of limit order
    /// @param decreaseAmount amount of token to sell the seller decreased
    /// @param point point of limit order
    /// @param claimSold claimed sold sell-token
    /// @param claimEarn claimed earned earn-token
    /// @param sellXEarnY direction of limit order, etc. sell tokenX or sell tokenY
    event DecLimitOrder(
        address indexed owner,
        uint128 decreaseAmount,
        int24 indexed point,
        uint128 claimSold,
        uint128 claimEarn,
        bool sellXEarnY
    );

    /// @notice Emitted when collect from a limit order
    /// @param owner The owner of the Liquidity
    /// @param recipient recipient of those token
    /// @param point The point of the limit order
    /// @param collectDec The amount of decreased sell token collected
    /// @param collectEarn The amount of earn token collected
    /// @param sellXEarnY direction of limit order, etc. sell tokenX or sell tokenY
    event CollectLimitOrder(
        address indexed owner,
        address recipient,
        int24 indexed point,
        uint128 collectDec,
        uint128 collectEarn,
        bool sellXEarnY
    );

    /// @notice Returns the information about a liquidity by the liquidity's key.
    /// @param key the liquidity's key is a hash of a preimage composed by the miner(owner), pointLeft and pointRight
    /// @return liquidity the amount of liquidity,
    /// @return lastFeeScaleX_128 fee growth of tokenX inside the range as of the last mint/burn/collect,
    /// @return lastFeeScaleY_128 fee growth of tokenY inside the range as of the last mint/burn/collect,
    /// @return tokenOwedX the computed amount of tokenX miner can collect as of the last mint/burn/collect,
    /// @return tokenOwedY the computed amount of tokenY miner can collect as of the last mint/burn/collect
    function liquidity(bytes32 key)
        external
        view
        returns (
            uint128 liquidity,
            uint256 lastFeeScaleX_128,
            uint256 lastFeeScaleY_128,
            uint256 tokenOwedX,
            uint256 tokenOwedY
        );
    
    /// @notice Returns the information about a user's limit order (sell tokenY and earn tokenX).
    /// @param key the limit order's key is a hash of a preimage composed by the seller, point
    /// @return lastAccEarn total amount of tokenX earned by all users at this point as of the last add/dec/collect
    /// @return sellingRemain amount of tokenY not selled in this limit order
    /// @return sellingDec amount of tokenY decreased by seller from this limit order
    /// @return earn amount of unlegacy earned tokenX in this limit order not assigned
    /// @return legacyEarn amount of legacy earned tokenX in this limit order not assgined
    /// @return earnAssign assigned amount of tokenX earned (both legacy and unlegacy) in this limit order
    function userEarnX(bytes32 key)
        external
        view
        returns (
            uint256 lastAccEarn,
            uint128 sellingRemain,
            uint128 sellingDec,
            uint128 earn,
            uint128 legacyEarn,
            uint128 earnAssign
        );
    
    /// @notice Returns the information about a user's limit order (sell tokenX and earn tokenY).
    /// @param key the limit order's key is a hash of a preimage composed by the seller, point
    /// @return lastAccEarn total amount of tokenY earned by all users at this point as of the last add/dec/collect
    /// @return sellingRemain amount of tokenX not selled in this limit order
    /// @return sellingDec amount of tokenX decreased by seller from this limit order
    /// @return earn amount of unlegacy earned tokenY in this limit order not assigned
    /// @return legacyEarn amount of legacy earned tokenY in this limit order not assgined
    /// @return earnAssign assigned amount of tokenY earned (both legacy and unlegacy) in this limit order
    function userEarnY(bytes32 key)
        external
        view
        returns (
            uint256 lastAccEarn,
            uint128 sellingRemain,
            uint128 sellingDec,
            uint128 earn,
            uint128 legacyEarn,
            uint128 earnAssign
        );
    
    /// @notice Mark a given amount of tokenY in a limitorder(sellx and earn y) as assigned.
    /// @param point point (log Price) of seller's limit order,be sure to be times of pointDelta
    /// @param assignY max amount of tokenY to mark assigned
    /// @param fromLegacy true for assigning earned token from legacyEarnY
    /// @return actualAssignY actual amount of tokenY marked
    function assignLimOrderEarnY(
        int24 point,
        uint128 assignY,
        bool fromLegacy
    ) external returns(uint128 actualAssignY);
    
    /// @notice Mark a given amount of tokenX in a limitorder(selly and earn x) as assigned.
    /// @param point point (log Price) of seller's limit order,be sure to be times of pointDelta
    /// @param assignX max amount of tokenX to mark assigned
    /// @param fromLegacy true for assigning earned token from legacyEarnX
    /// @return actualAssignX actual amount of tokenX marked
    function assignLimOrderEarnX(
        int24 point,
        uint128 assignX,
        bool fromLegacy
    ) external returns(uint128 actualAssignX);

    /// @notice Decrease limitorder of selling X.
    /// @param point point of seller's limit order, be sure to be times of pointDelta
    /// @param deltaX max amount of tokenX seller wants to decrease
    /// @return actualDeltaX actual amount of tokenX decreased
    /// @return legacyAccEarn legacyAccEarnY of pointOrder at point when calling this interface
    function decLimOrderWithX(
        int24 point,
        uint128 deltaX
    ) external returns (uint128 actualDeltaX, uint256 legacyAccEarn);
    
    /// @notice Decrease limitorder of selling Y.
    /// @param point point of seller's limit order, be sure to be times of pointDelta
    /// @param deltaY max amount of tokenY seller wants to decrease
    /// @return actualDeltaY actual amount of tokenY decreased
    /// @return legacyAccEarn legacyAccEarnX of pointOrder at point when calling this interface
    function decLimOrderWithY(
        int24 point,
        uint128 deltaY
    ) external returns (uint128 actualDeltaY, uint256 legacyAccEarn);
    
    /// @notice Add a limit order (selling x) in the pool.
    /// @param recipient owner of the limit order
    /// @param point point of the order, be sure to be times of pointDelta
    /// @param amountX amount of tokenX to sell
    /// @param data any data that should be passed through to the callback
    /// @return orderX actual added amount of tokenX
    /// @return acquireY amount of tokenY acquired if there is a limit order to sell y before adding
    function addLimOrderWithX(
        address recipient,
        int24 point,
        uint128 amountX,
        bytes calldata data
    ) external returns (uint128 orderX, uint128 acquireY);

    /// @notice Add a limit order (selling y) in the pool.
    /// @param recipient owner of the limit order
    /// @param point point of the order, be sure to be times of pointDelta
    /// @param amountY amount of tokenY to sell
    /// @param data any data that should be passed through to the callback
    /// @return orderY actual added amount of tokenY
    /// @return acquireX amount of tokenX acquired if there exists a limit order to sell x before adding
    function addLimOrderWithY(
        address recipient,
        int24 point,
        uint128 amountY,
        bytes calldata data
    ) external returns (uint128 orderY, uint128 acquireX);

    /// @notice Collect earned or decreased token from limit order.
    /// @param recipient address to benefit
    /// @param point point of limit order, be sure to be times of pointDelta
    /// @param collectDec max amount of decreased selling token to collect
    /// @param collectEarn max amount of earned token to collect
    /// @param isEarnY direction of this limit order, true for sell y, false for sell x
    /// @return actualCollectDec actual amount of decresed selling token collected
    /// @return actualCollectEarn actual amount of earned token collected
    function collectLimOrder(
        address recipient, int24 point, uint128 collectDec, uint128 collectEarn, bool isEarnY
    ) external returns(uint128 actualCollectDec, uint128 actualCollectEarn);

    /// @notice Add liquidity to the pool.
    /// @param recipient newly created liquidity will belong to this address
    /// @param leftPt left endpoint of the liquidity, be sure to be times of pointDelta
    /// @param rightPt right endpoint of the liquidity, be sure to be times of pointDelta
    /// @param liquidDelta amount of liquidity to add
    /// @param data any data that should be passed through to the callback
    /// @return amountX The amount of tokenX that was paid for the liquidity. Matches the value in the callback
    /// @return amountY The amount of tokenY that was paid for the liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 leftPt,
        int24 rightPt,
        uint128 liquidDelta,
        bytes calldata data
    ) external returns (uint256 amountX, uint256 amountY);

    /// @notice Decrease a given amount of liquidity from msg.sender's liquidities.
    /// @param leftPt left endpoint of the liquidity
    /// @param rightPt right endpoint of the liquidity
    /// @param liquidDelta amount of liquidity to burn
    /// @return amountX The amount of tokenX should be refund after burn
    /// @return amountY The amount of tokenY should be refund after burn
    function burn(
        int24 leftPt,
        int24 rightPt,
        uint128 liquidDelta
    ) external returns (uint256 amountX, uint256 amountY);

    /// @notice Collect tokens (fee or refunded after burn) from a liquidity.
    /// @param recipient the address which should receive the collected tokens
    /// @param leftPt left endpoint of the liquidity
    /// @param rightPt right endpoint of the liquidity
    /// @param amountXLim max amount of tokenX the owner wants to collect
    /// @param amountYLim max amount of tokenY the owner wants to collect
    /// @return actualAmountX the amount tokenX collected
    /// @return actualAmountY the amount tokenY collected
    function collect(
        address recipient,
        int24 leftPt,
        int24 rightPt,
        uint256 amountXLim,
        uint256 amountYLim
    ) external returns (uint256 actualAmountX, uint256 actualAmountY);

    /// @notice Swap tokenY for tokenX, given max amount of tokenY user willing to pay.
    /// @param recipient the address to receive tokenX
    /// @param amount the max amount of tokenY user willing to pay
    /// @param highPt the highest point(price) of x/y during swap
    /// @param data any data to be passed through to the callback
    /// @return amountX amount of tokenX payed
    /// @return amountY amount of tokenY acquired
    function swapY2X(
        address recipient,
        uint128 amount,
        int24 highPt,
        bytes calldata data
    ) external returns (uint256 amountX, uint256 amountY);
    
    /// @notice Swap tokenY for tokenX, given amount of tokenX user desires.
    /// @param recipient the address to receive tokenX
    /// @param desireX the amount of tokenX user desires
    /// @param highPt the highest point(price) of x/y during swap
    /// @param data any data to be passed through to the callback
    /// @return amountX amount of tokenX payed
    /// @return amountY amount of tokenY acquired
    function swapY2XDesireX(
        address recipient,
        uint128 desireX,
        int24 highPt,
        bytes calldata data
    ) external returns (uint256 amountX, uint256 amountY);
    
    /// @notice Swap tokenX for tokenY, given max amount of tokenX user willing to pay.
    /// @param recipient the address to receive tokenY
    /// @param amount the max amount of tokenX user willing to pay
    /// @param lowPt the lowest point(price) of x/y during swap
    /// @param data any data to be passed through to the callback
    /// @return amountX amount of tokenX acquired
    /// @return amountY amount of tokenY payed
    function swapX2Y(
        address recipient,
        uint128 amount,
        int24 lowPt,
        bytes calldata data
    ) external returns (uint256 amountX, uint256 amountY);
    
    /// @notice Swap tokenX for tokenY, given amount of tokenY user desires.
    /// @param recipient the address to receive tokenY
    /// @param desireY the amount of tokenY user desires
    /// @param lowPt the lowest point(price) of x/y during swap
    /// @param data any data to be passed through to the callback
    /// @return amountX amount of tokenX acquired
    /// @return amountY amount of tokenY payed
    function swapX2YDesireY(
        address recipient,
        uint128 desireY,
        int24 lowPt,
        bytes calldata data
    ) external returns (uint256 amountX, uint256 amountY);

    /// @notice Returns sqrt(1.0001), in 96 bit fixpoint number.
    function sqrtRate_96() external view returns(uint160);
    
    /// @notice State values of pool.
    /// @return sqrtPrice_96 a 96 fixpoing number describe the sqrt value of current price(tokenX/tokenY)
    /// @return currentPoint the current point of the pool, 1.0001 ^ currentPoint = price
    /// @return observationCurrentIndex the index of the last oracle observation that was written,
    /// @return observationQueueLen the current maximum number of observations stored in the pool,
    /// @return observationNextQueueLen the next maximum number of observations, to be updated when the observation.
    /// @return locked whether the pool is locked (only used for checking reentrance)
    /// @return liquidity liquidity on the currentPoint (currX * sqrtPrice + currY / sqrtPrice)
    /// @return liquidityX liquidity of tokenX
    function state()
        external view
        returns(
            uint160 sqrtPrice_96,
            int24 currentPoint,
            uint16 observationCurrentIndex,
            uint16 observationQueueLen,
            uint16 observationNextQueueLen,
            bool locked,
            uint128 liquidity,
            uint128 liquidityX
        );
    
    /// @notice LimitOrder info on a given point.
    /// @param point the given point 
    /// @return sellingX total amount of tokenX selling on the point
    /// @return earnY total amount of unclaimed earned tokenY for unlegacy sellingX
    /// @return accEarnY total amount of earned tokenY(via selling tokenX) by all users at this point as of the last swap
    /// @return legacyAccEarnY latest recorded 'accEarnY' value when sellingX is clear (legacy)
    /// @return legacyEarnY total amount of unclaimed earned tokenY for legacy (cleared during swap) sellingX
    /// @return sellingY total amount of tokenYselling on the point
    /// @return earnX total amount of unclaimed earned tokenX for unlegacy sellingY
    /// @return legacyEarnX total amount of unclaimed earned tokenX for legacy (cleared during swap) sellingY
    /// @return accEarnX total amount of earned tokenX(via selling tokenY) by all users at this point as of the last swap
    /// @return legacyAccEarnX latest recorded 'accEarnX' value when sellingY is clear (legacy)
    function limitOrderData(int24 point)
        external view
        returns(
            uint128 sellingX,
            uint128 earnY,
            uint256 accEarnY,
            uint256 legacyAccEarnY,
            uint128 legacyEarnY,
            uint128 sellingY,
            uint128 earnX,
            uint128 legacyEarnX,
            uint256 accEarnX,
            uint256 legacyAccEarnX
        );
    
    /// @notice Query infomation about a point whether has limit order or is an liquidity's endpoint.
    /// @param point point to query
    /// @return val endpoint for val&1>0 and has limit order for val&2 > 0
    function orderOrEndpoint(int24 point) external returns(int24 val);

    /// @notice Returns observation data about a specific index.
    /// @param index the index of observation array
    /// @return timestamp the timestamp of the observation,
    /// @return accPoint the point multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// @return init whether the observation has been initialized and the above values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 timestamp,
            int56 accPoint,
            bool init
        );

    /// @notice Point status in the pool.
    /// @param point the point
    /// @return liquidSum the total amount of liquidity that uses the point either as left endpoint or right endpoint
    /// @return liquidDelta how much liquidity changes when the pool price crosses the point from left to right
    /// @return accFeeXOut_128 the fee growth on the other side of the point from the current point in tokenX
    /// @return accFeeYOut_128 the fee growth on the other side of the point from the current point in tokenY
    /// @return isEndpt whether the point is an endpoint of a some miner's liquidity, true if liquidSum > 0
    function points(int24 point)
        external
        view
        returns (
            uint128 liquidSum,
            int128 liquidDelta,
            uint256 accFeeXOut_128,
            uint256 accFeeYOut_128,
            bool isEndpt
        );

    /// @notice Returns 256 packed point (statusVal>0) boolean values. See PointBitmap for more information.
    function pointBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the integral value of point(time) and integral value of 1/liquidity(time)
    ///     at some target timestamps (block.timestamp - secondsAgo[i])
    /// @dev Reverts if target timestamp is early than oldest observation in the queue
    /// @dev If you call this method with secondsAgos = [3600, 0]. the average point of this pool during recent hour is 
    /// (accPoints[1] - accPoints[0]) / 3600
    /// @param secondsAgos describe the target timestamp , targetTimestimp[i] = block.timestamp - secondsAgo[i]
    /// @return accPoints integral value of point(time) from 0 to each target timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory accPoints);
    
    /// @notice Expand max-length of observation queue.
    /// @param newNextQueueLen new value of observationNextQueueLen, which should be greater than current observationNextQueueLen
    function expandObservationQueue(uint16 newNextQueueLen) external;

    /// @notice Borrow tokenX and/or tokenY and pay it back within a block.
    /// @dev The caller needs to implement a IiZiSwapPool#flashCallback callback function
    /// @param recipient the address which will receive the tokenY and/or tokenX
    /// @param amountX the amount of tokenX to borrow
    /// @param amountY the amount of tokenY to borrow
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amountX,
        uint256 amountY,
        bytes calldata data
    ) external;

    /// @notice Returns a snapshot infomation of Liquidity in [leftPoint, rightPoint).
    /// @param leftPoint left endpoint of range, should be times of pointDelta
    /// @param rightPoint right endpoint of range, should be times of pointDelta
    /// @return deltaLiquidities an array of delta liquidity for points in the range
    ///    note 1. delta liquidity here is amount of liquidity changed when cross a point from left to right
    ///    note 2. deltaLiquidities only contains points which are times of pointDelta
    ///    note 3. this function may cost a ENORMOUS amount of gas, be careful to call
    function liquiditySnapshot(int24 leftPoint, int24 rightPoint) external view returns(int128[] memory deltaLiquidities);

    struct LimitOrderStruct {
        uint128 sellingX;
        uint128 earnY;
        uint256 accEarnY;
        uint128 sellingY;
        uint128 earnX;
        uint256 accEarnX;
    }

    /// @notice Returns a snapshot infomation of Limit Order in [leftPoint, rightPoint).
    /// @param leftPoint left endpoint of range, should be times of pointDelta
    /// @param rightPoint right endpoint of range, should be times of pointDelta
    /// @return limitOrders an array of Limit Orders for points in the range
    ///    note 1. this function may cost a HUGE amount of gas, be careful to call
    function limitOrderSnapshot(int24 leftPoint, int24 rightPoint) external view returns(LimitOrderStruct[] memory limitOrders); 

    /// @notice Amount of charged fee on tokenX.
    function totalFeeXCharged() external view returns(uint256);

    /// @notice Amount of charged fee on tokenY.
    function totalFeeYCharged() external view returns(uint256);

    /// @notice Percent to charge from miner's fee.
    function feeChargePercent() external view returns(uint24);

    /// @notice Collect charged fee, only factory's chargeReceiver can call.
    function collectFeeCharged() external;

    /// @notice modify 'feeChargePercent', only owner has authority.
    /// @param newFeeChargePercent new value of feeChargePercent, a nature number range in [0, 100], 
    function modifyFeeChargePercent(uint24 newFeeChargePercent) external;
    
}

File 6 of 11 : MulDivMath.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.4;

library MulDivMath {

    // compute res = floor(a * b / c), assuming res < 2^256
    function mulDivFloor(
        uint256 a,
        uint256 b,
        uint256 c
    ) internal pure returns (uint256 res) {
        
        // let prodMod2_256 = a * b % 2^256
        uint256 prodMod2_256; 
        // let prodDiv2_256 = a * b / 2^256
        uint256 prodDiv2_256;
        assembly {
            let prodModM1 := mulmod(a, b, not(0))
            prodMod2_256 := mul(a, b)
            prodDiv2_256 := sub(sub(prodModM1, prodMod2_256), lt(prodModM1, prodMod2_256))
        }

        if (prodDiv2_256 == 0) {
            require(c > 0);
            assembly {
                res := div(prodMod2_256, c)
            }
            return res;
        }

        // we should ensure that a * b /c < 2^256 before calling
        require(c > prodDiv2_256);

        uint256 resMod;
        assembly {
            resMod := mulmod(a, b, c)
            // a * b - resMod
            prodDiv2_256 := sub(prodDiv2_256, gt(resMod, prodMod2_256))
            prodMod2_256 := sub(prodMod2_256, resMod)

            // compute lowbit of c
            let lowbit := not(c)
            lowbit := add(lowbit, 1)
            lowbit := and(lowbit, c)

            // c / lowbit
            c := div(c, lowbit)
            // a * b / lowbit
            prodMod2_256 := div(prodMod2_256, lowbit)
            lowbit := add(div(sub(0, lowbit), lowbit), 1)
            prodDiv2_256 := mul(prodDiv2_256, lowbit)
            prodMod2_256 := or(prodMod2_256, prodDiv2_256)

            // get inv of c
            // cInv * c = 1 (mod 2^4)
            let cInv := xor(mul(3, c), 2)
            cInv := mul(cInv, sub(2, mul(c, cInv))) // shift to 2^8
            cInv := mul(cInv, sub(2, mul(c, cInv))) // shift to 2^16
            cInv := mul(cInv, sub(2, mul(c, cInv))) // shift to 2^32
            cInv := mul(cInv, sub(2, mul(c, cInv))) // shift to 2^64
            cInv := mul(cInv, sub(2, mul(c, cInv))) // shift to 2^128
            cInv := mul(cInv, sub(2, mul(c, cInv))) // shift to 2^256

            // a * b / c = prodMod2_256 * cInv (mod 2^256)
            res := mul(prodMod2_256, cInv)
        }
    }

    // compute res = ceil(a * b / c), assuming res < 2^256
    function mulDivCeil(
        uint256 a,
        uint256 b,
        uint256 c
    ) internal pure returns (uint256 res) {
        res = mulDivFloor(a, b, c);
        if (mulmod(a, b, c) > 0) {
            require(res < type(uint256).max);
            res++;
        }
    }
    
}

File 7 of 11 : TwoPower.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.4;

/// @title FixedPoint128
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
library TwoPower {

    uint256 internal constant pow96 = 0x1000000000000000000000000;
    uint256 internal constant pow128 = 0x100000000000000000000000000000000;
    uint8 internal constant RESOLUTION = 96;

}

File 8 of 11 : LogPowMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

library LogPowMath {

    int24 internal constant MIN_POINT = -887272;

    int24 internal constant MAX_POINT = -MIN_POINT;


    uint160 internal constant MIN_SQRT_PRICE = 4295128739;

    uint160 internal constant MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342;

    /// @notice sqrt(1.0001^point) in form oy 96-bit fix point num
    function getSqrtPrice(int24 point) internal pure returns (uint160 sqrtPrice_96) {
        uint256 absIdx = point < 0 ? uint256(-int256(point)) : uint256(int256(point));
        require(absIdx <= uint256(int256(MAX_POINT)), 'T');

        uint256 value = absIdx & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
        if (absIdx & 0x2 != 0) value = (value * 0xfff97272373d413259a46990580e213a) >> 128;
        if (absIdx & 0x4 != 0) value = (value * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
        if (absIdx & 0x8 != 0) value = (value * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
        if (absIdx & 0x10 != 0) value = (value * 0xffcb9843d60f6159c9db58835c926644) >> 128;
        if (absIdx & 0x20 != 0) value = (value * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
        if (absIdx & 0x40 != 0) value = (value * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
        if (absIdx & 0x80 != 0) value = (value * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
        if (absIdx & 0x100 != 0) value = (value * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
        if (absIdx & 0x200 != 0) value = (value * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
        if (absIdx & 0x400 != 0) value = (value * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
        if (absIdx & 0x800 != 0) value = (value * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
        if (absIdx & 0x1000 != 0) value = (value * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
        if (absIdx & 0x2000 != 0) value = (value * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
        if (absIdx & 0x4000 != 0) value = (value * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
        if (absIdx & 0x8000 != 0) value = (value * 0x31be135f97d08fd981231505542fcfa6) >> 128;
        if (absIdx & 0x10000 != 0) value = (value * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
        if (absIdx & 0x20000 != 0) value = (value * 0x5d6af8dedb81196699c329225ee604) >> 128;
        if (absIdx & 0x40000 != 0) value = (value * 0x2216e584f5fa1ea926041bedfe98) >> 128;
        if (absIdx & 0x80000 != 0) value = (value * 0x48a170391f7dc42444e8fa2) >> 128;

        if (point > 0) value = type(uint256).max / value;

        sqrtPrice_96 = uint160((value >> 32) + (value % (1 << 32) == 0 ? 0 : 1));
    }

    // floor(log1.0001(sqrtPrice_96))
    function getLogSqrtPriceFloor(uint160 sqrtPrice_96) internal pure returns (int24 logValue) {
        // second inequality must be < because the price can nevex reach the price at the max tick
        require(sqrtPrice_96 >= MIN_SQRT_PRICE && sqrtPrice_96 < MAX_SQRT_PRICE, 'R');
        uint256 sqrtPrice_128 = uint256(sqrtPrice_96) << 32;

        uint256 x = sqrtPrice_128;
        uint256 m = 0;

        assembly {
            let y := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(5, gt(x, 0xFFFFFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(4, gt(x, 0xFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(3, gt(x, 0xFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(2, gt(x, 0xF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(1, gt(x, 0x3))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := gt(x, 0x1)
            m := or(m, y)
        }

        if (m >= 128) x = sqrtPrice_128 >> (m - 127);
        else x = sqrtPrice_128 << (127 - m);

        int256 l2 = (int256(m) - 128) << 64;

        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(63, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(62, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(61, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(60, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(59, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(58, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(57, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(56, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(55, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(54, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(53, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(52, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(51, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(50, y))
        }

        int256 ls10001 = l2 * 255738958999603826347141;

        int24 logFloor = int24((ls10001 - 3402992956809132418596140100660247210) >> 128);
        int24 logUpper = int24((ls10001 + 291339464771989622907027621153398088495) >> 128);

        logValue = logFloor == logUpper ? logFloor : getSqrtPrice(logUpper) <= sqrtPrice_96 ? logUpper : logFloor;
    }

    function getLogSqrtPriceFU(uint160 sqrtPrice_96) internal pure returns (int24 logFloor, int24 logUpper) {
        // second inequality must be < because the price can nevex reach the price at the max tick
        require(sqrtPrice_96 >= MIN_SQRT_PRICE && sqrtPrice_96 < MAX_SQRT_PRICE, 'R');
        uint256 sqrtPrice_128 = uint256(sqrtPrice_96) << 32;

        uint256 x = sqrtPrice_128;
        uint256 m = 0;

        assembly {
            let y := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(5, gt(x, 0xFFFFFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(4, gt(x, 0xFFFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(3, gt(x, 0xFF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(2, gt(x, 0xF))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := shl(1, gt(x, 0x3))
            m := or(m, y)
            x := shr(y, x)
        }
        assembly {
            let y := gt(x, 0x1)
            m := or(m, y)
        }

        if (m >= 128) x = sqrtPrice_128 >> (m - 127);
        else x = sqrtPrice_128 << (127 - m);

        int256 l2 = (int256(m) - 128) << 64;

        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(63, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(62, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(61, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(60, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(59, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(58, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(57, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(56, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(55, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(54, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(53, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(52, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(51, y))
            x := shr(y, x)
        }
        assembly {
            x := shr(127, mul(x, x))
            let y := shr(128, x)
            l2 := or(l2, shl(50, y))
        }

        int256 ls10001 = l2 * 255738958999603826347141;

        logFloor = int24((ls10001 - 3402992956809132418596140100660247210) >> 128);
        logUpper = int24((ls10001 + 291339464771989622907027621153398088495) >> 128);
    }
    
}

File 9 of 11 : LimOrder.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.4;

// infomation of a limit order
struct LimOrder {
    // total amount of earned token by all users at this point 
    // with same direction (sell x or sell y) as of the last update(add/dec)
    uint256 lastAccEarn;
    // initial amount of token on sale
    uint128 amount;
    // remaing amount of token on sale
    uint128 sellingRemain;
    // accumulated decreased token
    uint128 accSellingDec;
    // uncollected decreased token
    uint128 sellingDec;
    // uncollected earned token
    uint128 earn;
    // id of pool in which this liquidity is added
    uint128 poolId;
    // block.timestamp when add a limit order
    uint128 timestamp;
    // point (price) of limit order
    int24 pt;
    // direction of limit order (sellx or sell y)
    bool sellXEarnY;
    // active or not
    bool active;
}

File 10 of 11 : LimOrderCircularQueue.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.4;

import "./LimOrder.sol";

library LimOrderCircularQueue {

    struct Queue {
        // start, start+1, ..., MAX_LENGTH-1, 0, 1, ..., start-1
        uint256 start;
        LimOrder[] limOrders;
    }

    function add(Queue storage queue, LimOrder memory limOrder, uint256 capacity) internal {
        if (queue.limOrders.length < capacity) {
            queue.limOrders.push(limOrder);
        } else {
            queue.limOrders[queue.start] = limOrder;
            queue.start = (queue.start + 1) % queue.limOrders.length;
        }
    }

}

File 11 of 11 : base.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "../core/interfaces/IiZiSwapFactory.sol";

/// @title Interface for WETH9
interface IWETH9 is IERC20 {
    /// @notice Deposit ether to get wrapped ether
    function deposit() external payable;

    /// @notice Withdraw wrapped ether to get ether
    function withdraw(uint256) external;
}

abstract contract Base {
    /// @notice address of iZiSwapFactory
    address public immutable factory;

    /// @notice address of weth9 token
    address public immutable WETH9;

    modifier checkDeadline(uint256 deadline) {
        require(block.timestamp <= deadline, 'Out of time');
        _;
    }

    receive() external payable {}

    /// @notice Constructor of base.
    /// @param _factory address of iZiSwapFactory
    /// @param _WETH9 address of weth9 token
    constructor(address _factory, address _WETH9) {
        factory = _factory;
        WETH9 = _WETH9;
    }

    /// @notice Make multiple function calls in this contract in a single transaction
    ///     and return the data for each function call, revert if any function call fails
    /// @param data The encoded function data for each function call
    /// @return results result of each function call
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);

            if (!success) {
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }

            results[i] = result;
        }
    }

    /// @notice Transfer tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfer tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approve the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfer ETH to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }

    /// @notice Withdraw all weth9 token of this contract and send the withdrawed eth to recipient
    ///    usually used in multicall when mint/swap/update limitorder with eth
    ///    normally this contract has no any erc20 token or eth after or before a transaction
    ///    we donot need to worry that some one can steal eth from this contract
    /// @param minAmount The minimum amount of WETH9 to withdraw
    /// @param recipient The address to receive all withdrawed eth from this contract
    function unwrapWETH9(uint256 minAmount, address recipient) external payable {
        uint256 all = IWETH9(WETH9).balanceOf(address(this));
        require(all >= minAmount, 'WETH9 Not Enough');

        if (all > 0) {
            IWETH9(WETH9).withdraw(all);
            safeTransferETH(recipient, all);
        }
    }

    /// @notice Send all balance of specified token in this contract to recipient
    ///    usually used in multicall when mint/swap/update limitorder with eth
    ///    normally this contract has no any erc20 token or eth after or before a transaction
    ///    we donot need to worry that some one can steal some token from this contract
    /// @param token address of the token
    /// @param minAmount balance should >= minAmount
    /// @param recipient the address to receive specified token from this contract
    function sweepToken(
        address token,
        uint256 minAmount,
        address recipient
    ) external payable {
        uint256 all = IERC20(token).balanceOf(address(this));
        require(all >= minAmount, 'WETH9 Not Enough');

        if (all > 0) {
            safeTransfer(token, recipient, all);
        }
    }

    /// @notice Send all balance of eth in this contract to msg.sender
    ///    usually used in multicall when mint/swap/update limitorder with eth
    ///    normally this contract has no any erc20 token or eth after or before a transaction
    ///    we donot need to worry that some one can steal some token from this contract
    function refundETH() external payable {
        if (address(this).balance > 0) safeTransferETH(msg.sender, address(this).balance);
    }

    /// @param token The token to pay
    /// @param payer The entity that must pay
    /// @param recipient The entity that will receive payment
    /// @param value The amount to pay
    function pay(
        address token,
        address payer,
        address recipient,
        uint256 value
    ) internal {
        if (token == WETH9 && address(this).balance >= value) {
            // pay with WETH9
            IWETH9(WETH9).deposit{value: value}(); // wrap only what is needed to pay
            IWETH9(WETH9).transfer(recipient, value);
        } else if (payer == address(this)) {
            // pay with tokens already in the contract (for the exact input multihop case)
            safeTransfer(token, recipient, value);
        } else {
            // pull payment
            safeTransferFrom(token, payer, recipient, value);
        }
    }

    /// @notice Query pool address from factory by (tokenX, tokenY, fee).
    /// @param tokenX tokenX of swap pool
    /// @param tokenY tokenY of swap pool
    /// @param fee fee amount of swap pool
    function pool(address tokenX, address tokenY, uint24 fee) public view returns(address) {
        return IiZiSwapFactory(factory).pool(tokenX, tokenY, fee);
    }
    function verify(address tokenX, address tokenY, uint24 fee) internal view {
        require (msg.sender == pool(tokenX, tokenY, fee), "sp");
    }
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"factory","type":"address"},{"internalType":"address","name":"weth","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"int24","name":"point","type":"int24"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint128","name":"sold","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"earn","type":"uint128"},{"indexed":false,"internalType":"bool","name":"sellXEaryY","type":"bool"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"int24","name":"point","type":"int24"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"sellingRemain","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"earn","type":"uint128"},{"indexed":false,"internalType":"bool","name":"sellXEaryY","type":"bool"}],"name":"NewLimitOrder","type":"event"},{"inputs":[],"name":"DEACTIVE_ORDER_LIM","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"orderIdx","type":"uint256"},{"internalType":"uint128","name":"collectDec","type":"uint128"},{"internalType":"uint128","name":"collectEarn","type":"uint128"}],"name":"collectLimOrder","outputs":[{"internalType":"uint128","name":"actualCollectDec","type":"uint128"},{"internalType":"uint128","name":"actualCollectEarn","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderIdx","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"decLimOrder","outputs":[{"internalType":"uint128","name":"actualDelta","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"idx","type":"uint256"}],"name":"getActiveOrder","outputs":[{"components":[{"internalType":"uint256","name":"lastAccEarn","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"sellingRemain","type":"uint128"},{"internalType":"uint128","name":"accSellingDec","type":"uint128"},{"internalType":"uint128","name":"sellingDec","type":"uint128"},{"internalType":"uint128","name":"earn","type":"uint128"},{"internalType":"uint128","name":"poolId","type":"uint128"},{"internalType":"uint128","name":"timestamp","type":"uint128"},{"internalType":"int24","name":"pt","type":"int24"},{"internalType":"bool","name":"sellXEarnY","type":"bool"},{"internalType":"bool","name":"active","type":"bool"}],"internalType":"struct LimOrder","name":"limOrder","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getActiveOrders","outputs":[{"internalType":"uint256[]","name":"activeIdx","type":"uint256[]"},{"components":[{"internalType":"uint256","name":"lastAccEarn","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"sellingRemain","type":"uint128"},{"internalType":"uint128","name":"accSellingDec","type":"uint128"},{"internalType":"uint128","name":"sellingDec","type":"uint128"},{"internalType":"uint128","name":"earn","type":"uint128"},{"internalType":"uint128","name":"poolId","type":"uint128"},{"internalType":"uint128","name":"timestamp","type":"uint128"},{"internalType":"int24","name":"pt","type":"int24"},{"internalType":"bool","name":"sellXEarnY","type":"bool"},{"internalType":"bool","name":"active","type":"bool"}],"internalType":"struct LimOrder[]","name":"activeLimitOrder","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"idx","type":"uint256"}],"name":"getDeactiveOrder","outputs":[{"components":[{"internalType":"uint256","name":"lastAccEarn","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"sellingRemain","type":"uint128"},{"internalType":"uint128","name":"accSellingDec","type":"uint128"},{"internalType":"uint128","name":"sellingDec","type":"uint128"},{"internalType":"uint128","name":"earn","type":"uint128"},{"internalType":"uint128","name":"poolId","type":"uint128"},{"internalType":"uint128","name":"timestamp","type":"uint128"},{"internalType":"int24","name":"pt","type":"int24"},{"internalType":"bool","name":"sellXEarnY","type":"bool"},{"internalType":"bool","name":"active","type":"bool"}],"internalType":"struct LimOrder","name":"limOrder","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getDeactiveOrders","outputs":[{"components":[{"internalType":"uint256","name":"lastAccEarn","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"sellingRemain","type":"uint128"},{"internalType":"uint128","name":"accSellingDec","type":"uint128"},{"internalType":"uint128","name":"sellingDec","type":"uint128"},{"internalType":"uint128","name":"earn","type":"uint128"},{"internalType":"uint128","name":"poolId","type":"uint128"},{"internalType":"uint128","name":"timestamp","type":"uint128"},{"internalType":"int24","name":"pt","type":"int24"},{"internalType":"bool","name":"sellXEarnY","type":"bool"},{"internalType":"bool","name":"active","type":"bool"}],"internalType":"struct LimOrder[]","name":"deactiveLimitOrder","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getDeactiveSlot","outputs":[{"internalType":"uint256","name":"slotIdx","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"idx","type":"uint256"},{"components":[{"internalType":"address","name":"tokenX","type":"address"},{"internalType":"address","name":"tokenY","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"pt","type":"int24"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"bool","name":"sellXEarnY","type":"bool"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct LimitOrderManager.AddLimOrderParam","name":"addLimitOrderParam","type":"tuple"}],"name":"newLimOrder","outputs":[{"internalType":"uint128","name":"orderAmount","type":"uint128"},{"internalType":"uint128","name":"acquire","type":"uint128"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"payCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenX","type":"address"},{"internalType":"address","name":"tokenY","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"}],"name":"pool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"}],"name":"poolAddrs","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"poolIds","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"","type":"uint128"}],"name":"poolMetas","outputs":[{"internalType":"address","name":"tokenX","type":"address"},{"internalType":"address","name":"tokenY","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refundETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"sellers","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"sweepToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"unwrapWETH9","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderIdx","type":"uint256"}],"name":"updateOrder","outputs":[{"internalType":"uint256","name":"earn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60e0604052600080546001600160801b031916600117905561012c60c0523480156200002a57600080fd5b5060405162004885380380620048858339810160408190526200004d9162000089565b6001600160601b0319606092831b8116608052911b1660a052620000c0565b80516001600160a01b03811681146200008457600080fd5b919050565b600080604083850312156200009c578182fd5b620000a7836200006c565b9150620000b7602084016200006c565b90509250929050565b60805160601c60a05160601c60c0516147576200012e60003960008181610233015261196401526000818161027a01528181610ae701528181610baa01528181612a7101528181612ab70152612b4c0152600081816103db01528181610cb30152611c7501526147576000f3fe6080604052600436106101395760003560e01c80638f159451116100ab578063c45a01551161006f578063c45a0155146103c9578063c53a490a146103fd578063cee26ed51461042b578063d4175be214610461578063df2ab5bb14610497578063f655dbc1146104aa57600080fd5b80638f1594511461031c5780639948e4571461033c578063ac9650d814610369578063becbcc6a14610389578063c1c49c8c146103a957600080fd5b806332f37547116100fd57806332f375471461022157806349404b7c146102555780634aa4a4fc146102685780635ddf57451461029c5780638400eff6146102cf57806385de020e146102ef57600080fd5b80630eaa9b071461014557806312210e8a146101915780631490d44b1461019b57806321d85d69146101d35780632b80da901461020157600080fd5b3661014057005b600080fd5b34801561015157600080fd5b5061017b610160366004613e1a565b6003602052600090815260409020546001600160a01b031681565b604051610188919061421f565b60405180910390f35b610199610508565b005b3480156101a757600080fd5b506101bb6101b6366004613fd9565b61051a565b6040516001600160801b039091168152602001610188565b3480156101df57600080fd5b506101f36101ee366004613ed2565b6108f6565b604051908152602001610188565b34801561020d57600080fd5b506101f361021c366004613a43565b610a19565b34801561022d57600080fd5b506101f37f000000000000000000000000000000000000000000000000000000000000000081565b610199610263366004613f02565b610acd565b34801561027457600080fd5b5061017b7f000000000000000000000000000000000000000000000000000000000000000081565b6102af6102aa366004613f26565b610c1d565b604080516001600160801b03938416815292909116602083015201610188565b3480156102db57600080fd5b506101996102ea366004614010565b6112f7565b3480156102fb57600080fd5b5061030f61030a366004613a43565b611359565b60405161018891906142f9565b34801561032857600080fd5b506102af610337366004613b2d565b611539565b34801561034857600080fd5b5061035c610357366004613ac1565b611995565b60405161018891906144b9565b61037c610377366004613b7f565b611ada565b6040516101889190614298565b34801561039557600080fd5b5061017b6103a4366004613a7b565b611c5b565b3480156103b557600080fd5b5061035c6103c4366004613ac1565b611d08565b3480156103d557600080fd5b5061017b7f000000000000000000000000000000000000000000000000000000000000000081565b34801561040957600080fd5b5061041d610418366004613a43565b611e44565b60405161018892919061430c565b34801561043757600080fd5b5061017b610446366004613ed2565b6001602052600090815260409020546001600160a01b031681565b34801561046d57600080fd5b506101bb61047c366004613a43565b6004602052600090815260409020546001600160801b031681565b6101996104a5366004613aec565b612197565b3480156104b657600080fd5b506104f96104c5366004613e1a565b600260205260009081526040902080546001909101546001600160a01b0391821691811690600160a01b900462ffffff1683565b60405161018893929190614233565b471561051857610518334761224f565b565b33600090815260056020526040812054849081106105535760405162461bcd60e51b815260040161054a906143b8565b60405180910390fd5b33600090815260056020526040902080548290811061058257634e487b7160e01b600052603260045260246000fd5b906000526020600020906005020160040160149054906101000a900460ff166105bd5760405162461bcd60e51b815260040161054a906143e0565b82804211156105de5760405162461bcd60e51b815260040161054a90614456565b6000856001600160801b03161161061c5760405162461bcd60e51b8152602060048201526002602482015261041360f41b604482015260640161054a565b33600090815260056020526040812080548890811061064b57634e487b7160e01b600052603260045260246000fd5b600091825260208083206003600590930201828101546001600160801b03600160801b9091041684529190526040909120549091506001600160a01b031661069382826122f2565b5060018201548795506001600160801b03600160801b909104811690861611156106cf576001820154600160801b90046001600160801b031694505b6004820154600090600160981b900460ff161561077b57600480840154604051634cd70e9160e01b81526001600160a01b03851692634cd70e919261072292600160801b90910460020b918b9101614363565b6040805180830381600087803b15801561073b57600080fd5b505af115801561074f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107739190613e8b565b50905061080c565b600480840154604051633164a26560e11b81526001600160a01b038516926362c944ca926107b792600160801b90910460020b918b9101614363565b6040805180830381600087803b1580156107d057600080fd5b505af11580156107e4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108089190613e8b565b5090505b858360010160108282829054906101000a90046001600160801b031661083291906145a8565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808360020160108282829054906101000a90046001600160801b031661087c919061450c565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808360020160008282829054906101000a90046001600160801b03166108c6919061450c565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555050505050509392505050565b33600090815260056020526040812054829081106109265760405162461bcd60e51b815260040161054a906143b8565b33600090815260056020526040902080548290811061095557634e487b7160e01b600052603260045260246000fd5b906000526020600020906005020160040160149054906101000a900460ff166109905760405162461bcd60e51b815260040161054a906143e0565b3360009081526005602052604081208054859081106109bf57634e487b7160e01b600052603260045260246000fd5b600091825260208083206003600590930201828101546001600160801b03600160801b9091041684529190526040909120549091506001600160a01b0316610a0782826122f2565b6001600160801b031695945050505050565b6001600160a01b038116600090815260056020526040812054905b6001600160a01b038316600090815260056020526040902054811015610ac7576001600160a01b0383166000908152600560205260409020805482908110610a8c57634e487b7160e01b600052603260045260246000fd5b906000526020600020906005020160040160149054906101000a900460ff16610ab55792915050565b80610abf8161463a565b915050610a34565b50919050565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190610b1c90309060040161421f565b60206040518083038186803b158015610b3457600080fd5b505afa158015610b48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6c9190613eea565b905082811015610b8e5760405162461bcd60e51b815260040161054a90614405565b8015610c1857604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015610bf657600080fd5b505af1158015610c0a573d6000803e3d6000fd5b50505050610c18828261224f565b505050565b6000808260c0013580421115610c455760405162461bcd60e51b815260040161054a90614456565b610c556040850160208601613a43565b6001600160a01b0316610c6b6020860186613a43565b6001600160a01b031610610ca75760405162461bcd60e51b8152602060048201526003602482015262783c7960e81b604482015260640161054a565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663becbcc6a610ce56020880188613a43565b610cf56040890160208a01613a43565b610d0560608a0160408b01613eb8565b6040518463ffffffff1660e01b8152600401610d2393929190614233565b60206040518083038186803b158015610d3b57600080fd5b505afa158015610d4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d739190613a5f565b9050610d8d81610d8836889003880188613ce8565b6126c1565b90945092506000610dbe8230610da960808a0160608b01613c26565b610db960c08b0160a08c01613bee565b6128d1565b505090506000610e318360405180606001604052808a6000016020810190610de69190613a43565b6001600160a01b031681526020018a6020016020810190610e079190613a43565b6001600160a01b03168152602001610e2560608c0160408d01613eb8565b62ffffff169052612920565b33600090815260056020526040902080549192509089101561109357808981548110610e6d57634e487b7160e01b600052603260045260246000fd5b6000918252602090912060059091020160040154600160a01b900460ff1615610ecb5760405162461bcd60e51b815260206004820152601060248201526f61637469766520636f6e666c6963742160801b604482015260640161054a565b60408051610160810190915283815260208101610eee60a08b0160808c01613e1a565b6001600160801b03168152602001886001600160801b0316815260200160006001600160801b0316815260200160006001600160801b03168152602001876001600160801b03168152602001836001600160801b03168152602001426001600160801b03168152602001896060016020810190610f6b9190613c26565b60020b8152602001610f8360c08b0160a08c01613bee565b1515815260200160011515815250818a81548110610fb157634e487b7160e01b600052603260045260246000fd5b60009182526020918290208351600592909202019081559082015160408301516001600160801b03918216600160801b91831682021760018401556060840151608085015190831690831682021760028085019190915560a085015160c0860151908416908416830217600385015560e08501516004909401805461010087015161012088015161014090980151969095166001600160981b03199091161762ffffff9490920b939093169091021761ffff60981b1916600160981b9315159390930260ff60a01b191692909217600160a01b9115159190910217905561123e565b806040518061016001604052808581526020018a60800160208101906110b99190613e1a565b6001600160801b03168152602001896001600160801b0316815260200160006001600160801b0316815260200160006001600160801b03168152602001886001600160801b03168152602001846001600160801b03168152602001426001600160801b031681526020018a60600160208101906111369190613c26565b60020b815260200161114e60c08c0160a08d01613bee565b15158152600160209182018190528354808201855560009485529382902083516005909502019384559082015160408301516001600160801b03908116600160801b908102928216929092179285019290925560608301516080840151831682029083161760028086019190915560a084015160c08501518416830290841617600386015560e084015160049095018054610100860151610120870151610140909701511515600160a01b0260ff60a01b19971515600160981b029790971661ffff60981b199190940b62ffffff169094026001600160981b031990911696909416959095179290921716171790555b7f2698353c4d06f732989c559a540266c64c36028530473e5af23b864a413a861f8461127060808b0160608c01613c26565b3361128160a08d0160808e01613e1a565b8b8b8e60a00160208101906112969190613bee565b604080516001600160a01b03988916815260029790970b602088015294909616858501526001600160801b03928316606086015290821660808501521660a083015291151560c082015290519081900360e00190a150505050509250929050565b600061130582840184613d99565b905061131e816000015182602001518360400151612a1f565b841561133857611338816000015182606001513388612a6f565b831561135257611352816020015182606001513387612a6f565b5050505050565b6001600160a01b03811660009081526006602052604090206001810154606091906113845750919050565b60018101546001600160401b038111156113ae57634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156113e757816020015b6113d46139bd565b8152602001906001900390816113cc5790505b50815490925060005b60018301548110156115315760018301805461140c8385614537565b6114169190614655565b8154811061143457634e487b7160e01b600052603260045260246000fd5b6000918252602091829020604080516101608101825260059093029091018054835260018101546001600160801b0380821695850195909552600160801b90819004851692840192909252600280820154808616606086015283900485166080850152600382015480861660a0860152839004851660c085015260049091015493841660e0840152908304810b810b900b61010082015260ff600160981b830481161515610120830152600160a01b9092049091161515610140820152845185908390811061151357634e487b7160e01b600052603260045260246000fd5b602002602001018190525080806115299061463a565b9150506113f0565b505050919050565b3360009081526005602052604081205481908590811061156b5760405162461bcd60e51b815260040161054a906143b8565b33600090815260056020526040902080548290811061159a57634e487b7160e01b600052603260045260246000fd5b906000526020600020906005020160040160149054906101000a900460ff166115d55760405162461bcd60e51b815260040161054a906143e0565b33600090815260056020526040812080548890811061160457634e487b7160e01b600052603260045260246000fd5b600091825260208083206003600590930201828101546001600160801b03600160801b9091041684529190526040909120549091506001600160a01b031661164c82826122f2565b5060028201548795506001600160801b03600160801b90910481169086161115611688576002820154600160801b90046001600160801b031694505b60038201548694506001600160801b0390811690851611156116b55760038201546001600160801b031693505b6001600160a01b0389166116c7573098505b600482810154604051636ad1718f60e01b81526001600160a01b038c811693820193909352600160801b8204600290810b900b60248201526001600160801b03808916604483015287166064820152600160981b90910460ff161515608482015290821690636ad1718f9060a4016040805180830381600087803b15801561174e57600080fd5b505af1158015611762573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117869190613e52565b5050848260020160108282829054906101000a90046001600160801b03166117ae91906145a8565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550838260030160008282829054906101000a90046001600160801b03166117f891906145a8565b82546101009290920a6001600160801b038181021990931691831602179091556001840154600160801b90041615905080611860576001830154620186a090611853906001600160801b03600160801b82048116911661454f565b6001600160801b03161190505b6002830154600160801b90046001600160801b031615801561187f5750805b8015611896575060038301546001600160801b0316155b156119885760048301805460ff60a01b1981169182905560408051610160810182528654815260018701546001600160801b03808216602080850191909152600160801b928390048216848601526002808b015480841660608701528490048316608086015260038b015480841660a0870152849004831660c08601529190951660e0840152908504810b810b900b61010082015260ff600160981b850481161515610120830152600160a01b909404909316151561014084015233600090815260069092529020611988917f0000000000000000000000000000000000000000000000000000000000000000612bff565b5050505094509492505050565b61199d6139bd565b6001600160a01b0383166000908152600660205260409020600181015483106119d85760405162461bcd60e51b815260040161054a9061442f565b60018101805482546119eb908690614537565b6119f59190614655565b81548110611a1357634e487b7160e01b600052603260045260246000fd5b6000918252602091829020604080516101608101825260059093029091018054835260018101546001600160801b0380821695850195909552600160801b90819004851692840192909252600280820154808616606086015283900485166080850152600382015480861660a0860152839004851660c085015260049091015493841660e0840152908304810b810b900b61010082015260ff600160981b830481161515610120830152600160a01b90920490911615156101408201529150505b92915050565b6060816001600160401b03811115611b0257634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611b3557816020015b6060815260200190600190039081611b205790505b50905060005b82811015611c545760008030868685818110611b6757634e487b7160e01b600052603260045260246000fd5b9050602002810190611b7991906144c8565b604051611b879291906141f3565b600060405180830381855af49150503d8060008114611bc2576040519150601f19603f3d011682016040523d82523d6000602084013e611bc7565b606091505b509150915081611c1357604481511015611be057600080fd5b60048101905080806020019051810190611bfa9190613c40565b60405162461bcd60e51b815260040161054a91906143a5565b80848481518110611c3457634e487b7160e01b600052603260045260246000fd5b602002602001018190525050508080611c4c9061463a565b915050611b3b565b5092915050565b604051635f65e63560e11b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063becbcc6a90611cae90879087908790600401614233565b60206040518083038186803b158015611cc657600080fd5b505afa158015611cda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cfe9190613a5f565b90505b9392505050565b611d106139bd565b6001600160a01b0383166000908152600560205260409020548210611d475760405162461bcd60e51b815260040161054a9061442f565b6001600160a01b0383166000908152600560205260409020805483908110611d7f57634e487b7160e01b600052603260045260246000fd5b6000918252602091829020604080516101608101825260059093029091018054835260018101546001600160801b0380821695850195909552600160801b90819004851692840192909252600280820154808616606086015283900485166080850152600382015480861660a0860152839004851660c085015260049091015493841660e0840152908304810b810b900b61010082015260ff600160981b830481161515610120830152600160a01b9092049091161515610140820152905092915050565b6001600160a01b0381166000908152600560205260408120546060918291815b81811015611ee8576001600160a01b0386166000908152600560205260409020805482908110611ea457634e487b7160e01b600052603260045260246000fd5b906000526020600020906005020160040160149054906101000a900460ff1615611ed657611ed3600184614537565b92505b80611ee08161463a565b915050611e64565b5081611ef5575050915091565b816001600160401b03811115611f1b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611f44578160200160208202803683370190505b509350816001600160401b03811115611f6d57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611fa657816020015b611f936139bd565b815260200190600190039081611f8b5790505b5092506000915060005b8181101561218f576001600160a01b0386166000908152600560205260409020805482908110611ff057634e487b7160e01b600052603260045260246000fd5b906000526020600020906005020160040160149054906101000a900460ff161561217d578085848151811061203557634e487b7160e01b600052603260045260246000fd5b60200260200101818152505060056000876001600160a01b03166001600160a01b03168152602001908152602001600020818154811061208557634e487b7160e01b600052603260045260246000fd5b6000918252602091829020604080516101608101825260059093029091018054835260018101546001600160801b0380821695850195909552600160801b90819004851692840192909252600280820154808616606086015283900485166080850152600382015480861660a0860152839004851660c085015260049091015493841660e0840152908304810b810b900b61010082015260ff600160981b830481161515610120830152600160a01b9092049091161515610140820152845185908590811061216457634e487b7160e01b600052603260045260246000fd5b602090810291909101015261217a600184614537565b92505b806121878161463a565b915050611fb0565b505050915091565b6040516370a0823160e01b81526000906001600160a01b038516906370a08231906121c690309060040161421f565b60206040518083038186803b1580156121de57600080fd5b505afa1580156121f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122169190613eea565b9050828110156122385760405162461bcd60e51b815260040161054a90614405565b801561224957612249848383612e25565b50505050565b604080516000808252602082019092526001600160a01b0384169083906040516122799190614203565b60006040518083038185875af1925050503d80600081146122b6576040519150601f19603f3d011682016040523d82523d6000602084013e6122bb565b606091505b5050905080610c185760405162461bcd60e51b815260206004820152600360248201526253544560e81b604482015260640161054a565b60048201546000908190600160981b900460ff16156123a257600480850154604051634cd70e9160e01b81526001600160a01b03861692634cd70e919261234892600160801b90910460020b9160009101614363565b6040805180830381600087803b15801561236157600080fd5b505af1158015612375573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123999190613e8b565b91506124349050565b600480850154604051633164a26560e11b81526001600160a01b038616926362c944ca926123df92600160801b90910460020b9160009101614363565b6040805180830381600087803b1580156123f857600080fd5b505af115801561240c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124309190613e8b565b9150505b6004840154600090819061245190600160801b900460020b612f1e565b6004870154909150600090819081906124829089903090600160801b810460020b90600160981b900460ff166128d1565b925092509250858960000154101561254d57600189015460048a01546124c69186918491600160801b90046001600160801b031690600160981b900460ff16613331565b60048a01549097506124f2908990600160801b810460020b908a90600160981b900460ff1660016133de565b60018a015460038b01549198506001600160801b03600160801b9091048116965061251f9189911661450c565b60038a0180546001600160801b0319166001600160801b0392831617905560018a0180549091169055612630565b885461255a9084846134fd565b915061259084838b60010160109054906101000a90046001600160801b03168c60040160139054906101000a900460ff16613565565b60048b015491985095506125be908990600160801b810460020b908a90600160981b900460ff1660006133de565b60038a01549097506125da9088906001600160801b031661450c565b60038a0180546001600160801b0319166001600160801b0392831617905560018a0154612610918791600160801b9004166145a8565b60018a0180546001600160801b03928316600160801b0292169190911790555b8289556004890154604080516001600160a01b038b168152600160801b8304600290810b900b602082015233818301526001600160801b0388811660608301528a166080820152600160981b90920460ff16151560a0830152517f35dbc0879e3456d619a96ce76932eff5c5b51c95db75c6dd2a2ca4aa42560c329160c0908290030190a150505050505092915050565b6000808260a00151156127ce57836001600160a01b031663ff12504e3085606001518660800151604051806080016040528089600001516001600160a01b0316815260200189602001516001600160a01b03168152602001896040015162ffffff168152602001336001600160a01b0316815250604051602001612745919061447b565b6040516020818303038152906040526040518563ffffffff1660e01b8152600401612773949392919061425b565b6040805180830381600087803b15801561278c57600080fd5b505af11580156127a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c49190613e52565b90925090506128ca565b836001600160a01b0316630e1552f03085606001518660800151604051806080016040528089600001516001600160a01b0316815260200189602001516001600160a01b03168152602001896040015162ffffff168152602001336001600160a01b0316815250604051602001612845919061447b565b6040516020818303038152906040526040518563ffffffff1660e01b8152600401612873949392919061425b565b6040805180830381600087803b15801561288c57600080fd5b505af11580156128a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c49190613e52565b90925090505b9250929050565b600080600083156128fb576128ef876128ea8888613698565b6136e5565b91945092509050612916565b61290e876129098888613698565b613781565b919450925090505b9450945094915050565b6001600160a01b0382166000908152600460205260409020546001600160801b031680611ad457600080546001600160801b0316908061295f83614613565b82546001600160801b039182166101009390930a9283029282021916919091179091556001600160a01b03948516600081815260046020908152604080832080549587166001600160801b0319909616861790559382526002815283822087518154908a166001600160a01b03199182161782558883015160019290920180549987015162ffffff16600160a01b026001600160b81b0319909a1692909a1691909117979097179097556003909652942080549093169093179091555090565b612a2a838383611c5b565b6001600160a01b0316336001600160a01b031614610c185760405162461bcd60e51b8152602060048201526002602482015261073760f41b604482015260640161054a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316148015612ab05750804710155b15612bd2577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015612b1057600080fd5b505af1158015612b24573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038681166004830152602482018690527f000000000000000000000000000000000000000000000000000000000000000016935063a9059cbb92506044019050602060405180830381600087803b158015612b9457600080fd5b505af1158015612ba8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bcc9190613c0a565b50612249565b6001600160a01b038316301415612bf357612bee848383612e25565b612249565b612249848484846137b8565b6001830154811115612cf657600183810180548083018255600091825260209182902085516005909202019081559084015160408501516001600160801b03918216600160801b918316820217938301939093556060850151608086015190821690821684021760028084019190915560a086015160c0870151908316908316850217600384015560e0860151600490930180546101008801516101208901516101408a0151969095166001600160981b03199092169190911762ffffff9190930b169094021761ffff60981b1916600160981b9115159190910260ff60a01b191617600160a01b91151591909102179055505050565b8183600101846000015481548110612d1e57634e487b7160e01b600052603260045260246000fd5b600091825260209182902083516005909202019081559082015160408301516001600160801b03908116600160801b9081029282169290921760018085019190915560608501516080860151831684029083161760028086019190915560a086015160c08701518416850290841617600386015560e086015160049095018054610100880151610120890151610140909901511515600160a01b0260ff60a01b19991515600160981b029990991661ffff60981b199190940b62ffffff169096026001600160981b031990911696909416959095179290921792909216179290921790558381015484549091612e149190614537565b612e1e9190614655565b8355505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1790529151600092839290871691612e819190614203565b6000604051808303816000865af19150503d8060008114612ebe576040519150601f19603f3d011682016040523d82523d6000602084013e612ec3565b606091505b5091509150818015612eed575080511580612eed575080806020019051810190612eed9190613c0a565b6113525760405162461bcd60e51b815260206004820152600260248201526114d560f21b604482015260640161054a565b60008060008360020b12612f35578260020b612f42565b8260020b612f429061468a565b9050612f51620d89e719614669565b60020b811115612f875760405162461bcd60e51b81526020600482015260016024820152601560fa1b604482015260640161054a565b600060018216612f9b57600160801b612fad565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b031690506002821615612fe2576080612fdd826ffff97272373d413259a46990580e213a614589565b901c90505b600482161561300c576080613007826ffff2e50f5f656932ef12357cf3c7fdcc614589565b901c90505b6008821615613036576080613031826fffe5caca7e10e4e61c3624eaa0941cd0614589565b901c90505b601082161561306057608061305b826fffcb9843d60f6159c9db58835c926644614589565b901c90505b602082161561308a576080613085826fff973b41fa98c081472e6896dfb254c0614589565b901c90505b60408216156130b45760806130af826fff2ea16466c96a3843ec78b326b52861614589565b901c90505b60808216156130de5760806130d9826ffe5dee046a99a2a811c461f1969c3053614589565b901c90505b610100821615613109576080613104826ffcbe86c7900a88aedcffc83b479aa3a4614589565b901c90505b61020082161561313457608061312f826ff987a7253ac413176f2b074cf7815e54614589565b901c90505b61040082161561315f57608061315a826ff3392b0822b70005940c7a398e4b70f3614589565b901c90505b61080082161561318a576080613185826fe7159475a2c29b7443b29c7fa6e889d9614589565b901c90505b6110008216156131b55760806131b0826fd097f3bdfd2022b8845ad8f792aa5825614589565b901c90505b6120008216156131e05760806131db826fa9f746462d870fdf8a65dc1f90e061e5614589565b901c90505b61400082161561320b576080613206826f70d869a156d2a1b890bb3df62baf32f7614589565b901c90505b618000821615613236576080613231826f31be135f97d08fd981231505542fcfa6614589565b901c90505b6201000082161561326257608061325d826f09aa508b5b7a84e1c677de54f3e99bc9614589565b901c90505b6202000082161561328d576080613288826e5d6af8dedb81196699c329225ee604614589565b901c90505b620400008216156132b75760806132b2826d2216e584f5fa1ea926041bedfe98614589565b901c90505b620800008216156132df5760806132da826b048a170391f7dc42444e8fa2614589565b901c90505b60008460020b13156132fa576132f781600019614575565b90505b61330964010000000082614655565b15613315576001613318565b60005b6133299060ff16602083901c614537565b949350505050565b60006001600160801b038316821561337f57600061335d82886001600160a01b0316600160601b6138c2565b905061337781886001600160a01b0316600160601b6138c2565b9250506133b7565b600061339982600160601b896001600160a01b03166138c2565b90506133b381600160601b896001600160a01b03166138c2565b9250505b846001600160801b0316826001600160801b031611156133d5578491505b50949350505050565b6000821561346f5760405163544e705760e01b81526001600160a01b0387169063544e7057906134169088908890879060040161437f565b602060405180830381600087803b15801561343057600080fd5b505af1158015613444573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134689190613e36565b90506134f4565b604051633c058fbd60e21b81526001600160a01b0387169063f0163ef49061349f9088908890879060040161437f565b602060405180830381600087803b1580156134b957600080fd5b505af11580156134cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134f19190613e36565b90505b95945050505050565b6000838310156135355760405162461bcd60e51b815260206004820152600360248201526241454f60e81b604482015260640161054a565b600061354185856145d0565b9050826001600160801b03168111156133295750506001600160801b031692915050565b8260008083156135b4576000613592846001600160801b0316600160601b8a6001600160a01b031661396f565b90506135ac81600160601b8a6001600160a01b031661396f565b9150506135f5565b60006135d7846001600160801b0316896001600160a01b0316600160601b61396f565b90506135f181896001600160a01b0316600160601b61396f565b9150505b846001600160801b031681111561368b57506001600160801b038416831561365357600061363182896001600160a01b0316600160601b6138c2565b905061364b81896001600160a01b0316600160601b6138c2565b93505061368b565b600061366d82600160601b8a6001600160a01b03166138c2565b905061368781600160601b8a6001600160a01b03166138c2565b9350505b8091505094509492505050565b6040516bffffffffffffffffffffffff19606084901b166020820152600282900b60e81b603482015260009060370160405160208183030381529060405280519060200120905092915050565b600080600080600080876001600160a01b0316631621835f886040518263ffffffff1660e01b815260040161371c91815260200190565b60c06040518083038186803b15801561373457600080fd5b505afa158015613748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376c9190613f5d565b50939950975091955050505050509250925092565b600080600080600080876001600160a01b03166362ccaafd886040518263ffffffff1660e01b815260040161371c91815260200190565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b179052915160009283929088169161381c9190614203565b6000604051808303816000865af19150503d8060008114613859576040519150601f19603f3d011682016040523d82523d6000602084013e61385e565b606091505b50915091508180156138885750805115806138885750808060200190518101906138889190613c0a565b6138ba5760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015260640161054a565b505050505050565b6000808060001985870985870292508281108382030391505080600014156138fc57600084116138f157600080fd5b508290049050611d01565b80841161390857600080fd5b6000848688096001861981018716968790046003810260029081188083028203028083028203028083028203028083028203028083028203029182029003026000889003889004909101858311909403939093029303949094049190911702949350505050565b600061397c8484846138c2565b90506000828061399c57634e487b7160e01b600052601260045260246000fd5b8486091115611d015760001981106139b357600080fd5b806134f48161463a565b6040805161016081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081019190915290565b8035600281900b8114613a2b57600080fd5b919050565b803562ffffff81168114613a2b57600080fd5b600060208284031215613a54578081fd5b8135611d01816146e6565b600060208284031215613a70578081fd5b8151611d01816146e6565b600080600060608486031215613a8f578182fd5b8335613a9a816146e6565b92506020840135613aaa816146e6565b9150613ab860408501613a30565b90509250925092565b60008060408385031215613ad3578182fd5b8235613ade816146e6565b946020939093013593505050565b600080600060608486031215613b00578283fd5b8335613b0b816146e6565b9250602084013591506040840135613b22816146e6565b809150509250925092565b60008060008060808587031215613b42578081fd5b8435613b4d816146e6565b9350602085013592506040850135613b648161470c565b91506060850135613b748161470c565b939692955090935050565b60008060208385031215613b91578182fd5b82356001600160401b0380821115613ba7578384fd5b818501915085601f830112613bba578384fd5b813581811115613bc8578485fd5b8660208260051b8501011115613bdc578485fd5b60209290920196919550909350505050565b600060208284031215613bff578081fd5b8135611d01816146fe565b600060208284031215613c1b578081fd5b8151611d01816146fe565b600060208284031215613c37578081fd5b611d0182613a19565b600060208284031215613c51578081fd5b81516001600160401b0380821115613c67578283fd5b818401915084601f830112613c7a578283fd5b815181811115613c8c57613c8c6146d0565b604051601f8201601f19908116603f01168101908382118183101715613cb457613cb46146d0565b81604052828152876020848701011115613ccc578586fd5b613cdd8360208301602088016145e7565b979650505050505050565b600060e08284031215613cf9578081fd5b60405160e081018181106001600160401b0382111715613d1b57613d1b6146d0565b6040528235613d29816146e6565b81526020830135613d39816146e6565b6020820152613d4a60408401613a30565b6040820152613d5b60608401613a19565b60608201526080830135613d6e8161470c565b608082015260a0830135613d81816146fe565b60a082015260c0928301359281019290925250919050565b600060808284031215613daa578081fd5b604051608081018181106001600160401b0382111715613dcc57613dcc6146d0565b6040528235613dda816146e6565b81526020830135613dea816146e6565b6020820152613dfb60408401613a30565b60408201526060830135613e0e816146e6565b60608201529392505050565b600060208284031215613e2b578081fd5b8135611d018161470c565b600060208284031215613e47578081fd5b8151611d018161470c565b60008060408385031215613e64578182fd5b8251613e6f8161470c565b6020840151909250613e808161470c565b809150509250929050565b60008060408385031215613e9d578182fd5b8251613ea88161470c565b6020939093015192949293505050565b600060208284031215613ec9578081fd5b611d0182613a30565b600060208284031215613ee3578081fd5b5035919050565b600060208284031215613efb578081fd5b5051919050565b60008060408385031215613f14578182fd5b823591506020830135613e80816146e6565b600080828403610100811215613f3a578283fd5b8335925060e0601f1982011215613f4f578182fd5b506020830190509250929050565b60008060008060008060c08789031215613f75578384fd5b865195506020870151613f878161470c565b6040880151909550613f988161470c565b6060880151909450613fa98161470c565b6080880151909350613fba8161470c565b60a0880151909250613fcb8161470c565b809150509295509295509295565b600080600060608486031215613fed578081fd5b833592506020840135613fff8161470c565b929592945050506040919091013590565b60008060008060608587031215614025578182fd5b843593506020850135925060408501356001600160401b0380821115614049578384fd5b818701915087601f83011261405c578384fd5b81358181111561406a578485fd5b88602082850101111561407b578485fd5b95989497505060200194505050565b6000815180845260208085019450808401835b838110156140c4576140b08783516140fb565b61016096909601959082019060010161409d565b509495945050505050565b600081518084526140e78160208601602086016145e7565b601f01601f19169290920160200192915050565b80518252602081015161411960208401826001600160801b03169052565b50604081015161413460408401826001600160801b03169052565b50606081015161414f60608401826001600160801b03169052565b50608081015161416a60808401826001600160801b03169052565b5060a081015161418560a08401826001600160801b03169052565b5060c08101516141a060c08401826001600160801b03169052565b5060e08101516141bb60e08401826001600160801b03169052565b50610100808201516141d18285018260020b9052565b5050610120818101511515908301526101408082015180151582850152612249565b8183823760009101908152919050565b600082516142158184602087016145e7565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b6001600160a01b0385168152600284900b60208201526001600160801b03831660408201526080606082018190526000906134f1908301846140cf565b6000602080830181845280855180835260408601915060408160051b8701019250838701855b828110156142ec57603f198886030184526142da8583516140cf565b945092850192908501906001016142be565b5092979650505050505050565b602081526000611d01602083018461408a565b604080825283519082018190526000906020906060840190828701845b8281101561434557815184529284019290840190600101614329565b50505083810382850152614359818661408a565b9695505050505050565b60029290920b82526001600160801b0316602082015260400190565b60029390930b83526001600160801b039190911660208301521515604082015260600190565b602081526000611d0160208301846140cf565b6020808252600e908201526d4f7574204f66204c656e6774682160901b604082015260600190565b6020808252600b908201526a4e6f74204163746976652160a81b604082015260600190565b60208082526010908201526f0ae8aa89072409cdee8408adcdeeaced60831b604082015260600190565b6020808252600d908201526c09eeae8409ecc4098cadccee8d609b1b604082015260600190565b6020808252600b908201526a4f7574206f662074696d6560a81b604082015260600190565b81516001600160a01b03908116825260208084015182169083015260408084015162ffffff1690830152606092830151169181019190915260800190565b6101608101611ad482846140fb565b6000808335601e198436030181126144de578283fd5b8301803591506001600160401b038211156144f7578283fd5b6020019150368190038213156128ca57600080fd5b60006001600160801b0382811684821680830382111561452e5761452e6146a4565b01949350505050565b6000821982111561454a5761454a6146a4565b500190565b60006001600160801b0383811680614569576145696146ba565b92169190910492915050565b600082614584576145846146ba565b500490565b60008160001904831182151516156145a3576145a36146a4565b500290565b60006001600160801b03838116908316818110156145c8576145c86146a4565b039392505050565b6000828210156145e2576145e26146a4565b500390565b60005b838110156146025781810151838201526020016145ea565b838111156122495750506000910152565b60006001600160801b0382811680821415614630576146306146a4565b6001019392505050565b600060001982141561464e5761464e6146a4565b5060010190565b600082614664576146646146ba565b500690565b60008160020b627fffff19811415614683576146836146a4565b9003919050565b6000600160ff1b8214156146a0576146a06146a4565b0390565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146146fb57600080fd5b50565b80151581146146fb57600080fd5b6001600160801b03811681146146fb57600080fdfea264697066735822122017bd22b1324ce91ba1fe294da4bad195dc99c2f4ff3522d44d5879db43bf9fc364736f6c634300080400330000000000000000000000003ef68d3f7664b2805d4e88381b64868a56f88bc40000000000000000000000005c7f8a570d578ed84e63fdfa7b1ee72deae1ae23

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

0000000000000000000000003ef68d3f7664b2805d4e88381b64868a56f88bc40000000000000000000000005c7f8a570d578ed84e63fdfa7b1ee72deae1ae23

-----Decoded View---------------
Arg [0] : factory (address): 0x3ef68d3f7664b2805d4e88381b64868a56f88bc4
Arg [1] : weth (address): 0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000003ef68d3f7664b2805d4e88381b64868a56f88bc4
Arg [1] : 0000000000000000000000005c7f8a570d578ed84e63fdfa7b1ee72deae1ae23


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.