Contract 0x6Ba75f25251b3F6361ACa5E873c04821a2916E83

  Note: Our ETH balance display is temporarily unavailable. Please check back later.

Contract Overview

Balance:
Txn Hash Method
Block
From
To
Value
0x8f51109e95fc9be73fa6ab58c206a7f468f68a581cba2778ec0ebbafa38225cb0x60806040179767232023-11-30 21:58:34175 days 14 hrs ago0xd866b2332d4383c1bf719732177e2d9109c99dbc IN  Create: SportsAMMUtils0 ETH0.0000000319640.00001
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SportsAMMUtils

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 24 : SportsAMMUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol";
import "../interfaces/ISportPositionalMarket.sol";
import "../interfaces/ISportPositionalMarketManager.sol";
import "../interfaces/IPosition.sol";
import "../interfaces/ITherundownConsumer.sol";
import "../interfaces/ISportsAMM.sol";
import "../interfaces/ISportAMMRiskManager.sol";

import "./LiquidityPool/SportAMMLiquidityPool.sol";

/// @title Sports AMM utils
contract SportsAMMUtils {
    uint private constant ONE = 1e18;
    uint private constant ZERO_POINT_ONE = 1e17;
    uint private constant ONE_PERCENT = 1e16;
    uint private constant MAX_APPROVAL = type(uint256).max;
    int private constant ONE_INT = 1e18;
    int private constant ONE_PERCENT_INT = 1e16;
    uint public constant TAG_NUMBER_PLAYERS = 10010;

    ISportsAMM public sportsAMM;

    constructor(address _sportsAMM) {
        sportsAMM = ISportsAMM(_sportsAMM);
    }

    struct DiscountParams {
        uint balancePosition;
        uint balanceOtherSide;
        uint amount;
        uint availableToBuyFromAMM;
        uint max_spread;
    }

    struct NegativeDiscountsParams {
        uint amount;
        uint balancePosition;
        uint balanceOtherSide;
        uint _availableToBuyFromAMMOtherSide;
        uint _availableToBuyFromAMM;
        uint pricePosition;
        uint priceOtherPosition;
        uint max_spread;
    }

    struct PriceImpactParams {
        address market;
        ISportsAMM.Position position;
        uint amount;
        uint _availableToBuyFromAMM;
        uint _availableToBuyFromAMMOtherSide;
        SportAMMLiquidityPool liquidityPool;
        uint max_spread;
        uint minSupportedOdds;
    }

    struct AvailableHigher {
        address market;
        ISportsAMM.Position positionFirst;
        ISportsAMM.Position positionSecond;
        bool inverse;
        address marketPool;
        uint minOdds;
        uint cap;
        uint maxSpreadForMarket;
        uint spentOnGame;
    }

    function buyPriceImpactImbalancedSkew(
        uint amount,
        uint balanceOtherSide,
        uint balancePosition,
        uint balanceOtherSideAfter,
        uint balancePositionAfter,
        uint availableToBuyFromAMM,
        uint max_spread
    ) public view returns (uint) {
        uint maxPossibleSkew = balanceOtherSide + availableToBuyFromAMM - balancePosition;
        uint skew = balanceOtherSideAfter - (balancePositionAfter);
        uint newImpact = (max_spread * ((skew * ONE) / (maxPossibleSkew))) / ONE;
        if (balancePosition > 0) {
            uint newPriceForMintedOnes = newImpact / 2;
            uint tempMultiplier = (amount - balancePosition) * newPriceForMintedOnes;
            return (tempMultiplier * ONE) / (amount) / ONE;
        } else {
            uint previousSkew = balanceOtherSide;
            uint previousImpact = (max_spread * ((previousSkew * ONE) / maxPossibleSkew)) / ONE;
            return (newImpact + previousImpact) / 2;
        }
    }

    function calculateDiscount(DiscountParams memory params) public view returns (int) {
        uint currentBuyImpactOtherSide = buyPriceImpactImbalancedSkew(
            params.amount,
            params.balancePosition,
            params.balanceOtherSide,
            params.balanceOtherSide > ONE
                ? params.balancePosition
                : params.balancePosition + (ONE - params.balanceOtherSide),
            params.balanceOtherSide > ONE ? params.balanceOtherSide - ONE : 0,
            params.availableToBuyFromAMM,
            params.max_spread
        );

        uint startDiscount = currentBuyImpactOtherSide;
        uint tempMultiplier = params.balancePosition - params.amount;
        uint finalDiscount = ((startDiscount / 2) * ((tempMultiplier * ONE) / params.balancePosition + ONE)) / ONE;

        return -int(finalDiscount);
    }

    function calculateDiscountFromNegativeToPositive(NegativeDiscountsParams memory params)
        public
        view
        returns (int priceImpact)
    {
        uint amountToBeMinted = params.amount - params.balancePosition;
        uint sum1 = params.balanceOtherSide + params.balancePosition;
        uint sum2 = params.balanceOtherSide + amountToBeMinted;
        uint red3 = params._availableToBuyFromAMM - params.balancePosition;
        uint positiveSkew = buyPriceImpactImbalancedSkew(amountToBeMinted, sum1, 0, sum2, 0, red3, params.max_spread);

        uint skew = (params.priceOtherPosition * positiveSkew) / params.pricePosition;

        int discount = calculateDiscount(
            DiscountParams(
                params.balancePosition,
                params.balanceOtherSide,
                params.balancePosition,
                params._availableToBuyFromAMMOtherSide,
                params.max_spread
            )
        );

        int discountBalance = int(params.balancePosition) * discount;
        int discountMinted = int(amountToBeMinted * skew);
        int amountInt = int(params.balancePosition + amountToBeMinted);

        priceImpact = (discountBalance + discountMinted) / amountInt;

        if (priceImpact > 0) {
            int numerator = int(params.pricePosition) * priceImpact;
            priceImpact = numerator / int(params.priceOtherPosition);
        }
    }

    function calculateTempQuote(
        int skewImpact,
        uint baseOdds,
        uint safeBoxImpact,
        uint amount
    ) public pure returns (int tempQuote) {
        if (skewImpact >= 0) {
            int impactPrice = ((ONE_INT - int(baseOdds)) * skewImpact) / ONE_INT;
            // add 2% to the price increase to avoid edge cases on the extremes
            impactPrice = (impactPrice * (ONE_INT + (ONE_PERCENT_INT * 2))) / ONE_INT;
            tempQuote = (int(amount) * (int(baseOdds) + impactPrice)) / ONE_INT;
        } else {
            tempQuote = ((int(amount)) * ((int(baseOdds) * (ONE_INT + skewImpact)) / ONE_INT)) / ONE_INT;
        }
        tempQuote = (tempQuote * (ONE_INT + (int(safeBoxImpact)))) / ONE_INT;
    }

    function calculateAvailableToBuy(
        uint capUsed,
        uint spentOnThisGame,
        uint baseOdds,
        uint balance,
        uint max_spread
    ) public pure returns (uint availableAmount) {
        uint discountedPrice = (baseOdds * (ONE - max_spread / 2)) / ONE;
        uint additionalBufferFromSelling = (balance * discountedPrice) / ONE;
        if ((capUsed + additionalBufferFromSelling) > spentOnThisGame) {
            uint availableUntilCapSUSD = capUsed + additionalBufferFromSelling - spentOnThisGame;
            if (availableUntilCapSUSD > capUsed) {
                availableUntilCapSUSD = capUsed;
            }

            uint midImpactPriceIncrease = ((ONE - baseOdds) * (max_spread / 2)) / ONE;
            uint divider_price = ONE - (baseOdds + midImpactPriceIncrease);

            availableAmount = balance + ((availableUntilCapSUSD * ONE) / divider_price);
        }
    }

    function getCanExercize(address market, address toCheck) public view returns (bool canExercize) {
        if (
            ISportPositionalMarketManager(sportsAMM.manager()).isKnownMarket(market) &&
            !ISportPositionalMarket(market).paused() &&
            ISportPositionalMarket(market).resolved()
        ) {
            (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions();
            if (_hasNotBeenInitialized(home)) {
                return false;
            }
            if (
                (home.getBalanceOf(address(toCheck)) > 0) ||
                (away.getBalanceOf(address(toCheck)) > 0) ||
                (ISportPositionalMarket(market).optionsCount() > 2 && draw.getBalanceOf(address(toCheck)) > 0)
            ) {
                canExercize = true;
            }
        }
    }

    function obtainOdds(address _market, ISportsAMM.Position _position) public view returns (uint oddsToReturn) {
        address theRundownConsumer = sportsAMM.theRundownConsumer();
        ISportAMMRiskManager riskManager = sportsAMM.riskManager();
        if (ISportPositionalMarket(_market).optionsCount() > uint(_position)) {
            uint[] memory odds = new uint[](ISportPositionalMarket(_market).optionsCount());
            odds = ITherundownConsumer(theRundownConsumer).getNormalizedOddsForMarket(_market);
            (uint firstTag, uint secondTag, uint thirdTag) = _getTagsForMarket(_market);
            if (secondTag == TAG_NUMBER_PLAYERS) {
                if (!riskManager.isMarketForPlayerPropsOnePositional(thirdTag) || uint(_position) == 0) {
                    oddsToReturn = odds[uint(_position)];
                }
            } else {
                if ((!riskManager.isMarketForSportOnePositional(firstTag) || uint(_position) == 0)) {
                    oddsToReturn = odds[uint(_position)];
                }
            }
        }
    }

    function obtainOddsMulti(
        address _market,
        ISportsAMM.Position _position1,
        ISportsAMM.Position _position2
    ) public view returns (uint oddsToReturn1, uint oddsToReturn2) {
        address theRundownConsumer = sportsAMM.theRundownConsumer();
        uint positionsCount = ISportPositionalMarket(_market).optionsCount();
        uint[] memory odds = new uint[](ISportPositionalMarket(_market).optionsCount());
        odds = ITherundownConsumer(theRundownConsumer).getNormalizedOddsForMarket(_market);
        if (positionsCount > uint(_position1)) {
            oddsToReturn1 = odds[uint(_position1)];
        }
        if (positionsCount > uint(_position2)) {
            oddsToReturn2 = odds[uint(_position2)];
        }
    }

    function getBalanceOtherSideOnThreePositions(
        ISportsAMM.Position position,
        address addressToCheck,
        address market
    ) public view returns (uint balanceOfTheOtherSide) {
        (uint homeBalance, uint awayBalance, uint drawBalance) = getBalanceOfPositionsOnMarket(market, addressToCheck);
        if (position == ISportsAMM.Position.Home) {
            balanceOfTheOtherSide = awayBalance < drawBalance ? awayBalance : drawBalance;
        } else if (position == ISportsAMM.Position.Away) {
            balanceOfTheOtherSide = homeBalance < drawBalance ? homeBalance : drawBalance;
        } else {
            balanceOfTheOtherSide = homeBalance < awayBalance ? homeBalance : awayBalance;
        }
    }

    function getBalanceOfPositionsOnMarket(address market, address addressToCheck)
        public
        view
        returns (
            uint homeBalance,
            uint awayBalance,
            uint drawBalance
        )
    {
        (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions();
        if (_hasNotBeenInitialized(home)) {
            return (0, 0, 0);
        }
        homeBalance = home.getBalanceOf(addressToCheck);
        awayBalance = away.getBalanceOf(addressToCheck);
        if (ISportPositionalMarket(market).optionsCount() == 3) {
            drawBalance = draw.getBalanceOf(addressToCheck);
        }
    }

    function getBalanceOfPositionsOnMarketByPositions(
        address market,
        address addressToCheck,
        ISportsAMM.Position position1,
        ISportsAMM.Position position2
    ) public view returns (uint firstBalance, uint secondBalance) {
        (uint homeBalance, uint awayBalance, uint drawBalance) = getBalanceOfPositionsOnMarket(market, addressToCheck);
        firstBalance = position1 == ISportsAMM.Position.Home ? homeBalance : position1 == ISportsAMM.Position.Away
            ? awayBalance
            : drawBalance;
        secondBalance = position2 == ISportsAMM.Position.Home ? homeBalance : position2 == ISportsAMM.Position.Away
            ? awayBalance
            : drawBalance;
    }

    function balanceOfPositionsOnMarket(
        address market,
        ISportsAMM.Position position,
        address addressToCheck
    )
        public
        view
        returns (
            uint,
            uint,
            uint
        )
    {
        (IPosition home, IPosition away, ) = ISportPositionalMarket(market).getOptions();
        if (_hasNotBeenInitialized(home)) {
            return (0, 0, 0);
        }
        uint balance = position == ISportsAMM.Position.Home
            ? home.getBalanceOf(addressToCheck)
            : away.getBalanceOf(addressToCheck);
        uint balanceOtherSideMax = position == ISportsAMM.Position.Home
            ? away.getBalanceOf(addressToCheck)
            : home.getBalanceOf(addressToCheck);
        uint balanceOtherSideMin = balanceOtherSideMax;
        if (ISportPositionalMarket(market).optionsCount() == 3) {
            (uint homeBalance, uint awayBalance, uint drawBalance) = getBalanceOfPositionsOnMarket(market, addressToCheck);
            if (position == ISportsAMM.Position.Home) {
                balance = homeBalance;
                if (awayBalance < drawBalance) {
                    balanceOtherSideMax = drawBalance;
                    balanceOtherSideMin = awayBalance;
                } else {
                    balanceOtherSideMax = awayBalance;
                    balanceOtherSideMin = drawBalance;
                }
            } else if (position == ISportsAMM.Position.Away) {
                balance = awayBalance;
                if (homeBalance < drawBalance) {
                    balanceOtherSideMax = drawBalance;
                    balanceOtherSideMin = homeBalance;
                } else {
                    balanceOtherSideMax = homeBalance;
                    balanceOtherSideMin = drawBalance;
                }
            } else if (position == ISportsAMM.Position.Draw) {
                balance = drawBalance;
                if (homeBalance < awayBalance) {
                    balanceOtherSideMax = awayBalance;
                    balanceOtherSideMin = homeBalance;
                } else {
                    balanceOtherSideMax = homeBalance;
                    balanceOtherSideMin = awayBalance;
                }
            }
        }
        return (balance, balanceOtherSideMax, balanceOtherSideMin);
    }

    function balanceOfPositionOnMarket(
        address market,
        ISportsAMM.Position position,
        address addressToCheck
    ) public view returns (uint) {
        (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions();
        if (_hasNotBeenInitialized(home)) {
            return 0;
        }
        uint balance = position == ISportsAMM.Position.Home
            ? home.getBalanceOf(addressToCheck)
            : away.getBalanceOf(addressToCheck);
        if (ISportPositionalMarket(market).optionsCount() == 3 && position != ISportsAMM.Position.Home) {
            balance = position == ISportsAMM.Position.Away
                ? away.getBalanceOf(addressToCheck)
                : draw.getBalanceOf(addressToCheck);
        }
        return balance;
    }

    function getParentMarketPositions(address market)
        public
        view
        returns (
            ISportsAMM.Position position1,
            ISportsAMM.Position position2,
            address parentMarket
        )
    {
        ISportPositionalMarket parentMarketContract = ISportPositionalMarket(market).parentMarket();
        (IPosition home, IPosition away, ) = parentMarketContract.getOptions();
        parentMarket = address(parentMarketContract);
        if (_hasNotBeenInitialized(home)) {
            (uint parentPosition1, uint parentPosition2) = ISportPositionalMarket(market).getParentMarketPositionsUint();
            position1 = parentPosition1 == 0 ? ISportsAMM.Position.Home : parentPosition1 == 1
                ? ISportsAMM.Position.Away
                : ISportsAMM.Position.Draw;
            position2 = parentPosition2 == 0 ? ISportsAMM.Position.Home : parentPosition2 == 1
                ? ISportsAMM.Position.Away
                : ISportsAMM.Position.Draw;
        } else {
            (IPosition parentPosition1, IPosition parentPosition2) = ISportPositionalMarket(market)
                .getParentMarketPositions();
            position1 = parentPosition1 == home ? ISportsAMM.Position.Home : parentPosition1 == away
                ? ISportsAMM.Position.Away
                : ISportsAMM.Position.Draw;
            position2 = parentPosition2 == home ? ISportsAMM.Position.Home : parentPosition2 == away
                ? ISportsAMM.Position.Away
                : ISportsAMM.Position.Draw;
        }
    }

    function getParentMarketPositionsImpactDoubleChance(address market, uint amount) public view returns (int) {
        (ISportsAMM.Position position1, ISportsAMM.Position position2, address parentMarket) = getParentMarketPositions(
            market
        );

        int firstPriceImpact = sportsAMM.buyPriceImpact(parentMarket, position1, amount);
        int secondPriceImpact = sportsAMM.buyPriceImpact(parentMarket, position2, amount);

        return (firstPriceImpact + secondPriceImpact) / 2;
    }

    function getParentMarketPositionAddresses(address market)
        public
        view
        returns (address parentMarketPosition1, address parentMarketPosition2)
    {
        (IPosition position1, IPosition position2) = ISportPositionalMarket(market).getParentMarketPositions();

        parentMarketPosition1 = address(position1);
        parentMarketPosition2 = address(position2);
    }

    function getBaseOddsForDoubleChance(address market, uint minSupportedOdds)
        public
        view
        returns (uint oddsPosition1, uint oddsPosition2)
    {
        (ISportsAMM.Position position1, ISportsAMM.Position position2, address parentMarket) = getParentMarketPositions(
            market
        );
        oddsPosition1 = obtainOdds(parentMarket, position1);
        oddsPosition2 = obtainOdds(parentMarket, position2);

        if (oddsPosition1 > 0 && oddsPosition2 > 0) {
            oddsPosition1 = oddsPosition1 < minSupportedOdds ? minSupportedOdds : oddsPosition1;
            oddsPosition2 = oddsPosition2 < minSupportedOdds ? minSupportedOdds : oddsPosition2;
        }
    }

    function getBaseOddsForDoubleChanceSum(address market, uint minSupportedOdds) public view returns (uint sum) {
        (uint oddsPosition1, uint oddsPosition2) = getBaseOddsForDoubleChance(market, minSupportedOdds);

        sum = oddsPosition1 + oddsPosition2;
    }

    function getBuyPriceImpact(PriceImpactParams memory params) public view returns (int priceImpact) {
        (uint balancePosition, , uint balanceOtherSide) = balanceOfPositionsOnMarket(
            params.market,
            params.position,
            params.liquidityPool.getMarketPool(params.market)
        );
        bool isTwoPositional = ISportPositionalMarket(params.market).optionsCount() == 2;
        uint balancePositionAfter = balancePosition > params.amount ? balancePosition - params.amount : 0;
        uint balanceOtherSideAfter = balancePosition > params.amount
            ? balanceOtherSide
            : balanceOtherSide + (params.amount - balancePosition);
        if (params.amount <= balancePosition) {
            priceImpact = calculateDiscount(
                DiscountParams(
                    balancePosition,
                    balanceOtherSide,
                    params.amount,
                    params._availableToBuyFromAMMOtherSide,
                    params.max_spread
                )
            );
        } else {
            if (balancePosition > 0) {
                uint pricePosition = _obtainOdds(params.market, params.position, params.minSupportedOdds);
                uint priceOtherPosition = isTwoPositional
                    ? _obtainOdds(
                        params.market,
                        params.position == ISportsAMM.Position.Home ? ISportsAMM.Position.Away : ISportsAMM.Position.Home,
                        params.minSupportedOdds
                    )
                    : ONE - pricePosition;
                priceImpact = calculateDiscountFromNegativeToPositive(
                    NegativeDiscountsParams(
                        params.amount,
                        balancePosition,
                        balanceOtherSide,
                        params._availableToBuyFromAMMOtherSide,
                        params._availableToBuyFromAMM,
                        pricePosition,
                        priceOtherPosition,
                        params.max_spread
                    )
                );
            } else {
                priceImpact = int(
                    buyPriceImpactImbalancedSkew(
                        params.amount,
                        balanceOtherSide,
                        balancePosition,
                        balanceOtherSideAfter,
                        balancePositionAfter,
                        params._availableToBuyFromAMM,
                        params.max_spread
                    )
                );
            }
        }
    }

    function _obtainOdds(
        address _market,
        ISportsAMM.Position _position,
        uint minSupportedOdds
    ) internal view returns (uint) {
        if (ISportPositionalMarket(_market).isDoubleChance()) {
            if (_position == ISportsAMM.Position.Home) {
                return getBaseOddsForDoubleChanceSum(_market, minSupportedOdds);
            }
        }
        return obtainOdds(_market, _position);
    }

    function _getTagsForMarket(address _market)
        internal
        view
        returns (
            uint tag1,
            uint tag2,
            uint tag3
        )
    {
        ISportPositionalMarket sportMarket = ISportPositionalMarket(_market);
        tag1 = sportMarket.tags(0);
        tag2 = sportMarket.isChild() ? sportMarket.tags(1) : 0;
        tag3 = sportMarket.isChild() && sportMarket.tags(1) == TAG_NUMBER_PLAYERS ? sportMarket.tags(2) : 0;
    }

    function getAvailableHigherForPositions(AvailableHigher memory params) public view returns (uint _availableHigher) {
        (uint baseOddsFirst, uint baseOddsSecond) = obtainOddsMulti(
            params.market,
            params.positionFirst,
            params.positionSecond
        );

        baseOddsFirst = baseOddsFirst < params.minOdds ? params.minOdds : baseOddsFirst;
        baseOddsSecond = baseOddsSecond < params.minOdds ? params.minOdds : baseOddsSecond;

        (uint balanceFirst, uint balanceSecond) = getBalanceOfPositionsOnMarketByPositions(
            params.market,
            params.marketPool,
            params.positionFirst,
            params.positionSecond
        );
        uint _availableOtherSideFirst = calculateAvailableToBuy(
            params.cap,
            params.spentOnGame,
            baseOddsFirst,
            baseOddsFirst,
            params.maxSpreadForMarket
        );

        uint _availableOtherSideSecond = calculateAvailableToBuy(
            params.cap,
            params.spentOnGame,
            baseOddsSecond,
            balanceSecond,
            params.maxSpreadForMarket
        );

        _availableHigher = _availableOtherSideFirst;
        if (
            (params.inverse && _availableOtherSideFirst > _availableOtherSideSecond) ||
            (!params.inverse && _availableOtherSideFirst <= _availableOtherSideSecond)
        ) {
            _availableHigher = _availableOtherSideSecond;
        }
    }

    function _hasNotBeenInitialized(IPosition home) internal view returns (bool) {
        return address(home) == address(0);
    }
}

File 2 of 24 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

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

    function safeTransferFrom(
        IERC20Upgradeable token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

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

    function safeDecreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 4 of 24 : ISportPositionalMarket.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.16;

import "../interfaces/IPositionalMarketManager.sol";
import "../interfaces/IPosition.sol";
import "../interfaces/IPriceFeed.sol";

interface ISportPositionalMarket {
    /* ========== TYPES ========== */

    enum Phase {
        Trading,
        Maturity,
        Expiry
    }
    enum Side {
        Cancelled,
        Home,
        Away,
        Draw
    }

    /* ========== VIEWS / VARIABLES ========== */

    function getOptions()
        external
        view
        returns (
            IPosition home,
            IPosition away,
            IPosition draw
        );

    function times() external view returns (uint maturity, uint destruction);

    function getGameDetails() external view returns (bytes32 gameId, string memory gameLabel);

    function getGameId() external view returns (bytes32);

    function deposited() external view returns (uint);

    function optionsCount() external view returns (uint);

    function creator() external view returns (address);

    function resolved() external view returns (bool);

    function cancelled() external view returns (bool);

    function paused() external view returns (bool);

    function phase() external view returns (Phase);

    function canResolve() external view returns (bool);

    function result() external view returns (Side);

    function isChild() external view returns (bool);

    function optionsInitialized() external view returns (bool);

    function tags(uint idx) external view returns (uint);

    function getTags() external view returns (uint tag1, uint tag2);

    function getTagsLength() external view returns (uint tagsLength);

    function getParentMarketPositions() external view returns (IPosition position1, IPosition position2);

    function getParentMarketPositionsUint() external view returns (uint position1, uint position2);

    function getStampedOdds()
        external
        view
        returns (
            uint,
            uint,
            uint
        );

    function balancesOf(address account)
        external
        view
        returns (
            uint home,
            uint away,
            uint draw
        );

    function totalSupplies()
        external
        view
        returns (
            uint home,
            uint away,
            uint draw
        );

    function isDoubleChance() external view returns (bool);

    function parentMarket() external view returns (ISportPositionalMarket);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function setPaused(bool _paused) external;

    function updateDates(uint256 _maturity, uint256 _expiry) external;

    function mint(uint value) external;

    function exerciseOptions() external;

    function restoreInvalidOdds(
        uint _homeOdds,
        uint _awayOdds,
        uint _drawOdds
    ) external;
}

File 5 of 24 : ISportPositionalMarketManager.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../interfaces/ISportPositionalMarket.sol";

interface ISportPositionalMarketManager {
    /* ========== VIEWS / VARIABLES ========== */

    function marketCreationEnabled() external view returns (bool);

    function totalDeposited() external view returns (uint);

    function numActiveMarkets() external view returns (uint);

    function activeMarkets(uint index, uint pageSize) external view returns (address[] memory);

    function numMaturedMarkets() external view returns (uint);

    function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory);

    function isActiveMarket(address candidate) external view returns (bool);

    function isDoubleChanceMarket(address candidate) external view returns (bool);

    function doesSportSupportDoubleChance(uint _sport) external view returns (bool);

    function isDoubleChanceSupported() external view returns (bool);

    function isKnownMarket(address candidate) external view returns (bool);

    function getActiveMarketAddress(uint _index) external view returns (address);

    function transformCollateral(uint value) external view returns (uint);

    function reverseTransformCollateral(uint value) external view returns (uint);

    function isMarketPaused(address _market) external view returns (bool);

    function expiryDuration() external view returns (uint);

    function isWhitelistedAddress(address _address) external view returns (bool);

    function getOddsObtainer() external view returns (address obtainer);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function createMarket(
        bytes32 gameId,
        string memory gameLabel,
        uint maturity,
        uint initialMint, // initial sUSD to mint options for,
        uint positionCount,
        uint[] memory tags,
        bool isChild,
        address parentMarket
    ) external returns (ISportPositionalMarket);

    function setMarketPaused(address _market, bool _paused) external;

    function updateDatesForMarket(address _market, uint256 _newStartTime) external;

    function resolveMarket(address market, uint outcome) external;

    function expireMarkets(address[] calldata market) external;

    function transferSusdTo(
        address sender,
        address receiver,
        uint amount
    ) external;

    function queryMintsAndMaturityStatusForPlayerProps(address[] memory _playerPropsMarkets)
        external
        view
        returns (
            bool[] memory _hasAnyMintsArray,
            bool[] memory _isMaturedArray,
            bool[] memory _isResolvedArray,
            uint[] memory _maturities
        );
}

File 6 of 24 : IPosition.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

import "./IPositionalMarket.sol";

interface IPosition {
    /* ========== VIEWS / VARIABLES ========== */

    function getBalanceOf(address account) external view returns (uint);

    function getTotalSupply() external view returns (uint);

    function exerciseWithAmount(address claimant, uint amount) external;
}

File 7 of 24 : ITherundownConsumer.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface ITherundownConsumer {
    struct GameCreate {
        bytes32 gameId;
        uint256 startTime;
        int24 homeOdds;
        int24 awayOdds;
        int24 drawOdds;
        string homeTeam;
        string awayTeam;
    }

    // view functions
    function supportedSport(uint _sportId) external view returns (bool);

    function gameOnADate(bytes32 _gameId) external view returns (uint);

    function isGameResolvedOrCanceled(bytes32 _gameId) external view returns (bool);

    function getNormalizedOddsForMarket(address _market) external view returns (uint[] memory);

    function getGamesPerDatePerSport(uint _sportId, uint _date) external view returns (bytes32[] memory);

    function getGamePropsForOdds(address _market)
        external
        view
        returns (
            uint,
            uint,
            bytes32
        );

    function gameIdPerMarket(address _market) external view returns (bytes32);

    function getGameCreatedById(bytes32 _gameId) external view returns (GameCreate memory);

    function isChildMarket(address _market) external view returns (bool);

    function gameFulfilledCreated(bytes32 _gameId) external view returns (bool);

    function playerProps() external view returns (address);

    function oddsObtainer() external view returns (address);

    // write functions
    function fulfillGamesCreated(
        bytes32 _requestId,
        bytes[] memory _games,
        uint _sportsId,
        uint _date
    ) external;

    function fulfillGamesResolved(
        bytes32 _requestId,
        bytes[] memory _games,
        uint _sportsId
    ) external;

    function fulfillGamesOdds(bytes32 _requestId, bytes[] memory _games) external;

    function setPausedByCanceledStatus(address _market, bool _flag) external;

    function setGameIdPerChildMarket(bytes32 _gameId, address _child) external;

    function pauseOrUnpauseMarket(address _market, bool _pause) external;

    function pauseOrUnpauseMarketForPlayerProps(
        address _market,
        bool _pause,
        bool _invalidOdds,
        bool _circuitBreakerMain
    ) external;

    function setChildMarkets(
        bytes32 _gameId,
        address _main,
        address _child,
        bool _isSpread,
        int16 _spreadHome,
        uint24 _totalOver
    ) external;

    function resolveMarketManually(
        address _market,
        uint _outcome,
        uint8 _homeScore,
        uint8 _awayScore,
        bool _usebackupOdds
    ) external;

    function getOddsForGame(bytes32 _gameId)
        external
        view
        returns (
            int24,
            int24,
            int24
        );

    function sportsIdPerGame(bytes32 _gameId) external view returns (uint);

    function getGameStartTime(bytes32 _gameId) external view returns (uint256);

    function getLastUpdatedFromGameResolve(bytes32 _gameId) external view returns (uint40);

    function marketPerGameId(bytes32 _gameId) external view returns (address);

    function marketResolved(address _market) external view returns (bool);

    function marketCanceled(address _market) external view returns (bool);

    function invalidOdds(address _market) external view returns (bool);

    function isPausedByCanceledStatus(address _market) external view returns (bool);

    function isSportOnADate(uint _date, uint _sportId) external view returns (bool);

    function isSportTwoPositionsSport(uint _sportsId) external view returns (bool);
}

File 8 of 24 : ISportsAMM.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../interfaces/ISportAMMRiskManager.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";

interface ISportsAMM {
    /* ========== VIEWS / VARIABLES ========== */

    enum Position {
        Home,
        Away,
        Draw
    }

    struct SellRequirements {
        address user;
        address market;
        Position position;
        uint amount;
        uint expectedPayout;
        uint additionalSlippage;
    }

    function theRundownConsumer() external view returns (address);

    function riskManager() external view returns (ISportAMMRiskManager riskManager);

    function getMarketDefaultOdds(address _market, bool isSell) external view returns (uint[] memory);

    function isMarketInAMMTrading(address _market) external view returns (bool);

    function isMarketForSportOnePositional(uint _tag) external view returns (bool);

    function availableToBuyFromAMM(address market, Position position) external view returns (uint _available);

    function parlayAMM() external view returns (address);

    function minSupportedOdds() external view returns (uint);

    function maxSupportedOdds() external view returns (uint);

    function minSupportedOddsPerSport(uint) external view returns (uint);

    function min_spread() external view returns (uint);

    function max_spread() external view returns (uint);

    function minimalTimeLeftToMaturity() external view returns (uint);

    function getSpentOnGame(address market) external view returns (uint);

    function safeBoxImpact() external view returns (uint);

    function manager() external view returns (address);

    function getLiquidityPool() external view returns (address);

    function sUSD() external view returns (IERC20Upgradeable);

    function buyFromAMM(
        address market,
        Position position,
        uint amount,
        uint expectedPayout,
        uint additionalSlippage
    ) external;

    function buyFromAmmQuote(
        address market,
        Position position,
        uint amount
    ) external view returns (uint);

    function buyFromAmmQuoteForParlayAMM(
        address market,
        Position position,
        uint amount
    ) external view returns (uint);

    function updateParlayVolume(address _account, uint _amount) external;

    function buyPriceImpact(
        address market,
        ISportsAMM.Position position,
        uint amount
    ) external view returns (int impact);

    function obtainOdds(address _market, ISportsAMM.Position _position) external view returns (uint oddsToReturn);

    function buyFromAmmQuoteWithDifferentCollateral(
        address market,
        ISportsAMM.Position position,
        uint amount,
        address collateral
    ) external view returns (uint collateralQuote, uint sUSDToPay);

    function availableToBuyFromAMMWithBaseOdds(
        address market,
        ISportsAMM.Position position,
        uint baseOdds,
        uint balance,
        bool useBalance
    ) external view returns (uint availableAmount);

    function floorBaseOdds(uint baseOdds, address market) external view returns (uint);
}

File 9 of 24 : ISportAMMRiskManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface ISportAMMRiskManager {
    function calculateCapToBeUsed(address _market) external view returns (uint toReturn);

    function isTotalSpendingLessThanTotalRisk(uint _totalSpent, address _market) external view returns (bool _isNotRisky);

    function isMarketForSportOnePositional(uint _tag) external view returns (bool);

    function isMarketForPlayerPropsOnePositional(uint _tag) external view returns (bool);

    function minSupportedOddsPerSport(uint tag) external view returns (uint);

    function minSpreadPerSport(uint tag1, uint tag2) external view returns (uint);

    function maxSpreadPerSport(uint tag) external view returns (uint);

    function getMinSpreadToUse(
        bool useDefaultMinSpread,
        address market,
        uint min_spread,
        uint min_spreadPerAddress
    ) external view returns (uint);

    function getMaxSpreadForMarket(address _market, uint max_spread) external view returns (uint);

    function getMinOddsForMarket(address _market, uint minSupportedOdds) external view returns (uint minOdds);

    function getCapAndMaxSpreadForMarket(address _market, uint max_spread) external view returns (uint, uint);

    function getCapMaxSpreadAndMinOddsForMarket(
        address _market,
        uint max_spread,
        uint minSupportedOdds
    )
        external
        view
        returns (
            uint cap,
            uint maxSpread,
            uint minOddsForMarket
        );
}

File 10 of 24 : SportAMMLiquidityPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";

import "../../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol";
import "../../utils/proxy/solidity-0.8.0/ProxyOwned.sol";
import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol";

import "../../interfaces/ISportsAMM.sol";
import "../../interfaces/ISportPositionalMarket.sol";
import "../../interfaces/IStakingThales.sol";

import "./SportAMMLiquidityPoolRound.sol";

contract SportAMMLiquidityPool is Initializable, ProxyOwned, PausableUpgradeable, ProxyReentrancyGuard {
    /* ========== LIBRARIES ========== */
    using SafeERC20Upgradeable for IERC20Upgradeable;

    struct InitParams {
        address _owner;
        ISportsAMM _sportsAmm;
        IERC20Upgradeable _sUSD;
        uint _roundLength;
        uint _maxAllowedDeposit;
        uint _minDepositAmount;
        uint _maxAllowedUsers;
        bool _needsTransformingCollateral;
    }

    /* ========== CONSTANTS ========== */
    uint private constant HUNDRED = 1e20;
    uint private constant ONE = 1e18;
    uint private constant ONE_PERCENT = 1e16;

    /* ========== STATE VARIABLES ========== */

    ISportsAMM public sportsAMM;
    IERC20Upgradeable public sUSD;

    bool public started;

    uint public round;
    uint public roundLength;
    uint public firstRoundStartTime;

    mapping(uint => address) public roundPools;

    mapping(uint => address[]) public usersPerRound;
    mapping(uint => mapping(address => bool)) public userInRound;

    mapping(uint => mapping(address => uint)) public balancesPerRound;
    mapping(uint => uint) public allocationPerRound;

    mapping(address => bool) public withdrawalRequested;

    mapping(uint => address[]) public tradingMarketsPerRound;
    mapping(uint => mapping(address => bool)) public isTradingMarketInARound;

    mapping(uint => uint) public profitAndLossPerRound;
    mapping(uint => uint) public cumulativeProfitAndLoss;

    uint public maxAllowedDeposit;
    uint public minDepositAmount;
    uint public maxAllowedUsers;
    uint public usersCurrentlyInPool;

    address public defaultLiquidityProvider;

    IStakingThales public stakingThales;

    uint public stakedThalesMultiplier;

    address public poolRoundMastercopy;

    mapping(address => bool) public whitelistedDeposits;

    uint public totalDeposited;

    bool public onlyWhitelistedStakersAllowed;

    mapping(address => bool) public whitelistedStakers;

    bool public needsTransformingCollateral;

    mapping(uint => mapping(address => bool)) public marketAlreadyExercisedInRound;

    bool public roundClosingPrepared;

    uint public usersProcessedInRound;

    mapping(address => uint) public withdrawalShare;

    uint public utilizationRate;

    address public safeBox;
    uint public safeBoxImpact;

    /* ========== CONSTRUCTOR ========== */

    function initialize(InitParams calldata params) external initializer {
        setOwner(params._owner);
        initNonReentrant();
        sportsAMM = ISportsAMM(params._sportsAmm);

        sUSD = params._sUSD;
        roundLength = params._roundLength;
        maxAllowedDeposit = params._maxAllowedDeposit;
        minDepositAmount = params._minDepositAmount;
        maxAllowedUsers = params._maxAllowedUsers;

        needsTransformingCollateral = params._needsTransformingCollateral;

        sUSD.approve(address(sportsAMM), type(uint256).max);
    }

    /// @notice Start pool and begin round #1
    function start() external onlyOwner {
        require(!started, "Liquidity pool has already started");
        require(allocationPerRound[1] > 0, "can not start with 0 deposits");

        firstRoundStartTime = block.timestamp;
        round = 1;

        address roundPool = _getOrCreateRoundPool(1);
        SportAMMLiquidityPoolRound(roundPool).updateRoundTimes(firstRoundStartTime, getRoundEndTime(1));

        started = true;
        emit PoolStarted();
    }

    /// @notice Deposit funds from user into pool for the next round
    /// @param amount Value to be deposited
    function deposit(uint amount) external canDeposit(amount) nonReentrant whenNotPaused roundClosingNotPrepared {
        uint nextRound = round + 1;
        address roundPool = _getOrCreateRoundPool(nextRound);
        sUSD.safeTransferFrom(msg.sender, roundPool, amount);

        if (!whitelistedDeposits[msg.sender]) {
            require(!onlyWhitelistedStakersAllowed || whitelistedStakers[msg.sender], "Only whitelisted stakers allowed");
            require(address(stakingThales) != address(0), "Staking Thales not set");
            require(
                (balancesPerRound[round][msg.sender] + amount + balancesPerRound[nextRound][msg.sender]) <=
                    _transformCollateral((stakingThales.stakedBalanceOf(msg.sender) * stakedThalesMultiplier) / ONE),
                "Not enough staked THALES"
            );
        }

        require(msg.sender != defaultLiquidityProvider, "Can't deposit directly as default liquidity provider");

        // new user enters the pool
        if (balancesPerRound[round][msg.sender] == 0 && balancesPerRound[nextRound][msg.sender] == 0) {
            require(usersCurrentlyInPool < maxAllowedUsers, "Max amount of users reached");
            usersPerRound[nextRound].push(msg.sender);
            usersCurrentlyInPool = usersCurrentlyInPool + 1;
        }

        balancesPerRound[nextRound][msg.sender] += amount;

        allocationPerRound[nextRound] += amount;
        totalDeposited += amount;

        if (address(stakingThales) != address(0)) {
            stakingThales.updateVolume(msg.sender, amount);
        }

        emit Deposited(msg.sender, amount, round);
    }

    /// @notice get sUSD to mint for buy and store market as trading in the round
    /// @param market to trade
    /// @param amountToMint amount to get for mint
    function commitTrade(address market, uint amountToMint)
        external
        nonReentrant
        whenNotPaused
        onlyAMM
        roundClosingNotPrepared
    {
        require(started, "Pool has not started");
        require(amountToMint > 0, "Can't commit a zero trade");

        amountToMint = _transformCollateral(amountToMint);
        // add 1e-6 due to rounding issue, will be sent back to AMM at the end
        amountToMint = needsTransformingCollateral ? amountToMint + 1 : amountToMint;

        uint marketRound = getMarketRound(market);
        address liquidityPoolRound = _getOrCreateRoundPool(marketRound);

        if (marketRound == round) {
            sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint);
            require(
                sUSD.balanceOf(liquidityPoolRound) >=
                    (allocationPerRound[round] - ((allocationPerRound[round] * utilizationRate) / ONE)),
                "Amount exceeds available utilization for round"
            );
        } else {
            uint poolBalance = sUSD.balanceOf(liquidityPoolRound);
            if (poolBalance >= amountToMint) {
                sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint);
            } else {
                uint differenceToLPAsDefault = amountToMint - poolBalance;
                _depositAsDefault(differenceToLPAsDefault, liquidityPoolRound, marketRound);
                sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint);
            }
        }

        if (!isTradingMarketInARound[marketRound][market]) {
            tradingMarketsPerRound[marketRound].push(market);
            isTradingMarketInARound[marketRound][market] = true;
        }
    }

    /// @notice get options that are in the LP into the AMM for the buy tx
    /// @param market to get options for
    /// @param optionsAmount to get options for
    /// @param position to get options for
    function getOptionsForBuy(
        address market,
        uint optionsAmount,
        ISportsAMM.Position position
    ) external nonReentrant whenNotPaused onlyAMM roundClosingNotPrepared {
        if (optionsAmount > 0) {
            require(started, "Pool has not started");

            uint marketRound = getMarketRound(market);
            address liquidityPoolRound = _getOrCreateRoundPool(marketRound);

            (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions();
            require(address(home) != address(0), "0A");
            IPosition target = position == ISportsAMM.Position.Home ? home : away;
            if (ISportPositionalMarket(market).optionsCount() > 2 && position != ISportsAMM.Position.Home) {
                target = position == ISportsAMM.Position.Away ? away : draw;
            }

            SportAMMLiquidityPoolRound(liquidityPoolRound).moveOptions(
                IERC20Upgradeable(address(target)),
                optionsAmount,
                address(sportsAMM)
            );
        }
    }

    /// @notice get options that are in the LP into the AMM for the buy tx
    /// @param market to get options for
    /// @param optionsAmount to get options for
    /// @param position to get options for
    function getOptionsForBuyByAddress(
        address market,
        uint optionsAmount,
        address position
    ) external nonReentrant whenNotPaused onlyAMM roundClosingNotPrepared {
        if (optionsAmount > 0) {
            require(started, "Pool has not started");

            uint marketRound = getMarketRound(market);
            address liquidityPoolRound = _getOrCreateRoundPool(marketRound);

            SportAMMLiquidityPoolRound(liquidityPoolRound).moveOptions(
                IERC20Upgradeable(position),
                optionsAmount,
                address(sportsAMM)
            );
        }
    }

    /// @notice Create a round pool by market maturity date if it doesnt already exist
    /// @param market to use
    /// @return roundPool the pool for the passed market
    function getOrCreateMarketPool(address market)
        external
        onlyAMM
        nonReentrant
        whenNotPaused
        roundClosingNotPrepared
        returns (address roundPool)
    {
        uint marketRound = getMarketRound(market);
        roundPool = _getOrCreateRoundPool(marketRound);
    }

    /// @notice request withdrawal from the LP
    function withdrawalRequest() external nonReentrant canWithdraw whenNotPaused roundClosingNotPrepared {
        if (totalDeposited > balancesPerRound[round][msg.sender]) {
            totalDeposited -= balancesPerRound[round][msg.sender];
        } else {
            totalDeposited = 0;
        }

        usersCurrentlyInPool = usersCurrentlyInPool - 1;
        withdrawalRequested[msg.sender] = true;
        emit WithdrawalRequested(msg.sender);
    }

    /// @notice request partial withdrawal from the LP.
    /// @param share the percentage the user is wihdrawing from his total deposit
    function partialWithdrawalRequest(uint share) external nonReentrant canWithdraw whenNotPaused roundClosingNotPrepared {
        require(share >= ONE_PERCENT * 10 && share <= ONE_PERCENT * 90, "Share has to be between 10% and 90%");

        uint toWithdraw = (balancesPerRound[round][msg.sender] * share) / ONE;
        if (totalDeposited > toWithdraw) {
            totalDeposited -= toWithdraw;
        } else {
            totalDeposited = 0;
        }

        withdrawalRequested[msg.sender] = true;
        withdrawalShare[msg.sender] = share;
        emit WithdrawalRequested(msg.sender);
    }

    /// @notice Prepare round closing
    /// excercise options of trading markets and ensure there are no markets left unresolved
    function prepareRoundClosing() external nonReentrant whenNotPaused roundClosingNotPrepared {
        require(canCloseCurrentRound(), "Can't close current round");
        // excercise market options
        exerciseMarketsReadyToExercised();

        address roundPool = roundPools[round];
        // final balance is the final amount of sUSD in the round pool
        uint currentBalance = sUSD.balanceOf(roundPool);

        // send profit reserved for SafeBox if positive round
        if (currentBalance > allocationPerRound[round]) {
            uint safeBoxAmount = ((currentBalance - allocationPerRound[round]) * safeBoxImpact) / ONE;
            sUSD.safeTransferFrom(roundPool, safeBox, safeBoxAmount);
            currentBalance = currentBalance - safeBoxAmount;
            emit SafeBoxSharePaid(safeBoxImpact, safeBoxAmount);
        }

        // calculate PnL

        // if no allocation for current round
        if (allocationPerRound[round] == 0) {
            profitAndLossPerRound[round] = 1;
        } else {
            profitAndLossPerRound[round] = (currentBalance * ONE) / allocationPerRound[round];
        }

        roundClosingPrepared = true;

        emit RoundClosingPrepared(round);
    }

    /// @notice Prepare round closing
    /// excercise options of trading markets and ensure there are no markets left unresolved
    function processRoundClosingBatch(uint batchSize) external nonReentrant whenNotPaused {
        require(roundClosingPrepared, "Round closing not prepared");
        require(usersProcessedInRound < usersPerRound[round].length, "All users already processed");
        require(batchSize > 0, "batchSize has to be greater than 0");

        address roundPool = roundPools[round];

        uint endCursor = usersProcessedInRound + batchSize;
        if (endCursor > usersPerRound[round].length) {
            endCursor = usersPerRound[round].length;
        }

        for (uint i = usersProcessedInRound; i < endCursor; i++) {
            address user = usersPerRound[round][i];
            uint balanceAfterCurRound = (balancesPerRound[round][user] * profitAndLossPerRound[round]) / ONE;
            if (!withdrawalRequested[user] && (profitAndLossPerRound[round] > 0)) {
                balancesPerRound[round + 1][user] = balancesPerRound[round + 1][user] + balanceAfterCurRound;
                usersPerRound[round + 1].push(user);
                if (address(stakingThales) != address(0)) {
                    stakingThales.updateVolume(user, balanceAfterCurRound);
                }
            } else {
                if (withdrawalShare[user] > 0) {
                    uint amountToClaim = (balanceAfterCurRound * withdrawalShare[user]) / ONE;
                    sUSD.safeTransferFrom(roundPool, user, amountToClaim);
                    emit Claimed(user, amountToClaim);
                    withdrawalRequested[user] = false;
                    withdrawalShare[user] = 0;
                    usersPerRound[round + 1].push(user);
                    balancesPerRound[round + 1][user] = balanceAfterCurRound - amountToClaim;
                } else {
                    balancesPerRound[round + 1][user] = 0;
                    sUSD.safeTransferFrom(roundPool, user, balanceAfterCurRound);
                    withdrawalRequested[user] = false;
                    emit Claimed(user, balanceAfterCurRound);
                }
            }
            usersProcessedInRound = usersProcessedInRound + 1;
        }

        emit RoundClosingBatchProcessed(round, batchSize);
    }

    /// @notice Close current round and begin next round,
    /// calculate profit and loss and process withdrawals
    function closeRound() external nonReentrant whenNotPaused {
        require(roundClosingPrepared, "Round closing not prepared");
        require(usersProcessedInRound == usersPerRound[round].length, "Not all users processed yet");
        // set for next round to false
        roundClosingPrepared = false;

        address roundPool = roundPools[round];

        //always claim for defaultLiquidityProvider
        if (balancesPerRound[round][defaultLiquidityProvider] > 0) {
            uint balanceAfterCurRound = (balancesPerRound[round][defaultLiquidityProvider] * profitAndLossPerRound[round]) /
                ONE;
            sUSD.safeTransferFrom(roundPool, defaultLiquidityProvider, balanceAfterCurRound);
            emit Claimed(defaultLiquidityProvider, balanceAfterCurRound);
        }

        if (round == 1) {
            cumulativeProfitAndLoss[round] = profitAndLossPerRound[round];
        } else {
            cumulativeProfitAndLoss[round] = (cumulativeProfitAndLoss[round - 1] * profitAndLossPerRound[round]) / ONE;
        }

        // start next round
        round += 1;

        //add all carried over sUSD
        allocationPerRound[round] += sUSD.balanceOf(roundPool);

        totalDeposited = allocationPerRound[round] - balancesPerRound[round][defaultLiquidityProvider];

        address roundPoolNewRound = _getOrCreateRoundPool(round);

        sUSD.safeTransferFrom(roundPool, roundPoolNewRound, sUSD.balanceOf(roundPool));

        usersProcessedInRound = 0;

        emit RoundClosed(round - 1, profitAndLossPerRound[round - 1]);
    }

    /// @notice Iterate all markets in the current round and exercise those ready to be exercised
    function exerciseMarketsReadyToExercised() public whenNotPaused roundClosingNotPrepared {
        SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]);
        ISportPositionalMarket market;
        for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) {
            address marketAddress = tradingMarketsPerRound[round][i];
            if (!marketAlreadyExercisedInRound[round][marketAddress]) {
                market = ISportPositionalMarket(marketAddress);
                if (market.resolved()) {
                    poolRound.exerciseMarketReadyToExercised(market);
                    marketAlreadyExercisedInRound[round][marketAddress] = true;
                }
            }
        }
    }

    /// @notice Exercises markets in a round
    /// @param batchSize number of markets to be processed
    function exerciseMarketsReadyToExercisedBatch(uint batchSize)
        external
        nonReentrant
        whenNotPaused
        roundClosingNotPrepared
    {
        require(batchSize > 0, "batchSize has to be greater than 0");

        SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]);
        uint count = 0;
        ISportPositionalMarket market;
        for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) {
            if (count == batchSize) break;
            address marketAddress = tradingMarketsPerRound[round][i];
            if (!marketAlreadyExercisedInRound[round][marketAddress]) {
                market = ISportPositionalMarket(marketAddress);
                if (market.resolved()) {
                    poolRound.exerciseMarketReadyToExercised(market);
                    marketAlreadyExercisedInRound[round][marketAddress] = true;
                    count += 1;
                }
            }
        }
    }

    /* ========== VIEWS ========== */

    /// @notice whether the user is currently LPing
    /// @param user to check
    /// @return isUserInLP whether the user is currently LPing
    function isUserLPing(address user) external view returns (bool isUserInLP) {
        isUserInLP =
            (balancesPerRound[round][user] > 0 || balancesPerRound[round + 1][user] > 0) &&
            (!withdrawalRequested[user] || withdrawalShare[user] > 0);
    }

    /// @notice Return the maximum amount the user can deposit now
    /// @param user address to check
    /// @return maxDepositForUser the maximum amount the user can deposit in total including already deposited
    /// @return availableToDepositForUser the maximum amount the user can deposit now
    /// @return stakedThalesForUser how much THALES the user has staked
    function getMaxAvailableDepositForUser(address user)
        external
        view
        returns (
            uint maxDepositForUser,
            uint availableToDepositForUser,
            uint stakedThalesForUser
        )
    {
        uint nextRound = round + 1;
        stakedThalesForUser = stakingThales.stakedBalanceOf(user);
        maxDepositForUser = _transformCollateral((stakedThalesForUser * stakedThalesMultiplier) / ONE);
        availableToDepositForUser = maxDepositForUser > (balancesPerRound[round][user] + balancesPerRound[nextRound][user])
            ? (maxDepositForUser - balancesPerRound[round][user] - balancesPerRound[nextRound][user])
            : 0;
    }

    //deprecated User can now withdraw at any time
    /// @notice Return how much the user needs to have staked to withdraw
    /// @param user address to check
    /// @return neededStaked how much the user needs to have staked to withdraw
    function getNeededStakedThalesToWithdrawForUser(address user) external view returns (uint neededStaked) {
        uint nextRound = round + 1;
        neededStaked =
            _reverseTransformCollateral((balancesPerRound[round][user] + balancesPerRound[nextRound][user]) * ONE) /
            stakedThalesMultiplier;
    }

    /// @notice get the pool address for the market
    /// @param market to check
    /// @return roundPool the pool address for the market
    function getMarketPool(address market) external view returns (address roundPool) {
        roundPool = roundPools[getMarketRound(market)];
    }

    /// @notice Checks if all conditions are met to close the round
    /// @return bool
    function canCloseCurrentRound() public view returns (bool) {
        if (!started || block.timestamp < getRoundEndTime(round)) {
            return false;
        }
        ISportPositionalMarket market;
        for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) {
            address marketAddress = tradingMarketsPerRound[round][i];
            if (!marketAlreadyExercisedInRound[round][marketAddress]) {
                market = ISportPositionalMarket(marketAddress);
                if (!market.resolved()) {
                    return false;
                }
            }
        }
        return true;
    }

    /// @notice Iterate all markets in the current round and return true if at least one can be exercised
    function hasMarketsReadyToBeExercised() public view returns (bool) {
        SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]);
        ISportPositionalMarket market;
        for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) {
            address marketAddress = tradingMarketsPerRound[round][i];
            if (!marketAlreadyExercisedInRound[round][marketAddress]) {
                market = ISportPositionalMarket(marketAddress);
                if (market.resolved()) {
                    (uint homeBalance, uint awayBalance, uint drawBalance) = market.balancesOf(address(poolRound));
                    if (homeBalance > 0 || awayBalance > 0 || drawBalance > 0) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    /// @notice Return multiplied PnLs between rounds
    /// @param roundA Round number from
    /// @param roundB Round number to
    /// @return uint
    function cumulativePnLBetweenRounds(uint roundA, uint roundB) public view returns (uint) {
        return (cumulativeProfitAndLoss[roundB] * profitAndLossPerRound[roundA]) / cumulativeProfitAndLoss[roundA];
    }

    /// @notice Return the start time of the passed round
    /// @param _round number
    /// @return uint the start time of the given round
    function getRoundStartTime(uint _round) public view returns (uint) {
        return firstRoundStartTime + (_round - 1) * roundLength;
    }

    /// @notice Return the end time of the passed round
    /// @param _round number
    /// @return uint the end time of the given round
    function getRoundEndTime(uint _round) public view returns (uint) {
        return firstRoundStartTime + _round * roundLength;
    }

    /// @notice Return the round to which a market belongs to
    /// @param market to get the round for
    /// @return _round the round which the market belongs to
    function getMarketRound(address market) public view returns (uint _round) {
        ISportPositionalMarket marketContract = ISportPositionalMarket(market);
        (uint maturity, ) = marketContract.times();
        if (maturity > firstRoundStartTime) {
            _round = (maturity - firstRoundStartTime) / roundLength + 1;
        } else {
            _round = 1;
        }
    }

    /// @notice Return the count of users in current round
    /// @return _the count of users in current round
    function getUsersCountInCurrentRound() external view returns (uint) {
        return usersPerRound[round].length;
    }

    /* ========== INTERNAL FUNCTIONS ========== */

    function _transformCollateral(uint value) internal view returns (uint) {
        if (needsTransformingCollateral) {
            return value / 1e12;
        } else {
            return value;
        }
    }

    function _reverseTransformCollateral(uint value) internal view returns (uint) {
        if (needsTransformingCollateral) {
            return value * 1e12;
        } else {
            return value;
        }
    }

    function _depositAsDefault(
        uint amount,
        address roundPool,
        uint _round
    ) internal {
        require(defaultLiquidityProvider != address(0), "default liquidity provider not set");

        sUSD.safeTransferFrom(defaultLiquidityProvider, roundPool, amount);

        balancesPerRound[_round][defaultLiquidityProvider] += amount;
        allocationPerRound[_round] += amount;

        emit Deposited(defaultLiquidityProvider, amount, _round);
    }

    function _getOrCreateRoundPool(uint _round) internal returns (address roundPool) {
        roundPool = roundPools[_round];
        if (roundPool == address(0)) {
            require(poolRoundMastercopy != address(0), "Round pool mastercopy not set");
            SportAMMLiquidityPoolRound newRoundPool = SportAMMLiquidityPoolRound(Clones.clone(poolRoundMastercopy));
            newRoundPool.initialize(address(this), sUSD, _round, getRoundEndTime(_round - 1), getRoundEndTime(_round));
            roundPool = address(newRoundPool);
            roundPools[_round] = roundPool;
            emit RoundPoolCreated(_round, roundPool);
        }
    }

    /* ========== SETTERS ========== */

    function setPaused(bool _setPausing) external onlyOwner {
        _setPausing ? _pause() : _unpause();
    }

    /// @notice Set onlyWhitelistedStakersAllowed variable
    /// @param flagToSet self explanatory
    function setOnlyWhitelistedStakersAllowed(bool flagToSet) external onlyOwner {
        onlyWhitelistedStakersAllowed = flagToSet;
        emit SetOnlyWhitelistedStakersAllowed(flagToSet);
    }

    /// @notice Set setNeedsTransformingCollateral variable
    /// @param _needsTransformingCollateral self explanatory
    function setNeedsTransformingCollateral(bool _needsTransformingCollateral) external onlyOwner {
        needsTransformingCollateral = _needsTransformingCollateral;
        emit SetNeedsTransformingCollateral(_needsTransformingCollateral);
    }

    /// @notice Set _poolRoundMastercopy
    /// @param _poolRoundMastercopy to clone round pools from
    function setPoolRoundMastercopy(address _poolRoundMastercopy) external onlyOwner {
        require(_poolRoundMastercopy != address(0), "Can not set a zero address!");
        poolRoundMastercopy = _poolRoundMastercopy;
        emit PoolRoundMastercopyChanged(poolRoundMastercopy);
    }

    /// @notice Set _stakedThalesMultiplier
    /// @param _stakedThalesMultiplier the number of sUSD one can deposit per THALES staked
    function setStakedThalesMultiplier(uint _stakedThalesMultiplier) external onlyOwner {
        stakedThalesMultiplier = _stakedThalesMultiplier;
        emit StakedThalesMultiplierChanged(_stakedThalesMultiplier);
    }

    /// @notice Set IStakingThales contract
    /// @param _stakingThales IStakingThales address
    function setStakingThales(IStakingThales _stakingThales) external onlyOwner {
        require(address(_stakingThales) != address(0), "Can not set a zero address!");
        stakingThales = _stakingThales;
        emit StakingThalesChanged(address(_stakingThales));
    }

    /// @notice Set max allowed deposit
    /// @param _maxAllowedDeposit Deposit value
    function setMaxAllowedDeposit(uint _maxAllowedDeposit) external onlyOwner {
        maxAllowedDeposit = _maxAllowedDeposit;
        emit MaxAllowedDepositChanged(_maxAllowedDeposit);
    }

    /// @notice Set min allowed deposit
    /// @param _minDepositAmount Deposit value
    function setMinAllowedDeposit(uint _minDepositAmount) external onlyOwner {
        minDepositAmount = _minDepositAmount;
        emit MinAllowedDepositChanged(_minDepositAmount);
    }

    /// @notice Set _maxAllowedUsers
    /// @param _maxAllowedUsers Deposit value
    function setMaxAllowedUsers(uint _maxAllowedUsers) external onlyOwner {
        maxAllowedUsers = _maxAllowedUsers;
        emit MaxAllowedUsersChanged(_maxAllowedUsers);
    }

    /// @notice Set ThalesAMM contract
    /// @param _sportAMM ThalesAMM address
    function setSportAmm(ISportsAMM _sportAMM) external onlyOwner {
        require(address(_sportAMM) != address(0), "Can not set a zero address!");
        sportsAMM = _sportAMM;
        sUSD.approve(address(sportsAMM), type(uint256).max);
        emit SportAMMChanged(address(_sportAMM));
    }

    /// @notice Set defaultLiquidityProvider wallet
    /// @param _defaultLiquidityProvider default liquidity provider
    function setDefaultLiquidityProvider(address _defaultLiquidityProvider) external onlyOwner {
        require(_defaultLiquidityProvider != address(0), "Can not set a zero address!");
        defaultLiquidityProvider = _defaultLiquidityProvider;
        emit DefaultLiquidityProviderChanged(_defaultLiquidityProvider);
    }

    /// @notice Set length of rounds
    /// @param _roundLength Length of a round in miliseconds
    function setRoundLength(uint _roundLength) external onlyOwner {
        require(!started, "Can't change round length after start");
        roundLength = _roundLength;
        emit RoundLengthChanged(_roundLength);
    }

    /// @notice set addresses which can deposit into the AMM bypassing the staking checks
    /// @param _whitelistedAddresses Addresses to set the whitelist flag for
    /// @param _flag to set
    function setWhitelistedAddresses(address[] calldata _whitelistedAddresses, bool _flag) external onlyOwner {
        require(_whitelistedAddresses.length > 0, "Whitelisted addresses cannot be empty");
        for (uint256 index = 0; index < _whitelistedAddresses.length; index++) {
            // only if current flag is different, if same skip it
            if (whitelistedDeposits[_whitelistedAddresses[index]] != _flag) {
                whitelistedDeposits[_whitelistedAddresses[index]] = _flag;
                emit AddedIntoWhitelist(_whitelistedAddresses[index], _flag);
            }
        }
    }

    /// @notice set addresses which can deposit into the AMM when only whitelisted stakers are allowed
    /// @param _whitelistedAddresses Addresses to set the whitelist flag for
    /// @param _flag to set
    function setWhitelistedStakerAddresses(address[] calldata _whitelistedAddresses, bool _flag) external onlyOwner {
        require(_whitelistedAddresses.length > 0, "Whitelisted addresses cannot be empty");
        for (uint256 index = 0; index < _whitelistedAddresses.length; index++) {
            // only if current flag is different, if same skip it
            if (whitelistedStakers[_whitelistedAddresses[index]] != _flag) {
                whitelistedStakers[_whitelistedAddresses[index]] = _flag;
                emit AddedIntoWhitelistStaker(_whitelistedAddresses[index], _flag);
            }
        }
    }

    /// @notice set utilization rate parameter
    /// @param _utilizationRate value as percentage
    function setUtilizationRate(uint _utilizationRate) external onlyOwner {
        utilizationRate = _utilizationRate;
        emit UtilizationRateChanged(_utilizationRate);
    }

    /// @notice set SafeBox params
    /// @param _safeBox where to send a profit reserved for protocol from each round
    /// @param _safeBoxImpact how much is the SafeBox percentage
    function setSafeBoxParams(address _safeBox, uint _safeBoxImpact) external onlyOwner {
        safeBox = _safeBox;
        safeBoxImpact = _safeBoxImpact;
        emit SetSafeBoxParams(_safeBox, _safeBoxImpact);
    }

    /* ========== MODIFIERS ========== */

    modifier canDeposit(uint amount) {
        require(!withdrawalRequested[msg.sender], "Withdrawal is requested, cannot deposit");
        require(totalDeposited + amount <= maxAllowedDeposit, "Deposit amount exceeds AMM LP cap");
        if (balancesPerRound[round][msg.sender] == 0 && balancesPerRound[round + 1][msg.sender] == 0) {
            require(amount >= minDepositAmount, "Amount less than minDepositAmount");
        }
        _;
    }

    modifier canWithdraw() {
        require(started, "Pool has not started");
        require(!withdrawalRequested[msg.sender], "Withdrawal already requested");
        require(balancesPerRound[round][msg.sender] > 0, "Nothing to withdraw");
        require(balancesPerRound[round + 1][msg.sender] == 0, "Can't withdraw as you already deposited for next round");
        _;
    }

    modifier onlyAMM() {
        require(msg.sender == address(sportsAMM), "only the AMM may perform these methods");
        _;
    }

    modifier roundClosingNotPrepared() {
        require(!roundClosingPrepared, "Not allowed during roundClosingPrepared");
        _;
    }

    /* ========== EVENTS ========== */
    event PoolStarted();
    event Deposited(address user, uint amount, uint round);
    event WithdrawalRequested(address user);
    event RoundClosed(uint round, uint roundPnL);
    event Claimed(address user, uint amount);
    event RoundPoolCreated(uint _round, address roundPool);
    event PoolRoundMastercopyChanged(address newMastercopy);
    event StakedThalesMultiplierChanged(uint _stakedThalesMultiplier);
    event StakingThalesChanged(address stakingThales);
    event MaxAllowedDepositChanged(uint maxAllowedDeposit);
    event MinAllowedDepositChanged(uint minAllowedDeposit);
    event MaxAllowedUsersChanged(uint MaxAllowedUsersChanged);
    event SportAMMChanged(address sportAMM);
    event DefaultLiquidityProviderChanged(address newProvider);
    event AddedIntoWhitelist(address _whitelistAddress, bool _flag);
    event AddedIntoWhitelistStaker(address _whitelistAddress, bool _flag);
    event RoundLengthChanged(uint roundLength);
    event SetOnlyWhitelistedStakersAllowed(bool flagToSet);
    event RoundClosingPrepared(uint round);
    event RoundClosingBatchProcessed(uint round, uint batchSize);
    event UtilizationRateChanged(uint utilizationRate);
    event SetSafeBoxParams(address safeBox, uint safeBoxImpact);
    event SafeBoxSharePaid(uint safeBoxShare, uint safeBoxAmount);
    event SetNeedsTransformingCollateral(bool needs);
}

File 11 of 24 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `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 12 of 24 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    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;
        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");

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 13 of 24 : IPositionalMarketManager.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

import "../interfaces/IPositionalMarket.sol";

interface IPositionalMarketManager {
    /* ========== VIEWS / VARIABLES ========== */

    function durations() external view returns (uint expiryDuration, uint maxTimeToMaturity);

    function capitalRequirement() external view returns (uint);

    function marketCreationEnabled() external view returns (bool);

    function onlyAMMMintingAndBurning() external view returns (bool);

    function transformCollateral(uint value) external view returns (uint);

    function reverseTransformCollateral(uint value) external view returns (uint);

    function totalDeposited() external view returns (uint);

    function numActiveMarkets() external view returns (uint);

    function activeMarkets(uint index, uint pageSize) external view returns (address[] memory);

    function numMaturedMarkets() external view returns (uint);

    function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory);

    function isActiveMarket(address candidate) external view returns (bool);

    function isKnownMarket(address candidate) external view returns (bool);

    function getThalesAMM() external view returns (address);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function createMarket(
        bytes32 oracleKey,
        uint strikePrice,
        uint maturity,
        uint initialMint // initial sUSD to mint options for,
    ) external returns (IPositionalMarket);

    function resolveMarket(address market) external;

    function expireMarkets(address[] calldata market) external;

    function transferSusdTo(
        address sender,
        address receiver,
        uint amount
    ) external;
}

File 14 of 24 : IPriceFeed.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

interface IPriceFeed {
    // Structs
    struct RateAndUpdatedTime {
        uint216 rate;
        uint40 time;
    }

    // Mutative functions
    function addAggregator(bytes32 currencyKey, address aggregatorAddress) external;

    function removeAggregator(bytes32 currencyKey) external;

    // Views

    function rateForCurrency(bytes32 currencyKey) external view returns (uint);

    function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time);

    function getRates() external view returns (uint[] memory);

    function getCurrencies() external view returns (bytes32[] memory);
}

File 15 of 24 : IPositionalMarket.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

import "../interfaces/IPositionalMarketManager.sol";
import "../interfaces/IPosition.sol";
import "../interfaces/IPriceFeed.sol";

interface IPositionalMarket {
    /* ========== TYPES ========== */

    enum Phase {
        Trading,
        Maturity,
        Expiry
    }
    enum Side {
        Up,
        Down
    }

    /* ========== VIEWS / VARIABLES ========== */

    function getOptions() external view returns (IPosition up, IPosition down);

    function times() external view returns (uint maturity, uint destructino);

    function getOracleDetails()
        external
        view
        returns (
            bytes32 key,
            uint strikePrice,
            uint finalPrice
        );

    function fees() external view returns (uint poolFee, uint creatorFee);

    function deposited() external view returns (uint);

    function creator() external view returns (address);

    function resolved() external view returns (bool);

    function phase() external view returns (Phase);

    function oraclePrice() external view returns (uint);

    function oraclePriceAndTimestamp() external view returns (uint price, uint updatedAt);

    function canResolve() external view returns (bool);

    function result() external view returns (Side);

    function balancesOf(address account) external view returns (uint up, uint down);

    function totalSupplies() external view returns (uint up, uint down);

    function getMaximumBurnable(address account) external view returns (uint amount);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function mint(uint value) external;

    function exerciseOptions() external returns (uint);

    function burnOptions(uint amount) external;

    function burnOptionsMaximum() external;
}

File 16 of 24 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
    uint256[49] private __gap;
}

File 17 of 24 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

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

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

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

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 18 of 24 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Context_init_unchained();
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
    uint256[49] private __gap;
}

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

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the `nonReentrant` modifier
 * available, which can be aplied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 */
contract ProxyReentrancyGuard {
    /// @dev counter to allow mutex lock with only one SSTORE operation
    uint256 private _guardCounter;
    bool private _initialized;

    function initNonReentrant() public {
        require(!_initialized, "Already initialized");
        _initialized = true;
        _guardCounter = 1;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _guardCounter += 1;
        uint256 localCounter = _guardCounter;
        _;
        require(localCounter == _guardCounter, "ReentrancyGuard: reentrant call");
    }
}

File 20 of 24 : ProxyOwned.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// Clone of syntetix contract without constructor
contract ProxyOwned {
    address public owner;
    address public nominatedOwner;
    bool private _initialized;
    bool private _transferredAtInit;

    function setOwner(address _owner) public {
        require(_owner != address(0), "Owner address cannot be 0");
        require(!_initialized, "Already initialized, use nominateNewOwner");
        _initialized = true;
        owner = _owner;
        emit OwnerChanged(address(0), _owner);
    }

    function nominateNewOwner(address _owner) external onlyOwner {
        nominatedOwner = _owner;
        emit OwnerNominated(_owner);
    }

    function acceptOwnership() external {
        require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership");
        emit OwnerChanged(owner, nominatedOwner);
        owner = nominatedOwner;
        nominatedOwner = address(0);
    }

    function transferOwnershipAtInit(address proxyAddress) external onlyOwner {
        require(proxyAddress != address(0), "Invalid address");
        require(!_transferredAtInit, "Already transferred");
        owner = proxyAddress;
        _transferredAtInit = true;
        emit OwnerChanged(owner, proxyAddress);
    }

    modifier onlyOwner {
        _onlyOwner();
        _;
    }

    function _onlyOwner() private view {
        require(msg.sender == owner, "Only the contract owner may perform this action");
    }

    event OwnerNominated(address newOwner);
    event OwnerChanged(address oldOwner, address newOwner);
}

File 21 of 24 : Clones.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/Clones.sol)

pragma solidity ^0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 *
 * _Available since v3.4._
 */
library Clones {
    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            instance := create(0, ptr, 0x37)
        }
        require(instance != address(0), "ERC1167: create failed");
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            instance := create2(0, ptr, 0x37, salt)
        }
        require(instance != address(0), "ERC1167: create2 failed");
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
            mstore(add(ptr, 0x38), shl(0x60, deployer))
            mstore(add(ptr, 0x4c), salt)
            mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
            predicted := keccak256(add(ptr, 0x37), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(address implementation, bytes32 salt)
        internal
        view
        returns (address predicted)
    {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

File 22 of 24 : IStakingThales.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

interface IStakingThales {
    function updateVolume(address account, uint amount) external;

    /* ========== VIEWS / VARIABLES ==========  */
    function totalStakedAmount() external view returns (uint);

    function stakedBalanceOf(address account) external view returns (uint);

    function currentPeriodRewards() external view returns (uint);

    function currentPeriodFees() external view returns (uint);

    function getLastPeriodOfClaimedRewards(address account) external view returns (uint);

    function getRewardsAvailable(address account) external view returns (uint);

    function getRewardFeesAvailable(address account) external view returns (uint);

    function getAlreadyClaimedRewards(address account) external view returns (uint);

    function getContractRewardFunds() external view returns (uint);

    function getContractFeeFunds() external view returns (uint);

    function getAMMVolume(address account) external view returns (uint);
}

File 23 of 24 : SportAMMLiquidityPoolRound.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";

import "../../interfaces/ISportPositionalMarket.sol";

import "./SportAMMLiquidityPool.sol";

contract SportAMMLiquidityPoolRound {
    /* ========== LIBRARIES ========== */
    using SafeERC20Upgradeable for IERC20Upgradeable;

    /* ========== STATE VARIABLES ========== */

    SportAMMLiquidityPool public liquidityPool;
    IERC20Upgradeable public sUSD;

    uint public round;
    uint public roundStartTime;
    uint public roundEndTime;

    /* ========== CONSTRUCTOR ========== */

    bool public initialized;

    function initialize(
        address _liquidityPool,
        IERC20Upgradeable _sUSD,
        uint _round,
        uint _roundStartTime,
        uint _roundEndTime
    ) external {
        require(!initialized, "Already initialized");
        initialized = true;
        liquidityPool = SportAMMLiquidityPool(_liquidityPool);
        sUSD = _sUSD;
        round = _round;
        roundStartTime = _roundStartTime;
        roundEndTime = _roundEndTime;
        sUSD.approve(_liquidityPool, type(uint256).max);
    }

    function updateRoundTimes(uint _roundStartTime, uint _roundEndTime) external onlyLiquidityPool {
        roundStartTime = _roundStartTime;
        roundEndTime = _roundEndTime;
        emit RoundTimesUpdated(_roundStartTime, _roundEndTime);
    }

    function exerciseMarketReadyToExercised(ISportPositionalMarket market) external onlyLiquidityPool {
        if (market.resolved()) {
            (uint homeBalance, uint awayBalance, uint drawBalance) = market.balancesOf(address(this));
            if (homeBalance > 0 || awayBalance > 0 || drawBalance > 0) {
                market.exerciseOptions();
            }
        }
    }

    function moveOptions(
        IERC20Upgradeable option,
        uint optionsAmount,
        address destination
    ) external onlyLiquidityPool {
        option.safeTransfer(destination, optionsAmount);
    }

    modifier onlyLiquidityPool() {
        require(msg.sender == address(liquidityPool), "only the Pool manager may perform these methods");
        _;
    }

    event RoundTimesUpdated(uint _roundStartTime, uint _roundEndTime);
}

File 24 of 24 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    uint256[50] private __gap;
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_sportsAMM","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"TAG_NUMBER_PLAYERS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"address","name":"addressToCheck","type":"address"}],"name":"balanceOfPositionOnMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"address","name":"addressToCheck","type":"address"}],"name":"balanceOfPositionsOnMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"balanceOtherSide","type":"uint256"},{"internalType":"uint256","name":"balancePosition","type":"uint256"},{"internalType":"uint256","name":"balanceOtherSideAfter","type":"uint256"},{"internalType":"uint256","name":"balancePositionAfter","type":"uint256"},{"internalType":"uint256","name":"availableToBuyFromAMM","type":"uint256"},{"internalType":"uint256","name":"max_spread","type":"uint256"}],"name":"buyPriceImpactImbalancedSkew","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"capUsed","type":"uint256"},{"internalType":"uint256","name":"spentOnThisGame","type":"uint256"},{"internalType":"uint256","name":"baseOdds","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"max_spread","type":"uint256"}],"name":"calculateAvailableToBuy","outputs":[{"internalType":"uint256","name":"availableAmount","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"balancePosition","type":"uint256"},{"internalType":"uint256","name":"balanceOtherSide","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"availableToBuyFromAMM","type":"uint256"},{"internalType":"uint256","name":"max_spread","type":"uint256"}],"internalType":"struct SportsAMMUtils.DiscountParams","name":"params","type":"tuple"}],"name":"calculateDiscount","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"balancePosition","type":"uint256"},{"internalType":"uint256","name":"balanceOtherSide","type":"uint256"},{"internalType":"uint256","name":"_availableToBuyFromAMMOtherSide","type":"uint256"},{"internalType":"uint256","name":"_availableToBuyFromAMM","type":"uint256"},{"internalType":"uint256","name":"pricePosition","type":"uint256"},{"internalType":"uint256","name":"priceOtherPosition","type":"uint256"},{"internalType":"uint256","name":"max_spread","type":"uint256"}],"internalType":"struct SportsAMMUtils.NegativeDiscountsParams","name":"params","type":"tuple"}],"name":"calculateDiscountFromNegativeToPositive","outputs":[{"internalType":"int256","name":"priceImpact","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"skewImpact","type":"int256"},{"internalType":"uint256","name":"baseOdds","type":"uint256"},{"internalType":"uint256","name":"safeBoxImpact","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"calculateTempQuote","outputs":[{"internalType":"int256","name":"tempQuote","type":"int256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"positionFirst","type":"uint8"},{"internalType":"enum ISportsAMM.Position","name":"positionSecond","type":"uint8"},{"internalType":"bool","name":"inverse","type":"bool"},{"internalType":"address","name":"marketPool","type":"address"},{"internalType":"uint256","name":"minOdds","type":"uint256"},{"internalType":"uint256","name":"cap","type":"uint256"},{"internalType":"uint256","name":"maxSpreadForMarket","type":"uint256"},{"internalType":"uint256","name":"spentOnGame","type":"uint256"}],"internalType":"struct SportsAMMUtils.AvailableHigher","name":"params","type":"tuple"}],"name":"getAvailableHigherForPositions","outputs":[{"internalType":"uint256","name":"_availableHigher","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"address","name":"addressToCheck","type":"address"}],"name":"getBalanceOfPositionsOnMarket","outputs":[{"internalType":"uint256","name":"homeBalance","type":"uint256"},{"internalType":"uint256","name":"awayBalance","type":"uint256"},{"internalType":"uint256","name":"drawBalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"address","name":"addressToCheck","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position1","type":"uint8"},{"internalType":"enum ISportsAMM.Position","name":"position2","type":"uint8"}],"name":"getBalanceOfPositionsOnMarketByPositions","outputs":[{"internalType":"uint256","name":"firstBalance","type":"uint256"},{"internalType":"uint256","name":"secondBalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"address","name":"addressToCheck","type":"address"},{"internalType":"address","name":"market","type":"address"}],"name":"getBalanceOtherSideOnThreePositions","outputs":[{"internalType":"uint256","name":"balanceOfTheOtherSide","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"minSupportedOdds","type":"uint256"}],"name":"getBaseOddsForDoubleChance","outputs":[{"internalType":"uint256","name":"oddsPosition1","type":"uint256"},{"internalType":"uint256","name":"oddsPosition2","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"minSupportedOdds","type":"uint256"}],"name":"getBaseOddsForDoubleChanceSum","outputs":[{"internalType":"uint256","name":"sum","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"_availableToBuyFromAMM","type":"uint256"},{"internalType":"uint256","name":"_availableToBuyFromAMMOtherSide","type":"uint256"},{"internalType":"contract SportAMMLiquidityPool","name":"liquidityPool","type":"address"},{"internalType":"uint256","name":"max_spread","type":"uint256"},{"internalType":"uint256","name":"minSupportedOdds","type":"uint256"}],"internalType":"struct SportsAMMUtils.PriceImpactParams","name":"params","type":"tuple"}],"name":"getBuyPriceImpact","outputs":[{"internalType":"int256","name":"priceImpact","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"address","name":"toCheck","type":"address"}],"name":"getCanExercize","outputs":[{"internalType":"bool","name":"canExercize","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"}],"name":"getParentMarketPositionAddresses","outputs":[{"internalType":"address","name":"parentMarketPosition1","type":"address"},{"internalType":"address","name":"parentMarketPosition2","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"}],"name":"getParentMarketPositions","outputs":[{"internalType":"enum ISportsAMM.Position","name":"position1","type":"uint8"},{"internalType":"enum ISportsAMM.Position","name":"position2","type":"uint8"},{"internalType":"address","name":"parentMarket","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getParentMarketPositionsImpactDoubleChance","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"_position","type":"uint8"}],"name":"obtainOdds","outputs":[{"internalType":"uint256","name":"oddsToReturn","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"_position1","type":"uint8"},{"internalType":"enum ISportsAMM.Position","name":"_position2","type":"uint8"}],"name":"obtainOddsMulti","outputs":[{"internalType":"uint256","name":"oddsToReturn1","type":"uint256"},{"internalType":"uint256","name":"oddsToReturn2","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sportsAMM","outputs":[{"internalType":"contract ISportsAMM","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b50604051620039063803806200390683398101604081905262000034916200005a565b600080546001600160a01b0319166001600160a01b03929092169190911790556200008a565b6000602082840312156200006c578081fd5b81516001600160a01b038116811462000083578182fd5b9392505050565b61386c806200009a6000396000f3fe608060405234801561001057600080fd5b50600436106101425760003560e01c8063a119612d116100b8578063d20f87cf1161007c578063d20f87cf14610307578063d95bff251461031a578063e468265c1461032d578063ea25928a14610340578063f54ffd0014610353578063f947c6b31461036657600080fd5b8063a119612d14610281578063a4d682dd14610294578063ad2ddaa4146102b6578063c3812fe2146102c9578063c9925288146102dc57600080fd5b80634ab96c831161010a5780634ab96c83146101cf57806350d851a1146101f75780636116ad1e1461020a578063755cc89c1461023857806380143b9b1461024b5780639612e9a31461025e57600080fd5b80630381cd091461014757806311ecf33e1461016d5780632888a20d1461018057806331b8975e14610193578063343d372f146101c6575b600080fd5b61015a6101553660046133f3565b610379565b6040519081526020015b60405180910390f35b61015a61017b366004613279565b610639565b61015a61018e366004613316565b610729565b6101a66101a1366004612f1e565b610840565b604080516001600160a01b03938416815292909116602083015201610164565b61015a61271a81565b6101e26101dd3660046130a5565b6108c2565b60408051928352602083019190915201610164565b61015a610205366004612fe5565b610933565b61021d610218366004613019565b610e28565b60408051938452602084019290925290820152606001610164565b6101e2610246366004612f8e565b611292565b61015a610259366004613385565b611373565b61027161026c366004612f56565b6114e0565b6040519015158152602001610164565b61015a61028f3660046130a5565b61198e565b6102a76102a2366004612f1e565b6119b5565b6040516101649392919061356e565b61015a6102c4366004613248565b611c90565b61015a6102d73660046134d6565b611d9d565b6000546102ef906001600160a01b031681565b6040516001600160a01b039091168152602001610164565b61015a6103153660046130a5565b611eab565b61015a610328366004613203565b611ff7565b61015a61033b366004613019565b6120a5565b61021d61034e366004612f56565b612436565b6101e2610361366004613061565b6126d7565b61015a61037436600461349c565b612a0b565b8051602082015160a083015160405163c2edfc7360e01b81526001600160a01b0380851660048301526000948594859461040d949293919291169063c2edfc739060240160206040518083038186803b1580156103d557600080fd5b505afa1580156103e9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102189190612f3a565b9250509150600084600001516001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561045157600080fd5b505afa158015610465573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104899190613230565b60021490506000856040015184116104a25760006104b1565b60408601516104b1908561379d565b90506000866040015185116104df578487604001516104d0919061379d565b6104da9085613662565b6104e1565b835b905084876040015111610530576105296040518060a0016040528087815260200186815260200189604001518152602001896080015181526020018960c00151815250610729565b955061062f565b841561061157600061054f886000015189602001518a60e00151612b36565b905060008461056f5761056a82670de0b6b3a764000061379d565b6105b4565b88516105b49060008b60200151600281111561059b57634e487b7160e01b600052602160045260246000fd5b146105a75760006105aa565b60015b8b60e00151612b36565b90506106086040518061010001604052808b6040015181526020018981526020018881526020018b6080015181526020018b6060015181526020018481526020018381526020018b60c00151815250611373565b9750505061062f565b61062c8760400151858784868c606001518d60c00151611d9d565b95505b5050505050919050565b60008060006106558460000151856020015186604001516126d7565b915091508360a00151821061066a5781610670565b8360a001515b91508360a0015181106106835780610689565b8360a001515b90506000806106aa8660000151876080015188602001518960400151611292565b9150915060006106ca8760c0015188610100015187888b60e00151612a0b565b905060006106e88860c0015189610100015187868c60e00151612a0b565b9050819650876060015180156106fd57508082115b80610715575087606001511580156107155750808211155b1561071e578096505b505050505050919050565b60408101518151602083015160009283926107b992670de0b6b3a7640000811161077557602087015161076490670de0b6b3a764000061379d565b87516107709190613662565b610778565b86515b670de0b6b3a76400008860200151116107925760006107aa565b670de0b6b3a764000088602001516107aa919061379d565b88606001518960800151611d9d565b6040840151845191925082916000916107d19161379d565b90506000670de0b6b3a7640000808760000151670de0b6b3a7640000856107f8919061373f565b61080291906136a8565b61080c9190613662565b6108176002866136a8565b610821919061373f565b61082b91906136a8565b9050610836816137b4565b9695505050505050565b600080600080846001600160a01b031663647b65df6040518163ffffffff1660e01b8152600401604080518083038186803b15801561087e57600080fd5b505afa158015610892573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108b69190613194565b90969095509350505050565b60008060008060006108d3876119b5565b9250925092506108e38184610933565b94506108ef8183610933565b93506000851180156109015750600084115b15610929578585106109135784610915565b855b94508584106109245783610926565b855b93505b5050509250929050565b600080546040805163bb96af6560e01b8152905183926001600160a01b03169163bb96af65916004808301926020929190829003018186803b15801561097857600080fd5b505afa15801561098c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109b09190612f3a565b905060008060009054906101000a90046001600160a01b03166001600160a01b031663478426636040518163ffffffff1660e01b815260040160206040518083038186803b158015610a0157600080fd5b505afa158015610a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a399190612f3a565b9050836002811115610a5b57634e487b7160e01b600052602160045260246000fd5b856001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b158015610a9457600080fd5b505afa158015610aa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610acc9190613230565b1115610e20576000856001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b158015610b0d57600080fd5b505afa158015610b21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b459190613230565b67ffffffffffffffff811115610b6b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610b94578160200160208202803683370190505b5060405163db0d457960e01b81526001600160a01b0388811660048301529192509084169063db0d45799060240160006040518083038186803b158015610bda57600080fd5b505afa158015610bee573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c1691908101906130d0565b90506000806000610c2689612bf9565b92509250925061271a821415610d2b576040516313adb56360e11b8152600481018290526001600160a01b0386169063275b6ac69060240160206040518083038186803b158015610c7657600080fd5b505afa158015610c8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cae9190613178565b1580610cd75750876002811115610cd557634e487b7160e01b600052602160045260246000fd5b155b15610d265783886002811115610cfd57634e487b7160e01b600052602160045260246000fd5b81518110610d1b57634e487b7160e01b600052603260045260246000fd5b602002602001015196505b610e1b565b6040516346fe88bf60e11b8152600481018490526001600160a01b03861690638dfd117e9060240160206040518083038186803b158015610d6b57600080fd5b505afa158015610d7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da39190613178565b1580610dcc5750876002811115610dca57634e487b7160e01b600052602160045260246000fd5b155b15610e1b5783886002811115610df257634e487b7160e01b600052602160045260246000fd5b81518110610e1057634e487b7160e01b600052603260045260246000fd5b602002602001015196505b505050505b505092915050565b6000806000806000876001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b158015610e6957600080fd5b505afa158015610e7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ea191906131c2565b5091509150610eb7826001600160a01b03161590565b15610ece5760008060009450945094505050611289565b600080886002811115610ef157634e487b7160e01b600052602160045260246000fd5b14610f7457604051634dcb776760e11b81526001600160a01b038881166004830152831690639b96eece9060240160206040518083038186803b158015610f3757600080fd5b505afa158015610f4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6f9190613230565b610fed565b604051634dcb776760e11b81526001600160a01b038881166004830152841690639b96eece9060240160206040518083038186803b158015610fb557600080fd5b505afa158015610fc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fed9190613230565b905060008089600281111561101257634e487b7160e01b600052602160045260246000fd5b1461109557604051634dcb776760e11b81526001600160a01b038981166004830152851690639b96eece9060240160206040518083038186803b15801561105857600080fd5b505afa15801561106c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110909190613230565b61110e565b604051634dcb776760e11b81526001600160a01b038981166004830152841690639b96eece9060240160206040518083038186803b1580156110d657600080fd5b505afa1580156110ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110e9190613230565b905060008190508a6001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561114e57600080fd5b505afa158015611162573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111869190613230565b6003141561127f57600080600061119d8e8d612436565b9194509250905060008d60028111156111c657634e487b7160e01b600052602160045260246000fd5b14156111ed57829550808210156111e25780945081935061127b565b81945080935061127b565b60018d600281111561120f57634e487b7160e01b600052602160045260246000fd5b1415611236578195508083101561122b5780945082935061127b565b82945080935061127b565b60028d600281111561125857634e487b7160e01b600052602160045260246000fd5b141561127b57809550818310156112745781945082935061127b565b8294508193505b5050505b9196509450925050505b93509350939050565b60008060008060006112a48989612436565b9194509250905060008760028111156112cd57634e487b7160e01b600052602160045260246000fd5b146113055760018760028111156112f457634e487b7160e01b600052602160045260246000fd5b146112ff5780611307565b81611307565b825b9450600086600281111561132b57634e487b7160e01b600052602160045260246000fd5b1461136357600186600281111561135257634e487b7160e01b600052602160045260246000fd5b1461135d5780611365565b81611365565b825b935050505094509492505050565b6000808260200151836000015161138a919061379d565b90506000836020015184604001516113a29190613662565b905060008285604001516113b69190613662565b90506000856020015186608001516113ce919061379d565b905060006113e785856000866000878d60e00151611d9d565b905060008760a00151828960c00151611400919061373f565b61140a91906136a8565b905060006114516040518060a001604052808b6020015181526020018b6040015181526020018b6020015181526020018b6060015181526020018b60e00151815250610729565b90506000818a6020015161146591906136bc565b90506000611473848a61373f565b90506000898c602001516114879190613662565b9050806114948385613621565b61149e919061367a565b9a5060008b13156114d15760008b8d60a001516114bb91906136bc565b90508c60c00151816114cd919061367a565b9b50505b50505050505050505050919050565b60008060009054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b15801561152f57600080fd5b505afa158015611543573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115679190612f3a565b60405163e62b888960e01b81526001600160a01b038581166004830152919091169063e62b88899060240160206040518083038186803b1580156115aa57600080fd5b505afa1580156115be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e29190613178565b801561165c5750826001600160a01b0316635c975abb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561162257600080fd5b505afa158015611636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165a9190613178565b155b80156116d45750826001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b15801561169c57600080fd5b505afa1580156116b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d49190613178565b15611988576000806000856001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b15801561171757600080fd5b505afa15801561172b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174f91906131c2565b925092509250611766836001600160a01b03161590565b156117775760009350505050611988565b604051634dcb776760e11b81526001600160a01b03868116600483015260009190851690639b96eece9060240160206040518083038186803b1580156117bc57600080fd5b505afa1580156117d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f49190613230565b118061187a5750604051634dcb776760e11b81526001600160a01b03868116600483015260009190841690639b96eece9060240160206040518083038186803b15801561184057600080fd5b505afa158015611854573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118789190613230565b115b8061197a57506002866001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156118bb57600080fd5b505afa1580156118cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f39190613230565b11801561197a5750604051634dcb776760e11b81526001600160a01b03868116600483015260009190831690639b96eece9060240160206040518083038186803b15801561194057600080fd5b505afa158015611954573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119789190613230565b115b1561198457600193505b5050505b92915050565b600080600061199d85856108c2565b90925090506119ac8183613662565b95945050505050565b600080600080846001600160a01b031663d03ecc646040518163ffffffff1660e01b815260040160206040518083038186803b1580156119f457600080fd5b505afa158015611a08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a2c9190612f3a565b9050600080826001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b158015611a6a57600080fd5b505afa158015611a7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aa291906131c2565b5091509150829350611abb826001600160a01b03161590565b15611b8257600080886001600160a01b03166308a0106c6040518163ffffffff1660e01b8152600401604080518083038186803b158015611afb57600080fd5b505afa158015611b0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b339190613479565b9150915081600014611b555781600114611b4e576002611b58565b6001611b58565b60005b97508015611b765780600114611b6f576002611b79565b6001611b79565b60005b96505050611c86565b600080886001600160a01b031663647b65df6040518163ffffffff1660e01b8152600401604080518083038186803b158015611bbd57600080fd5b505afa158015611bd1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf59190613194565b91509150836001600160a01b0316826001600160a01b031614611c3957826001600160a01b0316826001600160a01b031614611c32576002611c3c565b6001611c3c565b60005b9750836001600160a01b0316816001600160a01b031614611c7e57826001600160a01b0316816001600160a01b031614611c77576002611c81565b6001611c81565b60005b965050505b5050509193909250565b6000808512611d37576000670de0b6b3a764000086611caf878361375e565b611cb991906136bc565b611cc3919061367a565b9050670de0b6b3a7640000611ce0662386f26fc1000060026136bc565b611cf290670de0b6b3a7640000613621565b611cfc90836136bc565b611d06919061367a565b9050670de0b6b3a7640000611d1b8287613621565b611d2590856136bc565b611d2f919061367a565b915050611d76565b670de0b6b3a764000080611d4b8782613621565b611d5590876136bc565b611d5f919061367a565b611d6990846136bc565b611d73919061367a565b90505b670de0b6b3a7640000611d898482613621565b611d9390836136bc565b6119ac919061367a565b60008086611dab858a613662565b611db5919061379d565b90506000611dc3868861379d565b90506000670de0b6b3a764000083611ddb828561373f565b611de591906136a8565b611def908761373f565b611df991906136a8565b90508815611e5d576000611e0e6002836136a8565b9050600081611e1d8c8f61379d565b611e27919061373f565b9050670de0b6b3a76400008d611e3d828461373f565b611e4791906136a8565b611e5191906136a8565b95505050505050611ea0565b896000670de0b6b3a764000085611e74828561373f565b611e7e91906136a8565b611e88908961373f565b611e9291906136a8565b90506002611e478285613662565b979650505050505050565b600080600080611eba866119b5565b60008054604051632fd1b02d60e21b8152949750929550909350916001600160a01b039091169063bf46c0b490611ef990859088908b90600401613543565b60206040518083038186803b158015611f1157600080fd5b505afa158015611f25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f499190613230565b60008054604051632fd1b02d60e21b815292935090916001600160a01b039091169063bf46c0b490611f8390869088908c90600401613543565b60206040518083038186803b158015611f9b57600080fd5b505afa158015611faf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd39190613230565b90506002611fe18284613621565b611feb919061367a565b98975050505050505050565b6000806000806120078587612436565b91945092509050600087600281111561203057634e487b7160e01b600052602160045260246000fd5b141561204c578082106120435780612045565b815b935061209b565b600187600281111561206e57634e487b7160e01b600052602160045260246000fd5b1415612089578083106120815780612045565b82935061209b565b8183106120965781612098565b825b93505b5050509392505050565b600080600080866001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b1580156120e457600080fd5b505afa1580156120f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061211c91906131c2565b925092509250612133836001600160a01b03161590565b15612144576000935050505061242f565b60008087600281111561216757634e487b7160e01b600052602160045260246000fd5b146121ea57604051634dcb776760e11b81526001600160a01b038781166004830152841690639b96eece9060240160206040518083038186803b1580156121ad57600080fd5b505afa1580156121c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121e59190613230565b612263565b604051634dcb776760e11b81526001600160a01b038781166004830152851690639b96eece9060240160206040518083038186803b15801561222b57600080fd5b505afa15801561223f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122639190613230565b9050876001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561229e57600080fd5b505afa1580156122b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122d69190613230565b60031480156123055750600087600281111561230257634e487b7160e01b600052602160045260246000fd5b14155b1561209857600187600281111561232c57634e487b7160e01b600052602160045260246000fd5b146123af57604051634dcb776760e11b81526001600160a01b038781166004830152831690639b96eece9060240160206040518083038186803b15801561237257600080fd5b505afa158015612386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123aa9190613230565b612428565b604051634dcb776760e11b81526001600160a01b038781166004830152841690639b96eece9060240160206040518083038186803b1580156123f057600080fd5b505afa158015612404573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124289190613230565b9450505050505b9392505050565b600080600080600080876001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b15801561247857600080fd5b505afa15801561248c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124b091906131c2565b9250925092506124c7836001600160a01b03161590565b156124df5760008060009550955095505050506126d0565b604051634dcb776760e11b81526001600160a01b038881166004830152841690639b96eece9060240160206040518083038186803b15801561252057600080fd5b505afa158015612534573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125589190613230565b604051634dcb776760e11b81526001600160a01b03898116600483015291975090831690639b96eece9060240160206040518083038186803b15801561259d57600080fd5b505afa1580156125b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125d59190613230565b9450876001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561261057600080fd5b505afa158015612624573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126489190613230565b600314156126cc57604051634dcb776760e11b81526001600160a01b038881166004830152821690639b96eece9060240160206040518083038186803b15801561269157600080fd5b505afa1580156126a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126c99190613230565b93505b5050505b9250925092565b60008060008060009054906101000a90046001600160a01b03166001600160a01b031663bb96af656040518163ffffffff1660e01b815260040160206040518083038186803b15801561272957600080fd5b505afa15801561273d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127619190612f3a565b90506000866001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561279e57600080fd5b505afa1580156127b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d69190613230565b90506000876001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561281357600080fd5b505afa158015612827573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284b9190613230565b67ffffffffffffffff81111561287157634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561289a578160200160208202803683370190505b5060405163db0d457960e01b81526001600160a01b038a811660048301529192509084169063db0d45799060240160006040518083038186803b1580156128e057600080fd5b505afa1580156128f4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261291c91908101906130d0565b905086600281111561293e57634e487b7160e01b600052602160045260246000fd5b82111561298f578087600281111561296657634e487b7160e01b600052602160045260246000fd5b8151811061298457634e487b7160e01b600052603260045260246000fd5b602002602001015194505b8560028111156129af57634e487b7160e01b600052602160045260246000fd5b821115612a0057808660028111156129d757634e487b7160e01b600052602160045260246000fd5b815181106129f557634e487b7160e01b600052603260045260246000fd5b602002602001015193505b505050935093915050565b600080670de0b6b3a7640000612a226002856136a8565b612a3490670de0b6b3a764000061379d565b612a3e908761373f565b612a4891906136a8565b90506000670de0b6b3a7640000612a5f838761373f565b612a6991906136a8565b905086612a76828a613662565b1115612b2b57600087612a89838b613662565b612a93919061379d565b905088811115612aa05750875b6000670de0b6b3a7640000612ab66002886136a8565b612ac88a670de0b6b3a764000061379d565b612ad2919061373f565b612adc91906136a8565b90506000612aea828a613662565b612afc90670de0b6b3a764000061379d565b905080612b11670de0b6b3a76400008561373f565b612b1b91906136a8565b612b259089613662565b95505050505b505095945050505050565b6000836001600160a01b031663fa20d6686040518163ffffffff1660e01b815260040160206040518083038186803b158015612b7157600080fd5b505afa158015612b85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba99190613178565b15612be7576000836002811115612bd057634e487b7160e01b600052602160045260246000fd5b1415612be757612be0848361198e565b905061242f565b612bf18484610933565b949350505050565b6040516308208aaf60e21b8152600060048201819052908190819084906001600160a01b038216906320822abc9060240160206040518083038186803b158015612c4257600080fd5b505afa158015612c56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c7a9190613230565b9350806001600160a01b03166311f2d4946040518163ffffffff1660e01b815260040160206040518083038186803b158015612cb557600080fd5b505afa158015612cc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ced9190613178565b612cf8576000612d70565b6040516308208aaf60e21b8152600160048201526001600160a01b038216906320822abc9060240160206040518083038186803b158015612d3857600080fd5b505afa158015612d4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d709190613230565b9250806001600160a01b03166311f2d4946040518163ffffffff1660e01b815260040160206040518083038186803b158015612dab57600080fd5b505afa158015612dbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612de39190613178565b8015612e6857506040516308208aaf60e21b81526001600482015261271a906001600160a01b038316906320822abc9060240160206040518083038186803b158015612e2e57600080fd5b505afa158015612e42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e669190613230565b145b612e73576000612eeb565b6040516308208aaf60e21b8152600260048201526001600160a01b038216906320822abc9060240160206040518083038186803b158015612eb357600080fd5b505afa158015612ec7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eeb9190613230565b93959294505050565b8035612eff81613810565b919050565b8035612eff81613828565b803560038110612eff57600080fd5b600060208284031215612f2f578081fd5b813561242f81613810565b600060208284031215612f4b578081fd5b815161242f81613810565b60008060408385031215612f68578081fd5b8235612f7381613810565b91506020830135612f8381613810565b809150509250929050565b60008060008060808587031215612fa3578182fd5b8435612fae81613810565b93506020850135612fbe81613810565b9250612fcc60408601612f0f565b9150612fda60608601612f0f565b905092959194509250565b60008060408385031215612ff7578182fd5b823561300281613810565b915061301060208401612f0f565b90509250929050565b60008060006060848603121561302d578081fd5b833561303881613810565b925061304660208501612f0f565b9150604084013561305681613810565b809150509250925092565b600080600060608486031215613075578081fd5b833561308081613810565b925061308e60208501612f0f565b915061309c60408501612f0f565b90509250925092565b600080604083850312156130b7578182fd5b82356130c281613810565b946020939093013593505050565b600060208083850312156130e2578182fd5b825167ffffffffffffffff808211156130f9578384fd5b818501915085601f83011261310c578384fd5b81518181111561311e5761311e6137fa565b8060051b915061312f8483016135f0565b8181528481019084860184860187018a1015613149578788fd5b8795505b8386101561316b57805183526001959095019491860191860161314d565b5098975050505050505050565b600060208284031215613189578081fd5b815161242f81613828565b600080604083850312156131a6578182fd5b82516131b181613810565b6020840151909250612f8381613810565b6000806000606084860312156131d6578081fd5b83516131e181613810565b60208501519093506131f281613810565b604085015190925061305681613810565b600080600060608486031215613217578081fd5b61322084612f0f565b9250602084013561304681613810565b600060208284031215613241578081fd5b5051919050565b6000806000806080858703121561325d578182fd5b5050823594602084013594506040840135936060013592509050565b6000610120828403121561328b578081fd5b6132936135a2565b61329c83612ef4565b81526132aa60208401612f0f565b60208201526132bb60408401612f0f565b60408201526132cc60608401612f04565b60608201526132dd60808401612ef4565b608082015260a083013560a082015260c083013560c082015260e083013560e08201526101008084013581830152508091505092915050565b600060a08284031215613327578081fd5b60405160a0810181811067ffffffffffffffff8211171561334a5761334a6137fa565b806040525082358152602083013560208201526040830135604082015260608301356060820152608083013560808201528091505092915050565b60006101008284031215613397578081fd5b61339f6135cc565b823581526020830135602082015260408301356040820152606083013560608201526080830135608082015260a083013560a082015260c083013560c082015260e083013560e08201528091505092915050565b60006101008284031215613405578081fd5b61340d6135cc565b823561341881613810565b815261342660208401612f0f565b602082015260408301356040820152606083013560608201526080830135608082015260a083013561345781613810565b60a082015260c0838101359082015260e0928301359281019290925250919050565b6000806040838503121561348b578182fd5b505080516020909101519092909150565b600080600080600060a086880312156134b3578283fd5b505083359560208501359550604085013594606081013594506080013592509050565b600080600080600080600060e0888a0312156134f0578485fd5b505085359760208701359750604087013596606081013596506080810135955060a0810135945060c0013592509050565b6003811061353f57634e487b7160e01b600052602160045260246000fd5b9052565b6001600160a01b0384168152606081016135606020830185613521565b826040830152949350505050565b6060810161357c8286613521565b6135896020830185613521565b6001600160a01b03929092166040919091015292915050565b604051610120810167ffffffffffffffff811182821017156135c6576135c66137fa565b60405290565b604051610100810167ffffffffffffffff811182821017156135c6576135c66137fa565b604051601f8201601f1916810167ffffffffffffffff81118282101715613619576136196137fa565b604052919050565b600080821280156001600160ff1b0384900385131615613643576136436137ce565b600160ff1b839003841281161561365c5761365c6137ce565b50500190565b60008219821115613675576136756137ce565b500190565b600082613689576136896137e4565b600160ff1b8214600019841416156136a3576136a36137ce565b500590565b6000826136b7576136b76137e4565b500490565b60006001600160ff1b03818413828413808216868404861116156136e2576136e26137ce565b600160ff1b84871282811687830589121615613700576137006137ce565b85871292508782058712848416161561371b5761371b6137ce565b87850587128184161615613731576137316137ce565b505050929093029392505050565b6000816000190483118215151615613759576137596137ce565b500290565b60008083128015600160ff1b85018412161561377c5761377c6137ce565b6001600160ff1b0384018313811615613797576137976137ce565b50500390565b6000828210156137af576137af6137ce565b500390565b6000600160ff1b8214156137ca576137ca6137ce565b0390565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461382557600080fd5b50565b801515811461382557600080fdfea26469706673582212209835838592dc3d6ef07171993a59ddabac4039acce9dc2452320c87e099364d564736f6c634300080400330000000000000000000000007465c5d60d3d095443cf9991da03304a30d42eae

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101425760003560e01c8063a119612d116100b8578063d20f87cf1161007c578063d20f87cf14610307578063d95bff251461031a578063e468265c1461032d578063ea25928a14610340578063f54ffd0014610353578063f947c6b31461036657600080fd5b8063a119612d14610281578063a4d682dd14610294578063ad2ddaa4146102b6578063c3812fe2146102c9578063c9925288146102dc57600080fd5b80634ab96c831161010a5780634ab96c83146101cf57806350d851a1146101f75780636116ad1e1461020a578063755cc89c1461023857806380143b9b1461024b5780639612e9a31461025e57600080fd5b80630381cd091461014757806311ecf33e1461016d5780632888a20d1461018057806331b8975e14610193578063343d372f146101c6575b600080fd5b61015a6101553660046133f3565b610379565b6040519081526020015b60405180910390f35b61015a61017b366004613279565b610639565b61015a61018e366004613316565b610729565b6101a66101a1366004612f1e565b610840565b604080516001600160a01b03938416815292909116602083015201610164565b61015a61271a81565b6101e26101dd3660046130a5565b6108c2565b60408051928352602083019190915201610164565b61015a610205366004612fe5565b610933565b61021d610218366004613019565b610e28565b60408051938452602084019290925290820152606001610164565b6101e2610246366004612f8e565b611292565b61015a610259366004613385565b611373565b61027161026c366004612f56565b6114e0565b6040519015158152602001610164565b61015a61028f3660046130a5565b61198e565b6102a76102a2366004612f1e565b6119b5565b6040516101649392919061356e565b61015a6102c4366004613248565b611c90565b61015a6102d73660046134d6565b611d9d565b6000546102ef906001600160a01b031681565b6040516001600160a01b039091168152602001610164565b61015a6103153660046130a5565b611eab565b61015a610328366004613203565b611ff7565b61015a61033b366004613019565b6120a5565b61021d61034e366004612f56565b612436565b6101e2610361366004613061565b6126d7565b61015a61037436600461349c565b612a0b565b8051602082015160a083015160405163c2edfc7360e01b81526001600160a01b0380851660048301526000948594859461040d949293919291169063c2edfc739060240160206040518083038186803b1580156103d557600080fd5b505afa1580156103e9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102189190612f3a565b9250509150600084600001516001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561045157600080fd5b505afa158015610465573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104899190613230565b60021490506000856040015184116104a25760006104b1565b60408601516104b1908561379d565b90506000866040015185116104df578487604001516104d0919061379d565b6104da9085613662565b6104e1565b835b905084876040015111610530576105296040518060a0016040528087815260200186815260200189604001518152602001896080015181526020018960c00151815250610729565b955061062f565b841561061157600061054f886000015189602001518a60e00151612b36565b905060008461056f5761056a82670de0b6b3a764000061379d565b6105b4565b88516105b49060008b60200151600281111561059b57634e487b7160e01b600052602160045260246000fd5b146105a75760006105aa565b60015b8b60e00151612b36565b90506106086040518061010001604052808b6040015181526020018981526020018881526020018b6080015181526020018b6060015181526020018481526020018381526020018b60c00151815250611373565b9750505061062f565b61062c8760400151858784868c606001518d60c00151611d9d565b95505b5050505050919050565b60008060006106558460000151856020015186604001516126d7565b915091508360a00151821061066a5781610670565b8360a001515b91508360a0015181106106835780610689565b8360a001515b90506000806106aa8660000151876080015188602001518960400151611292565b9150915060006106ca8760c0015188610100015187888b60e00151612a0b565b905060006106e88860c0015189610100015187868c60e00151612a0b565b9050819650876060015180156106fd57508082115b80610715575087606001511580156107155750808211155b1561071e578096505b505050505050919050565b60408101518151602083015160009283926107b992670de0b6b3a7640000811161077557602087015161076490670de0b6b3a764000061379d565b87516107709190613662565b610778565b86515b670de0b6b3a76400008860200151116107925760006107aa565b670de0b6b3a764000088602001516107aa919061379d565b88606001518960800151611d9d565b6040840151845191925082916000916107d19161379d565b90506000670de0b6b3a7640000808760000151670de0b6b3a7640000856107f8919061373f565b61080291906136a8565b61080c9190613662565b6108176002866136a8565b610821919061373f565b61082b91906136a8565b9050610836816137b4565b9695505050505050565b600080600080846001600160a01b031663647b65df6040518163ffffffff1660e01b8152600401604080518083038186803b15801561087e57600080fd5b505afa158015610892573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108b69190613194565b90969095509350505050565b60008060008060006108d3876119b5565b9250925092506108e38184610933565b94506108ef8183610933565b93506000851180156109015750600084115b15610929578585106109135784610915565b855b94508584106109245783610926565b855b93505b5050509250929050565b600080546040805163bb96af6560e01b8152905183926001600160a01b03169163bb96af65916004808301926020929190829003018186803b15801561097857600080fd5b505afa15801561098c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109b09190612f3a565b905060008060009054906101000a90046001600160a01b03166001600160a01b031663478426636040518163ffffffff1660e01b815260040160206040518083038186803b158015610a0157600080fd5b505afa158015610a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a399190612f3a565b9050836002811115610a5b57634e487b7160e01b600052602160045260246000fd5b856001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b158015610a9457600080fd5b505afa158015610aa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610acc9190613230565b1115610e20576000856001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b158015610b0d57600080fd5b505afa158015610b21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b459190613230565b67ffffffffffffffff811115610b6b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610b94578160200160208202803683370190505b5060405163db0d457960e01b81526001600160a01b0388811660048301529192509084169063db0d45799060240160006040518083038186803b158015610bda57600080fd5b505afa158015610bee573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c1691908101906130d0565b90506000806000610c2689612bf9565b92509250925061271a821415610d2b576040516313adb56360e11b8152600481018290526001600160a01b0386169063275b6ac69060240160206040518083038186803b158015610c7657600080fd5b505afa158015610c8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cae9190613178565b1580610cd75750876002811115610cd557634e487b7160e01b600052602160045260246000fd5b155b15610d265783886002811115610cfd57634e487b7160e01b600052602160045260246000fd5b81518110610d1b57634e487b7160e01b600052603260045260246000fd5b602002602001015196505b610e1b565b6040516346fe88bf60e11b8152600481018490526001600160a01b03861690638dfd117e9060240160206040518083038186803b158015610d6b57600080fd5b505afa158015610d7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da39190613178565b1580610dcc5750876002811115610dca57634e487b7160e01b600052602160045260246000fd5b155b15610e1b5783886002811115610df257634e487b7160e01b600052602160045260246000fd5b81518110610e1057634e487b7160e01b600052603260045260246000fd5b602002602001015196505b505050505b505092915050565b6000806000806000876001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b158015610e6957600080fd5b505afa158015610e7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ea191906131c2565b5091509150610eb7826001600160a01b03161590565b15610ece5760008060009450945094505050611289565b600080886002811115610ef157634e487b7160e01b600052602160045260246000fd5b14610f7457604051634dcb776760e11b81526001600160a01b038881166004830152831690639b96eece9060240160206040518083038186803b158015610f3757600080fd5b505afa158015610f4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6f9190613230565b610fed565b604051634dcb776760e11b81526001600160a01b038881166004830152841690639b96eece9060240160206040518083038186803b158015610fb557600080fd5b505afa158015610fc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fed9190613230565b905060008089600281111561101257634e487b7160e01b600052602160045260246000fd5b1461109557604051634dcb776760e11b81526001600160a01b038981166004830152851690639b96eece9060240160206040518083038186803b15801561105857600080fd5b505afa15801561106c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110909190613230565b61110e565b604051634dcb776760e11b81526001600160a01b038981166004830152841690639b96eece9060240160206040518083038186803b1580156110d657600080fd5b505afa1580156110ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110e9190613230565b905060008190508a6001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561114e57600080fd5b505afa158015611162573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111869190613230565b6003141561127f57600080600061119d8e8d612436565b9194509250905060008d60028111156111c657634e487b7160e01b600052602160045260246000fd5b14156111ed57829550808210156111e25780945081935061127b565b81945080935061127b565b60018d600281111561120f57634e487b7160e01b600052602160045260246000fd5b1415611236578195508083101561122b5780945082935061127b565b82945080935061127b565b60028d600281111561125857634e487b7160e01b600052602160045260246000fd5b141561127b57809550818310156112745781945082935061127b565b8294508193505b5050505b9196509450925050505b93509350939050565b60008060008060006112a48989612436565b9194509250905060008760028111156112cd57634e487b7160e01b600052602160045260246000fd5b146113055760018760028111156112f457634e487b7160e01b600052602160045260246000fd5b146112ff5780611307565b81611307565b825b9450600086600281111561132b57634e487b7160e01b600052602160045260246000fd5b1461136357600186600281111561135257634e487b7160e01b600052602160045260246000fd5b1461135d5780611365565b81611365565b825b935050505094509492505050565b6000808260200151836000015161138a919061379d565b90506000836020015184604001516113a29190613662565b905060008285604001516113b69190613662565b90506000856020015186608001516113ce919061379d565b905060006113e785856000866000878d60e00151611d9d565b905060008760a00151828960c00151611400919061373f565b61140a91906136a8565b905060006114516040518060a001604052808b6020015181526020018b6040015181526020018b6020015181526020018b6060015181526020018b60e00151815250610729565b90506000818a6020015161146591906136bc565b90506000611473848a61373f565b90506000898c602001516114879190613662565b9050806114948385613621565b61149e919061367a565b9a5060008b13156114d15760008b8d60a001516114bb91906136bc565b90508c60c00151816114cd919061367a565b9b50505b50505050505050505050919050565b60008060009054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b15801561152f57600080fd5b505afa158015611543573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115679190612f3a565b60405163e62b888960e01b81526001600160a01b038581166004830152919091169063e62b88899060240160206040518083038186803b1580156115aa57600080fd5b505afa1580156115be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e29190613178565b801561165c5750826001600160a01b0316635c975abb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561162257600080fd5b505afa158015611636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165a9190613178565b155b80156116d45750826001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b15801561169c57600080fd5b505afa1580156116b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d49190613178565b15611988576000806000856001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b15801561171757600080fd5b505afa15801561172b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174f91906131c2565b925092509250611766836001600160a01b03161590565b156117775760009350505050611988565b604051634dcb776760e11b81526001600160a01b03868116600483015260009190851690639b96eece9060240160206040518083038186803b1580156117bc57600080fd5b505afa1580156117d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f49190613230565b118061187a5750604051634dcb776760e11b81526001600160a01b03868116600483015260009190841690639b96eece9060240160206040518083038186803b15801561184057600080fd5b505afa158015611854573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118789190613230565b115b8061197a57506002866001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156118bb57600080fd5b505afa1580156118cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f39190613230565b11801561197a5750604051634dcb776760e11b81526001600160a01b03868116600483015260009190831690639b96eece9060240160206040518083038186803b15801561194057600080fd5b505afa158015611954573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119789190613230565b115b1561198457600193505b5050505b92915050565b600080600061199d85856108c2565b90925090506119ac8183613662565b95945050505050565b600080600080846001600160a01b031663d03ecc646040518163ffffffff1660e01b815260040160206040518083038186803b1580156119f457600080fd5b505afa158015611a08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a2c9190612f3a565b9050600080826001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b158015611a6a57600080fd5b505afa158015611a7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aa291906131c2565b5091509150829350611abb826001600160a01b03161590565b15611b8257600080886001600160a01b03166308a0106c6040518163ffffffff1660e01b8152600401604080518083038186803b158015611afb57600080fd5b505afa158015611b0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b339190613479565b9150915081600014611b555781600114611b4e576002611b58565b6001611b58565b60005b97508015611b765780600114611b6f576002611b79565b6001611b79565b60005b96505050611c86565b600080886001600160a01b031663647b65df6040518163ffffffff1660e01b8152600401604080518083038186803b158015611bbd57600080fd5b505afa158015611bd1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf59190613194565b91509150836001600160a01b0316826001600160a01b031614611c3957826001600160a01b0316826001600160a01b031614611c32576002611c3c565b6001611c3c565b60005b9750836001600160a01b0316816001600160a01b031614611c7e57826001600160a01b0316816001600160a01b031614611c77576002611c81565b6001611c81565b60005b965050505b5050509193909250565b6000808512611d37576000670de0b6b3a764000086611caf878361375e565b611cb991906136bc565b611cc3919061367a565b9050670de0b6b3a7640000611ce0662386f26fc1000060026136bc565b611cf290670de0b6b3a7640000613621565b611cfc90836136bc565b611d06919061367a565b9050670de0b6b3a7640000611d1b8287613621565b611d2590856136bc565b611d2f919061367a565b915050611d76565b670de0b6b3a764000080611d4b8782613621565b611d5590876136bc565b611d5f919061367a565b611d6990846136bc565b611d73919061367a565b90505b670de0b6b3a7640000611d898482613621565b611d9390836136bc565b6119ac919061367a565b60008086611dab858a613662565b611db5919061379d565b90506000611dc3868861379d565b90506000670de0b6b3a764000083611ddb828561373f565b611de591906136a8565b611def908761373f565b611df991906136a8565b90508815611e5d576000611e0e6002836136a8565b9050600081611e1d8c8f61379d565b611e27919061373f565b9050670de0b6b3a76400008d611e3d828461373f565b611e4791906136a8565b611e5191906136a8565b95505050505050611ea0565b896000670de0b6b3a764000085611e74828561373f565b611e7e91906136a8565b611e88908961373f565b611e9291906136a8565b90506002611e478285613662565b979650505050505050565b600080600080611eba866119b5565b60008054604051632fd1b02d60e21b8152949750929550909350916001600160a01b039091169063bf46c0b490611ef990859088908b90600401613543565b60206040518083038186803b158015611f1157600080fd5b505afa158015611f25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f499190613230565b60008054604051632fd1b02d60e21b815292935090916001600160a01b039091169063bf46c0b490611f8390869088908c90600401613543565b60206040518083038186803b158015611f9b57600080fd5b505afa158015611faf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd39190613230565b90506002611fe18284613621565b611feb919061367a565b98975050505050505050565b6000806000806120078587612436565b91945092509050600087600281111561203057634e487b7160e01b600052602160045260246000fd5b141561204c578082106120435780612045565b815b935061209b565b600187600281111561206e57634e487b7160e01b600052602160045260246000fd5b1415612089578083106120815780612045565b82935061209b565b8183106120965781612098565b825b93505b5050509392505050565b600080600080866001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b1580156120e457600080fd5b505afa1580156120f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061211c91906131c2565b925092509250612133836001600160a01b03161590565b15612144576000935050505061242f565b60008087600281111561216757634e487b7160e01b600052602160045260246000fd5b146121ea57604051634dcb776760e11b81526001600160a01b038781166004830152841690639b96eece9060240160206040518083038186803b1580156121ad57600080fd5b505afa1580156121c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121e59190613230565b612263565b604051634dcb776760e11b81526001600160a01b038781166004830152851690639b96eece9060240160206040518083038186803b15801561222b57600080fd5b505afa15801561223f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122639190613230565b9050876001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561229e57600080fd5b505afa1580156122b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122d69190613230565b60031480156123055750600087600281111561230257634e487b7160e01b600052602160045260246000fd5b14155b1561209857600187600281111561232c57634e487b7160e01b600052602160045260246000fd5b146123af57604051634dcb776760e11b81526001600160a01b038781166004830152831690639b96eece9060240160206040518083038186803b15801561237257600080fd5b505afa158015612386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123aa9190613230565b612428565b604051634dcb776760e11b81526001600160a01b038781166004830152841690639b96eece9060240160206040518083038186803b1580156123f057600080fd5b505afa158015612404573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124289190613230565b9450505050505b9392505050565b600080600080600080876001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b15801561247857600080fd5b505afa15801561248c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124b091906131c2565b9250925092506124c7836001600160a01b03161590565b156124df5760008060009550955095505050506126d0565b604051634dcb776760e11b81526001600160a01b038881166004830152841690639b96eece9060240160206040518083038186803b15801561252057600080fd5b505afa158015612534573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125589190613230565b604051634dcb776760e11b81526001600160a01b03898116600483015291975090831690639b96eece9060240160206040518083038186803b15801561259d57600080fd5b505afa1580156125b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125d59190613230565b9450876001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561261057600080fd5b505afa158015612624573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126489190613230565b600314156126cc57604051634dcb776760e11b81526001600160a01b038881166004830152821690639b96eece9060240160206040518083038186803b15801561269157600080fd5b505afa1580156126a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126c99190613230565b93505b5050505b9250925092565b60008060008060009054906101000a90046001600160a01b03166001600160a01b031663bb96af656040518163ffffffff1660e01b815260040160206040518083038186803b15801561272957600080fd5b505afa15801561273d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127619190612f3a565b90506000866001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561279e57600080fd5b505afa1580156127b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d69190613230565b90506000876001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561281357600080fd5b505afa158015612827573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284b9190613230565b67ffffffffffffffff81111561287157634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561289a578160200160208202803683370190505b5060405163db0d457960e01b81526001600160a01b038a811660048301529192509084169063db0d45799060240160006040518083038186803b1580156128e057600080fd5b505afa1580156128f4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261291c91908101906130d0565b905086600281111561293e57634e487b7160e01b600052602160045260246000fd5b82111561298f578087600281111561296657634e487b7160e01b600052602160045260246000fd5b8151811061298457634e487b7160e01b600052603260045260246000fd5b602002602001015194505b8560028111156129af57634e487b7160e01b600052602160045260246000fd5b821115612a0057808660028111156129d757634e487b7160e01b600052602160045260246000fd5b815181106129f557634e487b7160e01b600052603260045260246000fd5b602002602001015193505b505050935093915050565b600080670de0b6b3a7640000612a226002856136a8565b612a3490670de0b6b3a764000061379d565b612a3e908761373f565b612a4891906136a8565b90506000670de0b6b3a7640000612a5f838761373f565b612a6991906136a8565b905086612a76828a613662565b1115612b2b57600087612a89838b613662565b612a93919061379d565b905088811115612aa05750875b6000670de0b6b3a7640000612ab66002886136a8565b612ac88a670de0b6b3a764000061379d565b612ad2919061373f565b612adc91906136a8565b90506000612aea828a613662565b612afc90670de0b6b3a764000061379d565b905080612b11670de0b6b3a76400008561373f565b612b1b91906136a8565b612b259089613662565b95505050505b505095945050505050565b6000836001600160a01b031663fa20d6686040518163ffffffff1660e01b815260040160206040518083038186803b158015612b7157600080fd5b505afa158015612b85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba99190613178565b15612be7576000836002811115612bd057634e487b7160e01b600052602160045260246000fd5b1415612be757612be0848361198e565b905061242f565b612bf18484610933565b949350505050565b6040516308208aaf60e21b8152600060048201819052908190819084906001600160a01b038216906320822abc9060240160206040518083038186803b158015612c4257600080fd5b505afa158015612c56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c7a9190613230565b9350806001600160a01b03166311f2d4946040518163ffffffff1660e01b815260040160206040518083038186803b158015612cb557600080fd5b505afa158015612cc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ced9190613178565b612cf8576000612d70565b6040516308208aaf60e21b8152600160048201526001600160a01b038216906320822abc9060240160206040518083038186803b158015612d3857600080fd5b505afa158015612d4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d709190613230565b9250806001600160a01b03166311f2d4946040518163ffffffff1660e01b815260040160206040518083038186803b158015612dab57600080fd5b505afa158015612dbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612de39190613178565b8015612e6857506040516308208aaf60e21b81526001600482015261271a906001600160a01b038316906320822abc9060240160206040518083038186803b158015612e2e57600080fd5b505afa158015612e42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e669190613230565b145b612e73576000612eeb565b6040516308208aaf60e21b8152600260048201526001600160a01b038216906320822abc9060240160206040518083038186803b158015612eb357600080fd5b505afa158015612ec7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eeb9190613230565b93959294505050565b8035612eff81613810565b919050565b8035612eff81613828565b803560038110612eff57600080fd5b600060208284031215612f2f578081fd5b813561242f81613810565b600060208284031215612f4b578081fd5b815161242f81613810565b60008060408385031215612f68578081fd5b8235612f7381613810565b91506020830135612f8381613810565b809150509250929050565b60008060008060808587031215612fa3578182fd5b8435612fae81613810565b93506020850135612fbe81613810565b9250612fcc60408601612f0f565b9150612fda60608601612f0f565b905092959194509250565b60008060408385031215612ff7578182fd5b823561300281613810565b915061301060208401612f0f565b90509250929050565b60008060006060848603121561302d578081fd5b833561303881613810565b925061304660208501612f0f565b9150604084013561305681613810565b809150509250925092565b600080600060608486031215613075578081fd5b833561308081613810565b925061308e60208501612f0f565b915061309c60408501612f0f565b90509250925092565b600080604083850312156130b7578182fd5b82356130c281613810565b946020939093013593505050565b600060208083850312156130e2578182fd5b825167ffffffffffffffff808211156130f9578384fd5b818501915085601f83011261310c578384fd5b81518181111561311e5761311e6137fa565b8060051b915061312f8483016135f0565b8181528481019084860184860187018a1015613149578788fd5b8795505b8386101561316b57805183526001959095019491860191860161314d565b5098975050505050505050565b600060208284031215613189578081fd5b815161242f81613828565b600080604083850312156131a6578182fd5b82516131b181613810565b6020840151909250612f8381613810565b6000806000606084860312156131d6578081fd5b83516131e181613810565b60208501519093506131f281613810565b604085015190925061305681613810565b600080600060608486031215613217578081fd5b61322084612f0f565b9250602084013561304681613810565b600060208284031215613241578081fd5b5051919050565b6000806000806080858703121561325d578182fd5b5050823594602084013594506040840135936060013592509050565b6000610120828403121561328b578081fd5b6132936135a2565b61329c83612ef4565b81526132aa60208401612f0f565b60208201526132bb60408401612f0f565b60408201526132cc60608401612f04565b60608201526132dd60808401612ef4565b608082015260a083013560a082015260c083013560c082015260e083013560e08201526101008084013581830152508091505092915050565b600060a08284031215613327578081fd5b60405160a0810181811067ffffffffffffffff8211171561334a5761334a6137fa565b806040525082358152602083013560208201526040830135604082015260608301356060820152608083013560808201528091505092915050565b60006101008284031215613397578081fd5b61339f6135cc565b823581526020830135602082015260408301356040820152606083013560608201526080830135608082015260a083013560a082015260c083013560c082015260e083013560e08201528091505092915050565b60006101008284031215613405578081fd5b61340d6135cc565b823561341881613810565b815261342660208401612f0f565b602082015260408301356040820152606083013560608201526080830135608082015260a083013561345781613810565b60a082015260c0838101359082015260e0928301359281019290925250919050565b6000806040838503121561348b578182fd5b505080516020909101519092909150565b600080600080600060a086880312156134b3578283fd5b505083359560208501359550604085013594606081013594506080013592509050565b600080600080600080600060e0888a0312156134f0578485fd5b505085359760208701359750604087013596606081013596506080810135955060a0810135945060c0013592509050565b6003811061353f57634e487b7160e01b600052602160045260246000fd5b9052565b6001600160a01b0384168152606081016135606020830185613521565b826040830152949350505050565b6060810161357c8286613521565b6135896020830185613521565b6001600160a01b03929092166040919091015292915050565b604051610120810167ffffffffffffffff811182821017156135c6576135c66137fa565b60405290565b604051610100810167ffffffffffffffff811182821017156135c6576135c66137fa565b604051601f8201601f1916810167ffffffffffffffff81118282101715613619576136196137fa565b604052919050565b600080821280156001600160ff1b0384900385131615613643576136436137ce565b600160ff1b839003841281161561365c5761365c6137ce565b50500190565b60008219821115613675576136756137ce565b500190565b600082613689576136896137e4565b600160ff1b8214600019841416156136a3576136a36137ce565b500590565b6000826136b7576136b76137e4565b500490565b60006001600160ff1b03818413828413808216868404861116156136e2576136e26137ce565b600160ff1b84871282811687830589121615613700576137006137ce565b85871292508782058712848416161561371b5761371b6137ce565b87850587128184161615613731576137316137ce565b505050929093029392505050565b6000816000190483118215151615613759576137596137ce565b500290565b60008083128015600160ff1b85018412161561377c5761377c6137ce565b6001600160ff1b0384018313811615613797576137976137ce565b50500390565b6000828210156137af576137af6137ce565b500390565b6000600160ff1b8214156137ca576137ca6137ce565b0390565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461382557600080fd5b50565b801515811461382557600080fdfea26469706673582212209835838592dc3d6ef07171993a59ddabac4039acce9dc2452320c87e099364d564736f6c63430008040033

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

0000000000000000000000007465c5d60d3d095443cf9991da03304a30d42eae

-----Decoded View---------------
Arg [0] : _sportsAMM (address): 0x7465c5d60d3d095443CF9991Da03304A30D42Eae

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000007465c5d60d3d095443cf9991da03304a30d42eae


Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading