ETH Price: $2,947.26 (-0.18%)

Contract

0x7a02481c3bBE5780e0B044D98854cE9e774dd281

Overview

ETH Balance

Linea Mainnet LogoLinea Mainnet LogoLinea Mainnet Logo0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

> 10 Internal Transactions found.

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
194042492025-05-27 10:43:23242 days ago1748342603
0x7a02481c...e774dd281
0 ETH
193998742025-05-27 7:52:56242 days ago1748332376
0x7a02481c...e774dd281
0 ETH
193998742025-05-27 7:52:56242 days ago1748332376
0x7a02481c...e774dd281
0 ETH
193998742025-05-27 7:52:56242 days ago1748332376
0x7a02481c...e774dd281
0 ETH
193998742025-05-27 7:52:56242 days ago1748332376
0x7a02481c...e774dd281
0 ETH
193998742025-05-27 7:52:56242 days ago1748332376
0x7a02481c...e774dd281
0 ETH
193998742025-05-27 7:52:56242 days ago1748332376
0x7a02481c...e774dd281
0 ETH
193998702025-05-27 7:52:48242 days ago1748332368
0x7a02481c...e774dd281
0 ETH
193998632025-05-27 7:52:29242 days ago1748332349
0x7a02481c...e774dd281
0 ETH
193998632025-05-27 7:52:29242 days ago1748332349
0x7a02481c...e774dd281
0 ETH
193998632025-05-27 7:52:29242 days ago1748332349
0x7a02481c...e774dd281
0 ETH
193998632025-05-27 7:52:29242 days ago1748332349
0x7a02481c...e774dd281
0 ETH
193998632025-05-27 7:52:29242 days ago1748332349
0x7a02481c...e774dd281
0 ETH
193998632025-05-27 7:52:29242 days ago1748332349
0x7a02481c...e774dd281
0 ETH
193998592025-05-27 7:52:21242 days ago1748332341
0x7a02481c...e774dd281
0 ETH
193929282025-05-27 2:52:12242 days ago1748314332
0x7a02481c...e774dd281
0 ETH
193929282025-05-27 2:52:12242 days ago1748314332
0x7a02481c...e774dd281
0 ETH
193929282025-05-27 2:52:12242 days ago1748314332
0x7a02481c...e774dd281
0 ETH
193929282025-05-27 2:52:12242 days ago1748314332
0x7a02481c...e774dd281
0 ETH
193929282025-05-27 2:52:12242 days ago1748314332
0x7a02481c...e774dd281
0 ETH
193929282025-05-27 2:52:12242 days ago1748314332
0x7a02481c...e774dd281
0 ETH
193929252025-05-27 2:52:06242 days ago1748314326
0x7a02481c...e774dd281
0.0001 ETH
193929182025-05-27 2:51:52242 days ago1748314312
0x7a02481c...e774dd281
0 ETH
193929182025-05-27 2:51:52242 days ago1748314312
0x7a02481c...e774dd281
0 ETH
193929182025-05-27 2:51:52242 days ago1748314312
0x7a02481c...e774dd281
0 ETH
View All Internal Transactions
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OrderManager

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../libraries/PrecisionUtils.sol";
import "../libraries/PositionKey.sol";
import "../libraries/Int256Utils.sol";
import "../libraries/Upgradeable.sol";
import "../libraries/TradingTypes.sol";

import "../helpers/ValidationHelper.sol";
import '../helpers/TradingHelper.sol';
import "../interfaces/IPriceFeed.sol";
import "../interfaces/IPool.sol";
import "../interfaces/IOrderManager.sol";
import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IRoleManager.sol";
import "../interfaces/IPositionManager.sol";
import "../interfaces/IOrderCallback.sol";

contract OrderManager is IOrderManager, Upgradeable {
    using SafeERC20 for IERC20;
    using PrecisionUtils for uint256;
    using Math for uint256;
    using SafeMath for uint256;
    using Int256Utils for int256;
    using Int256Utils for uint256;
    using Position for mapping(bytes32 => Position.Info);
    using Position for Position.Info;

    uint256 public override ordersIndex;

    mapping(uint256 => TradingTypes.IncreasePositionOrder) public increaseMarketOrders;
    mapping(uint256 => TradingTypes.DecreasePositionOrder) public decreaseMarketOrders;
    mapping(uint256 => TradingTypes.IncreasePositionOrder) public increaseLimitOrders;
    mapping(uint256 => TradingTypes.DecreasePositionOrder) public decreaseLimitOrders;
    mapping(uint256 => TradingTypes.OrderNetworkFee) public orderNetworkFees;

    // positionKey
    mapping(bytes32 => PositionOrder[]) public positionOrders;
    mapping(bytes32 => mapping(uint256 => uint256)) public positionOrderIndex;

    mapping(TradingTypes.NetworkFeePaymentType => mapping(uint256 => NetworkFee)) public networkFees;

    IPool public pool;
    IPositionManager public positionManager;
    address public router;

    mapping(uint256 => OrderTpSl) public ordersTpSl;

    mapping(uint256 => bool) public orderMakerOnly;

    mapping(address => bool) public isAllowedRouters;

    function initialize(
        IAddressesProvider addressProvider,
        IPool _pool,
        IPositionManager _positionManager
    ) public initializer {
        ADDRESS_PROVIDER = addressProvider;
        pool = _pool;
        positionManager = _positionManager;
    }

    modifier onlyRouter() {
        require(isAllowedRouters[msg.sender], "onlyRouter");
        _;
    }

    modifier onlyExecutor() {
        require(
            msg.sender == ADDRESS_PROVIDER.executionLogic() ||
                msg.sender == ADDRESS_PROVIDER.liquidationLogic(),
            "onlyExecutor"
        );
        _;
    }

    modifier onlyExecutorAndRouter() {
        require(
            msg.sender == ADDRESS_PROVIDER.executionLogic() ||
            msg.sender == ADDRESS_PROVIDER.liquidationLogic() ||
            isAllowedRouters[msg.sender],
            "onlyExecutor&Router"
        );
        _;
    }

    function setRouter(address _router) external onlyPoolAdmin {
        revert("deprecated");
    }

    function setAllowedRouters(address _router, bool _enable) external onlyPoolAdmin {
        isAllowedRouters[_router] = _enable;
        emit SetAllowedRouters(msg.sender, _router, _enable);
    }

    function updateNetworkFees(
        TradingTypes.NetworkFeePaymentType[] memory paymentTypes,
        uint256[] memory pairIndexes,
        NetworkFee[] memory fees
    ) external onlyPoolAdmin {
        require(paymentTypes.length == pairIndexes.length && pairIndexes.length == fees.length, "inconsistent params length");

        for (uint256 i = 0; i < fees.length; i++) {
            _updateNetworkFee(paymentTypes[i], pairIndexes[i], fees[i]);
        }
    }

    function _updateNetworkFee(
        TradingTypes.NetworkFeePaymentType paymentType,
        uint256 pairIndex,
        NetworkFee memory fee
    ) internal {
        networkFees[paymentType][pairIndex] = fee;
        emit UpdatedNetworkFee(msg.sender, paymentType, pairIndex, fee.basicNetworkFee, fee.discountThreshold, fee.discountedNetworkFee);
    }

    function getNetworkFee(TradingTypes.NetworkFeePaymentType paymentType, uint256 pairIndex) external view override returns (NetworkFee memory) {
        return networkFees[paymentType][pairIndex];
    }

    function createOrder(
        TradingTypes.CreateOrderRequest calldata request
    ) public payable onlyExecutorAndRouter returns (uint256 orderId) {
        address account = request.account;

        // account is frozen
        ValidationHelper.validateAccountBlacklist(ADDRESS_PROVIDER, account);

        // pair enabled
        IPool.Pair memory pair = pool.getPair(request.pairIndex);
        require(pair.enable, "disabled");

        // network fees
        int256 collateral = request.collateral;
        if (request.paymentType == TradingTypes.InnerPaymentType.ETH) {
            NetworkFee memory networkFee = networkFees[TradingTypes.NetworkFeePaymentType.ETH][request.pairIndex];
            if (networkFee.basicNetworkFee > 0) {
                if ((request.sizeAmount.abs() >= networkFee.discountThreshold && msg.value < networkFee.discountedNetworkFee)
                    || (request.sizeAmount.abs() < networkFee.discountThreshold && msg.value < networkFee.basicNetworkFee)) {
                    revert("insufficient network fee");
                }
                (bool success, ) = address(pool).call{value: msg.value}(new bytes(0));
                require(success, "transfer eth failed");
            }
        } else if (request.paymentType == TradingTypes.InnerPaymentType.COLLATERAL) {
            NetworkFee memory networkFee = networkFees[TradingTypes.NetworkFeePaymentType.COLLATERAL][request.pairIndex];
            if (networkFee.basicNetworkFee > 0) {
                if ((request.sizeAmount.abs() >= networkFee.discountThreshold && request.networkFeeAmount < networkFee.discountedNetworkFee)
                    || (request.sizeAmount.abs() < networkFee.discountThreshold && request.networkFeeAmount < networkFee.basicNetworkFee)) {
                    revert("insufficient network fee");
                }
                _transferOrderCollateral(
                    pair.stableToken,
                    request.networkFeeAmount,
                    address(pool),
                    request.data
                );
            }
        }

        if (
            request.tradeType == TradingTypes.TradeType.MARKET ||
            request.tradeType == TradingTypes.TradeType.LIMIT
        ) {
            IPool.TradingConfig memory tradingConfig = pool.getTradingConfig(request.pairIndex);
            if (request.sizeAmount >= 0) {
                require(
                    request.sizeAmount == 0 ||
                        (request.sizeAmount.abs() >= tradingConfig.minTradeAmount &&
                            request.sizeAmount.abs() <= tradingConfig.maxTradeAmount),
                    "invalid trade size"
                );
            }
        }

        // transfer collateral
        if (collateral > 0) {
            _transferOrderCollateral(
                pair.stableToken,
                collateral.abs(),
                address(pool),
                request.data
            );
        }

        if (request.sizeAmount > 0) {
            return
                _saveIncreaseOrder(
                    TradingTypes.IncreasePositionRequest({
                        account: account,
                        pairIndex: request.pairIndex,
                        tradeType: request.tradeType,
                        collateral: collateral,
                        openPrice: request.openPrice,
                        isLong: request.isLong,
                        makerOnly: request.makerOnly,
                        sizeAmount: request.sizeAmount.abs(),
                        maxSlippage: request.maxSlippage,
                        paymentType: TradingTypes.NetworkFeePaymentType.ETH,
                        networkFeeAmount: request.networkFeeAmount
                    }),
                    request.paymentType
                );
        } else if (request.sizeAmount < 0) {
            return
                _saveDecreaseOrder(
                    TradingTypes.DecreasePositionRequest({
                        account: account,
                        pairIndex: request.pairIndex,
                        tradeType: request.tradeType,
                        collateral: collateral,
                        triggerPrice: request.openPrice,
                        sizeAmount: request.sizeAmount.abs(),
                        isLong: request.isLong,
                        makerOnly: request.makerOnly,
                        maxSlippage: request.maxSlippage,
                        paymentType: TradingTypes.NetworkFeePaymentType.ETH,
                        networkFeeAmount: request.networkFeeAmount
                    }),
                    request.paymentType
                );
        } else {
            require(collateral != 0, "collateral required");
            return
                _saveIncreaseOrder(
                    TradingTypes.IncreasePositionRequest({
                        account: account,
                        pairIndex: request.pairIndex,
                        tradeType: request.tradeType,
                        collateral: collateral,
                        openPrice: request.openPrice,
                        isLong: request.isLong,
                        makerOnly: request.makerOnly,
                        sizeAmount: 0,
                        maxSlippage: request.maxSlippage,
                        paymentType: TradingTypes.NetworkFeePaymentType.ETH,
                        networkFeeAmount: request.networkFeeAmount
                    }),
                    request.paymentType
                );
        }
    }

    function cancelOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        bool isIncrease,
        string memory reason
    ) external onlyExecutorAndRouter {
        _cancelOrder(orderId, tradeType, isIncrease, reason);
    }

    function addOrderTpSl(AddOrderTpSlRequest calldata request) public payable onlyRouter {
        uint256 orderId = request.orderId;

        (TradingTypes.IncreasePositionOrder memory order,) = getIncreaseOrder(orderId, request.tradeType);
        address account = order.account;
        uint256 orderSize = order.sizeAmount;
        uint256 pairIndex = order.pairIndex;

        address sender = abi.decode(request.data, (address));
        require(sender == account, "not allowed");
        ValidationHelper.validateAccountBlacklist(ADDRESS_PROVIDER, account);

        require(orderSize >= request.tp && orderSize >= request.sl, "exceeds order size");

        // network fees
        uint256 count = 0;
        if (request.tp > 0) count += 1;
        if (request.sl > 0) count += 1;
        IPool.Pair memory pair = pool.getPair(pairIndex);
        if (request.paymentType == TradingTypes.InnerPaymentType.ETH) {
            NetworkFee memory networkFee = networkFees[TradingTypes.NetworkFeePaymentType.ETH][pairIndex];

            uint256 requiredDiscountedNetworkFee = networkFee.discountedNetworkFee * count;
            uint256 requiredBasicNetworkFee = networkFee.basicNetworkFee * count;
            if (networkFee.basicNetworkFee > 0) {
                if ((orderSize >= networkFee.discountThreshold && msg.value < requiredDiscountedNetworkFee)
                    || (orderSize < networkFee.discountThreshold && msg.value < requiredBasicNetworkFee)) {
                    revert("insufficient network fee");
                }
                (bool success, ) = address(pool).call{value: msg.value}(new bytes(0));
                require(success, "transfer eth failed");
            }
        } else if (request.paymentType == TradingTypes.InnerPaymentType.COLLATERAL) {
            NetworkFee memory networkFee = networkFees[TradingTypes.NetworkFeePaymentType.COLLATERAL][pairIndex];
            uint256 requiredDiscountedNetworkFee = networkFee.discountedNetworkFee * count;
            uint256 requiredBasicNetworkFee = networkFee.basicNetworkFee * count;
            if (networkFee.basicNetworkFee > 0) {
                if ((orderSize >= networkFee.discountThreshold && request.networkFeeAmount < requiredDiscountedNetworkFee)
                    || (orderSize < networkFee.discountThreshold && request.networkFeeAmount < requiredBasicNetworkFee)) {
                    revert("insufficient network fee");
                }
                _transferOrderCollateral(
                    pair.stableToken,
                    request.networkFeeAmount,
                    address(pool),
                    request.data
                );
            }
        }

        OrderTpSl memory orderTpSl = OrderTpSl({
            account: account,
            orderId: orderId,
            tpSize: request.tp,
            tpPrice: request.tpPrice,
            slSize: request.sl,
            slPrice: request.slPrice
        });
        ordersTpSl[orderId] = orderTpSl;

        emit SetOrderTpSl(account, orderId, pairIndex, request.tpPrice, request.slPrice, request.tp, request.sl);
    }

    function createOrderTpSl(uint256 orderId, TradingTypes.TradeType tradeType) external onlyExecutor {
        (TradingTypes.IncreasePositionOrder memory order, TradingTypes.OrderNetworkFee memory orderNetworkFee) = getIncreaseOrder(orderId, tradeType);

        OrderTpSl memory orderTpSl = ordersTpSl[order.orderId];
        if (orderTpSl.tpSize > 0) {
            _saveDecreaseOrder(
                TradingTypes.DecreasePositionRequest({
                    account: order.account,
                    pairIndex: order.pairIndex,
                    tradeType: TradingTypes.TradeType.TP,
                    collateral: 0,
                    triggerPrice: orderTpSl.tpPrice,
                    sizeAmount: orderTpSl.tpSize,
                    isLong: order.isLong,
                    makerOnly: false,
                    maxSlippage: 0,
                    paymentType: TradingTypes.NetworkFeePaymentType.ETH,
                    networkFeeAmount: orderNetworkFee.networkFeeAmount
                }),
                orderNetworkFee.paymentType
            );
        }
        if (orderTpSl.slSize > 0) {
            _saveDecreaseOrder(
                TradingTypes.DecreasePositionRequest({
                    account: order.account,
                    pairIndex: order.pairIndex,
                    tradeType: TradingTypes.TradeType.SL,
                    collateral: 0,
                    triggerPrice: orderTpSl.slPrice,
                    sizeAmount: orderTpSl.slSize,
                    isLong: order.isLong,
                    makerOnly: false,
                    maxSlippage: 0,
                    paymentType: TradingTypes.NetworkFeePaymentType.ETH,
                    networkFeeAmount: orderNetworkFee.networkFeeAmount
                }),
                orderNetworkFee.paymentType
            );
        }

        delete ordersTpSl[order.orderId];
    }

    function _cancelOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        bool isIncrease,
        string memory reason
    ) private {
        if (isIncrease) {
            (TradingTypes.IncreasePositionOrder memory order,) = getIncreaseOrder(orderId, tradeType);
            if (order.account == address(0)) {
                return;
            }
            _cancelIncreaseOrder(order);
            emit CancelOrderV2(orderId, order.account, order.pairIndex, tradeType, reason);
        } else {
            (TradingTypes.DecreasePositionOrder memory order,) = getDecreaseOrder(orderId, tradeType);
            if (order.account == address(0)) {
                return;
            }
            _cancelDecreaseOrder(order);
            emit CancelOrderV2(orderId, order.account, order.pairIndex, tradeType, reason);
        }
    }

    function cancelAllPositionOrders(
        address account,
        uint256 pairIndex,
        bool isLong
    ) external onlyExecutor {
        ValidationHelper.validateAccountBlacklist(ADDRESS_PROVIDER, account);

        bytes32 key = PositionKey.getPositionKey(account, pairIndex, isLong);

        uint256 total = positionOrders[key].length;
        uint256 count = total > 256 ? 256 : total;

        for (uint256 i = 1; i <= count; i++) {
            PositionOrder memory positionOrder = positionOrders[key][count - i];
            _cancelOrder(
                positionOrder.orderId,
                positionOrder.tradeType,
                positionOrder.isIncrease,
                "cancelAllPositionOrders"
            );
        }
    }

    function increaseOrderExecutedSize(
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        bool isIncrease,
        uint256 increaseSize
    ) external override onlyExecutor {
        if (isIncrease) {
            if (tradeType == TradingTypes.TradeType.MARKET) {
                increaseMarketOrders[orderId].executedSize += increaseSize;
            } else if (tradeType == TradingTypes.TradeType.LIMIT) {
                increaseLimitOrders[orderId].executedSize += increaseSize;
            }
        } else {
            if (tradeType == TradingTypes.TradeType.MARKET) {
                decreaseMarketOrders[orderId].executedSize += increaseSize;
            } else {
                decreaseLimitOrders[orderId].executedSize += increaseSize;
            }
        }
    }

    function removeOrderFromPosition(PositionOrder memory order) public onlyExecutor {
        _removeOrderFromPosition(order);
    }

    function removeIncreaseMarketOrders(uint256 orderId) external onlyExecutor {
        delete increaseMarketOrders[orderId];
        delete orderNetworkFees[orderId];
        delete orderMakerOnly[orderId];
    }

    function removeIncreaseLimitOrders(uint256 orderId) external onlyExecutor {
        delete increaseLimitOrders[orderId];
        delete orderNetworkFees[orderId];
        delete orderMakerOnly[orderId];
    }

    function removeDecreaseMarketOrders(uint256 orderId) external onlyExecutor {
        delete decreaseMarketOrders[orderId];
        delete orderNetworkFees[orderId];
        delete orderMakerOnly[orderId];
    }

    function removeDecreaseLimitOrders(uint256 orderId) external onlyExecutor {
        delete decreaseLimitOrders[orderId];
        delete orderNetworkFees[orderId];
        delete orderMakerOnly[orderId];
    }

    function setOrderNeedADL(
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        bool needADL
    ) external onlyExecutor {
        TradingTypes.DecreasePositionOrder storage order;
        if (tradeType == TradingTypes.TradeType.MARKET) {
            order = decreaseMarketOrders[orderId];
        } else {
            order = decreaseLimitOrders[orderId];
            require(order.tradeType == tradeType, "trade type not match");
        }
        order.needADL = needADL;
    }

    function _transferOrderCollateral(
        address collateral,
        uint256 collateralAmount,
        address to,
        bytes calldata data
    ) internal {
        uint256 balanceBefore = IERC20(collateral).balanceOf(to);

        if (collateralAmount > 0) {
            IOrderCallback(msg.sender).createOrderCallback(collateral, collateralAmount, to, data);
        }
        require(balanceBefore.add(collateralAmount) <= IERC20(collateral).balanceOf(to), "tc");
    }

    function _saveIncreaseOrder(
        TradingTypes.IncreasePositionRequest memory _request,
        TradingTypes.InnerPaymentType paymentType
    ) internal returns (uint256) {
        TradingTypes.IncreasePositionOrder memory order = TradingTypes.IncreasePositionOrder({
            orderId: ordersIndex,
            account: _request.account,
            pairIndex: _request.pairIndex,
            tradeType: _request.tradeType,
            collateral: _request.collateral,
            openPrice: _request.openPrice,
            isLong: _request.isLong,
            sizeAmount: _request.sizeAmount,
            executedSize: 0,
            maxSlippage: _request.maxSlippage,
            blockTime: block.timestamp
        });

        TradingTypes.OrderNetworkFee memory orderNetworkFee = TradingTypes.OrderNetworkFee({
            paymentType: paymentType,
            networkFeeAmount: _request.networkFeeAmount
        });
        orderNetworkFees[ordersIndex] = orderNetworkFee;

        if (_request.tradeType == TradingTypes.TradeType.MARKET) {
            increaseMarketOrders[ordersIndex] = order;
        } else if (_request.tradeType == TradingTypes.TradeType.LIMIT) {
            increaseLimitOrders[ordersIndex] = order;
        } else {
            revert("invalid trade type");
        }

        if (_request.makerOnly) {
            orderMakerOnly[ordersIndex] = _request.makerOnly;
        }
        ordersIndex++;

        _addOrderToPosition(
            PositionOrder(
                order.account,
                order.pairIndex,
                order.isLong,
                true,
                order.tradeType,
                order.orderId,
                order.sizeAmount
            )
        );

        emit CreateOrderV2(
            order.account,
            order.orderId,
            _request.tradeType,
            _request.collateral,
            _request.pairIndex,
            _request.openPrice,
            _request.sizeAmount,
            paymentType,
            _request.networkFeeAmount,
            TradingHelper.packOrderEventFlags(true, _request.isLong, _request.makerOnly, false)
        );
        return order.orderId;
    }

    function _saveDecreaseOrder(
        TradingTypes.DecreasePositionRequest memory _request,
        TradingTypes.InnerPaymentType paymentType
    ) internal returns (uint256) {
        TradingTypes.DecreasePositionOrder memory order = TradingTypes.DecreasePositionOrder({
            orderId: ordersIndex, // orderId
            account: _request.account,
            pairIndex: _request.pairIndex,
            tradeType: _request.tradeType,
            collateral: _request.collateral,
            triggerPrice: _request.triggerPrice,
            sizeAmount: _request.sizeAmount,
            executedSize: 0,
            maxSlippage: _request.maxSlippage,
            isLong: _request.isLong,
            abovePrice: false, // abovePrice
            blockTime: block.timestamp,
            needADL: false
        });

        TradingTypes.OrderNetworkFee memory orderNetworkFee = TradingTypes.OrderNetworkFee({
            paymentType: paymentType,
            networkFeeAmount: _request.networkFeeAmount
        });
        orderNetworkFees[ordersIndex] = orderNetworkFee;

        // abovePrice
        // market:long: true,  short: false
        //  limit:long: false, short: true
        //     tp:long: false, short: true
        //     sl:long: true,  short: false
        if (_request.tradeType == TradingTypes.TradeType.MARKET) {
            order.abovePrice = _request.isLong;

            decreaseMarketOrders[ordersIndex] = order;
        } else if (_request.tradeType == TradingTypes.TradeType.LIMIT) {
            order.abovePrice = !_request.isLong;

            decreaseLimitOrders[ordersIndex] = order;
        } else if (_request.tradeType == TradingTypes.TradeType.TP) {
            order.abovePrice = !_request.isLong;

            decreaseLimitOrders[ordersIndex] = order;
        } else if (_request.tradeType == TradingTypes.TradeType.SL) {
            order.abovePrice = _request.isLong;

            decreaseLimitOrders[ordersIndex] = order;
        } else {
            revert("invalid trade type");
        }

        if (_request.makerOnly) {
            orderMakerOnly[ordersIndex] = _request.makerOnly;
        }

        ordersIndex++;

        // add decrease order
        _addOrderToPosition(
            PositionOrder(
                order.account,
                order.pairIndex,
                order.isLong,
                false,
                order.tradeType,
                order.orderId,
                order.sizeAmount
            )
        );

        emit CreateOrderV2(
            order.account,
            order.orderId,
            _request.tradeType,
            _request.collateral,
            _request.pairIndex,
            _request.triggerPrice,
            _request.sizeAmount,
            paymentType,
            _request.networkFeeAmount,
            TradingHelper.packOrderEventFlags(false, _request.isLong, _request.makerOnly, order.abovePrice)
        );
        return order.orderId;
    }

    function _cancelIncreaseOrder(TradingTypes.IncreasePositionOrder memory order) internal {
        ValidationHelper.validateAccountBlacklist(ADDRESS_PROVIDER, order.account);

        _removeOrderAndRefundCollateral(
            order.account,
            order.pairIndex,
            order.executedSize == 0 ? order.collateral : int256(0),
            PositionOrder({
                account: order.account,
                pairIndex: order.pairIndex,
                isLong: order.isLong,
                isIncrease: true,
                tradeType: order.tradeType,
                orderId: order.orderId,
                sizeAmount: order.sizeAmount
            })
        );

        if (order.tradeType == TradingTypes.TradeType.MARKET) {
            delete increaseMarketOrders[order.orderId];
        } else if (order.tradeType == TradingTypes.TradeType.LIMIT) {
            delete increaseLimitOrders[order.orderId];
        }

        delete ordersTpSl[order.orderId];
        delete orderMakerOnly[order.orderId];

        emit CancelIncreaseOrder(order.account, order.orderId, order.tradeType);
    }

    function _cancelDecreaseOrder(TradingTypes.DecreasePositionOrder memory order) internal {
        ValidationHelper.validateAccountBlacklist(ADDRESS_PROVIDER, order.account);

        _removeOrderAndRefundCollateral(
            order.account,
            order.pairIndex,
            order.executedSize == 0 ? order.collateral : int256(0),
            PositionOrder({
                account: order.account,
                pairIndex: order.pairIndex,
                isLong: order.isLong,
                isIncrease: false,
                tradeType: order.tradeType,
                orderId: order.orderId,
                sizeAmount: order.sizeAmount
            })
        );

        if (order.tradeType == TradingTypes.TradeType.MARKET) {
            delete decreaseMarketOrders[order.orderId];
        } else if (order.tradeType == TradingTypes.TradeType.LIMIT) {
            delete decreaseLimitOrders[order.orderId];
        } else {
            delete decreaseLimitOrders[order.orderId];
        }

        delete ordersTpSl[order.orderId];
        delete orderMakerOnly[order.orderId];

        emit CancelDecreaseOrder(order.account, order.orderId, order.tradeType);
    }

    function _removeOrderAndRefundCollateral(
        address account,
        uint256 pairIndex,
        int256 collateral,
        PositionOrder memory positionOrder
    ) internal {
        _removeOrderFromPosition(positionOrder);

        if (collateral > 0) {
            IPool.Pair memory pair = pool.getPair(pairIndex);
            pool.transferTokenOrSwap(pairIndex, pair.stableToken, account, collateral.abs());
        }
    }

    function _addOrderToPosition(PositionOrder memory order) private {
        bytes32 positionKey = PositionKey.getPositionKey(
            order.account,
            order.pairIndex,
            order.isLong
        );
        positionOrderIndex[positionKey][order.orderId] = positionOrders[positionKey].length;
        positionOrders[positionKey].push(order);
    }

    function _removeOrderFromPosition(PositionOrder memory order) private {
        bytes32 positionKey = PositionKey.getPositionKey(
            order.account,
            order.pairIndex,
            order.isLong
        );

        uint256 index = positionOrderIndex[positionKey][order.orderId];
        uint256 lastIndex = positionOrders[positionKey].length - 1;

        if (index < lastIndex) {
            // swap last order
            PositionOrder memory lastOrder = positionOrders[positionKey][
                positionOrders[positionKey].length - 1
            ];

            positionOrders[positionKey][index] = lastOrder;
            positionOrderIndex[positionKey][lastOrder.orderId] = index;
        }
        delete positionOrderIndex[positionKey][order.orderId];
        positionOrders[positionKey].pop();
    }

    function getIncreaseOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType
    ) public view returns (
        TradingTypes.IncreasePositionOrder memory order,
        TradingTypes.OrderNetworkFee memory orderNetworkFee
    ) {
        if (tradeType == TradingTypes.TradeType.MARKET) {
            order = increaseMarketOrders[orderId];
        } else if (tradeType == TradingTypes.TradeType.LIMIT) {
            order = increaseLimitOrders[orderId];
        } else {
            revert("invalid trade type");
        }
        orderNetworkFee = orderNetworkFees[order.orderId];
    }

    function getDecreaseOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType
    ) public view returns (
        TradingTypes.DecreasePositionOrder memory order,
        TradingTypes.OrderNetworkFee memory orderNetworkFee
    ) {
        if (tradeType == TradingTypes.TradeType.MARKET) {
            order = decreaseMarketOrders[orderId];
        } else {
            order = decreaseLimitOrders[orderId];
        }
        orderNetworkFee = orderNetworkFees[order.orderId];
    }

    function getPositionOrders(bytes32 key) public view override returns (PositionOrder[] memory) {
        return positionOrders[key];
    }

    function getOrderTpSl(uint256 orderId) public view override returns (OrderTpSl memory) {
        return ordersTpSl[orderId];
    }
}

File 2 of 37 : draft-IERC1822Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822ProxiableUpgradeable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 3 of 37 : IERC1967Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 *
 * _Available since v4.8.3._
 */
interface IERC1967Upgradeable {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

File 4 of 37 : IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
        }
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

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

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeTo(address newImplementation) public virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlotUpgradeable {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // 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 (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

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

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

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../libraries/PrecisionUtils.sol";
import "../interfaces/IPool.sol";

library TokenHelper {
    using PrecisionUtils for uint256;
    using SafeMath for uint256;

    function convertIndexAmountToStable(
        IPool.Pair memory pair,
        int256 indexTokenAmount
    ) internal view returns (int256 amount) {
        if (indexTokenAmount == 0) return 0;

        uint8 stableTokenDec = IERC20Metadata(pair.stableToken).decimals();
        return convertTokenAmountTo(pair.indexToken, indexTokenAmount, stableTokenDec);
    }

    function convertIndexAmountToStableWithPrice(
        IPool.Pair memory pair,
        int256 indexTokenAmount,
        uint256 price
    ) internal view returns (int256 amount) {
        if (indexTokenAmount == 0) return 0;

        uint8 stableTokenDec = IERC20Metadata(pair.stableToken).decimals();
        return convertTokenAmountWithPrice(pair.indexToken, indexTokenAmount, stableTokenDec, price);
    }

    function convertTokenAmountWithPrice(
        address token,
        int256 tokenAmount,
        uint8 targetDecimals,
        uint256 price
    ) internal view returns (int256 amount) {
        if (tokenAmount == 0) return 0;

        uint256 tokenDec = uint256(IERC20Metadata(token).decimals());

        uint256 tokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - tokenDec);
        uint256 targetTokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - targetDecimals);

        amount = (tokenAmount * int256(tokenWad)) * int256(price) / int256(targetTokenWad) / int256(PrecisionUtils.PRICE_PRECISION);
    }

    function convertStableAmountToIndex(
        IPool.Pair memory pair,
        int256 stableTokenAmount
    ) internal view returns (int256 amount) {
        if (stableTokenAmount == 0) return 0;

        uint8 indexTokenDec = IERC20Metadata(pair.indexToken).decimals();
        return convertTokenAmountTo(pair.stableToken, stableTokenAmount, indexTokenDec);
    }

    function convertTokenAmountTo(
        address token,
        int256 tokenAmount,
        uint8 targetDecimals
    ) internal view returns (int256 amount) {
        if (tokenAmount == 0) return 0;

        uint256 tokenDec = uint256(IERC20Metadata(token).decimals());

        uint256 tokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - tokenDec);
        uint256 targetTokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - targetDecimals);
        amount = (tokenAmount * int256(tokenWad)) / int256(targetTokenWad);
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "../libraries/PrecisionUtils.sol";
import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IPriceFeed.sol";
import "../interfaces/IOraclePriceFeed.sol";
import "../interfaces/IPool.sol";
import "../interfaces/IBacktracker.sol";
import "../helpers/TokenHelper.sol";
import "../libraries/Int256Utils.sol";

library TradingHelper {
    using PrecisionUtils for uint256;
    using Int256Utils for int256;

    function getValidPrice(
        IAddressesProvider addressesProvider,
        address token,
        IPool.TradingConfig memory tradingConfig
    ) internal view returns (uint256) {
        bool backtracking = IBacktracker(addressesProvider.backtracker()).backtracking();
        if (backtracking) {
            uint64 backtrackRound = IBacktracker(addressesProvider.backtracker()).backtrackRound();
            return IOraclePriceFeed(addressesProvider.priceOracle()).getHistoricalPrice(backtrackRound, token);
        }
        uint256 oraclePrice = IPriceFeed(addressesProvider.priceOracle()).getPriceSafely(token);
        uint256 indexPrice = IPriceFeed(addressesProvider.indexPriceOracle()).getPrice(token);

        uint256 diffP = oraclePrice > indexPrice
            ? oraclePrice - indexPrice
            : indexPrice - oraclePrice;
        diffP = diffP.calculatePercentage(oraclePrice);

        require(diffP <= tradingConfig.maxPriceDeviationP, "exceed max price deviation");
        return oraclePrice;
    }

    function exposureAmountChecker(
        IPool.Vault memory lpVault,
        IPool.Pair memory pair,
        int256 exposedPositions,
        bool isLong,
        uint256 orderSize,
        uint256 executionPrice
    ) internal view returns (uint256 executionSize) {
        executionSize = orderSize;

        uint256 available = maxAvailableLiquidity(lpVault, pair, exposedPositions, isLong, executionPrice);
        if (executionSize > available) {
            executionSize = available;
        }
        return executionSize;
    }

    function maxAvailableLiquidity(
        IPool.Vault memory lpVault,
        IPool.Pair memory pair,
        int256 exposedPositions,
        bool isLong,
        uint256 executionPrice
    ) internal view returns (uint256 amount) {
        if (exposedPositions >= 0) {
            if (isLong) {
                amount = lpVault.indexTotalAmount >= lpVault.indexReservedAmount ?
                    lpVault.indexTotalAmount - lpVault.indexReservedAmount : 0;
            } else {
                int256 availableStable = int256(lpVault.stableTotalAmount) - int256(lpVault.stableReservedAmount);
                int256 stableToIndexAmount = TokenHelper.convertStableAmountToIndex(
                    pair,
                    availableStable
                );
                if (stableToIndexAmount < 0) {
                    if (uint256(exposedPositions) <= stableToIndexAmount.abs().divPrice(executionPrice)) {
                        amount = 0;
                    } else {
                        amount = uint256(exposedPositions) - stableToIndexAmount.abs().divPrice(executionPrice);
                    }
                } else {
                    amount = uint256(exposedPositions) + stableToIndexAmount.abs().divPrice(executionPrice);
                }
            }
        } else {
            if (isLong) {
                int256 availableIndex = int256(lpVault.indexTotalAmount) - int256(lpVault.indexReservedAmount);
                if (availableIndex > 0) {
                    amount = uint256(-exposedPositions) + availableIndex.abs();
                } else {
                    amount = uint256(-exposedPositions) >= availableIndex.abs() ?
                        uint256(-exposedPositions) - availableIndex.abs() : 0;
                }
            } else {
                int256 availableStable = int256(lpVault.stableTotalAmount) - int256(lpVault.stableReservedAmount);
                int256 stableToIndexAmount = TokenHelper.convertStableAmountToIndex(
                    pair,
                    availableStable
                );
                if (stableToIndexAmount < 0) {
                    amount = 0;
                } else {
                    amount = stableToIndexAmount.abs().divPrice(executionPrice);
                }
            }
        }
        return amount;
    }

    function packExecuteEventFlags(
        bool isIncrease,
        bool isLong,
        bool needADL,
        bool closed
    ) internal pure returns (uint256) {
        return boolToUint(isIncrease) | (boolToUint(isLong) << 1) | (boolToUint(needADL) << 2) | (boolToUint(closed) << 3);
    }

    function packOrderEventFlags(
        bool isIncrease,
        bool isLong,
        bool makerOnly,
        bool abovePrice
    ) internal pure returns (uint256) {
        return boolToUint(isIncrease) | (boolToUint(isLong) << 1) | (boolToUint(makerOnly) << 2) | (boolToUint(abovePrice) << 3);
    }

    function boolToUint(bool flag) private pure returns (uint256) {
        return flag ? 1 : 0;
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "../interfaces/IPool.sol";
import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IRoleManager.sol";
import "../libraries/PrecisionUtils.sol";
import "../libraries/TradingTypes.sol";

library ValidationHelper {
    using PrecisionUtils for uint256;

    function validateAccountBlacklist(
        IAddressesProvider addressesProvider,
        address account
    ) internal view {
        require(
            !IRoleManager(addressesProvider.roleManager()).isBlackList(account),
            "blacklist account"
        );
    }

    function validatePriceTriggered(
        IPool.TradingConfig memory tradingConfig,
        TradingTypes.TradeType tradeType,
        bool isIncrease,
        bool isLong,
        bool isAbove,
        uint256 currentPrice,
        uint256 orderPrice,
        uint256 maxSlippage
    ) internal pure {
        if (tradeType == TradingTypes.TradeType.MARKET) {
            bool valid;
            if ((isIncrease && isLong) || (!isIncrease && !isLong)) {
                valid = currentPrice <= orderPrice.mulPercentage(PrecisionUtils.percentage() + maxSlippage);
            } else {
                valid = currentPrice >= orderPrice.mulPercentage(PrecisionUtils.percentage() - maxSlippage);
            }
            require(maxSlippage == 0 || valid, "exceeds max slippage");
        } else if (tradeType == TradingTypes.TradeType.LIMIT) {
            require(
                isAbove
                    ? currentPrice.mulPercentage(
                        PrecisionUtils.percentage() - tradingConfig.priceSlipP
                    ) <= orderPrice
                    : currentPrice.mulPercentage(
                        PrecisionUtils.percentage() + tradingConfig.priceSlipP
                    ) >= orderPrice,
                "not reach trigger price"
            );
        } else {
            require(
                isAbove ? currentPrice <= orderPrice : currentPrice >= orderPrice,
                "not reach trigger price"
            );
        }
    }
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

interface IAddressesProvider {
    event AddressSet(bytes32 indexed id, address indexed oldAddress, address indexed newAddress);

    function WETH() external view returns (address);

    function timelock() external view returns (address);

    function priceOracle() external view returns (address);

    function indexPriceOracle() external view returns (address);

    function fundingRate() external view returns (address);

    function executionLogic() external view returns (address);

    function liquidationLogic() external view returns (address);

    function roleManager() external view returns (address);

    function backtracker() external view returns (address);
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IBacktracker {

    event Backtracking(address account, uint64 round);

    event UnBacktracking(address account);

    event UpdatedExecutorAddress(address sender, address oldAddress, address newAddress);

    function backtracking() external view returns (bool);

    function backtrackRound() external view returns (uint64);

    function enterBacktracking(uint64 _backtrackRound) external;

    function quitBacktracking() external;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./IPool.sol";
import "../libraries/TradingTypes.sol";
import "./IPositionManager.sol";

interface IFeeCollector {

    event UpdatedTradingFeeTier(
        address sender,
        uint8 tier,
        uint256 oldTakerFee,
        int256 oldMakerFee,
        uint256 newTakerFee,
        int256 newMakerFee
    );

    event UpdateMaxReferralsRatio(uint256 oldRatio, uint256 newRatio);

    event UpdatedStakingPoolAddress(address sender, address oldAddress, address newAddress);
    event UpdatePoolAddress(address sender, address oldAddress, address newAddress);
    event UpdatePledgeAddress(address sender, address oldAddress, address newAddress);

    event UpdatedPositionManagerAddress(address sender, address oldAddress, address newAddress);

    event UpdateExecutionLogicAddress(address sender, address oldAddress, address newAddress);

    event UpdateRouterAddress(address sender, address oldAddress, address newAddress);
    event SetAllowedRouters(address sender, address router, bool enable);

    event DistributeTradingFeeV2(
        address account,
        uint256 pairIndex,
        uint256 orderId,
        uint256 sizeDelta,
        uint256 regularTradingFee,
        bool isMaker,
        int256 feeRate,
        int256 vipTradingFee,
        uint256 returnAmount,
        uint256 referralsAmount,
        uint256 referralUserAmount,
        address referralOwner,
        int256 lpAmount,
        int256 keeperAmount,
        int256 stakingAmount,
        int256 reservedAmount,
        int256 ecoFundAmount,
        int256 treasuryAmount
    );

    event ClaimedStakingTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedDistributorTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedReservedTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedEcoFundTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedReferralsTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedUserTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedKeeperTradingFee(address account, address claimToken, uint256 amount);

    event ClaimedKeeperNetworkFee(address account, address claimToken, uint256 amount);

    struct TradingFeeTier {
        int256 makerFee;
        uint256 takerFee;
    }

    function maxReferralsRatio() external view returns (uint256 maxReferenceRatio);

    function stakingTradingFee() external view returns (uint256);
    function stakingTradingFeeDebt() external view returns (uint256);

    function treasuryFee() external view returns (uint256);

    function treasuryFeeDebt() external view returns (uint256);

    function reservedTradingFee() external view returns (int256);

    function ecoFundTradingFee() external view returns (int256);

    function userTradingFee(address _account) external view returns (uint256);

    function keeperTradingFee(address _account) external view returns (int256);

    function referralFee(address _referralOwner) external view returns (uint256);

    function getTradingFeeTier(uint256 pairIndex, uint8 tier) external view returns (TradingFeeTier memory);

    function getRegularTradingFeeTier(uint256 pairIndex) external view returns (TradingFeeTier memory);

    function getKeeperNetworkFee(
        address account,
        TradingTypes.InnerPaymentType paymentType
    ) external view returns (uint256);

    function updateMaxReferralsRatio(uint256 newRatio) external;

    function claimStakingTradingFee() external returns (uint256);

    function claimTreasuryFee() external returns (uint256);

    function claimReferralFee() external returns (uint256);

    function claimReferralFeeDelegate(address user) external returns (uint256);

    function claimUserTradingFee() external returns (uint256);

    function claimUserTradingFeeDelegate(address user) external returns (uint256);

    function claimKeeperTradingFee() external returns (uint256);

    function claimKeeperNetworkFee(
        TradingTypes.InnerPaymentType paymentType
    ) external returns (uint256);

    struct RescueKeeperNetworkFee {
        address keeper;
        address receiver;
    }

    function rescueKeeperNetworkFee(
        TradingTypes.InnerPaymentType paymentType,
        RescueKeeperNetworkFee[] calldata rescues
    ) external;

    function distributeTradingFee(
        IPool.Pair memory pair,
        address account,
        uint256 orderId,
        address keeper,
        uint256 size,
        uint256 sizeDelta,
        uint256 executionPrice,
        uint256 tradingFee,
        bool isMaker,
        TradingFeeTier memory tradingFeeTier,
        int256 exposureAmount,
        int256 afterExposureAmount,
        uint256 referralsRatio,
        uint256 referralUserRatio,
        address referralOwner
    ) external returns (int256 lpAmount, int256 vipTradingFee, uint256 givebackFeeAmount);

    function distributeNetworkFee(
        address keeper,
        TradingTypes.InnerPaymentType paymentType,
        uint256 networkFeeAmount
    ) external;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {IPriceFeed} from "./IPriceFeed.sol";

interface IOraclePriceFeed is IPriceFeed {

    function updateHistoricalPrice(
        address[] calldata tokens,
        bytes[] calldata updateData,
        uint64 backtrackRound
    ) external payable;

    function removeHistoricalPrice(
        uint64 backtrackRound,
        address[] calldata tokens
    ) external;

    function getHistoricalPrice(
        uint64 backtrackRound,
        address token
    ) external view returns (uint256);

}

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;

interface IOrderCallback {
    function createOrderCallback(address collateral, uint256 amount, address to, bytes calldata data) external;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import '../libraries/TradingTypes.sol';

interface IOrderManager {
    event UpdatePositionManager(address oldAddress, address newAddress);
    event CancelOrder(uint256 orderId, TradingTypes.TradeType tradeType, string reason);

    event CancelOrderV2(
        uint256 orderId,
        address account,
        uint256 pairIndex,
        TradingTypes.TradeType tradeType,
        string reason
    );

    event CreateOrderV2(
        address account,
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        int256 collateral,
        uint256 pairIndex,
        uint256 openPrice,
        uint256 sizeAmount,
        TradingTypes.InnerPaymentType paymentType,
        uint256 networkFeeAmount,
        uint256 flags //isIncrease, isLong, makerOnly, abovePrice
    );

    event UpdateRouterAddress(address sender, address oldAddress, address newAddress);
    event SetAllowedRouters(address sender, address router, bool enable);

    event CancelIncreaseOrder(address account, uint256 orderId, TradingTypes.TradeType tradeType);
    event CancelDecreaseOrder(address account, uint256 orderId, TradingTypes.TradeType tradeType);

    event UpdatedNetworkFee(
        address sender,
        TradingTypes.NetworkFeePaymentType paymentType,
        uint256 pairIndex,
        uint256 basicNetworkFee,
        uint256 discountThreshold,
        uint256 discountedNetworkFee
    );

    event SetOrderTpSl(
        address account,
        uint256 orderId,
        uint256 pairId,
        uint256 tpPrice,
        uint256 slPrice,
        uint128 tpSize,
        uint128 slSize
    );

    struct AddOrderTpSlRequest {
        uint256 orderId;
        TradingTypes.TradeType tradeType;
        uint256 tpPrice;
        uint128 tp;
        uint256 slPrice;
        uint128 sl;
        TradingTypes.InnerPaymentType paymentType;
        uint256 networkFeeAmount;
        bytes data;
    }

    struct PositionOrder {
        address account;
        uint256 pairIndex;
        bool isLong;
        bool isIncrease;
        TradingTypes.TradeType tradeType;
        uint256 orderId;
        uint256 sizeAmount;
    }

    struct OrderTpSl {
        address account;
        uint256 orderId;
        uint256 tpSize;
        uint256 tpPrice;
        uint256 slSize;
        uint256 slPrice;
    }

    struct NetworkFee {
        uint256 basicNetworkFee;
        uint256 discountThreshold;
        uint256 discountedNetworkFee;
    }

    function ordersIndex() external view returns (uint256);

    function getPositionOrders(bytes32 key) external view returns (PositionOrder[] memory);

    function getOrderTpSl(uint256 orderId) external view returns (OrderTpSl memory);

    function getNetworkFee(TradingTypes.NetworkFeePaymentType paymentType, uint256 pairIndex) external view returns (NetworkFee memory);

    function createOrder(TradingTypes.CreateOrderRequest memory request) external payable returns (uint256 orderId);

    function cancelOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        bool isIncrease,
        string memory reason
    ) external;

    function addOrderTpSl(AddOrderTpSlRequest calldata request) external payable;

    function createOrderTpSl(uint256 orderId, TradingTypes.TradeType tradeType) external;

    function cancelAllPositionOrders(address account, uint256 pairIndex, bool isLong) external;

    function orderMakerOnly(uint256 orderId) external view returns (bool);

    function getIncreaseOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType
    ) external view returns (
        TradingTypes.IncreasePositionOrder memory order,
        TradingTypes.OrderNetworkFee memory orderNetworkFee
    );

    function getDecreaseOrder(
        uint256 orderId,
        TradingTypes.TradeType tradeType
    ) external view returns (
        TradingTypes.DecreasePositionOrder memory order,
        TradingTypes.OrderNetworkFee memory orderNetworkFee
    );

    function increaseOrderExecutedSize(
        uint256 orderId,
        TradingTypes.TradeType tradeType,
        bool isIncrease,
        uint256 increaseSize
    ) external;

    function removeOrderFromPosition(PositionOrder memory order) external;

    function removeIncreaseMarketOrders(uint256 orderId) external;

    function removeIncreaseLimitOrders(uint256 orderId) external;

    function removeDecreaseMarketOrders(uint256 orderId) external;

    function removeDecreaseLimitOrders(uint256 orderId) external;

    function setOrderNeedADL(uint256 orderId, TradingTypes.TradeType tradeType, bool needADL) external;

}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IPool {
    // Events
    event PairAdded(
        address indexed indexToken,
        address indexed stableToken,
        address lpToken,
        uint256 index
    );

    event UpdateTotalAmount(
        uint256 indexed pairIndex,
        int256 indexAmount,
        int256 stableAmount,
        uint256 indexTotalAmount,
        uint256 stableTotalAmount
    );

    event UpdateReserveAmount(
        uint256 indexed pairIndex,
        int256 indexAmount,
        int256 stableAmount,
        uint256 indexReservedAmount,
        uint256 stableReservedAmount
    );

    event UpdateLPProfit(
        uint256 indexed pairIndex,
        address token,
        int256 profit,
        uint256 totalAmount
    );

    event GivebackTradingFee(
        uint256 indexed pairIndex,
        address token,
        uint256 amount
    );

    event UpdateAveragePrice(uint256 indexed pairIndex, uint256 averagePrice);

    event UpdateSpotSwap(address sender, address oldAddress, address newAddress);

    event UpdatePoolView(address sender, address oldAddress, address newAddress);

    event UpdateRouter(address sender, address oldAddress, address newAddress);
    event SetAllowedRouters(address sender, address router, bool enable);

    event UpdateRiskReserve(address sender, address oldAddress, address newAddress);

    event UpdateFeeCollector(address sender, address oldAddress, address newAddress);

    event UpdatePositionManager(address sender, address oldAddress, address newAddress);

    event UpdateOrderManager(address sender, address oldAddress, address newAddress);

    event AddStableToken(address sender, address token);

    event RemoveStableToken(address sender, address token);

    event AddLiquidity(
        address indexed recipient,
        uint256 indexed pairIndex,
        uint256 indexAmount,
        uint256 stableAmount,
        uint256 lpAmount,
        uint256 indexFeeAmount,
        uint256 stableFeeAmount,
        address slipToken,
        uint256 slipFeeAmount,
        uint256 lpPrice
    );

    event RemoveLiquidityV2(
        address indexed recipient,
        uint256 indexed pairIndex,
        uint256 indexAmount,
        uint256 stableAmount,
        uint256 lpAmount,
        uint256 feeAmount,
        uint256 lpPrice,
        uint256 feeIndexAmount,
        uint256 feeStableAmount
    );

    event ClaimedFee(address sender, address token, uint256 amount);

    struct Vault {
        uint256 indexTotalAmount; // total amount of tokens
        uint256 indexReservedAmount; // amount of tokens reserved for open positions
        uint256 stableTotalAmount;
        uint256 stableReservedAmount;
        uint256 averagePrice;
    }

    struct Pair {
        uint256 pairIndex;
        address indexToken;
        address stableToken;
        address pairToken;
        bool enable;
        uint256 kOfSwap; //Initial k value of liquidity
        uint256 expectIndexTokenP; //   for 100%
        uint256 maxUnbalancedP;
        uint256 unbalancedDiscountRate;
        uint256 addLpFeeP; // Add liquidity fee
        uint256 removeLpFeeP; // remove liquidity fee
    }

    struct TradingConfig {
        uint256 minLeverage;
        uint256 maxLeverage;
        uint256 minTradeAmount;
        uint256 maxTradeAmount;
        uint256 maxPositionAmount;
        uint256 maintainMarginRate; // Maintain the margin rate of  for 100%
        uint256 priceSlipP; // Price slip point
        uint256 maxPriceDeviationP; // Maximum offset of index price
    }

    struct TradingFeeConfig {
        uint256 lpFeeDistributeP;
        uint256 stakingFeeDistributeP;
        uint256 keeperFeeDistributeP;
        uint256 treasuryFeeDistributeP;
        uint256 reservedFeeDistributeP;
        uint256 ecoFundFeeDistributeP;
    }

    function pairsIndex() external view returns (uint256);

    function getPairIndex(address indexToken, address stableToken) external view returns (uint256);

    function getPair(uint256) external view returns (Pair memory);

    function getTradingConfig(uint256 _pairIndex) external view returns (TradingConfig memory);

    function getTradingFeeConfig(uint256) external view returns (TradingFeeConfig memory);

    function getVault(uint256 _pairIndex) external view returns (Vault memory vault);

    function transferTokenTo(address token, address to, uint256 amount) external;

    function transferEthTo(address to, uint256 amount) external;

    function transferTokenOrSwap(
        uint256 pairIndex,
        address token,
        address to,
        uint256 amount
    ) external;

    function getLpPnl(
        uint256 _pairIndex,
        bool lpIsLong,
        uint amount,
        uint256 _price
    ) external view returns (int256);

    function lpProfit(
        uint pairIndex,
        address token,
        uint256 price
    ) external view returns (int256);

    function increaseReserveAmount(
        uint256 _pairToken,
        uint256 _indexAmount,
        uint256 _stableAmount
    ) external;

    function decreaseReserveAmount(
        uint256 _pairToken,
        uint256 _indexAmount,
        uint256 _stableAmount
    ) external;

    function updateAveragePrice(uint256 _pairIndex, uint256 _averagePrice) external;

    function setLPStableProfit(uint256 _pairIndex, int256 _profit) external;

    function givebackTradingFee(
        uint256 pairIndex,
        uint256 amount
    ) external;

    function getAvailableLiquidity(uint256 pairIndex, uint256 price) external view returns(int256 v, int256 u, int256 e);

    function addLiquidity(
        address recipient,
        uint256 _pairIndex,
        uint256 _indexAmount,
        uint256 _stableAmount,
        bytes calldata data
    ) external returns (uint256 mintAmount, address slipToken, uint256 slipAmount);

    function removeLiquidity(
        address payable _receiver,
        uint256 _pairIndex,
        uint256 _amount,
        bool useETH,
        bytes calldata data
    )
        external
        returns (uint256 receivedIndexAmount, uint256 receivedStableAmount, uint256 feeAmount);

    function claimFee(address token, uint256 amount) external;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import '../libraries/Position.sol';
import "./IFeeCollector.sol";

enum PositionStatus {
    Balance,
    NetLong,
    NetShort
}

interface IPositionManager {
    event UpdateFundingInterval(uint256 oldInterval, uint256 newInterval);

    event UpdatePosition(
        address account,
        bytes32 positionKey,
        uint256 pairIndex,
        uint256 orderId,
        bool isLong,
        uint256 beforCollateral,
        uint256 afterCollateral,
        uint256 price,
        uint256 beforPositionAmount,
        uint256 afterPositionAmount,
        uint256 averagePrice,
        int256 fundFeeTracker,
        int256 pnl
    );

    event UpdatedExecutionLogic(address sender, address oldAddress, address newAddress);

    event UpdatedLiquidationLogic(address sender, address oldAddress, address newAddress);

    event UpdateRouterAddress(address sender, address oldAddress, address newAddress);
    event SetAllowedRouters(address sender, address router, bool enable);

    event UpdateFundingRate(uint256 pairIndex, uint price, int256 fundingRate, uint256 lastFundingTime);

    event UpdatePositionRiskAnalyzer(address sender, address oldAddress, address newAddress);

    event UpdateFundingRateV2(
        uint256 pairIndex,
        uint price,
        int256 fundingRate,
        uint256 lastFundingTime,
        int256 globalFundingFeeTracker,
        int256 lpFundingFee
    );

    event TakeFundingFeeAddTraderFeeV2(
        address account,
        uint256 pairIndex,
        uint256 orderId,
        uint256 sizeDelta,
        int256 fundingFee,
        uint256 regularTradingFee,
        int256 vipTradingFee,
        uint256 returnAmount,
        int256 lpTradingFee
    );

    event AdjustCollateral(
        address account,
        uint256 pairIndex,
        bool isLong,
        bytes32 positionKey,
        uint256 collateralBefore,
        uint256 collateralAfter
    );

    function getExposedPositions(uint256 pairIndex) external view returns (int256);

    function longTracker(uint256 pairIndex) external view returns (uint256);

    function shortTracker(uint256 pairIndex) external view returns (uint256);

    function getTradingFee(
        uint256 _pairIndex,
        bool _isLong,
        bool _isIncrease,
        uint256 _sizeAmount,
        uint256 price
    ) external view returns (uint256 tradingFee);

    function getFundingFee(
        address _account,
        uint256 _pairIndex,
        bool _isLong
    ) external view returns (int256 fundingFee);

    function getCurrentFundingRate(uint256 _pairIndex) external view returns (int256);

    function getNextFundingRate(uint256 _pairIndex, uint256 price) external view returns (int256);

    function getNextFundingRateUpdateTime(uint256 _pairIndex) external view returns (uint256);

    function needADL(
        uint256 pairIndex,
        bool isLong,
        uint256 executionSize,
        uint256 executionPrice
    ) external view returns (bool needADL, uint256 needADLAmount);

    function needLiquidation(
        bytes32 positionKey,
        uint256 price
    ) external view returns (bool);

    function exposureAmountChecker(
        uint256 pairIndex,
        bool isLong,
        uint256 orderSize,
        uint256 executionPrice
    ) external view returns (uint256 executionSize);

    function maxAvailableLiquidity(
        IPool.Vault memory lpVault,
        IPool.Pair memory pair,
        int256 exposedPositions,
        bool isLong,
        uint256 executionPrice
    ) external view returns (uint256 amount);

    function getPosition(
        address _account,
        uint256 _pairIndex,
        bool _isLong
    ) external view returns (Position.Info memory);

    function getPositionByKey(bytes32 key) external view returns (Position.Info memory);

    function getPositionUpdateAtByKey(bytes32 key) external view returns (uint64);

    function getPositionKey(address _account, uint256 _pairIndex, bool _isLong) external pure returns (bytes32);

    function increasePosition(
        uint256 _pairIndex,
        uint256 orderId,
        address _account,
        address _keeper,
        uint256 _sizeAmount,
        bool _isLong,
        int256 _collateral,
        IFeeCollector.TradingFeeTier memory tradingFeeTier,
        uint256 referralsRatio,
        uint256 referralUserRatio,
        address referralOwner,
        uint256 _price
    ) external returns (uint256 tradingFee, int256 fundingFee);

    function decreasePosition(
        uint256 _pairIndex,
        uint256 orderId,
        address _account,
        address _keeper,
        uint256 _sizeAmount,
        bool _isLong,
        int256 _collateral,
        IFeeCollector.TradingFeeTier memory tradingFeeTier,
        uint256 referralsRatio,
        uint256 referralUserRatio,
        address referralOwner,
        uint256 _price,
        bool useRiskReserve
    ) external returns (uint256 tradingFee, int256 fundingFee, int256 pnl);

    function adjustCollateral(uint256 pairIndex, address account, bool isLong, int256 collateral) external;

    function updateFundingRate(uint256 _pairIndex) external;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IPriceFeed {

    event PriceAgeUpdated(uint256 oldAge, uint256 newAge);

    function getPrice(address token) external view returns (uint256);

    function getPriceSafely(address token) external view returns (uint256);

    function decimals() external pure returns (uint256);

}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

interface IRoleManager {
    function setRoleAdmin(bytes32 role, bytes32 adminRole) external;

    function isAdmin(address) external view returns (bool);

    function isPoolAdmin(address poolAdmin) external view returns (bool);

    function isOperator(address operator) external view returns (bool);

    function isTreasurer(address treasurer) external view returns (bool);

    function isKeeper(address) external view returns (bool);

    function isBlackList(address account) external view returns (bool);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import '@openzeppelin/contracts/utils/math/Math.sol';
import '@openzeppelin/contracts/utils/Strings.sol';

library Int256Utils {
    using Strings for uint256;

    function abs(int256 a) internal pure returns (uint256) {
        return a >= 0 ? uint256(a) : uint256(-a);
    }

    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    function safeConvertToInt256(uint256 value) internal pure returns (int256) {
        require(value <= uint256(type(int256).max), "Value too large to fit in int256.");
        return int256(value);
    }

    function toString(int256 amount) internal pure returns (string memory) {
        return string.concat(amount >= 0 ? '' : '-', abs(amount).toString());
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import '@openzeppelin/contracts/utils/math/Math.sol';
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import '../libraries/PrecisionUtils.sol';
import '../libraries/Int256Utils.sol';
import '../libraries/TradingTypes.sol';
import '../libraries/PositionKey.sol';
import "../interfaces/IPool.sol";
import "../helpers/TokenHelper.sol";

library Position {
    using Int256Utils for int256;
    using Math for uint256;
    using PrecisionUtils for uint256;

    struct Info {
        address account;
        uint256 pairIndex;
        bool isLong;
        uint256 collateral;
        uint256 positionAmount;
        uint256 averagePrice;
        int256 fundingFeeTracker;
    }

    function get(
        mapping(bytes32 => Info) storage self,
        address _account,
        uint256 _pairIndex,
        bool _isLong
    ) internal view returns (Position.Info storage position) {
        position = self[PositionKey.getPositionKey(_account, _pairIndex, _isLong)];
    }

    function getPositionByKey(
        mapping(bytes32 => Info) storage self,
        bytes32 key
    ) internal view returns (Position.Info storage position) {
        position = self[key];
    }

    function init(Info storage self, uint256 pairIndex, address account, bool isLong, uint256 oraclePrice) internal {
        self.pairIndex = pairIndex;
        self.account = account;
        self.isLong = isLong;
        self.averagePrice = oraclePrice;
    }

    function getUnrealizedPnl(
        Info memory self,
        IPool.Pair memory pair,
        uint256 _sizeAmount,
        uint256 price
    ) internal view returns (int256 pnl) {
        if (price == self.averagePrice || self.averagePrice == 0 || _sizeAmount == 0) {
            return 0;
        }

        if (self.isLong) {
            if (price > self.averagePrice) {
                pnl = TokenHelper.convertIndexAmountToStableWithPrice(
                    pair,
                    int256(_sizeAmount),
                    price - self.averagePrice
                );
            } else {
                pnl = TokenHelper.convertIndexAmountToStableWithPrice(
                    pair,
                    -int256(_sizeAmount),
                    self.averagePrice - price
                );
            }
        } else {
            if (self.averagePrice > price) {
                pnl = TokenHelper.convertIndexAmountToStableWithPrice(
                    pair,
                    int256(_sizeAmount),
                    self.averagePrice - price
                );
            } else {
                pnl = TokenHelper.convertIndexAmountToStableWithPrice(
                    pair,
                    -int256(_sizeAmount),
                    price - self.averagePrice
                );
            }
        }

        return pnl;
    }

    function validLeverage(
        Info memory self,
        IPool.Pair memory pair,
        uint256 price,
        int256 _collateral,
        uint256 _sizeAmount,
        bool _increase,
        uint256 maxLeverage,
        uint256 maxPositionAmount,
        bool simpleVerify,
        int256 fundingFee
    ) internal view returns (uint256, uint256) {
        // only increase collateral
        if (_sizeAmount == 0 && _collateral >= 0) {
            return (self.positionAmount, self.collateral);
        }

        uint256 afterPosition;
        if (_increase) {
            afterPosition = self.positionAmount + _sizeAmount;
        } else {
            afterPosition = self.positionAmount >= _sizeAmount ? self.positionAmount - _sizeAmount : 0;
        }

        if (_increase && afterPosition > maxPositionAmount) {
            revert("exceeds max position");
        }

        int256 availableCollateral = int256(self.collateral) + fundingFee;

        // pnl
        if (!simpleVerify) {
            int256 pnl = getUnrealizedPnl(self, pair, self.positionAmount, price);
            if (!_increase && _sizeAmount > 0 && _sizeAmount < self.positionAmount) {
                if (pnl >= 0) {
//                    availableCollateral += getUnrealizedPnl(self, pair, self.positionAmount - _sizeAmount, price);
                    availableCollateral += getUnrealizedPnl(self, pair, _sizeAmount, price);
                } else {
//                    availableCollateral += getUnrealizedPnl(self, pair, _sizeAmount, price);
                    availableCollateral += pnl;
                }
            } else {
                availableCollateral += pnl;
            }
        }

        // adjust collateral
        if (_collateral != 0) {
            availableCollateral += _collateral;
        }
        require(simpleVerify || availableCollateral >= 0, 'collateral not enough');

        if (!simpleVerify && ((_increase && _sizeAmount > 0) || _collateral < 0)) {
            uint256 collateralDec = uint256(IERC20Metadata(pair.stableToken).decimals());
            uint256 tokenDec = uint256(IERC20Metadata(pair.indexToken).decimals());

            uint256 tokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - tokenDec);
            uint256 collateralWad = 10 ** (PrecisionUtils.maxTokenDecimals() - collateralDec);

            uint256 afterPositionD = afterPosition * tokenWad;
            uint256 availableD = (availableCollateral.abs() * maxLeverage * collateralWad).divPrice(price);
            require(afterPositionD <= availableD, 'exceeds max leverage');
        }

        return (afterPosition, availableCollateral.abs());
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library PositionKey {
    function getPositionKey(address account, uint256 pairIndex, bool isLong) internal pure returns (bytes32) {
        require(pairIndex < 2 ** (96 - 32), "ptl");
        return bytes32(
            uint256(uint160(account)) << 96 | pairIndex << 32 | (isLong ? 1 : 0)
        );
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import '@openzeppelin/contracts/utils/math/Math.sol';

library PrecisionUtils {
    uint256 public constant PERCENTAGE = 1e8;
    uint256 public constant PRICE_PRECISION = 1e30;
    uint256 public constant MAX_TOKEN_DECIMALS = 18;

    function mulPrice(uint256 amount, uint256 price) internal pure returns (uint256) {
        return Math.mulDiv(amount, price, PRICE_PRECISION);
    }

    function divPrice(uint256 delta, uint256 price) internal pure returns (uint256) {
        return Math.mulDiv(delta, PRICE_PRECISION, price);
    }

    function calculatePrice(uint256 delta, uint256 amount) internal pure returns (uint256) {
        return Math.mulDiv(delta, PRICE_PRECISION, amount);
    }

    function mulPercentage(uint256 amount, uint256 _percentage) internal pure returns (uint256) {
        return Math.mulDiv(amount, _percentage, PERCENTAGE);
    }

    function divPercentage(uint256 amount, uint256 _percentage) internal pure returns (uint256) {
        return Math.mulDiv(amount, PERCENTAGE, _percentage);
    }

    function calculatePercentage(uint256 amount0, uint256 amount1) internal pure returns (uint256) {
        return Math.mulDiv(amount0, PERCENTAGE, amount1);
    }

    function percentage() internal pure returns (uint256) {
        return PERCENTAGE;
    }

    function fundingRatePrecision() internal pure returns (uint256) {
        return PERCENTAGE;
    }

    function pricePrecision() internal pure returns (uint256) {
        return PRICE_PRECISION;
    }

    function maxTokenDecimals() internal pure returns (uint256) {
        return MAX_TOKEN_DECIMALS;
    }
}

File 36 of 37 : TradingTypes.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library TradingTypes {
    enum TradeType {
        MARKET,
        LIMIT,
        TP,
        SL
    }

    enum NetworkFeePaymentType {
        ETH,
        COLLATERAL
    }

    struct CreateOrderRequest {
        address account;
        uint256 pairIndex; // pair index
        TradeType tradeType; // 0: MARKET, 1: LIMIT 2: TP 3: SL
        int256 collateral; // 1e18 collateral amount,negative number is withdrawal
        uint256 openPrice; // 1e30, price
        bool isLong; // long or short
        bool makerOnly;
        int256 sizeAmount; // size
        uint256 maxSlippage;
        InnerPaymentType paymentType;
        uint256 networkFeeAmount;
        bytes data;
    }

    struct OrderWithTpSl {
        uint256 tpPrice; // 1e30, tp price
        uint128 tp; // tp size
        uint256 slPrice; // 1e30, sl price
        uint128 sl; // sl size
    }

    struct IncreasePositionRequest {
        address account;
        uint256 pairIndex; // pair index
        TradeType tradeType; // 0: MARKET, 1: LIMIT 2: TP 3: SL
        int256 collateral; // 1e18 collateral amount,negative number is withdrawal
        uint256 openPrice; // 1e30, price
        bool isLong; // long or short
        bool makerOnly;
        uint256 sizeAmount; // size
        uint256 maxSlippage;
        NetworkFeePaymentType paymentType;
        uint256 networkFeeAmount;
    }

    struct IncreasePositionWithTpSlRequest {
        address account;
        uint256 pairIndex; // pair index
        TradeType tradeType; // 0: MARKET, 1: LIMIT 2: TP 3: SL
        int256 collateral; // 1e18 collateral amount,negative number is withdrawal
        uint256 openPrice; // 1e30, price
        bool isLong; // long or short
        bool makerOnly;
        uint128 sizeAmount; // size
        uint256 tpPrice; // 1e30, tp price
        uint128 tp; // tp size
        uint256 slPrice; // 1e30, sl price
        uint128 sl; // sl size
        uint256 maxSlippage;
        NetworkFeePaymentType paymentType; // 1: eth 2: collateral
        uint256 networkFeeAmount;
        uint256 tpNetworkFeeAmount;
        uint256 slNetworkFeeAmount;
    }

    struct DecreasePositionRequest {
        address account;
        uint256 pairIndex;
        TradeType tradeType;
        int256 collateral; // 1e18 collateral amount,negative number is withdrawal
        uint256 triggerPrice; // 1e30, price
        uint256 sizeAmount; // size
        bool isLong;
        bool makerOnly;
        uint256 maxSlippage;
        NetworkFeePaymentType paymentType;
        uint256 networkFeeAmount;
    }

    struct CreateTpSlRequest {
        address account;
        uint256 pairIndex; // pair index
        bool isLong;
        uint256 tpPrice; // Stop profit price 1e30
        uint128 tp; // The number of profit stops
        uint256 slPrice; // Stop price 1e30
        uint128 sl; // Stop loss quantity
        NetworkFeePaymentType paymentType;
        uint256 tpNetworkFeeAmount;
        uint256 slNetworkFeeAmount;
    }

    struct IncreasePositionOrder {
        uint256 orderId;
        address account;
        uint256 pairIndex; // pair index
        TradeType tradeType; // 0: MARKET, 1: LIMIT
        int256 collateral; // 1e18 Margin amount
        uint256 openPrice; // 1e30 Market acceptable price/Limit opening price
        bool isLong; // Long/short
        uint256 sizeAmount; // Number of positions
        uint256 executedSize;
        uint256 maxSlippage;
        uint256 blockTime;
    }

    struct DecreasePositionOrder {
        uint256 orderId;
        address account;
        uint256 pairIndex;
        TradeType tradeType;
        int256 collateral; // 1e18 Margin amount
        uint256 triggerPrice; // Limit trigger price
        uint256 sizeAmount; // Number of customs documents
        uint256 executedSize;
        uint256 maxSlippage;
        bool isLong;
        bool abovePrice; // Above or below the trigger price
        // market:long: true,  short: false
        //  limit:long: false, short: true
        //     tp:long: false, short: true
        //     sl:long: true,  short: false
        uint256 blockTime;
        bool needADL;
    }

    struct OrderNetworkFee {
        InnerPaymentType paymentType;
        uint256 networkFeeAmount;
    }

    enum InnerPaymentType {
        NONE,
        ETH,
        COLLATERAL
    }

    function convertPaymentType(
        NetworkFeePaymentType paymentType
    ) internal pure returns (InnerPaymentType) {
        if (paymentType == NetworkFeePaymentType.ETH) {
            return InnerPaymentType.ETH;
        } else if (paymentType == NetworkFeePaymentType.COLLATERAL) {
            return InnerPaymentType.COLLATERAL;
        } else {
            revert("Invalid payment type");
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IRoleManager.sol";

contract Upgradeable is Initializable, UUPSUpgradeable {
    IAddressesProvider public ADDRESS_PROVIDER;

    modifier onlyAdmin() {
        require(IRoleManager(ADDRESS_PROVIDER.roleManager()).isAdmin(msg.sender), "onlyAdmin");
        _;
    }

    modifier onlyPoolAdmin() {
        require(
            IRoleManager(ADDRESS_PROVIDER.roleManager()).isPoolAdmin(msg.sender),
            "onlyPoolAdmin"
        );
        _;
    }

    function _authorizeUpgrade(address) internal virtual override {
        require(msg.sender == ADDRESS_PROVIDER.timelock(), "Unauthorized access");
    }
}

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

Contract Security Audit

Contract ABI

API
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"}],"name":"CancelDecreaseOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"}],"name":"CancelIncreaseOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"CancelOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"pairIndex","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"CancelOrderV2","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"indexed":false,"internalType":"int256","name":"collateral","type":"int256"},{"indexed":false,"internalType":"uint256","name":"pairIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"openPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"networkFeeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"flags","type":"uint256"}],"name":"CreateOrderV2","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"router","type":"address"},{"indexed":false,"internalType":"bool","name":"enable","type":"bool"}],"name":"SetAllowedRouters","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pairId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tpPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"slPrice","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"tpSize","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"slSize","type":"uint128"}],"name":"SetOrderTpSl","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newAddress","type":"address"}],"name":"UpdatePositionManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newAddress","type":"address"}],"name":"UpdateRouterAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"enum TradingTypes.NetworkFeePaymentType","name":"paymentType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"pairIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"basicNetworkFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"discountThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"discountedNetworkFee","type":"uint256"}],"name":"UpdatedNetworkFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"ADDRESS_PROVIDER","outputs":[{"internalType":"contract IAddressesProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"uint256","name":"tpPrice","type":"uint256"},{"internalType":"uint128","name":"tp","type":"uint128"},{"internalType":"uint256","name":"slPrice","type":"uint256"},{"internalType":"uint128","name":"sl","type":"uint128"},{"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"internalType":"uint256","name":"networkFeeAmount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct IOrderManager.AddOrderTpSlRequest","name":"request","type":"tuple"}],"name":"addOrderTpSl","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"}],"name":"cancelAllPositionOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"string","name":"reason","type":"string"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"openPrice","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"makerOnly","type":"bool"},{"internalType":"int256","name":"sizeAmount","type":"int256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"internalType":"uint256","name":"networkFeeAmount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct TradingTypes.CreateOrderRequest","name":"request","type":"tuple"}],"name":"createOrder","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"}],"name":"createOrderTpSl","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"decreaseLimitOrders","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"triggerPrice","type":"uint256"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint256","name":"executedSize","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"abovePrice","type":"bool"},{"internalType":"uint256","name":"blockTime","type":"uint256"},{"internalType":"bool","name":"needADL","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"decreaseMarketOrders","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"triggerPrice","type":"uint256"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint256","name":"executedSize","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"abovePrice","type":"bool"},{"internalType":"uint256","name":"blockTime","type":"uint256"},{"internalType":"bool","name":"needADL","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"}],"name":"getDecreaseOrder","outputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"triggerPrice","type":"uint256"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint256","name":"executedSize","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"abovePrice","type":"bool"},{"internalType":"uint256","name":"blockTime","type":"uint256"},{"internalType":"bool","name":"needADL","type":"bool"}],"internalType":"struct TradingTypes.DecreasePositionOrder","name":"order","type":"tuple"},{"components":[{"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"internalType":"uint256","name":"networkFeeAmount","type":"uint256"}],"internalType":"struct TradingTypes.OrderNetworkFee","name":"orderNetworkFee","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"}],"name":"getIncreaseOrder","outputs":[{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"openPrice","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint256","name":"executedSize","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"uint256","name":"blockTime","type":"uint256"}],"internalType":"struct TradingTypes.IncreasePositionOrder","name":"order","type":"tuple"},{"components":[{"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"internalType":"uint256","name":"networkFeeAmount","type":"uint256"}],"internalType":"struct TradingTypes.OrderNetworkFee","name":"orderNetworkFee","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum TradingTypes.NetworkFeePaymentType","name":"paymentType","type":"uint8"},{"internalType":"uint256","name":"pairIndex","type":"uint256"}],"name":"getNetworkFee","outputs":[{"components":[{"internalType":"uint256","name":"basicNetworkFee","type":"uint256"},{"internalType":"uint256","name":"discountThreshold","type":"uint256"},{"internalType":"uint256","name":"discountedNetworkFee","type":"uint256"}],"internalType":"struct IOrderManager.NetworkFee","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"getOrderTpSl","outputs":[{"components":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"tpSize","type":"uint256"},{"internalType":"uint256","name":"tpPrice","type":"uint256"},{"internalType":"uint256","name":"slSize","type":"uint256"},{"internalType":"uint256","name":"slPrice","type":"uint256"}],"internalType":"struct IOrderManager.OrderTpSl","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getPositionOrders","outputs":[{"components":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"}],"internalType":"struct IOrderManager.PositionOrder[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"increaseLimitOrders","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"openPrice","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint256","name":"executedSize","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"uint256","name":"blockTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"increaseMarketOrders","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"collateral","type":"int256"},{"internalType":"uint256","name":"openPrice","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint256","name":"executedSize","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"uint256","name":"blockTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint256","name":"increaseSize","type":"uint256"}],"name":"increaseOrderExecutedSize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAddressesProvider","name":"addressProvider","type":"address"},{"internalType":"contract IPool","name":"_pool","type":"address"},{"internalType":"contract IPositionManager","name":"_positionManager","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAllowedRouters","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum TradingTypes.NetworkFeePaymentType","name":"","type":"uint8"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"networkFees","outputs":[{"internalType":"uint256","name":"basicNetworkFee","type":"uint256"},{"internalType":"uint256","name":"discountThreshold","type":"uint256"},{"internalType":"uint256","name":"discountedNetworkFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"orderMakerOnly","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"orderNetworkFees","outputs":[{"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"internalType":"uint256","name":"networkFeeAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ordersIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"ordersTpSl","outputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"tpSize","type":"uint256"},{"internalType":"uint256","name":"tpPrice","type":"uint256"},{"internalType":"uint256","name":"slSize","type":"uint256"},{"internalType":"uint256","name":"slPrice","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"contract IPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract IPositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"positionOrderIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"positionOrders","outputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"removeDecreaseLimitOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"removeDecreaseMarketOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"removeIncreaseLimitOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"removeIncreaseMarketOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"}],"internalType":"struct IOrderManager.PositionOrder","name":"order","type":"tuple"}],"name":"removeOrderFromPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_router","type":"address"},{"internalType":"bool","name":"_enable","type":"bool"}],"name":"setAllowedRouters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"needADL","type":"bool"}],"name":"setOrderNeedADL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_router","type":"address"}],"name":"setRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum TradingTypes.NetworkFeePaymentType[]","name":"paymentTypes","type":"uint8[]"},{"internalType":"uint256[]","name":"pairIndexes","type":"uint256[]"},{"components":[{"internalType":"uint256","name":"basicNetworkFee","type":"uint256"},{"internalType":"uint256","name":"discountThreshold","type":"uint256"},{"internalType":"uint256","name":"discountedNetworkFee","type":"uint256"}],"internalType":"struct IOrderManager.NetworkFee[]","name":"fees","type":"tuple[]"}],"name":"updateNetworkFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"}]

60a080604052346100325730608052615a2f9081620000388239608051818181611a0501528181611b0501526124970152f35b600080fdfe608080604052600436101561001357600080fd5b60003560e01c908162c5ecd214612fef57508063021a34dd14612f5957806316f0115b14612f305780631848effa14612f0757806320a8199314612e9c57806325a70b55146128455780632670e98d146126cd5780633659cfe6146124725780633e5005e51461234b578063410f27031461231a5780634cc42b51146122185780634d3cb810146120f15780634d506d77146120ab5780634dc3abec14611de85780634f1ef28614611ab657806352d1902d146119f257806353cb6c7514611974578063626a7ef2146117c7578063671e11071461174f5780636de317b4146116825780636e30e0161461160a578063791b98bc146115e15780638168c0b6146115105780638e2678d4146111995780638ffb8b2f14610f6357806390a4a76814610e3c5780639f89e0fb14610e09578063a46fff9814610c74578063af2616ab14610c56578063be7cd4c414610c17578063be82e5b114610acc578063c0c53b8b14610961578063c0d7865514610839578063c1872cf31461066a578063cb80318b14610513578063dbe6f79f146104d4578063ecd1bbcb1461034a578063f887ea4014610321578063f9d244fd1461026a5763fca5c793146101d657600080fd5b346102655760203660031901126102655760043560005260686020526040600020805461026160018060a01b036001840154169160028401549360ff600382015416916004820154906005830154600684015460078501549060088601549260098701549560ff600b600a8a015499015416986040519c8d9c8d9860ff808c60081c169b169961307f565b0390f35b600080fd5b34610265576101a060206102866102803661329f565b906153ab565b604092919251928051845260018060a01b03838201511683850152604081015160408501526102bd60608201516060860190613072565b6080810151608085015260a081015160a085015260c0810151151560c085015260e081015160e08501526101008082015190850152610120808201519085015261014080910151908401526103176101608401825161336d565b0151610180820152f35b34610265576000366003190112610265576071546040516001600160a01b039091168152602090f35b346102655760803660031901126102655760243560048110156102655761036f613258565b6064356001600160401b03811161026557366023820112156102655761039f9036906024816004013591016132d9565b60655460405163c4aa304160e01b81526001600160a01b03918216949293929160209182816004818a5afa801561049057829160009161049c575b50163314958615610423575b505093610406948115610408575b506103fe90613668565b600435613f96565b005b6074915033600052526103fe60ff60406000205416906103f4565b60405163477a86ef60e01b815296508290879060049082905afa80156104905760009061045a575b610406965016331494866103e6565b508186813d8311610489575b6104708183613221565b8101031261026557610484610406966135e8565b61044b565b503d610466565b6040513d6000823e3d90fd5b809250848092503d83116104cd575b6104b58183613221565b81010312610265576104c782916135e8565b886103da565b503d6104ab565b34610265576020366003190112610265576001600160a01b036104f5613242565b166000526074602052602060ff604060002054166040519015158152f35b6020600319818136011261026557600435906001600160401b038211610265576101809082360301126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908481600481875afa9081156104905785918391600091610631575b501633149384156105c5575b505050816105a59290156105ad575b61059d90613668565b600401613812565b604051908152f35b5033600090815260748452604090205460ff16610594565b60405163477a86ef60e01b81529450849060049082905afa8015610490576000906105fb575b6105a59350163314918385610585565b508383813d831161062a575b6106118183613221565b81010312610265576106256105a5936135e8565b6105eb565b503d610607565b928092508391503d8311610663575b61064a8183613221565b81010312610265578161065d86926135e8565b87610579565b503d610640565b3461026557606036600319011261026557600435602435600481101561026557610692613258565b60655460405163c4aa304160e01b8152919260209290916001600160a01b03908116918481600481865afa9081156104905785918391600091610800575b50163314928315610794575b5050506106e890613f23565b8061071357506068906104069360005252600b60406000205b019060ff801983541691151516179055565b92600052606a815260406000209260ff600385015416600481101561077e57036107435750600b61040692610701565b6064906040519062461bcd60e51b8252600482015260146024820152730e8e4c2c8ca40e8f2e0ca40dcdee840dac2e8c6d60631b6044820152fd5b634e487b7160e01b600052602160045260246000fd5b60405163477a86ef60e01b81529350839060049082905afa8015610490576000906107ca575b6106e892501633149083876106dc565b508382813d83116107f9575b6107e08183613221565b81010312610265576107f46106e8926135e8565b6107ba565b503d6107d6565b928092508391503d8311610832575b6108198183613221565b81010312610265578161082c86926135e8565b896106d0565b503d61080f565b346102655760208060031936011261026557610853613242565b5060655460405162435da560e01b81526001600160a01b03929182908290600490829087165afa801561049057829160009161092b575b50602460405180958193637be53ca160e01b8352336004840152165afa918215610490576000926108f0575b506108c2606492613609565b6040519062461bcd60e51b82526004820152600a60248201526919195c1c9958d85d195960b21b6044820152fd5b91508082813d8311610924575b6109078183613221565b81010312610265576108c261091d6064936135fc565b92506108b6565b503d6108fd565b82819392503d831161095a575b6109428183613221565b810103126102655761095482916135e8565b8461088a565b503d610938565b34610265576060366003190112610265576004356001600160a01b0381811691829003610265576024359181831680930361026557604435918216809203610265576000549260ff8460081c161593848095610abf575b8015610aa8575b15610a4c5760ff19811660011760005584610a3a575b506001600160601b0360a01b9182606554161760655581606f541617606f556070541617607055610a0257005b61ff0019600054166000557f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498602060405160018152a1005b61ffff191661010117600055846109d5565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b1580156109bf5750600160ff8216146109bf565b50600160ff8216106109b8565b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa8015610490578291600091610bdf575b50163314928315610b67575b607383610b2c86613f23565b60043560005260688152610b436040600020614451565b606b81526000600160408220828155015552604060002060ff198154169055600080f35b60405163477a86ef60e01b81529193508290829060049082905afa90811561049057600091610ba2575b50607392610b2c9116331492610b20565b90508181813d8311610bd8575b610bb98183613221565b8101031261026557607392610bd0610b2c926135e8565b915092610b91565b503d610baf565b809250848092503d8311610c10575b610bf88183613221565b8101031261026557610c0a82916135e8565b85610b14565b503d610bee565b3461026557602036600319011261026557600435600052606b602052604080600020600160ff825416910154610c4f8351809361336d565b6020820152f35b34610265576000366003190112610265576020606654604051908152f35b3461026557604036600319011261026557610c8d613242565b602435908115158083036102655760018060a01b0392836065541692604051809462435da560e01b825281600460209788935afa9081156104905786918691600091610dd2575b50602460405180948193637be53ca160e01b8352336004840152165afa90811561049057600091610d66575b7f5dc7e1b4c8dc174937170a1d0edc6abd532ab4dedf78b93f6b51a6ce225b80426060878787610d548c89610d348a613609565b1691826000526074855260406000209060ff801983541691151516179055565b604051923384528301526040820152a1005b9050848181959493963d8311610dcb575b610d818183613221565b81010312610265577f5dc7e1b4c8dc174937170a1d0edc6abd532ab4dedf78b93f6b51a6ce225b804295606095610d34610dbd610d54946135fc565b935050929394955095610d00565b503d610d77565b92505081813d8311610e02575b610de98183613221565b810103126102655784610dfc87926135e8565b88610cd4565b503d610ddf565b3461026557610e17366130f1565b90600052606d6020526040600020906000526020526020604060002054604051908152f35b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa8015610490578291600091610f2b575b50163314928315610eb3575b607383610e9c86613f23565b60043560005260698152610b43604060002061440f565b60405163477a86ef60e01b81529193508290829060049082905afa90811561049057600091610eee575b50607392610e9c9116331492610e90565b90508181813d8311610f24575b610f058183613221565b8101031261026557607392610f1c610e9c926135e8565b915092610edd565b503d610efb565b809250848092503d8311610f5c575b610f448183613221565b8101031261026557610f5682916135e8565b85610e84565b503d610f3a565b346102655760608060031936011261026557610f7d613242565b610f85613258565b60655460405163c4aa304160e01b8152602094926001600160a01b03928316929091908682600481875afa8015610490578692600091611160575b50811633149081156110e3575b5090610fef93610fdf610fe493613f23565b615808565b602493843590615951565b9182600052606c808552604060002054610100908181116000146110db5750905b60015b8281111561101d57005b856000528187526040600020818403908482116110c6576110479161104191613107565b506143a7565b60a08101519060808101519060048210156110b157916110a791886110ac9594015115159060405192611079846131cf565b601784527f63616e63656c416c6c506f736974696f6e4f72646572730000000000000000008d850152613f96565b613645565b611013565b86634e487b7160e01b60005260216004526000fd5b85634e487b7160e01b60005260116004526000fd5b905090611010565b60405163477a86ef60e01b8152925090508682600481875afa8015610490578692600091611118575b50163314610fef610fcd565b809350888092503d8311611159575b6111318183613221565b8101031261026557610fef93610fdf879261114e610fe4956135e8565b92965092935061110c565b503d611127565b809350888092503d8311611192575b6111798183613221565b81010312610265578061118c87936135e8565b90610fc0565b503d61116f565b346102655760608060031936011261026557600435906001600160401b038083116102655736602384011215610265578260040135906111d88261337a565b926111e66040519485613221565b8284526020948585016024809560051b83010191368311610265578501905b8282106114f85750505082359082821161026557366023830112156102655781600401356112328161337a565b926112406040519485613221565b818452858885019260051b820101913683116102655786899201905b8382106114e9575050505060443592831161026557366023840112156102655782600401359261128b8461337a565b936112996040519586613221565b8085528583898701920283010191368311610265578601905b8282106114b057505060655460405162435da560e01b81526001600160a01b0392509088908290600490829086165afa801561049057889160009161147a575b508660405180948193637be53ca160e01b8352336004840152165afa801561049057600090611444575b6113269150613609565b845182518091149081611439575b50156113f55760005b8351811015610406576113508187613654565b51600290818110156110b15760c08984937f34277869391e6b06632d8da807f22afe881d4d09db9281cdee96b1070871908b936113906113f0978a613654565b519061139c878c613654565b51916113a782613286565b816000528552604060002091835192838155604087860151958660018401550151958691015560405195338752860152604085015288840152608083015260a0820152a1613645565b61133d565b60405162461bcd60e51b815260048101879052601a818601527f696e636f6e73697374656e7420706172616d73206c656e6774680000000000006044820152606490fd5b905083511487611334565b508681813d8311611473575b61145a8183613221565b810103126102655761146e611326916135fc565b61131c565b503d611450565b82819392503d83116114a9575b6114918183613221565b81010312610265576114a388916135e8565b896112f2565b503d611487565b8382360312610265578884916040516114c881613139565b843581528285013583820152604085013560408201528152019101906112b2565b8135815290820190820161125c565b81356002811015610265578152908701908701611205565b34610265576101e0602061152c6115263661329f565b906155e3565b604092919251928051845260018060a01b038382015116838501526040810151604085015261156360608201516060860190613072565b6080810151608085015260a081015160a085015260c081015160c085015260e081015160e0850152610100808201519085015261012080820151151590850152610140808201511515908501526101608082015190850152610180809101511515908401526115d76101a08401825161336d565b01516101c0820152f35b34610265576000366003190112610265576070546040516001600160a01b039091168152602090f35b346102655760203660031901126102655760043560005260696020526040600020805461026160018060a01b036001840154169260028101549060ff6003820154166004820154600583015460ff60068501541690600785015492600886015494600a6009880154970154976040519b8c9b8c613310565b3461026557602036600319011261026557600060a06040516116a38161316a565b8281528260208201528260408201528260608201528260808201520152600435600052607260205260c060406000206040516116de8161316a565b60018060a01b03825416918282526001810154602083019081526002820154604084019081526003830154916060850192835260a0600560048601549560808801968752015495019485526040519586525160208601525160408501525160608401525160808301525160a0820152f35b346102655760203660031901126102655760043560005260676020526040600020805461026160018060a01b036001840154169260028101549060ff6003820154166004820154600583015460ff60068501541690600785015492600886015494600a6009880154970154976040519b8c9b8c613310565b3461026557608036600319011261026557600435602435906004821015610265576117f0613258565b60655460405163c4aa304160e01b815260643594602093909290916001600160a01b0391821691908581600481865afa908115610490578691839160009161193b575b501633149283156118cf575b50505061184b90613f23565b1561189757806118745750606791600052526118706008604060002001918254613f03565b9055005b60011461187d57005b606991600052526118706008604060002001918254613f03565b6118b557606891600052526118706007604060002001918254613f03565b606a91600052526118706007604060002001918254613f03565b60405163477a86ef60e01b81529350839060049082905afa801561049057600090611905575b61184b925016331490848861183f565b508482813d8311611934575b61191b8183613221565b810103126102655761192f61184b926135e8565b6118f5565b503d611911565b928092508391503d831161196d575b6119548183613221565b81010312610265578161196787926135e8565b8a611833565b503d61194a565b34610265576119a661198536613267565b919060006040805161199681613139565b8281528260208201520152613286565b90600052602052606060406000206040516119c081613139565b815491828252604060026001830154926020850193845201549201918252604051928352516020830152516040820152f35b34610265576000366003190112610265577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163003611a4b5760206040516000805160206159ba8339815191528152f35b60405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608490fd5b604036600319011261026557611aca613242565b6024356001600160401b038111610265573660238201121561026557611afa9036906024816004013591016132d9565b906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116611b3230821415613391565b611b4f6000805160206159ba8339815191529183835416146133f2565b81606554169160405180936334cc866d60e21b825281600460209687935afa8015610490578291600091611db0575b50163303611d75577f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611bbd575050506104069150613453565b83929316906040516352d1902d60e01b81528481600481865afa60009181611d46575b50611c415760405162461bcd60e51b815260048101869052602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b03611cef57611c4f82613453565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590611ce7575b611c8557005b6000806104069460405194611c9986613139565b602786527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c81870152660819985a5b195960ca1b604087015281519101845af4611ce16134e3565b91613513565b506001611c7f565b60405162461bcd60e51b815260048101849052602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608490fd5b9091508581813d8311611d6e575b611d5e8183613221565b8101031261026557519087611be0565b503d611d54565b60405162461bcd60e51b8152600481018490526013602482015272556e617574686f72697a65642061636365737360681b6044820152606490fd5b809250858092503d8311611de1575b611dc98183613221565b8101031261026557611ddb82916135e8565b87611b7e565b503d611dbf565b3461026557611df63661329f565b60655460405163c4aa304160e01b81526001600160a01b039360209392851692918481600481875afa9081156104905785918791600091612072575b50163314938415611ffa575b5050611e4c611e5193613f23565b6153ab565b815160005260728352604060002060405190611e6c8261316a565b858154168252600181015485830152600281015480604084015260038201549081606085015260a06005600485015494608087019586520154940193845280611f77575b5050519485611eef575b607285855160005252610406604060002060056000918281558260018201558260028201558260038201558260048201550155565b848401511694604084015191519060c0850151151591868501519360405198611f178a6131a0565b8952878901526003604089015260006060890152608088015260a087015260c0860152600060e0860152600061010086015260006101208601526101408501525192600384101561077e57607293611f6e91614af1565b50838080611eba565b8787870151169160408701519160c0880151151591898801519360405195611f9e876131a0565b86528a8601526002604086015260006060860152608085015260a084015260c0830152600060e0830152600061010083015260006101208301526101408201528351600381101561077e57611ff291614af1565b508680611eb0565b60405163477a86ef60e01b81529450849060049082905afa8015610490578593600091612032575b5090921633149183611e51611e3e565b809450858092503d831161206b575b61204b8183613221565b8101031261026557611e4c85612063611e51956135e8565b915093612022565b503d612041565b928092508391503d83116120a4575b61208b8183613221565b81010312610265578561209e86926135e8565b88611e32565b503d612081565b34610265576120c36120bc36613267565b9190613286565b9060005260205260606040600020805490600260018201549101549060405192835260208301526040820152f35b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa80156104905782916000916121e0575b50163314928315612168575b60738361215186613f23565b600435600052606a8152610b436040600020614451565b60405163477a86ef60e01b81529193508290829060049082905afa908115610490576000916121a3575b506073926121519116331492612145565b90508181813d83116121d9575b6121ba8183613221565b81010312610265576073926121d1612151926135e8565b915092612192565b503d6121b0565b809250848092503d8311612211575b6121f98183613221565b810103126102655761220b82916135e8565b85612139565b503d6121ef565b346102655760208060031936011261026557600435600052606c815260406000209081546122458161337a565b906122536040519283613221565b8082528282018094600052836000206000915b8383106122fd5760408051878152865181890181905289928201908960005b8281106122925784840385f35b9091928260e06001928851848060a01b03815116825283810151848301526040810151151560408301526060808201511515908301526122da60808083015190840190613072565b60a0808201519083015260c0809101519082015201960191019492919094612285565b60058660019261230c856143a7565b815201920192019190612266565b34610265576020366003190112610265576004356000526073602052602060ff604060002054166040519015158152f35b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa801561049057829160009161243a575b501633149283156123c2575b6073836123ab86613f23565b60043560005260678152610b43604060002061440f565b60405163477a86ef60e01b81529193508290829060049082905afa908115610490576000916123fd575b506073926123ab911633149261239f565b90508181813d8311612433575b6124148183613221565b810103126102655760739261242b6123ab926135e8565b9150926123ec565b503d61240a565b809250848092503d831161246b575b6124538183613221565b810103126102655761246582916135e8565b85612393565b503d612449565b34610265576020806003193601126102655761248c613242565b6001600160a01b03917f000000000000000000000000000000000000000000000000000000000000000083166124c430821415613391565b6124e16000805160206159ba8339815191529185835416146133f2565b6004828560655416604051928380926334cc866d60e21b82525afa8015610490578591600091612695575b5016330361265a576040519361252185613206565b600085527f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561255c575050506104069150613453565b83929316906040516352d1902d60e01b81528481600481865afa6000918161262b575b506125e05760405162461bcd60e51b815260048101869052602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b03611cef576125ee82613453565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a282511580159061262357611c8557005b506000611c7f565b9091508581813d8311612653575b6126438183613221565b810103126102655751908761257f565b503d612639565b60405162461bcd60e51b8152600481018390526013602482015272556e617574686f72697a65642061636365737360681b6044820152606490fd5b809250848092503d83116126c6575b6126ae8183613221565b81010312610265576126c085916135e8565b8661250c565b503d6126a4565b346102655760e0366003190112610265576040516126ea81613185565b6126f2613242565b815260209060243582820152612706613258565b60408201526064358015158103610265576060820152608435600481101561026557608082015260a43560a082015260c43560c082015260655460405163c4aa304160e01b81526001600160a01b0391821693908181600481885afa801561049057839160009161280d575b50163314938415612790575b6104068461278b87613f23565b61523e565b81929450906004916040519283809263477a86ef60e01b82525afa918215610490576000926127ce575b50506104069261278b91163314928461277e565b90809250813d8311612806575b6127e58183613221565b8101031261026557610406926127fd61278b926135e8565b918194506127ba565b503d6127db565b809250838092503d831161283e575b6128268183613221565b810103126102655761283883916135e8565b86612772565b503d61281c565b600319602036820112610265576001600160401b03600435116102655761012090600435360301126102655733600052607460205260ff6040600020541615612e6a57602460043501356004811015610265576128a890600435600401356153ab565b5060018060a01b0360208201511690604060e08201519101519060206128d961010460043501600435600401613785565b908092918101031261026557356001600160a01b03811690819003610265578303612e37576065546129159084906001600160a01b0316615808565b6001600160801b0361292b606460043501613eef565b1681101580612e17575b15612ddd576000906001600160801b03612953606460043501613eef565b16612dd4575b6001600160801b0361296f60a460043501613eef565b16612daa575b606f54604051632f7ce47360e21b815260048101859052906001600160a01b031661016082602481845afa91821561049057600092612d77575b5060c4600435013560038110156102655760018103612c185750505060008381527f136eb4aae73f7618d8559a84c5ff3678edc6b16994db052447ebc43c429b7d6f60205260409081902090519190612a0783613139565b80548352612a36612a2e856002600185015494602088019586520154806040880152613f10565b948451613f10565b9251612b66575b505050506000805160206159da833981519152916001600160801b0360e0925b81612a6c606460043501613eef565b6044600435013590612a8260a460043501613eef565b6005608460043501359260405192612a998461316a565b8984526020840191600435600401358352876040860191168152606085019087825288608087019316835260a086019387855260043560040135600052607260205260406000209660018060a01b039051166001600160601b0360a01b88541617875551600187015551600286015551600385015551600484015551910155612b26606460043501613eef565b91612b3560a460043501613eef565b946040519788526004356004013560208901526040880152606087015260808601521660a08401521660c0820152a1005b51119081159283612c0e575b508215612bf3575b5050612bd6576000805160206159da833981519152916001600160801b0360e092612bce600080808060018060a01b03606f541681604051612bbb81613206565b5234905af1612bc86134e3565b506137b7565b928294612a3d565b60405162461bcd60e51b815280612bef6004820161374d565b0390fd5b90915081612c04575b508380612b7a565b9050341083612bfc565b3410925085612b72565b949594919390929091600214612c4d575b5050505060e0906001600160801b036000805160206159da83398151915293612a5d565b60008681527f44e4f44bb0aae4b5d1e07207f82567d4201c1d09f6b5859dddcfb50647f55a7060205260409081902090519190612cb990612cb1908590600290612c9687613139565b80548752600181015460208801520154806040870152613f10565b938351613f10565b918051612cc8575b5050612c29565b6020909695960151119081159283612d67575b508215612d46575b5050612bd6576040909201516000805160206159da8339815191529360e0936001600160801b0392612d3c91906001600160a01b0316612d2c6004803561010481019101613785565b92909160e4600435013590614499565b9382938680612cc1565b90915081612d57575b508580612ce3565b905060e460043501351085612d4f565b60043560e4013510925087612cdb565b612d9c9192506101603d61016011612da3575b612d948183613221565b8101906136aa565b90866129af565b503d612d8a565b90600181018111612dbe5760010190612975565b634e487b7160e01b600052601160045260246000fd5b60019150612959565b60405162461bcd60e51b815260206004820152601260248201527165786365656473206f726465722073697a6560701b6044820152606490fd5b506001600160801b03612e2e60a460043501613eef565b16811015612935565b60405162461bcd60e51b815260206004820152600b60248201526a1b9bdd08185b1b1bddd95960aa1b6044820152606490fd5b60405162461bcd60e51b815260206004820152600a60248201526937b7363ca937baba32b960b11b6044820152606490fd5b3461026557602036600319011261026557600435600052607260205260c0604060002060018060a01b038154169060018101549060028101546003820154906005600484015493015493604051958652602086015260408501526060840152608083015260a0820152f35b34610265576000366003190112610265576065546040516001600160a01b039091168152602090f35b3461026557600036600319011261026557606f546040516001600160a01b039091168152602090f35b3461026557612f67366130f1565b90600052606c602052604060002080548210156102655760e091612f8a91613107565b5060018060a01b0381541690600181015490612fe360028201546004600384015493015493604051958652602086015260ff81161515604086015260ff8160081c161515606086015260ff608086019160101c16613072565b60a083015260c0820152f35b3461026557602036600319011261026557600435600052606a60205280610261604060002080549060018060a01b0360018201541684600283015460ff6003850154166004850154600586015460068701549160078801549360088901549560098a01549860ff600b600a8d01549c0154169b60ff808c60081c169b169961307f565b90600482101561077e5752565b9b99979593919d9c9a98969492909d6101a08d019e8d52600160a01b600190031660208d015260408c015260608b016130b791613072565b60808a015260a089015260c088015260e0870152610100860152151561012085015215156101408401526101608301521515906101800152565b6040906003190112610265576004359060243590565b8054821015613123576000526005602060002091020190600090565b634e487b7160e01b600052603260045260246000fd5b606081019081106001600160401b0382111761315457604052565b634e487b7160e01b600052604160045260246000fd5b60c081019081106001600160401b0382111761315457604052565b60e081019081106001600160401b0382111761315457604052565b61016081019081106001600160401b0382111761315457604052565b6001600160401b03811161315457604052565b604081019081106001600160401b0382111761315457604052565b6101a081019081106001600160401b0382111761315457604052565b602081019081106001600160401b0382111761315457604052565b90601f801991011681019081106001600160401b0382111761315457604052565b600435906001600160a01b038216820361026557565b60443590811515820361026557565b6040906003190112610265576004356002811015610265579060243590565b600281101561077e57600052606e602052604060002090565b6040906003190112610265576004359060243560048110156102655790565b6001600160401b03811161315457601f01601f191660200190565b9291926132e5826132be565b916132f36040519384613221565b829481845281830111610265578281602093846000960137010152565b97949193610140999693613347929d9c9b98956101608b019e8b5260018060a01b031660208b015260408a01526060890190613072565b608087015260a0860152151560c085015260e08401526101008301526101208201520152565b90600382101561077e5752565b6001600160401b0381116131545760051b60200190565b1561339857565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b19195b1959d85d1958d85b1b60a21b6064820152608490fd5b156133f957565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b6163746976652070726f787960a01b6064820152608490fd5b803b15613488576000805160206159ba83398151915280546001600160a01b0319166001600160a01b03909216919091179055565b60405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b3d1561350e573d906134f4826132be565b916135026040519384613221565b82523d6000602084013e565b606090565b919290156135755750815115613527575090565b3b156135305790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156135885750805190602001fd5b60405162461bcd60e51b815260206004820152908190612bef9060248301905b919082519283825260005b8481106135d4575050826000602080949584010152601f8019910116010190565b6020818301810151848301820152016135b3565b51906001600160a01b038216820361026557565b5190811515820361026557565b1561361057565b60405162461bcd60e51b815260206004820152600d60248201526c37b7363ca837b7b620b236b4b760991b6044820152606490fd5b6000198114612dbe5760010190565b80518210156131235760209160051b010190565b1561366f57565b60405162461bcd60e51b815260206004820152601360248201527237b7363ca2bc32b1baba37b9132937baba32b960691b6044820152606490fd5b908161016091031261026557604051906136c3826131a0565b805182526136d3602082016135e8565b60208301526136e4604082016135e8565b60408301526136f5606082016135e8565b6060830152613706608082016135fc565b608083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140809101519082015290565b60609060208152601860208201527f696e73756666696369656e74206e6574776f726b20666565000000000000000060408201520190565b903590601e198136030182121561026557018035906001600160401b0382116102655760200191813603831361026557565b156137be57565b60405162461bcd60e51b81526020600482015260136024820152721d1c985b9cd9995c88195d1a0819985a5b1959606a1b6044820152606490fd5b3580151581036102655790565b600482101561077e5752565b6001600160a01b038135818116929083810361026557613836908360655416615808565b81606f5416906040928351632f7ce47360e21b8152602090818401356004968188840152610160602493818186818c5afa908115613ee457600091613ec7575b506080928382015115613e9b5761012097888a01359b60038d10159b8c610265578d9060018203613d8c57505060008052606e8952826000208760005289528260002083516138c481613139565b8a8d60028454948585526001810154938501938452015493878401948552613cf5575b505050505b828b0135938185101592836102655785158015613ce7575b613b63575b8c6060810135978660008a13613b2d575b505060e001359991505060008913156139c05750506102655761393f60a08a016137f9565b9461394c60c08b016137f9565b9661395690615921565b9782519d8e613964816131a0565b528d01528b019061397491613806565b60608a01528086013590890152151560a0880152151560c087015260e086015261010080830135908601528401600090526101408091013590840152610265576139bd916146e1565b90565b60008994989912600014613a5e575050610265576139dd90615921565b936139ea60a08a016137f9565b956139f760c08b016137f9565b9782519d8e613a05816131a0565b528d01528b0190613a1591613806565b60608a0152808601359089015260a0880152151560c0870152151560e086015261010080830135908601528401600090526101408091013590840152610265576139bd91614af1565b909192508499989796939915613af557505061026557600096613aae91613a8760a08b016137f9565b95613a9460c08c016137f9565b9782519e8f90613aa3826131a0565b815201528c01613806565b60608a01528086013590890152151560a0880152151560c08701528160e087015261010080840135908701528501526101408091013590840152610265576139bd916146e1565b835162461bcd60e51b81529182018890526013908201527218dbdb1b185d195c985b081c995c5d5a5c9959606a1b6044820152606490fd5b83613b5191613b599601511692613b438b615921565b94606f541692810190613785565b939092614499565b38808c818661391a565b80606f5416855180916330a66e1560e01b82528b86830152818d6101009384935afa918215613cdc57908f91600093613c39575b505060e001356000811215613bae575b5050613909565b8015918215613bfd575b505015613bc6573880613ba7565b845162461bcd60e51b81528084018c90526012818c015271696e76616c69642074726164652073697a6560701b6044820152606490fd5b909150613c0982615921565b8782015111159182613c1f575b50503880613bb8565b6060919250613c2d90615921565b91015110153880613c16565b9150918282813d8311613cd5575b613c518183613221565b81010312613cd2578751928301908382106001600160401b03831117613cc057508752805182528c8101518d830152868101518783015260608082015190830152898101518a83015260a0808201519083015260c0808201519083015260e090810151818301528e9038613b97565b634e487b7160e01b8152604187528d90fd5b80fd5b503d613c47565b87513d6000823e3d90fd5b506000935060018614613904565b60e00135613d0281615921565b825111159384613d81575b508315613d57575b505050613d3e57613d35600080808086606f5416818951612bbb81613206565b3880808d6138e7565b825162461bcd60e51b8152908190612bef90820161374d565b613d6391929350615921565b9051119081613d76575b50388080613d15565b905051341038613d6d565b513410935038613d0d565b60009d5090600214613d9f575b506138ec565b60018d52606e8a52838d20888e528a52838d2084518b8e613dbf83613139565b60028454948585526001810154938501938452015493888401948552613de9575b50505050613d99565b60e081013590613df882615921565b835111159485613e88575b50508315613e59575b505050613e42576101408c613e3892858789015116613e2d8a840184613785565b949093013590614499565b388080808e613de0565b835162461bcd60e51b815280612bef81850161374d565b613e6591929350615921565b9051119081613e78575b50388080613e0c565b9050516101408d01351038613e6f565b5161014091909101351093508f38613e03565b5162461bcd60e51b8152808b0187905260088187015267191a5cd8589b195960c21b6044820152606490fd5b613ede9150823d8411612da357612d948183613221565b38613876565b83513d6000823e3d90fd5b356001600160801b03811681036102655790565b91908201809211612dbe57565b81810292918115918404141715612dbe57565b15613f2a57565b60405162461bcd60e51b815260206004820152600c60248201526b37b7363ca2bc32b1baba37b960a11b6044820152606490fd5b919360a0936139bd9695613f89938552600180871b0316602085015260408401526060830190613072565b81608082015201906135a8565b9293929091156141d157613faa82826153ab565b5060208082018051919492916001600160a01b039190821680156141c657613fd6908360655416615808565b8181511660409384810197885190610100830151156000906000146141c1575060808301515b60c08401511515926060850195865194600495868110156141ac57918b939161406295936140538a519160e08c0151938851986140388a613185565b868a52878c8b01528901526001606089015260808801613806565b60a086015260c0850152614fee565b83518281101561419757614168576073908351600052606781526140888860002061440f565b8351600052607281526140bc8860002060056000918281558260018201558260028201558260038201558260048201550155565b8351600052528560002060ff19815416905584845116915192519080821015614153575061414e96949286949261413c7f7e93a6b00cb3caacf000d7018943b12e2b4ad29e7849df14ebd51caf4fd739b8937f8e43c842a77ad600a970d5aded1e93f7f715700579caaaa9745b51d1d847558f9d9e995193849384614fc4565b0390a151169551905195869586613f5e565b0390a1565b602190634e487b7160e01b6000525260246000fd5b8351828110156141975790600160739203614088578351600052606981526141928860002061440f565b614088565b602183634e487b7160e01b6000525260246000fd5b602187634e487b7160e01b6000525260246000fd5b613ffc565b505050505050509050565b6141db82826155e3565b5060208082018051919492916001600160a01b039190821680156141c657614207908360655416615808565b818151166040938481019788519060e0830151156000906000146143a2575060808301515b6101208401511515926060850195865194600495868110156141ac57918b939161428495936140538a519160c08c0151938851986142698a613185565b868a52878c8b01528901526000606089015260808801613806565b8351828110156141975761435e576073908351600052606881526142aa88600020614451565b8351600052607281526142de8860002060056000918281558260018201558260028201558260038201558260048201550155565b8351600052528560002060ff19815416905584845116915192519080821015614153575061414e96949286949261413c7fb225fd6bcccad9342bc10ccc7e25ef77175b77348c8393d669ac2dbc98a1ae29937f8e43c842a77ad600a970d5aded1e93f7f715700579caaaa9745b51d1d847558f9d9e995193849384614fc4565b835182811015614197576073919060010361438d578351600052606a815261438888600020614451565b6142aa565b8351600052606a815261438888600020614451565b61422c565b906040516143b481613185565b60c06004829460018060a01b038154168452600181015460208501526143fe60ff600283015481811615156040880152818160081c161515606088015260101c1660808601613806565b600381015460a08501520154910152565b600a6000918281558260018201558260028201558260038201558260048201558260058201558260068201558260078201558260088201558260098201550155565b600b60009182815582600182015582600282015582600382015582600482015582600582015582600682015582600782015582600882015582600982015582600a8201550155565b90929360018060a01b038092169060409485516370a0823160e01b9485825260009616928360048301526020988983602481895afa92831561465757908a9594939291899361461f575b5083614582575b50506024916144f891613f03565b9487519485938492835260048301525afa9283156145775792614548575b5011614520575050565b60649250519062461bcd60e51b825260048201526002602482015261746360f01b6044820152fd5b9091508381813d8311614570575b6145608183613221565b8101031261026557519038614516565b503d614556565b8451903d90823e3d90fd5b909192939450333b1561461b578160a489928b5194859384926316e95edb60e31b84528b60048501528960248501528a604485015260806064850152816084850152848401378181018301859052601f01601f1916810103018183335af18015614611579089949392916145f7575b806144ea565b916144f891976146086024946131bc565b979150916145f1565b88513d89823e3d90fd5b8780fd5b8092935086919495963d8311614650575b61463a8183613221565b8101031261461b579089949392915191386144e3565b503d614630565b89513d8a823e3d90fd5b600382101561077e5752565b90600481101561077e5760ff80198354169116179055565b9692936146b961012099956146d797939d9c9b98946101408b019e60018060a01b03168b5260208b015260408a0190613072565b6060880152608087015260a086015260c085015260e084019061336d565b6101008201520152565b906066549160018060a01b038151169260208201516040830151600481101561077e576060840151608085015160a086015115159161474960e088015194610100890151966040519b6147338d6131a0565b898d5260208d015260408c015260608b01613806565b608089015260a088015260c087015260e08601526000610100860152610120850152610140904282860152818301519060405191614786836131cf565b6147908684614661565b6020830152600052606b6020526040600020908051600381101561077e5760019160209160ff8019865416911617845501519101556040820151600481101561077e576149e65760665460005260676020526040600020845181556001810160018060a01b036020870151166001600160601b0360a01b825416179055604085015160028201556060850151600481101561077e57614832906003830161466d565b6080850151600482015560a0850151600582015561486560c08601511515600683019060ff801983541691151516179055565b60e0850151600782015561010085015160088201556101208501516009820155600a828601519101555b60c08201511515806149bb575b506148a8606654613645565b6066556020840151604085015160c08601516060870151926001600160a01b031691901515600484101561077e5761490f61491e9489519260e08b015194604051966148f388613185565b8752602087015260408601526001606086015260808501613806565b60a083015260c08201526151aa565b60018060a01b0360208501511690845192604081015190600482101561077e577f459f5f85edf43d324c3891f0b72d72000cce329562b08f262e06121652c8800d956149b49360608301516020840151608085015191600160e087015194870151966149a261499a60c060a084015115159301511515926157f4565b831b916157f4565b60021b1717966040519a8b9a8b614685565b0390a15190565b6149e090606654600052607360205260406000209060ff801983541691151516179055565b3861489c565b6040820151600481101561077e57600103614ab75760665460005260696020526040600020845181556001810160018060a01b036020870151166001600160601b0360a01b825416179055604085015160028201556060850151600481101561077e57614a56906003830161466d565b6080850151600482015560a08501516005820155614a8960c08601511515600683019060ff801983541691151516179055565b60e0850151600782015561010085015160088201556101208501516009820155600a8286015191015561488f565b60405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207472616465207479706560701b6044820152606490fd5b6066549160018060a01b038251169260208301516040840151600481101561077e576060850151608086015160a087015191614b426101008901519460c08a01511515966040519b6147338d6131ea565b608089015260a088015260c0870152600060e087015261010086015261012085015260006101408501524261016085015260006101808501526101408301519060405191614b8f836131cf565b614b998484614661565b6020830152600052606b6020526040600020908051600381101561077e5760019160209160ff8019865416911617845501519101556040820151600481101561077e57614e3e5760c0820151151561014084015260665460005260686020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ce7926003830161466d565b6080850151600482015560a0850151600582015560c0850151600682015560e085015160078201556101008501516008820155614cbf60098201614ca36101208801511515829060ff801983541691151516179055565b610140870151815461ff00191690151560081b61ff0016179055565b610160850151600a820155600b610180860151151591019060ff801983541691151516179055565b60e0820151151580614e13575b50614d00606654613645565b606655602083015160408401516101208501516060860151926001600160a01b031691901515600484101561077e5761490f614d689488519260c08a01519460405196614d4c88613185565b8752602087015260408601526000606086015260808501613806565b60018060a01b036020840151168351916040840151600481101561077e57846149b49260607f459f5f85edf43d324c3891f0b72d72000cce329562b08f262e06121652c8800d970151602083015160808401519060a08501519261014086015195614e028d614df8614def61014060e060c0870151151596015115159301511515946157f4565b60011b916157f4565b60021b17916157f4565b60031b17966040519a8b9a8b614685565b614e3890606654600052607360205260406000209060ff801983541691151516179055565b38614cf4565b6040820151600481101561077e57600103614ec35760c082015115610140840152606654600052606a6020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ebe926003830161466d565b614ce7565b6040820151600481101561077e57600203614f435760c082015115610140840152606654600052606a6020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ebe926003830161466d565b6040820151600481101561077e57600303614ab75760c08201511515610140840152606654600052606a6020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ebe926003830161466d565b6001600160a01b0390911681526020810191909152606081019291614fec9160400190613072565b565b92614ffb9092919261523e565b60009182821361500c575b50505050565b606f54604051632f7ce47360e21b8152600481018390526001600160a01b039182169190610160908181602481875afa9182156150e95761505e9284926040928a926150cc575b505001511694615921565b90823b156150c857608492869594928692604051998a978896634f7a10db60e11b88526004880152602487015216604485015260648401525af19081156150bc57506150ad575b808080615006565b6150b6906131bc565b386150a5565b604051903d90823e3d90fd5b8580fd5b6150e29250803d10612da357612d948183613221565b3880615053565b6040513d89823e3d90fd5b91906151945760018060a01b038151166001600160601b0360a01b83541617825560208101516001830155600282019061514060408201511515839060ff801983541691151516179055565b6060810151825461ff00191690151560081b61ff0016178255608081015190600482101561077e578260c09262ff0000600495549160101b169062ff0000191617905560a081015160038501550151910155565b634e487b7160e01b600052600060045260246000fd5b8051602082015160408301516151cd9290151591906001600160a01b0316615951565b600090808252606c6020526040822054606d6020526040832060a0850151845260205260408320558152606c60205260408120805491600160401b83101561522a575081615224916001614fec9594018155613107565b906150f4565b634e487b7160e01b81526041600452602490fd5b8051602080830151604080850151929493909261526792901515916001600160a01b0316615951565b92600093808552606d825260a08386209401938451865282528285205493818652606c8352838620549460001995868101908111615397578110615324575b5090606c9291818752606d83528487209051875282528584812055855252822090815480156153105701916152db8383613107565b6152fc57808260049255826001820155826002820155826003820155015555565b634e487b7160e01b82526004829052602482fd5b634e487b7160e01b84526031600452602484fd5b828752606c845284872080549087820191821161538357611041606c969594939261534e92613107565b83895285855261536481615224848a8d20613107565b838952606d855260a0878a2091015189528452858820559091926152a6565b634e487b7160e01b89526011600452602489fd5b634e487b7160e01b88526011600452602488fd5b9190916040908151906153bd826131a0565b600094858352602092868482015286858201528660608201528660808201528660a08201528660c08201528660e08201526101009187838301526101209088828401526101409289848201525088868851615417816131cf565b828152015260048110156155cf578693929190806154ef5750600a906001958a5260678752848a209085519461544c866131a0565b82548652878060a01b0388840154168987015260028301548787015261547c60ff60038501541660608801613806565b60048301546080870152600583015460a087015260ff600684015416151560c0870152600783015460e0870152600883015490860152600982015490850152015490820152955b86518152606b8452209251926154d8846131cf565b6154e660ff82541685614661565b01549082015290565b9294919350916001036155965791600a6001949287948a5260698752848a209085519461551b866131a0565b82548652878060a01b0388840154168987015260028301548787015261554b60ff60038501541660608801613806565b60048301546080870152600583015460a087015260ff600684015416151560c0870152600783015460e0870152600883015490860152600982015490850152015490820152956154c3565b855162461bcd60e51b8152602060048201526012602482015271696e76616c6964207472616465207479706560701b6044820152606490fd5b634e487b7160e01b89526021600452602489fd5b9190916040908151936155f5856131ea565b600094858152602092868483015286858301528660608301528660808301528660a08301528660c08301528660e0830152610100928784840152610120918883850152610140908982860152610160928a848701528a610180809701528a888a5161565f816131cf565b828152015260048110156157e0579388959360ff9384888e600b9660019c9a1560001461573b57815260688d52209389519861569a8a6131ea565b85548a528b8060a01b038c870154168d8b015260028601548b8b01526156c98360038801541660608c01613806565b600486015460808b0152600586015460a08b0152600686015460c08b0152600786015460e08b01526008860154908a01526009850154908282161515908a015260081c16151590870152600a820154908601520154161515908201529586518152606b8452209251926154d8846131cf565b8152606a8d52209389519861574f8a6131ea565b85548a528b8060a01b038c870154168d8b015260028601548b8b015261577e8360038801541660608c01613806565b600486015460808b0152600586015460a08b0152600686015460c08b0152600786015460e08b01526008860154908a01526009850154908282161515908a015260081c16151590870152600a82015490860152015416151590820152956154c3565b634e487b7160e01b8b52602160045260248bfd5b600090156158025750600190565b60ff1690565b60405162435da560e01b8152602092916001600160a01b039084908390600490829085165afa9283156104905784926000946158e4575b5060405163b36d691960e01b815290821660048201529283916024918391165afa908115610490576000916158af575b506158775750565b6064906040519062461bcd60e51b825260048201526011602482015270189b1858dadb1a5cdd081858d8dbdd5b9d607a1b6044820152fd5b908282813d83116158dd575b6158c58183613221565b81010312613cd257506158d7906135fc565b3861586f565b503d6158bb565b919282819592953d831161591a575b6158fd8183613221565b81010312613cd2575090602461591385936135e8565b939061583f565b503d6158f3565b600080821261592e575090565b600160ff1b821461593d570390565b634e487b7160e01b81526011600452602490fd5b9091600160401b83101561598e5760009015615986575060ff60015b169160201b906001600160601b03199060601b16171790565b60ff9061596d565b60405162461bcd60e51b81526020600482015260036024820152621c1d1b60ea1b6044820152606490fdfe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbce826d5cd45302da284a0b7a10ef98a9de0284a6cda62ec6d24a0247c7d11ccffa26469706673582212207acb45c3c729754d4bf30b13ad4b45abf098cc83ef71cd8cfcf2fff517ceb58764736f6c63430008130033

Deployed Bytecode

0x608080604052600436101561001357600080fd5b60003560e01c908162c5ecd214612fef57508063021a34dd14612f5957806316f0115b14612f305780631848effa14612f0757806320a8199314612e9c57806325a70b55146128455780632670e98d146126cd5780633659cfe6146124725780633e5005e51461234b578063410f27031461231a5780634cc42b51146122185780634d3cb810146120f15780634d506d77146120ab5780634dc3abec14611de85780634f1ef28614611ab657806352d1902d146119f257806353cb6c7514611974578063626a7ef2146117c7578063671e11071461174f5780636de317b4146116825780636e30e0161461160a578063791b98bc146115e15780638168c0b6146115105780638e2678d4146111995780638ffb8b2f14610f6357806390a4a76814610e3c5780639f89e0fb14610e09578063a46fff9814610c74578063af2616ab14610c56578063be7cd4c414610c17578063be82e5b114610acc578063c0c53b8b14610961578063c0d7865514610839578063c1872cf31461066a578063cb80318b14610513578063dbe6f79f146104d4578063ecd1bbcb1461034a578063f887ea4014610321578063f9d244fd1461026a5763fca5c793146101d657600080fd5b346102655760203660031901126102655760043560005260686020526040600020805461026160018060a01b036001840154169160028401549360ff600382015416916004820154906005830154600684015460078501549060088601549260098701549560ff600b600a8a015499015416986040519c8d9c8d9860ff808c60081c169b169961307f565b0390f35b600080fd5b34610265576101a060206102866102803661329f565b906153ab565b604092919251928051845260018060a01b03838201511683850152604081015160408501526102bd60608201516060860190613072565b6080810151608085015260a081015160a085015260c0810151151560c085015260e081015160e08501526101008082015190850152610120808201519085015261014080910151908401526103176101608401825161336d565b0151610180820152f35b34610265576000366003190112610265576071546040516001600160a01b039091168152602090f35b346102655760803660031901126102655760243560048110156102655761036f613258565b6064356001600160401b03811161026557366023820112156102655761039f9036906024816004013591016132d9565b60655460405163c4aa304160e01b81526001600160a01b03918216949293929160209182816004818a5afa801561049057829160009161049c575b50163314958615610423575b505093610406948115610408575b506103fe90613668565b600435613f96565b005b6074915033600052526103fe60ff60406000205416906103f4565b60405163477a86ef60e01b815296508290879060049082905afa80156104905760009061045a575b610406965016331494866103e6565b508186813d8311610489575b6104708183613221565b8101031261026557610484610406966135e8565b61044b565b503d610466565b6040513d6000823e3d90fd5b809250848092503d83116104cd575b6104b58183613221565b81010312610265576104c782916135e8565b886103da565b503d6104ab565b34610265576020366003190112610265576001600160a01b036104f5613242565b166000526074602052602060ff604060002054166040519015158152f35b6020600319818136011261026557600435906001600160401b038211610265576101809082360301126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908481600481875afa9081156104905785918391600091610631575b501633149384156105c5575b505050816105a59290156105ad575b61059d90613668565b600401613812565b604051908152f35b5033600090815260748452604090205460ff16610594565b60405163477a86ef60e01b81529450849060049082905afa8015610490576000906105fb575b6105a59350163314918385610585565b508383813d831161062a575b6106118183613221565b81010312610265576106256105a5936135e8565b6105eb565b503d610607565b928092508391503d8311610663575b61064a8183613221565b81010312610265578161065d86926135e8565b87610579565b503d610640565b3461026557606036600319011261026557600435602435600481101561026557610692613258565b60655460405163c4aa304160e01b8152919260209290916001600160a01b03908116918481600481865afa9081156104905785918391600091610800575b50163314928315610794575b5050506106e890613f23565b8061071357506068906104069360005252600b60406000205b019060ff801983541691151516179055565b92600052606a815260406000209260ff600385015416600481101561077e57036107435750600b61040692610701565b6064906040519062461bcd60e51b8252600482015260146024820152730e8e4c2c8ca40e8f2e0ca40dcdee840dac2e8c6d60631b6044820152fd5b634e487b7160e01b600052602160045260246000fd5b60405163477a86ef60e01b81529350839060049082905afa8015610490576000906107ca575b6106e892501633149083876106dc565b508382813d83116107f9575b6107e08183613221565b81010312610265576107f46106e8926135e8565b6107ba565b503d6107d6565b928092508391503d8311610832575b6108198183613221565b81010312610265578161082c86926135e8565b896106d0565b503d61080f565b346102655760208060031936011261026557610853613242565b5060655460405162435da560e01b81526001600160a01b03929182908290600490829087165afa801561049057829160009161092b575b50602460405180958193637be53ca160e01b8352336004840152165afa918215610490576000926108f0575b506108c2606492613609565b6040519062461bcd60e51b82526004820152600a60248201526919195c1c9958d85d195960b21b6044820152fd5b91508082813d8311610924575b6109078183613221565b81010312610265576108c261091d6064936135fc565b92506108b6565b503d6108fd565b82819392503d831161095a575b6109428183613221565b810103126102655761095482916135e8565b8461088a565b503d610938565b34610265576060366003190112610265576004356001600160a01b0381811691829003610265576024359181831680930361026557604435918216809203610265576000549260ff8460081c161593848095610abf575b8015610aa8575b15610a4c5760ff19811660011760005584610a3a575b506001600160601b0360a01b9182606554161760655581606f541617606f556070541617607055610a0257005b61ff0019600054166000557f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498602060405160018152a1005b61ffff191661010117600055846109d5565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b1580156109bf5750600160ff8216146109bf565b50600160ff8216106109b8565b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa8015610490578291600091610bdf575b50163314928315610b67575b607383610b2c86613f23565b60043560005260688152610b436040600020614451565b606b81526000600160408220828155015552604060002060ff198154169055600080f35b60405163477a86ef60e01b81529193508290829060049082905afa90811561049057600091610ba2575b50607392610b2c9116331492610b20565b90508181813d8311610bd8575b610bb98183613221565b8101031261026557607392610bd0610b2c926135e8565b915092610b91565b503d610baf565b809250848092503d8311610c10575b610bf88183613221565b8101031261026557610c0a82916135e8565b85610b14565b503d610bee565b3461026557602036600319011261026557600435600052606b602052604080600020600160ff825416910154610c4f8351809361336d565b6020820152f35b34610265576000366003190112610265576020606654604051908152f35b3461026557604036600319011261026557610c8d613242565b602435908115158083036102655760018060a01b0392836065541692604051809462435da560e01b825281600460209788935afa9081156104905786918691600091610dd2575b50602460405180948193637be53ca160e01b8352336004840152165afa90811561049057600091610d66575b7f5dc7e1b4c8dc174937170a1d0edc6abd532ab4dedf78b93f6b51a6ce225b80426060878787610d548c89610d348a613609565b1691826000526074855260406000209060ff801983541691151516179055565b604051923384528301526040820152a1005b9050848181959493963d8311610dcb575b610d818183613221565b81010312610265577f5dc7e1b4c8dc174937170a1d0edc6abd532ab4dedf78b93f6b51a6ce225b804295606095610d34610dbd610d54946135fc565b935050929394955095610d00565b503d610d77565b92505081813d8311610e02575b610de98183613221565b810103126102655784610dfc87926135e8565b88610cd4565b503d610ddf565b3461026557610e17366130f1565b90600052606d6020526040600020906000526020526020604060002054604051908152f35b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa8015610490578291600091610f2b575b50163314928315610eb3575b607383610e9c86613f23565b60043560005260698152610b43604060002061440f565b60405163477a86ef60e01b81529193508290829060049082905afa90811561049057600091610eee575b50607392610e9c9116331492610e90565b90508181813d8311610f24575b610f058183613221565b8101031261026557607392610f1c610e9c926135e8565b915092610edd565b503d610efb565b809250848092503d8311610f5c575b610f448183613221565b8101031261026557610f5682916135e8565b85610e84565b503d610f3a565b346102655760608060031936011261026557610f7d613242565b610f85613258565b60655460405163c4aa304160e01b8152602094926001600160a01b03928316929091908682600481875afa8015610490578692600091611160575b50811633149081156110e3575b5090610fef93610fdf610fe493613f23565b615808565b602493843590615951565b9182600052606c808552604060002054610100908181116000146110db5750905b60015b8281111561101d57005b856000528187526040600020818403908482116110c6576110479161104191613107565b506143a7565b60a08101519060808101519060048210156110b157916110a791886110ac9594015115159060405192611079846131cf565b601784527f63616e63656c416c6c506f736974696f6e4f72646572730000000000000000008d850152613f96565b613645565b611013565b86634e487b7160e01b60005260216004526000fd5b85634e487b7160e01b60005260116004526000fd5b905090611010565b60405163477a86ef60e01b8152925090508682600481875afa8015610490578692600091611118575b50163314610fef610fcd565b809350888092503d8311611159575b6111318183613221565b8101031261026557610fef93610fdf879261114e610fe4956135e8565b92965092935061110c565b503d611127565b809350888092503d8311611192575b6111798183613221565b81010312610265578061118c87936135e8565b90610fc0565b503d61116f565b346102655760608060031936011261026557600435906001600160401b038083116102655736602384011215610265578260040135906111d88261337a565b926111e66040519485613221565b8284526020948585016024809560051b83010191368311610265578501905b8282106114f85750505082359082821161026557366023830112156102655781600401356112328161337a565b926112406040519485613221565b818452858885019260051b820101913683116102655786899201905b8382106114e9575050505060443592831161026557366023840112156102655782600401359261128b8461337a565b936112996040519586613221565b8085528583898701920283010191368311610265578601905b8282106114b057505060655460405162435da560e01b81526001600160a01b0392509088908290600490829086165afa801561049057889160009161147a575b508660405180948193637be53ca160e01b8352336004840152165afa801561049057600090611444575b6113269150613609565b845182518091149081611439575b50156113f55760005b8351811015610406576113508187613654565b51600290818110156110b15760c08984937f34277869391e6b06632d8da807f22afe881d4d09db9281cdee96b1070871908b936113906113f0978a613654565b519061139c878c613654565b51916113a782613286565b816000528552604060002091835192838155604087860151958660018401550151958691015560405195338752860152604085015288840152608083015260a0820152a1613645565b61133d565b60405162461bcd60e51b815260048101879052601a818601527f696e636f6e73697374656e7420706172616d73206c656e6774680000000000006044820152606490fd5b905083511487611334565b508681813d8311611473575b61145a8183613221565b810103126102655761146e611326916135fc565b61131c565b503d611450565b82819392503d83116114a9575b6114918183613221565b81010312610265576114a388916135e8565b896112f2565b503d611487565b8382360312610265578884916040516114c881613139565b843581528285013583820152604085013560408201528152019101906112b2565b8135815290820190820161125c565b81356002811015610265578152908701908701611205565b34610265576101e0602061152c6115263661329f565b906155e3565b604092919251928051845260018060a01b038382015116838501526040810151604085015261156360608201516060860190613072565b6080810151608085015260a081015160a085015260c081015160c085015260e081015160e0850152610100808201519085015261012080820151151590850152610140808201511515908501526101608082015190850152610180809101511515908401526115d76101a08401825161336d565b01516101c0820152f35b34610265576000366003190112610265576070546040516001600160a01b039091168152602090f35b346102655760203660031901126102655760043560005260696020526040600020805461026160018060a01b036001840154169260028101549060ff6003820154166004820154600583015460ff60068501541690600785015492600886015494600a6009880154970154976040519b8c9b8c613310565b3461026557602036600319011261026557600060a06040516116a38161316a565b8281528260208201528260408201528260608201528260808201520152600435600052607260205260c060406000206040516116de8161316a565b60018060a01b03825416918282526001810154602083019081526002820154604084019081526003830154916060850192835260a0600560048601549560808801968752015495019485526040519586525160208601525160408501525160608401525160808301525160a0820152f35b346102655760203660031901126102655760043560005260676020526040600020805461026160018060a01b036001840154169260028101549060ff6003820154166004820154600583015460ff60068501541690600785015492600886015494600a6009880154970154976040519b8c9b8c613310565b3461026557608036600319011261026557600435602435906004821015610265576117f0613258565b60655460405163c4aa304160e01b815260643594602093909290916001600160a01b0391821691908581600481865afa908115610490578691839160009161193b575b501633149283156118cf575b50505061184b90613f23565b1561189757806118745750606791600052526118706008604060002001918254613f03565b9055005b60011461187d57005b606991600052526118706008604060002001918254613f03565b6118b557606891600052526118706007604060002001918254613f03565b606a91600052526118706007604060002001918254613f03565b60405163477a86ef60e01b81529350839060049082905afa801561049057600090611905575b61184b925016331490848861183f565b508482813d8311611934575b61191b8183613221565b810103126102655761192f61184b926135e8565b6118f5565b503d611911565b928092508391503d831161196d575b6119548183613221565b81010312610265578161196787926135e8565b8a611833565b503d61194a565b34610265576119a661198536613267565b919060006040805161199681613139565b8281528260208201520152613286565b90600052602052606060406000206040516119c081613139565b815491828252604060026001830154926020850193845201549201918252604051928352516020830152516040820152f35b34610265576000366003190112610265577f0000000000000000000000007a02481c3bbe5780e0b044d98854ce9e774dd2816001600160a01b03163003611a4b5760206040516000805160206159ba8339815191528152f35b60405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608490fd5b604036600319011261026557611aca613242565b6024356001600160401b038111610265573660238201121561026557611afa9036906024816004013591016132d9565b906001600160a01b037f0000000000000000000000007a02481c3bbe5780e0b044d98854ce9e774dd2818116611b3230821415613391565b611b4f6000805160206159ba8339815191529183835416146133f2565b81606554169160405180936334cc866d60e21b825281600460209687935afa8015610490578291600091611db0575b50163303611d75577f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611bbd575050506104069150613453565b83929316906040516352d1902d60e01b81528481600481865afa60009181611d46575b50611c415760405162461bcd60e51b815260048101869052602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b03611cef57611c4f82613453565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590611ce7575b611c8557005b6000806104069460405194611c9986613139565b602786527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c81870152660819985a5b195960ca1b604087015281519101845af4611ce16134e3565b91613513565b506001611c7f565b60405162461bcd60e51b815260048101849052602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608490fd5b9091508581813d8311611d6e575b611d5e8183613221565b8101031261026557519087611be0565b503d611d54565b60405162461bcd60e51b8152600481018490526013602482015272556e617574686f72697a65642061636365737360681b6044820152606490fd5b809250858092503d8311611de1575b611dc98183613221565b8101031261026557611ddb82916135e8565b87611b7e565b503d611dbf565b3461026557611df63661329f565b60655460405163c4aa304160e01b81526001600160a01b039360209392851692918481600481875afa9081156104905785918791600091612072575b50163314938415611ffa575b5050611e4c611e5193613f23565b6153ab565b815160005260728352604060002060405190611e6c8261316a565b858154168252600181015485830152600281015480604084015260038201549081606085015260a06005600485015494608087019586520154940193845280611f77575b5050519485611eef575b607285855160005252610406604060002060056000918281558260018201558260028201558260038201558260048201550155565b848401511694604084015191519060c0850151151591868501519360405198611f178a6131a0565b8952878901526003604089015260006060890152608088015260a087015260c0860152600060e0860152600061010086015260006101208601526101408501525192600384101561077e57607293611f6e91614af1565b50838080611eba565b8787870151169160408701519160c0880151151591898801519360405195611f9e876131a0565b86528a8601526002604086015260006060860152608085015260a084015260c0830152600060e0830152600061010083015260006101208301526101408201528351600381101561077e57611ff291614af1565b508680611eb0565b60405163477a86ef60e01b81529450849060049082905afa8015610490578593600091612032575b5090921633149183611e51611e3e565b809450858092503d831161206b575b61204b8183613221565b8101031261026557611e4c85612063611e51956135e8565b915093612022565b503d612041565b928092508391503d83116120a4575b61208b8183613221565b81010312610265578561209e86926135e8565b88611e32565b503d612081565b34610265576120c36120bc36613267565b9190613286565b9060005260205260606040600020805490600260018201549101549060405192835260208301526040820152f35b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa80156104905782916000916121e0575b50163314928315612168575b60738361215186613f23565b600435600052606a8152610b436040600020614451565b60405163477a86ef60e01b81529193508290829060049082905afa908115610490576000916121a3575b506073926121519116331492612145565b90508181813d83116121d9575b6121ba8183613221565b81010312610265576073926121d1612151926135e8565b915092612192565b503d6121b0565b809250848092503d8311612211575b6121f98183613221565b810103126102655761220b82916135e8565b85612139565b503d6121ef565b346102655760208060031936011261026557600435600052606c815260406000209081546122458161337a565b906122536040519283613221565b8082528282018094600052836000206000915b8383106122fd5760408051878152865181890181905289928201908960005b8281106122925784840385f35b9091928260e06001928851848060a01b03815116825283810151848301526040810151151560408301526060808201511515908301526122da60808083015190840190613072565b60a0808201519083015260c0809101519082015201960191019492919094612285565b60058660019261230c856143a7565b815201920192019190612266565b34610265576020366003190112610265576004356000526073602052602060ff604060002054166040519015158152f35b34610265576020806003193601126102655760655460405163c4aa304160e01b81526001600160a01b039182169291908281600481875afa801561049057829160009161243a575b501633149283156123c2575b6073836123ab86613f23565b60043560005260678152610b43604060002061440f565b60405163477a86ef60e01b81529193508290829060049082905afa908115610490576000916123fd575b506073926123ab911633149261239f565b90508181813d8311612433575b6124148183613221565b810103126102655760739261242b6123ab926135e8565b9150926123ec565b503d61240a565b809250848092503d831161246b575b6124538183613221565b810103126102655761246582916135e8565b85612393565b503d612449565b34610265576020806003193601126102655761248c613242565b6001600160a01b03917f0000000000000000000000007a02481c3bbe5780e0b044d98854ce9e774dd28183166124c430821415613391565b6124e16000805160206159ba8339815191529185835416146133f2565b6004828560655416604051928380926334cc866d60e21b82525afa8015610490578591600091612695575b5016330361265a576040519361252185613206565b600085527f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561255c575050506104069150613453565b83929316906040516352d1902d60e01b81528481600481865afa6000918161262b575b506125e05760405162461bcd60e51b815260048101869052602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b03611cef576125ee82613453565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a282511580159061262357611c8557005b506000611c7f565b9091508581813d8311612653575b6126438183613221565b810103126102655751908761257f565b503d612639565b60405162461bcd60e51b8152600481018390526013602482015272556e617574686f72697a65642061636365737360681b6044820152606490fd5b809250848092503d83116126c6575b6126ae8183613221565b81010312610265576126c085916135e8565b8661250c565b503d6126a4565b346102655760e0366003190112610265576040516126ea81613185565b6126f2613242565b815260209060243582820152612706613258565b60408201526064358015158103610265576060820152608435600481101561026557608082015260a43560a082015260c43560c082015260655460405163c4aa304160e01b81526001600160a01b0391821693908181600481885afa801561049057839160009161280d575b50163314938415612790575b6104068461278b87613f23565b61523e565b81929450906004916040519283809263477a86ef60e01b82525afa918215610490576000926127ce575b50506104069261278b91163314928461277e565b90809250813d8311612806575b6127e58183613221565b8101031261026557610406926127fd61278b926135e8565b918194506127ba565b503d6127db565b809250838092503d831161283e575b6128268183613221565b810103126102655761283883916135e8565b86612772565b503d61281c565b600319602036820112610265576001600160401b03600435116102655761012090600435360301126102655733600052607460205260ff6040600020541615612e6a57602460043501356004811015610265576128a890600435600401356153ab565b5060018060a01b0360208201511690604060e08201519101519060206128d961010460043501600435600401613785565b908092918101031261026557356001600160a01b03811690819003610265578303612e37576065546129159084906001600160a01b0316615808565b6001600160801b0361292b606460043501613eef565b1681101580612e17575b15612ddd576000906001600160801b03612953606460043501613eef565b16612dd4575b6001600160801b0361296f60a460043501613eef565b16612daa575b606f54604051632f7ce47360e21b815260048101859052906001600160a01b031661016082602481845afa91821561049057600092612d77575b5060c4600435013560038110156102655760018103612c185750505060008381527f136eb4aae73f7618d8559a84c5ff3678edc6b16994db052447ebc43c429b7d6f60205260409081902090519190612a0783613139565b80548352612a36612a2e856002600185015494602088019586520154806040880152613f10565b948451613f10565b9251612b66575b505050506000805160206159da833981519152916001600160801b0360e0925b81612a6c606460043501613eef565b6044600435013590612a8260a460043501613eef565b6005608460043501359260405192612a998461316a565b8984526020840191600435600401358352876040860191168152606085019087825288608087019316835260a086019387855260043560040135600052607260205260406000209660018060a01b039051166001600160601b0360a01b88541617875551600187015551600286015551600385015551600484015551910155612b26606460043501613eef565b91612b3560a460043501613eef565b946040519788526004356004013560208901526040880152606087015260808601521660a08401521660c0820152a1005b51119081159283612c0e575b508215612bf3575b5050612bd6576000805160206159da833981519152916001600160801b0360e092612bce600080808060018060a01b03606f541681604051612bbb81613206565b5234905af1612bc86134e3565b506137b7565b928294612a3d565b60405162461bcd60e51b815280612bef6004820161374d565b0390fd5b90915081612c04575b508380612b7a565b9050341083612bfc565b3410925085612b72565b949594919390929091600214612c4d575b5050505060e0906001600160801b036000805160206159da83398151915293612a5d565b60008681527f44e4f44bb0aae4b5d1e07207f82567d4201c1d09f6b5859dddcfb50647f55a7060205260409081902090519190612cb990612cb1908590600290612c9687613139565b80548752600181015460208801520154806040870152613f10565b938351613f10565b918051612cc8575b5050612c29565b6020909695960151119081159283612d67575b508215612d46575b5050612bd6576040909201516000805160206159da8339815191529360e0936001600160801b0392612d3c91906001600160a01b0316612d2c6004803561010481019101613785565b92909160e4600435013590614499565b9382938680612cc1565b90915081612d57575b508580612ce3565b905060e460043501351085612d4f565b60043560e4013510925087612cdb565b612d9c9192506101603d61016011612da3575b612d948183613221565b8101906136aa565b90866129af565b503d612d8a565b90600181018111612dbe5760010190612975565b634e487b7160e01b600052601160045260246000fd5b60019150612959565b60405162461bcd60e51b815260206004820152601260248201527165786365656473206f726465722073697a6560701b6044820152606490fd5b506001600160801b03612e2e60a460043501613eef565b16811015612935565b60405162461bcd60e51b815260206004820152600b60248201526a1b9bdd08185b1b1bddd95960aa1b6044820152606490fd5b60405162461bcd60e51b815260206004820152600a60248201526937b7363ca937baba32b960b11b6044820152606490fd5b3461026557602036600319011261026557600435600052607260205260c0604060002060018060a01b038154169060018101549060028101546003820154906005600484015493015493604051958652602086015260408501526060840152608083015260a0820152f35b34610265576000366003190112610265576065546040516001600160a01b039091168152602090f35b3461026557600036600319011261026557606f546040516001600160a01b039091168152602090f35b3461026557612f67366130f1565b90600052606c602052604060002080548210156102655760e091612f8a91613107565b5060018060a01b0381541690600181015490612fe360028201546004600384015493015493604051958652602086015260ff81161515604086015260ff8160081c161515606086015260ff608086019160101c16613072565b60a083015260c0820152f35b3461026557602036600319011261026557600435600052606a60205280610261604060002080549060018060a01b0360018201541684600283015460ff6003850154166004850154600586015460068701549160078801549360088901549560098a01549860ff600b600a8d01549c0154169b60ff808c60081c169b169961307f565b90600482101561077e5752565b9b99979593919d9c9a98969492909d6101a08d019e8d52600160a01b600190031660208d015260408c015260608b016130b791613072565b60808a015260a089015260c088015260e0870152610100860152151561012085015215156101408401526101608301521515906101800152565b6040906003190112610265576004359060243590565b8054821015613123576000526005602060002091020190600090565b634e487b7160e01b600052603260045260246000fd5b606081019081106001600160401b0382111761315457604052565b634e487b7160e01b600052604160045260246000fd5b60c081019081106001600160401b0382111761315457604052565b60e081019081106001600160401b0382111761315457604052565b61016081019081106001600160401b0382111761315457604052565b6001600160401b03811161315457604052565b604081019081106001600160401b0382111761315457604052565b6101a081019081106001600160401b0382111761315457604052565b602081019081106001600160401b0382111761315457604052565b90601f801991011681019081106001600160401b0382111761315457604052565b600435906001600160a01b038216820361026557565b60443590811515820361026557565b6040906003190112610265576004356002811015610265579060243590565b600281101561077e57600052606e602052604060002090565b6040906003190112610265576004359060243560048110156102655790565b6001600160401b03811161315457601f01601f191660200190565b9291926132e5826132be565b916132f36040519384613221565b829481845281830111610265578281602093846000960137010152565b97949193610140999693613347929d9c9b98956101608b019e8b5260018060a01b031660208b015260408a01526060890190613072565b608087015260a0860152151560c085015260e08401526101008301526101208201520152565b90600382101561077e5752565b6001600160401b0381116131545760051b60200190565b1561339857565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b19195b1959d85d1958d85b1b60a21b6064820152608490fd5b156133f957565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b6163746976652070726f787960a01b6064820152608490fd5b803b15613488576000805160206159ba83398151915280546001600160a01b0319166001600160a01b03909216919091179055565b60405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b3d1561350e573d906134f4826132be565b916135026040519384613221565b82523d6000602084013e565b606090565b919290156135755750815115613527575090565b3b156135305790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156135885750805190602001fd5b60405162461bcd60e51b815260206004820152908190612bef9060248301905b919082519283825260005b8481106135d4575050826000602080949584010152601f8019910116010190565b6020818301810151848301820152016135b3565b51906001600160a01b038216820361026557565b5190811515820361026557565b1561361057565b60405162461bcd60e51b815260206004820152600d60248201526c37b7363ca837b7b620b236b4b760991b6044820152606490fd5b6000198114612dbe5760010190565b80518210156131235760209160051b010190565b1561366f57565b60405162461bcd60e51b815260206004820152601360248201527237b7363ca2bc32b1baba37b9132937baba32b960691b6044820152606490fd5b908161016091031261026557604051906136c3826131a0565b805182526136d3602082016135e8565b60208301526136e4604082016135e8565b60408301526136f5606082016135e8565b6060830152613706608082016135fc565b608083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140809101519082015290565b60609060208152601860208201527f696e73756666696369656e74206e6574776f726b20666565000000000000000060408201520190565b903590601e198136030182121561026557018035906001600160401b0382116102655760200191813603831361026557565b156137be57565b60405162461bcd60e51b81526020600482015260136024820152721d1c985b9cd9995c88195d1a0819985a5b1959606a1b6044820152606490fd5b3580151581036102655790565b600482101561077e5752565b6001600160a01b038135818116929083810361026557613836908360655416615808565b81606f5416906040928351632f7ce47360e21b8152602090818401356004968188840152610160602493818186818c5afa908115613ee457600091613ec7575b506080928382015115613e9b5761012097888a01359b60038d10159b8c610265578d9060018203613d8c57505060008052606e8952826000208760005289528260002083516138c481613139565b8a8d60028454948585526001810154938501938452015493878401948552613cf5575b505050505b828b0135938185101592836102655785158015613ce7575b613b63575b8c6060810135978660008a13613b2d575b505060e001359991505060008913156139c05750506102655761393f60a08a016137f9565b9461394c60c08b016137f9565b9661395690615921565b9782519d8e613964816131a0565b528d01528b019061397491613806565b60608a01528086013590890152151560a0880152151560c087015260e086015261010080830135908601528401600090526101408091013590840152610265576139bd916146e1565b90565b60008994989912600014613a5e575050610265576139dd90615921565b936139ea60a08a016137f9565b956139f760c08b016137f9565b9782519d8e613a05816131a0565b528d01528b0190613a1591613806565b60608a0152808601359089015260a0880152151560c0870152151560e086015261010080830135908601528401600090526101408091013590840152610265576139bd91614af1565b909192508499989796939915613af557505061026557600096613aae91613a8760a08b016137f9565b95613a9460c08c016137f9565b9782519e8f90613aa3826131a0565b815201528c01613806565b60608a01528086013590890152151560a0880152151560c08701528160e087015261010080840135908701528501526101408091013590840152610265576139bd916146e1565b835162461bcd60e51b81529182018890526013908201527218dbdb1b185d195c985b081c995c5d5a5c9959606a1b6044820152606490fd5b83613b5191613b599601511692613b438b615921565b94606f541692810190613785565b939092614499565b38808c818661391a565b80606f5416855180916330a66e1560e01b82528b86830152818d6101009384935afa918215613cdc57908f91600093613c39575b505060e001356000811215613bae575b5050613909565b8015918215613bfd575b505015613bc6573880613ba7565b845162461bcd60e51b81528084018c90526012818c015271696e76616c69642074726164652073697a6560701b6044820152606490fd5b909150613c0982615921565b8782015111159182613c1f575b50503880613bb8565b6060919250613c2d90615921565b91015110153880613c16565b9150918282813d8311613cd5575b613c518183613221565b81010312613cd2578751928301908382106001600160401b03831117613cc057508752805182528c8101518d830152868101518783015260608082015190830152898101518a83015260a0808201519083015260c0808201519083015260e090810151818301528e9038613b97565b634e487b7160e01b8152604187528d90fd5b80fd5b503d613c47565b87513d6000823e3d90fd5b506000935060018614613904565b60e00135613d0281615921565b825111159384613d81575b508315613d57575b505050613d3e57613d35600080808086606f5416818951612bbb81613206565b3880808d6138e7565b825162461bcd60e51b8152908190612bef90820161374d565b613d6391929350615921565b9051119081613d76575b50388080613d15565b905051341038613d6d565b513410935038613d0d565b60009d5090600214613d9f575b506138ec565b60018d52606e8a52838d20888e528a52838d2084518b8e613dbf83613139565b60028454948585526001810154938501938452015493888401948552613de9575b50505050613d99565b60e081013590613df882615921565b835111159485613e88575b50508315613e59575b505050613e42576101408c613e3892858789015116613e2d8a840184613785565b949093013590614499565b388080808e613de0565b835162461bcd60e51b815280612bef81850161374d565b613e6591929350615921565b9051119081613e78575b50388080613e0c565b9050516101408d01351038613e6f565b5161014091909101351093508f38613e03565b5162461bcd60e51b8152808b0187905260088187015267191a5cd8589b195960c21b6044820152606490fd5b613ede9150823d8411612da357612d948183613221565b38613876565b83513d6000823e3d90fd5b356001600160801b03811681036102655790565b91908201809211612dbe57565b81810292918115918404141715612dbe57565b15613f2a57565b60405162461bcd60e51b815260206004820152600c60248201526b37b7363ca2bc32b1baba37b960a11b6044820152606490fd5b919360a0936139bd9695613f89938552600180871b0316602085015260408401526060830190613072565b81608082015201906135a8565b9293929091156141d157613faa82826153ab565b5060208082018051919492916001600160a01b039190821680156141c657613fd6908360655416615808565b8181511660409384810197885190610100830151156000906000146141c1575060808301515b60c08401511515926060850195865194600495868110156141ac57918b939161406295936140538a519160e08c0151938851986140388a613185565b868a52878c8b01528901526001606089015260808801613806565b60a086015260c0850152614fee565b83518281101561419757614168576073908351600052606781526140888860002061440f565b8351600052607281526140bc8860002060056000918281558260018201558260028201558260038201558260048201550155565b8351600052528560002060ff19815416905584845116915192519080821015614153575061414e96949286949261413c7f7e93a6b00cb3caacf000d7018943b12e2b4ad29e7849df14ebd51caf4fd739b8937f8e43c842a77ad600a970d5aded1e93f7f715700579caaaa9745b51d1d847558f9d9e995193849384614fc4565b0390a151169551905195869586613f5e565b0390a1565b602190634e487b7160e01b6000525260246000fd5b8351828110156141975790600160739203614088578351600052606981526141928860002061440f565b614088565b602183634e487b7160e01b6000525260246000fd5b602187634e487b7160e01b6000525260246000fd5b613ffc565b505050505050509050565b6141db82826155e3565b5060208082018051919492916001600160a01b039190821680156141c657614207908360655416615808565b818151166040938481019788519060e0830151156000906000146143a2575060808301515b6101208401511515926060850195865194600495868110156141ac57918b939161428495936140538a519160c08c0151938851986142698a613185565b868a52878c8b01528901526000606089015260808801613806565b8351828110156141975761435e576073908351600052606881526142aa88600020614451565b8351600052607281526142de8860002060056000918281558260018201558260028201558260038201558260048201550155565b8351600052528560002060ff19815416905584845116915192519080821015614153575061414e96949286949261413c7fb225fd6bcccad9342bc10ccc7e25ef77175b77348c8393d669ac2dbc98a1ae29937f8e43c842a77ad600a970d5aded1e93f7f715700579caaaa9745b51d1d847558f9d9e995193849384614fc4565b835182811015614197576073919060010361438d578351600052606a815261438888600020614451565b6142aa565b8351600052606a815261438888600020614451565b61422c565b906040516143b481613185565b60c06004829460018060a01b038154168452600181015460208501526143fe60ff600283015481811615156040880152818160081c161515606088015260101c1660808601613806565b600381015460a08501520154910152565b600a6000918281558260018201558260028201558260038201558260048201558260058201558260068201558260078201558260088201558260098201550155565b600b60009182815582600182015582600282015582600382015582600482015582600582015582600682015582600782015582600882015582600982015582600a8201550155565b90929360018060a01b038092169060409485516370a0823160e01b9485825260009616928360048301526020988983602481895afa92831561465757908a9594939291899361461f575b5083614582575b50506024916144f891613f03565b9487519485938492835260048301525afa9283156145775792614548575b5011614520575050565b60649250519062461bcd60e51b825260048201526002602482015261746360f01b6044820152fd5b9091508381813d8311614570575b6145608183613221565b8101031261026557519038614516565b503d614556565b8451903d90823e3d90fd5b909192939450333b1561461b578160a489928b5194859384926316e95edb60e31b84528b60048501528960248501528a604485015260806064850152816084850152848401378181018301859052601f01601f1916810103018183335af18015614611579089949392916145f7575b806144ea565b916144f891976146086024946131bc565b979150916145f1565b88513d89823e3d90fd5b8780fd5b8092935086919495963d8311614650575b61463a8183613221565b8101031261461b579089949392915191386144e3565b503d614630565b89513d8a823e3d90fd5b600382101561077e5752565b90600481101561077e5760ff80198354169116179055565b9692936146b961012099956146d797939d9c9b98946101408b019e60018060a01b03168b5260208b015260408a0190613072565b6060880152608087015260a086015260c085015260e084019061336d565b6101008201520152565b906066549160018060a01b038151169260208201516040830151600481101561077e576060840151608085015160a086015115159161474960e088015194610100890151966040519b6147338d6131a0565b898d5260208d015260408c015260608b01613806565b608089015260a088015260c087015260e08601526000610100860152610120850152610140904282860152818301519060405191614786836131cf565b6147908684614661565b6020830152600052606b6020526040600020908051600381101561077e5760019160209160ff8019865416911617845501519101556040820151600481101561077e576149e65760665460005260676020526040600020845181556001810160018060a01b036020870151166001600160601b0360a01b825416179055604085015160028201556060850151600481101561077e57614832906003830161466d565b6080850151600482015560a0850151600582015561486560c08601511515600683019060ff801983541691151516179055565b60e0850151600782015561010085015160088201556101208501516009820155600a828601519101555b60c08201511515806149bb575b506148a8606654613645565b6066556020840151604085015160c08601516060870151926001600160a01b031691901515600484101561077e5761490f61491e9489519260e08b015194604051966148f388613185565b8752602087015260408601526001606086015260808501613806565b60a083015260c08201526151aa565b60018060a01b0360208501511690845192604081015190600482101561077e577f459f5f85edf43d324c3891f0b72d72000cce329562b08f262e06121652c8800d956149b49360608301516020840151608085015191600160e087015194870151966149a261499a60c060a084015115159301511515926157f4565b831b916157f4565b60021b1717966040519a8b9a8b614685565b0390a15190565b6149e090606654600052607360205260406000209060ff801983541691151516179055565b3861489c565b6040820151600481101561077e57600103614ab75760665460005260696020526040600020845181556001810160018060a01b036020870151166001600160601b0360a01b825416179055604085015160028201556060850151600481101561077e57614a56906003830161466d565b6080850151600482015560a08501516005820155614a8960c08601511515600683019060ff801983541691151516179055565b60e0850151600782015561010085015160088201556101208501516009820155600a8286015191015561488f565b60405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207472616465207479706560701b6044820152606490fd5b6066549160018060a01b038251169260208301516040840151600481101561077e576060850151608086015160a087015191614b426101008901519460c08a01511515966040519b6147338d6131ea565b608089015260a088015260c0870152600060e087015261010086015261012085015260006101408501524261016085015260006101808501526101408301519060405191614b8f836131cf565b614b998484614661565b6020830152600052606b6020526040600020908051600381101561077e5760019160209160ff8019865416911617845501519101556040820151600481101561077e57614e3e5760c0820151151561014084015260665460005260686020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ce7926003830161466d565b6080850151600482015560a0850151600582015560c0850151600682015560e085015160078201556101008501516008820155614cbf60098201614ca36101208801511515829060ff801983541691151516179055565b610140870151815461ff00191690151560081b61ff0016179055565b610160850151600a820155600b610180860151151591019060ff801983541691151516179055565b60e0820151151580614e13575b50614d00606654613645565b606655602083015160408401516101208501516060860151926001600160a01b031691901515600484101561077e5761490f614d689488519260c08a01519460405196614d4c88613185565b8752602087015260408601526000606086015260808501613806565b60018060a01b036020840151168351916040840151600481101561077e57846149b49260607f459f5f85edf43d324c3891f0b72d72000cce329562b08f262e06121652c8800d970151602083015160808401519060a08501519261014086015195614e028d614df8614def61014060e060c0870151151596015115159301511515946157f4565b60011b916157f4565b60021b17916157f4565b60031b17966040519a8b9a8b614685565b614e3890606654600052607360205260406000209060ff801983541691151516179055565b38614cf4565b6040820151600481101561077e57600103614ec35760c082015115610140840152606654600052606a6020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ebe926003830161466d565b614ce7565b6040820151600481101561077e57600203614f435760c082015115610140840152606654600052606a6020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ebe926003830161466d565b6040820151600481101561077e57600303614ab75760c08201511515610140840152606654600052606a6020526040600020835181556001810160018060a01b036020860151166001600160601b0360a01b82541617905560408401516002820155606084015190600482101561077e57614c4c614ebe926003830161466d565b6001600160a01b0390911681526020810191909152606081019291614fec9160400190613072565b565b92614ffb9092919261523e565b60009182821361500c575b50505050565b606f54604051632f7ce47360e21b8152600481018390526001600160a01b039182169190610160908181602481875afa9182156150e95761505e9284926040928a926150cc575b505001511694615921565b90823b156150c857608492869594928692604051998a978896634f7a10db60e11b88526004880152602487015216604485015260648401525af19081156150bc57506150ad575b808080615006565b6150b6906131bc565b386150a5565b604051903d90823e3d90fd5b8580fd5b6150e29250803d10612da357612d948183613221565b3880615053565b6040513d89823e3d90fd5b91906151945760018060a01b038151166001600160601b0360a01b83541617825560208101516001830155600282019061514060408201511515839060ff801983541691151516179055565b6060810151825461ff00191690151560081b61ff0016178255608081015190600482101561077e578260c09262ff0000600495549160101b169062ff0000191617905560a081015160038501550151910155565b634e487b7160e01b600052600060045260246000fd5b8051602082015160408301516151cd9290151591906001600160a01b0316615951565b600090808252606c6020526040822054606d6020526040832060a0850151845260205260408320558152606c60205260408120805491600160401b83101561522a575081615224916001614fec9594018155613107565b906150f4565b634e487b7160e01b81526041600452602490fd5b8051602080830151604080850151929493909261526792901515916001600160a01b0316615951565b92600093808552606d825260a08386209401938451865282528285205493818652606c8352838620549460001995868101908111615397578110615324575b5090606c9291818752606d83528487209051875282528584812055855252822090815480156153105701916152db8383613107565b6152fc57808260049255826001820155826002820155826003820155015555565b634e487b7160e01b82526004829052602482fd5b634e487b7160e01b84526031600452602484fd5b828752606c845284872080549087820191821161538357611041606c969594939261534e92613107565b83895285855261536481615224848a8d20613107565b838952606d855260a0878a2091015189528452858820559091926152a6565b634e487b7160e01b89526011600452602489fd5b634e487b7160e01b88526011600452602488fd5b9190916040908151906153bd826131a0565b600094858352602092868482015286858201528660608201528660808201528660a08201528660c08201528660e08201526101009187838301526101209088828401526101409289848201525088868851615417816131cf565b828152015260048110156155cf578693929190806154ef5750600a906001958a5260678752848a209085519461544c866131a0565b82548652878060a01b0388840154168987015260028301548787015261547c60ff60038501541660608801613806565b60048301546080870152600583015460a087015260ff600684015416151560c0870152600783015460e0870152600883015490860152600982015490850152015490820152955b86518152606b8452209251926154d8846131cf565b6154e660ff82541685614661565b01549082015290565b9294919350916001036155965791600a6001949287948a5260698752848a209085519461551b866131a0565b82548652878060a01b0388840154168987015260028301548787015261554b60ff60038501541660608801613806565b60048301546080870152600583015460a087015260ff600684015416151560c0870152600783015460e0870152600883015490860152600982015490850152015490820152956154c3565b855162461bcd60e51b8152602060048201526012602482015271696e76616c6964207472616465207479706560701b6044820152606490fd5b634e487b7160e01b89526021600452602489fd5b9190916040908151936155f5856131ea565b600094858152602092868483015286858301528660608301528660808301528660a08301528660c08301528660e0830152610100928784840152610120918883850152610140908982860152610160928a848701528a610180809701528a888a5161565f816131cf565b828152015260048110156157e0579388959360ff9384888e600b9660019c9a1560001461573b57815260688d52209389519861569a8a6131ea565b85548a528b8060a01b038c870154168d8b015260028601548b8b01526156c98360038801541660608c01613806565b600486015460808b0152600586015460a08b0152600686015460c08b0152600786015460e08b01526008860154908a01526009850154908282161515908a015260081c16151590870152600a820154908601520154161515908201529586518152606b8452209251926154d8846131cf565b8152606a8d52209389519861574f8a6131ea565b85548a528b8060a01b038c870154168d8b015260028601548b8b015261577e8360038801541660608c01613806565b600486015460808b0152600586015460a08b0152600686015460c08b0152600786015460e08b01526008860154908a01526009850154908282161515908a015260081c16151590870152600a82015490860152015416151590820152956154c3565b634e487b7160e01b8b52602160045260248bfd5b600090156158025750600190565b60ff1690565b60405162435da560e01b8152602092916001600160a01b039084908390600490829085165afa9283156104905784926000946158e4575b5060405163b36d691960e01b815290821660048201529283916024918391165afa908115610490576000916158af575b506158775750565b6064906040519062461bcd60e51b825260048201526011602482015270189b1858dadb1a5cdd081858d8dbdd5b9d607a1b6044820152fd5b908282813d83116158dd575b6158c58183613221565b81010312613cd257506158d7906135fc565b3861586f565b503d6158bb565b919282819592953d831161591a575b6158fd8183613221565b81010312613cd2575090602461591385936135e8565b939061583f565b503d6158f3565b600080821261592e575090565b600160ff1b821461593d570390565b634e487b7160e01b81526011600452602490fd5b9091600160401b83101561598e5760009015615986575060ff60015b169160201b906001600160601b03199060601b16171790565b60ff9061596d565b60405162461bcd60e51b81526020600482015260036024820152621c1d1b60ea1b6044820152606490fdfe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbce826d5cd45302da284a0b7a10ef98a9de0284a6cda62ec6d24a0247c7d11ccffa26469706673582212207acb45c3c729754d4bf30b13ad4b45abf098cc83ef71cd8cfcf2fff517ceb58764736f6c63430008130033

Block Transaction Gas Used Reward
view all blocks sequenced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ 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.