ETH Price: $3,640.76 (-1.21%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Set Order Disabl...178602382023-08-07 3:00:35519 days ago1691377235IN
0xE85fcb42...841487D84
0 ETH0.0004786913.58088796
Set Order Disabl...178602382023-08-07 3:00:35519 days ago1691377235IN
0xE85fcb42...841487D84
0 ETH0.0004786913.58088796
Set Order Disabl...178602382023-08-07 3:00:35519 days ago1691377235IN
0xE85fcb42...841487D84
0 ETH0.0004786913.58088796
Set Order Disabl...178602372023-08-07 3:00:23519 days ago1691377223IN
0xE85fcb42...841487D84
0 ETH0.0006998113.3684585
Set Order Disabl...178602322023-08-07 2:59:23519 days ago1691377163IN
0xE85fcb42...841487D84
0 ETH0.0004376212.41561628
Set Order Disabl...178602322023-08-07 2:59:23519 days ago1691377163IN
0xE85fcb42...841487D84
0 ETH0.0004376212.41561628
Set Order Disabl...178602322023-08-07 2:59:23519 days ago1691377163IN
0xE85fcb42...841487D84
0 ETH0.0004376212.41561628
Set Order Disabl...178602312023-08-07 2:59:11519 days ago1691377151IN
0xE85fcb42...841487D84
0 ETH0.0006597812.60380934
Set Order Disabl...178602292023-08-07 2:58:47519 days ago1691377127IN
0xE85fcb42...841487D84
0 ETH0.0004684313.2897675
Set Order Disabl...178602292023-08-07 2:58:47519 days ago1691377127IN
0xE85fcb42...841487D84
0 ETH0.0004684313.2897675
Set Order Disabl...178602292023-08-07 2:58:47519 days ago1691377127IN
0xE85fcb42...841487D84
0 ETH0.0004684313.2897675
Set Order Disabl...178602282023-08-07 2:58:35519 days ago1691377115IN
0xE85fcb42...841487D84
0 ETH0.0006857513.09999765
Set Order Disabl...178602252023-08-07 2:57:59519 days ago1691377079IN
0xE85fcb42...841487D84
0 ETH0.0004783213.57027204
Set Order Disabl...178602252023-08-07 2:57:59519 days ago1691377079IN
0xE85fcb42...841487D84
0 ETH0.0004783213.57027204
Set Order Disabl...178602252023-08-07 2:57:59519 days ago1691377079IN
0xE85fcb42...841487D84
0 ETH0.0004783213.57027204
Set Order Disabl...178602242023-08-07 2:57:47519 days ago1691377067IN
0xE85fcb42...841487D84
0 ETH0.0007018813.40806206
Set Order Disabl...178602172023-08-07 2:56:23519 days ago1691376983IN
0xE85fcb42...841487D84
0 ETH0.0004221911.97773764
Set Order Disabl...178602172023-08-07 2:56:23519 days ago1691376983IN
0xE85fcb42...841487D84
0 ETH0.0004221911.97773764
Set Order Disabl...178602172023-08-07 2:56:23519 days ago1691376983IN
0xE85fcb42...841487D84
0 ETH0.0004221911.97773764
Set Order Disabl...178602172023-08-07 2:56:23519 days ago1691376983IN
0xE85fcb42...841487D84
0 ETH0.0006270111.97773764
Set Order Disabl...178602132023-08-07 2:55:35519 days ago1691376935IN
0xE85fcb42...841487D84
0 ETH0.0004351612.34572012
Set Order Disabl...178602122023-08-07 2:55:23519 days ago1691376923IN
0xE85fcb42...841487D84
0 ETH0.0004471212.68500902
Set Order Disabl...178602122023-08-07 2:55:23519 days ago1691376923IN
0xE85fcb42...841487D84
0 ETH0.0004471212.68500902
Set Order Disabl...178602112023-08-07 2:55:11519 days ago1691376911IN
0xE85fcb42...841487D84
0 ETH0.0006384112.19560889
Set Order Disabl...178602002023-08-07 2:52:59519 days ago1691376779IN
0xE85fcb42...841487D84
0 ETH0.0004477112.70186768
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
178601552023-08-07 2:43:59519 days ago1691376239
0xE85fcb42...841487D84
0.00469688 ETH
178601552023-08-07 2:43:59519 days ago1691376239
0xE85fcb42...841487D84
0.00434956 ETH
178600042023-08-07 2:13:23519 days ago1691374403
0xE85fcb42...841487D84
0.00045232 ETH
178600042023-08-07 2:13:23519 days ago1691374403
0xE85fcb42...841487D84
0.00949877 ETH
178593392023-08-06 23:58:47519 days ago1691366327
0xE85fcb42...841487D84
0.00519735 ETH
178593392023-08-06 23:58:47519 days ago1691366327
0xE85fcb42...841487D84
0.00388007 ETH
178591892023-08-06 23:28:11519 days ago1691364491
0xE85fcb42...841487D84
0.00045387 ETH
178591892023-08-06 23:28:11519 days ago1691364491
0xE85fcb42...841487D84
0.00953129 ETH
178585902023-08-06 21:27:35519 days ago1691357255
0xE85fcb42...841487D84
0.00513568 ETH
178585902023-08-06 21:27:35519 days ago1691357255
0xE85fcb42...841487D84
0.00401182 ETH
178585902023-08-06 21:27:35519 days ago1691357255
0xE85fcb42...841487D84
0.00502736 ETH
178585902023-08-06 21:27:35519 days ago1691357255
0xE85fcb42...841487D84
0.00412014 ETH
178584402023-08-06 20:57:11519 days ago1691355431
0xE85fcb42...841487D84
0.00045737 ETH
178584402023-08-06 20:57:11519 days ago1691355431
0xE85fcb42...841487D84
0.00960488 ETH
178584402023-08-06 20:57:11519 days ago1691355431
0xE85fcb42...841487D84
0.00045737 ETH
178584402023-08-06 20:57:11519 days ago1691355431
0xE85fcb42...841487D84
0.00960488 ETH
178583622023-08-06 20:41:35519 days ago1691354495
0xE85fcb42...841487D84
0.00510269 ETH
178583622023-08-06 20:41:35519 days ago1691354495
0xE85fcb42...841487D84
0.00402725 ETH
178582112023-08-06 20:10:59519 days ago1691352659
0xE85fcb42...841487D84
0.00045649 ETH
178582112023-08-06 20:10:59519 days ago1691352659
0xE85fcb42...841487D84
0.00958644 ETH
178581142023-08-06 19:51:35519 days ago1691351495
0xE85fcb42...841487D84
0.00476413 ETH
178581142023-08-06 19:51:35519 days ago1691351495
0xE85fcb42...841487D84
0.00440877 ETH
178579632023-08-06 19:21:11519 days ago1691349671
0xE85fcb42...841487D84
0.00045864 ETH
178579632023-08-06 19:21:11519 days ago1691349671
0xE85fcb42...841487D84
0.00963156 ETH
178578232023-08-06 18:52:47519 days ago1691347967
0xE85fcb42...841487D84
0.00478907 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TwapDelay

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 16 : TwapDelay.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;
pragma abicoder v2;

import './interfaces/ITwapPair.sol';
import './interfaces/ITwapDelay.sol';
import './interfaces/IWETH.sol';
import './libraries/SafeMath.sol';
import './libraries/Orders.sol';
import './libraries/TokenShares.sol';
import './libraries/AddLiquidity.sol';
import './libraries/WithdrawHelper.sol';

contract TwapDelay is ITwapDelay {
    using SafeMath for uint256;
    using Orders for Orders.Data;
    using TokenShares for TokenShares.Data;

    Orders.Data internal orders;
    TokenShares.Data internal tokenShares;

    uint256 private constant ORDER_CANCEL_TIME = 24 hours;
    uint256 private constant BOT_EXECUTION_TIME = 20 minutes;
    uint256 private constant ORDER_LIFESPAN = 48 hours;
    uint16 private constant MAX_TOLERANCE = 10;

    address public override owner;
    mapping(address => bool) public override isBot;

    mapping(address => uint16) public override tolerance;

    constructor(
        address _factory,
        address _weth,
        address _bot
    ) {
        orders.factory = _factory;
        owner = msg.sender;
        isBot[_bot] = true;
        orders.gasPrice = tx.gasprice;
        tokenShares.weth = _weth;
        orders.delay = 30 minutes;
        orders.maxGasLimit = 5_000_000;
        orders.gasPriceInertia = 20_000_000;
        orders.maxGasPriceImpact = 1_000_000;
        orders.setTransferGasCost(address(0), Orders.ETHER_TRANSFER_CALL_COST);

        emit OwnerSet(msg.sender);
    }

    function getTransferGasCost(address token) external view override returns (uint256 gasCost) {
        return orders.transferGasCosts[token];
    }

    function getDepositDisabled(address pair) external view override returns (bool) {
        return orders.getDepositDisabled(pair);
    }

    function getWithdrawDisabled(address pair) external view override returns (bool) {
        return orders.getWithdrawDisabled(pair);
    }

    function getBuyDisabled(address pair) external view override returns (bool) {
        return orders.getBuyDisabled(pair);
    }

    function getSellDisabled(address pair) external view override returns (bool) {
        return orders.getSellDisabled(pair);
    }

    function getOrderStatus(uint256 orderId, uint256 validAfterTimestamp)
        external
        view
        override
        returns (Orders.OrderStatus)
    {
        return orders.getOrderStatus(orderId, validAfterTimestamp);
    }

    uint256 private locked;
    modifier lock() {
        require(locked == 0, 'TD06');
        locked = 1;
        _;
        locked = 0;
    }

    function factory() external view override returns (address) {
        return orders.factory;
    }

    function totalShares(address token) external view override returns (uint256) {
        return tokenShares.totalShares[token];
    }

    // returns wrapped native currency for particular blockchain (WETH or WMATIC)
    function weth() external view override returns (address) {
        return tokenShares.weth;
    }

    function delay() external view override returns (uint256) {
        return orders.delay;
    }

    function lastProcessedOrderId() external view returns (uint256) {
        return orders.lastProcessedOrderId;
    }

    function newestOrderId() external view returns (uint256) {
        return orders.newestOrderId;
    }

    function isOrderCanceled(uint256 orderId) external view returns (bool) {
        return orders.canceled[orderId];
    }

    function maxGasLimit() external view override returns (uint256) {
        return orders.maxGasLimit;
    }

    function maxGasPriceImpact() external view override returns (uint256) {
        return orders.maxGasPriceImpact;
    }

    function gasPriceInertia() external view override returns (uint256) {
        return orders.gasPriceInertia;
    }

    function gasPrice() external view override returns (uint256) {
        return orders.gasPrice;
    }

    function setOrderDisabled(
        address pair,
        Orders.OrderType orderType,
        bool disabled
    ) external payable override {
        require(msg.sender == owner, 'TD00');
        orders.setOrderDisabled(pair, orderType, disabled);
    }

    function setOwner(address _owner) external payable override {
        require(msg.sender == owner, 'TD00');
        // require(_owner != owner, 'TD01'); // Comment out to save size
        require(_owner != address(0), 'TD02');
        owner = _owner;
        emit OwnerSet(_owner);
    }

    function setBot(address _bot, bool _isBot) external payable override {
        require(msg.sender == owner, 'TD00');
        // require(_isBot != isBot[_bot], 'TD01'); // Comment out to save size
        isBot[_bot] = _isBot;
        emit BotSet(_bot, _isBot);
    }

    function setMaxGasLimit(uint256 _maxGasLimit) external payable override {
        require(msg.sender == owner, 'TD00');
        orders.setMaxGasLimit(_maxGasLimit);
    }

    function setDelay(uint32 _delay) external payable override {
        require(msg.sender == owner, 'TD00');
        // require(_delay != orders.delay, 'TD01'); // Comment out to save size
        orders.delay = _delay;
        emit DelaySet(_delay);
    }

    function setGasPriceInertia(uint256 _gasPriceInertia) external payable override {
        require(msg.sender == owner, 'TD00');
        orders.setGasPriceInertia(_gasPriceInertia);
    }

    function setMaxGasPriceImpact(uint256 _maxGasPriceImpact) external payable override {
        require(msg.sender == owner, 'TD00');
        orders.setMaxGasPriceImpact(_maxGasPriceImpact);
    }

    function setTransferGasCost(address token, uint256 gasCost) external payable override {
        require(msg.sender == owner, 'TD00');
        orders.setTransferGasCost(token, gasCost);
    }

    function setTolerance(address pair, uint16 amount) external payable override {
        require(msg.sender == owner, 'TD00');
        require(amount <= MAX_TOLERANCE, 'TD54');
        tolerance[pair] = amount;
        emit ToleranceSet(pair, amount);
    }

    function deposit(Orders.DepositParams calldata depositParams)
        external
        payable
        override
        lock
        returns (uint256 orderId)
    {
        orders.deposit(depositParams, tokenShares);
        return orders.newestOrderId;
    }

    function withdraw(Orders.WithdrawParams calldata withdrawParams)
        external
        payable
        override
        lock
        returns (uint256 orderId)
    {
        orders.withdraw(withdrawParams);
        return orders.newestOrderId;
    }

    function sell(Orders.SellParams calldata sellParams) external payable override lock returns (uint256 orderId) {
        orders.sell(sellParams, tokenShares);
        return orders.newestOrderId;
    }

    function buy(Orders.BuyParams calldata buyParams) external payable override lock returns (uint256 orderId) {
        orders.buy(buyParams, tokenShares);
        return orders.newestOrderId;
    }

    /// @dev This implementation processes orders sequentially and skips orders that have already been executed.
    /// If it encounters an order that is not yet valid, it stops execution since subsequent orders will also be invalid
    /// at the time.
    function execute(Orders.Order[] calldata _orders) external payable override lock {
        uint256 ordersLength = _orders.length;
        uint256 gasBefore = gasleft();
        bool orderExecuted;
        bool senderCanExecute = isBot[msg.sender] || isBot[address(0)];
        for (uint256 i; i < ordersLength; ++i) {
            if (_orders[i].orderId <= orders.lastProcessedOrderId) {
                continue;
            }
            if (orders.canceled[_orders[i].orderId]) {
                orders.dequeueOrder(_orders[i].orderId);
                continue;
            }
            orders.verifyOrder(_orders[i]);
            uint256 validAfterTimestamp = _orders[i].validAfterTimestamp;
            if (validAfterTimestamp >= block.timestamp) {
                break;
            }
            require(senderCanExecute || block.timestamp >= validAfterTimestamp + BOT_EXECUTION_TIME, 'TD00');
            orderExecuted = true;
            if (_orders[i].orderType == Orders.DEPOSIT_TYPE) {
                executeDeposit(_orders[i]);
            } else if (_orders[i].orderType == Orders.WITHDRAW_TYPE) {
                executeWithdraw(_orders[i]);
            } else if (_orders[i].orderType == Orders.SELL_TYPE || _orders[i].orderType == Orders.SELL_INVERTED_TYPE) {
                executeSell(_orders[i]);
            } else if (_orders[i].orderType == Orders.BUY_TYPE || _orders[i].orderType == Orders.BUY_INVERTED_TYPE) {
                executeBuy(_orders[i]);
            }
        }
        if (orderExecuted) {
            orders.updateGasPrice(gasBefore.sub(gasleft()));
        }
    }

    /// @dev The `order` must be verified by calling `Orders.verifyOrder` before calling this function.
    function executeDeposit(Orders.Order calldata order) internal {
        uint256 gasStart = gasleft();
        orders.dequeueOrder(order.orderId);

        (bool executionSuccess, bytes memory data) = address(this).call{
            gas: order.gasLimit.sub(
                Orders.ORDER_BASE_COST.add(orders.transferGasCosts[order.token0]).add(
                    orders.transferGasCosts[order.token1]
                )
            )
        }(abi.encodeWithSelector(this._executeDeposit.selector, order));

        bool refundSuccess = true;
        if (!executionSuccess) {
            refundSuccess = refundTokens(
                order.to,
                order.token0,
                order.value0,
                order.token1,
                order.value1,
                order.unwrap
            );
        }
        finalizeOrder(refundSuccess);
        (uint256 gasUsed, uint256 ethRefund) = refund(order.gasLimit, order.gasPrice, gasStart, order.to);
        emit OrderExecuted(orders.lastProcessedOrderId, executionSuccess, data, gasUsed, ethRefund);
    }

    /// @dev The `order` must be verified by calling `Orders.verifyOrder` before calling this function.
    function executeWithdraw(Orders.Order calldata order) internal {
        uint256 gasStart = gasleft();
        orders.dequeueOrder(order.orderId);

        (bool executionSuccess, bytes memory data) = address(this).call{
            gas: order.gasLimit.sub(Orders.ORDER_BASE_COST.add(Orders.PAIR_TRANSFER_COST))
        }(abi.encodeWithSelector(this._executeWithdraw.selector, order));

        bool refundSuccess = true;
        if (!executionSuccess) {
            (address pair, ) = orders.getPair(order.token0, order.token1);
            refundSuccess = Orders.refundLiquidity(pair, order.to, order.liquidity, this._refundLiquidity.selector);
        }
        finalizeOrder(refundSuccess);
        (uint256 gasUsed, uint256 ethRefund) = refund(order.gasLimit, order.gasPrice, gasStart, order.to);
        emit OrderExecuted(orders.lastProcessedOrderId, executionSuccess, data, gasUsed, ethRefund);
    }

    /// @dev The `order` must be verified by calling `Orders.verifyOrder` before calling this function.
    function executeSell(Orders.Order calldata order) internal {
        uint256 gasStart = gasleft();
        orders.dequeueOrder(order.orderId);

        (bool executionSuccess, bytes memory data) = address(this).call{
            gas: order.gasLimit.sub(Orders.ORDER_BASE_COST.add(orders.transferGasCosts[order.token0]))
        }(abi.encodeWithSelector(this._executeSell.selector, order));

        bool refundSuccess = true;
        if (!executionSuccess) {
            refundSuccess = refundToken(order.token0, order.to, order.value0, order.unwrap);
        }
        finalizeOrder(refundSuccess);
        (uint256 gasUsed, uint256 ethRefund) = refund(order.gasLimit, order.gasPrice, gasStart, order.to);
        emit OrderExecuted(orders.lastProcessedOrderId, executionSuccess, data, gasUsed, ethRefund);
    }

    /// @dev The `order` must be verified by calling `Orders.verifyOrder` before calling this function.
    function executeBuy(Orders.Order calldata order) internal {
        uint256 gasStart = gasleft();
        orders.dequeueOrder(order.orderId);

        (bool executionSuccess, bytes memory data) = address(this).call{
            gas: order.gasLimit.sub(Orders.ORDER_BASE_COST.add(orders.transferGasCosts[order.token0]))
        }(abi.encodeWithSelector(this._executeBuy.selector, order));

        bool refundSuccess = true;
        if (!executionSuccess) {
            refundSuccess = refundToken(order.token0, order.to, order.value0, order.unwrap);
        }
        finalizeOrder(refundSuccess);
        (uint256 gasUsed, uint256 ethRefund) = refund(order.gasLimit, order.gasPrice, gasStart, order.to);
        emit OrderExecuted(orders.lastProcessedOrderId, executionSuccess, data, gasUsed, ethRefund);
    }

    function finalizeOrder(bool refundSuccess) private {
        if (!refundSuccess) {
            orders.markRefundFailed();
        } else {
            orders.forgetLastProcessedOrder();
        }
    }

    function refund(
        uint256 gasLimit,
        uint256 gasPriceInOrder,
        uint256 gasStart,
        address to
    ) private returns (uint256 gasUsed, uint256 leftOver) {
        uint256 feeCollected = gasLimit.mul(gasPriceInOrder);
        gasUsed = gasStart.sub(gasleft()).add(Orders.REFUND_BASE_COST);
        uint256 actualRefund = Math.min(feeCollected, gasUsed.mul(orders.gasPrice));
        leftOver = feeCollected.sub(actualRefund);
        require(refundEth(msg.sender, actualRefund), 'TD40');
        refundEth(payable(to), leftOver);
    }

    function refundEth(address payable to, uint256 value) internal returns (bool success) {
        if (value == 0) {
            return true;
        }
        success = TransferHelper.transferETH(to, value, orders.transferGasCosts[address(0)]);
        emit EthRefund(to, success, value);
    }

    function refundToken(
        address token,
        address to,
        uint256 share,
        bool unwrap
    ) private returns (bool) {
        if (share == 0) {
            return true;
        }
        (bool success, bytes memory data) = address(this).call{ gas: orders.transferGasCosts[token] }(
            abi.encodeWithSelector(this._refundToken.selector, token, to, share, unwrap)
        );
        if (!success) {
            emit RefundFailed(to, token, share, data);
        }
        return success;
    }

    function refundTokens(
        address to,
        address token0,
        uint256 share0,
        address token1,
        uint256 share1,
        bool unwrap
    ) private returns (bool) {
        (bool success, bytes memory data) = address(this).call{
            gas: orders.transferGasCosts[token0].add(orders.transferGasCosts[token1])
        }(abi.encodeWithSelector(this._refundTokens.selector, to, token0, share0, token1, share1, unwrap));
        if (!success) {
            emit RefundFailed(to, token0, share0, data);
            emit RefundFailed(to, token1, share1, data);
        }
        return success;
    }

    function _refundTokens(
        address to,
        address token0,
        uint256 share0,
        address token1,
        uint256 share1,
        bool unwrap
    ) external payable {
        // no need to check sender, because it is checked in _refundToken
        _refundToken(token0, to, share0, unwrap);
        _refundToken(token1, to, share1, unwrap);
    }

    function _refundToken(
        address token,
        address to,
        uint256 share,
        bool unwrap
    ) public payable {
        require(msg.sender == address(this), 'TD00');
        if (token == tokenShares.weth && unwrap) {
            uint256 amount = tokenShares.sharesToAmount(token, share, 0, to);
            IWETH(tokenShares.weth).withdraw(amount);
            TransferHelper.safeTransferETH(to, amount, orders.transferGasCosts[address(0)]);
        } else {
            TransferHelper.safeTransfer(token, to, tokenShares.sharesToAmount(token, share, 0, to));
        }
    }

    function _refundLiquidity(
        address pair,
        address to,
        uint256 liquidity
    ) external payable {
        require(msg.sender == address(this), 'TD00');
        return TransferHelper.safeTransfer(pair, to, liquidity);
    }

    function _executeDeposit(Orders.Order calldata order) external payable {
        require(msg.sender == address(this), 'TD00');
        require(order.validAfterTimestamp + ORDER_LIFESPAN >= block.timestamp, 'TD04');

        (address pair, ) = orders.getPair(order.token0, order.token1);
        (uint256 amount0Left, uint256 amount1Left, uint256 swapToken) = _initialDeposit(order, pair);

        if (order.swap && swapToken != 0) {
            bytes memory data = encodePriceInfo(pair, order.priceAccumulator, order.timestamp);
            if (amount0Left != 0 && swapToken == 1) {
                uint256 extraAmount1;
                (amount0Left, extraAmount1) = AddLiquidity.swapDeposit0(
                    pair,
                    order.token0,
                    amount0Left,
                    order.minSwapPrice,
                    tolerance[pair],
                    data
                );
                amount1Left = amount1Left.add(extraAmount1);
            } else if (amount1Left != 0 && swapToken == 2) {
                uint256 extraAmount0;
                (extraAmount0, amount1Left) = AddLiquidity.swapDeposit1(
                    pair,
                    order.token1,
                    amount1Left,
                    order.maxSwapPrice,
                    tolerance[pair],
                    data
                );
                amount0Left = amount0Left.add(extraAmount0);
            }
        }

        if (amount0Left != 0 && amount1Left != 0) {
            (amount0Left, amount1Left, ) = AddLiquidity.addLiquidityAndMint(
                pair,
                order.to,
                order.token0,
                order.token1,
                amount0Left,
                amount1Left
            );
        }

        AddLiquidity._refundDeposit(order.to, order.token0, order.token1, amount0Left, amount1Left);
    }

    function _initialDeposit(Orders.Order calldata order, address pair)
        private
        returns (
            uint256 amount0Left,
            uint256 amount1Left,
            uint256 swapToken
        )
    {
        uint256 amount0Desired = tokenShares.sharesToAmount(order.token0, order.value0, order.amountLimit0, order.to);
        uint256 amount1Desired = tokenShares.sharesToAmount(order.token1, order.value1, order.amountLimit1, order.to);
        ITwapPair(pair).sync();
        (amount0Left, amount1Left, swapToken) = AddLiquidity.addLiquidityAndMint(
            pair,
            order.to,
            order.token0,
            order.token1,
            amount0Desired,
            amount1Desired
        );
    }

    function _executeWithdraw(Orders.Order calldata order) external payable {
        require(msg.sender == address(this), 'TD00');
        require(order.validAfterTimestamp + ORDER_LIFESPAN >= block.timestamp, 'TD04');
        (address pair, ) = orders.getPair(order.token0, order.token1);
        ITwapPair(pair).sync();
        TransferHelper.safeTransfer(pair, pair, order.liquidity);
        uint256 wethAmount;
        uint256 amount0;
        uint256 amount1;
        if (order.unwrap && (order.token0 == tokenShares.weth || order.token1 == tokenShares.weth)) {
            bool success;
            (success, wethAmount, amount0, amount1) = WithdrawHelper.withdrawAndUnwrap(
                order.token0,
                order.token1,
                pair,
                tokenShares.weth,
                order.to,
                orders.transferGasCosts[address(0)]
            );
            if (!success) {
                tokenShares.onUnwrapFailed(order.to, wethAmount);
            }
        } else {
            (amount0, amount1) = ITwapPair(pair).burn(order.to);
        }
        require(amount0 >= order.value0 && amount1 >= order.value1, 'TD03');
    }

    function _executeBuy(Orders.Order calldata order) external payable {
        require(msg.sender == address(this), 'TD00');
        require(order.validAfterTimestamp + ORDER_LIFESPAN >= block.timestamp, 'TD04');

        (address pairAddress, ) = orders.getPair(order.token0, order.token1);
        uint256 amountInMax = tokenShares.sharesToAmount(order.token0, order.value0, order.amountLimit0, order.to);
        ITwapPair(pairAddress).sync();
        bytes memory priceInfo = encodePriceInfo(pairAddress, order.priceAccumulator, order.timestamp);
        uint256 amountIn;
        uint256 amountOut;
        uint256 reserveOut;
        bool inverted = order.orderType == Orders.BUY_INVERTED_TYPE;
        {
            // scope for reserve out logic, avoids stack too deep errors
            (uint112 reserve0, uint112 reserve1) = ITwapPair(pairAddress).getReserves();
            // subtract 1 to prevent reserve going to 0
            reserveOut = uint256(inverted ? reserve0 : reserve1).sub(1);
        }
        {
            // scope for partial fill logic, avoids stack too deep errors
            address oracle = ITwapPair(pairAddress).oracle();
            uint256 swapFee = ITwapPair(pairAddress).swapFee();
            (amountIn, amountOut) = ITwapOracle(oracle).getSwapAmountInMaxOut(
                inverted,
                swapFee,
                order.value1,
                priceInfo
            );
            uint256 amountInMaxScaled;
            if (amountOut > reserveOut) {
                amountInMaxScaled = amountInMax.mul(reserveOut).ceil_div(order.value1);
                (amountIn, amountOut) = ITwapOracle(oracle).getSwapAmountInMinOut(
                    inverted,
                    swapFee,
                    reserveOut,
                    priceInfo
                );
            } else {
                amountInMaxScaled = amountInMax;
                amountOut = order.value1; // Truncate to desired out
            }
            require(amountInMaxScaled >= amountIn, 'TD08');
            if (amountInMax > amountIn) {
                if (order.token0 == tokenShares.weth && order.unwrap) {
                    _forceEtherTransfer(order.to, amountInMax.sub(amountIn));
                } else {
                    TransferHelper.safeTransfer(order.token0, order.to, amountInMax.sub(amountIn));
                }
            }
            TransferHelper.safeTransfer(order.token0, pairAddress, amountIn);
        }
        amountOut = amountOut.sub(tolerance[pairAddress]);
        uint256 amount0Out;
        uint256 amount1Out;
        if (inverted) {
            amount0Out = amountOut;
        } else {
            amount1Out = amountOut;
        }
        if (order.token1 == tokenShares.weth && order.unwrap) {
            ITwapPair(pairAddress).swap(amount0Out, amount1Out, address(this), priceInfo);
            _forceEtherTransfer(order.to, amountOut);
        } else {
            ITwapPair(pairAddress).swap(amount0Out, amount1Out, order.to, priceInfo);
        }
    }

    function _executeSell(Orders.Order calldata order) external payable {
        require(msg.sender == address(this), 'TD00');
        require(order.validAfterTimestamp + ORDER_LIFESPAN >= block.timestamp, 'TD04');

        (address pairAddress, ) = orders.getPair(order.token0, order.token1);
        ITwapPair(pairAddress).sync();
        bytes memory priceInfo = encodePriceInfo(pairAddress, order.priceAccumulator, order.timestamp);

        bool inverted = order.orderType == Orders.SELL_INVERTED_TYPE;
        uint256 amountOut = _executeSellHelper(order, inverted, pairAddress, priceInfo);

        (uint256 amount0Out, uint256 amount1Out) = inverted ? (amountOut, uint256(0)) : (uint256(0), amountOut);
        if (order.token1 == tokenShares.weth && order.unwrap) {
            ITwapPair(pairAddress).swap(amount0Out, amount1Out, address(this), priceInfo);
            _forceEtherTransfer(order.to, amountOut);
        } else {
            ITwapPair(pairAddress).swap(amount0Out, amount1Out, order.to, priceInfo);
        }
    }

    function _executeSellHelper(
        Orders.Order calldata order,
        bool inverted,
        address pairAddress,
        bytes memory priceInfo
    ) internal returns (uint256 amountOut) {
        uint256 reserveOut;
        {
            // scope for determining reserve out, avoids stack too deep errors
            (uint112 reserve0, uint112 reserve1) = ITwapPair(pairAddress).getReserves();
            // subtract 1 to prevent reserve going to 0
            reserveOut = uint256(inverted ? reserve0 : reserve1).sub(1);
        }
        {
            // scope for calculations, avoids stack too deep errors
            address oracle = ITwapPair(pairAddress).oracle();
            uint256 swapFee = ITwapPair(pairAddress).swapFee();
            uint256 amountIn = tokenShares.sharesToAmount(order.token0, order.value0, order.amountLimit0, order.to);
            amountOut = inverted
                ? ITwapOracle(oracle).getSwapAmount0Out(swapFee, amountIn, priceInfo)
                : ITwapOracle(oracle).getSwapAmount1Out(swapFee, amountIn, priceInfo);

            uint256 amountOutMinScaled;
            if (amountOut > reserveOut) {
                amountOutMinScaled = order.value1.mul(reserveOut).div(amountOut);
                uint256 _amountIn = amountIn;
                (amountIn, amountOut) = ITwapOracle(oracle).getSwapAmountInMinOut(
                    inverted,
                    swapFee,
                    reserveOut,
                    priceInfo
                );
                if (order.token0 == tokenShares.weth && order.unwrap) {
                    _forceEtherTransfer(order.to, _amountIn.sub(amountIn));
                } else {
                    TransferHelper.safeTransfer(order.token0, order.to, _amountIn.sub(amountIn));
                }
            } else {
                amountOutMinScaled = order.value1;
            }
            amountOut = amountOut.sub(tolerance[pairAddress]);
            require(amountOut >= amountOutMinScaled, 'TD37');
            TransferHelper.safeTransfer(order.token0, pairAddress, amountIn);
        }
    }

    function _forceEtherTransfer(address to, uint256 amount) internal {
        IWETH(tokenShares.weth).withdraw(amount);
        (bool success, ) = to.call{ value: amount, gas: orders.transferGasCosts[address(0)] }('');
        if (!success) {
            tokenShares.onUnwrapFailed(to, amount);
        }
    }

    /// @dev The `order` must be verified by calling `Orders.verifyOrder` before calling this function.
    function performRefund(Orders.Order calldata order, bool shouldRefundEth) internal {
        bool canOwnerRefund = order.validAfterTimestamp.add(365 days) < block.timestamp;

        if (order.orderType == Orders.DEPOSIT_TYPE) {
            address to = canOwnerRefund ? owner : order.to;
            require(refundTokens(to, order.token0, order.value0, order.token1, order.value1, order.unwrap), 'TD14');
            if (shouldRefundEth) {
                require(refundEth(payable(to), order.gasPrice.mul(order.gasLimit)), 'TD40');
            }
        } else if (order.orderType == Orders.WITHDRAW_TYPE) {
            (address pair, ) = orders.getPair(order.token0, order.token1);
            address to = canOwnerRefund ? owner : order.to;
            require(Orders.refundLiquidity(pair, to, order.liquidity, this._refundLiquidity.selector), 'TD14');
            if (shouldRefundEth) {
                require(refundEth(payable(to), order.gasPrice.mul(order.gasLimit)), 'TD40');
            }
        } else if (order.orderType == Orders.SELL_TYPE || order.orderType == Orders.SELL_INVERTED_TYPE) {
            address to = canOwnerRefund ? owner : order.to;
            require(refundToken(order.token0, to, order.value0, order.unwrap), 'TD14');
            if (shouldRefundEth) {
                require(refundEth(payable(to), order.gasPrice.mul(order.gasLimit)), 'TD40');
            }
        } else if (order.orderType == Orders.BUY_TYPE || order.orderType == Orders.BUY_INVERTED_TYPE) {
            address to = canOwnerRefund ? owner : order.to;
            require(refundToken(order.token0, to, order.value0, order.unwrap), 'TD14');
            if (shouldRefundEth) {
                require(refundEth(payable(to), order.gasPrice.mul(order.gasLimit)), 'TD40');
            }
        } else {
            return;
        }
        orders.forgetOrder(order.orderId);
    }

    function retryRefund(Orders.Order calldata order) external override lock {
        orders.verifyOrder(order);
        require(orders.refundFailed[order.orderId], 'TD21');
        performRefund(order, false);
    }

    function cancelOrder(Orders.Order calldata order) external override lock {
        orders.verifyOrder(order);
        require(
            orders.getOrderStatus(order.orderId, order.validAfterTimestamp) == Orders.OrderStatus.EnqueuedReady,
            'TD52'
        );
        require(order.validAfterTimestamp.sub(orders.delay).add(ORDER_CANCEL_TIME) < block.timestamp, 'TD1C');
        orders.canceled[order.orderId] = true;
        performRefund(order, true);
    }

    function encodePriceInfo(
        address pair,
        uint256 priceAccumulator,
        uint256 priceTimestamp
    ) internal view returns (bytes memory data) {
        uint256 price = ITwapOracle(ITwapPair(pair).oracle()).getAveragePrice(priceAccumulator, priceTimestamp);
        // Pack everything as 32 bytes / uint256 to simplify decoding
        data = abi.encode(price);
    }

    receive() external payable {}
}

File 2 of 16 : IERC20.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

interface IERC20 {
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Transfer(address indexed from, address indexed to, uint256 value);

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

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

    function decimals() external view returns (uint8);

    function totalSupply() external view returns (uint256);

    function balanceOf(address owner) external view returns (uint256);

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 value) external returns (bool);

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

    function transferFrom(
        address from,
        address to,
        uint256 value
    ) external returns (bool);
}

File 3 of 16 : IReserves.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

interface IReserves {
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1);

    function getFees() external view returns (uint256 fee0, uint256 fee1);
}

File 4 of 16 : ITwapDelay.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;
pragma abicoder v2;

import '../libraries/Orders.sol';

interface ITwapDelay {
    event OrderExecuted(uint256 indexed id, bool indexed success, bytes data, uint256 gasSpent, uint256 ethRefunded);
    event RefundFailed(address indexed to, address indexed token, uint256 amount, bytes data);
    event EthRefund(address indexed to, bool indexed success, uint256 value);
    event OwnerSet(address owner);
    event BotSet(address bot, bool isBot);
    event DelaySet(uint256 delay);
    event MaxGasLimitSet(uint256 maxGasLimit);
    event GasPriceInertiaSet(uint256 gasPriceInertia);
    event MaxGasPriceImpactSet(uint256 maxGasPriceImpact);
    event TransferGasCostSet(address token, uint256 gasCost);
    event ToleranceSet(address pair, uint16 amount);
    event OrderDisabled(address pair, Orders.OrderType orderType, bool disabled);
    event UnwrapFailed(address to, uint256 amount);

    function factory() external returns (address);

    function owner() external returns (address);

    function isBot(address bot) external returns (bool);

    function tolerance(address pair) external returns (uint16);

    function gasPriceInertia() external returns (uint256);

    function gasPrice() external view returns (uint256);

    function maxGasPriceImpact() external returns (uint256);

    function maxGasLimit() external returns (uint256);

    function delay() external returns (uint256);

    function totalShares(address token) external returns (uint256);

    function weth() external returns (address);

    function getTransferGasCost(address token) external returns (uint256);

    function getDepositDisabled(address pair) external returns (bool);

    function getWithdrawDisabled(address pair) external returns (bool);

    function getBuyDisabled(address pair) external returns (bool);

    function getSellDisabled(address pair) external returns (bool);

    function getOrderStatus(uint256 orderId, uint256 validAfterTimestamp) external view returns (Orders.OrderStatus);

    function setOrderDisabled(
        address pair,
        Orders.OrderType orderType,
        bool disabled
    ) external payable;

    function setOwner(address _owner) external payable;

    function setBot(address _bot, bool _isBot) external payable;

    function setMaxGasLimit(uint256 _maxGasLimit) external payable;

    function setDelay(uint32 _delay) external payable;

    function setGasPriceInertia(uint256 _gasPriceInertia) external payable;

    function setMaxGasPriceImpact(uint256 _maxGasPriceImpact) external payable;

    function setTransferGasCost(address token, uint256 gasCost) external payable;

    function setTolerance(address pair, uint16 amount) external payable;

    function deposit(Orders.DepositParams memory depositParams) external payable returns (uint256 orderId);

    function withdraw(Orders.WithdrawParams memory withdrawParams) external payable returns (uint256 orderId);

    function sell(Orders.SellParams memory sellParams) external payable returns (uint256 orderId);

    function buy(Orders.BuyParams memory buyParams) external payable returns (uint256 orderId);

    function execute(Orders.Order[] calldata orders) external payable;

    function retryRefund(Orders.Order calldata order) external;

    function cancelOrder(Orders.Order calldata order) external;
}

File 5 of 16 : ITwapERC20.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

import './IERC20.sol';

interface ITwapERC20 is IERC20 {
    function PERMIT_TYPEHASH() external pure returns (bytes32);

    function nonces(address owner) external view returns (uint256);

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);

    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);
}

File 6 of 16 : ITwapFactory.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

interface ITwapFactory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint256);
    event OwnerSet(address owner);

    function owner() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);

    function allPairs(uint256) external view returns (address pair);

    function allPairsLength() external view returns (uint256);

    function createPair(
        address tokenA,
        address tokenB,
        address oracle,
        address trader
    ) external returns (address pair);

    function setOwner(address) external;

    function setMintFee(
        address tokenA,
        address tokenB,
        uint256 fee
    ) external;

    function setBurnFee(
        address tokenA,
        address tokenB,
        uint256 fee
    ) external;

    function setSwapFee(
        address tokenA,
        address tokenB,
        uint256 fee
    ) external;

    function setOracle(
        address tokenA,
        address tokenB,
        address oracle
    ) external;

    function setTrader(
        address tokenA,
        address tokenB,
        address trader
    ) external;

    function collect(
        address tokenA,
        address tokenB,
        address to
    ) external;

    function withdraw(
        address tokenA,
        address tokenB,
        uint256 amount,
        address to
    ) external;
}

File 7 of 16 : ITwapOracle.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

interface ITwapOracle {
    event OwnerSet(address owner);
    event UniswapPairSet(address uniswapPair);

    function decimalsConverter() external view returns (int256);

    function xDecimals() external view returns (uint8);

    function yDecimals() external view returns (uint8);

    function owner() external view returns (address);

    function uniswapPair() external view returns (address);

    function getPriceInfo() external view returns (uint256 priceAccumulator, uint256 priceTimestamp);

    function getSpotPrice() external view returns (uint256);

    function getAveragePrice(uint256 priceAccumulator, uint256 priceTimestamp) external view returns (uint256);

    function setOwner(address _owner) external;

    function setUniswapPair(address _uniswapPair) external;

    function tradeX(
        uint256 xAfter,
        uint256 xBefore,
        uint256 yBefore,
        bytes calldata data
    ) external view returns (uint256 yAfter);

    function tradeY(
        uint256 yAfter,
        uint256 yBefore,
        uint256 xBefore,
        bytes calldata data
    ) external view returns (uint256 xAfter);

    function depositTradeXIn(
        uint256 xLeft,
        uint256 xBefore,
        uint256 yBefore,
        bytes calldata data
    ) external view returns (uint256 xIn);

    function depositTradeYIn(
        uint256 yLeft,
        uint256 yBefore,
        uint256 xBefore,
        bytes calldata data
    ) external view returns (uint256 yIn);

    function getSwapAmount0Out(
        uint256 swapFee,
        uint256 amount1In,
        bytes calldata data
    ) external view returns (uint256 amount0Out);

    function getSwapAmount1Out(
        uint256 swapFee,
        uint256 amount0In,
        bytes calldata data
    ) external view returns (uint256 amount1Out);

    function getSwapAmountInMaxOut(
        bool inverse,
        uint256 swapFee,
        uint256 _amountOut,
        bytes calldata data
    ) external view returns (uint256 amountIn, uint256 amountOut);

    function getSwapAmountInMinOut(
        bool inverse,
        uint256 swapFee,
        uint256 _amountOut,
        bytes calldata data
    ) external view returns (uint256 amountIn, uint256 amountOut);
}

File 8 of 16 : ITwapPair.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

import './ITwapERC20.sol';
import './IReserves.sol';

interface ITwapPair is ITwapERC20, IReserves {
    event Mint(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 liquidityOut, address indexed to);
    event Burn(address indexed sender, uint256 amount0Out, uint256 amount1Out, uint256 liquidityIn, address indexed to);
    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event SetMintFee(uint256 fee);
    event SetBurnFee(uint256 fee);
    event SetSwapFee(uint256 fee);
    event SetOracle(address account);
    event SetTrader(address trader);

    function MINIMUM_LIQUIDITY() external pure returns (uint256);

    function factory() external view returns (address);

    function token0() external view returns (address);

    function token1() external view returns (address);

    function oracle() external view returns (address);

    function trader() external view returns (address);

    function mintFee() external view returns (uint256);

    function setMintFee(uint256 fee) external;

    function mint(address to) external returns (uint256 liquidity);

    function burnFee() external view returns (uint256);

    function setBurnFee(uint256 fee) external;

    function burn(address to) external returns (uint256 amount0, uint256 amount1);

    function swapFee() external view returns (uint256);

    function setSwapFee(uint256 fee) external;

    function setOracle(address account) external;

    function setTrader(address account) external;

    function collect(address to) external;

    function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external;

    function sync() external;

    function initialize(
        address _token0,
        address _token1,
        address _oracle,
        address _trader
    ) external;

    function getSwapAmount0In(uint256 amount1Out, bytes calldata data) external view returns (uint256 swapAmount0In);

    function getSwapAmount1In(uint256 amount0Out, bytes calldata data) external view returns (uint256 swapAmount1In);

    function getSwapAmount0Out(uint256 amount1In, bytes calldata data) external view returns (uint256 swapAmount0Out);

    function getSwapAmount1Out(uint256 amount0In, bytes calldata data) external view returns (uint256 swapAmount1Out);

    function getDepositAmount0In(uint256 amount0, bytes calldata data) external view returns (uint256 depositAmount0In);

    function getDepositAmount1In(uint256 amount1, bytes calldata data) external view returns (uint256 depositAmount1In);
}

File 9 of 16 : IWETH.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

interface IWETH {
    function deposit() external payable;

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

    function withdraw(uint256) external;
}

File 10 of 16 : AddLiquidity.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

import './TransferHelper.sol';
import './SafeMath.sol';
import './Math.sol';
import '../interfaces/ITwapPair.sol';
import '../interfaces/ITwapOracle.sol';

library AddLiquidity {
    using SafeMath for uint256;

    function addLiquidity(
        address pair,
        uint256 amount0Desired,
        uint256 amount1Desired
    )
        internal
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 swapToken
        )
    {
        if (amount0Desired == 0 || amount1Desired == 0) {
            if (amount0Desired > 0) {
                swapToken = 1;
            } else if (amount1Desired > 0) {
                swapToken = 2;
            }
            return (0, 0, swapToken);
        }
        (uint256 reserve0, uint256 reserve1) = ITwapPair(pair).getReserves();
        if (reserve0 == 0 && reserve1 == 0) {
            (amount0, amount1) = (amount0Desired, amount1Desired);
        } else {
            require(reserve0 > 0 && reserve1 > 0, 'AL07');
            uint256 amount1Optimal = amount0Desired.mul(reserve1) / reserve0;
            if (amount1Optimal <= amount1Desired) {
                swapToken = 2;
                (amount0, amount1) = (amount0Desired, amount1Optimal);
            } else {
                uint256 amount0Optimal = amount1Desired.mul(reserve0) / reserve1;
                assert(amount0Optimal <= amount0Desired);
                swapToken = 1;
                (amount0, amount1) = (amount0Optimal, amount1Desired);
            }

            uint256 totalSupply = ITwapPair(pair).totalSupply();
            uint256 liquidityOut = Math.min(amount0.mul(totalSupply) / reserve0, amount1.mul(totalSupply) / reserve1);
            if (liquidityOut == 0) {
                amount0 = 0;
                amount1 = 0;
            }
        }
    }

    function addLiquidityAndMint(
        address pair,
        address to,
        address token0,
        address token1,
        uint256 amount0Desired,
        uint256 amount1Desired
    )
        external
        returns (
            uint256 amount0Left,
            uint256 amount1Left,
            uint256 swapToken
        )
    {
        uint256 amount0;
        uint256 amount1;
        (amount0, amount1, swapToken) = addLiquidity(pair, amount0Desired, amount1Desired);
        if (amount0 == 0 || amount1 == 0) {
            return (amount0Desired, amount1Desired, swapToken);
        }
        TransferHelper.safeTransfer(token0, pair, amount0);
        TransferHelper.safeTransfer(token1, pair, amount1);
        ITwapPair(pair).mint(to);

        amount0Left = amount0Desired.sub(amount0);
        amount1Left = amount1Desired.sub(amount1);
    }

    function swapDeposit0(
        address pair,
        address token0,
        uint256 amount0,
        uint256 minSwapPrice,
        uint16 tolerance,
        bytes calldata data
    ) external returns (uint256 amount0Left, uint256 amount1Left) {
        uint256 amount0In = ITwapPair(pair).getDepositAmount0In(amount0, data);
        amount1Left = ITwapPair(pair).getSwapAmount1Out(amount0In, data).sub(tolerance);
        if (amount1Left == 0) {
            return (amount0, amount1Left);
        }
        uint256 price = getPrice(amount0In, amount1Left, pair);
        require(minSwapPrice == 0 || price >= minSwapPrice, 'AL15');
        TransferHelper.safeTransfer(token0, pair, amount0In);
        ITwapPair(pair).swap(0, amount1Left, address(this), data);
        amount0Left = amount0.sub(amount0In);
    }

    function swapDeposit1(
        address pair,
        address token1,
        uint256 amount1,
        uint256 maxSwapPrice,
        uint16 tolerance,
        bytes calldata data
    ) external returns (uint256 amount0Left, uint256 amount1Left) {
        uint256 amount1In = ITwapPair(pair).getDepositAmount1In(amount1, data);
        amount0Left = ITwapPair(pair).getSwapAmount0Out(amount1In, data).sub(tolerance);
        if (amount0Left == 0) {
            return (amount0Left, amount1);
        }
        uint256 price = getPrice(amount0Left, amount1In, pair);
        require(maxSwapPrice == 0 || price <= maxSwapPrice, 'AL16');
        TransferHelper.safeTransfer(token1, pair, amount1In);
        ITwapPair(pair).swap(amount0Left, 0, address(this), data);
        amount1Left = amount1.sub(amount1In);
    }

    function getPrice(
        uint256 amount0,
        uint256 amount1,
        address pair
    ) internal view returns (uint256) {
        ITwapOracle oracle = ITwapOracle(ITwapPair(pair).oracle());
        return amount1.mul(uint256(oracle.decimalsConverter())).div(amount0);
    }

    function _refundDeposit(
        address to,
        address token0,
        address token1,
        uint256 amount0,
        uint256 amount1
    ) internal {
        if (amount0 > 0) {
            TransferHelper.safeTransfer(token0, to, amount0);
        }
        if (amount1 > 0) {
            TransferHelper.safeTransfer(token1, to, amount1);
        }
    }
}

File 11 of 16 : Math.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

// a library for performing various math operations

library Math {
    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = x < y ? x : y;
    }

    function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = x > y ? x : y;
    }

    // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
    }
}

File 12 of 16 : Orders.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;
pragma abicoder v2;

import './SafeMath.sol';
import '../libraries/Math.sol';
import '../interfaces/ITwapFactory.sol';
import '../interfaces/ITwapPair.sol';
import '../interfaces/ITwapOracle.sol';
import '../libraries/TokenShares.sol';

library Orders {
    using SafeMath for uint256;
    using TokenShares for TokenShares.Data;
    using TransferHelper for address;

    enum OrderType {
        Empty,
        Deposit,
        Withdraw,
        Sell,
        Buy
    }
    enum OrderStatus {
        NonExistent,
        EnqueuedWaiting,
        EnqueuedReady,
        ExecutedSucceeded,
        ExecutedFailed,
        Canceled
    }

    event MaxGasLimitSet(uint256 maxGasLimit);
    event GasPriceInertiaSet(uint256 gasPriceInertia);
    event MaxGasPriceImpactSet(uint256 maxGasPriceImpact);
    event TransferGasCostSet(address token, uint256 gasCost);

    event DepositEnqueued(uint256 indexed orderId, Order order);
    event WithdrawEnqueued(uint256 indexed orderId, Order order);
    event SellEnqueued(uint256 indexed orderId, Order order);
    event BuyEnqueued(uint256 indexed orderId, Order order);

    event OrderDisabled(address pair, Orders.OrderType orderType, bool disabled);

    event RefundFailed(address indexed to, address indexed token, uint256 amount, bytes data);

    uint256 public constant DEPOSIT_TYPE = 1;
    uint256 public constant WITHDRAW_TYPE = 2;
    uint256 public constant BUY_TYPE = 3;
    uint256 public constant BUY_INVERTED_TYPE = 4;
    uint256 public constant SELL_TYPE = 5;
    uint256 public constant SELL_INVERTED_TYPE = 6;

    uint256 private constant ETHER_TRANSFER_COST = 2600 + 1504; // EIP-2929 acct access cost + Gnosis Safe receive ETH cost
    uint256 private constant BUFFER_COST = 10000;
    uint256 private constant ORDER_EXECUTED_EVENT_COST = 3700;
    uint256 private constant EXECUTE_PREPARATION_COST = 55000; // dequeue + getPair in execute

    uint256 public constant ETHER_TRANSFER_CALL_COST = 10000;
    uint256 public constant PAIR_TRANSFER_COST = 55000;
    uint256 public constant REFUND_BASE_COST = 2 * ETHER_TRANSFER_COST + BUFFER_COST + ORDER_EXECUTED_EVENT_COST;
    uint256 public constant ORDER_BASE_COST = EXECUTE_PREPARATION_COST + REFUND_BASE_COST;

    // Masks used for setting order disabled
    // Different bits represent different order types
    uint8 private constant DEPOSIT_MASK = uint8(1 << uint8(OrderType.Deposit)); //   00000010
    uint8 private constant WITHDRAW_MASK = uint8(1 << uint8(OrderType.Withdraw)); // 00000100
    uint8 private constant SELL_MASK = uint8(1 << uint8(OrderType.Sell)); //         00001000
    uint8 private constant BUY_MASK = uint8(1 << uint8(OrderType.Buy)); //           00010000

    struct Data {
        uint256 delay;
        uint256 newestOrderId;
        uint256 lastProcessedOrderId;
        mapping(uint256 => bytes32) orderQueue;
        address factory;
        uint256 maxGasLimit;
        uint256 gasPrice;
        uint256 gasPriceInertia;
        uint256 maxGasPriceImpact;
        mapping(address => uint256) transferGasCosts;
        mapping(uint256 => bool) canceled;
        // Bit on specific positions indicates whether order type is disabled (1) or enabled (0) on specific pair
        mapping(address => uint8) orderDisabled;
        mapping(uint256 => bool) refundFailed;
    }

    struct Order {
        uint256 orderId;
        uint256 orderType;
        uint256 validAfterTimestamp;
        bool unwrap;
        uint256 timestamp;
        uint256 gasLimit;
        uint256 gasPrice;
        uint256 liquidity;
        uint256 value0; // Deposit: share0, Withdraw: amount0Min, Sell: shareIn, Buy: shareInMax
        uint256 value1; // Deposit: share1, Withdraw: amount1Min, Sell: amountOutMin, Buy: amountOut
        address token0; // Sell: tokenIn, Buy: tokenIn
        address token1; // Sell: tokenOut, Buy: tokenOut
        address to;
        uint256 minSwapPrice;
        uint256 maxSwapPrice;
        bool swap;
        uint256 priceAccumulator;
        uint256 amountLimit0;
        uint256 amountLimit1;
    }

    function getOrderStatus(
        Data storage data,
        uint256 orderId,
        uint256 validAfterTimestamp
    ) internal view returns (OrderStatus) {
        if (orderId > data.newestOrderId) {
            return OrderStatus.NonExistent;
        }
        if (data.canceled[orderId]) {
            return OrderStatus.Canceled;
        }
        if (data.refundFailed[orderId]) {
            return OrderStatus.ExecutedFailed;
        }
        if (data.orderQueue[orderId] == bytes32(0)) {
            return OrderStatus.ExecutedSucceeded;
        }
        if (validAfterTimestamp >= block.timestamp) {
            return OrderStatus.EnqueuedWaiting;
        }
        return OrderStatus.EnqueuedReady;
    }

    function getPair(
        Data storage data,
        address tokenA,
        address tokenB
    ) internal view returns (address pair, bool inverted) {
        pair = ITwapFactory(data.factory).getPair(tokenA, tokenB);
        require(pair != address(0), 'OS17');
        inverted = tokenA > tokenB;
    }

    function getDepositDisabled(Data storage data, address pair) internal view returns (bool) {
        return data.orderDisabled[pair] & DEPOSIT_MASK != 0;
    }

    function getWithdrawDisabled(Data storage data, address pair) internal view returns (bool) {
        return data.orderDisabled[pair] & WITHDRAW_MASK != 0;
    }

    function getSellDisabled(Data storage data, address pair) internal view returns (bool) {
        return data.orderDisabled[pair] & SELL_MASK != 0;
    }

    function getBuyDisabled(Data storage data, address pair) internal view returns (bool) {
        return data.orderDisabled[pair] & BUY_MASK != 0;
    }

    function setOrderDisabled(
        Data storage data,
        address pair,
        Orders.OrderType orderType,
        bool disabled
    ) external {
        require(orderType != Orders.OrderType.Empty, 'OS32');
        uint8 currentSettings = data.orderDisabled[pair];

        // zeros with 1 bit set at position specified by orderType
        uint8 mask = uint8(1 << uint8(orderType));

        // set/unset a bit accordingly to 'disabled' value
        if (disabled) {
            // OR operation to disable order
            // e.g. for disable DEPOSIT
            // currentSettings   = 00010100 (BUY and WITHDRAW disabled)
            // mask for DEPOSIT  = 00000010
            // the result of OR  = 00010110
            currentSettings = currentSettings | mask;
        } else {
            // AND operation with a mask negation to enable order
            // e.g. for enable DEPOSIT
            // currentSettings   = 00010100 (BUY and WITHDRAW disabled)
            // 0xff              = 11111111
            // mask for Deposit  = 00000010
            // mask negation     = 11111101
            // the result of AND = 00010100
            currentSettings = currentSettings & (mask ^ 0xff);
        }
        require(currentSettings != data.orderDisabled[pair], 'OS01');
        data.orderDisabled[pair] = currentSettings;

        emit OrderDisabled(pair, orderType, disabled);
    }

    function markRefundFailed(Data storage data) internal {
        data.refundFailed[data.lastProcessedOrderId] = true;
    }

    /// @dev The passed in order.oderId is ignored and overwritten with the correct value, i.e. an updated data.newestOrderId.
    /// This is done to ensure atomicity of these two actions while optimizing gas usage - adding an order to the queue and incrementing
    /// data.newestOrderId (which should not be done anywhere else in the contract).
    /// Must only be called on verified orders.
    function enqueueOrder(Data storage data, Order memory order) internal {
        order.orderId = ++data.newestOrderId;
        data.orderQueue[order.orderId] = getOrderDigest(order);
    }

    struct DepositParams {
        address token0;
        address token1;
        uint256 amount0;
        uint256 amount1;
        uint256 minSwapPrice;
        uint256 maxSwapPrice;
        bool wrap;
        bool swap;
        address to;
        uint256 gasLimit;
        uint32 submitDeadline;
    }

    function deposit(
        Data storage data,
        DepositParams calldata depositParams,
        TokenShares.Data storage tokenShares
    ) external {
        {
            // scope for checks, avoids stack too deep errors
            uint256 token0TransferCost = data.transferGasCosts[depositParams.token0];
            uint256 token1TransferCost = data.transferGasCosts[depositParams.token1];
            require(token0TransferCost != 0 && token1TransferCost != 0, 'OS0F');
            checkOrderParams(
                data,
                depositParams.to,
                depositParams.gasLimit,
                depositParams.submitDeadline,
                ORDER_BASE_COST.add(token0TransferCost).add(token1TransferCost)
            );
        }
        require(depositParams.amount0 != 0 || depositParams.amount1 != 0, 'OS25');
        (address pairAddress, bool inverted) = getPair(data, depositParams.token0, depositParams.token1);
        require(!getDepositDisabled(data, pairAddress), 'OS46');
        {
            // scope for value, avoids stack too deep errors
            uint256 value = msg.value;

            // allocate gas refund
            if (depositParams.wrap) {
                if (depositParams.token0 == tokenShares.weth) {
                    value = msg.value.sub(depositParams.amount0, 'OS1E');
                } else if (depositParams.token1 == tokenShares.weth) {
                    value = msg.value.sub(depositParams.amount1, 'OS1E');
                }
            }
            allocateGasRefund(data, value, depositParams.gasLimit);
        }

        uint256 shares0 = tokenShares.amountToShares(
            inverted ? depositParams.token1 : depositParams.token0,
            inverted ? depositParams.amount1 : depositParams.amount0,
            depositParams.wrap
        );
        uint256 shares1 = tokenShares.amountToShares(
            inverted ? depositParams.token0 : depositParams.token1,
            inverted ? depositParams.amount0 : depositParams.amount1,
            depositParams.wrap
        );

        (uint256 priceAccumulator, uint256 timestamp) = ITwapOracle(ITwapPair(pairAddress).oracle()).getPriceInfo();

        Order memory order = Order(
            0,
            DEPOSIT_TYPE,
            timestamp + data.delay, // validAfterTimestamp
            depositParams.wrap,
            timestamp,
            depositParams.gasLimit,
            data.gasPrice,
            0, // liquidity
            shares0,
            shares1,
            inverted ? depositParams.token1 : depositParams.token0,
            inverted ? depositParams.token0 : depositParams.token1,
            depositParams.to,
            depositParams.minSwapPrice,
            depositParams.maxSwapPrice,
            depositParams.swap,
            priceAccumulator,
            inverted ? depositParams.amount1 : depositParams.amount0,
            inverted ? depositParams.amount0 : depositParams.amount1
        );
        enqueueOrder(data, order);

        emit DepositEnqueued(order.orderId, order);
    }

    struct WithdrawParams {
        address token0;
        address token1;
        uint256 liquidity;
        uint256 amount0Min;
        uint256 amount1Min;
        bool unwrap;
        address to;
        uint256 gasLimit;
        uint32 submitDeadline;
    }

    function withdraw(Data storage data, WithdrawParams calldata withdrawParams) external {
        (address pair, bool inverted) = getPair(data, withdrawParams.token0, withdrawParams.token1);
        require(!getWithdrawDisabled(data, pair), 'OS0A');
        checkOrderParams(
            data,
            withdrawParams.to,
            withdrawParams.gasLimit,
            withdrawParams.submitDeadline,
            ORDER_BASE_COST.add(PAIR_TRANSFER_COST)
        );
        require(withdrawParams.liquidity != 0, 'OS22');

        allocateGasRefund(data, msg.value, withdrawParams.gasLimit);
        pair.safeTransferFrom(msg.sender, address(this), withdrawParams.liquidity);

        Order memory order = Order(
            0,
            WITHDRAW_TYPE,
            block.timestamp + data.delay, // validAfterTimestamp
            withdrawParams.unwrap,
            0, // timestamp
            withdrawParams.gasLimit,
            data.gasPrice,
            withdrawParams.liquidity,
            inverted ? withdrawParams.amount1Min : withdrawParams.amount0Min,
            inverted ? withdrawParams.amount0Min : withdrawParams.amount1Min,
            inverted ? withdrawParams.token1 : withdrawParams.token0,
            inverted ? withdrawParams.token0 : withdrawParams.token1,
            withdrawParams.to,
            0, // minSwapPrice
            0, // maxSwapPrice
            false, // swap
            0, // priceAccumulator
            0, // amountLimit0
            0 // amountLimit1
        );
        enqueueOrder(data, order);

        emit WithdrawEnqueued(order.orderId, order);
    }

    struct SellParams {
        address tokenIn;
        address tokenOut;
        uint256 amountIn;
        uint256 amountOutMin;
        bool wrapUnwrap;
        address to;
        uint256 gasLimit;
        uint32 submitDeadline;
    }

    function sell(
        Data storage data,
        SellParams calldata sellParams,
        TokenShares.Data storage tokenShares
    ) external {
        uint256 tokenTransferCost = data.transferGasCosts[sellParams.tokenIn];
        require(tokenTransferCost != 0, 'OS0F');
        checkOrderParams(
            data,
            sellParams.to,
            sellParams.gasLimit,
            sellParams.submitDeadline,
            ORDER_BASE_COST.add(tokenTransferCost)
        );
        require(sellParams.amountIn != 0, 'OS24');
        (address pairAddress, bool inverted) = getPair(data, sellParams.tokenIn, sellParams.tokenOut);
        require(!getSellDisabled(data, pairAddress), 'OS13');
        uint256 value = msg.value;

        // allocate gas refund
        if (sellParams.tokenIn == tokenShares.weth && sellParams.wrapUnwrap) {
            value = msg.value.sub(sellParams.amountIn, 'OS1E');
        }

        allocateGasRefund(data, value, sellParams.gasLimit);

        uint256 shares = tokenShares.amountToShares(sellParams.tokenIn, sellParams.amountIn, sellParams.wrapUnwrap);

        (uint256 priceAccumulator, uint256 timestamp) = ITwapOracle(ITwapPair(pairAddress).oracle()).getPriceInfo();

        Order memory order = Order(
            0,
            inverted ? SELL_INVERTED_TYPE : SELL_TYPE,
            timestamp + data.delay, // validAfterTimestamp
            sellParams.wrapUnwrap,
            timestamp,
            sellParams.gasLimit,
            data.gasPrice,
            0, // liquidity
            shares,
            sellParams.amountOutMin,
            sellParams.tokenIn,
            sellParams.tokenOut,
            sellParams.to,
            0, // minSwapPrice
            0, // maxSwapPrice
            false, // swap
            priceAccumulator,
            sellParams.amountIn,
            0 // amountLimit1
        );
        enqueueOrder(data, order);

        emit SellEnqueued(order.orderId, order);
    }

    struct BuyParams {
        address tokenIn;
        address tokenOut;
        uint256 amountInMax;
        uint256 amountOut;
        bool wrapUnwrap;
        address to;
        uint256 gasLimit;
        uint32 submitDeadline;
    }

    function buy(
        Data storage data,
        BuyParams calldata buyParams,
        TokenShares.Data storage tokenShares
    ) external {
        uint256 tokenTransferCost = data.transferGasCosts[buyParams.tokenIn];
        require(tokenTransferCost != 0, 'OS0F');
        checkOrderParams(
            data,
            buyParams.to,
            buyParams.gasLimit,
            buyParams.submitDeadline,
            ORDER_BASE_COST.add(tokenTransferCost)
        );
        require(buyParams.amountOut != 0, 'OS23');
        (address pairAddress, bool inverted) = getPair(data, buyParams.tokenIn, buyParams.tokenOut);
        require(!getBuyDisabled(data, pairAddress), 'OS49');
        uint256 value = msg.value;

        // allocate gas refund
        if (buyParams.tokenIn == tokenShares.weth && buyParams.wrapUnwrap) {
            value = msg.value.sub(buyParams.amountInMax, 'OS1E');
        }

        allocateGasRefund(data, value, buyParams.gasLimit);

        uint256 shares = tokenShares.amountToShares(buyParams.tokenIn, buyParams.amountInMax, buyParams.wrapUnwrap);

        (uint256 priceAccumulator, uint256 timestamp) = ITwapOracle(ITwapPair(pairAddress).oracle()).getPriceInfo();

        Order memory order = Order(
            0,
            inverted ? BUY_INVERTED_TYPE : BUY_TYPE,
            timestamp + data.delay, // validAfterTimestamp
            buyParams.wrapUnwrap,
            timestamp,
            buyParams.gasLimit,
            data.gasPrice,
            0, // liquidity
            shares,
            buyParams.amountOut,
            buyParams.tokenIn,
            buyParams.tokenOut,
            buyParams.to,
            0, // minSwapPrice
            0, // maxSwapPrice
            false, // swap
            priceAccumulator,
            buyParams.amountInMax,
            0 // amountLimit1
        );
        enqueueOrder(data, order);

        emit BuyEnqueued(order.orderId, order);
    }

    function checkOrderParams(
        Data storage data,
        address to,
        uint256 gasLimit,
        uint32 submitDeadline,
        uint256 minGasLimit
    ) private view {
        require(submitDeadline >= block.timestamp, 'OS04');
        require(gasLimit <= data.maxGasLimit, 'OS3E');
        require(gasLimit >= minGasLimit, 'OS3D');
        require(to != address(0), 'OS26');
    }

    function allocateGasRefund(
        Data storage data,
        uint256 value,
        uint256 gasLimit
    ) private returns (uint256 futureFee) {
        futureFee = data.gasPrice.mul(gasLimit);
        require(value >= futureFee, 'OS1E');
        if (value > futureFee) {
            TransferHelper.safeTransferETH(msg.sender, value.sub(futureFee), data.transferGasCosts[address(0)]);
        }
    }

    function updateGasPrice(Data storage data, uint256 gasUsed) external {
        uint256 scale = Math.min(gasUsed, data.maxGasPriceImpact);
        data.gasPrice = data.gasPrice.mul(data.gasPriceInertia.sub(scale)).add(tx.gasprice.mul(scale)).div(
            data.gasPriceInertia
        );
    }

    function setMaxGasLimit(Data storage data, uint256 _maxGasLimit) external {
        require(_maxGasLimit != data.maxGasLimit, 'OS01');
        require(_maxGasLimit <= 10000000, 'OS2B');
        data.maxGasLimit = _maxGasLimit;
        emit MaxGasLimitSet(_maxGasLimit);
    }

    function setGasPriceInertia(Data storage data, uint256 _gasPriceInertia) external {
        require(_gasPriceInertia != data.gasPriceInertia, 'OS01');
        require(_gasPriceInertia >= 1, 'OS35');
        data.gasPriceInertia = _gasPriceInertia;
        emit GasPriceInertiaSet(_gasPriceInertia);
    }

    function setMaxGasPriceImpact(Data storage data, uint256 _maxGasPriceImpact) external {
        require(_maxGasPriceImpact != data.maxGasPriceImpact, 'OS01');
        require(_maxGasPriceImpact <= data.gasPriceInertia, 'OS33');
        data.maxGasPriceImpact = _maxGasPriceImpact;
        emit MaxGasPriceImpactSet(_maxGasPriceImpact);
    }

    function setTransferGasCost(
        Data storage data,
        address token,
        uint256 gasCost
    ) external {
        require(gasCost != data.transferGasCosts[token], 'OS01');
        data.transferGasCosts[token] = gasCost;
        emit TransferGasCostSet(token, gasCost);
    }

    function refundLiquidity(
        address pair,
        address to,
        uint256 liquidity,
        bytes4 selector
    ) internal returns (bool) {
        if (liquidity == 0) {
            return true;
        }
        (bool success, bytes memory data) = address(this).call{ gas: PAIR_TRANSFER_COST }(
            abi.encodeWithSelector(selector, pair, to, liquidity, false)
        );
        if (!success) {
            emit RefundFailed(to, pair, liquidity, data);
        }
        return success;
    }

    function dequeueOrder(Data storage data, uint256 orderId) internal {
        ++data.lastProcessedOrderId;
        require(orderId == data.lastProcessedOrderId, 'OS72');
    }

    function forgetOrder(Data storage data, uint256 orderId) internal {
        delete data.orderQueue[orderId];
    }

    function forgetLastProcessedOrder(Data storage data) internal {
        delete data.orderQueue[data.lastProcessedOrderId];
    }

    function getOrderDigest(Order memory order) internal pure returns (bytes32) {
        // Used to avoid the 'stack too deep' error.
        bytes memory partialOrderData = abi.encodePacked(
            order.orderId,
            order.orderType,
            order.validAfterTimestamp,
            order.unwrap,
            order.timestamp,
            order.gasLimit,
            order.gasPrice,
            order.liquidity,
            order.value0,
            order.value1,
            order.token0,
            order.token1,
            order.to,
            order.minSwapPrice
        );

        return
            keccak256(
                abi.encodePacked(
                    partialOrderData,
                    order.maxSwapPrice,
                    order.swap,
                    order.priceAccumulator,
                    order.amountLimit0,
                    order.amountLimit1
                )
            );
    }

    function verifyOrder(Data storage data, Order memory order) external view {
        require(getOrderDigest(order) == data.orderQueue[order.orderId], 'OS71');
    }
}

File 13 of 16 : SafeMath.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)

library SafeMath {
    int256 private constant _INT256_MIN = -2**255;

    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x + y) >= x, 'SM4E');
    }

    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = sub(x, y, 'SM12');
    }

    function sub(
        uint256 x,
        uint256 y,
        string memory message
    ) internal pure returns (uint256 z) {
        require((z = x - y) <= x, message);
    }

    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require(y == 0 || (z = x * y) / y == x, 'SM2A');
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, 'SM43');
        return a / b;
    }

    function ceil_div(uint256 a, uint256 b) internal pure returns (uint256 c) {
        c = div(a, b);
        if (a != mul(b, c)) {
            return add(c, 1);
        }
    }

    function toUint32(uint256 n) internal pure returns (uint32) {
        require(n <= type(uint32).max, 'SM50');
        return uint32(n);
    }

    function toUint64(uint256 n) internal pure returns (uint64) {
        require(n <= type(uint64).max, 'SM54');
        return uint64(n);
    }

    function toUint112(uint256 n) internal pure returns (uint112) {
        require(n <= type(uint112).max, 'SM51');
        return uint112(n);
    }

    function toInt256(uint256 unsigned) internal pure returns (int256 signed) {
        require(unsigned <= uint256(type(int256).max), 'SM34');
        signed = int256(unsigned);
    }

    // int256

    function add(int256 a, int256 b) internal pure returns (int256 c) {
        c = a + b;
        require((b >= 0 && c >= a) || (b < 0 && c < a), 'SM4D');
    }

    function sub(int256 a, int256 b) internal pure returns (int256 c) {
        c = a - b;
        require((b >= 0 && c <= a) || (b < 0 && c > a), 'SM11');
    }

    function mul(int256 a, int256 b) internal pure returns (int256 c) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        require(!(a == -1 && b == _INT256_MIN), 'SM29');

        c = a * b;
        require(c / a == b, 'SM29');
    }

    function div(int256 a, int256 b) internal pure returns (int256) {
        require(b != 0, 'SM43');
        require(!(b == -1 && a == _INT256_MIN), 'SM42');

        return a / b;
    }

    function neg_floor_div(int256 a, int256 b) internal pure returns (int256 c) {
        c = div(a, b);
        if ((a < 0 && b > 0) || (a >= 0 && b < 0)) {
            if (a != mul(b, c)) {
                c = sub(c, 1);
            }
        }
    }
}

File 14 of 16 : TokenShares.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

import '../interfaces/IERC20.sol';
import '../interfaces/IWETH.sol';
import './SafeMath.sol';
import './TransferHelper.sol';

library TokenShares {
    using SafeMath for uint256;
    using TransferHelper for address;

    uint256 private constant PRECISION = 10**18;
    uint256 private constant TOLERANCE = 10**18 + 10**16;
    uint256 private constant TOTAL_SHARES_PRECISION = 10**18;

    event UnwrapFailed(address to, uint256 amount);

    struct Data {
        mapping(address => uint256) totalShares;
        address weth; // represents wrapped native currency (WETH or WMATIC)
    }

    function sharesToAmount(
        Data storage data,
        address token,
        uint256 share,
        uint256 amountLimit,
        address refundTo
    ) external returns (uint256) {
        if (share == 0) {
            return 0;
        }
        if (token == data.weth) {
            return share;
        }

        uint256 totalTokenShares = data.totalShares[token];
        require(totalTokenShares >= share, 'TS3A');
        uint256 balance = IERC20(token).balanceOf(address(this));
        uint256 value = balance.mul(share).div(totalTokenShares);
        data.totalShares[token] = totalTokenShares.sub(share);

        if (amountLimit > 0) {
            uint256 amountLimitWithTolerance = amountLimit.mul(TOLERANCE).div(PRECISION);
            if (value > amountLimitWithTolerance) {
                TransferHelper.safeTransfer(token, refundTo, value.sub(amountLimitWithTolerance));
                return amountLimitWithTolerance;
            }
        }

        return value;
    }

    function amountToShares(
        Data storage data,
        address token,
        uint256 amount,
        bool wrap
    ) external returns (uint256) {
        if (amount == 0) {
            return 0;
        }
        if (token == data.weth) {
            if (wrap) {
                require(msg.value >= amount, 'TS03');
                IWETH(token).deposit{ value: amount }();
            } else {
                token.safeTransferFrom(msg.sender, address(this), amount);
            }
            return amount;
        } else {
            uint256 balanceBefore = IERC20(token).balanceOf(address(this));
            uint256 totalTokenShares = data.totalShares[token];
            require(balanceBefore > 0 || totalTokenShares == 0, 'TS30');
            token.safeTransferFrom(msg.sender, address(this), amount);
            uint256 balanceAfter = IERC20(token).balanceOf(address(this));
            require(balanceAfter > balanceBefore, 'TS2C');
            if (balanceBefore > 0) {
                if (totalTokenShares == 0) {
                    totalTokenShares = balanceBefore.mul(TOTAL_SHARES_PRECISION);
                }
                uint256 newShares = totalTokenShares.mul(balanceAfter).div(balanceBefore);
                require(balanceAfter < type(uint256).max.div(newShares), 'TS73'); // to prevent overflow at execution
                data.totalShares[token] = newShares;
                return newShares - totalTokenShares;
            } else {
                balanceAfter = balanceAfter.mul(TOTAL_SHARES_PRECISION);
                require(balanceAfter < type(uint256).max.div(balanceAfter), 'TS73'); // to prevent overflow at execution
                data.totalShares[token] = balanceAfter;
                return balanceAfter;
            }
        }
    }

    function onUnwrapFailed(
        Data storage data,
        address to,
        uint256 amount
    ) external {
        emit UnwrapFailed(to, amount);
        IWETH(data.weth).deposit{ value: amount }();
        TransferHelper.safeTransfer(data.weth, to, amount);
    }
}

File 15 of 16 : TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TH4B');
    }

    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TH05');
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TH0E');
    }

    function safeTransferETH(
        address to,
        uint256 value,
        uint256 gasLimit
    ) internal {
        (bool success, ) = to.call{ value: value, gas: gasLimit }('');
        require(success, 'TH3F');
    }

    function transferETH(
        address to,
        uint256 value,
        uint256 gasLimit
    ) internal returns (bool success) {
        (success, ) = to.call{ value: value, gas: gasLimit }('');
    }
}

File 16 of 16 : WithdrawHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Deployed with donations via Gitcoin GR9

pragma solidity 0.7.6;
pragma abicoder v2;

import '../interfaces/ITwapPair.sol';
import '../interfaces/IWETH.sol';
import './Orders.sol';

library WithdrawHelper {
    using SafeMath for uint256;

    function _transferToken(
        uint256 balanceBefore,
        address token,
        address to
    ) internal {
        uint256 tokenAmount = IERC20(token).balanceOf(address(this)).sub(balanceBefore);
        TransferHelper.safeTransfer(token, to, tokenAmount);
    }

    // unwraps wrapped native currency
    function _unwrapWeth(
        uint256 ethAmount,
        address weth,
        address to,
        uint256 gasLimit
    ) internal returns (bool) {
        IWETH(weth).withdraw(ethAmount);
        (bool success, ) = to.call{ value: ethAmount, gas: gasLimit }('');
        return success;
    }

    function withdrawAndUnwrap(
        address token0,
        address token1,
        address pair,
        address weth,
        address to,
        uint256 gasLimit
    )
        external
        returns (
            bool,
            uint256,
            uint256,
            uint256
        )
    {
        bool isToken0Weth = token0 == weth;
        address otherToken = isToken0Weth ? token1 : token0;

        uint256 balanceBefore = IERC20(otherToken).balanceOf(address(this));
        (uint256 amount0, uint256 amount1) = ITwapPair(pair).burn(address(this));
        _transferToken(balanceBefore, otherToken, to);

        bool success = _unwrapWeth(isToken0Weth ? amount0 : amount1, weth, to, gasLimit);

        return (success, isToken0Weth ? amount0 : amount1, amount0, amount1);
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {
    "contracts/libraries/TokenShares.sol": {
      "TokenShares": "0xa33efea216b31f7c16697654fbd8d6c857965d96"
    },
    "contracts/libraries/Orders.sol": {
      "Orders": "0xe02c42a6a5099430834893be473c6a8452adb90b"
    },
    "contracts/libraries/AddLiquidity.sol": {
      "AddLiquidity": "0x0ec2323adafbebc6c80257c7359692bcceb0b3f1"
    },
    "contracts/libraries/WithdrawHelper.sol": {
      "WithdrawHelper": "0x19f6bc0755fd4a465b3961fb335d6e55ab8b9eaa"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_bot","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"bot","type":"address"},{"indexed":false,"internalType":"bool","name":"isBot","type":"bool"}],"name":"BotSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"delay","type":"uint256"}],"name":"DelaySet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"EthRefund","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"gasPriceInertia","type":"uint256"}],"name":"GasPriceInertiaSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxGasLimit","type":"uint256"}],"name":"MaxGasLimitSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxGasPriceImpact","type":"uint256"}],"name":"MaxGasPriceImpactSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"enum Orders.OrderType","name":"orderType","type":"uint8"},{"indexed":false,"internalType":"bool","name":"disabled","type":"bool"}],"name":"OrderDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"gasSpent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethRefunded","type":"uint256"}],"name":"OrderExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"OwnerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"RefundFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint16","name":"amount","type":"uint16"}],"name":"ToleranceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"gasCost","type":"uint256"}],"name":"TransferGasCostSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"UnwrapFailed","type":"event"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order","name":"order","type":"tuple"}],"name":"_executeBuy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order","name":"order","type":"tuple"}],"name":"_executeDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order","name":"order","type":"tuple"}],"name":"_executeSell","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order","name":"order","type":"tuple"}],"name":"_executeWithdraw","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"name":"_refundLiquidity","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"}],"name":"_refundToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"uint256","name":"share0","type":"uint256"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"share1","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"}],"name":"_refundTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"bool","name":"wrapUnwrap","type":"bool"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint32","name":"submitDeadline","type":"uint32"}],"internalType":"struct Orders.BuyParams","name":"buyParams","type":"tuple"}],"name":"buy","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order","name":"order","type":"tuple"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"delay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"wrap","type":"bool"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint32","name":"submitDeadline","type":"uint32"}],"internalType":"struct Orders.DepositParams","name":"depositParams","type":"tuple"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order[]","name":"_orders","type":"tuple[]"}],"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gasPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gasPriceInertia","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"getBuyDisabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"getDepositDisabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"}],"name":"getOrderStatus","outputs":[{"internalType":"enum Orders.OrderStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"getSellDisabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getTransferGasCost","outputs":[{"internalType":"uint256","name":"gasCost","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"getWithdrawDisabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isBot","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"isOrderCanceled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastProcessedOrderId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxGasLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxGasPriceImpact","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"newestOrderId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"orderType","type":"uint256"},{"internalType":"uint256","name":"validAfterTimestamp","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"minSwapPrice","type":"uint256"},{"internalType":"uint256","name":"maxSwapPrice","type":"uint256"},{"internalType":"bool","name":"swap","type":"bool"},{"internalType":"uint256","name":"priceAccumulator","type":"uint256"},{"internalType":"uint256","name":"amountLimit0","type":"uint256"},{"internalType":"uint256","name":"amountLimit1","type":"uint256"}],"internalType":"struct Orders.Order","name":"order","type":"tuple"}],"name":"retryRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"bool","name":"wrapUnwrap","type":"bool"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint32","name":"submitDeadline","type":"uint32"}],"internalType":"struct Orders.SellParams","name":"sellParams","type":"tuple"}],"name":"sell","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_bot","type":"address"},{"internalType":"bool","name":"_isBot","type":"bool"}],"name":"setBot","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_delay","type":"uint32"}],"name":"setDelay","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_gasPriceInertia","type":"uint256"}],"name":"setGasPriceInertia","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxGasLimit","type":"uint256"}],"name":"setMaxGasLimit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxGasPriceImpact","type":"uint256"}],"name":"setMaxGasPriceImpact","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"enum Orders.OrderType","name":"orderType","type":"uint8"},{"internalType":"bool","name":"disabled","type":"bool"}],"name":"setOrderDisabled","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"uint16","name":"amount","type":"uint16"}],"name":"setTolerance","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"gasCost","type":"uint256"}],"name":"setTransferGasCost","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tolerance","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"totalShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint32","name":"submitDeadline","type":"uint32"}],"internalType":"struct Orders.WithdrawParams","name":"withdrawParams","type":"tuple"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b506040516200529938038062005299833981016040819052620000349162000176565b600480546001600160a01b038086166001600160a01b0319928316178355600f8054831633179055838116600090815260106020526040808220805460ff191660011790553a600655600e805493881693909416929092179092556107088255624c4b406005556301312d00600755620f42406008555163b2456a0760e01b815273e02c42a6a5099430834893be473c6a8452adb90b9263b2456a0792620000e592909182916127109101620001d3565b60006040518083038186803b158015620000fe57600080fd5b505af415801562000113573d6000803e3d6000fd5b505050507f50146d0e3c60aa1d17a70635b05494f864e86144a2201275021014fbf08bafe233604051620001489190620001bf565b60405180910390a1505050620001f2565b80516001600160a01b03811681146200017157600080fd5b919050565b6000806000606084860312156200018b578283fd5b620001968462000159565b9250620001a66020850162000159565b9150620001b66040850162000159565b90509250925092565b6001600160a01b0391909116815260200190565b9283526001600160a01b03919091166020830152604082015260600190565b61509780620002026000396000f3fe6080604052600436106102605760003560e01c80637f6a1caf11610144578063bf6b874e116100b6578063e29577ee1161007a578063e29577ee14610614578063e30a499314610627578063e5b1be651461063c578063e5e7988e1461064f578063e6a0cc941461066f578063fe173b971461068457610267565b8063bf6b874e1461058c578063c45a0155146105ac578063c9cd9760146105c1578063ceb0981f146105d4578063d22e92421461060157610267565b80639d08ebb5116101085780639d08ebb5146104f3578063a70885c114610506578063af482b5814610533578063b32ac93614610553578063b5540b2b14610566578063ba4d53121461057957610267565b80637f6a1caf1461048557806389e707ad146104985780638da5cb5b146104ab57806394531713146104c05780639718f627146104d357610267565b80634c016016116101dd57806368f63a34116101a157806368f63a34146103f55780636a42b8f8146104085780636de3c67c1461041d57806370190d4c1461043257806377632ec214610452578063793ab2971461047257610267565b80634c016016146103785780635051349a14610398578063576b332b146103b857806357a62a4f146103cb5780635e45da23146103e057610267565b8063303a892b11610224578063303a892b146102fd578063342aa8b5146103105780633bbac579146103235780633ed76f17146103435780633fc8cef31461035657610267565b806302241c701461026c578063103486651461028e57806313af4035146102a15780631776834a146102b457806320a68fab146102c757610267565b3661026757005b600080fd5b34801561027857600080fd5b5061028c610287366004614601565b610699565b005b61028c61029c3660046146f8565b6107ea565b61028c6102af3660046142ec565b610859565b61028c6102c2366004614657565b6108f4565b3480156102d357600080fd5b506102e76102e23660046142ec565b61098b565b6040516102f49190614ab7565b60405180910390f35b61028c61030b366004614601565b61099f565b61028c61031e366004614425565b610d71565b34801561032f57600080fd5b506102e761033e3660046142ec565b610dfd565b61028c610351366004614364565b610e12565b34801561036257600080fd5b5061036b610e32565b6040516102f49190614929565b34801561038457600080fd5b506102e76103933660046142ec565b610e41565b6103ab6103a63660046145d3565b610e4d565b6040516102f49190614f6a565b6103ab6103c6366004614613565b610ef0565b3480156103d757600080fd5b506103ab610f53565b3480156103ec57600080fd5b506103ab610f59565b61028c610403366004614601565b610f5f565b34801561041457600080fd5b506103ab6111a6565b34801561042957600080fd5b506103ab6111ac565b34801561043e57600080fd5b5061028c61044d366004614601565b6111b2565b34801561045e57600080fd5b506102e761046d366004614657565b61127d565b61028c6104803660046144aa565b611292565b61028c61049336600461445d565b61133a565b61028c6104a6366004614601565b6113ce565b3480156104b757600080fd5b5061036b611aae565b61028c6104ce366004614657565b611abd565b3480156104df57600080fd5b506103ab6104ee3660046142ec565b611b21565b6103ab6105013660046145ef565b611b3c565b34801561051257600080fd5b506105266105213660046142ec565b611ba2565b6040516102f49190614f5b565b34801561053f57600080fd5b506102e761054e3660046142ec565b611bb8565b61028c610561366004614657565b611bc4565b61028c610574366004614508565b611c28565b6103ab6105873660046145d3565b611fbf565b34801561059857600080fd5b506103ab6105a73660046142ec565b612025565b3480156105b857600080fd5b5061036b612040565b61028c6105cf366004614324565b61204f565b3480156105e057600080fd5b506105f46105ef366004614687565b61207e565b6040516102f49190614b18565b61028c61060f3660046144dd565b612094565b61028c610622366004614601565b612126565b34801561063357600080fd5b506103ab6124ac565b61028c61064a3660046143d3565b6124b2565b34801561065b57600080fd5b506102e761066a3660046142ec565b6126b1565b34801561067b57600080fd5b506103ab6126bd565b34801561069057600080fd5b506103ab6126c3565b601254156106c25760405162461bcd60e51b81526004016106b990614b2c565b60405180910390fd5b6001601255604051632e548b5b60e01b815273e02c42a6a5099430834893be473c6a8452adb90b90632e548b5b90610701906000908590600401614e52565b60006040518083038186803b15801561071957600080fd5b505af415801561072d573d6000803e3d6000fd5b506002925061073a915050565b61074b6000833560408501356126c9565b600581111561075657fe5b146107735760405162461bcd60e51b81526004016106b990614c76565b4261079c620151806107966000800154856040013561275890919063ffffffff16565b90612781565b106107b95760405162461bcd60e51b81526004016106b990614b4a565b80356000908152600a60205260409020805460ff191660019081179091556107e29082906127c2565b506000601255565b600f546001600160a01b031633146108145760405162461bcd60e51b81526004016106b990614be0565b63ffffffff81166000556040517f63e09f16584208fba1fc7ff64c62b00f07bec177c0d97ca6689891b1e77a35c79061084e908390614fe1565b60405180910390a150565b600f546001600160a01b031633146108835760405162461bcd60e51b81526004016106b990614be0565b6001600160a01b0381166108a95760405162461bcd60e51b81526004016106b990614cb2565b600f80546001600160a01b0319166001600160a01b0383161790556040517f50146d0e3c60aa1d17a70635b05494f864e86144a2201275021014fbf08bafe29061084e908390614929565b600f546001600160a01b0316331461091e5760405162461bcd60e51b81526004016106b990614be0565b604051636702eca360e01b815273e02c42a6a5099430834893be473c6a8452adb90b90636702eca390610958906000908590600401614f12565b60006040518083038186803b15801561097057600080fd5b505af4158015610984573d6000803e3d6000fd5b5050505050565b60006109978183612a59565b90505b919050565b3330146109be5760405162461bcd60e51b81526004016106b990614be0565b426202a30082604001350110156109e75760405162461bcd60e51b81526004016106b990614c58565b6000610a196109fe610160840161014085016142ec565b610a10610180850161016086016142ec565b60009190612a8d565b5090506000806000610a2b8585612b5a565b91945092509050610a4461020086016101e08701614579565b8015610a4f57508015155b15610c53576000610a6a858761020001358860800135612e06565b90508315801590610a7b5750816001145b15610b61576000730ec2323adafbebc6c80257c7359692bcceb0b3f163d0b0a9bc87610aaf6101608b016101408c016142ec565b6001600160a01b038a16600090815260116020526040908190205490516001600160e01b031960e086901b168152610afb9392918b916101a08f01359161ffff16908a90600401614a2f565b604080518083038186803b158015610b1257600080fd5b505af4158015610b26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4a91906146a8565b9095509050610b598482612781565b935050610c51565b8215801590610b705750816002145b15610c51576000730ec2323adafbebc6c80257c7359692bcceb0b3f163adf5f8f387610ba46101808b016101608c016142ec565b6001600160a01b038a16600090815260116020526040908190205490516001600160e01b031960e086901b168152610bf09392918a916101c08f01359161ffff16908a90600401614a2f565b604080518083038186803b158015610c0757600080fd5b505af4158015610c1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3f91906146a8565b94509050610c4d8582612781565b9450505b505b8215801590610c6157508115155b15610d3157730ec2323adafbebc6c80257c7359692bcceb0b3f1637a528bd285610c936101a089016101808a016142ec565b610ca56101608a016101408b016142ec565b610cb76101808b016101608c016142ec565b88886040518763ffffffff1660e01b8152600401610cda96959493929190614992565b60606040518083038186803b158015610cf257600080fd5b505af4158015610d06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2a91906146cb565b5090935091505b610984610d466101a0870161018088016142ec565b610d58610160880161014089016142ec565b610d6a61018089016101608a016142ec565b8686612f24565b600f546001600160a01b03163314610d9b5760405162461bcd60e51b81526004016106b990614be0565b6001600160a01b03821660009081526010602052604090819020805460ff1916831515179055517f70af441dbb427737e6a5ef2cf5b664321011765ce1d19ce4a69cd024e69d4f2f90610df19084908490614a7f565b60405180910390a15050565b60106020526000908152604090205460ff1681565b610e1e858786846124b2565b610e2a838784846124b2565b505050505050565b600e546001600160a01b031690565b60006109978183612f46565b6000601254600014610e715760405162461bcd60e51b81526004016106b990614b2c565b600160125560405162c44ff160e31b815273e02c42a6a5099430834893be473c6a8452adb90b906306227f8890610eb2906000908690600d90600401614d44565b60006040518083038186803b158015610eca57600080fd5b505af4158015610ede573d6000803e3d6000fd5b50506001546000601255949350505050565b6000601254600014610f145760405162461bcd60e51b81526004016106b990614b2c565b6001601255604051636587992160e01b815273e02c42a6a5099430834893be473c6a8452adb90b90636587992190610eb2906000908690600401614e67565b60085490565b60055490565b333014610f7e5760405162461bcd60e51b81526004016106b990614be0565b426202a3008260400135011015610fa75760405162461bcd60e51b81526004016106b990614c58565b6000610fbe6109fe610160840161014085016142ec565b509050806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610ffc57600080fd5b505af1158015611010573d6000803e3d6000fd5b50505050600061102a828461020001358560800135612e06565b90506020830135600614600061104285838686612f4f565b90506000808361105457600083611058565b8260005b600e5491935091506001600160a01b031661107b61018089016101608a016142ec565b6001600160a01b031614801561109c575061109c6080880160608901614579565b156111275760405163022c0d9f60e01b81526001600160a01b0387169063022c0d9f906110d3908590859030908b90600401614f8c565b600060405180830381600087803b1580156110ed57600080fd5b505af1158015611101573d6000803e3d6000fd5b50611122925061111c9150506101a089016101808a016142ec565b8461345e565b61119d565b6001600160a01b03861663022c0d9f838361114a6101a08c016101808d016142ec565b896040518563ffffffff1660e01b815260040161116a9493929190614f8c565b600060405180830381600087803b15801561118457600080fd5b505af1158015611198573d6000803e3d6000fd5b505050505b50505050505050565b60005490565b60075490565b601254156111d25760405162461bcd60e51b81526004016106b990614b2c565b6001601255604051632e548b5b60e01b815273e02c42a6a5099430834893be473c6a8452adb90b90632e548b5b90611211906000908590600401614e52565b60006040518083038186803b15801561122957600080fd5b505af415801561123d573d6000803e3d6000fd5b50505081356000908152600c602052604090205460ff1690506112725760405162461bcd60e51b81526004016106b990614b86565b6107e28160006127c2565b6000908152600a602052604090205460ff1690565b600f546001600160a01b031633146112bc5760405162461bcd60e51b81526004016106b990614be0565b600a61ffff821611156112e15760405162461bcd60e51b81526004016106b990614c3a565b6001600160a01b03821660009081526011602052604090819020805461ffff191661ffff8416179055517f6b4044e33be5af8fcdb7449c49137010eede3c8c06d5d08067151a7ace17266d90610df19084908490614a9a565b600f546001600160a01b031633146113645760405162461bcd60e51b81526004016106b990614be0565b60405163146bce4f60e31b815273e02c42a6a5099430834893be473c6a8452adb90b9063a35e7278906113a290600090879087908790600401614cee565b60006040518083038186803b1580156113ba57600080fd5b505af415801561119d573d6000803e3d6000fd5b3330146113ed5760405162461bcd60e51b81526004016106b990614be0565b426202a30082604001350110156114165760405162461bcd60e51b81526004016106b990614c58565b600061142d6109fe610160840161014085016142ec565b509050600073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d611460610160870161014088016142ec565b61010087013561022088013561147e6101a08a016101808b016142ec565b6040518663ffffffff1660e01b815260040161149e959493929190614f20565b60206040518083038186803b1580156114b657600080fd5b505af41580156114ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ee919061466f565b9050816001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561152b57600080fd5b505af115801561153f573d6000803e3d6000fd5b505050506000611559838561020001358660800135612e06565b905060008060008060048860200135149050600080886001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401604080518083038186803b1580156115a657600080fd5b505afa1580156115ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115de9190614625565b915091506116036001846115f257826115f4565b835b6001600160701b031690612758565b935050506000876001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b15801561164257600080fd5b505afa158015611656573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061167a9190614308565b90506000886001600160a01b03166354cf2aeb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156116b757600080fd5b505afa1580156116cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116ef919061466f565b9050816001600160a01b031663daab4b6e84838d61012001358b6040518563ffffffff1660e01b81526004016117289493929190614ac2565b604080518083038186803b15801561173f57600080fd5b505afa158015611753573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177791906146a8565b909650945060008486111561182d5761179f6101208c01356117998b8861357e565b906135d3565b60405163a7d2087760e01b81529091506001600160a01b0384169063a7d20877906117d490879086908a908e90600401614ac2565b604080518083038186803b1580156117eb57600080fd5b505afa1580156117ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182391906146a8565b9097509550611838565b506101208a01359450875b868110156118585760405162461bcd60e51b81526004016106b990614cd0565b8689111561190357600e546001600160a01b031661187e6101608d016101408e016142ec565b6001600160a01b031614801561189f575061189f60808c0160608d01614579565b156118cd576118c86118b96101a08d016101808e016142ec565b6118c38b8a612758565b61345e565b611903565b6119036118e26101608d016101408e016142ec565b6118f46101a08e016101808f016142ec565b6118fe8c8b612758565b613603565b61191f6119186101608d016101408e016142ec565b8b89613603565b5050506001600160a01b03871660009081526011602052604090205461194a90849061ffff16612758565b9250600080821561195d57849150611960565b50835b600e546001600160a01b031661197e6101808c016101608d016142ec565b6001600160a01b031614801561199f575061199f60808b0160608c01614579565b15611a2a5760405163022c0d9f60e01b81526001600160a01b038a169063022c0d9f906119d6908590859030908d90600401614f8c565b600060405180830381600087803b1580156119f057600080fd5b505af1158015611a04573d6000803e3d6000fd5b50611a259250611a1f9150506101a08c016101808d016142ec565b8661345e565b611aa2565b886001600160a01b031663022c0d9f83838d610180016020810190611a4f91906142ec565b8b6040518563ffffffff1660e01b8152600401611a6f9493929190614f8c565b600060405180830381600087803b158015611a8957600080fd5b505af1158015611a9d573d6000803e3d6000fd5b505050505b50505050505050505050565b600f546001600160a01b031681565b600f546001600160a01b03163314611ae75760405162461bcd60e51b81526004016106b990614be0565b604051630fd1437d60e11b815273e02c42a6a5099430834893be473c6a8452adb90b90631fa286fa90610958906000908590600401614f12565b6001600160a01b031660009081526009602052604090205490565b6000601254600014611b605760405162461bcd60e51b81526004016106b990614b2c565b6001601255604051638f0e6bef60e01b815273e02c42a6a5099430834893be473c6a8452adb90b90638f0e6bef90610eb2906000908690600d90600401614d68565b60116020526000908152604090205461ffff1681565b6000610997818361374e565b600f546001600160a01b03163314611bee5760405162461bcd60e51b81526004016106b990614be0565b60405163153cc2fd60e31b815273e02c42a6a5099430834893be473c6a8452adb90b9063a9e617e890610958906000908590600401614f12565b60125415611c485760405162461bcd60e51b81526004016106b990614b2c565b60016012558060005a3360009081526010602052604081205491925090819060ff1680611c9f57506000805260106020527f6e0956cda88cad152e89927e53611735b61a5c762d1428573c6931b0a5efcb015460ff165b905060005b84811015611f3657600254878783818110611cbb57fe5b905061026002016000013511611cd057611f2e565b600a6000888884818110611ce057fe5b61026002919091013582525060208101919091526040016000205460ff1615611d2957611d24878783818110611d1257fe5b60009261026090910201359050613757565b611f2e565b73e02c42a6a5099430834893be473c6a8452adb90b632e548b5b6000898985818110611d5157fe5b905061026002016040518363ffffffff1660e01b8152600401611d75929190614e52565b60006040518083038186803b158015611d8d57600080fd5b505af4158015611da1573d6000803e3d6000fd5b505050506000878783818110611db357fe5b90506102600201604001359050428110611dcd5750611f36565b8280611ddd57506104b081014210155b611df95760405162461bcd60e51b81526004016106b990614be0565b600193506001888884818110611e0b57fe5b90506102600201602001351415611e3c57611e37888884818110611e2b57fe5b90506102600201613782565b611f2c565b6002888884818110611e4a57fe5b90506102600201602001351415611e7657611e37888884818110611e6a57fe5b90506102600201613999565b6005888884818110611e8457fe5b90506102600201602001351480611eb157506006888884818110611ea457fe5b9050610260020160200135145b15611ed157611e37888884818110611ec557fe5b90506102600201613ac8565b6003888884818110611edf57fe5b90506102600201602001351480611f0c57506004888884818110611eff57fe5b9050610260020160200135145b15611f2c57611f2c888884818110611f2057fe5b90506102600201613bdd565b505b600101611ca4565b508115611fb25773e02c42a6a5099430834893be473c6a8452adb90b639db74df16000611f645a8790612758565b6040518363ffffffff1660e01b8152600401611f81929190614f12565b60006040518083038186803b158015611f9957600080fd5b505af4158015611fad573d6000803e3d6000fd5b505050505b5050600060125550505050565b6000601254600014611fe35760405162461bcd60e51b81526004016106b990614b2c565b600160125560405163758e99b360e01b815273e02c42a6a5099430834893be473c6a8452adb90b9063758e99b390610eb2906000908690600d90600401614d44565b6001600160a01b03166000908152600d602052604090205490565b6004546001600160a01b031690565b33301461206e5760405162461bcd60e51b81526004016106b990614be0565b612079838383613603565b505050565b600061208b8184846126c9565b90505b92915050565b600f546001600160a01b031633146120be5760405162461bcd60e51b81526004016106b990614be0565b60405163b2456a0760e01b815273e02c42a6a5099430834893be473c6a8452adb90b9063b2456a07906120fa9060009086908690600401614d25565b60006040518083038186803b15801561211257600080fd5b505af4158015610e2a573d6000803e3d6000fd5b3330146121455760405162461bcd60e51b81526004016106b990614be0565b426202a300826040013501101561216e5760405162461bcd60e51b81526004016106b990614c58565b60006121856109fe610160840161014085016142ec565b509050806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156121c357600080fd5b505af11580156121d7573d6000803e3d6000fd5b505050506121ea81828460e00135613603565b600080806121fe6080860160608701614579565b801561225c5750600e546001600160a01b0316612223610160870161014088016142ec565b6001600160a01b0316148061225c5750600e546001600160a01b0316612251610180870161016088016142ec565b6001600160a01b0316145b156123e25760007319f6bc0755fd4a465b3961fb335d6e55ab8b9eaa63cf58beed61228f61016089016101408a016142ec565b6122a16101808a016101608b016142ec565b600e5489906001600160a01b03166122c16101a08d016101808e016142ec565b600080526009602052600080516020615042833981519152546040516001600160e01b031960e089901b16815261230096959493929190600401614957565b60806040518083038186803b15801561231857600080fd5b505af415801561232c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123509190614595565b919650945092509050806123dc5773a33efea216b31f7c16697654fbd8d6c857965d9663656621e0600d61238c6101a08a016101808b016142ec565b876040518463ffffffff1660e01b81526004016123ab93929190614d25565b60006040518083038186803b1580156123c357600080fd5b505af41580156123d7573d6000803e3d6000fd5b505050505b50612476565b6001600160a01b0384166389afcb446124036101a0880161018089016142ec565b6040518263ffffffff1660e01b815260040161241f9190614929565b6040805180830381600087803b15801561243857600080fd5b505af115801561244c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061247091906146a8565b90925090505b846101000135821015801561249057508461012001358110155b6109845760405162461bcd60e51b81526004016106b990614ba4565b60015490565b3330146124d15760405162461bcd60e51b81526004016106b990614be0565b600e546001600160a01b0385811691161480156124eb5750805b1561261257604051632a359a6d60e21b815260009073a33efea216b31f7c16697654fbd8d6c857965d969063a8d669b49061253390600d908990889087908b90600401614f20565b60206040518083038186803b15801561254b57600080fd5b505af415801561255f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612583919061466f565b600e54604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d906125b4908490600401614f6a565b600060405180830381600087803b1580156125ce57600080fd5b505af11580156125e2573d6000803e3d6000fd5b505060008052505060096020526000805160206150428339815191525461260c9085908390613c27565b506126ab565b604051632a359a6d60e21b81526126ab908590859073a33efea216b31f7c16697654fbd8d6c857965d969063a8d669b49061265b90600d9086908a906000908890600401614f20565b60206040518083038186803b15801561267357600080fd5b505af4158015612687573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fe919061466f565b50505050565b60006109978183613cb9565b60025490565b60065490565b600083600101548311156126df57506000612751565b6000838152600a8501602052604090205460ff161561270057506005612751565b6000838152600c8501602052604090205460ff161561272157506004612751565b600083815260038501602052604090205461273e57506003612751565b42821061274d57506001612751565b5060025b9392505050565b600061208b83836040518060400160405280600481526020016329a6989960e11b815250613cc2565b8082018281101561208e576040805162461bcd60e51b81526020600480830191909152602482015263534d344560e01b604482015290519081900360640190fd5b6000426127d760408501356301e13380612781565b1090506001836020013514156128bc57600081612805576128006101a0850161018086016142ec565b612812565b600f546001600160a01b03165b905061285d8161282a610160870161014088016142ec565b61010087013561284261018089016101608a016142ec565b61012089013561285860808b0160608c01614579565b613d5a565b6128795760405162461bcd60e51b81526004016106b990614b68565b82156128b65761289a8161289560c087013560a088013561357e565b613ee4565b6128b65760405162461bcd60e51b81526004016106b990614bfe565b50612a49565b6002836020013514156129945760006128f26128e0610160860161014087016142ec565b610a10610180870161016088016142ec565b5090506000826129135761290e6101a0860161018087016142ec565b612920565b600f546001600160a01b03165b9050612939828260e088013563064e6cbb60e51b613f65565b6129555760405162461bcd60e51b81526004016106b990614b68565b831561298d576129718161289560c088013560a089013561357e565b61298d5760405162461bcd60e51b81526004016106b990614bfe565b5050612a49565b6005836020013514806129ab575060068360200135145b15612a0e576000816129ce576129c96101a0850161018086016142ec565b6129db565b600f546001600160a01b03165b905061285d6129f2610160860161014087016142ec565b82610100870135612a096080890160608a01614579565b614082565b600383602001351480612a25575060048360200135145b15612a43576000816129ce576129c96101a0850161018086016142ec565b50612a55565b612079600084356140ce565b5050565b600060025b6001600160a01b0383166000908152600b85016020526040902054600160ff9283161b16161515905092915050565b60048084015460405163e6a4390560e01b815260009283926001600160a01b03169163e6a4390591612ac391889188910161493d565b60206040518083038186803b158015612adb57600080fd5b505afa158015612aef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b139190614308565b91506001600160a01b038216612b3b5760405162461bcd60e51b81526004016106b990614c1c565b826001600160a01b0316846001600160a01b0316119050935093915050565b600080808073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d612b8d6101608a016101408b016142ec565b6101008a01356102208b0135612bab6101a08d016101808e016142ec565b6040518663ffffffff1660e01b8152600401612bcb959493929190614f20565b60206040518083038186803b158015612be357600080fd5b505af4158015612bf7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c1b919061466f565b9050600073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d612c4d6101808b016101608c016142ec565b6101208b01356102408c0135612c6b6101a08e016101808f016142ec565b6040518663ffffffff1660e01b8152600401612c8b959493929190614f20565b60206040518083038186803b158015612ca357600080fd5b505af4158015612cb7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cdb919061466f565b9050856001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612d1857600080fd5b505af1158015612d2c573d6000803e3d6000fd5b50505050730ec2323adafbebc6c80257c7359692bcceb0b3f1637a528bd28789610180016020810190612d5f91906142ec565b612d716101608c016101408d016142ec565b612d836101808d016101608e016142ec565b87876040518763ffffffff1660e01b8152600401612da696959493929190614992565b60606040518083038186803b158015612dbe57600080fd5b505af4158015612dd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df691906146cb565b9199909850909650945050505050565b60606000846001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b158015612e4357600080fd5b505afa158015612e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7b9190614308565b6001600160a01b0316636a9150fe85856040518363ffffffff1660e01b8152600401612ea8929190614f12565b60206040518083038186803b158015612ec057600080fd5b505afa158015612ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef8919061466f565b905080604051602001612f0b9190614f6a565b6040516020818303038152906040529150509392505050565b8115612f3557612f35848684613603565b801561098457610984838683613603565b60006003612a5e565b600080600080856001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401604080518083038186803b158015612f8d57600080fd5b505afa158015612fa1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fc59190614625565b91509150612fd96001886115f257826115f4565b925050506000846001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b15801561301857600080fd5b505afa15801561302c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130509190614308565b90506000856001600160a01b03166354cf2aeb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561308d57600080fd5b505afa1580156130a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130c5919061466f565b9050600073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d6130f76101608d016101408e016142ec565b8c61010001358d61022001358e61018001602081019061311791906142ec565b6040518663ffffffff1660e01b8152600401613137959493929190614f20565b60206040518083038186803b15801561314f57600080fd5b505af4158015613163573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613187919061466f565b905087613213576040516304a8fad760e31b81526001600160a01b03841690632547d6b8906131be90859085908b90600401614fb9565b60206040518083038186803b1580156131d657600080fd5b505afa1580156131ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061320e919061466f565b613293565b60405163c4109d2560e01b81526001600160a01b0384169063c4109d259061324390859085908b90600401614fb9565b60206040518083038186803b15801561325b57600080fd5b505afa15801561326f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613293919061466f565b94506000848611156133e3576132b8866132b26101208d01358861357e565b906140e2565b60405163a7d2087760e01b815290915082906001600160a01b0386169063a7d20877906132ef908d9088908b908e90600401614ac2565b604080518083038186803b15801561330657600080fd5b505afa15801561331a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061333e91906146a8565b600e549098509093506001600160a01b03166133626101608d016101408e016142ec565b6001600160a01b0316148015613383575061338360808c0160608d01614579565b156133ac576133a761339d6101a08d016101808e016142ec565b6118c38386612758565b6133dd565b6133dd6133c16101608d016101408e016142ec565b6133d36101a08e016101808f016142ec565b6118fe8487612758565b506133eb565b506101208901355b6001600160a01b03881660009081526011602052604090205461341390879061ffff16612758565b9550808610156134355760405162461bcd60e51b81526004016106b990614bc2565b61345161344a6101608c016101408d016142ec565b8984613603565b5050505050949350505050565b600e54604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d9061348e908490600401614f6a565b600060405180830381600087803b1580156134a857600080fd5b505af11580156134bc573d6000803e3d6000fd5b505060008080526009602052600080516020615042833981519152546040519193506001600160a01b03861692509084906134f690614926565b600060405180830381858888f193505050503d8060008114613534576040519150601f19603f3d011682016040523d82523d6000602084013e613539565b606091505b50509050806120795760405163032b310f60e51b815273a33efea216b31f7c16697654fbd8d6c857965d969063656621e0906113a290600d9087908790600401614d25565b60008115806135995750508082028282828161359657fe5b04145b61208e576040805162461bcd60e51b81526020600480830191909152602482015263534d324160e01b604482015290519081900360640190fd5b60006135df83836140e2565b90506135eb828261357e565b831461208e576135fc816001612781565b905061208e565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b6020831061367f5780518252601f199092019160209182019101613660565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146136e1576040519150601f19603f3d011682016040523d82523d6000602084013e6136e6565b606091505b5091509150818015613714575080511580613714575080806020019051602081101561371157600080fd5b50515b610984576040805162461bcd60e51b815260206004808301919091526024820152635448303560e01b604482015290519081900360640190fd5b60006001612a5e565b600282018054600101908190558114612a555760405162461bcd60e51b81526004016106b990614c94565b60005a905061379360008335613757565b6000803061381761380c6009846137b26101808a016101608b016142ec565b6001600160a01b03168152602081019190915260400160009081205490610796906009906137e86101608c016101408d016142ec565b6001600160a01b0316815260208101919091526040016000205462012c6c90612781565b60a087013590612758565b60405163303a892b60e01b90613831908890602401614f4c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161386f919061490a565b60006040518083038160008787f1925050503d80600081146138ad576040519150601f19603f3d011682016040523d82523d6000602084013e6138b2565b606091505b509092509050600182613917576139146138d46101a0870161018088016142ec565b6138e6610160880161014089016142ec565b6101008801356138fe6101808a016101608b016142ec565b6101208a013561285860808c0160608d01614579565b90505b61392081614132565b60008061394860a088013560c0890135886139436101a08c016101808d016142ec565b614153565b915091508415156000600201547ff0cc99aeb224e65869630a14e23683d20b9c535c00427b50024ce8b6b21d35c386858560405161398893929190614af3565b60405180910390a350505050505050565b60005a90506139aa60008335613757565b600080306139c061380c62012c6c61d6d8612781565b60405163714abbf760e11b906139da908890602401614f4c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613a18919061490a565b60006040518083038160008787f1925050503d8060008114613a56576040519150601f19603f3d011682016040523d82523d6000602084013e613a5b565b606091505b509092509050600182613917576000613a91613a7f610160880161014089016142ec565b610a1061018089016101608a016142ec565b509050613abc81613aaa6101a089016101808a016142ec565b60e089013563064e6cbb60e51b613f65565b91505061392081614132565b60005a9050613ad960008335613757565b60008030613af861380c6009846137e86101608a016101408b016142ec565b604051631a3d8e8d60e21b90613b12908890602401614f4c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613b50919061490a565b60006040518083038160008787f1925050503d8060008114613b8e576040519150601f19603f3d011682016040523d82523d6000602084013e613b93565b606091505b50909250905060018261391757613914613bb5610160870161014088016142ec565b613bc76101a0880161018089016142ec565b610100880135612a0960808a0160608b01614579565b60005a9050613bee60008335613757565b60008030613c0d61380c6009846137e86101608a016101408b016142ec565b6040516389e707ad60e01b90613b12908890602401614f4c565b6040516000906001600160a01b038516908390859084818181858888f193505050503d8060008114613c75576040519150601f19603f3d011682016040523d82523d6000602084013e613c7a565b606091505b50509050806126ab576040805162461bcd60e51b815260206004808301919091526024820152632a2419a360e11b604482015290519081900360640190fd5b60006004612a5e565b8183038184821115613d525760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613d17578181015183820152602001613cff565b50505050905090810190601f168015613d445780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b509392505050565b6001600160a01b038381166000908152600960205260408082205492881682528120549091829182913091613d8e91612781565b604051633ed76f1760e01b90613db2908d908d908d908d908d908d906024016149cc565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613df0919061490a565b60006040518083038160008787f1925050503d8060008114613e2e576040519150601f19603f3d011682016040523d82523d6000602084013e613e33565b606091505b509150915081613ed857876001600160a01b0316896001600160a01b03167f786212e89f390a4c768f3b935b85e0ec2561a24b6f48cda3c4b48a996b2115928984604051613e82929190614f73565b60405180910390a3856001600160a01b0316896001600160a01b03167f786212e89f390a4c768f3b935b85e0ec2561a24b6f48cda3c4b48a996b2115928784604051613ecf929190614f73565b60405180910390a35b50979650505050505050565b600081613ef35750600161208e565b60008052600960205260008051602061504283398151915254613f1990849084906141e3565b9050801515836001600160a01b03167fdbef2fc26e7694e7a1c5a4801b1ad144136d149cf76f310a780689b4087f0ffe84604051613f579190614f6a565b60405180910390a392915050565b600082613f745750600161407a565b600080306001600160a01b031661d6d8858989896000604051602401613f9d9493929190614a06565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613fdb919061490a565b60006040518083038160008787f1925050503d8060008114614019576040519150601f19603f3d011682016040523d82523d6000602084013e61401e565b606091505b50915091508161407657866001600160a01b0316866001600160a01b03167f786212e89f390a4c768f3b935b85e0ec2561a24b6f48cda3c4b48a996b211592878460405161406d929190614f73565b60405180910390a35b5090505b949350505050565b6000826140915750600161407a565b6001600160a01b0385166000908152600960205260408082205490518291309163e5b1be6560e01b90613f9d908b908b908b908b90602401614a06565b600090815260039091016020526040812055565b6000808211614121576040805162461bcd60e51b81526020600480830191909152602482015263534d343360e01b604482015290519081900360640190fd5b81838161412a57fe5b049392505050565b80614146576141416000614241565b614150565b6141506000614264565b50565b60008080614161878761357e565b90506141746155946107965a8890612758565b92506000614199826141946000600601548761357e90919063ffffffff16565b61427d565b90506141a58282612758565b92506141b13382613ee4565b6141cd5760405162461bcd60e51b81526004016106b990614bfe565b6141d78584613ee4565b50505094509492505050565b6040516000906001600160a01b038516908390859084818181858888f193505050503d8060008114614231576040519150601f19603f3d011682016040523d82523d6000602084013e614236565b606091505b509095945050505050565b60028101546000908152600c90910160205260409020805460ff19166001179055565b6002810154600090815260039091016020526040812055565b600081831061428c578161208b565b5090919050565b803561099a8161501e565b803561099a81615033565b600061010082840312156142bb578081fd5b50919050565b80516001600160701b038116811461099a57600080fd5b803563ffffffff8116811461099a57600080fd5b6000602082840312156142fd578081fd5b81356127518161501e565b600060208284031215614319578081fd5b81516127518161501e565b600080600060608486031215614338578182fd5b83356143438161501e565b925060208401356143538161501e565b929592945050506040919091013590565b60008060008060008060c0878903121561437c578182fd5b86356143878161501e565b955060208701356143978161501e565b94506040870135935060608701356143ae8161501e565b92506080870135915060a08701356143c581615033565b809150509295509295509295565b600080600080608085870312156143e8578384fd5b84356143f38161501e565b935060208501356144038161501e565b925060408501359150606085013561441a81615033565b939692955090935050565b60008060408385031215614437578182fd5b82356144428161501e565b9150602083013561445281615033565b809150509250929050565b600080600060608486031215614471578283fd5b833561447c8161501e565b925060208401356005811061448f578283fd5b9150604084013561449f81615033565b809150509250925092565b600080604083850312156144bc578182fd5b82356144c78161501e565b9150602083013561ffff81168114614452578182fd5b600080604083850312156144ef578081fd5b82356144fa8161501e565b946020939093013593505050565b6000806020838503121561451a578182fd5b823567ffffffffffffffff80821115614531578384fd5b818501915085601f830112614544578384fd5b813581811115614552578485fd5b86602061026083028501011115614567578485fd5b60209290920196919550909350505050565b60006020828403121561458a578081fd5b813561275181615033565b600080600080608085870312156145aa578182fd5b84516145b581615033565b60208601516040870151606090970151919890975090945092505050565b600061010082840312156145e5578081fd5b61208b83836142a9565b600061016082840312156142bb578081fd5b600061026082840312156142bb578081fd5b600061012082840312156142bb578081fd5b60008060408385031215614637578182fd5b614640836142c1565b915061464e602084016142c1565b90509250929050565b600060208284031215614668578081fd5b5035919050565b600060208284031215614680578081fd5b5051919050565b60008060408385031215614699578182fd5b50508035926020909101359150565b600080604083850312156146ba578182fd5b505080516020909101519092909150565b6000806000606084860312156146df578081fd5b8351925060208401519150604084015190509250925092565b600060208284031215614709578081fd5b61208b826142d8565b6001600160a01b03169052565b15159052565b6000815180845261473d816020860160208601614ff2565b601f01601f19169290920160200192915050565b803561475c8161501e565b6001600160a01b0390811683526020820135906147788261501e565b166020830152604081810135908301526060808201359083015260808101356147a081615033565b1515608083015260a08101356147b58161501e565b6147c260a0840182614712565b5060c081013560c08301526147d960e082016142d8565b61207960e0840182614900565b80358252602081013560208301526040810135604083015261480a6060820161429e565b614817606084018261471f565b506080810135608083015260a081013560a083015260c081013560c083015260e081013560e0830152610100808201358184015250610120808201358184015250610140614866818301614293565b61487282850182614712565b5050610160614882818301614293565b61488e82850182614712565b505061018061489e818301614293565b6148aa82850182614712565b50506101a081810135908301526101c080820135908301526101e06148d081830161429e565b6148dc8285018261471f565b50506102008181013590830152610220808201359083015261024090810135910152565b63ffffffff169052565b6000825161491c818460208701614ff2565b9190910192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039687168152948616602086015292851660408501529084166060840152909216608082015260a081019190915260c00190565b6001600160a01b0396871681529486166020860152928516604085015293166060830152608082019290925260a081019190915260c00190565b6001600160a01b0396871681529486166020860152604085019390935293166060830152608082019290925290151560a082015260c00190565b6001600160a01b0394851681529290931660208301526040820152901515606082015260800190565b6001600160a01b03878116825286166020820152604081018590526060810184905261ffff8316608082015260c060a08201819052600090614a7390830184614725565b98975050505050505050565b6001600160a01b039290921682521515602082015260400190565b6001600160a01b0392909216825261ffff16602082015260400190565b901515815260200190565b6000851515825284602083015283604083015260806060830152614ae96080830184614725565b9695505050505050565b600060608252614b066060830186614725565b60208301949094525060400152919050565b6020810160068310614b2657fe5b91905290565b6020808252600490820152632a22181b60e11b604082015260600190565b6020808252600490820152635444314360e01b604082015260600190565b60208082526004908201526315110c4d60e21b604082015260600190565b6020808252600490820152635444323160e01b604082015260600190565b6020808252600490820152635444303360e01b604082015260600190565b6020808252600490820152635444333760e01b604082015260600190565b6020808252600490820152630544430360e41b604082015260600190565b6020808252600490820152630544434360e41b604082015260600190565b6020808252600490820152634f53313760e01b604082015260600190565b60208082526004908201526315110d4d60e21b604082015260600190565b60208082526004908201526315110c0d60e21b604082015260600190565b6020808252600490820152632a221a9960e11b604082015260600190565b60208082526004908201526327a99b9960e11b604082015260600190565b6020808252600490820152632a22181960e11b604082015260600190565b6020808252600490820152630a88860760e31b604082015260600190565b8481526001600160a01b03841660208201526080810160058410614d0e57fe5b836040830152821515606083015295945050505050565b9283526001600160a01b03919091166020830152604082015260600190565b8381526101408101614d596020830185614751565b82610120830152949350505050565b8381526101a08101614d8560208301614d8086614293565b614712565b614d9160208501614293565b614d9e6040840182614712565b506040840135606083015260608401356080830152608084013560a083015260a084013560c0830152614dd360c0850161429e565b614de060e084018261471f565b50614ded60e0850161429e565b610100614dfc8185018361471f565b614e07818701614293565b915050610120614e1981850183614712565b6101409150808601358285015250614e328186016142d8565b9050614e42610160840182614900565b5082610180830152949350505050565b828152610280810161275160208301846147e6565b8281526101408101614e7f60208301614d8085614293565b614e8b60208401614293565b614e986040840182614712565b506040830135606083015260608301356080830152608083013560a0830152614ec360a0840161429e565b614ed060c084018261471f565b50614edd60c08401614293565b614eea60e0840182614712565b5061010060e084013581840152614f028185016142d8565b9050613d52610120840182614900565b918252602082015260400190565b9485526001600160a01b0393841660208601526040850192909252606084015216608082015260a00190565b610260810161208e82846147e6565b61ffff91909116815260200190565b90815260200190565b60008382526040602083015261407a6040830184614725565b600085825284602083015260018060a01b038416604083015260806060830152614ae96080830184614725565b600084825283602083015260606040830152614fd86060830184614725565b95945050505050565b63ffffffff91909116815260200190565b60005b8381101561500d578181015183820152602001614ff5565b838111156126ab5750506000910152565b6001600160a01b038116811461415057600080fd5b801515811461415057600080fdfeec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6ba2646970667358221220e5130bef40aa458ce994409390489e3bef2cd61a29a5f9eb62a8550b8a4978c964736f6c63430007060033000000000000000000000000c480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000003a1d749fa4a9e650fce844ff1c58c5faf7e2a9d1

Deployed Bytecode

0x6080604052600436106102605760003560e01c80637f6a1caf11610144578063bf6b874e116100b6578063e29577ee1161007a578063e29577ee14610614578063e30a499314610627578063e5b1be651461063c578063e5e7988e1461064f578063e6a0cc941461066f578063fe173b971461068457610267565b8063bf6b874e1461058c578063c45a0155146105ac578063c9cd9760146105c1578063ceb0981f146105d4578063d22e92421461060157610267565b80639d08ebb5116101085780639d08ebb5146104f3578063a70885c114610506578063af482b5814610533578063b32ac93614610553578063b5540b2b14610566578063ba4d53121461057957610267565b80637f6a1caf1461048557806389e707ad146104985780638da5cb5b146104ab57806394531713146104c05780639718f627146104d357610267565b80634c016016116101dd57806368f63a34116101a157806368f63a34146103f55780636a42b8f8146104085780636de3c67c1461041d57806370190d4c1461043257806377632ec214610452578063793ab2971461047257610267565b80634c016016146103785780635051349a14610398578063576b332b146103b857806357a62a4f146103cb5780635e45da23146103e057610267565b8063303a892b11610224578063303a892b146102fd578063342aa8b5146103105780633bbac579146103235780633ed76f17146103435780633fc8cef31461035657610267565b806302241c701461026c578063103486651461028e57806313af4035146102a15780631776834a146102b457806320a68fab146102c757610267565b3661026757005b600080fd5b34801561027857600080fd5b5061028c610287366004614601565b610699565b005b61028c61029c3660046146f8565b6107ea565b61028c6102af3660046142ec565b610859565b61028c6102c2366004614657565b6108f4565b3480156102d357600080fd5b506102e76102e23660046142ec565b61098b565b6040516102f49190614ab7565b60405180910390f35b61028c61030b366004614601565b61099f565b61028c61031e366004614425565b610d71565b34801561032f57600080fd5b506102e761033e3660046142ec565b610dfd565b61028c610351366004614364565b610e12565b34801561036257600080fd5b5061036b610e32565b6040516102f49190614929565b34801561038457600080fd5b506102e76103933660046142ec565b610e41565b6103ab6103a63660046145d3565b610e4d565b6040516102f49190614f6a565b6103ab6103c6366004614613565b610ef0565b3480156103d757600080fd5b506103ab610f53565b3480156103ec57600080fd5b506103ab610f59565b61028c610403366004614601565b610f5f565b34801561041457600080fd5b506103ab6111a6565b34801561042957600080fd5b506103ab6111ac565b34801561043e57600080fd5b5061028c61044d366004614601565b6111b2565b34801561045e57600080fd5b506102e761046d366004614657565b61127d565b61028c6104803660046144aa565b611292565b61028c61049336600461445d565b61133a565b61028c6104a6366004614601565b6113ce565b3480156104b757600080fd5b5061036b611aae565b61028c6104ce366004614657565b611abd565b3480156104df57600080fd5b506103ab6104ee3660046142ec565b611b21565b6103ab6105013660046145ef565b611b3c565b34801561051257600080fd5b506105266105213660046142ec565b611ba2565b6040516102f49190614f5b565b34801561053f57600080fd5b506102e761054e3660046142ec565b611bb8565b61028c610561366004614657565b611bc4565b61028c610574366004614508565b611c28565b6103ab6105873660046145d3565b611fbf565b34801561059857600080fd5b506103ab6105a73660046142ec565b612025565b3480156105b857600080fd5b5061036b612040565b61028c6105cf366004614324565b61204f565b3480156105e057600080fd5b506105f46105ef366004614687565b61207e565b6040516102f49190614b18565b61028c61060f3660046144dd565b612094565b61028c610622366004614601565b612126565b34801561063357600080fd5b506103ab6124ac565b61028c61064a3660046143d3565b6124b2565b34801561065b57600080fd5b506102e761066a3660046142ec565b6126b1565b34801561067b57600080fd5b506103ab6126bd565b34801561069057600080fd5b506103ab6126c3565b601254156106c25760405162461bcd60e51b81526004016106b990614b2c565b60405180910390fd5b6001601255604051632e548b5b60e01b815273e02c42a6a5099430834893be473c6a8452adb90b90632e548b5b90610701906000908590600401614e52565b60006040518083038186803b15801561071957600080fd5b505af415801561072d573d6000803e3d6000fd5b506002925061073a915050565b61074b6000833560408501356126c9565b600581111561075657fe5b146107735760405162461bcd60e51b81526004016106b990614c76565b4261079c620151806107966000800154856040013561275890919063ffffffff16565b90612781565b106107b95760405162461bcd60e51b81526004016106b990614b4a565b80356000908152600a60205260409020805460ff191660019081179091556107e29082906127c2565b506000601255565b600f546001600160a01b031633146108145760405162461bcd60e51b81526004016106b990614be0565b63ffffffff81166000556040517f63e09f16584208fba1fc7ff64c62b00f07bec177c0d97ca6689891b1e77a35c79061084e908390614fe1565b60405180910390a150565b600f546001600160a01b031633146108835760405162461bcd60e51b81526004016106b990614be0565b6001600160a01b0381166108a95760405162461bcd60e51b81526004016106b990614cb2565b600f80546001600160a01b0319166001600160a01b0383161790556040517f50146d0e3c60aa1d17a70635b05494f864e86144a2201275021014fbf08bafe29061084e908390614929565b600f546001600160a01b0316331461091e5760405162461bcd60e51b81526004016106b990614be0565b604051636702eca360e01b815273e02c42a6a5099430834893be473c6a8452adb90b90636702eca390610958906000908590600401614f12565b60006040518083038186803b15801561097057600080fd5b505af4158015610984573d6000803e3d6000fd5b5050505050565b60006109978183612a59565b90505b919050565b3330146109be5760405162461bcd60e51b81526004016106b990614be0565b426202a30082604001350110156109e75760405162461bcd60e51b81526004016106b990614c58565b6000610a196109fe610160840161014085016142ec565b610a10610180850161016086016142ec565b60009190612a8d565b5090506000806000610a2b8585612b5a565b91945092509050610a4461020086016101e08701614579565b8015610a4f57508015155b15610c53576000610a6a858761020001358860800135612e06565b90508315801590610a7b5750816001145b15610b61576000730ec2323adafbebc6c80257c7359692bcceb0b3f163d0b0a9bc87610aaf6101608b016101408c016142ec565b6001600160a01b038a16600090815260116020526040908190205490516001600160e01b031960e086901b168152610afb9392918b916101a08f01359161ffff16908a90600401614a2f565b604080518083038186803b158015610b1257600080fd5b505af4158015610b26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4a91906146a8565b9095509050610b598482612781565b935050610c51565b8215801590610b705750816002145b15610c51576000730ec2323adafbebc6c80257c7359692bcceb0b3f163adf5f8f387610ba46101808b016101608c016142ec565b6001600160a01b038a16600090815260116020526040908190205490516001600160e01b031960e086901b168152610bf09392918a916101c08f01359161ffff16908a90600401614a2f565b604080518083038186803b158015610c0757600080fd5b505af4158015610c1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3f91906146a8565b94509050610c4d8582612781565b9450505b505b8215801590610c6157508115155b15610d3157730ec2323adafbebc6c80257c7359692bcceb0b3f1637a528bd285610c936101a089016101808a016142ec565b610ca56101608a016101408b016142ec565b610cb76101808b016101608c016142ec565b88886040518763ffffffff1660e01b8152600401610cda96959493929190614992565b60606040518083038186803b158015610cf257600080fd5b505af4158015610d06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2a91906146cb565b5090935091505b610984610d466101a0870161018088016142ec565b610d58610160880161014089016142ec565b610d6a61018089016101608a016142ec565b8686612f24565b600f546001600160a01b03163314610d9b5760405162461bcd60e51b81526004016106b990614be0565b6001600160a01b03821660009081526010602052604090819020805460ff1916831515179055517f70af441dbb427737e6a5ef2cf5b664321011765ce1d19ce4a69cd024e69d4f2f90610df19084908490614a7f565b60405180910390a15050565b60106020526000908152604090205460ff1681565b610e1e858786846124b2565b610e2a838784846124b2565b505050505050565b600e546001600160a01b031690565b60006109978183612f46565b6000601254600014610e715760405162461bcd60e51b81526004016106b990614b2c565b600160125560405162c44ff160e31b815273e02c42a6a5099430834893be473c6a8452adb90b906306227f8890610eb2906000908690600d90600401614d44565b60006040518083038186803b158015610eca57600080fd5b505af4158015610ede573d6000803e3d6000fd5b50506001546000601255949350505050565b6000601254600014610f145760405162461bcd60e51b81526004016106b990614b2c565b6001601255604051636587992160e01b815273e02c42a6a5099430834893be473c6a8452adb90b90636587992190610eb2906000908690600401614e67565b60085490565b60055490565b333014610f7e5760405162461bcd60e51b81526004016106b990614be0565b426202a3008260400135011015610fa75760405162461bcd60e51b81526004016106b990614c58565b6000610fbe6109fe610160840161014085016142ec565b509050806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610ffc57600080fd5b505af1158015611010573d6000803e3d6000fd5b50505050600061102a828461020001358560800135612e06565b90506020830135600614600061104285838686612f4f565b90506000808361105457600083611058565b8260005b600e5491935091506001600160a01b031661107b61018089016101608a016142ec565b6001600160a01b031614801561109c575061109c6080880160608901614579565b156111275760405163022c0d9f60e01b81526001600160a01b0387169063022c0d9f906110d3908590859030908b90600401614f8c565b600060405180830381600087803b1580156110ed57600080fd5b505af1158015611101573d6000803e3d6000fd5b50611122925061111c9150506101a089016101808a016142ec565b8461345e565b61119d565b6001600160a01b03861663022c0d9f838361114a6101a08c016101808d016142ec565b896040518563ffffffff1660e01b815260040161116a9493929190614f8c565b600060405180830381600087803b15801561118457600080fd5b505af1158015611198573d6000803e3d6000fd5b505050505b50505050505050565b60005490565b60075490565b601254156111d25760405162461bcd60e51b81526004016106b990614b2c565b6001601255604051632e548b5b60e01b815273e02c42a6a5099430834893be473c6a8452adb90b90632e548b5b90611211906000908590600401614e52565b60006040518083038186803b15801561122957600080fd5b505af415801561123d573d6000803e3d6000fd5b50505081356000908152600c602052604090205460ff1690506112725760405162461bcd60e51b81526004016106b990614b86565b6107e28160006127c2565b6000908152600a602052604090205460ff1690565b600f546001600160a01b031633146112bc5760405162461bcd60e51b81526004016106b990614be0565b600a61ffff821611156112e15760405162461bcd60e51b81526004016106b990614c3a565b6001600160a01b03821660009081526011602052604090819020805461ffff191661ffff8416179055517f6b4044e33be5af8fcdb7449c49137010eede3c8c06d5d08067151a7ace17266d90610df19084908490614a9a565b600f546001600160a01b031633146113645760405162461bcd60e51b81526004016106b990614be0565b60405163146bce4f60e31b815273e02c42a6a5099430834893be473c6a8452adb90b9063a35e7278906113a290600090879087908790600401614cee565b60006040518083038186803b1580156113ba57600080fd5b505af415801561119d573d6000803e3d6000fd5b3330146113ed5760405162461bcd60e51b81526004016106b990614be0565b426202a30082604001350110156114165760405162461bcd60e51b81526004016106b990614c58565b600061142d6109fe610160840161014085016142ec565b509050600073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d611460610160870161014088016142ec565b61010087013561022088013561147e6101a08a016101808b016142ec565b6040518663ffffffff1660e01b815260040161149e959493929190614f20565b60206040518083038186803b1580156114b657600080fd5b505af41580156114ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ee919061466f565b9050816001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561152b57600080fd5b505af115801561153f573d6000803e3d6000fd5b505050506000611559838561020001358660800135612e06565b905060008060008060048860200135149050600080886001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401604080518083038186803b1580156115a657600080fd5b505afa1580156115ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115de9190614625565b915091506116036001846115f257826115f4565b835b6001600160701b031690612758565b935050506000876001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b15801561164257600080fd5b505afa158015611656573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061167a9190614308565b90506000886001600160a01b03166354cf2aeb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156116b757600080fd5b505afa1580156116cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116ef919061466f565b9050816001600160a01b031663daab4b6e84838d61012001358b6040518563ffffffff1660e01b81526004016117289493929190614ac2565b604080518083038186803b15801561173f57600080fd5b505afa158015611753573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177791906146a8565b909650945060008486111561182d5761179f6101208c01356117998b8861357e565b906135d3565b60405163a7d2087760e01b81529091506001600160a01b0384169063a7d20877906117d490879086908a908e90600401614ac2565b604080518083038186803b1580156117eb57600080fd5b505afa1580156117ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182391906146a8565b9097509550611838565b506101208a01359450875b868110156118585760405162461bcd60e51b81526004016106b990614cd0565b8689111561190357600e546001600160a01b031661187e6101608d016101408e016142ec565b6001600160a01b031614801561189f575061189f60808c0160608d01614579565b156118cd576118c86118b96101a08d016101808e016142ec565b6118c38b8a612758565b61345e565b611903565b6119036118e26101608d016101408e016142ec565b6118f46101a08e016101808f016142ec565b6118fe8c8b612758565b613603565b61191f6119186101608d016101408e016142ec565b8b89613603565b5050506001600160a01b03871660009081526011602052604090205461194a90849061ffff16612758565b9250600080821561195d57849150611960565b50835b600e546001600160a01b031661197e6101808c016101608d016142ec565b6001600160a01b031614801561199f575061199f60808b0160608c01614579565b15611a2a5760405163022c0d9f60e01b81526001600160a01b038a169063022c0d9f906119d6908590859030908d90600401614f8c565b600060405180830381600087803b1580156119f057600080fd5b505af1158015611a04573d6000803e3d6000fd5b50611a259250611a1f9150506101a08c016101808d016142ec565b8661345e565b611aa2565b886001600160a01b031663022c0d9f83838d610180016020810190611a4f91906142ec565b8b6040518563ffffffff1660e01b8152600401611a6f9493929190614f8c565b600060405180830381600087803b158015611a8957600080fd5b505af1158015611a9d573d6000803e3d6000fd5b505050505b50505050505050505050565b600f546001600160a01b031681565b600f546001600160a01b03163314611ae75760405162461bcd60e51b81526004016106b990614be0565b604051630fd1437d60e11b815273e02c42a6a5099430834893be473c6a8452adb90b90631fa286fa90610958906000908590600401614f12565b6001600160a01b031660009081526009602052604090205490565b6000601254600014611b605760405162461bcd60e51b81526004016106b990614b2c565b6001601255604051638f0e6bef60e01b815273e02c42a6a5099430834893be473c6a8452adb90b90638f0e6bef90610eb2906000908690600d90600401614d68565b60116020526000908152604090205461ffff1681565b6000610997818361374e565b600f546001600160a01b03163314611bee5760405162461bcd60e51b81526004016106b990614be0565b60405163153cc2fd60e31b815273e02c42a6a5099430834893be473c6a8452adb90b9063a9e617e890610958906000908590600401614f12565b60125415611c485760405162461bcd60e51b81526004016106b990614b2c565b60016012558060005a3360009081526010602052604081205491925090819060ff1680611c9f57506000805260106020527f6e0956cda88cad152e89927e53611735b61a5c762d1428573c6931b0a5efcb015460ff165b905060005b84811015611f3657600254878783818110611cbb57fe5b905061026002016000013511611cd057611f2e565b600a6000888884818110611ce057fe5b61026002919091013582525060208101919091526040016000205460ff1615611d2957611d24878783818110611d1257fe5b60009261026090910201359050613757565b611f2e565b73e02c42a6a5099430834893be473c6a8452adb90b632e548b5b6000898985818110611d5157fe5b905061026002016040518363ffffffff1660e01b8152600401611d75929190614e52565b60006040518083038186803b158015611d8d57600080fd5b505af4158015611da1573d6000803e3d6000fd5b505050506000878783818110611db357fe5b90506102600201604001359050428110611dcd5750611f36565b8280611ddd57506104b081014210155b611df95760405162461bcd60e51b81526004016106b990614be0565b600193506001888884818110611e0b57fe5b90506102600201602001351415611e3c57611e37888884818110611e2b57fe5b90506102600201613782565b611f2c565b6002888884818110611e4a57fe5b90506102600201602001351415611e7657611e37888884818110611e6a57fe5b90506102600201613999565b6005888884818110611e8457fe5b90506102600201602001351480611eb157506006888884818110611ea457fe5b9050610260020160200135145b15611ed157611e37888884818110611ec557fe5b90506102600201613ac8565b6003888884818110611edf57fe5b90506102600201602001351480611f0c57506004888884818110611eff57fe5b9050610260020160200135145b15611f2c57611f2c888884818110611f2057fe5b90506102600201613bdd565b505b600101611ca4565b508115611fb25773e02c42a6a5099430834893be473c6a8452adb90b639db74df16000611f645a8790612758565b6040518363ffffffff1660e01b8152600401611f81929190614f12565b60006040518083038186803b158015611f9957600080fd5b505af4158015611fad573d6000803e3d6000fd5b505050505b5050600060125550505050565b6000601254600014611fe35760405162461bcd60e51b81526004016106b990614b2c565b600160125560405163758e99b360e01b815273e02c42a6a5099430834893be473c6a8452adb90b9063758e99b390610eb2906000908690600d90600401614d44565b6001600160a01b03166000908152600d602052604090205490565b6004546001600160a01b031690565b33301461206e5760405162461bcd60e51b81526004016106b990614be0565b612079838383613603565b505050565b600061208b8184846126c9565b90505b92915050565b600f546001600160a01b031633146120be5760405162461bcd60e51b81526004016106b990614be0565b60405163b2456a0760e01b815273e02c42a6a5099430834893be473c6a8452adb90b9063b2456a07906120fa9060009086908690600401614d25565b60006040518083038186803b15801561211257600080fd5b505af4158015610e2a573d6000803e3d6000fd5b3330146121455760405162461bcd60e51b81526004016106b990614be0565b426202a300826040013501101561216e5760405162461bcd60e51b81526004016106b990614c58565b60006121856109fe610160840161014085016142ec565b509050806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156121c357600080fd5b505af11580156121d7573d6000803e3d6000fd5b505050506121ea81828460e00135613603565b600080806121fe6080860160608701614579565b801561225c5750600e546001600160a01b0316612223610160870161014088016142ec565b6001600160a01b0316148061225c5750600e546001600160a01b0316612251610180870161016088016142ec565b6001600160a01b0316145b156123e25760007319f6bc0755fd4a465b3961fb335d6e55ab8b9eaa63cf58beed61228f61016089016101408a016142ec565b6122a16101808a016101608b016142ec565b600e5489906001600160a01b03166122c16101a08d016101808e016142ec565b600080526009602052600080516020615042833981519152546040516001600160e01b031960e089901b16815261230096959493929190600401614957565b60806040518083038186803b15801561231857600080fd5b505af415801561232c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123509190614595565b919650945092509050806123dc5773a33efea216b31f7c16697654fbd8d6c857965d9663656621e0600d61238c6101a08a016101808b016142ec565b876040518463ffffffff1660e01b81526004016123ab93929190614d25565b60006040518083038186803b1580156123c357600080fd5b505af41580156123d7573d6000803e3d6000fd5b505050505b50612476565b6001600160a01b0384166389afcb446124036101a0880161018089016142ec565b6040518263ffffffff1660e01b815260040161241f9190614929565b6040805180830381600087803b15801561243857600080fd5b505af115801561244c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061247091906146a8565b90925090505b846101000135821015801561249057508461012001358110155b6109845760405162461bcd60e51b81526004016106b990614ba4565b60015490565b3330146124d15760405162461bcd60e51b81526004016106b990614be0565b600e546001600160a01b0385811691161480156124eb5750805b1561261257604051632a359a6d60e21b815260009073a33efea216b31f7c16697654fbd8d6c857965d969063a8d669b49061253390600d908990889087908b90600401614f20565b60206040518083038186803b15801561254b57600080fd5b505af415801561255f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612583919061466f565b600e54604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d906125b4908490600401614f6a565b600060405180830381600087803b1580156125ce57600080fd5b505af11580156125e2573d6000803e3d6000fd5b505060008052505060096020526000805160206150428339815191525461260c9085908390613c27565b506126ab565b604051632a359a6d60e21b81526126ab908590859073a33efea216b31f7c16697654fbd8d6c857965d969063a8d669b49061265b90600d9086908a906000908890600401614f20565b60206040518083038186803b15801561267357600080fd5b505af4158015612687573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fe919061466f565b50505050565b60006109978183613cb9565b60025490565b60065490565b600083600101548311156126df57506000612751565b6000838152600a8501602052604090205460ff161561270057506005612751565b6000838152600c8501602052604090205460ff161561272157506004612751565b600083815260038501602052604090205461273e57506003612751565b42821061274d57506001612751565b5060025b9392505050565b600061208b83836040518060400160405280600481526020016329a6989960e11b815250613cc2565b8082018281101561208e576040805162461bcd60e51b81526020600480830191909152602482015263534d344560e01b604482015290519081900360640190fd5b6000426127d760408501356301e13380612781565b1090506001836020013514156128bc57600081612805576128006101a0850161018086016142ec565b612812565b600f546001600160a01b03165b905061285d8161282a610160870161014088016142ec565b61010087013561284261018089016101608a016142ec565b61012089013561285860808b0160608c01614579565b613d5a565b6128795760405162461bcd60e51b81526004016106b990614b68565b82156128b65761289a8161289560c087013560a088013561357e565b613ee4565b6128b65760405162461bcd60e51b81526004016106b990614bfe565b50612a49565b6002836020013514156129945760006128f26128e0610160860161014087016142ec565b610a10610180870161016088016142ec565b5090506000826129135761290e6101a0860161018087016142ec565b612920565b600f546001600160a01b03165b9050612939828260e088013563064e6cbb60e51b613f65565b6129555760405162461bcd60e51b81526004016106b990614b68565b831561298d576129718161289560c088013560a089013561357e565b61298d5760405162461bcd60e51b81526004016106b990614bfe565b5050612a49565b6005836020013514806129ab575060068360200135145b15612a0e576000816129ce576129c96101a0850161018086016142ec565b6129db565b600f546001600160a01b03165b905061285d6129f2610160860161014087016142ec565b82610100870135612a096080890160608a01614579565b614082565b600383602001351480612a25575060048360200135145b15612a43576000816129ce576129c96101a0850161018086016142ec565b50612a55565b612079600084356140ce565b5050565b600060025b6001600160a01b0383166000908152600b85016020526040902054600160ff9283161b16161515905092915050565b60048084015460405163e6a4390560e01b815260009283926001600160a01b03169163e6a4390591612ac391889188910161493d565b60206040518083038186803b158015612adb57600080fd5b505afa158015612aef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b139190614308565b91506001600160a01b038216612b3b5760405162461bcd60e51b81526004016106b990614c1c565b826001600160a01b0316846001600160a01b0316119050935093915050565b600080808073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d612b8d6101608a016101408b016142ec565b6101008a01356102208b0135612bab6101a08d016101808e016142ec565b6040518663ffffffff1660e01b8152600401612bcb959493929190614f20565b60206040518083038186803b158015612be357600080fd5b505af4158015612bf7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c1b919061466f565b9050600073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d612c4d6101808b016101608c016142ec565b6101208b01356102408c0135612c6b6101a08e016101808f016142ec565b6040518663ffffffff1660e01b8152600401612c8b959493929190614f20565b60206040518083038186803b158015612ca357600080fd5b505af4158015612cb7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cdb919061466f565b9050856001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612d1857600080fd5b505af1158015612d2c573d6000803e3d6000fd5b50505050730ec2323adafbebc6c80257c7359692bcceb0b3f1637a528bd28789610180016020810190612d5f91906142ec565b612d716101608c016101408d016142ec565b612d836101808d016101608e016142ec565b87876040518763ffffffff1660e01b8152600401612da696959493929190614992565b60606040518083038186803b158015612dbe57600080fd5b505af4158015612dd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df691906146cb565b9199909850909650945050505050565b60606000846001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b158015612e4357600080fd5b505afa158015612e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7b9190614308565b6001600160a01b0316636a9150fe85856040518363ffffffff1660e01b8152600401612ea8929190614f12565b60206040518083038186803b158015612ec057600080fd5b505afa158015612ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef8919061466f565b905080604051602001612f0b9190614f6a565b6040516020818303038152906040529150509392505050565b8115612f3557612f35848684613603565b801561098457610984838683613603565b60006003612a5e565b600080600080856001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401604080518083038186803b158015612f8d57600080fd5b505afa158015612fa1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fc59190614625565b91509150612fd96001886115f257826115f4565b925050506000846001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b15801561301857600080fd5b505afa15801561302c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130509190614308565b90506000856001600160a01b03166354cf2aeb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561308d57600080fd5b505afa1580156130a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130c5919061466f565b9050600073a33efea216b31f7c16697654fbd8d6c857965d9663a8d669b4600d6130f76101608d016101408e016142ec565b8c61010001358d61022001358e61018001602081019061311791906142ec565b6040518663ffffffff1660e01b8152600401613137959493929190614f20565b60206040518083038186803b15801561314f57600080fd5b505af4158015613163573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613187919061466f565b905087613213576040516304a8fad760e31b81526001600160a01b03841690632547d6b8906131be90859085908b90600401614fb9565b60206040518083038186803b1580156131d657600080fd5b505afa1580156131ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061320e919061466f565b613293565b60405163c4109d2560e01b81526001600160a01b0384169063c4109d259061324390859085908b90600401614fb9565b60206040518083038186803b15801561325b57600080fd5b505afa15801561326f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613293919061466f565b94506000848611156133e3576132b8866132b26101208d01358861357e565b906140e2565b60405163a7d2087760e01b815290915082906001600160a01b0386169063a7d20877906132ef908d9088908b908e90600401614ac2565b604080518083038186803b15801561330657600080fd5b505afa15801561331a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061333e91906146a8565b600e549098509093506001600160a01b03166133626101608d016101408e016142ec565b6001600160a01b0316148015613383575061338360808c0160608d01614579565b156133ac576133a761339d6101a08d016101808e016142ec565b6118c38386612758565b6133dd565b6133dd6133c16101608d016101408e016142ec565b6133d36101a08e016101808f016142ec565b6118fe8487612758565b506133eb565b506101208901355b6001600160a01b03881660009081526011602052604090205461341390879061ffff16612758565b9550808610156134355760405162461bcd60e51b81526004016106b990614bc2565b61345161344a6101608c016101408d016142ec565b8984613603565b5050505050949350505050565b600e54604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d9061348e908490600401614f6a565b600060405180830381600087803b1580156134a857600080fd5b505af11580156134bc573d6000803e3d6000fd5b505060008080526009602052600080516020615042833981519152546040519193506001600160a01b03861692509084906134f690614926565b600060405180830381858888f193505050503d8060008114613534576040519150601f19603f3d011682016040523d82523d6000602084013e613539565b606091505b50509050806120795760405163032b310f60e51b815273a33efea216b31f7c16697654fbd8d6c857965d969063656621e0906113a290600d9087908790600401614d25565b60008115806135995750508082028282828161359657fe5b04145b61208e576040805162461bcd60e51b81526020600480830191909152602482015263534d324160e01b604482015290519081900360640190fd5b60006135df83836140e2565b90506135eb828261357e565b831461208e576135fc816001612781565b905061208e565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b6020831061367f5780518252601f199092019160209182019101613660565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146136e1576040519150601f19603f3d011682016040523d82523d6000602084013e6136e6565b606091505b5091509150818015613714575080511580613714575080806020019051602081101561371157600080fd5b50515b610984576040805162461bcd60e51b815260206004808301919091526024820152635448303560e01b604482015290519081900360640190fd5b60006001612a5e565b600282018054600101908190558114612a555760405162461bcd60e51b81526004016106b990614c94565b60005a905061379360008335613757565b6000803061381761380c6009846137b26101808a016101608b016142ec565b6001600160a01b03168152602081019190915260400160009081205490610796906009906137e86101608c016101408d016142ec565b6001600160a01b0316815260208101919091526040016000205462012c6c90612781565b60a087013590612758565b60405163303a892b60e01b90613831908890602401614f4c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161386f919061490a565b60006040518083038160008787f1925050503d80600081146138ad576040519150601f19603f3d011682016040523d82523d6000602084013e6138b2565b606091505b509092509050600182613917576139146138d46101a0870161018088016142ec565b6138e6610160880161014089016142ec565b6101008801356138fe6101808a016101608b016142ec565b6101208a013561285860808c0160608d01614579565b90505b61392081614132565b60008061394860a088013560c0890135886139436101a08c016101808d016142ec565b614153565b915091508415156000600201547ff0cc99aeb224e65869630a14e23683d20b9c535c00427b50024ce8b6b21d35c386858560405161398893929190614af3565b60405180910390a350505050505050565b60005a90506139aa60008335613757565b600080306139c061380c62012c6c61d6d8612781565b60405163714abbf760e11b906139da908890602401614f4c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613a18919061490a565b60006040518083038160008787f1925050503d8060008114613a56576040519150601f19603f3d011682016040523d82523d6000602084013e613a5b565b606091505b509092509050600182613917576000613a91613a7f610160880161014089016142ec565b610a1061018089016101608a016142ec565b509050613abc81613aaa6101a089016101808a016142ec565b60e089013563064e6cbb60e51b613f65565b91505061392081614132565b60005a9050613ad960008335613757565b60008030613af861380c6009846137e86101608a016101408b016142ec565b604051631a3d8e8d60e21b90613b12908890602401614f4c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613b50919061490a565b60006040518083038160008787f1925050503d8060008114613b8e576040519150601f19603f3d011682016040523d82523d6000602084013e613b93565b606091505b50909250905060018261391757613914613bb5610160870161014088016142ec565b613bc76101a0880161018089016142ec565b610100880135612a0960808a0160608b01614579565b60005a9050613bee60008335613757565b60008030613c0d61380c6009846137e86101608a016101408b016142ec565b6040516389e707ad60e01b90613b12908890602401614f4c565b6040516000906001600160a01b038516908390859084818181858888f193505050503d8060008114613c75576040519150601f19603f3d011682016040523d82523d6000602084013e613c7a565b606091505b50509050806126ab576040805162461bcd60e51b815260206004808301919091526024820152632a2419a360e11b604482015290519081900360640190fd5b60006004612a5e565b8183038184821115613d525760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613d17578181015183820152602001613cff565b50505050905090810190601f168015613d445780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b509392505050565b6001600160a01b038381166000908152600960205260408082205492881682528120549091829182913091613d8e91612781565b604051633ed76f1760e01b90613db2908d908d908d908d908d908d906024016149cc565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613df0919061490a565b60006040518083038160008787f1925050503d8060008114613e2e576040519150601f19603f3d011682016040523d82523d6000602084013e613e33565b606091505b509150915081613ed857876001600160a01b0316896001600160a01b03167f786212e89f390a4c768f3b935b85e0ec2561a24b6f48cda3c4b48a996b2115928984604051613e82929190614f73565b60405180910390a3856001600160a01b0316896001600160a01b03167f786212e89f390a4c768f3b935b85e0ec2561a24b6f48cda3c4b48a996b2115928784604051613ecf929190614f73565b60405180910390a35b50979650505050505050565b600081613ef35750600161208e565b60008052600960205260008051602061504283398151915254613f1990849084906141e3565b9050801515836001600160a01b03167fdbef2fc26e7694e7a1c5a4801b1ad144136d149cf76f310a780689b4087f0ffe84604051613f579190614f6a565b60405180910390a392915050565b600082613f745750600161407a565b600080306001600160a01b031661d6d8858989896000604051602401613f9d9493929190614a06565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613fdb919061490a565b60006040518083038160008787f1925050503d8060008114614019576040519150601f19603f3d011682016040523d82523d6000602084013e61401e565b606091505b50915091508161407657866001600160a01b0316866001600160a01b03167f786212e89f390a4c768f3b935b85e0ec2561a24b6f48cda3c4b48a996b211592878460405161406d929190614f73565b60405180910390a35b5090505b949350505050565b6000826140915750600161407a565b6001600160a01b0385166000908152600960205260408082205490518291309163e5b1be6560e01b90613f9d908b908b908b908b90602401614a06565b600090815260039091016020526040812055565b6000808211614121576040805162461bcd60e51b81526020600480830191909152602482015263534d343360e01b604482015290519081900360640190fd5b81838161412a57fe5b049392505050565b80614146576141416000614241565b614150565b6141506000614264565b50565b60008080614161878761357e565b90506141746155946107965a8890612758565b92506000614199826141946000600601548761357e90919063ffffffff16565b61427d565b90506141a58282612758565b92506141b13382613ee4565b6141cd5760405162461bcd60e51b81526004016106b990614bfe565b6141d78584613ee4565b50505094509492505050565b6040516000906001600160a01b038516908390859084818181858888f193505050503d8060008114614231576040519150601f19603f3d011682016040523d82523d6000602084013e614236565b606091505b509095945050505050565b60028101546000908152600c90910160205260409020805460ff19166001179055565b6002810154600090815260039091016020526040812055565b600081831061428c578161208b565b5090919050565b803561099a8161501e565b803561099a81615033565b600061010082840312156142bb578081fd5b50919050565b80516001600160701b038116811461099a57600080fd5b803563ffffffff8116811461099a57600080fd5b6000602082840312156142fd578081fd5b81356127518161501e565b600060208284031215614319578081fd5b81516127518161501e565b600080600060608486031215614338578182fd5b83356143438161501e565b925060208401356143538161501e565b929592945050506040919091013590565b60008060008060008060c0878903121561437c578182fd5b86356143878161501e565b955060208701356143978161501e565b94506040870135935060608701356143ae8161501e565b92506080870135915060a08701356143c581615033565b809150509295509295509295565b600080600080608085870312156143e8578384fd5b84356143f38161501e565b935060208501356144038161501e565b925060408501359150606085013561441a81615033565b939692955090935050565b60008060408385031215614437578182fd5b82356144428161501e565b9150602083013561445281615033565b809150509250929050565b600080600060608486031215614471578283fd5b833561447c8161501e565b925060208401356005811061448f578283fd5b9150604084013561449f81615033565b809150509250925092565b600080604083850312156144bc578182fd5b82356144c78161501e565b9150602083013561ffff81168114614452578182fd5b600080604083850312156144ef578081fd5b82356144fa8161501e565b946020939093013593505050565b6000806020838503121561451a578182fd5b823567ffffffffffffffff80821115614531578384fd5b818501915085601f830112614544578384fd5b813581811115614552578485fd5b86602061026083028501011115614567578485fd5b60209290920196919550909350505050565b60006020828403121561458a578081fd5b813561275181615033565b600080600080608085870312156145aa578182fd5b84516145b581615033565b60208601516040870151606090970151919890975090945092505050565b600061010082840312156145e5578081fd5b61208b83836142a9565b600061016082840312156142bb578081fd5b600061026082840312156142bb578081fd5b600061012082840312156142bb578081fd5b60008060408385031215614637578182fd5b614640836142c1565b915061464e602084016142c1565b90509250929050565b600060208284031215614668578081fd5b5035919050565b600060208284031215614680578081fd5b5051919050565b60008060408385031215614699578182fd5b50508035926020909101359150565b600080604083850312156146ba578182fd5b505080516020909101519092909150565b6000806000606084860312156146df578081fd5b8351925060208401519150604084015190509250925092565b600060208284031215614709578081fd5b61208b826142d8565b6001600160a01b03169052565b15159052565b6000815180845261473d816020860160208601614ff2565b601f01601f19169290920160200192915050565b803561475c8161501e565b6001600160a01b0390811683526020820135906147788261501e565b166020830152604081810135908301526060808201359083015260808101356147a081615033565b1515608083015260a08101356147b58161501e565b6147c260a0840182614712565b5060c081013560c08301526147d960e082016142d8565b61207960e0840182614900565b80358252602081013560208301526040810135604083015261480a6060820161429e565b614817606084018261471f565b506080810135608083015260a081013560a083015260c081013560c083015260e081013560e0830152610100808201358184015250610120808201358184015250610140614866818301614293565b61487282850182614712565b5050610160614882818301614293565b61488e82850182614712565b505061018061489e818301614293565b6148aa82850182614712565b50506101a081810135908301526101c080820135908301526101e06148d081830161429e565b6148dc8285018261471f565b50506102008181013590830152610220808201359083015261024090810135910152565b63ffffffff169052565b6000825161491c818460208701614ff2565b9190910192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039687168152948616602086015292851660408501529084166060840152909216608082015260a081019190915260c00190565b6001600160a01b0396871681529486166020860152928516604085015293166060830152608082019290925260a081019190915260c00190565b6001600160a01b0396871681529486166020860152604085019390935293166060830152608082019290925290151560a082015260c00190565b6001600160a01b0394851681529290931660208301526040820152901515606082015260800190565b6001600160a01b03878116825286166020820152604081018590526060810184905261ffff8316608082015260c060a08201819052600090614a7390830184614725565b98975050505050505050565b6001600160a01b039290921682521515602082015260400190565b6001600160a01b0392909216825261ffff16602082015260400190565b901515815260200190565b6000851515825284602083015283604083015260806060830152614ae96080830184614725565b9695505050505050565b600060608252614b066060830186614725565b60208301949094525060400152919050565b6020810160068310614b2657fe5b91905290565b6020808252600490820152632a22181b60e11b604082015260600190565b6020808252600490820152635444314360e01b604082015260600190565b60208082526004908201526315110c4d60e21b604082015260600190565b6020808252600490820152635444323160e01b604082015260600190565b6020808252600490820152635444303360e01b604082015260600190565b6020808252600490820152635444333760e01b604082015260600190565b6020808252600490820152630544430360e41b604082015260600190565b6020808252600490820152630544434360e41b604082015260600190565b6020808252600490820152634f53313760e01b604082015260600190565b60208082526004908201526315110d4d60e21b604082015260600190565b60208082526004908201526315110c0d60e21b604082015260600190565b6020808252600490820152632a221a9960e11b604082015260600190565b60208082526004908201526327a99b9960e11b604082015260600190565b6020808252600490820152632a22181960e11b604082015260600190565b6020808252600490820152630a88860760e31b604082015260600190565b8481526001600160a01b03841660208201526080810160058410614d0e57fe5b836040830152821515606083015295945050505050565b9283526001600160a01b03919091166020830152604082015260600190565b8381526101408101614d596020830185614751565b82610120830152949350505050565b8381526101a08101614d8560208301614d8086614293565b614712565b614d9160208501614293565b614d9e6040840182614712565b506040840135606083015260608401356080830152608084013560a083015260a084013560c0830152614dd360c0850161429e565b614de060e084018261471f565b50614ded60e0850161429e565b610100614dfc8185018361471f565b614e07818701614293565b915050610120614e1981850183614712565b6101409150808601358285015250614e328186016142d8565b9050614e42610160840182614900565b5082610180830152949350505050565b828152610280810161275160208301846147e6565b8281526101408101614e7f60208301614d8085614293565b614e8b60208401614293565b614e986040840182614712565b506040830135606083015260608301356080830152608083013560a0830152614ec360a0840161429e565b614ed060c084018261471f565b50614edd60c08401614293565b614eea60e0840182614712565b5061010060e084013581840152614f028185016142d8565b9050613d52610120840182614900565b918252602082015260400190565b9485526001600160a01b0393841660208601526040850192909252606084015216608082015260a00190565b610260810161208e82846147e6565b61ffff91909116815260200190565b90815260200190565b60008382526040602083015261407a6040830184614725565b600085825284602083015260018060a01b038416604083015260806060830152614ae96080830184614725565b600084825283602083015260606040830152614fd86060830184614725565b95945050505050565b63ffffffff91909116815260200190565b60005b8381101561500d578181015183820152602001614ff5565b838111156126ab5750506000910152565b6001600160a01b038116811461415057600080fd5b801515811461415057600080fdfeec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6ba2646970667358221220e5130bef40aa458ce994409390489e3bef2cd61a29a5f9eb62a8550b8a4978c964736f6c63430007060033

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

000000000000000000000000c480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000003a1d749fa4a9e650fce844ff1c58c5faf7e2a9d1

-----Decoded View---------------
Arg [0] : _factory (address): 0xC480b33eE5229DE3FbDFAD1D2DCD3F3BAD0C56c6
Arg [1] : _weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : _bot (address): 0x3a1D749fa4a9E650FCe844fF1C58C5faf7e2a9D1

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000c480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 0000000000000000000000003a1d749fa4a9e650fce844ff1c58c5faf7e2a9d1


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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