Contract 0xAE5b86c0c4415a61dc1f6E7b2305Ad4ad0fCA22F

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x9d80957135c44c921f941b90e664dcd9954fde80e31eb60c4b1d9e304f40b6150x613f326142746042022-08-22 6:28:49584 days 1 hr ago0x06da697e5953b22960210a683f148c418dff6969 IN  Create: OpenLevV1Lib0 CRO17.5013457838420
[ Download CSV Export 
Parent Txn Hash Block From To Value
Index Block
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OpenLevV1Lib

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 19 : OpenLevV1Lib.sol
pragma solidity 0.7.6;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./OpenLevInterface.sol";
import "./Adminable.sol";
import "./XOLEInterface.sol";
import "./IWETH.sol";

pragma experimental ABIEncoderV2;


library OpenLevV1Lib {
    using SafeMath for uint;
    using TransferHelper for IERC20;
    using DexData for bytes;

    struct PricesVar {
        uint current;
        uint cAvg;
        uint hAvg;
        uint price;
        uint cAvgPrice;
    }

    function addMarket(
        LPoolInterface pool0,
        LPoolInterface pool1,
        uint16 marginLimit,
        bytes memory dexData,
        uint16 marketId,
        mapping(uint16 => Types.Market) storage markets,
        OpenLevStorage.CalculateConfig storage config,
        OpenLevStorage.AddressConfig storage addressConfig,
        mapping(uint8 => bool) storage _supportDexs,
        mapping(uint16 => mapping(address => mapping(uint => uint24))) storage taxes
    ) external {
        address token0 = pool0.underlying();
        address token1 = pool1.underlying(); 
        uint8 dex = dexData.toDex();
        require(isSupportDex(_supportDexs, dex) && msg.sender == address(addressConfig.controller) && marginLimit >= config.defaultMarginLimit && marginLimit < 100000, "UDX");

        {
            uint24[] memory taxRates = dexData.toTransferFeeRates();
            require(taxRates[0] < 200000 && taxRates[1] < 200000 && taxRates[2] < 200000 && taxRates[3] < 200000 &&taxRates[4] < 200000 && taxRates[5] < 200000, "WTR" );
            taxes[marketId][token0][0]= taxRates[0];
            taxes[marketId][token1][0]= taxRates[1];
            taxes[marketId][token0][1]= taxRates[2];
            taxes[marketId][token1][1]= taxRates[3];
            taxes[marketId][token0][2]= taxRates[4];
            taxes[marketId][token1][2]= taxRates[5];
        }

        // Approve the max number for pools
        IERC20(token0).safeApprove(address(pool0), uint256(- 1));
        IERC20(token1).safeApprove(address(pool1), uint256(- 1));
        //Create Market
        uint32[] memory dexs = new uint32[](1);
        dexs[0] = dexData.toDexDetail();
        markets[marketId] = Types.Market(pool0, pool1, token0, token1, marginLimit, config.defaultFeesRate, config.priceDiffientRatio, address(0), 0, 0, dexs);
        // Init price oracle
        if (dexData.isUniV2Class()) {
            updatePriceInternal(token0, token1, dexData);
        } else if (dex == DexData.DEX_UNIV3) {
            addressConfig.dexAggregator.updateV3Observation(token0, token1, dexData);
        }
    }

    function setCalculateConfigInternal(
        uint16 defaultFeesRate,
        uint8 insuranceRatio,
        uint16 defaultMarginLimit,
        uint16 priceDiffientRatio,
        uint16 updatePriceDiscount,
        uint16 feesDiscount,
        uint128 feesDiscountThreshold,
        uint16 penaltyRatio,
        uint8 maxLiquidationPriceDiffientRatio,
        uint16 twapDuration,
        OpenLevStorage.CalculateConfig storage calculateConfig
    ) external {
        require(defaultFeesRate < 10000 && insuranceRatio < 100 && defaultMarginLimit > 0 && updatePriceDiscount <= 100
        && feesDiscount <= 100 && penaltyRatio < 10000 && twapDuration > 0, 'PRI');
        calculateConfig.defaultFeesRate = defaultFeesRate;
        calculateConfig.insuranceRatio = insuranceRatio;
        calculateConfig.defaultMarginLimit = defaultMarginLimit;
        calculateConfig.priceDiffientRatio = priceDiffientRatio;
        calculateConfig.updatePriceDiscount = updatePriceDiscount;
        calculateConfig.feesDiscount = feesDiscount;
        calculateConfig.feesDiscountThreshold = feesDiscountThreshold;
        calculateConfig.penaltyRatio = penaltyRatio;
        calculateConfig.maxLiquidationPriceDiffientRatio = maxLiquidationPriceDiffientRatio;
        calculateConfig.twapDuration = twapDuration;
    }

    function setAddressConfigInternal(
        address controller,
        DexAggregatorInterface dexAggregator,
        OpenLevStorage.AddressConfig storage addressConfig
    ) external {
        require(controller != address(0) && address(dexAggregator) != address(0), 'CD0');
        addressConfig.controller = controller;
        addressConfig.dexAggregator = dexAggregator;
    }

    function setMarketConfigInternal(
        uint16 feesRate,
        uint16 marginLimit,
        uint16 priceDiffientRatio,
        uint32[] memory dexs,
        Types.Market storage market
    ) external {
        require(feesRate < 10000 && marginLimit > 0 && dexs.length > 0, 'PRI');
        market.feesRate = feesRate;
        market.marginLimit = marginLimit;
        market.dexs = dexs;
        market.priceDiffientRatio = priceDiffientRatio;
    }

    function marginRatio(
        address owner,
        uint held,
        address heldToken,
        address sellToken,
        LPoolInterface borrowPool,
        bytes memory dexData
    ) external view returns (uint, uint, uint, uint, uint){
        return marginRatioPrivate(owner, held, heldToken, sellToken, borrowPool, false, dexData);
    }

    function marginRatioPrivate(
        address owner,
        uint held,
        address heldToken,
        address sellToken,
        LPoolInterface borrowPool,
        bool isOpen,
        bytes memory dexData
    ) private view returns (uint, uint, uint, uint, uint){
        Types.MarginRatioVars memory ratioVars;
        ratioVars.held = held;
        ratioVars.dexData = dexData;
        ratioVars.heldToken = heldToken;
        ratioVars.sellToken = sellToken;
        ratioVars.owner = owner;
        ratioVars.multiplier = 10000;

        (DexAggregatorInterface dexAggregator,,,) = OpenLevStorage(address(this)).addressConfig();
        (,,,,,,,,,uint16 twapDuration) = OpenLevStorage(address(this)).calculateConfig();

        uint borrowed = isOpen ? borrowPool.borrowBalanceStored(ratioVars.owner) : borrowPool.borrowBalanceCurrent(ratioVars.owner);
        if (borrowed == 0) {
            return (ratioVars.multiplier, ratioVars.multiplier, ratioVars.multiplier, ratioVars.multiplier, ratioVars.multiplier);
        }
        (ratioVars.price, ratioVars.cAvgPrice, ratioVars.hAvgPrice, ratioVars.decimals, ratioVars.lastUpdateTime) = dexAggregator.getPriceCAvgPriceHAvgPrice(ratioVars.heldToken, ratioVars.sellToken, twapDuration, ratioVars.dexData);
        //Ignore hAvgPrice
        if (block.timestamp > ratioVars.lastUpdateTime.add(twapDuration)) {
            ratioVars.hAvgPrice = ratioVars.cAvgPrice;
        }
        //marginRatio=(marketValue-borrowed)/borrowed
        uint marketValue = ratioVars.held.mul(ratioVars.price).div(10 ** uint(ratioVars.decimals));
        uint current = marketValue >= borrowed ? marketValue.sub(borrowed).mul(ratioVars.multiplier).div(borrowed) : 0;
        marketValue = ratioVars.held.mul(ratioVars.cAvgPrice).div(10 ** uint(ratioVars.decimals));
        uint cAvg = marketValue >= borrowed ? marketValue.sub(borrowed).mul(ratioVars.multiplier).div(borrowed) : 0;
        marketValue = ratioVars.held.mul(ratioVars.hAvgPrice).div(10 ** uint(ratioVars.decimals));
        uint hAvg = marketValue >= borrowed ? marketValue.sub(borrowed).mul(ratioVars.multiplier).div(borrowed) : 0;
        return (current, cAvg, hAvg, ratioVars.price, ratioVars.cAvgPrice);
    }

    function isPositionHealthy(
        address owner,
        bool isOpen,
        uint amount,
        Types.MarketVars memory vars,
        bytes memory dexData
    ) external view returns (bool){
        PricesVar memory prices;
        (prices.current, prices.cAvg, prices.hAvg, prices.price, prices.cAvgPrice) = marginRatioPrivate(owner,
            amount,
            isOpen ? address(vars.buyToken) : address(vars.sellToken),
            isOpen ? address(vars.sellToken) : address(vars.buyToken),
            isOpen ? vars.sellPool : vars.buyPool,
            isOpen,
            dexData
        );

        (,,,,,,,,uint8 maxLiquidationPriceDiffientRatio,) = OpenLevStorage(address(this)).calculateConfig();
        if (isOpen) {
            return prices.current >= vars.marginLimit && prices.cAvg >= vars.marginLimit && prices.hAvg >= vars.marginLimit;
        } else {
            // Avoid flash loan
            if (prices.price < prices.cAvgPrice) {
                uint differencePriceRatio = prices.cAvgPrice.mul(100).div(prices.price);
                require(differencePriceRatio - 100 < maxLiquidationPriceDiffientRatio, 'MPT');
            }
            return prices.current >= vars.marginLimit || prices.cAvg >= vars.marginLimit || prices.hAvg >= vars.marginLimit;
        }
    }

    function updatePriceInternal(address token0, address token1, bytes memory dexData) internal returns (bool){
        (DexAggregatorInterface dexAggregator,,,) = OpenLevStorage(address(this)).addressConfig();
        (,,,,,,,,,uint16 twapDuration) = OpenLevStorage(address(this)).calculateConfig();
        return dexAggregator.updatePriceOracle(token0, token1, twapDuration, dexData);
    }

    function shouldUpdatePriceInternal(DexAggregatorInterface dexAggregator, uint16 twapDuration, uint16 priceDiffientRatio, address token0, address token1, bytes memory dexData) public view returns (bool){
        if (!dexData.isUniV2Class()) {
            return false;
        }
        (, uint cAvgPrice, uint hAvgPrice,, uint lastUpdateTime) = dexAggregator.getPriceCAvgPriceHAvgPrice(token0, token1, twapDuration, dexData);
        if (block.timestamp < lastUpdateTime.add(twapDuration)) {
            return false;
        }
        //Not initialized yet
        if (cAvgPrice == 0 || hAvgPrice == 0) {
            return true;
        }
        //price difference
        uint one = 100;
        uint differencePriceRatio = cAvgPrice.mul(one).div(hAvgPrice);
        if (differencePriceRatio >= (one.add(priceDiffientRatio)) || differencePriceRatio <= (one.sub(priceDiffientRatio))) {
            return true;
        }
        return false;
    }

    function updatePrice(uint16 marketId, Types.Market storage market, OpenLevStorage.AddressConfig storage addressConfig,
        OpenLevStorage.CalculateConfig storage calculateConfig, bytes memory dexData) external {
        bool shouldUpdate = shouldUpdatePriceInternal(addressConfig.dexAggregator, calculateConfig.twapDuration, market.priceDiffientRatio, market.token1, market.token0, dexData);
        bool updateResult = updatePriceInternal(market.token0, market.token1, dexData);
        if (updateResult) {
            //Discount
            market.priceUpdater = msg.sender;
            //Reward OLE
            if (shouldUpdate) {
                (ControllerInterface(addressConfig.controller)).updatePriceAllowed(marketId, msg.sender);
            }
        }
    }

    function transferIn(address from, IERC20 token, address weth, uint amount) external returns (uint) {
        if (address(token) == weth) {
            IWETH(weth).deposit{value : msg.value}();
            return msg.value;
        } else {
            return token.safeTransferFrom(from, address(this), amount);
        }
    }

    function doTransferOut(address to, IERC20 token, address weth, uint amount) external {
        if (address(token) == weth) {
            IWETH(weth).withdraw(amount);
            (bool success, ) = to.call{value: amount}("");
            require(success);
        } else {
            token.safeTransfer(to, amount);
        }
    }

    function isInSupportDex(uint32[] memory dexs, uint32 dex) internal pure returns (bool supported){
        for (uint i = 0; i < dexs.length; i++) {
            if (dexs[i] == 0) {
                break;
            }
            if (dexs[i] == dex) {
                supported = true;
                break;
            }
        }
    }

    function feeAndInsurance(
        address trader, 
        uint tradeSize, 
        address token, 
        address xOLE,
        uint totalHeld, 
        uint reserve,
        Types.Market storage  market, 
        mapping(address => uint) storage totalHelds,
        OpenLevStorage.CalculateConfig memory calculateConfig
    ) external returns (uint newFees) {
        uint defaultFees = tradeSize.mul(market.feesRate).div(10000);
        newFees = defaultFees;
        // if trader holds more xOLE, then should enjoy trading discount.
        if (XOLEInterface(xOLE).balanceOf(trader) > calculateConfig.feesDiscountThreshold) {
            newFees = defaultFees.sub(defaultFees.mul(calculateConfig.feesDiscount).div(100));
        }
        // if trader update price, then should enjoy trading discount.
        if (market.priceUpdater == trader) {
            newFees = newFees.sub(defaultFees.mul(calculateConfig.updatePriceDiscount).div(100));
        }
        uint newInsurance = newFees.mul(calculateConfig.insuranceRatio).div(100);
        IERC20(token).safeTransfer(xOLE, newFees.sub(newInsurance));

        newInsurance = OpenLevV1Lib.amountToShare(newInsurance, totalHeld, reserve);
        if (token == market.token1) {
            market.pool1Insurance = market.pool1Insurance.add(newInsurance);
        } else {
            market.pool0Insurance = market.pool0Insurance.add(newInsurance);
        }

        totalHelds[token] = totalHelds[token].add(newInsurance);
        return newFees;
    }

    function reduceInsurance(
        uint totalRepayment, 
        uint remaining, 
        bool longToken, 
        address token, 
        uint reserve, 
        Types.Market storage  market, 
        mapping(address => uint
    ) storage totalHelds) external returns (uint maxCanRepayAmount) {
        uint needed = totalRepayment.sub(remaining);
        needed = amountToShare(needed, totalHelds[token], reserve);
        maxCanRepayAmount = totalRepayment;
        if (longToken) {
            if (market.pool0Insurance >= needed) {
                market.pool0Insurance = market.pool0Insurance - needed;
                totalHelds[token] = totalHelds[token].sub(needed);
            } else {
                maxCanRepayAmount = shareToAmount(market.pool0Insurance, totalHelds[token], reserve);
                maxCanRepayAmount = maxCanRepayAmount.add(remaining);
                totalHelds[token] = totalHelds[token].sub(market.pool0Insurance);
                market.pool0Insurance = 0;
            }
        } else {
            if (market.pool1Insurance >= needed) {
                market.pool1Insurance = market.pool1Insurance - needed;
            } else {
                maxCanRepayAmount = shareToAmount(market.pool1Insurance, totalHelds[token], reserve);
                maxCanRepayAmount = maxCanRepayAmount.add(remaining);
                totalHelds[token] = totalHelds[token].sub(market.pool1Insurance);
                market.pool1Insurance = 0;
            }
        }
    }  

    function moveInsurance(Types.Market storage market, uint8 poolIndex, address to, uint amount,  mapping(address => uint) storage totalHelds) external{
        if (poolIndex == 0) {
            market.pool0Insurance = market.pool0Insurance.sub(amount);
            (IERC20(market.token0)).safeTransfer(to, shareToAmount(amount, totalHelds[market.token0], IERC20(market.token0).balanceOf(address(this))));
        }else{
            market.pool1Insurance = market.pool1Insurance.sub(amount);
            (IERC20(market.token1)).safeTransfer(to, shareToAmount(amount, totalHelds[market.token1], IERC20(market.token1).balanceOf(address(this))));
        }
    }

    function updateLegacy(address[] calldata tokens, mapping(address => uint) storage totalHelds) external{
        for(uint i; i < tokens.length; i++){
            address token = tokens[i];
            uint balance = IERC20(token).balanceOf(address(this));
            if (totalHelds[token] == 0 && balance > 0){
                totalHelds[token] = balance;
            }
        }
    }

    function isSupportDex(mapping(uint8 => bool) storage _supportDexs, uint8 dex) internal view returns (bool){
        return _supportDexs[dex];
    }

    function amountToShare(uint amount, uint totalShare, uint reserve) internal pure returns (uint share){
        share = totalShare > 0 && reserve > 0 ? totalShare.mul(amount) / reserve : amount;
    }

    function shareToAmount(uint share, uint totalShare, uint reserve) internal pure returns (uint amount){
        if (totalShare > 0 && reserve > 0){
            amount = reserve.mul(share) / totalShare;
        }
    }

    function verifyTrade(Types.MarketVars memory vars, bool longToken, bool depositToken, uint deposit, uint borrow, bytes memory dexData, OpenLevStorage.AddressConfig memory addressConfig, Types.Trade memory trade) external view {
        //verify if deposit token allowed
        address depositTokenAddr = depositToken == longToken ? address(vars.buyToken) : address(vars.sellToken);

        //verify minimal deposit > absolute value 0.0001
        uint decimals = ERC20(depositTokenAddr).decimals();
        uint minimalDeposit = decimals > 4 ? 10 ** (decimals - 4) : 1;
        uint actualDeposit = depositTokenAddr == addressConfig.wETH ? msg.value : deposit;
        require(actualDeposit > minimalDeposit, "DTS");
        require(isInSupportDex(vars.dexs, dexData.toDexDetail()), "DNS");

        // New trade
        if (trade.lastBlockNum == 0) {
            require(borrow > 0, "BB0");
            return;
        } else {
            // For new trade, these checks are not needed
            require(depositToken == trade.depositToken && trade.lastBlockNum != uint128(block.number), " DTS");
        }
    }
}

File 2 of 19 : LPoolInterface.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;


abstract contract LPoolStorage {

    //Guard variable for re-entrancy checks
    bool internal _notEntered;

    /**
     * EIP-20 token name for this token
     */
    string public name;

    /**
     * EIP-20 token symbol for this token
     */
    string public symbol;

    /**
     * EIP-20 token decimals for this token
     */
    uint8 public decimals;

    /**
    * Total number of tokens in circulation
    */
    uint public totalSupply;


    //Official record of token balances for each account
    mapping(address => uint) internal accountTokens;

    //Approved token transfer amounts on behalf of others
    mapping(address => mapping(address => uint)) internal transferAllowances;


    //Maximum borrow rate that can ever be applied (.0005% / block)
    uint internal constant borrowRateMaxMantissa = 0.0005e16;

    /**
    * Maximum fraction of borrower cap(80%)
    */
    uint public  borrowCapFactorMantissa;
    /**
     * Contract which oversees inter-lToken operations
     */
    address public controller;


    // Initial exchange rate used when minting the first lTokens (used when totalSupply = 0)
    uint internal initialExchangeRateMantissa;

    /**
     * Block number that interest was last accrued at
     */
    uint public accrualBlockNumber;

    /**
     * Accumulator of the total earned interest rate since the opening of the market
     */
    uint public borrowIndex;

    /**
     * Total amount of outstanding borrows of the underlying in this market
     */
    uint public totalBorrows;

    //useless
    uint internal totalCash;

    /**
    * @notice Fraction of interest currently set aside for reserves 20%
    */
    uint public reserveFactorMantissa;

    uint public totalReserves;

    address public underlying;

    bool public isWethPool;

    /**
     * Container for borrow balance information
     * principal Total balance (with accrued interest), after applying the most recent balance-changing action
     * interestIndex Global borrowIndex as of the most recent balance-changing action
     */
    struct BorrowSnapshot {
        uint principal;
        uint interestIndex;
    }

    uint256 public baseRatePerBlock;
    uint256 public multiplierPerBlock;
    uint256 public jumpMultiplierPerBlock;
    uint256 public kink;

    // Mapping of account addresses to outstanding borrow balances

    mapping(address => BorrowSnapshot) internal accountBorrows;


    /**
    * Block timestamp that interest was last accrued at
    */
    uint public accrualBlockTimestamp;



    /*** Token Events ***/

    /**
    * Event emitted when tokens are minted
    */
    event Mint(address minter, uint mintAmount, uint mintTokens);

    /**
     * EIP20 Transfer event
     */
    event Transfer(address indexed from, address indexed to, uint amount);

    /**
     * EIP20 Approval event
     */
    event Approval(address indexed owner, address indexed spender, uint amount);

    /*** Market Events ***/

    /**
     * Event emitted when interest is accrued
     */
    event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows);

    /**
     * Event emitted when tokens are redeemed
     */
    event Redeem(address redeemer, uint redeemAmount, uint redeemTokens);

    /**
     * Event emitted when underlying is borrowed
     */
    event Borrow(address borrower, address payee, uint borrowAmount, uint accountBorrows, uint totalBorrows);

    /**
     * Event emitted when a borrow is repaid
     */
    event RepayBorrow(address payer, address borrower, uint repayAmount, uint badDebtsAmount, uint accountBorrows, uint totalBorrows);

    /*** Admin Events ***/

    /**
     * Event emitted when controller is changed
     */
    event NewController(address oldController, address newController);

    /**
     * Event emitted when interestParam is changed
     */
    event NewInterestParam(uint baseRatePerBlock, uint multiplierPerBlock, uint jumpMultiplierPerBlock, uint kink);

    /**
    * @notice Event emitted when the reserve factor is changed
    */
    event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);

    /**
     * @notice Event emitted when the reserves are added
     */
    event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves);

    /**
     * @notice Event emitted when the reserves are reduced
     */
    event ReservesReduced(address to, uint reduceAmount, uint newTotalReserves);

    event NewBorrowCapFactorMantissa(uint oldBorrowCapFactorMantissa, uint newBorrowCapFactorMantissa);

}

abstract contract LPoolInterface is LPoolStorage {


    /*** User Interface ***/

    function transfer(address dst, uint amount) external virtual returns (bool);

    function transferFrom(address src, address dst, uint amount) external virtual returns (bool);

    function approve(address spender, uint amount) external virtual returns (bool);

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

    function balanceOf(address owner) external virtual view returns (uint);

    function balanceOfUnderlying(address owner) external virtual returns (uint);

    /*** Lender & Borrower Functions ***/

    function mint(uint mintAmount) external virtual;

    function mintTo(address to, uint amount) external payable virtual;

    function mintEth() external payable virtual;

    function redeem(uint redeemTokens) external virtual;

    function redeemUnderlying(uint redeemAmount) external virtual;

    function borrowBehalf(address borrower, uint borrowAmount) external virtual;

    function repayBorrowBehalf(address borrower, uint repayAmount) external virtual;

    function repayBorrowEndByOpenLev(address borrower, uint repayAmount) external virtual;

    function availableForBorrow() external view virtual returns (uint);

    function getAccountSnapshot(address account) external virtual view returns (uint, uint, uint);

    function borrowRatePerBlock() external virtual view returns (uint);

    function supplyRatePerBlock() external virtual view returns (uint);

    function totalBorrowsCurrent() external virtual view returns (uint);

    function borrowBalanceCurrent(address account) external virtual view returns (uint);

    function borrowBalanceStored(address account) external virtual view returns (uint);

    function exchangeRateCurrent() public virtual returns (uint);

    function exchangeRateStored() public virtual view returns (uint);

    function getCash() external view virtual returns (uint);

    function accrueInterest() public virtual;

    /*** Admin Functions ***/

    function setController(address newController) external virtual;

    function setBorrowCapFactorMantissa(uint newBorrowCapFactorMantissa) external virtual;

    function setInterestParams(uint baseRatePerBlock_, uint multiplierPerBlock_, uint jumpMultiplierPerBlock_, uint kink_) external virtual;

    function setReserveFactor(uint newReserveFactorMantissa) external virtual;

    function addReserves(uint addAmount) external payable virtual;

    function reduceReserves(address payable to, uint reduceAmount) external virtual;

}

File 3 of 19 : Utils.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.7.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";

library Utils{
    using SafeMath for uint;

    uint constant feeRatePrecision = 10**6;

    function toAmountBeforeTax(uint256 amount, uint24 feeRate) internal pure returns (uint){
        uint denominator = feeRatePrecision.sub(feeRate);
        uint numerator = amount.mul(feeRatePrecision).add(denominator).sub(1);
        return numerator / denominator;
    }

    function toAmountAfterTax(uint256 amount, uint24 feeRate) internal pure returns (uint){
        return amount.mul(feeRatePrecision.sub(feeRate)) / feeRatePrecision;
    }

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

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

File 4 of 19 : TransferHelper.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

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

/**
 * @title TransferHelper
 * @dev Wrappers around ERC20 operations that returns the value received by recipent and the actual allowance of approval.
 * To use this library you can add a `using TransferHelper for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
 library TransferHelper{
    // using SafeMath for uint;

    function safeTransfer(IERC20 _token, address _to, uint _amount) internal returns (uint amountReceived){
        if (_amount > 0){
            uint balanceBefore = _token.balanceOf(_to);
            address(_token).call(abi.encodeWithSelector(_token.transfer.selector, _to, _amount));
            uint balanceAfter = _token.balanceOf(_to);
            require(balanceAfter > balanceBefore, "TF");
            amountReceived = balanceAfter - balanceBefore;
        }
    }

    function safeTransferFrom(IERC20 _token, address _from, address _to, uint _amount) internal returns (uint amountReceived){
        if (_amount > 0){
            uint balanceBefore = _token.balanceOf(_to);
            address(_token).call(abi.encodeWithSelector(_token.transferFrom.selector, _from, _to, _amount));
            // _token.transferFrom(_from, _to, _amount);
            uint balanceAfter = _token.balanceOf(_to);
            require(balanceAfter > balanceBefore, "TFF");
            amountReceived = balanceAfter - balanceBefore;
        }
    }

    function safeApprove(IERC20 _token, address _spender, uint256 _amount) internal returns (uint) {
        bool success;
        if (_token.allowance(address(this), _spender) != 0){
            (success, ) = address(_token).call(abi.encodeWithSelector(_token.approve.selector, _spender, 0));
            require(success, "AF");
        }
        (success, ) = address(_token).call(abi.encodeWithSelector(_token.approve.selector, _spender, _amount));
        require(success, "AF");

        return _token.allowance(address(this), _spender);
    }

    // function safeIncreaseAllowance(IERC20 _token, address _spender, uint256 _amount) internal returns (uint) {
    //     uint256 allowanceBefore = _token.allowance(address(this), _spender);
    //     uint256 allowanceNew = allowanceBefore.add(_amount);
    //     uint256 allowanceAfter = safeApprove(_token, _spender, allowanceNew);
    //     require(allowanceAfter == allowanceNew, "AF");
    //     return allowanceNew;
    // }

    // function safeDecreaseAllowance(IERC20 _token, address _spender, uint256 _amount) internal returns (uint) {
    //     uint256 allowanceBefore = _token.allowance(address(this), _spender);
    //     uint256 allowanceNew = allowanceBefore.sub(_amount);
    //     uint256 allowanceAfter = safeApprove(_token, _spender, allowanceNew);
    //     require(allowanceAfter == allowanceNew, "AF");
    //     return allowanceNew;
    // }
}

File 5 of 19 : DexData.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.7.6;
pragma experimental ABIEncoderV2;

/// @dev DexDataFormat addPair = byte(dexID) + bytes3(feeRate) + bytes(arrayLength) + byte3[arrayLength](trasferFeeRate Lpool <-> openlev) 
/// + byte3[arrayLength](transferFeeRate openLev -> Dex) + byte3[arrayLength](Dex -> transferFeeRate openLev)
/// exp: 0x0100000002011170000000011170000000011170000000
/// DexDataFormat dexdata = byte(dexID)+ bytes3(feeRate) + byte(arrayLength) + path
/// uniV2Path = bytes20[arraylength](address)
/// uniV3Path = bytes20(address)+ bytes20[arraylength-1](address + fee)
library DexData {
    // in byte
    uint constant DEX_INDEX = 0;
    uint constant FEE_INDEX = 1;
    uint constant ARRYLENTH_INDEX = 4;
    uint constant TRANSFERFEE_INDEX = 5;
    uint constant PATH_INDEX = 5;
    uint constant FEE_SIZE = 3;
    uint constant ADDRESS_SIZE = 20;
    uint constant NEXT_OFFSET = ADDRESS_SIZE + FEE_SIZE;

    uint8 constant DEX_UNIV2 = 1;
    uint8 constant DEX_UNIV3 = 2;
    uint8 constant DEX_PANCAKE = 3;
    uint8 constant DEX_SUSHI = 4;
    uint8 constant DEX_MDEX = 5;
    uint8 constant DEX_TRADERJOE = 6;
    uint8 constant DEX_SPOOKY = 7;
    uint8 constant DEX_QUICK = 8;
    uint8 constant DEX_SHIBA = 9;
    uint8 constant DEX_APE = 10;
    uint8 constant DEX_PANCAKEV1 = 11;
    uint8 constant DEX_BABY = 12;
    uint8 constant DEX_MOJITO = 13;
    uint8 constant DEX_KU = 14;
    uint8 constant DEX_BISWAP=15;
    uint8 constant DEX_VVS=20;

    struct V3PoolData {
        address tokenA;
        address tokenB;
        uint24 fee;
    }

    function toDex(bytes memory data) internal pure returns (uint8) {
        require(data.length >= FEE_INDEX, "DexData: toDex wrong data format");
        uint8 temp;
        assembly {
            temp := byte(0, mload(add(data, add(0x20, DEX_INDEX))))
        }
        return temp;
    }

    function toFee(bytes memory data) internal pure returns (uint24) {
        require(data.length >= ARRYLENTH_INDEX, "DexData: toFee wrong data format");
        uint temp;
        assembly {
            temp := mload(add(data, add(0x20, FEE_INDEX)))
        }
        return uint24(temp >> (256 - (ARRYLENTH_INDEX - FEE_INDEX) * 8));
    }

    function toDexDetail(bytes memory data) internal pure returns (uint32) {
        require (data.length >= FEE_INDEX, "DexData: toDexDetail wrong data format");
        if (isUniV2Class(data)){
            uint8 temp;
            assembly {
                temp := byte(0, mload(add(data, add(0x20, DEX_INDEX))))
            }
            return uint32(temp);
        } else {
            uint temp;
            assembly {
                temp := mload(add(data, add(0x20, DEX_INDEX)))
            }
            return uint32(temp >> (256 - ((FEE_SIZE + FEE_INDEX) * 8)));
        }
    }

    function toArrayLength(bytes memory data) internal pure returns(uint8 length){
        require(data.length >= TRANSFERFEE_INDEX, "DexData: toArrayLength wrong data format");

        assembly {
            length := byte(0, mload(add(data, add(0x20, ARRYLENTH_INDEX))))
        }
    }

    // only for add pair
    function toTransferFeeRates(bytes memory data) internal pure returns (uint24[] memory transferFeeRates){
        uint8 length = toArrayLength(data) * 3;
        uint start = TRANSFERFEE_INDEX;

        transferFeeRates = new uint24[](length);
        for (uint i = 0; i < length; i++){
            // use default value
            if (data.length <= start){
                transferFeeRates[i] = 0;
                continue;
            }

            // use input value
            uint temp;
            assembly {
                temp := mload(add(data, add(0x20, start)))
            }

            transferFeeRates[i] = uint24(temp >> (256 - FEE_SIZE * 8));
            start += FEE_SIZE;
        }
    }

    function toUniV2Path(bytes memory data) internal pure returns (address[] memory path) {
        uint8 length = toArrayLength(data);
        uint end =  PATH_INDEX + ADDRESS_SIZE * length;
        require(data.length >= end, "DexData: toUniV2Path wrong data format");

        uint start = PATH_INDEX;
        path = new address[](length);
        for (uint i = 0; i < length; i++) {
            uint startIndex = start + ADDRESS_SIZE * i;
            uint temp;
            assembly {
                temp := mload(add(data, add(0x20, startIndex)))
            }

            path[i] = address(temp >> (256 - ADDRESS_SIZE * 8));
        }
    }

    function isUniV2Class(bytes memory data) internal pure returns(bool){
        return toDex(data) != DEX_UNIV3;
    }

    function toUniV3Path(bytes memory data) internal pure returns (V3PoolData[] memory path) {
        uint8 length = toArrayLength(data);
        uint end = PATH_INDEX + (FEE_SIZE  + ADDRESS_SIZE) * length - FEE_SIZE;
        require(data.length >= end, "DexData: toUniV3Path wrong data format");
        require(length > 1, "DexData: toUniV3Path path too short");

        uint temp;
        uint index = PATH_INDEX;
        path = new V3PoolData[](length - 1);

        for (uint i = 0; i < length - 1; i++) {
            V3PoolData memory pool;

            // get tokenA
            if (i == 0) {
                assembly {
                    temp := mload(add(data, add(0x20, index)))
                }
                pool.tokenA = address(temp >> (256 - ADDRESS_SIZE * 8));
                index += ADDRESS_SIZE;
            }else{
                pool.tokenA = path[i-1].tokenB;
                index += NEXT_OFFSET;
            }

            // get TokenB
            assembly {
                temp := mload(add(data, add(0x20, index)))
            }

            uint tokenBAndFee = temp >> (256 - NEXT_OFFSET * 8);
            pool.tokenB = address(tokenBAndFee >> (FEE_SIZE * 8));
            pool.fee = uint24(tokenBAndFee - (tokenBAndFee << (FEE_SIZE * 8)));

            path[i] = pool;
        }
    }
}

File 6 of 19 : DexAggregatorInterface.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";

interface DexAggregatorInterface {

    function sell(address buyToken, address sellToken, uint sellAmount, uint minBuyAmount, bytes memory data) external returns (uint buyAmount);

    function sellMul(uint sellAmount, uint minBuyAmount, bytes memory data) external returns (uint buyAmount);

    function buy(address buyToken, address sellToken, uint24 buyTax, uint24 sellTax, uint buyAmount, uint maxSellAmount, bytes memory data) external returns (uint sellAmount);

    function calBuyAmount(address buyToken, address sellToken, uint24 buyTax, uint24 sellTax, uint sellAmount, bytes memory data) external view returns (uint);

    function calSellAmount(address buyToken, address sellToken, uint24 buyTax, uint24 sellTax, uint buyAmount, bytes memory data) external view returns (uint);

    function getPrice(address desToken, address quoteToken, bytes memory data) external view returns (uint256 price, uint8 decimals);

    function getAvgPrice(address desToken, address quoteToken, uint32 secondsAgo, bytes memory data) external view returns (uint256 price, uint8 decimals, uint256 timestamp);

    //cal current avg price and get history avg price
    function getPriceCAvgPriceHAvgPrice(address desToken, address quoteToken, uint32 secondsAgo, bytes memory dexData) external view returns (uint price, uint cAvgPrice, uint256 hAvgPrice, uint8 decimals, uint256 timestamp);

    function updatePriceOracle(address desToken, address quoteToken, uint32 timeWindow, bytes memory data) external returns(bool);

    function updateV3Observation(address desToken, address quoteToken, bytes memory data) external;

    function setDexInfo(uint8[] memory dexName, IUniswapV2Factory[] memory factoryAddr, uint16[] memory fees) external;
}

File 7 of 19 : XOLEInterface.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "./dex/DexAggregatorInterface.sol";


contract XOLEStorage {

    // EIP-20 token name for this token
    string public constant name = 'xOLE';

    // EIP-20 token symbol for this token
    string public constant symbol = 'xOLE';

    // EIP-20 token decimals for this token
    uint8 public constant decimals = 18;

    // Total number of tokens supply
    uint public totalSupply;

    // Total number of tokens locked
    uint public totalLocked;

    // Official record of token balances for each account
    mapping(address => uint) internal balances;

    mapping(address => LockedBalance) public locked;

    DexAggregatorInterface public dexAgg;

    IERC20 public oleToken;

    struct LockedBalance {
        uint256 amount;
        uint256 end;
    }

    uint constant oneWeekExtraRaise = 208;// 2.08% * 210 = 436% (4 years raise)

    int128 constant DEPOSIT_FOR_TYPE = 0;
    int128 constant CREATE_LOCK_TYPE = 1;
    int128 constant INCREASE_LOCK_AMOUNT = 2;
    int128 constant INCREASE_UNLOCK_TIME = 3;

    uint256 constant WEEK = 7 * 86400;  // all future times are rounded by week
    uint256 constant MAXTIME = 4 * 365 * 86400;  // 4 years
    uint256 constant MULTIPLIER = 10 ** 18;


    // dev team account
    address public dev;

    uint public devFund;

    uint public devFundRatio; // ex. 5000 => 50%

    // user => reward
    // useless
    mapping(address => uint256) public rewards;

    // useless
    uint public totalStaked;

    // total to shared
    uint public totalRewarded;

    uint public withdrewReward;

    // useless
    uint public lastUpdateTime;

    // useless
    uint public rewardPerTokenStored;

    // useless
    mapping(address => uint256) public userRewardPerTokenPaid;


    // A record of each accounts delegate
    mapping(address => address) public delegates;

    // A checkpoint for marking number of votes from a given block
    struct Checkpoint {
        uint32 fromBlock;
        uint votes;
    }

    mapping(uint256 => Checkpoint) public totalSupplyCheckpoints;

    uint256 public totalSupplyNumCheckpoints;

    // A record of votes checkpoints for each account, by index
    mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;

    // The number of checkpoints for each account
    mapping(address => uint32) public numCheckpoints;

    // The EIP-712 typehash for the contract's domain
    bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

    // The EIP-712 typehash for the delegation struct used by the contract
    bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");

    // A record of states for signing / validating signatures
    mapping(address => uint) public nonces;

    // An event thats emitted when an account changes its delegate
    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);

    // An event thats emitted when a delegate account's vote balance changes
    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);


    event RewardAdded(address fromToken, uint convertAmount, uint reward);

    event RewardConvert(address fromToken, address toToken, uint convertAmount, uint returnAmount);

    event RewardPaid (
        address paidTo,
        uint256 amount
    );

    event Transfer(address indexed from, address indexed to, uint256 value);

    event Deposit (
        address indexed provider,
        uint256 value,
        uint256 unlocktime,
        int128 type_,
        uint256 prevBalance,
        uint256 balance
    );

    event Withdraw (
        address indexed provider,
        uint256 value,
        uint256 prevBalance,
        uint256 balance
    );

    event Supply (
        uint256 prevSupply,
        uint256 supply
    );

    event FailedDelegateBySig(
        address indexed delegatee,
        uint indexed nonce,
        uint expiry,
        uint8 v,
        bytes32 r,
        bytes32 s
    );
}


interface XOLEInterface {

    function shareableTokenAmount() external view returns (uint256);

    function claimableTokenAmount() external view returns (uint256);

    function convertToSharingToken(uint amount, uint minBuyAmount, bytes memory data) external;

    function withdrawDevFund() external;

    /*** Admin Functions ***/

    function withdrawCommunityFund(address to) external;

    function setDevFundRatio(uint newRatio) external;

    function setDev(address newDev) external;

    function setDexAgg(DexAggregatorInterface newDexAgg) external;

    function setShareToken(address _shareToken) external;

    function setOleLpStakeToken(address _oleLpStakeToken) external;

    function setOleLpStakeAutomator(address _oleLpStakeAutomator) external;

    // xOLE functions

    function create_lock(uint256 _value, uint256 _unlock_time) external;

    function create_lock_for(address to, uint256 _value, uint256 _unlock_time) external;

    function increase_amount(uint256 _value) external;

    function increase_amount_for(address to, uint256 _value) external;

    function increase_unlock_time(uint256 _unlock_time) external;

    function withdraw() external;

    function withdraw_automator(address owner) external;

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

}

File 8 of 19 : Types.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "./liquidity/LPoolInterface.sol";
import "./lib/TransferHelper.sol";

library Types {
    using TransferHelper for IERC20;

    struct Market {// Market info
        LPoolInterface pool0;       // Lending Pool 0
        LPoolInterface pool1;       // Lending Pool 1
        address token0;              // Lending Token 0
        address token1;              // Lending Token 1
        uint16 marginLimit;         // Margin ratio limit for specific trading pair. Two decimal in percentage, ex. 15.32% => 1532
        uint16 feesRate;            // feesRate 30=>0.3%
        uint16 priceDiffientRatio;
        address priceUpdater;
        uint pool0Insurance;        // Insurance balance for token 0
        uint pool1Insurance;        // Insurance balance for token 1
        uint32[] dexs;
    }

    struct Trade {// Trade storage
        uint deposited;             // Balance of deposit token
        uint held;                  // Balance of held position
        bool depositToken;          // Indicate if the deposit token is token 0 or token 1
        uint128 lastBlockNum;       // Block number when the trade was touched last time, to prevent more than one operation within same block
    }

    struct MarketVars {// A variables holder for market info
        LPoolInterface buyPool;     // Lending pool address of the token to buy. It's a calculated field on open or close trade.
        LPoolInterface sellPool;    // Lending pool address of the token to sell. It's a calculated field on open or close trade.
        IERC20 buyToken;            // Token to buy
        IERC20 sellToken;           // Token to sell
        uint reserveBuyToken;
        uint reserveSellToken;
        uint buyPoolInsurance;      // Insurance balance of token to buy
        uint sellPoolInsurance;     // Insurance balance of token to sell
        uint16 marginLimit;         // Margin Ratio Limit for specific trading pair.
        uint16 priceDiffientRatio;
        uint32[] dexs;
    }

    struct TradeVars {// A variables holder for trade info
        uint depositValue;          // Deposit value
        IERC20 depositErc20;        // Deposit Token address
        uint fees;                  // Fees value
        uint depositAfterFees;      // Deposit minus fees
        uint tradeSize;             // Trade amount to be swap on DEX
        uint newHeld;               // Latest held position
        uint borrowValue;
        uint token0Price;
        uint32 dexDetail;
        uint totalHeld;
    }

    struct CloseTradeVars {// A variables holder for close trade info
        uint16 marketId;
        bool longToken;
        bool depositToken;
        uint closeRatio;          // Close ratio
        bool isPartialClose;        // Is partial close
        uint closeAmountAfterFees;  // Close amount sub Fees value
        uint borrowed;
        uint repayAmount;           // Repay to pool value
        uint depositDecrease;       // Deposit decrease
        uint depositReturn;         // Deposit actual returns
        uint sellAmount;
        uint receiveAmount;
        uint token0Price;
        uint fees;                  // Fees value
        uint32 dexDetail;
    }


    struct LiquidateVars {// A variable holder for liquidation process
        uint16 marketId;
        bool longToken;
        uint borrowed;              // Total borrowed balance of trade
        uint fees;                  // Fees for liquidation process
        uint penalty;               // Penalty
        uint remainAmountAfterFees;   // Held-fees-penalty
        bool isSellAllHeld;         // Is need sell all held
        uint depositDecrease;       // Deposit decrease
        uint depositReturn;         // Deposit actual returns
        uint sellAmount;
        uint receiveAmount;
        uint token0Price;
        uint outstandingAmount;
        uint finalRepayAmount;
        uint32 dexDetail;
    }

    struct MarginRatioVars {
        address heldToken;
        address sellToken;
        address owner;
        uint held;
        bytes dexData;
        uint16 multiplier;
        uint price;
        uint cAvgPrice;
        uint hAvgPrice; 
        uint8 decimals;
        uint lastUpdateTime;
    }
}

File 9 of 19 : OpenLevInterface.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

pragma experimental ABIEncoderV2;

import "./Types.sol";
import "./liquidity/LPoolInterface.sol";
import "./ControllerInterface.sol";
import "./dex/DexAggregatorInterface.sol";
import "./OpenLevInterface.sol";
import "./lib/DexData.sol";
import "./lib/TransferHelper.sol";
import "./lib/Utils.sol";

abstract contract OpenLevStorage {
    using SafeMath for uint;
    using TransferHelper for IERC20;

    struct CalculateConfig {
        uint16 defaultFeesRate; // 30 =>0.003
        uint8 insuranceRatio; // 33=>33%
        uint16 defaultMarginLimit; // 3000=>30%
        uint16 priceDiffientRatio; //10=>10%
        uint16 updatePriceDiscount;//25=>25%
        uint16 feesDiscount; // 25=>25%
        uint128 feesDiscountThreshold; //  30 * (10 ** 18) minimal holding of xOLE to enjoy fees discount
        uint16 penaltyRatio;//100=>1%
        uint8 maxLiquidationPriceDiffientRatio;//30=>30%
        uint16 twapDuration;//28=>28s
    }

    struct AddressConfig {
        DexAggregatorInterface dexAggregator;
        address controller;
        address wETH;
        address xOLE;
    }

    // number of markets
    uint16 public numPairs;

    // marketId => Pair
    mapping(uint16 => Types.Market) public markets;

    // owner => marketId => long0(true)/long1(false) => Trades
    mapping(address => mapping(uint16 => mapping(bool => Types.Trade))) public activeTrades;

    //useless
    mapping(address => bool) public allowedDepositTokens;

    CalculateConfig public calculateConfig;

    AddressConfig public addressConfig;

    mapping(uint8 => bool) public supportDexs;

    mapping(address => uint) public totalHelds;

    // map(marketId, tokenAddress, index) => taxRate)
    mapping(uint16 => mapping(address => mapping(uint => uint24))) public taxes;

    event MarginTrade(
        address trader,
        uint16 marketId,
        bool longToken, // 0 => long token 0; 1 => long token 1;
        bool depositToken,
        uint deposited,
        uint borrowed,
        uint held,
        uint fees,
        uint token0Price,
        uint32 dex
    );

    event TradeClosed(
        address owner,
        uint16 marketId,
        bool longToken,
        bool depositToken,
        uint closeAmount,
        uint depositDecrease,
        uint depositReturn,
        uint fees,
        uint token0Price,
        uint32 dex
    );

    event Liquidation(
        address owner,
        uint16 marketId,
        bool longToken,
        bool depositToken,
        uint liquidationAmount,
        uint outstandingAmount,
        address liquidator,
        uint depositDecrease,
        uint depositReturn,
        uint fees,
        uint token0Price,
        uint penalty,
        uint32 dex
    );

    event NewAddressConfig(address controller, address dexAggregator);

    event NewCalculateConfig(
        uint16 defaultFeesRate,
        uint8 insuranceRatio,
        uint16 defaultMarginLimit,
        uint16 priceDiffientRatio,
        uint16 updatePriceDiscount,
        uint16 feesDiscount,
        uint128 feesDiscountThreshold,
        uint16 penaltyRatio,
        uint8 maxLiquidationPriceDiffientRatio,
        uint16 twapDuration);

    event NewMarketConfig(uint16 marketId, uint16 feesRate, uint32 marginLimit, uint16 priceDiffientRatio, uint32[] dexs);

    event ChangeAllowedDepositTokens(address[] token, bool allowed);

}

/**
  * @title OpenLevInterface
  * @author OpenLeverage
  */
interface OpenLevInterface {

    function addMarket(
        LPoolInterface pool0,
        LPoolInterface pool1,
        uint16 marginLimit,
        bytes memory dexData
    ) external returns (uint16);


    function marginTrade(uint16 marketId, bool longToken, bool depositToken, uint deposit, uint borrow, uint minBuyAmount, bytes memory dexData) external payable;

    function closeTrade(uint16 marketId, bool longToken, uint closeAmount, uint minOrMaxAmount, bytes memory dexData) external;

    function liquidate(address owner, uint16 marketId, bool longToken, uint minBuy, uint maxAmount, bytes memory dexData) external;

    function marginRatio(address owner, uint16 marketId, bool longToken, bytes memory dexData) external view returns (uint current, uint cAvg, uint hAvg, uint32 limit);

    function updatePrice(uint16 marketId, bytes memory dexData) external;

    function shouldUpdatePrice(uint16 marketId, bytes memory dexData) external view returns (bool);

    function getMarketSupportDexs(uint16 marketId) external view returns (uint32[] memory);

    // function getCalculateConfig() external view returns (OpenLevStorage.CalculateConfig memory);

    /*** Admin Functions ***/
    function setCalculateConfig(uint16 defaultFeesRate, uint8 insuranceRatio, uint16 defaultMarginLimit, uint16 priceDiffientRatio,
        uint16 updatePriceDiscount, uint16 feesDiscount, uint128 feesDiscountThreshold, uint16 penaltyRatio, uint8 maxLiquidationPriceDiffientRatio, uint16 twapDuration) external;

    function setAddressConfig(address controller, DexAggregatorInterface dexAggregator) external;

    function setMarketConfig(uint16 marketId, uint16 feesRate, uint16 marginLimit, uint16 priceDiffientRatio, uint32[] memory dexs) external;

    function moveInsurance(uint16 marketId, uint8 poolIndex, address to, uint amount) external;

    function setSupportDex(uint8 dex, bool support) external;

    function setTaxRate(uint16 marketId, address token, uint index, uint24 tax) external;

}

File 10 of 19 : IWETH.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

interface IWETH {
    function deposit() external payable;

    function withdraw(uint256) external;
}

File 11 of 19 : ControllerInterface.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

pragma experimental ABIEncoderV2;

import "./liquidity/LPoolInterface.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./dex/DexAggregatorInterface.sol";

contract ControllerStorage {

    //lpool-pair
    struct LPoolPair {
        address lpool0;
        address lpool1;
    }
    //lpool-distribution
    struct LPoolDistribution {
        uint64 startTime;
        uint64 endTime;
        uint64 duration;
        uint64 lastUpdateTime;
        uint256 totalRewardAmount;
        uint256 rewardRate;
        uint256 rewardPerTokenStored;
        uint256 extraTotalToken;
    }
    //lpool-rewardByAccount
    struct LPoolRewardByAccount {
        uint rewardPerTokenStored;
        uint rewards;
        uint extraToken;
    }

    struct OLETokenDistribution {
        uint supplyBorrowBalance;
        uint extraBalance;
        uint128 updatePricePer;
        uint128 liquidatorMaxPer;
        uint16 liquidatorOLERatio;//300=>300%
        uint16 xoleRaiseRatio;//150=>150%
        uint128 xoleRaiseMinAmount;
    }

    IERC20 public oleToken;

    address public xoleToken;

    address public wETH;

    address public lpoolImplementation;

    //interest param
    uint256 public baseRatePerBlock;
    uint256 public multiplierPerBlock;
    uint256 public jumpMultiplierPerBlock;
    uint256 public kink;

    bytes public oleWethDexData;

    address public openLev;

    DexAggregatorInterface public dexAggregator;

    bool public suspend;

    OLETokenDistribution public oleTokenDistribution;
    //token0=>token1=>pair
    mapping(address => mapping(address => LPoolPair)) public lpoolPairs;
    //marketId=>isDistribution
    mapping(uint => bool) public marketExtraDistribution;
    //marketId=>isSuspend
    mapping(uint => bool) public marketSuspend;
    //pool=>allowed
    mapping(address => bool) public lpoolUnAlloweds;
    //pool=>bool=>distribution(true is borrow,false is supply)
    mapping(LPoolInterface => mapping(bool => LPoolDistribution)) public lpoolDistributions;
    //pool=>bool=>distribution(true is borrow,false is supply)
    mapping(LPoolInterface => mapping(bool => mapping(address => LPoolRewardByAccount))) public lPoolRewardByAccounts;

    bool public suspendAll;

    event LPoolPairCreated(address token0, address pool0, address token1, address pool1, uint16 marketId, uint16 marginLimit, bytes dexData);

    event Distribution2Pool(address pool, uint supplyAmount, uint borrowerAmount, uint64 startTime, uint64 duration, uint newSupplyBorrowBalance);

    event UpdatePriceReward(uint marketId, address updator, uint reward, uint newExtraBalance);

    event LiquidateReward(uint marketId, address liquidator, uint reward, uint newExtraBalance);

    event PoolReward(address pool, address rewarder, bool isBorrow, uint reward);

    event NewOLETokenDistribution(uint moreSupplyBorrowBalance, uint moreExtraBalance, uint128 updatePricePer, uint128 liquidatorMaxPer, uint16 liquidatorOLERatio, uint16 xoleRaiseRatio, uint128 xoleRaiseMinAmount);


}
/**
  * @title Controller
  * @author OpenLeverage
  */
interface ControllerInterface {

    function createLPoolPair(address tokenA, address tokenB, uint16 marginLimit, bytes memory dexData) external;

    /*** Policy Hooks ***/

    function mintAllowed(address minter, uint lTokenAmount) external;

    function transferAllowed(address from, address to, uint lTokenAmount) external;

    function redeemAllowed(address redeemer, uint lTokenAmount) external;

    function borrowAllowed(address borrower, address payee, uint borrowAmount) external;

    function repayBorrowAllowed(address payer, address borrower, uint repayAmount, bool isEnd) external;

    function liquidateAllowed(uint marketId, address liquidator, uint liquidateAmount, bytes memory dexData) external;

    function marginTradeAllowed(uint marketId) external view returns (bool);

    function closeTradeAllowed(uint marketId) external view returns (bool);

    function updatePriceAllowed(uint marketId, address to) external;

    /*** Admin Functions ***/

    function setLPoolImplementation(address _lpoolImplementation) external;

    function setOpenLev(address _openlev) external;

    function setDexAggregator(DexAggregatorInterface _dexAggregator) external;

    function setInterestParam(uint256 _baseRatePerBlock, uint256 _multiplierPerBlock, uint256 _jumpMultiplierPerBlock, uint256 _kink) external;

    function setLPoolUnAllowed(address lpool, bool unAllowed) external;

    function setSuspend(bool suspend) external;

    function setSuspendAll(bool suspend) external;

    function setMarketSuspend(uint marketId, bool suspend) external;

    function setOleWethDexData(bytes memory _oleWethDexData) external;

    // liquidatorOLERatio: Two decimal in percentage, ex. 300% => 300
    function setOLETokenDistribution(uint moreSupplyBorrowBalance, uint moreExtraBalance, uint128 updatePricePer, uint128 liquidatorMaxPer, uint16 liquidatorOLERatio, uint16 xoleRaiseRatio, uint128 xoleRaiseMinAmount) external;

    function distributeRewards2Pool(address pool, uint supplyAmount, uint borrowAmount, uint64 startTime, uint64 duration) external;

    function distributeRewards2PoolMore(address pool, uint supplyAmount, uint borrowAmount) external;

    function distributeExtraRewards2Markets(uint[] memory marketIds, bool isDistribution) external;

    /***Distribution Functions ***/

    function earned(LPoolInterface lpool, address account, bool isBorrow) external view returns (uint256);

    function getSupplyRewards(LPoolInterface[] calldata lpools, address account) external;

}

File 12 of 19 : Adminable.sol
// SPDX-License-Identifier: BUSL-1.1


pragma solidity 0.7.6;

abstract contract Adminable {
    address payable public admin;
    address payable public pendingAdmin;
    address payable public developer;

    event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);

    event NewAdmin(address oldAdmin, address newAdmin);
    constructor () {
        developer = msg.sender;
    }

    modifier onlyAdmin() {
        require(msg.sender == admin, "caller must be admin");
        _;
    }
    modifier onlyAdminOrDeveloper() {
        require(msg.sender == admin || msg.sender == developer, "caller must be admin or developer");
        _;
    }

    function setPendingAdmin(address payable newPendingAdmin) external virtual onlyAdmin {
        // Save current value, if any, for inclusion in log
        address oldPendingAdmin = pendingAdmin;
        // Store pendingAdmin with value newPendingAdmin
        pendingAdmin = newPendingAdmin;
        // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)
        emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);
    }

    function acceptAdmin() external virtual {
        require(msg.sender == pendingAdmin, "only pendingAdmin can accept admin");
        // Save current values for inclusion in log
        address oldAdmin = admin;
        address oldPendingAdmin = pendingAdmin;
        // Store admin with value pendingAdmin
        admin = pendingAdmin;
        // Clear the pending value
        pendingAdmin = address(0);
        emit NewAdmin(oldAdmin, admin);
        emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);
    }

}

File 13 of 19 : IUniswapV2Factory.sol
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

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

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

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

File 14 of 19 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

File 15 of 19 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

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

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 16 of 19 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20.sol";
import "../../math/SafeMath.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 SafeMath for uint256;
    using Address for address;

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

    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'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(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");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 17 of 19 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool);

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

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

File 18 of 19 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}

File 19 of 19 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
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) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        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) {
        // 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) {
        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) {
        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) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @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) {
        require(b <= a, "SafeMath: subtraction overflow");
        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) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @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. 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) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        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) {
        require(b > 0, "SafeMath: modulo by zero");
        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) {
        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.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * 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) {
        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) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"isOpen","type":"bool"},{"internalType":"uint256","name":"amount","type":"uint256"},{"components":[{"internalType":"contract LPoolInterface","name":"buyPool","type":"LPoolInterface"},{"internalType":"contract LPoolInterface","name":"sellPool","type":"LPoolInterface"},{"internalType":"contract IERC20","name":"buyToken","type":"IERC20"},{"internalType":"contract IERC20","name":"sellToken","type":"IERC20"},{"internalType":"uint256","name":"reserveBuyToken","type":"uint256"},{"internalType":"uint256","name":"reserveSellToken","type":"uint256"},{"internalType":"uint256","name":"buyPoolInsurance","type":"uint256"},{"internalType":"uint256","name":"sellPoolInsurance","type":"uint256"},{"internalType":"uint16","name":"marginLimit","type":"uint16"},{"internalType":"uint16","name":"priceDiffientRatio","type":"uint16"},{"internalType":"uint32[]","name":"dexs","type":"uint32[]"}],"internalType":"struct Types.MarketVars","name":"vars","type":"tuple"},{"internalType":"bytes","name":"dexData","type":"bytes"}],"name":"isPositionHealthy","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"held","type":"uint256"},{"internalType":"address","name":"heldToken","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"contract LPoolInterface","name":"borrowPool","type":"LPoolInterface"},{"internalType":"bytes","name":"dexData","type":"bytes"}],"name":"marginRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract DexAggregatorInterface","name":"dexAggregator","type":"DexAggregatorInterface"},{"internalType":"uint16","name":"twapDuration","type":"uint16"},{"internalType":"uint16","name":"priceDiffientRatio","type":"uint16"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"bytes","name":"dexData","type":"bytes"}],"name":"shouldUpdatePriceInternal","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract LPoolInterface","name":"buyPool","type":"LPoolInterface"},{"internalType":"contract LPoolInterface","name":"sellPool","type":"LPoolInterface"},{"internalType":"contract IERC20","name":"buyToken","type":"IERC20"},{"internalType":"contract IERC20","name":"sellToken","type":"IERC20"},{"internalType":"uint256","name":"reserveBuyToken","type":"uint256"},{"internalType":"uint256","name":"reserveSellToken","type":"uint256"},{"internalType":"uint256","name":"buyPoolInsurance","type":"uint256"},{"internalType":"uint256","name":"sellPoolInsurance","type":"uint256"},{"internalType":"uint16","name":"marginLimit","type":"uint16"},{"internalType":"uint16","name":"priceDiffientRatio","type":"uint16"},{"internalType":"uint32[]","name":"dexs","type":"uint32[]"}],"internalType":"struct Types.MarketVars","name":"vars","type":"tuple"},{"internalType":"bool","name":"longToken","type":"bool"},{"internalType":"bool","name":"depositToken","type":"bool"},{"internalType":"uint256","name":"deposit","type":"uint256"},{"internalType":"uint256","name":"borrow","type":"uint256"},{"internalType":"bytes","name":"dexData","type":"bytes"},{"components":[{"internalType":"contract DexAggregatorInterface","name":"dexAggregator","type":"DexAggregatorInterface"},{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"wETH","type":"address"},{"internalType":"address","name":"xOLE","type":"address"}],"internalType":"struct OpenLevStorage.AddressConfig","name":"addressConfig","type":"tuple"},{"components":[{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"held","type":"uint256"},{"internalType":"bool","name":"depositToken","type":"bool"},{"internalType":"uint128","name":"lastBlockNum","type":"uint128"}],"internalType":"struct Types.Trade","name":"trade","type":"tuple"}],"name":"verifyTrade","outputs":[],"stateMutability":"view","type":"function"}]

613f32610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100ff5760003560e01c80635d50820c116100a1578063c19ef55011610070578063c19ef55014610273578063da6288c814610286578063f7f623b5146102a6578063f8df0a21146102c6576100ff565b80635d50820c146101fc57806385259f1c146102205780639c34edf914610240578063b8cdbe4114610260576100ff565b8063289e376f116100dd578063289e376f14610166578063291345221461019c5780634256bde0146101bc5780634a009e00146101dc576100ff565b80630462282014610104578063154f09681461012657806319ea053f14610146575b600080fd5b81801561011057600080fd5b5061012461011f3660046137c3565b6102e6565b005b81801561013257600080fd5b50610124610141366004613871565b61043c565b81801561015257600080fd5b50610124610161366004613286565b6104f8565b81801561017257600080fd5b50610186610181366004613286565b6105f9565b6040516101939190613e32565b60405180910390f35b8180156101a857600080fd5b506101246101b73660046139c3565b610691565b8180156101c857600080fd5b506101246101d73660046134b3565b610861565b6101ef6101ea3660046135a1565b610963565b6040516101939190613c41565b61020f61020a3660046132d6565b610ab9565b604051610193959493929190613e3b565b81801561022c57600080fd5b5061018661023b366004613ab1565b610ae8565b81801561024c57600080fd5b5061012461025b366004613246565b610caf565b61012461026e366004613697565b610d18565b6101ef6102813660046131b7565b610ed8565b81801561029257600080fd5b506101246102a1366004613814565b6110c0565b8180156102b257600080fd5b506101866102c1366004613363565b6111be565b8180156102d257600080fd5b506101246102e13660046135e4565b6113cf565b60ff84166103be5760058501546102fd9083611be3565b600586015560028501546001600160a01b0316600081815260208390526040908190205490516370a0823160e01b81526103b89286926103a3928792906370a082319061034e903090600401613bcb565b60206040518083038186803b15801561036657600080fd5b505afa15801561037a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039e9190613a99565b611c45565b60028801546001600160a01b03169190611c78565b50610435565b60068501546103cd9083611be3565b600686015560038501546001600160a01b0316600081815260208390526040908190205490516370a0823160e01b815261043392869261041e928792906370a082319061034e903090600401613bcb565b60038801546001600160a01b03169190611c78565b505b5050505050565b6127108561ffff16108015610455575060008461ffff16115b8015610462575060008251115b6104875760405162461bcd60e51b815260040161047e90613ddb565b60405180910390fd5b60038101805461ffff868116600160a01b0261ffff60a01b19918916600160b01b0261ffff60b01b19909316929092171617905581516104d09060078301906020850190612db3565b50600301805461ffff909316600160c01b0261ffff60c01b1990931692909217909155505050565b816001600160a01b0316836001600160a01b031614156105df57604051632e1a7d4d60e01b81526001600160a01b03831690632e1a7d4d9061053e908490600401613e32565b600060405180830381600087803b15801561055857600080fd5b505af115801561056c573d6000803e3d6000fd5b505050506000846001600160a01b03168260405161058990613bc8565b60006040518083038185875af1925050503d80600081146105c6576040519150601f19603f3d011682016040523d82523d6000602084013e6105cb565b606091505b50509050806105d957600080fd5b506105f3565b6104356001600160a01b0384168583611c78565b50505050565b6000826001600160a01b0316846001600160a01b0316141561067157826001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561065057600080fd5b505af1158015610664573d6000803e3d6000fd5b5050505050349050610689565b6106866001600160a01b038516863085611ea0565b90505b949350505050565b6127108b61ffff161080156106a9575060648a60ff16105b80156106b9575060008961ffff16115b80156106ca575060648761ffff1611155b80156106db575060648661ffff1611155b80156106ec57506127108461ffff16105b80156106fc575060008261ffff16115b6107185760405162461bcd60e51b815260040161047e90613ddb565b8a8160000160006101000a81548161ffff021916908361ffff160217905550898160000160026101000a81548160ff021916908360ff160217905550888160000160036101000a81548161ffff021916908361ffff160217905550878160000160056101000a81548161ffff021916908361ffff160217905550868160000160076101000a81548161ffff021916908361ffff160217905550858160000160096101000a81548161ffff021916908361ffff1602179055508481600001600b6101000a8154816001600160801b0302191690836001600160801b031602179055508381600001601b6101000a81548161ffff021916908361ffff1602179055508281600001601d6101000a81548160ff021916908360ff1602179055508181600001601e6101000a81548161ffff021916908361ffff1602179055505050505050505050505050565b60005b828110156105f357600084848381811061087a57fe5b905060200201602081019061088f919061317f565b90506000816001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016108bf9190613bcb565b60206040518083038186803b1580156108d757600080fd5b505afa1580156108eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090f9190613a99565b6001600160a01b0383166000908152602086905260409020549091501580156109385750600081115b15610959576001600160a01b03821660009081526020859052604090208190555b5050600101610864565b600061096e826120d2565b61097a57506000610aaf565b6000806000896001600160a01b031663a59a36ae88888c896040518563ffffffff1660e01b81526004016109b19493929190613c0b565b60a06040518083038186803b1580156109c957600080fd5b505afa1580156109dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a019190613b15565b9450509350935050610a208961ffff16826120ec90919063ffffffff16565b421015610a335760009350505050610aaf565b821580610a3e575081155b15610a4f5760019350505050610aaf565b60646000610a6784610a618785612146565b9061219f565b9050610a778261ffff8c166120ec565b81101580610a925750610a8e8261ffff8c16611be3565b8111155b15610aa557600195505050505050610aaf565b6000955050505050505b9695505050505050565b6000806000806000610ad18b8b8b8b8b60008c612206565b939f929e50909c509a509098509650505050505050565b600080610af58989611be3565b6001600160a01b038716600090815260208590526040902054909150610b1d908290876126a2565b90508891508615610c065780846005015410610b7f5760058401805482900390556001600160a01b038616600090815260208490526040902054610b619082611be3565b6001600160a01b038716600090815260208590526040902055610c01565b60058401546001600160a01b038716600090815260208590526040902054610ba8919087611c45565b9150610bb482896120ec565b60058501546001600160a01b038816600090815260208690526040902054919350610bdf9190611be3565b6001600160a01b03871660009081526020859052604081209190915560058501555b610ca3565b80846006015410610c21576006840180548290039055610ca3565b60068401546001600160a01b038716600090815260208590526040902054610c4a919087611c45565b9150610c5682896120ec565b60068501546001600160a01b038816600090815260208690526040902054919350610c819190611be3565b6001600160a01b03871660009081526020859052604081209190915560068501555b50979650505050505050565b6001600160a01b03831615801590610ccf57506001600160a01b03821615155b610ceb5760405162461bcd60e51b815260040161047e90613d84565b6001810180546001600160a01b03199081166001600160a01b039586161790915581541691909216179055565b600087151587151514610d2f578860600151610d35565b88604001515b90506000816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610d7257600080fd5b505afa158015610d86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610daa9190613b61565b60ff169050600060048211610dc0576001610dc8565b60048203600a0a5b9050600085604001516001600160a01b0316846001600160a01b031614610def5788610df1565b345b9050818111610e125760405162461bcd60e51b815260040161047e90613cc9565b610e298c6101400151610e24896126c8565b612716565b610e455760405162461bcd60e51b815260040161047e90613d21565b60608501516001600160801b0316610e805760008811610e775760405162461bcd60e51b815260040161047e90613d04565b50505050610ece565b846040015115158a1515148015610ead5750436001600160801b031685606001516001600160801b031614155b610ec95760405162461bcd60e51b815260040161047e90613ce6565b505050505b5050505050505050565b6000610ee2612e62565b610f2a878688610ef6578660600151610efc565b86604001515b89610f0b578760400151610f11565b87606001515b8a610f1d578851610f23565b88602001515b8b89612206565b60808601526060850152604080850191909152602084019190915290825280516302b2007560e31b81529051600091309163159003a89160048082019261014092909190829003018186803b158015610f8257600080fd5b505afa158015610f96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fba91906138eb565b509850505050505050505086156110175784610100015161ffff16826000015110158015610ff5575084610100015161ffff16826020015110155b801561100e575084610100015161ffff16826040015110155b925050506110b7565b8160800151826060015110156110725760006110498360600151610a616064866080015161214690919063ffffffff16565b90508160ff1660648203106110705760405162461bcd60e51b815260040161047e90613dbe565b505b84610100015161ffff16826000015110158061109b575084610100015161ffff16826020015110155b8061100e575084610100015161ffff1682604001511015925050505b95945050505050565b8254825460038601546002870154600093611105936001600160a01b039182169361ffff600160f01b909204821693600160c01b820490921692908116911687610963565b6002860154600387015491925060009161112c916001600160a01b03908116911685612789565b905080156111b5576004860180546001600160a01b0319163317905581156111b55760018501546040516313eb59bb60e31b81526001600160a01b0390911690639f5acdd890611182908a903390600401613e15565b600060405180830381600087803b15801561119c57600080fd5b505af11580156111b0573d6000803e3d6000fd5b505050505b50505050505050565b600383015460009081906111e69061271090610a61908d90600160b01b900461ffff16612146565b90508091508260c001516001600160801b0316886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016112259190613bcb565b60206040518083038186803b15801561123d57600080fd5b505afa158015611251573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112759190613a99565b11156112a8576112a561129e6064610a618660a0015161ffff168561214690919063ffffffff16565b8290611be3565b91505b60048501546001600160a01b038c8116911614156112ed576112ea6112e36064610a61866080015161ffff168561214690919063ffffffff16565b8390611be3565b91505b600061130e6064610a61866020015160ff168661214690919063ffffffff16565b905061132f8961131e8584611be3565b6001600160a01b038d169190611c78565b5061133b8189896126a2565b60038701549091506001600160a01b038b81169116141561136f57600686015461136590826120ec565b6006870155611384565b600586015461137e90826120ec565b60058701555b6001600160a01b038a166000908152602086905260409020546113a790826120ec565b6001600160a01b038b1660009081526020879052604090205550509998505050505050505050565b60008a6001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561140a57600080fd5b505afa15801561141e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611442919061319b565b905060008a6001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561147f57600080fd5b505afa158015611493573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114b7919061319b565b905060006114c48a612905565b90506114d08582612934565b80156114e8575060018601546001600160a01b031633145b80156115045750865461ffff63010000009091048116908c1610155b80156115165750620186a08b61ffff16105b6115325760405162461bcd60e51b815260040161047e90613da1565b600061153d8b61294e565b905062030d408160008151811061155057fe5b602002602001015162ffffff16108015611585575062030d408160018151811061157657fe5b602002602001015162ffffff16105b80156115ac575062030d408160028151811061159d57fe5b602002602001015162ffffff16105b80156115d3575062030d40816003815181106115c457fe5b602002602001015162ffffff16105b80156115fa575062030d40816004815181106115eb57fe5b602002602001015162ffffff16105b8015611621575062030d408160058151811061161257fe5b602002602001015162ffffff16105b61163d5760405162461bcd60e51b815260040161047e90613df8565b8060008151811061164a57fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b0389168352845280822082805290935291909120805462ffffff191662ffffff9092169190911790558051819060019081106116a757fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b0388168352845280822082805290935291909120805462ffffff191662ffffff90921691909117905580518190600290811061170457fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038916835284528082206001835290935291909120805462ffffff191662ffffff90921691909117905580518190600390811061176257fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038816835284528082206001835290935291909120805462ffffff191662ffffff9092169190911790558051819060049081106117c057fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038916835284528082206002835290935291909120805462ffffff191662ffffff90921691909117905580518190600590811061181e57fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038881168452908552818320600284529094529020805462ffffff191662ffffff90921691909117905561187d915084168e600019612a34565b506118946001600160a01b0383168d600019612a34565b50604080516001808252818301909252600091602080830190803683370190505090506118c08b6126c8565b816000815181106118cd57fe5b602002602001019063ffffffff16908163ffffffff16815250506040518061016001604052808f6001600160a01b031681526020018e6001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020018d61ffff1681526020018960000160009054906101000a900461ffff1661ffff1681526020018960000160059054906101000a900461ffff1661ffff16815260200160006001600160a01b031681526020016000815260200160008152602001828152508960008c61ffff1661ffff16815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160030160146101000a81548161ffff021916908361ffff16021790555060a08201518160030160166101000a81548161ffff021916908361ffff16021790555060c08201518160030160186101000a81548161ffff021916908361ffff16021790555060e08201518160040160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555061010082015181600501556101208201518160060155610140820151816007019080519060200190611b2a929190612db3565b50905050611b378b6120d2565b15611b4d57611b4784848d612789565b50611bd3565b60ff821660021415611bd3578660000160009054906101000a90046001600160a01b03166001600160a01b031663f18ef35985858e6040518463ffffffff1660e01b8152600401611ba093929190613bdf565b600060405180830381600087803b158015611bba57600080fd5b505af1158015611bce573d6000803e3d6000fd5b505050505b5050505050505050505050505050565b600082821115611c3a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b60008083118015611c565750600082115b15611c715782611c668386612146565b81611c6d57fe5b0490505b9392505050565b60008115611c71576000846001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015611ccf57600080fd5b505afa158015611ce3573d6000803e3d6000fd5b505050506040513d6020811015611cf957600080fd5b5051604080516001600160a01b038781166024830152604480830188905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825194955090891693919290918291908083835b60208310611d775780518252601f199092019160209182019101611d58565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611dd9576040519150601f19603f3d011682016040523d82523d6000602084013e611dde565b606091505b5050506000856001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015611e3057600080fd5b505afa158015611e44573d6000803e3d6000fd5b505050506040513d6020811015611e5a57600080fd5b50519050818111611e97576040805162461bcd60e51b81526020600482015260026024820152612a2360f11b604482015290519081900360640190fd5b03949350505050565b60008115610689576000856001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015611ef757600080fd5b505afa158015611f0b573d6000803e3d6000fd5b505050506040513d6020811015611f2157600080fd5b5051604080516001600160a01b0388811660248301528781166044830152606480830188905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17815292518251949550908a1693919290918291908083835b60208310611fa75780518252601f199092019160209182019101611f88565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612009576040519150601f19603f3d011682016040523d82523d6000602084013e61200e565b606091505b5050506000866001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561206057600080fd5b505afa158015612074573d6000803e3d6000fd5b505050506040513d602081101561208a57600080fd5b505190508181116120c8576040805162461bcd60e51b81526020600482015260036024820152622a232360e91b604482015290519081900360640190fd5b0395945050505050565b600060026120df83612905565b60ff16141590505b919050565b600082820183811015611c71576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60008261215557506000611c3f565b8282028284828161216257fe5b0414611c715760405162461bcd60e51b8152600401808060200182810382526021815260200180613edc6021913960400191505060405180910390fd5b60008082116121f5576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816121fe57fe5b049392505050565b6000806000806000612216612e91565b606081018c905260808082018890526001600160a01b03808d1683528b811660208401528e1660408084019190915261271060a0840152805163309d7f9560e21b81529051600092309263c275fe549260048083019392829003018186803b15801561228157600080fd5b505afa158015612295573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b99190613543565b50505090506000306001600160a01b031663159003a86040518163ffffffff1660e01b81526004016101406040518083038186803b1580156122fa57600080fd5b505afa15801561230e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061233291906138eb565b995050505050505050505060008a6123c95760408085015190516305eff7ef60e21b81526001600160a01b038e16916317bfdfbc916123749190600401613bcb565b60206040518083038186803b15801561238c57600080fd5b505afa1580156123a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123c49190613a99565b612449565b60408085015190516395dd919360e01b81526001600160a01b038e16916395dd9193916123f99190600401613bcb565b60206040518083038186803b15801561241157600080fd5b505afa158015612425573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124499190613a99565b90508061246e5750505060a0015161ffff169450849350839250829150819050612693565b8351602085015160808601516040516352cd1b5760e11b81526001600160a01b0387169363a59a36ae936124aa93919290918891600401613c0b565b60a06040518083038186803b1580156124c257600080fd5b505afa1580156124d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124fa9190613b15565b610140890181905260ff90911661012089015261010088019190915260e087019190915260c08601919091526125349061ffff84166120ec565b4211156125475760e08401516101008501525b600061257385610120015160ff16600a0a610a618760c00151886060015161214690919063ffffffff16565b90506000828210156125865760006125af565b6125af83610a618860a0015161ffff166125a98787611be390919063ffffffff16565b90612146565b90506125db86610120015160ff16600a0a610a618860e00151896060015161214690919063ffffffff16565b91506000838310156125ee576000612611565b61261184610a618960a0015161ffff166125a98888611be390919063ffffffff16565b905061263e87610120015160ff16600a0a610a618961010001518a6060015161214690919063ffffffff16565b9250600084841015612651576000612674565b61267485610a618a60a0015161ffff166125a98989611be390919063ffffffff16565b60c089015160e090990151939d50919b50909950959750955050505050505b97509750975097509792505050565b600080831180156126b35750600082115b6126bd5783610689565b81611c668486612146565b60006001825110156126ec5760405162461bcd60e51b815260040161047e90613d3e565b6126f5826120d2565b156127085750602081015160001a6120e7565b50602081015160e01c6120e7565b6000805b83518110156127825783818151811061272f57fe5b602002602001015163ffffffff166000141561274a57612782565b8263ffffffff1684828151811061275d57fe5b602002602001015163ffffffff16141561277a5760019150612782565b60010161271a565b5092915050565b600080306001600160a01b031663c275fe546040518163ffffffff1660e01b815260040160806040518083038186803b1580156127c557600080fd5b505afa1580156127d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127fd9190613543565b50505090506000306001600160a01b031663159003a86040518163ffffffff1660e01b81526004016101406040518083038186803b15801561283e57600080fd5b505afa158015612852573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061287691906138eb565b9950505050505050505050816001600160a01b03166315426c97878784886040518563ffffffff1660e01b81526004016128b39493929190613c0b565b602060405180830381600087803b1580156128cd57600080fd5b505af11580156128e1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaf9190613527565b60006001825110156129295760405162461bcd60e51b815260040161047e90613c4c565b506020015160001a90565b60ff90811660009081526020929092526040909120541690565b6060600061295b83612d84565b6003029050600560ff82166001600160401b038111801561297b57600080fd5b506040519080825280602002602001820160405280156129a5578160200160208202803683370190505b50925060005b8260ff16811015612a2c57818551116129e95760008482815181106129cc57fe5b602002602001019062ffffff16908162ffffff1681525050612a24565b84820160200151845160e882901c90869084908110612a0457fe5b602002602001019062ffffff16908162ffffff1681525050600383019250505b6001016129ab565b505050919050565b600080846001600160a01b031663dd62ed3e30866040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b031681526020019250505060206040518083038186803b158015612a9557600080fd5b505afa158015612aa9573d6000803e3d6000fd5b505050506040513d6020811015612abf57600080fd5b505115612be457604080516001600160a01b038681166024830152600060448084019190915283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b178152925182519189169390918291908083835b60208310612b405780518252601f199092019160209182019101612b21565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612ba2576040519150601f19603f3d011682016040523d82523d6000602084013e612ba7565b606091505b50508091505080612be4576040805162461bcd60e51b815260206004820152600260248201526120a360f11b604482015290519081900360640190fd5b604080516001600160a01b038681166024830152604480830187905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b178152925182519189169390918291908083835b60208310612c5b5780518252601f199092019160209182019101612c3c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612cbd576040519150601f19603f3d011682016040523d82523d6000602084013e612cc2565b606091505b50508091505080612cff576040805162461bcd60e51b815260206004820152600260248201526120a360f11b604482015290519081900360640190fd5b60408051636eb1769f60e11b81523060048201526001600160a01b03868116602483015291519187169163dd62ed3e91604480820192602092909190829003018186803b158015612d4f57600080fd5b505afa158015612d63573d6000803e3d6000fd5b505050506040513d6020811015612d7957600080fd5b505195945050505050565b6000600582511015612da85760405162461bcd60e51b815260040161047e90613c81565b506024015160001a90565b82805482825590600052602060002090600701600890048101928215612e525791602002820160005b83821115612e2057835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302612ddc565b8015612e505782816101000a81549063ffffffff0219169055600401602081600301049283019260010302612e20565b505b50612e5e929150612f0d565b5090565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b60405180610160016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016000815260200160608152602001600061ffff168152602001600081526020016000815260200160008152602001600060ff168152602001600081525090565b5b80821115612e5e5760008155600101612f0e565b600082601f830112612f32578081fd5b813560206001600160401b03821115612f4757fe5b808202612f55828201613e5e565b838152828101908684018388018501891015612f6f578687fd5b8693505b85841015610ca357803563ffffffff81168114612f8e578788fd5b835260019390930192918401918401612f73565b600082601f830112612fb2578081fd5b81356001600160401b03811115612fc557fe5b612fd8601f8201601f1916602001613e5e565b818152846020838601011115612fec578283fd5b816020850160208301379081016020019190915292915050565b80356120e781613e81565b6000610160808385031215613024578182fd5b61302d81613e5e565b91505061303982613006565b815261304760208301613006565b602082015261305860408301613006565b604082015261306960608301613006565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101006130a4818401613169565b908201526101206130b6838201613169565b90820152610140828101356001600160401b038111156130d557600080fd5b6130e185828601612f22565b82840152505092915050565b6000608082840312156130fe578081fd5b604051608081018181106001600160401b038211171561311a57fe5b80604052508091508235815260208301356020820152604083013561313e81613e99565b6040820152606083013561315181613ea7565b6060919091015292915050565b80356120e781613ea7565b80356120e781613ebc565b80356120e781613ecc565b600060208284031215613190578081fd5b8135611c7181613e81565b6000602082840312156131ac578081fd5b8151611c7181613e81565b600080600080600060a086880312156131ce578081fd5b85356131d981613e81565b945060208601356131e981613e99565b93506040860135925060608601356001600160401b038082111561320b578283fd5b61321789838a01613011565b9350608088013591508082111561322c578283fd5b5061323988828901612fa2565b9150509295509295909350565b60008060006060848603121561325a578081fd5b833561326581613e81565b9250602084013561327581613e81565b929592945050506040919091013590565b6000806000806080858703121561329b578182fd5b84356132a681613e81565b935060208501356132b681613e81565b925060408501356132c681613e81565b9396929550929360600135925050565b60008060008060008060c087890312156132ee578384fd5b86356132f981613e81565b955060208701359450604087013561331081613e81565b9350606087013561332081613e81565b9250608087013561333081613e81565b915060a08701356001600160401b0381111561334a578182fd5b61335689828a01612fa2565b9150509295509295509295565b6000806000806000806000806000898b03610240811215613382578788fd5b8a3561338d81613e81565b995060208b0135985060408b01356133a481613e81565b975060608b01356133b481613e81565b965060808b0135955060a08b0135945060c08b0135935060e08b0135925061010061014060ff1983018113156133e8578384fd5b6133f181613e5e565b92506133fe828e01613169565b835261012061340e818f01613174565b602085015261341e828f01613169565b60408501526134306101608f01613169565b60608501526134426101808f01613169565b60808501526134546101a08f01613169565b60a08501526134666101c08f0161315e565b60c08501526134786101e08f01613169565b60e085015261348a6102008f01613174565b8385015261349b6102208f01613169565b81850152505050809150509295985092959850929598565b6000806000604084860312156134c7578081fd5b83356001600160401b03808211156134dd578283fd5b818601915086601f8301126134f0578283fd5b8135818111156134fe578384fd5b8760208083028501011115613511578384fd5b6020928301989097509590910135949350505050565b600060208284031215613538578081fd5b8151611c7181613e99565b60008060008060808587031215613558578182fd5b845161356381613e81565b602086015190945061357481613e81565b604086015190935061358581613e81565b606086015190925061359681613e81565b939692955090935050565b60008060008060008060c087890312156135b9578384fd5b86356135c481613e81565b955060208701356135d481613ebc565b9450604087013561331081613ebc565b6000806000806000806000806000806101408b8d031215613603578384fd5b8a3561360e81613e81565b995060208b013561361e81613e81565b985060408b013561362e81613ebc565b975060608b01356001600160401b03811115613648578485fd5b6136548d828e01612fa2565b97505060808b013561366581613ebc565b999c989b50969995989760a0870135975060c08701359660e08101359650610100810135955061012001359350915050565b600080600080600080600080888a036101c08112156136b4578283fd5b89356001600160401b03808211156136ca578485fd5b6136d68d838e01613011565b9a5060208c013591506136e882613e99565b90985060408b0135906136fa82613e99565b90975060608b0135965060808b0135955060a08b0135908082111561371d578485fd5b6137298d838e01612fa2565b9550608060bf198401121561373c578485fd5b6040519250608083019150828210818311171561375557fe5b5060405260c08a013561376781613e81565b815260e08a013561377781613e81565b60208201526101008a013561378b81613e81565b60408201526101208a013561379f81613e81565b606082015291506137b48a6101408b016130ed565b90509295985092959890939650565b600080600080600060a086880312156137da578283fd5b8535945060208601356137ec81613ecc565b935060408601356137fc81613e81565b94979396509394606081013594506080013592915050565b600080600080600060a0868803121561382b578283fd5b853561383681613ebc565b945060208601359350604086013592506060860135915060808601356001600160401b03811115613865578182fd5b61323988828901612fa2565b600080600080600060a08688031215613888578283fd5b853561389381613ebc565b945060208601356138a381613ebc565b935060408601356138b381613ebc565b925060608601356001600160401b038111156138cd578182fd5b6138d988828901612f22565b95989497509295608001359392505050565b6000806000806000806000806000806101408b8d03121561390a578384fd5b8a5161391581613ebc565b60208c0151909a5061392681613ecc565b60408c015190995061393781613ebc565b60608c015190985061394881613ebc565b60808c015190975061395981613ebc565b60a08c015190965061396a81613ebc565b60c08c015190955061397b81613ea7565b60e08c015190945061398c81613ebc565b6101008c015190935061399e81613ecc565b6101208c01519092506139b081613ebc565b809150509295989b9194979a5092959850565b60008060008060008060008060008060006101608c8e0312156139e4578485fd5b8b356139ef81613ebc565b9a5060208c01356139ff81613ecc565b995060408c0135613a0f81613ebc565b985060608c0135613a1f81613ebc565b975060808c0135613a2f81613ebc565b965060a08c0135613a3f81613ebc565b955060c08c0135613a4f81613ea7565b945060e08c0135613a5f81613ebc565b93506101008c0135613a7081613ecc565b9250613a7f6101208d01613169565b91506101408c013590509295989b509295989b9093969950565b600060208284031215613aaa578081fd5b5051919050565b600080600080600080600060e0888a031215613acb578081fd5b87359650602088013595506040880135613ae481613e99565b94506060880135613af481613e81565b9699959850939660808101359560a0820135955060c0909101359350915050565b600080600080600060a08688031215613b2c578283fd5b8551945060208601519350604086015192506060860151613b4c81613ecc565b80925050608086015190509295509295909350565b600060208284031215613b72578081fd5b8151611c7181613ecc565b60008151808452815b81811015613ba257602081850181015186830182015201613b86565b81811115613bb35782602083870101525b50601f01601f19169290920160200192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b038481168252831660208201526060604082018190526000906110b790830184613b7d565b6001600160a01b0385811682528416602082015261ffff83166040820152608060608201819052600090610aaf90830184613b7d565b901515815260200190565b6020808252818101527f446578446174613a20746f4465782077726f6e67206461746120666f726d6174604082015260600190565b60208082526028908201527f446578446174613a20746f41727261794c656e6774682077726f6e67206461746040820152671848199bdc9b585d60c21b606082015260800190565b60208082526003908201526244545360e81b604082015260600190565b6020808252600490820152632044545360e01b604082015260600190565b60208082526003908201526204242360ec1b604082015260600190565b602080825260039082015262444e5360e81b604082015260600190565b60208082526026908201527f446578446174613a20746f44657844657461696c2077726f6e67206461746120604082015265199bdc9b585d60d21b606082015260800190565b60208082526003908201526204344360ec1b604082015260600190565b6020808252600390820152620aa88b60eb1b604082015260600190565b60208082526003908201526213541560ea1b604082015260600190565b60208082526003908201526250524960e81b604082015260600190565b6020808252600390820152622baa2960e91b604082015260600190565b61ffff9290921682526001600160a01b0316602082015260400190565b90815260200190565b948552602085019390935260408401919091526060830152608082015260a00190565b6040518181016001600160401b0381118282101715613e7957fe5b604052919050565b6001600160a01b0381168114613e9657600080fd5b50565b8015158114613e9657600080fd5b6001600160801b0381168114613e9657600080fd5b61ffff81168114613e9657600080fd5b60ff81168114613e9657600080fdfe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220f860000d46d65893a7bc7cfd93f67c02e9e7bfd246b50df0db69bf0ee16e33f664736f6c63430007060033

Deployed Bytecode

0x73ae5b86c0c4415a61dc1f6e7b2305ad4ad0fca22f30146080604052600436106100ff5760003560e01c80635d50820c116100a1578063c19ef55011610070578063c19ef55014610273578063da6288c814610286578063f7f623b5146102a6578063f8df0a21146102c6576100ff565b80635d50820c146101fc57806385259f1c146102205780639c34edf914610240578063b8cdbe4114610260576100ff565b8063289e376f116100dd578063289e376f14610166578063291345221461019c5780634256bde0146101bc5780634a009e00146101dc576100ff565b80630462282014610104578063154f09681461012657806319ea053f14610146575b600080fd5b81801561011057600080fd5b5061012461011f3660046137c3565b6102e6565b005b81801561013257600080fd5b50610124610141366004613871565b61043c565b81801561015257600080fd5b50610124610161366004613286565b6104f8565b81801561017257600080fd5b50610186610181366004613286565b6105f9565b6040516101939190613e32565b60405180910390f35b8180156101a857600080fd5b506101246101b73660046139c3565b610691565b8180156101c857600080fd5b506101246101d73660046134b3565b610861565b6101ef6101ea3660046135a1565b610963565b6040516101939190613c41565b61020f61020a3660046132d6565b610ab9565b604051610193959493929190613e3b565b81801561022c57600080fd5b5061018661023b366004613ab1565b610ae8565b81801561024c57600080fd5b5061012461025b366004613246565b610caf565b61012461026e366004613697565b610d18565b6101ef6102813660046131b7565b610ed8565b81801561029257600080fd5b506101246102a1366004613814565b6110c0565b8180156102b257600080fd5b506101866102c1366004613363565b6111be565b8180156102d257600080fd5b506101246102e13660046135e4565b6113cf565b60ff84166103be5760058501546102fd9083611be3565b600586015560028501546001600160a01b0316600081815260208390526040908190205490516370a0823160e01b81526103b89286926103a3928792906370a082319061034e903090600401613bcb565b60206040518083038186803b15801561036657600080fd5b505afa15801561037a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039e9190613a99565b611c45565b60028801546001600160a01b03169190611c78565b50610435565b60068501546103cd9083611be3565b600686015560038501546001600160a01b0316600081815260208390526040908190205490516370a0823160e01b815261043392869261041e928792906370a082319061034e903090600401613bcb565b60038801546001600160a01b03169190611c78565b505b5050505050565b6127108561ffff16108015610455575060008461ffff16115b8015610462575060008251115b6104875760405162461bcd60e51b815260040161047e90613ddb565b60405180910390fd5b60038101805461ffff868116600160a01b0261ffff60a01b19918916600160b01b0261ffff60b01b19909316929092171617905581516104d09060078301906020850190612db3565b50600301805461ffff909316600160c01b0261ffff60c01b1990931692909217909155505050565b816001600160a01b0316836001600160a01b031614156105df57604051632e1a7d4d60e01b81526001600160a01b03831690632e1a7d4d9061053e908490600401613e32565b600060405180830381600087803b15801561055857600080fd5b505af115801561056c573d6000803e3d6000fd5b505050506000846001600160a01b03168260405161058990613bc8565b60006040518083038185875af1925050503d80600081146105c6576040519150601f19603f3d011682016040523d82523d6000602084013e6105cb565b606091505b50509050806105d957600080fd5b506105f3565b6104356001600160a01b0384168583611c78565b50505050565b6000826001600160a01b0316846001600160a01b0316141561067157826001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561065057600080fd5b505af1158015610664573d6000803e3d6000fd5b5050505050349050610689565b6106866001600160a01b038516863085611ea0565b90505b949350505050565b6127108b61ffff161080156106a9575060648a60ff16105b80156106b9575060008961ffff16115b80156106ca575060648761ffff1611155b80156106db575060648661ffff1611155b80156106ec57506127108461ffff16105b80156106fc575060008261ffff16115b6107185760405162461bcd60e51b815260040161047e90613ddb565b8a8160000160006101000a81548161ffff021916908361ffff160217905550898160000160026101000a81548160ff021916908360ff160217905550888160000160036101000a81548161ffff021916908361ffff160217905550878160000160056101000a81548161ffff021916908361ffff160217905550868160000160076101000a81548161ffff021916908361ffff160217905550858160000160096101000a81548161ffff021916908361ffff1602179055508481600001600b6101000a8154816001600160801b0302191690836001600160801b031602179055508381600001601b6101000a81548161ffff021916908361ffff1602179055508281600001601d6101000a81548160ff021916908360ff1602179055508181600001601e6101000a81548161ffff021916908361ffff1602179055505050505050505050505050565b60005b828110156105f357600084848381811061087a57fe5b905060200201602081019061088f919061317f565b90506000816001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016108bf9190613bcb565b60206040518083038186803b1580156108d757600080fd5b505afa1580156108eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090f9190613a99565b6001600160a01b0383166000908152602086905260409020549091501580156109385750600081115b15610959576001600160a01b03821660009081526020859052604090208190555b5050600101610864565b600061096e826120d2565b61097a57506000610aaf565b6000806000896001600160a01b031663a59a36ae88888c896040518563ffffffff1660e01b81526004016109b19493929190613c0b565b60a06040518083038186803b1580156109c957600080fd5b505afa1580156109dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a019190613b15565b9450509350935050610a208961ffff16826120ec90919063ffffffff16565b421015610a335760009350505050610aaf565b821580610a3e575081155b15610a4f5760019350505050610aaf565b60646000610a6784610a618785612146565b9061219f565b9050610a778261ffff8c166120ec565b81101580610a925750610a8e8261ffff8c16611be3565b8111155b15610aa557600195505050505050610aaf565b6000955050505050505b9695505050505050565b6000806000806000610ad18b8b8b8b8b60008c612206565b939f929e50909c509a509098509650505050505050565b600080610af58989611be3565b6001600160a01b038716600090815260208590526040902054909150610b1d908290876126a2565b90508891508615610c065780846005015410610b7f5760058401805482900390556001600160a01b038616600090815260208490526040902054610b619082611be3565b6001600160a01b038716600090815260208590526040902055610c01565b60058401546001600160a01b038716600090815260208590526040902054610ba8919087611c45565b9150610bb482896120ec565b60058501546001600160a01b038816600090815260208690526040902054919350610bdf9190611be3565b6001600160a01b03871660009081526020859052604081209190915560058501555b610ca3565b80846006015410610c21576006840180548290039055610ca3565b60068401546001600160a01b038716600090815260208590526040902054610c4a919087611c45565b9150610c5682896120ec565b60068501546001600160a01b038816600090815260208690526040902054919350610c819190611be3565b6001600160a01b03871660009081526020859052604081209190915560068501555b50979650505050505050565b6001600160a01b03831615801590610ccf57506001600160a01b03821615155b610ceb5760405162461bcd60e51b815260040161047e90613d84565b6001810180546001600160a01b03199081166001600160a01b039586161790915581541691909216179055565b600087151587151514610d2f578860600151610d35565b88604001515b90506000816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610d7257600080fd5b505afa158015610d86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610daa9190613b61565b60ff169050600060048211610dc0576001610dc8565b60048203600a0a5b9050600085604001516001600160a01b0316846001600160a01b031614610def5788610df1565b345b9050818111610e125760405162461bcd60e51b815260040161047e90613cc9565b610e298c6101400151610e24896126c8565b612716565b610e455760405162461bcd60e51b815260040161047e90613d21565b60608501516001600160801b0316610e805760008811610e775760405162461bcd60e51b815260040161047e90613d04565b50505050610ece565b846040015115158a1515148015610ead5750436001600160801b031685606001516001600160801b031614155b610ec95760405162461bcd60e51b815260040161047e90613ce6565b505050505b5050505050505050565b6000610ee2612e62565b610f2a878688610ef6578660600151610efc565b86604001515b89610f0b578760400151610f11565b87606001515b8a610f1d578851610f23565b88602001515b8b89612206565b60808601526060850152604080850191909152602084019190915290825280516302b2007560e31b81529051600091309163159003a89160048082019261014092909190829003018186803b158015610f8257600080fd5b505afa158015610f96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fba91906138eb565b509850505050505050505086156110175784610100015161ffff16826000015110158015610ff5575084610100015161ffff16826020015110155b801561100e575084610100015161ffff16826040015110155b925050506110b7565b8160800151826060015110156110725760006110498360600151610a616064866080015161214690919063ffffffff16565b90508160ff1660648203106110705760405162461bcd60e51b815260040161047e90613dbe565b505b84610100015161ffff16826000015110158061109b575084610100015161ffff16826020015110155b8061100e575084610100015161ffff1682604001511015925050505b95945050505050565b8254825460038601546002870154600093611105936001600160a01b039182169361ffff600160f01b909204821693600160c01b820490921692908116911687610963565b6002860154600387015491925060009161112c916001600160a01b03908116911685612789565b905080156111b5576004860180546001600160a01b0319163317905581156111b55760018501546040516313eb59bb60e31b81526001600160a01b0390911690639f5acdd890611182908a903390600401613e15565b600060405180830381600087803b15801561119c57600080fd5b505af11580156111b0573d6000803e3d6000fd5b505050505b50505050505050565b600383015460009081906111e69061271090610a61908d90600160b01b900461ffff16612146565b90508091508260c001516001600160801b0316886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016112259190613bcb565b60206040518083038186803b15801561123d57600080fd5b505afa158015611251573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112759190613a99565b11156112a8576112a561129e6064610a618660a0015161ffff168561214690919063ffffffff16565b8290611be3565b91505b60048501546001600160a01b038c8116911614156112ed576112ea6112e36064610a61866080015161ffff168561214690919063ffffffff16565b8390611be3565b91505b600061130e6064610a61866020015160ff168661214690919063ffffffff16565b905061132f8961131e8584611be3565b6001600160a01b038d169190611c78565b5061133b8189896126a2565b60038701549091506001600160a01b038b81169116141561136f57600686015461136590826120ec565b6006870155611384565b600586015461137e90826120ec565b60058701555b6001600160a01b038a166000908152602086905260409020546113a790826120ec565b6001600160a01b038b1660009081526020879052604090205550509998505050505050505050565b60008a6001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561140a57600080fd5b505afa15801561141e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611442919061319b565b905060008a6001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561147f57600080fd5b505afa158015611493573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114b7919061319b565b905060006114c48a612905565b90506114d08582612934565b80156114e8575060018601546001600160a01b031633145b80156115045750865461ffff63010000009091048116908c1610155b80156115165750620186a08b61ffff16105b6115325760405162461bcd60e51b815260040161047e90613da1565b600061153d8b61294e565b905062030d408160008151811061155057fe5b602002602001015162ffffff16108015611585575062030d408160018151811061157657fe5b602002602001015162ffffff16105b80156115ac575062030d408160028151811061159d57fe5b602002602001015162ffffff16105b80156115d3575062030d40816003815181106115c457fe5b602002602001015162ffffff16105b80156115fa575062030d40816004815181106115eb57fe5b602002602001015162ffffff16105b8015611621575062030d408160058151811061161257fe5b602002602001015162ffffff16105b61163d5760405162461bcd60e51b815260040161047e90613df8565b8060008151811061164a57fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b0389168352845280822082805290935291909120805462ffffff191662ffffff9092169190911790558051819060019081106116a757fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b0388168352845280822082805290935291909120805462ffffff191662ffffff90921691909117905580518190600290811061170457fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038916835284528082206001835290935291909120805462ffffff191662ffffff90921691909117905580518190600390811061176257fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038816835284528082206001835290935291909120805462ffffff191662ffffff9092169190911790558051819060049081106117c057fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038916835284528082206002835290935291909120805462ffffff191662ffffff90921691909117905580518190600590811061181e57fe5b60209081029190910181015161ffff8c16600090815287835260408082206001600160a01b038881168452908552818320600284529094529020805462ffffff191662ffffff90921691909117905561187d915084168e600019612a34565b506118946001600160a01b0383168d600019612a34565b50604080516001808252818301909252600091602080830190803683370190505090506118c08b6126c8565b816000815181106118cd57fe5b602002602001019063ffffffff16908163ffffffff16815250506040518061016001604052808f6001600160a01b031681526020018e6001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020018d61ffff1681526020018960000160009054906101000a900461ffff1661ffff1681526020018960000160059054906101000a900461ffff1661ffff16815260200160006001600160a01b031681526020016000815260200160008152602001828152508960008c61ffff1661ffff16815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160030160146101000a81548161ffff021916908361ffff16021790555060a08201518160030160166101000a81548161ffff021916908361ffff16021790555060c08201518160030160186101000a81548161ffff021916908361ffff16021790555060e08201518160040160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555061010082015181600501556101208201518160060155610140820151816007019080519060200190611b2a929190612db3565b50905050611b378b6120d2565b15611b4d57611b4784848d612789565b50611bd3565b60ff821660021415611bd3578660000160009054906101000a90046001600160a01b03166001600160a01b031663f18ef35985858e6040518463ffffffff1660e01b8152600401611ba093929190613bdf565b600060405180830381600087803b158015611bba57600080fd5b505af1158015611bce573d6000803e3d6000fd5b505050505b5050505050505050505050505050565b600082821115611c3a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b60008083118015611c565750600082115b15611c715782611c668386612146565b81611c6d57fe5b0490505b9392505050565b60008115611c71576000846001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015611ccf57600080fd5b505afa158015611ce3573d6000803e3d6000fd5b505050506040513d6020811015611cf957600080fd5b5051604080516001600160a01b038781166024830152604480830188905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825194955090891693919290918291908083835b60208310611d775780518252601f199092019160209182019101611d58565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611dd9576040519150601f19603f3d011682016040523d82523d6000602084013e611dde565b606091505b5050506000856001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015611e3057600080fd5b505afa158015611e44573d6000803e3d6000fd5b505050506040513d6020811015611e5a57600080fd5b50519050818111611e97576040805162461bcd60e51b81526020600482015260026024820152612a2360f11b604482015290519081900360640190fd5b03949350505050565b60008115610689576000856001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015611ef757600080fd5b505afa158015611f0b573d6000803e3d6000fd5b505050506040513d6020811015611f2157600080fd5b5051604080516001600160a01b0388811660248301528781166044830152606480830188905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17815292518251949550908a1693919290918291908083835b60208310611fa75780518252601f199092019160209182019101611f88565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612009576040519150601f19603f3d011682016040523d82523d6000602084013e61200e565b606091505b5050506000866001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561206057600080fd5b505afa158015612074573d6000803e3d6000fd5b505050506040513d602081101561208a57600080fd5b505190508181116120c8576040805162461bcd60e51b81526020600482015260036024820152622a232360e91b604482015290519081900360640190fd5b0395945050505050565b600060026120df83612905565b60ff16141590505b919050565b600082820183811015611c71576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60008261215557506000611c3f565b8282028284828161216257fe5b0414611c715760405162461bcd60e51b8152600401808060200182810382526021815260200180613edc6021913960400191505060405180910390fd5b60008082116121f5576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816121fe57fe5b049392505050565b6000806000806000612216612e91565b606081018c905260808082018890526001600160a01b03808d1683528b811660208401528e1660408084019190915261271060a0840152805163309d7f9560e21b81529051600092309263c275fe549260048083019392829003018186803b15801561228157600080fd5b505afa158015612295573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b99190613543565b50505090506000306001600160a01b031663159003a86040518163ffffffff1660e01b81526004016101406040518083038186803b1580156122fa57600080fd5b505afa15801561230e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061233291906138eb565b995050505050505050505060008a6123c95760408085015190516305eff7ef60e21b81526001600160a01b038e16916317bfdfbc916123749190600401613bcb565b60206040518083038186803b15801561238c57600080fd5b505afa1580156123a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123c49190613a99565b612449565b60408085015190516395dd919360e01b81526001600160a01b038e16916395dd9193916123f99190600401613bcb565b60206040518083038186803b15801561241157600080fd5b505afa158015612425573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124499190613a99565b90508061246e5750505060a0015161ffff169450849350839250829150819050612693565b8351602085015160808601516040516352cd1b5760e11b81526001600160a01b0387169363a59a36ae936124aa93919290918891600401613c0b565b60a06040518083038186803b1580156124c257600080fd5b505afa1580156124d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124fa9190613b15565b610140890181905260ff90911661012089015261010088019190915260e087019190915260c08601919091526125349061ffff84166120ec565b4211156125475760e08401516101008501525b600061257385610120015160ff16600a0a610a618760c00151886060015161214690919063ffffffff16565b90506000828210156125865760006125af565b6125af83610a618860a0015161ffff166125a98787611be390919063ffffffff16565b90612146565b90506125db86610120015160ff16600a0a610a618860e00151896060015161214690919063ffffffff16565b91506000838310156125ee576000612611565b61261184610a618960a0015161ffff166125a98888611be390919063ffffffff16565b905061263e87610120015160ff16600a0a610a618961010001518a6060015161214690919063ffffffff16565b9250600084841015612651576000612674565b61267485610a618a60a0015161ffff166125a98989611be390919063ffffffff16565b60c089015160e090990151939d50919b50909950959750955050505050505b97509750975097509792505050565b600080831180156126b35750600082115b6126bd5783610689565b81611c668486612146565b60006001825110156126ec5760405162461bcd60e51b815260040161047e90613d3e565b6126f5826120d2565b156127085750602081015160001a6120e7565b50602081015160e01c6120e7565b6000805b83518110156127825783818151811061272f57fe5b602002602001015163ffffffff166000141561274a57612782565b8263ffffffff1684828151811061275d57fe5b602002602001015163ffffffff16141561277a5760019150612782565b60010161271a565b5092915050565b600080306001600160a01b031663c275fe546040518163ffffffff1660e01b815260040160806040518083038186803b1580156127c557600080fd5b505afa1580156127d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127fd9190613543565b50505090506000306001600160a01b031663159003a86040518163ffffffff1660e01b81526004016101406040518083038186803b15801561283e57600080fd5b505afa158015612852573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061287691906138eb565b9950505050505050505050816001600160a01b03166315426c97878784886040518563ffffffff1660e01b81526004016128b39493929190613c0b565b602060405180830381600087803b1580156128cd57600080fd5b505af11580156128e1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaf9190613527565b60006001825110156129295760405162461bcd60e51b815260040161047e90613c4c565b506020015160001a90565b60ff90811660009081526020929092526040909120541690565b6060600061295b83612d84565b6003029050600560ff82166001600160401b038111801561297b57600080fd5b506040519080825280602002602001820160405280156129a5578160200160208202803683370190505b50925060005b8260ff16811015612a2c57818551116129e95760008482815181106129cc57fe5b602002602001019062ffffff16908162ffffff1681525050612a24565b84820160200151845160e882901c90869084908110612a0457fe5b602002602001019062ffffff16908162ffffff1681525050600383019250505b6001016129ab565b505050919050565b600080846001600160a01b031663dd62ed3e30866040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b031681526020019250505060206040518083038186803b158015612a9557600080fd5b505afa158015612aa9573d6000803e3d6000fd5b505050506040513d6020811015612abf57600080fd5b505115612be457604080516001600160a01b038681166024830152600060448084019190915283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b178152925182519189169390918291908083835b60208310612b405780518252601f199092019160209182019101612b21565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612ba2576040519150601f19603f3d011682016040523d82523d6000602084013e612ba7565b606091505b50508091505080612be4576040805162461bcd60e51b815260206004820152600260248201526120a360f11b604482015290519081900360640190fd5b604080516001600160a01b038681166024830152604480830187905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b178152925182519189169390918291908083835b60208310612c5b5780518252601f199092019160209182019101612c3c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612cbd576040519150601f19603f3d011682016040523d82523d6000602084013e612cc2565b606091505b50508091505080612cff576040805162461bcd60e51b815260206004820152600260248201526120a360f11b604482015290519081900360640190fd5b60408051636eb1769f60e11b81523060048201526001600160a01b03868116602483015291519187169163dd62ed3e91604480820192602092909190829003018186803b158015612d4f57600080fd5b505afa158015612d63573d6000803e3d6000fd5b505050506040513d6020811015612d7957600080fd5b505195945050505050565b6000600582511015612da85760405162461bcd60e51b815260040161047e90613c81565b506024015160001a90565b82805482825590600052602060002090600701600890048101928215612e525791602002820160005b83821115612e2057835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302612ddc565b8015612e505782816101000a81549063ffffffff0219169055600401602081600301049283019260010302612e20565b505b50612e5e929150612f0d565b5090565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b60405180610160016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016000815260200160608152602001600061ffff168152602001600081526020016000815260200160008152602001600060ff168152602001600081525090565b5b80821115612e5e5760008155600101612f0e565b600082601f830112612f32578081fd5b813560206001600160401b03821115612f4757fe5b808202612f55828201613e5e565b838152828101908684018388018501891015612f6f578687fd5b8693505b85841015610ca357803563ffffffff81168114612f8e578788fd5b835260019390930192918401918401612f73565b600082601f830112612fb2578081fd5b81356001600160401b03811115612fc557fe5b612fd8601f8201601f1916602001613e5e565b818152846020838601011115612fec578283fd5b816020850160208301379081016020019190915292915050565b80356120e781613e81565b6000610160808385031215613024578182fd5b61302d81613e5e565b91505061303982613006565b815261304760208301613006565b602082015261305860408301613006565b604082015261306960608301613006565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101006130a4818401613169565b908201526101206130b6838201613169565b90820152610140828101356001600160401b038111156130d557600080fd5b6130e185828601612f22565b82840152505092915050565b6000608082840312156130fe578081fd5b604051608081018181106001600160401b038211171561311a57fe5b80604052508091508235815260208301356020820152604083013561313e81613e99565b6040820152606083013561315181613ea7565b6060919091015292915050565b80356120e781613ea7565b80356120e781613ebc565b80356120e781613ecc565b600060208284031215613190578081fd5b8135611c7181613e81565b6000602082840312156131ac578081fd5b8151611c7181613e81565b600080600080600060a086880312156131ce578081fd5b85356131d981613e81565b945060208601356131e981613e99565b93506040860135925060608601356001600160401b038082111561320b578283fd5b61321789838a01613011565b9350608088013591508082111561322c578283fd5b5061323988828901612fa2565b9150509295509295909350565b60008060006060848603121561325a578081fd5b833561326581613e81565b9250602084013561327581613e81565b929592945050506040919091013590565b6000806000806080858703121561329b578182fd5b84356132a681613e81565b935060208501356132b681613e81565b925060408501356132c681613e81565b9396929550929360600135925050565b60008060008060008060c087890312156132ee578384fd5b86356132f981613e81565b955060208701359450604087013561331081613e81565b9350606087013561332081613e81565b9250608087013561333081613e81565b915060a08701356001600160401b0381111561334a578182fd5b61335689828a01612fa2565b9150509295509295509295565b6000806000806000806000806000898b03610240811215613382578788fd5b8a3561338d81613e81565b995060208b0135985060408b01356133a481613e81565b975060608b01356133b481613e81565b965060808b0135955060a08b0135945060c08b0135935060e08b0135925061010061014060ff1983018113156133e8578384fd5b6133f181613e5e565b92506133fe828e01613169565b835261012061340e818f01613174565b602085015261341e828f01613169565b60408501526134306101608f01613169565b60608501526134426101808f01613169565b60808501526134546101a08f01613169565b60a08501526134666101c08f0161315e565b60c08501526134786101e08f01613169565b60e085015261348a6102008f01613174565b8385015261349b6102208f01613169565b81850152505050809150509295985092959850929598565b6000806000604084860312156134c7578081fd5b83356001600160401b03808211156134dd578283fd5b818601915086601f8301126134f0578283fd5b8135818111156134fe578384fd5b8760208083028501011115613511578384fd5b6020928301989097509590910135949350505050565b600060208284031215613538578081fd5b8151611c7181613e99565b60008060008060808587031215613558578182fd5b845161356381613e81565b602086015190945061357481613e81565b604086015190935061358581613e81565b606086015190925061359681613e81565b939692955090935050565b60008060008060008060c087890312156135b9578384fd5b86356135c481613e81565b955060208701356135d481613ebc565b9450604087013561331081613ebc565b6000806000806000806000806000806101408b8d031215613603578384fd5b8a3561360e81613e81565b995060208b013561361e81613e81565b985060408b013561362e81613ebc565b975060608b01356001600160401b03811115613648578485fd5b6136548d828e01612fa2565b97505060808b013561366581613ebc565b999c989b50969995989760a0870135975060c08701359660e08101359650610100810135955061012001359350915050565b600080600080600080600080888a036101c08112156136b4578283fd5b89356001600160401b03808211156136ca578485fd5b6136d68d838e01613011565b9a5060208c013591506136e882613e99565b90985060408b0135906136fa82613e99565b90975060608b0135965060808b0135955060a08b0135908082111561371d578485fd5b6137298d838e01612fa2565b9550608060bf198401121561373c578485fd5b6040519250608083019150828210818311171561375557fe5b5060405260c08a013561376781613e81565b815260e08a013561377781613e81565b60208201526101008a013561378b81613e81565b60408201526101208a013561379f81613e81565b606082015291506137b48a6101408b016130ed565b90509295985092959890939650565b600080600080600060a086880312156137da578283fd5b8535945060208601356137ec81613ecc565b935060408601356137fc81613e81565b94979396509394606081013594506080013592915050565b600080600080600060a0868803121561382b578283fd5b853561383681613ebc565b945060208601359350604086013592506060860135915060808601356001600160401b03811115613865578182fd5b61323988828901612fa2565b600080600080600060a08688031215613888578283fd5b853561389381613ebc565b945060208601356138a381613ebc565b935060408601356138b381613ebc565b925060608601356001600160401b038111156138cd578182fd5b6138d988828901612f22565b95989497509295608001359392505050565b6000806000806000806000806000806101408b8d03121561390a578384fd5b8a5161391581613ebc565b60208c0151909a5061392681613ecc565b60408c015190995061393781613ebc565b60608c015190985061394881613ebc565b60808c015190975061395981613ebc565b60a08c015190965061396a81613ebc565b60c08c015190955061397b81613ea7565b60e08c015190945061398c81613ebc565b6101008c015190935061399e81613ecc565b6101208c01519092506139b081613ebc565b809150509295989b9194979a5092959850565b60008060008060008060008060008060006101608c8e0312156139e4578485fd5b8b356139ef81613ebc565b9a5060208c01356139ff81613ecc565b995060408c0135613a0f81613ebc565b985060608c0135613a1f81613ebc565b975060808c0135613a2f81613ebc565b965060a08c0135613a3f81613ebc565b955060c08c0135613a4f81613ea7565b945060e08c0135613a5f81613ebc565b93506101008c0135613a7081613ecc565b9250613a7f6101208d01613169565b91506101408c013590509295989b509295989b9093969950565b600060208284031215613aaa578081fd5b5051919050565b600080600080600080600060e0888a031215613acb578081fd5b87359650602088013595506040880135613ae481613e99565b94506060880135613af481613e81565b9699959850939660808101359560a0820135955060c0909101359350915050565b600080600080600060a08688031215613b2c578283fd5b8551945060208601519350604086015192506060860151613b4c81613ecc565b80925050608086015190509295509295909350565b600060208284031215613b72578081fd5b8151611c7181613ecc565b60008151808452815b81811015613ba257602081850181015186830182015201613b86565b81811115613bb35782602083870101525b50601f01601f19169290920160200192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b038481168252831660208201526060604082018190526000906110b790830184613b7d565b6001600160a01b0385811682528416602082015261ffff83166040820152608060608201819052600090610aaf90830184613b7d565b901515815260200190565b6020808252818101527f446578446174613a20746f4465782077726f6e67206461746120666f726d6174604082015260600190565b60208082526028908201527f446578446174613a20746f41727261794c656e6774682077726f6e67206461746040820152671848199bdc9b585d60c21b606082015260800190565b60208082526003908201526244545360e81b604082015260600190565b6020808252600490820152632044545360e01b604082015260600190565b60208082526003908201526204242360ec1b604082015260600190565b602080825260039082015262444e5360e81b604082015260600190565b60208082526026908201527f446578446174613a20746f44657844657461696c2077726f6e67206461746120604082015265199bdc9b585d60d21b606082015260800190565b60208082526003908201526204344360ec1b604082015260600190565b6020808252600390820152620aa88b60eb1b604082015260600190565b60208082526003908201526213541560ea1b604082015260600190565b60208082526003908201526250524960e81b604082015260600190565b6020808252600390820152622baa2960e91b604082015260600190565b61ffff9290921682526001600160a01b0316602082015260400190565b90815260200190565b948552602085019390935260408401919091526060830152608082015260a00190565b6040518181016001600160401b0381118282101715613e7957fe5b604052919050565b6001600160a01b0381168114613e9657600080fd5b50565b8015158114613e9657600080fd5b6001600160801b0381168114613e9657600080fd5b61ffff81168114613e9657600080fd5b60ff81168114613e9657600080fdfe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220f860000d46d65893a7bc7cfd93f67c02e9e7bfd246b50df0db69bf0ee16e33f664736f6c63430007060033

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